Best JavaScript code snippet using playwright-internal
indexController.js
Source:indexController.js
1/**2 * åå§åangularjs3 */4var indexApp = angular.module("indexApp", []).run(function()5{6 FastClick.attach(document.body);7});8//èªå®ä¹repeatå®æäºä»¶9indexApp.directive('onFinishRenderFilters', function ($timeout) {10 return {11 restrict: 'A',12 link: function(scope, element, attr) {13 if (scope.$last === true) {14 $timeout(function() {15 scope.$emit('ngRepeatFinished');16 });17 }18 }19 };20});21/**22 * åå§åcontroller23 */24indexApp.controller("indexController", function($scope)25{26 initMN(function()27 {28 mnWebMain.disableDrag();29 headerController.init($scope, indexHeaderParams);30 indexController.init($scope);31 })32});33/**34 * é¦é¡µ35 */36var indexController = 37{38 //ä½ç¨å39 scope : null,40 41 //éæåºæ¬æ°æ®æ¨¡å42 staticBasicModel : 43 {44 "searchIndexIcon" : null,45 "searchIndexTip" : null,46 },47 48 //ç»å½æ°æ®æ¨¡å49 indexModel : 50 {51 msgId : null,52 originalMessageList : [],53 messageList : [],54 showModel : {},55 searchIndexName : null,56 touchStartTime : 0,57 delMsgUserId : null,58 touchStartPosition : {},59 notices : {},60 news : {},61 indexInner : null,62 scrollHeight : 0,63 containerHeight : 0,64 screenHeight : 0,65 skipAble : true,66 showIndexSearchBtn : null,67 showIndexSearchInput : null,68 totalMsgCount : 0,69 scrolled : false,70 emptySearch : false,71 },72 73 //åå§å74 init : function ($scope)75 {76 this.scope = $scope;77 78 mnWebMain.showLoading();79 80 81 this.setStaticBasicData();82 83 this.resetData();84 85// this.listenerScroll();86 87// this.getNoticeAndNews();88// this.getMessageList();89 90 this.reloadWillAppear();91 92 this.ngClickFunction();93 94 this.ngRepeatFinish();95 },96 97 //éåï¼çé¢æ¯æ¬¡æ¾ç¤ºæ¶åæ¶å°ä¼è¯æ¶ç触åäºä»¶98 reloadWillAppear : function ()99 {100 var self = this;101 102 //æ¶å°æ¶æ¯æ¶çåè°103 mnWebMain.cbToRefreshConversationUi = function ()104 {105 self.getMessageList();106 }107 108 //çé¢æ¾ç¤ºæ¶çåè°109 mnWebMain.cbViewWillAppear = function ()110 {111 self.getNoticeAndNews();112 113 mnWebMain.setMessageListener(function (){114 115 });116 }117 118 mnWebMain.cbViewWillDisappear = function ()119 {120 mnWebMain.removeMessageListener(function (){121 122 });123 }124 125 mnWebMain.cbNavRightClicked = function ()126 {127 mnWebMain.popupModal(pageUrl.APP_INDEX_RIGHT_POPMODAL, function (data) 128 {129 var type = JSON.parse(data).data.params;130 131 if (type == 1)132 {133 mnWebMain.syncSetLocalStorage(startChatRoomSkipTypeKey.SKIP_TO_START_CHAT_ROOM_TYPE, 1);134 135 mnWebMain.syncSetLocalStorage(chatRoomBackSkipType.BACK_SKIP_TYPE, 1);136 137 var baseParam = {138 "url" : pageUrl.APP_START_CHAT_ROOM_PAGE_URL,139 "isHideNavBar" : 0,140 "titleType" : 0,141 };142 var centerParam = [{"type" : 0,"param" : "éæ©è系人"}];143 var leftParam = [{"leftType":0, "type" : 0 ,"param" : "åæ¶"}];144 var rightParam = [{"type":0,"param":"ç¡®å®"}];145 var searchBarParam = {"title" : "æç´¢"}146 147 mnWebMain.openWebViewController(baseParam, leftParam, centerParam, rightParam, searchBarParam);148 149 }150 else if (type == 2)151 {152 var baseParam = {153 "url" : pageUrl.APP_ADD_FRIENDS_PAGE_URL,154 "isHideNavBar" : 0,155 "titleType" : 0,156 };157 var centerParam = [{"type" : 0,"param" : "æ·»å æå"}];158 var leftParam = [{"leftType":0, "type" : 1 ,"param" : "btn_back_nor"}];159 var rightParam = [];160 var searchBarParam = {"title" : "æç´¢"}161 162 mnWebMain.openWebViewController(baseParam, leftParam, centerParam, rightParam, searchBarParam);163 164// mnWebMain.closeSelfViewController(1);165 }166 });167 }168 169 //æç´¢çåè°170 mnWebMain.cbSearchToUpdateH5Ui = function (data)171 {172 var searchContent = data.searchContent;173 self.searchFriends(searchContent);174 }175 176 //æ¸
空æç´¢å
容177 mnWebMain.cbSearchClearToUpdateH5Ui = function ()178 {179 self.emptySearchContent();180 }181 },182 183 //çå¬å±å¹æ»å¨184 listenerScroll : function ()185 {186 var self = this;187 188 $(window).scroll(function (event)189 {190 var scrollTime = new Date().getTime();191 192 var time = scrollTime - self.indexModel.touchStartTime;193 194 if (time > 100)195 {196 self.indexModel.scrolled = true;197 self.indexModel.touchStartTime = 0;198 }199 });200 201 },202 203 //è·åä¼ä¸éç¥åæ°é»204 getNoticeAndNews : function ()205 {206 var self = this;207 208 var params = 209 {210 isSimple : "1"211 }212 213 jqHttpRequest.asyncHttpRequest(apiUrl.API_GET_NOTICE_AND_NEWS, params, function (data)214 {215 self.indexModel.notices = {};216 self.indexModel.news = {};217 self.indexModel.showModel.showNotices = false;218 self.indexModel.showModel.showNews = false;219 if (data.newsAndNotify.notify.length > 0)220 {221 self.indexModel.showModel.showNotices = true;222 self.indexModel.notices = data.newsAndNotify.notify[0];223 self.indexModel.notices.icon = "img/notice.png";224 self.indexModel.notices.content = self.indexModel.notices.title;225 self.indexModel.notices.title = "ä¼ä¸éç¥";226 self.indexModel.notices.publicTime = getMsgFormatedDate(self.indexModel.notices.publicTime * 1000);227 228 self.indexModel.notices.unreadMsgCount = data.newsAndNotify.noReadNotifyCount;229 230 if (self.indexModel.notices.unreadMsgCount > 0)231 {232 self.indexModel.notices.showMsgCount = true;233 }234 else235 {236 self.indexModel.notices.showMsgCount = false;237 }238 }239 else240 {241 self.indexModel.showModel.showNotices = false;242 }243 244 if (data.newsAndNotify.news.length > 0)245 {246 self.indexModel.showModel.showNews = true;247 self.indexModel.news = data.newsAndNotify.news[0];248 self.indexModel.news.icon = "img/news.png";249 self.indexModel.news.content = self.indexModel.news.title;250 self.indexModel.news.title = "ä¼ä¸æ°é»";251 self.indexModel.news.publicTime = getMsgFormatedDate(self.indexModel.news.publicTime * 1000);252 253 self.indexModel.news.unreadMsgCount = data.newsAndNotify.noReadNewsCount;254 255 if (self.indexModel.news.unreadMsgCount > 0)256 {257 self.indexModel.news.showMsgCount = true;258 }259 else260 {261 self.indexModel.news.showMsgCount = false;262 }263 }264 else265 {266 self.indexModel.showModel.showNews = false;267 }268 269 $(".all-container").show();270 271 self.scope.showModel = self.indexModel.showModel;272 273 self.scope.notices = self.indexModel.notices;274 self.scope.news = self.indexModel.news;275 self.scope.$apply();276// $(".index-right-dialog-bg").show();277// $(".index-right-dialog").show();278 279 if (!self.indexModel.showModel.showNotices && !self.indexModel.showModel.showNews)280 {281 $(".index-container").css("margin-top", "0px");282 $("#index-notices").css("display", "none");283 $("#index-news").css("display", "none");284 }285 else if (!self.indexModel.showModel.showNotices && self.indexModel.showModel.showNews)286 {287 $(".index-container").css("margin-top", "60px");288 $("#index-notices").css("display", "none");289 }290 else if (self.indexModel.showModel.showNotices && !self.indexModel.showModel.showNews)291 {292 $(".index-container").css("margin-top", "60px");293 $("#index-news").css("display", "none");294 }295 else296 {297 $(".index-container").css("margin-top", "120px");298 $("#index-notices").css("display", "block");299 $("#index-news").css("display", "block");300 }301 302 self.getMessageList();303 })304 305 },306 307 //è·åä¼è¯å表308 getMessageList : function ()309 {310 var self = this;311 312 mnWebMain.getConversationList(function (data)313 {314// self.staticBasicModel.searchIndexIcon = indexParams.SEARCH_ICON;315// self.staticBasicModel.searchIndexTip = indexParams.SEARCH_TIP;316// 317// self.scope.staticBasicModel = self.staticBasicModel;318// 319// self.indexModel.skipAble = true;320// 321// self.indexModel.showModel.showIndexRightDialog = false;322// self.indexModel.showModel.showIndexRightDialogBg = false;323// 324// self.indexModel.showModel.showIndexSearchBtn = true;325// self.indexModel.showModel.showIndexSearchInput = false;326// 327// self.indexModel.showIndexSearchBtn = "ng-show";328// self.indexModel.showIndexSearchInput = "ng-hide";329// self.scope.showIndexSearchBtn = self.indexModel.showIndexSearchBtn;330// self.scope.showIndexSearchInput = self.indexModel.showIndexSearchInput;331// 332// self.indexModel.showModel.showIndexDeleteIcon = false;333// 334// self.indexModel.showModel.showDelMsgContainer = false;335// 336// self.indexModel.showModel.showScroll = false;337// 338// self.scope.showModel = self.indexModel.showModel;339//340// self.indexModel.searchIndexName = null;341// self.scope.searchIndexName = self.indexModel.searchIndexName;342 343 self.indexModel.emptySearch = false;344 self.scope.emptySearch = self.indexModel.emptySearch;345 346 self.indexModel.originalMessageList = [];347 self.indexModel.messageList = [];348 349 self.indexModel.messageList = JSON.parse(data).data.data;350 351 var totalMsgCount = 0;352 353 for (var i = 0; i < self.indexModel.messageList.length; i ++)354 {355 self.indexModel.messageList[i].msgFrom = self.indexModel.messageList[i].userName;356 357// if (isEmpty(self.indexModel.messageList[i].msgFrom) || isEmpty(self.indexModel.messageList[i].lastMessage))358// {359// continue;360// }361 362 self.indexModel.messageList[i].time = getMsgFormatedDate(self.indexModel.messageList[i].time);363 364 if (self.indexModel.messageList[i].chatType == 1)365 {366 self.indexModel.messageList[i].type = msgType.SINGLE_CHAT;367 368 if (isEmpty(self.indexModel.messageList[i].userIcon))369 {370 self.indexModel.messageList[i].userIcon = "img/ease_default_avatar.png";371 }372 }373 else374 {375 self.indexModel.messageList[i].type = msgType.CHAT_ROOM;376// if (isEmpty(self.indexModel.messageList[i].userIcon))377// {378 self.indexModel.messageList[i].userIcon = "img/ease_chat_room.png";379// }380 }381 382 if (self.indexModel.messageList[i].unreadMsgCount > 0)383 {384 self.indexModel.messageList[i].showMsgCount = true;385 }386 else387 {388 self.indexModel.messageList[i].showMsgCount = false;389 }390 391 totalMsgCount += self.indexModel.messageList[i].unreadMsgCount;392 }393 394 totalMsgCount += self.indexModel.news.unreadMsgCount;395 totalMsgCount += self.indexModel.notices.unreadMsgCount;396 self.indexModel.totalMsgCount = totalMsgCount;397 398 mnWebMain.refreshTabbarUnreadCount(self.indexModel.totalMsgCount, function ()399 {400 401 });402 403// footerController.footerModel.footerMenuList[0].totalMsgCount = totalMsgCount;404 405// if (footerController.footerModel.footerMenuList[0].totalMsgCount > 99)406// {407// footerController.footerModel.footerMenuList[0].totalMsgCount = "99+";408// self.scope.msgCountStyle = "index-msg-count-99";409// }410// 411// if (totalMsgCount > 0)412// {413// footerController.footerModel.footerMenuList[0].msgCountShow = true;414// }415// else416// {417// footerController.footerModel.footerMenuList[0].msgCountShow = false;418// }419 420 self.indexModel.originalMessageList = deepCopy(self.indexModel.messageList);421 self.scope.messageList = self.indexModel.messageList;422 self.scope.$apply();423 424// $(".index-right-dialog-bg").show();425// $(".index-right-dialog").show();426 mnWebMain.closeLoading();427 $(".all-container").show();428 429// self.resetIndexHeight();430 });431 },432 433 //éæ°è®¾ç½®çé¢é«åº¦434 resetIndexHeight : function ()435 {436 var self = this;437 438 setTimeout(function()439 {440 var screenHeight = window.screen.availHeight;441 self.indexModel.screenHeight = screenHeight;442 var containerHeight = $(".index-container").height();443 if (containerHeight < screenHeight - 101)444 {445 $(".index-container").height(screenHeight - 101);446 }447 else448 {449 $(".index-container").css("height", "auto");450 }451 452 containerHeight = $(".index-container").height();453 454 if (containerHeight < screenHeight - 101)455 {456 $(".index-container").height(screenHeight - 101);457 }458 self.scope.$apply();459 setTimeout(function(){460// self.scope.$apply();461// allController.allModel.mySwiper.container[0].style.height=allController.allModel.mySwiper.slides[allController.allModel.mySwiper.activeIndex].offsetHeight+'px';462 }, 0);463 }, 10);464 },465 466 //ææangularjsç¹å»äºä»¶467 ngClickFunction : function ()468 {469 var self = this;470 471 //472// self.scope.back = function ()473// {474// mnWebMain.closeSelfViewController(1);475// }476 477 //æç´¢æå478 self.scope.onClickSearchFriend = function ()479 {480 self.indexModel.showModel.showIndexSearchBtn = false;481 self.indexModel.showModel.showIndexSearchInput = true;482 483 self.indexModel.showIndexSearchBtn = "ng-hide";484 self.indexModel.showIndexSearchInput = "ng-show";485 self.scope.showIndexSearchBtn = self.indexModel.showIndexSearchBtn;486 self.scope.showIndexSearchInput = self.indexModel.showIndexSearchInput;487 488 self.scope.showModel = self.indexModel.showModel;489 490 491 setTimeout(function()492 {493 $("#index-search-input").focus();494 }, 5);495 }496 497 //å é¤æç´¢ææ¬498 self.scope.onClickIndexDelete = function ()499 {500 501 }502 503 //æç´¢504 self.scope.searchFriend = function (searchIndexName)505 {506 507 508 }509 510 //æ¥çæ¶æ¯è¯¦æ
511 self.scope.onClickSeeMsgDetail = function (type, userId, userName, userIcon,$event)512 {513 $event.stopPropagation();514 515 for (var i = 0; i < self.indexModel.messageList.length; i ++)516 {517 if (self.indexModel.messageList[i].userId == userId)518 {519 self.indexModel.totalMsgCount -= self.indexModel.messageList[i].unreadMsgCount;520 self.indexModel.messageList[i].unreadMsgCount = 0;521 self.indexModel.messageList[i].showMsgCount = false;522 break;523 }524 }525 526 self.scope.messageList = self.indexModel.messageList;527 528 mnWebMain.refreshTabbarUnreadCount(self.indexModel.totalMsgCount, function ()529 {530 self.scope.$apply();531 });532 533 var params = 534 {535 type : "1"536 }537 538 jqHttpRequest.asyncHttpRequest(apiUrl.API_ADD_STATISTICS, params, function (data)539 {540 541 })542 543 var baseParam;544 var centerParam = [];545 var leftParam = [];546 var rightParam = [];547 548 switch (parseInt(type)){549 case msgType.NOTICE:550 baseParam = {551 "url" : pageUrl.APP_NOTICE_PAGE_URL,552 "isHideNavBar" : 1,553 "titleType" : 0,554 };555 mnWebMain.openWebViewController(baseParam, leftParam, centerParam, rightParam);556 break;557 case msgType.NEWS:558 baseParam = {559 "url" : pageUrl.APP_NEWS_PAGE_URL,560 "isHideNavBar" : 1,561 "titleType" : 0,562 };563 mnWebMain.openWebViewController(baseParam, leftParam, centerParam, rightParam);564 break;565 case msgType.CHAT_ROOM:566 var chatType = 2;567 var userId = userId;568 var userName = userName;569 var userIcon = userIcon;570 mnWebMain.openViewController(VCID_SINGLE_CHAT, chatType, userId, userName, userIcon);//åç群è571 break;572 case msgType.SINGLE_CHAT:573 var chatType = 1;574 var userId = userId;575 var userName = userName;576 var userIcon = userIcon;577 mnWebMain.openViewController(VCID_SINGLE_CHAT, chatType, userId, userName, userIcon);//åçåè578 break;579 default:580 break;581 }582 }583 584 //å·¦æ»å é¤585 self.scope.onClickDel = function(msgId, $event)586 {587 $event.stopPropagation();588 self.indexModel.msgId = msgId;589 $confirmDialog.show("ç¡®å®è¦å é¤ï¼",function(){590 591 });592 }593 594 //顶é¨å³ä¾§ç¹å»595 self.scope.rightPartClick = function ()596 {597 if (self.indexModel.showIndexRightDialog)598 {599 self.indexModel.showModel.showIndexRightDialog = false;600 self.indexModel.showModel.showIndexRightDialogBg = false;601 }602 else 603 {604 self.indexModel.showModel.showIndexRightDialog = true;605 self.indexModel.showModel.showIndexRightDialogBg = true;606 }607 608 self.scope.showModel = self.indexModel.showModel;609 }610 611 //é¿æå¼å§ å é¤ä¼è¯è®°å½612 self.scope.onTouchStartToDelMsg = function (userId, e)613 {614 e.stopPropagation();615// e.preventDefault();616 self.indexModel.touchStartPosition.x = event.changedTouches[0].clientX;617 self.indexModel.touchStartPosition.y = event.changedTouches[0].clientY;618 619 self.indexModel.delMsgUserId = userId;620 621 self.indexModel.touchStartTime = new Date().getTime();622 623 self.indexModel.scrolled = false;624// setTimeout(function (){625// 626// if (self.indexModel.touchStartTime > 0)627// {628// mnWebMain.popupModal(pageUrl.APP_LONG_TOUCH_DEL_MSG, function(dataObj)629// {630// var type = JSON.parse(dataObj).data.params;631// 632// if (type == 1)633// {634// mnWebMain.delConversation(self.indexModel.delMsgUserId, function (data)635// {636// var isDel = JSON.parse(data).data.isDel;637// 638// if (isDel)639// {640// self.getMessageList();641// }642// 643// self.indexModel.showModel.showDelMsgContainer = false;644// self.scope.showModel = self.indexModel.showModel;645// self.scope.$apply();646// });647// }648// });649// }650// 651// }, 800);652 }653 654 //æ»å¨åæ¶é¿æå é¤655 self.scope.onTouchMoveToCancelDelMsg = function (e)656 {657 e.stopPropagation();658// e.preventDefault();659 var x = event.changedTouches[0].clientX;660 var y = event.changedTouches[0].clientY;661 662 if (Math.abs(y - self.indexModel.touchStartPosition.y) > 10)663 {664 self.indexModel.showModel.showScroll = true;665 self.scope.showModel = self.indexModel.showModel;666 }667 668 //æ»å¨çè·ç¦»669 var distance = Math.sqrt(670 Math.pow((x - self.indexModel.touchStartPosition.x), 2) + 671 Math.pow((y - self.indexModel.touchStartPosition.y), 2)672 );673 674 if (distance > 10)675 {676 self.indexModel.touchStartTime = 0;677 }678 }679 680 //é¿æç»æ å é¤ä¼è¯è®°å½681 self.scope.onTouchEndToDelMsg = function (type, userId, userName, userIcon, e)682 {683 e.stopPropagation();684// e.preventDefault();685 self.indexModel.showModel.showScroll = false;686 self.scope.showModel = self.indexModel.showModel;687 var touchEndTime = new Date().getTime();688 689 var time = touchEndTime - self.indexModel.touchStartTime;690 691 if (time < 100)692 {693// if (self.indexModel.skipAble)694// {695// self.indexModel.skipAble = false;696 for (var i = 0; i < self.indexModel.messageList.length; i ++)697 {698 if (self.indexModel.messageList[i].userId == userId)699 {700 self.indexModel.totalMsgCount -= self.indexModel.messageList[i].unreadMsgCount;701 self.indexModel.messageList[i].unreadMsgCount = 0;702 self.indexModel.messageList[i].showMsgCount = false;703 break;704 }705 }706 707 self.scope.messageList = self.indexModel.messageList;708 709 mnWebMain.refreshTabbarUnreadCount(self.indexModel.totalMsgCount, function ()710 {711 712 });713 714 var baseParam;715 var centerParam = [];716 var leftParam = [];717 var rightParam = [];718 719 switch (parseInt(type))720 {721 case msgType.NOTICE:722 baseParam = {723 "url" : pageUrl.APP_NOTICE_PAGE_URL,724 "isHideNavBar" : 1,725 "titleType" : 0,726 };727 mnWebMain.openWebViewController(baseParam, leftParam, centerParam, rightParam);728 break;729 case msgType.NEWS:730 baseParam = {731 "url" : pageUrl.APP_NEWS_PAGE_URL,732 "isHideNavBar" : 1,733 "titleType" : 0,734 };735 mnWebMain.openWebViewController(baseParam, leftParam, centerParam, rightParam);736 break;737 case msgType.CHAT_ROOM:738 //TODO739 var chatType = 2;740 var userId = userId;741 var userName = userName;742 var userIcon = userIcon;743 mnWebMain.openViewController(VCID_SINGLE_CHAT, chatType, userId, userName, userIcon);//åç群è744 break;745 case msgType.SINGLE_CHAT:746 747 var chatType = 1;748 var userId = userId;749 var userName = userName;750 var userIcon = userIcon;751 mnWebMain.openViewController(VCID_SINGLE_CHAT, chatType, userId, userName, userIcon);//åçåè752 break;753 default:754 break;755 }756// }757 }758 759 if (self.indexModel.delMsgUserId != userId)760 {761 self.indexModel.touchStartTime = 0;762 }763 764 if (self.indexModel.scrolled)765 {766 self.indexModel.touchStartTime = 0;767 }768 769 var x = event.changedTouches[0].clientX;770 var y = event.changedTouches[0].clientY;771 772 if (Math.abs(y - self.indexModel.touchStartPosition.y) > 10)773 {774 self.indexModel.showModel.showScroll = true;775 self.scope.showModel = self.indexModel.showModel;776 }777 778 //æ»å¨çè·ç¦»779 var distance = Math.sqrt(780 Math.pow((x - self.indexModel.touchStartPosition.x), 2) + 781 Math.pow((y - self.indexModel.touchStartPosition.y), 2)782 );783 784 if (distance > 10)785 {786 self.indexModel.touchStartTime = 0;787 }788 789 if (time >= 800)790 {791 self.indexModel.touchStartTime = 0;792 mnWebMain.popupModal(pageUrl.APP_LONG_TOUCH_DEL_MSG, function(dataObj)793 {794 var type = JSON.parse(dataObj).data.params;795 796 if (type == 1)797 {798 mnWebMain.delConversation(self.indexModel.delMsgUserId, function (data)799 {800 var isDel = JSON.parse(data).data.isDel;801 802 if (isDel)803 {804 self.getMessageList();805 }806 807 self.indexModel.showModel.showDelMsgContainer = false;808 self.scope.showModel = self.indexModel.showModel;809 self.scope.$apply();810 });811 }812 });813 }814 815 816 }817 818 //éèå é¤ä¼è¯è天记å½å¼¹æ¡819 self.scope.onClickHideDelMsg = function ()820 {821 self.indexModel.showModel.showDelMsgContainer = false;822 self.scope.showModel = self.indexModel.showModel;823 }824 825 //å é¤ä¼è¯è天记å½826 self.scope.onClickDelMsg = function ()827 {828 829 }830 831 //跳转å°éç¥å表页832 self.scope.onClickToNoticeList = function ()833 {834 var baseParam = {835 "url" : pageUrl.APP_NOTICE_PAGE_URL,836 "isHideNavBar" : 0,837 "titleType" : 0,838 };839 var centerParam = [{"type" : 0,"param" : "ä¼ä¸éç¥"}];840 var leftParam = [{"leftType":0, "type" : 1 ,"param" : "btn_back_nor"}];841 var rightParam = [];842 843 mnWebMain.openWebViewController(baseParam, leftParam, centerParam, rightParam);844 }845 846 //跳转å°æ°é»å表页847 self.scope.onClickToNewsList = function ()848 {849 var baseParam = {850 "url" : pageUrl.APP_NEWS_PAGE_URL,851 "isHideNavBar" : 0,852 "titleType" : 0,853 };854 var centerParam = [{"type" : 0,"param" : "ä¼ä¸æ°é»"}];855 var leftParam = [{"leftType":0, "type" : 1 ,"param" : "btn_back_nor"}];856 var rightParam = [];857 858 mnWebMain.openWebViewController(baseParam, leftParam, centerParam, rightParam);859 }860 },861 862 //863 searchFriends : function (searchIndexName)864 {865 var self = this;866 867 self.indexModel.searchIndexName = searchIndexName;868 self.scope.searchIndexName = self.indexModel.searchIndexName;869 870 if (isEmpty(searchIndexName)) 871 {872// self.indexModel.showModel.showIndexDeleteIcon = false;873// self.scope.showModel = self.indexModel.showModel;874 875 self.indexModel.emptySearch = false;876 self.scope.emptySearch = self.indexModel.emptySearch;877 878 self.indexModel.messageList = [];879 self.indexModel.messageList = deepCopy(self.indexModel.originalMessageList);880 self.scope.messageList = self.indexModel.messageList;881 self.scope.$apply();882 }883 else884 {885// self.indexModel.showModel.showIndexDeleteIcon = true;886// self.scope.showModel = self.indexModel.showModel;887 var msgLists = deepCopy(self.indexModel.originalMessageList);888 889 self.indexModel.messageList = [];890 891 for (var i = 0; i < msgLists.length; i ++)892 {893 if (msgLists[i].msgFrom.indexOf(searchIndexName) > -1 || msgLists[i].lastMessage.indexOf(searchIndexName) > -1)894 {895 self.indexModel.messageList.push(msgLists[i]);896 }897 }898 899 if (self.indexModel.messageList.length == 0)900 {901 self.indexModel.emptySearch = true;902 self.scope.emptySearch = self.indexModel.emptySearch;903 }904 905 self.scope.messageList = self.indexModel.messageList;906 self.scope.$apply();907 }908 },909 910 //911 emptySearchContent : function ()912 {913 var self = this;914 915// self.indexModel.showModel.showIndexDeleteIcon = false;916// self.indexModel.showModel.showIndexSearchBtn = true;917// self.indexModel.showModel.showIndexSearchInput = false;918// 919// self.indexModel.showIndexSearchBtn = "ng-show";920// self.indexModel.showIndexSearchInput = "ng-hide";921// self.scope.showIndexSearchBtn = self.indexModel.showIndexSearchBtn;922// self.scope.showIndexSearchInput = self.indexModel.showIndexSearchInput;923// 924// self.scope.showModel = self.indexModel.showModel;925// 926// self.indexModel.searchIndexName = null;927// self.scope.searchIndexName = self.indexModel.searchIndexName;928 929 self.indexModel.emptySearch = false;930 self.scope.emptySearch = self.indexModel.emptySearch;931 932 self.indexModel.messageList = [];933 self.indexModel.messageList = deepCopy(self.indexModel.originalMessageList);934 self.scope.messageList = self.indexModel.messageList;935 self.scope.$apply();936 },937 938 //åå§ååºæ¬éææ°æ®939 setStaticBasicData : function ()940 {941 var self = this;942 943 self.staticBasicModel.searchIndexIcon = indexParams.SEARCH_ICON;944 self.staticBasicModel.searchIndexTip = indexParams.SEARCH_TIP;945 946 self.scope.staticBasicModel = self.staticBasicModel;947 948 self.indexModel.indexInner = document.getElementById("indexInner")949 self.indexModel.indexInner.style.top = "0px";950// self.scope.$apply();951 },952 953 //éç½®ééææ°æ®954 resetData : function ()955 {956 var self = this;957 self.indexModel.showModel.showIndexRightDialog = false;958 self.indexModel.showModel.showIndexRightDialogBg = false;959 960 self.indexModel.showModel.showIndexSearchBtn = true;961 self.indexModel.showModel.showIndexSearchInput = false;962 963 self.indexModel.showIndexSearchBtn = "ng-show";964 self.indexModel.showIndexSearchInput = "ng-hide";965 self.scope.showIndexSearchBtn = self.indexModel.showIndexSearchBtn;966 self.scope.showIndexSearchInput = self.indexModel.showIndexSearchInput;967 968 self.indexModel.showModel.showIndexDeleteIcon = false;969 970 self.indexModel.showModel.showDelMsgContainer = false;971 972 self.indexModel.showModel.showScroll = false;973 974 self.scope.showModel = self.indexModel.showModel;975 976 self.indexModel.searchIndexName = null;977 self.scope.searchIndexName = self.indexModel.searchIndexName;978 979 self.indexModel.emptySearch = false;980 self.scope.emptySearch = self.indexModel.emptySearch;981 982 self.indexModel.news.unreadMsgCount = 0;983 self.indexModel.notices.unreadMsgCount = 0;984 985 986// self.scope.$apply();987 988// $(".msg-list ul li").swipeLeft(function(e){989// e.stopPropagation();990// $(this).css("-webkit-transform","translateX(-70px)");991// });992// $(".msg-list ul li").swipeRight(function(e){993// e.stopPropagation();994// $(this).css("-webkit-transform","translateX(0)");995// });996 997 998 },999 1000 ngRepeatFinish : function(){1001 1002 var self = this;1003 1004 //ng-repeatå®æåæ§è¡çæä½1005 this.scope.$on('ngRepeatFinished', function(ngRepeatFinishedEvent)1006 {1007 $(".index-msg-long-click").longTap(function()1008 {1009 var userId = $(this).attr("data-id");1010 1011 self.indexModel.delMsgUserId = userId;1012 1013 mnWebMain.popupModal(pageUrl.APP_LONG_TOUCH_DEL_MSG, function(dataObj)1014 {1015 var type = JSON.parse(dataObj).data.params;1016 1017 if (type == 1)1018 {1019 mnWebMain.delConversation(self.indexModel.delMsgUserId, function (data)1020 {1021 var isDel = JSON.parse(data).data.isDel;1022 1023 if (isDel)1024 {1025 self.getMessageList();1026 }1027 1028 self.indexModel.showModel.showDelMsgContainer = false;1029 self.scope.showModel = self.indexModel.showModel;1030 self.scope.$apply();1031 });1032 }1033 });1034 1035 });1036 });1037 1038 },1039 1040 ...
IndexRoute.js
Source:IndexRoute.js
1/*2 Copyright 2013 Roy Russo3 Licensed under the Apache License, Version 2.0 (the "License");4 you may not use this file except in compliance with the License.5 You may obtain a copy of the License at6 http://www.apache.org/licenses/LICENSE-2.07 Unless required by applicable law or agreed to in writing, software8 distributed under the License is distributed on an "AS IS" BASIS,9 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.10 See the License for the specific language governing permissions and11 limitations under the License.12 Latest Builds: https://github.com/royrusso/elasticsearch-HQ13 */14var indexRoute = {};15/***16 * Abandon all hope, ye who enters here.17 *18 * @param indexId19 */20indexRoute.indexView = function (indexId) {21 var indexStatsModel = new IndexStatsModel({connectionRootURL:cluster.get("connectionRootURL"), indexId:indexId});22 var indexStatusModel = new IndexStatusModel({connectionRootURL:cluster.get("connectionRootURL"), indexId:indexId});23 var indexHealthModel = new IndexHealthModel({connectionRootURL:cluster.get("connectionRootURL"), indexId:indexId});24 var indexAliasModel = new IndexAliasModel({connectionRootURL:cluster.get("connectionRootURL"), indexId:indexId});25 indexStatusModel.fetch({26 success:function (model, response) {27 var polloptions = {delay:settingsModel.get('settings').poller.index};28 indexPoller = Backbone.Poller.get(indexStatusModel, polloptions);29 indexPoller.start();30 indexPoller.on('success', function (indexStatusModel) {31 ajaxloading.show();32 $.when(indexStatsModel.fetch(), indexHealthModel.fetch(), indexAliasModel.fetch())33 .done(function () {34 var indexView = new IndexView({indexId:indexId, model:indexStatsModel, statusModel:indexStatusModel, healthModel:indexHealthModel, aliasModel:indexAliasModel});35 indexView.render();36 });37 ajaxloading.hide();38 });39 }40 });41};42indexRoute.deleteIndex = function (indexId) {43 var indexModel = new IndexModel({connectionRootURL:cluster.get("connectionRootURL"), indexId:indexId});44 indexModel.id = indexId;45 indexModel.destroy({46 success:function (model, response) {47 var str = JSON.stringify(response, undefined, 2);48 var template = _.template(indexActionTemplate.defaultModal, {title:'Index Deleted!', res:str});49 $('#infoModal-loc').html(template);50 prettyPrint();51 $('#deleteindexmodal').modal('hide');52 $('#deleteindexmodal').on('hidden', function () {53 $('#defaultindexmodal').modal('show');54 $('#defaultindexmodal').on('hidden', function () {55 router.navigate("indices", true);56 });57 });58 },59 error:function (model, response, options) {60 var str = JSON.stringify(response, undefined, 2);61 var template = _.template(indexActionTemplate.defaultModal, {title:'Index Delete Failed!', res:str});62 $('#infoModal-loc').html(template);63 prettyPrint();64 $('#deleteindexmodal').modal('hide');65 $('#deleteindexmodal').on('hidden', function () {66 $('#defaultindexmodal').modal('show');67 $('#defaultindexmodal').on('hidden', function () {68 router.navigate("indices", true);69 });70 });71 }72 });73};74indexRoute.openIndex = function (indexId) {75 var indexModel = new IndexModel({connectionRootURL:cluster.get("connectionRootURL"), indexId:indexId, cmd:'_open'});76 indexModel.save({}, {77 success:function (model, response) {78 var str = JSON.stringify(response, undefined, 2);79 var template = _.template(indexActionTemplate.defaultModal, {title:'Index Opened for Business!', res:str});80 $('#infoModal-loc').html(template);81 prettyPrint();82 $('#defaultindexmodal').modal('show');83 var clusterState = cluster.get("clusterState");84 clusterState.fetch({85 success:function () {86 $('#defaultindexmodal').on('hidden', function () {87 router.navigate("indices", true);88 });89 }90 });91 },92 error:function (model, response, options) {93 var str = JSON.stringify(response, undefined, 2);94 var template = _.template(indexActionTemplate.defaultModal, {title:'Index Open Failed!', res:str});95 $('#infoModal-loc').html(template);96 prettyPrint();97 $('#defaultindexmodal').modal('show');98 $('#defaultindexmodal').on('hidden', function () {99 router.navigate("indices", true);100 });101 }102 });103};104indexRoute.closeIndex = function (indexId) {105 var indexModel = new IndexModel({connectionRootURL:cluster.get("connectionRootURL"), indexId:indexId, cmd:'_close'});106 indexModel.save({}, {107 success:function (model, response) {108 var str = JSON.stringify(response, undefined, 2);109 var template = _.template(indexActionTemplate.defaultModal, {title:'Index Closed!', res:str});110 $('#infoModal-loc').html(template);111 prettyPrint();112 $('#defaultindexmodal').modal('show');113 var clusterState = cluster.get("clusterState");114 clusterState.fetch({115 success:function () {116 $('#defaultindexmodal').on('hidden', function () {117 router.navigate("indices", true);118 });119 }120 });121 },122 error:function (model, response, options) {123 var str = JSON.stringify(response, undefined, 2);124 var template = _.template(indexActionTemplate.defaultModal, {title:'Index Close Failed!', res:str});125 $('#infoModal-loc').html(template);126 prettyPrint();127 $('#defaultindexmodal').modal('show');128 $('#defaultindexmodal').on('hidden', function () {129 router.navigate("indices", true);130 });131 }132 });133};134indexRoute.flushIndex = function (indexId) {135 var indexModel = new IndexModel({connectionRootURL:cluster.get("connectionRootURL"), indexId:indexId, cmd:'_flush'});136 indexModel.fetch({137 success:function (model, response) {138 var str = JSON.stringify(response, undefined, 2);139 var template = _.template(indexActionTemplate.defaultModal, {title:'Index Flushed!', res:str});140 $('#infoModal-loc').html(template);141 prettyPrint();142 $('#defaultindexmodal').modal('show');143 },144 error:function (model, response, options) {145 var str = JSON.stringify(response, undefined, 2);146 var template = _.template(indexActionTemplate.defaultModal, {title:'Index Flush Failed!', res:str});147 $('#infoModal-loc').html(template);148 prettyPrint();149 $('#defaultindexmodal').modal('show');150 }151 });152};153indexRoute.refreshIndex = function (indexId) {154 var indexModel = new IndexModel({connectionRootURL:cluster.get("connectionRootURL"), indexId:indexId, cmd:'_refresh'});155 indexModel.fetch({156 success:function (model, response) {157 var str = JSON.stringify(response, undefined, 2);158 var template = _.template(indexActionTemplate.defaultModal, {title:'Index Refreshed!', res:str});159 $('#infoModal-loc').html(template);160 prettyPrint();161 $('#defaultindexmodal').modal('show');162 },163 error:function (model, response, options) {164 var str = JSON.stringify(response, undefined, 2);165 var template = _.template(indexActionTemplate.defaultModal, {title:'Index Refresh Failed!', res:str});166 $('#infoModal-loc').html(template);167 prettyPrint();168 $('#defaultindexmodal').modal('show');169 }170 });171};172indexRoute.optimizeIndex = function (indexId) {173 var indexModel = new IndexModel({connectionRootURL:cluster.get("connectionRootURL"), indexId:indexId, cmd:'_optimize'});174 indexModel.fetch({175 success:function (model, response) {176 var str = JSON.stringify(response, undefined, 2);177 var template = _.template(indexActionTemplate.defaultModal, {title:'Index Optimized!', res:str});178 $('#infoModal-loc').html(template);179 prettyPrint();180 $('#defaultindexmodal').modal('show');181 },182 error:function (model, response, options) {183 var str = JSON.stringify(response, undefined, 2);184 var template = _.template(indexActionTemplate.defaultModal, {title:'Index Optimization Failed!', res:str});185 $('#infoModal-loc').html(template);186 prettyPrint();187 $('#defaultindexmodal').modal('show');188 }189 });190};191indexRoute.clearCacheIndex = function (indexId) {192 var indexModel = new IndexModel({connectionRootURL:cluster.get("connectionRootURL"), indexId:indexId, cmd:'_cache/clear'});193 indexModel.fetch({194 success:function (model, response) {195 var str = JSON.stringify(response, undefined, 2);196 var template = _.template(indexActionTemplate.defaultModal, {title:'Index Cache Cleared!', res:str});197 $('#infoModal-loc').html(template);198 prettyPrint();199 $('#defaultindexmodal').modal('show');200 },201 error:function (model, response, options) {202 var str = JSON.stringify(response, undefined, 2);203 var template = _.template(indexActionTemplate.defaultModal, {title:'Clear Cache Failed!', res:str});204 $('#infoModal-loc').html(template);205 prettyPrint();206 $('#defaultindexmodal').modal('show');207 }208 });...
ClusterHealthView.js
Source:ClusterHealthView.js
1/*2 Copyright 2013 Roy Russo3 Licensed under the Apache License, Version 2.0 (the "License");4 you may not use this file except in compliance with the License.5 You may obtain a copy of the License at6 http://www.apache.org/licenses/LICENSE-2.07 Unless required by applicable law or agreed to in writing, software8 distributed under the License is distributed on an "AS IS" BASIS,9 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.10 See the License for the specific language governing permissions and11 limitations under the License.12 Latest Builds: https://github.com/royrusso/elasticsearch-HQ13 */14/**15 Following the backbone vernacular. This obj simply handles the draw on the upper main screen.16 */17var ClusterHealthView = Backbone.View.extend({18 initialize:function (args) {19 this.stateModel = args.stateModel;20 this.indexModel = args.indexModel;21 },22 events:{23 "click #clusterHealthButton":"clicked"24 },25 clicked:function (e) {26 this.renderWorkspace();27 },28 renderWorkspace:function () {29 var clusterHealth = this.model;30 if (this.stateModel === undefined) {31 this.stateModel = cluster.get("clusterState");32 }33 if (this.indexModel === undefined) {34 this.indexModel = cluster.get("indexStats");35 }36 var indices = {};37 indices.shards = this.indexModel.get('_shards');38 if (jQuery.isEmptyObject(this.indexModel.get('_all'))) {39 indices.docs = {};40 }41 else {42 indices.docs = this.indexModel.get('_all').primaries.docs;43 }44 if (indices.docs === undefined) {45 indices.docs = {};46 indices.docs.count = 0;47 }48 indices.store = this.indexModel.get('_all').primaries.store;49 if (indices.store === undefined) {50 indices.store = {};51 indices.store.size = 0;52 indices.store.size_in_bytes = 0;53 }54 var indexKeys = _.keys(this.indexModel.get('indices'));55 if (indexKeys !== undefined) {56 indices.count = indexKeys.length;57 }58 else {59 indices.count = 0;60 }61 var metaIndices = this.stateModel.get('metadata').indices.twitter;62 var indexValues = _.values(this.indexModel.get('indices'));63 for (var i = 0; i < indexKeys.length; i++) {64 indexValues[i].id = indexKeys[i];65 }66 indices.indices = [];67 for (var $i = 0; $i < indexValues.length; $i++) {68 var index = indexValues[$i];69 index.name = index.id;70 if (versionUtil.isNewer("0.99.0", cluster.versionNumber.concat)) {71 index.numshards = this.stateModel.get('metadata').indices[index.id].settings.index.number_of_shards;72 index.numreplicas = this.stateModel.get('metadata').indices[index.id].settings.index.number_of_replicas;73 }74 else {75 index.numshards = this.stateModel.get('metadata').indices[index.id].settings['index.number_of_shards'];76 index.numreplicas = this.stateModel.get('metadata').indices[index.id].settings['index.number_of_replicas'];77 }78 index.status = this.stateModel.get('metadata').indices[index.id].state;79 if (index.docs === undefined) {80 index.docs = {num_docs:0};81 }82 indices.indices.push(index);83 }84 var template = _.template(clusterTemplate.HealthDescribe, {85 health:clusterHealth.attributes,86 state:this.stateModel,87 indices:indices,88 polling:settingsModel.get('settings').poller.cluster,89 lastUpdateTime:timeUtil.lastUpdated()90 });91 $('#workspace').html(template);92 $("[rel=tipRight]").tooltip();93 return this;94 },95 render:function () {96 var clusterHealth = this.model;97 console.log('Drawing clusterHealth ' + clusterHealth.get('cluster_name'));98 if (clusterHealth) {99 var status = clusterHealth.get('status');100 if (status == 'yellow') {101 clusterHealth.set({statusClass:'warning'});102 clusterHealth.set({statusClassLabel:'warning'});103 clusterHealth.set({statusText:'Yellow'});104 }105 else if (status == 'green') {106 clusterHealth.set({statusClass:'success'});107 clusterHealth.set({statusClassLabel:'success'});108 clusterHealth.set({statusText:'Green'});109 }110 else if (status == 'red') {111 clusterHealth.set({statusClass:'danger'});112 clusterHealth.set({statusClassLabel:'important'});113 clusterHealth.set({statusText:'Red'});114 }115 var t = _.template(clusterTemplate.Health);116 $(this.el).html(t(clusterHealth.attributes));117 //this.renderWorkspace();118 $("[rel=popRight]").popover({});119 }120 return this;121 },122 stateModel:undefined...
dataDictionaryController.js
Source:dataDictionaryController.js
1const ColumnModel = require('../model/columnModel');2const IndexModel = require('../model/indexModel');3const RolesModel = require('../model/roleModel');4const RankModel = require('../model/rankModel');5const DataDictionaryService = require('../service/dataDictionaryService.js');6class DataDictionaryController {7 constructor() {8 this.columnModel = new ColumnModel();9 this.indexModel = new IndexModel();10 this.dataDictionaryService = new DataDictionaryService();11 }12 async columnController(req, res, next) {13 var param = req.query, 14 direction = 'asc', 15 orderBy= 'gmt_create';16 this.columnModel.setTableName(param.table_name);17 this.columnModel.setService(param.service);18 this.columnModel.setStartTime(param.starttime);19 this.columnModel.setOwner(param.owner);20 this.columnModel.setEndTime(param.endtime);21 if(param.sort) {22 direction = param.sort.startsWith('-') ? 'asc' : 'desc';23 orderBy = param.sort.slice(1);24 }25 this.columnModel.setDirection(direction);26 this.columnModel.setOrderBy(orderBy);27 if(param.start && param.limit) {28 this.columnModel.setStart(Number(param.start));29 this.columnModel.setLimit(Number(param.limit));30 }31 let list = await this.dataDictionaryService.queryColumnList(this.columnModel, next);32 let total= await this.dataDictionaryService.queryColumnCount(this.columnModel, next);33 return res.json({34 status: 200,35 error_code: 200,36 data: list,37 total: total,38 })39 }40 async indexController(req, res, next) {41 var param = req.query, 42 direction = 'asc', 43 orderBy= 'gmt_create';44 this.indexModel.setService(param.service);45 this.indexModel.setOwner(param.owner);46 this.indexModel.setTableName(param.table_name);47 this.indexModel.setStartTime(param.starttime);48 this.indexModel.setEndTime(param.endtime);49 if(param.sort) {50 direction = param.sort.startsWith('-') ? 'asc' : 'desc';51 orderBy = param.sort.slice(1);52 }53 this.indexModel.setDirection(direction);54 this.indexModel.setOrderBy(orderBy);55 if(param.start && param.limit) {56 this.indexModel.setStart(Number(param.start));57 this.indexModel.setLimit(Number(param.limit));58 }59 let list = await this.dataDictionaryService.queryIndexList(this.indexModel, next);60 let total= await this.dataDictionaryService.queryIndexCount(this.indexModel, next);61 return res.json({62 status: 200,63 error_code: 200,64 data: list,65 total: total,66 })67 }68 async userRolesListController(req, res, next) {69 var param = req.query, 70 direction = 'asc', 71 orderBy= 'gmt_create';72 this.rolesModel.setId(param.id);73 this.rolesModel.setOwner(param.owner);74 this.rolesModel.setName(param.name);75 this.rolesModel.setStartTime(param.starttime);76 this.rolesModel.setEndTime(param.endtime);77 if(param.sort) {78 direction = param.sort.startsWith('-') ? 'asc' : 'desc';79 orderBy = param.sort.slice(1);80 }81 this.rolesModel.setDirection(direction);82 this.rolesModel.setOrderBy(orderBy);83 if(param.start && param.limit) {84 this.rolesModel.setStart(Number(param.start));85 this.rolesModel.setLimit(Number(param.limit));86 }87 let list = await this.userService.queryRolesList(this.rolesModel, next);88 let total= await this.userService.queryRolesCount(this.rolesModel, next);89 return res.json({90 status: 200,91 error_code: 200,92 data: list,93 total: total,94 })95 }96 async userRankListController(req, res, next) {97 var param = req.query, 98 direction = 'asc', 99 orderBy= 'last_time';100 this.rankModel.setId(param.id);101 this.rankModel.setUserName(param.user_name);102 this.rankModel.setStartTime(param.starttime);103 this.rankModel.setEndTime(param.endtime);104 if(param.sort) {105 direction = param.sort.startsWith('-') ? 'asc' : 'desc';106 orderBy = param.sort.slice(1);107 }108 this.rankModel.setDirection(direction);109 this.rankModel.setOrderBy(orderBy);110 if(param.start && param.limit) {111 this.rankModel.setStart(Number(param.start));112 this.rankModel.setLimit(Number(param.limit));113 }114 let list = await this.userService.queryRankList(this.rankModel, next);115 let total= await this.userService.queryRankCount(this.rankModel, next);116 return res.json({117 status: 200,118 error_code: 200,119 data: list,120 total: total,121 })122 }123}...
brandsModel.js
Source:brandsModel.js
1var brandsModel = { 2 birthdays: ko.observableArray(),3 products: [],4 pageNo: 1,5 init: function(data){6 try{7 brandsModel.birthdays = (indexModel.birthdays && indexModel.birthdays.length>0) ? indexModel.birthdays : [];8 9 for(var i=0; i<data.length; i++){10 (data[i].image_path.indexOf('http') == -1) ? data[i].image_path = app.app_URL.DOMAIN+data[i].image_path : '';11 }12 indexModel.brands(data);13 }14 catch(e){15 console.log(e.message);16 }17 },18 isEven: ko.computed(function(index){19 return (brandsModel && indexModel.brands().length%2 != 0 && index == indexModel.brands().length-1) ? true : false;20 }),21 bdayFriends: ko.computed(function(){22 return (brandsModel && brandsModel.birthdays().length > 0) ? brandsModel.birthdays().toString() : '';23 }), 24 onStoreChange: function(){25 if(indexModel.user_details().store){26 indexModel.user_details().storeDesc = $$('.store select option[value="'+indexModel.user_details().store+'"]').text();27 indexModel.user_details.valueHasMutated();28 var obj = {29 city: 0,30 store: indexModel.user_details().store31 };32 serviceFacade.makeServiceCall(brandsModel.reloadBrands, {url: 'BRANDS', data: obj});33 }34 },35 reloadBrands: function(data){36 brandsModel.init(data.Data);37 },38 onCityChange: function(){39 if(indexModel.user_details().city){ 40 indexModel.user_details().cityDesc = $$('.city select option[value="'+indexModel.user_details().city+'"]').text(); 41 var obj = {42 city: indexModel.user_details().city43 }; 44 indexModel.locations().stores = [];45 indexModel.user_details().store = '';46 indexModel.brands([]);47 indexModel.locations.valueHasMutated();48 indexModel.user_details.valueHasMutated();49 serviceFacade.makeServiceCall(brandsModel.updateLocation, {url: 'STORES', data: obj}, 'store');50 }51 },52 updateLocation: function(data){53 indexModel.locations().stores = data.Data;54 indexModel.locations.valueHasMutated();55 brandsModel.getBrands();56 }, 57 getBrands: function(){58 var obj = {59 city: indexModel.user_details().city,60 store: 061 };62 serviceFacade.makeServiceCall(brandsModel.reloadBrands, {url: 'BRANDS', data: obj});63 },64 brandDetails: function(data, event){65 /*var brand_id = data.brand_id,66 brand_name = data.brand_name,67 favourites = utils.getFavourites();68 data.pageNo = brandsModel.pageNo; 69 data.isReset = true;70 data.action = 'brand';71 indexModel.getProducts(data, brandsModel.showProducts);*/72 indexModel.resetPaginationParams();73 indexModel.paginationParams.brand_id = data.brand_id;74 indexModel.paginationParams.brand_name = data.brand_name;75 indexModel.paginationParams.sort_by = 'name';76 indexModel.paginationParams.sort_type = 'asc';77 indexModel.getAllProducts(brandsModel.showProducts);78 }, 79 showProducts: function(data, brand_info){80 if(data.Data){81 //data.brand_info = brand_info;82 //brandsModel.products = data;83 mainView.router.loadPage('html/products.html');84 }85 } 86};87var brandspage = myApp.onPageInit('brands', function (page) {88 //if(indexModel.brands().length == 0){89 ko.applyBindings(brandsModel, document.getElementById('brands')); 90 brandsModel.init(indexModel.brandsData);91 //}...
index.controller.js
Source:index.controller.js
1var Index = require("./../models/index.model");2var message = require("./../utils/message");34module.exports = {5 getAllIndex: getAllIndex,6 getIndex: getIndex,7 createIndex: createIndex,8 updateIndex: updateIndex9};1011function getAllIndex() {12 return new Promise((resolve, reject) => {13 Index.find({}).exec(function(err, indexes) {14 if (err) {15 reject(err);16 } else {17 resolve(indexes);18 }19 });20 });21}2223function getIndex(request) {24 return new Promise((resolve, reject) => {25 Index.findOne({26 col: request.col,27 row: request.row28 }).exec(function(err, indexModel) {29 if (err) {30 reject(err);31 } else {32 if (!indexModel) {33 reject({34 statusCode: 404,35 message: message.ERROR_MESSAGE.INDEX.NOT_FOUND36 });37 } else {38 resolve(indexModel);39 }40 }41 });42 });43}4445function createIndex(request) {46 return new Promise((resolve, reject) => {47 Index.findOne({ col: request.col, row: request.row }).exec(48 (err, indexModel) => {49 if (err) {50 reject(err);51 } else {52 if (!indexModel) {53 reject({54 statusCode: 404,55 message: message.ERROR_MESSAGE.INDEX.NOT_FOUND56 });57 } else {58 if (indexModel.status === 1) {59 reject({60 statusCode: 400,61 message: message.ERROR_MESSAGE.INDEX.EXIST62 });63 } else {64 indexModel.companyName = request.companyName;65 indexModel.status = request.status;66 indexModel.rentedDate = request.rentedDate;67 indexModel.expirationDate = request.expirationDate;68 indexModel.renter = request.renter;69 indexModel.carNumber = request.carNumber;70 indexModel.save((err, response) => {71 if (err) reject(err);72 else {73 resolve(response);74 }75 });76 }77 }78 }79 }80 );81 });82}8384function updateIndex(request) {85 return new Promise((resolve, reject) => {86 Index.findOne({ col: request.col, row: request.row }).exec(87 (err, indexModel) => {88 if (err) {89 reject(err);90 } else {91 if (!indexModel) {92 reject({93 statusCode: 404,94 message: message.ERROR_MESSAGE.INDEX.NOT_FOUND95 });96 } else {97 if (indexModel.status === 0) {98 reject({99 statusCode: 404,100 message: message.ERROR_MESSAGE.INDEX.EMPTY101 });102 } else {103 indexModel.companyName = request.companyName;104 indexModel.status = request.status;105 indexModel.rentedDate = request.rentedDate;106 indexModel.expirationDate = request.expirationDate;107 indexModel.renter = request.renter;108 indexModel.carNumber = request.carNumber;109 indexModel.save((err, response) => {110 if (err) reject(err);111 else {112 resolve(response);113 }114 });115 }116 }117 }118 }119 );120 });
...
index.js
Source:index.js
1const express = require('express')2const router = express.Router()3const indexModel = require('../model/indexModel')4const { checkSignature } = require('../utils/wxUtils')5// login6router.post('/login', (req, res) => {7 indexModel.login(req, res)8})9// version10router.get('/version', (req, res) => {11 indexModel.findAllVersion(req, res)12})13router.post('/version', (req, res) => {14 indexModel.releaseNewVersion(req, res)15})16router.put('/version', (req, res) => {17 indexModel.editVersion(req, res)18})19router.delete('/version/:version_info', (req, res) => {20 indexModel.delVersion(req, res)21})22router.get('/version/:version_info', (req, res) => {23 indexModel.findVersion(req, res)24})25// wx push26router.get('/wxmessage', (req, res) => {27 checkSignature(req, res)28})29// colorful eggs30router.get('/config', (req, res) => {31 indexModel.getColorfulEggs(req, res)32})33router.post('/config', (req, res) => {34 indexModel.addColorfulEggs(req, res)35})36// event37router.get('/:user_id/events', (req, res) => {38 indexModel.findAllEventsByUserId(req, res)39})40router.post('/:user_id/events', (req, res) => {41 indexModel.addEvents(req, res)42})43router.put('/:user_id/events', (req, res) => {44 indexModel.editEvents(req, res)45})46router.delete('/:user_id/events/:event_id', (req, res) => {47 indexModel.delEvent(req, res)48})49router.get('/:user_id/events/:event_id', (req, res) => {50 indexModel.findEventByEventId(req, res)51})52router.get('/:user_id/statistics', (req, res) => {53 indexModel.eventStatistics(req, res)54})55// task56router.get('/:event_id/tasks', (req, res) => {57 indexModel.findAllTasksByEventId(req, res)58})59router.post('/:event_id/tasks', (req, res) => {60 indexModel.addTask(req, res)61})62router.put('/:event_id/tasks', (req, res) => {63 indexModel.editTask(req, res)64})65router.delete('/:event_id/tasks/:task_id', (req, res) => {66 indexModel.delTask(req, res)67})68router.get('/:event_id/tasks/:task_id', (req, res) => {69 indexModel.findTaskByTaskId(req, res)70})71// punch72router.get('/:user_id/punch', (req, res) => {73 indexModel.findAllPunch(req, res)74})75router.post('/:user_id/punch', (req, res) => {76 indexModel.addPunch(req, res)77})78router.put('/:user_id/punch', (req, res) => {79 indexModel.editPunch(req, res)80})81router.delete('/:user_id/punch/:punch_id', (req, res) => {82 indexModel.delPunch(req, res)83})84router.get('/:user_id/punch/:punch_id', (req, res) => {85 indexModel.findPunchById(req, res)86})87// countdown88router.get('/:user_id/countdown', (req, res) => {89 indexModel.findAllCountdown(req, res)90})91router.post('/:user_id/countdown', (req, res) => {92 indexModel.addCountdown(req, res)93})94router.put('/:user_id/countdown', (req, res) => {95 indexModel.editCountdown(req, res)96})97router.delete('/:user_id/countdown/:countdown_id', (req, res) => {98 indexModel.delCountdown(req, res)99})100router.get('/:user_id/countdown/:countdown_id', (req, res) => {101 indexModel.findCountdownById(req, res)102})103// werun104router.post('/:user_id/werun', (req, res) => {105 indexModel.weRun(req, res)106})107router.get('/:user_id/werun/:year', (req, res) => {108 indexModel.weRunEachYear(req, res)109})110router.get('/:user_id/werun/:year/:month', (req, res) => {111 indexModel.weRunEachMonth(req, res)112})113// tools data overview114router.get('/:user_id/tools_data_overview', (req, res) => {115 indexModel.toolsDataOverview(req, res)116})...
DslCollectionModel.js
Source:DslCollectionModel.js
1/*2* Name : DslCollectionModel.js3* Module : Back-end::Lib::Model::DSLModel4* Location : /lib/model/dslmodel/5*6* History :7* 8* Version Date Programmer9* =================================================10* 0.0.1 2014-03-01 Giacomo Fornari11* -------------------------------------------------12* Codifica modulo13* =================================================14* 0.0.2 2014-03-01 Luca De Franceschi15* -------------------------------------------------16* Incremento metodi17* =================================================18*/19"use strict";20var AttributeReader = require("../../utils/AttributeReader");21var DocumentSchema = require("./DocumentSchema");22var ShowModel = require("./ShowModel");23var IndexModel = require("./IndexModel");24var MaapError = require("../../utils/MaapError");25var DslCollectionModel = function(dslDomain, params) {26 var self = this;27 this.dslDomain = dslDomain;28 29 // Valori di default30 this.weight = 0;31 this.showModel = new ShowModel(this, {});32 this.indexModel = new IndexModel(this, {});33 34 // Leggi i parametri obbligatori e opzionali35 AttributeReader.readRequiredAttributes(params, this, ["name"], function(param){36 throw new MaapError(8000, "Required parameter '" + param + "' in collection '" + self.toString() + "'");37 });38 AttributeReader.readOptionalAttributes(params, this, ["id", "label", "weight"]);39 AttributeReader.assertEmptyAttributes(params, function(param){40 throw new MaapError(8000, "Unexpected parameter '" + param + "' in collection '" + self.toString() + "'");41 });42 43 // Valori di default44 if (this.id === undefined) {45 this.id = this.name;46 }47 if (this.label === undefined) {48 var label = this.name.toLowerCase();49 this.label = label.substring(0,1).toUpperCase() + label.substring(1);50 }51 if (this.weight === undefined) {52 this.weight = 0;53 }54 // Verifiche55 if (!this.id.match( /^[a-z0-9-]+$/i )) {56 throw new MaapError(8001, "The collection id '"+this.id+"' must contain only alphabetic characters, digits and minus. It can not be empty");57 }58 59 this.docModel = this.dslDomain.db.model(this.name, DocumentSchema);60};61DslCollectionModel.prototype.getId = function() {62 return this.id;63};64DslCollectionModel.prototype.getName = function() {65 return this.name;66};67DslCollectionModel.prototype.getLabel = function() {68 return this.label;69};70DslCollectionModel.prototype.getWeight = function() {71 return this.weight;72};73DslCollectionModel.prototype.getIndexModel = function() {74 return this.indexModel;75};76DslCollectionModel.prototype.getShowModel = function() {77 return this.showModel;78};79DslCollectionModel.prototype.setIndexModel = function(indexModel) {80 this.indexModel = indexModel;81};82DslCollectionModel.prototype.setShowModel = function(showModel) {83 this.showModel = showModel;84};85DslCollectionModel.prototype.toString = function() {86 return this.getName();87};...
Using AI Code Generation
1const { indexModel } = require('@playwright/test');2const { indexModel } = require('@playwright/test');3const { indexModel } = require('@playwright/test');4const { indexModel } = require('@playwright/test');5const { indexModel } = require('@playwright/test');6const { indexModel } = require('@playwright/test');7const { test, expect } = require('@playwright/test');8test('test', async ({ page }) => {9 const title = page.locator('.navbar__inner .navbar__title');10 await expect(title).toHaveText('Playwright');11});12const { indexModel } = require('@playwright/test');13const { indexModel } = require('@playwright/test');14const { indexModel } = require('@playwright/test');15const { indexModel } = require('@playwright/test');16const { indexModel } = require('@playwright/test');17const { indexModel } = require('@playwright/test');18const { indexModel } = require('@playwright/test');19const { indexModel } = require('@playwright/test');20const { indexModel } = require('@playwright/test');21const { indexModel } = require('@playwright/test');22const { indexModel } = require('@playwright/test');
Using AI Code Generation
1const {indexModel} = require('playwright-internal');2const {Page} = require('playwright');3const {indexModel} = require('playwright-internal');4const {Page} = require('playwright');5const {indexModel} = require('playwright-internal');6const {Page} = require('playwright');7const {indexModel} = require('playwright-internal');8const {Page} = require('playwright');9const {indexModel} = require('playwright-internal');10const {Page} = require('playwright');11const {indexModel} = require('playwright-internal');12const {Page} = require('playwright');13const {indexModel} = require('playwright-internal');14const {Page} = require('playwright');15const {indexModel} = require('playwright-internal');16const {Page} = require('playwright');17const {indexModel} = require('playwright-internal');18const {Page} = require('playwright');19const {indexModel} = require('playwright-internal');20const {Page} = require('playwright');21const {indexModel} = require('playwright-internal');22const {Page} = require('playwright');23const {indexModel} = require('playwright-internal');24const {Page} = require('playwright');25const {indexModel} = require('playwright-internal');26const {Page} = require('playwright');27const {indexModel} = require('playwright-internal');28const {Page} = require('playwright');29const {indexModel} = require('
Using AI Code Generation
1const { indexModel } = require('playwright');2const { chromium } = require('playwright-chromium');3const browser = await chromium.launch();4const page = await browser.newPage();5await indexModel(page, 'foo');6await browser.close();7const { indexModel } = require('playwright');8const { chromium } = require('playwright-chromium');9const browser = await chromium.launch();10const page = await browser.newPage();11await indexModel(page, 'foo');12await browser.close();13const { indexModel } = require('playwright');14const { chromium } = require('playwright-chromium');15const browser = await chromium.launch();16const page = await browser.newPage();17await indexModel(page, 'foo');18await browser.close();19const { indexModel } = require('playwright');20const { chromium } = require('playwright-chromium');21const browser = await chromium.launch();22const page = await browser.newPage();23await indexModel(page, 'foo');24await browser.close();25const { indexModel } = require('playwright');26const { chromium } = require('playwright-chromium');27const browser = await chromium.launch();28const page = await browser.newPage();29await indexModel(page, 'foo');30await browser.close();31const { indexModel } = require('playwright');32const { chromium } = require('playwright-chromium');33const browser = await chromium.launch();34const page = await browser.newPage();35await indexModel(page, 'foo');36await browser.close();37const { indexModel } = require('playwright');38const { chromium } = require('playwright-chromium');39const browser = await chromium.launch();40const page = await browser.newPage();41await indexModel(page, 'foo');42await browser.close();43const { indexModel } = require('playwright');44const { chromium
Using AI Code Generation
1const { indexModel } = require('playwright-chromium/lib/server/chromium/crPage');2(async () => {3 const {page} = await browser.newPage();4 const model = await indexModel(page);5 console.log(model);6})();
Using AI Code Generation
1const { indexModel } = require('@playwright/test');2const { test, expect } = require('@playwright/test');3test('test', async ({ page }) => {4 await page.click('text=Get Started');5 const index = await indexModel(page, 'text=Get Started');6 expect(index).toBe(0);7});8 at Object.<anonymous> (test.js:9:13)9 at Object.<anonymous> (test.js:10:13)10 at Object.<anonymous> (test.js:11:13)11 at Object.<anonymous> (test.js:12:13)12 at Object.<anonymous> (test.js:13:13)13 at Object.<anonymous> (test.js:14:13)14 at Object.<anonymous> (test.js:15:13)15 at Object.<anonymous> (test.js:16:13)16 at Object.<anonymous> (test.js:17:13)17 at Object.<anonymous> (test.js:18:13)18 at Object.<anonymous> (test.js:19:13)19 at Object.<anonymous> (test.js:20:13)20 at Object.<anonymous> (test.js:21:13)21 at Object.<anonymous> (test.js:22:13)22 at Object.<anonymous> (test.js:23:13)23 at Object.<anonymous> (test.js:24:13)24 at Object.<anonymous> (test.js:25:13)25 at Object.<anonymous> (test.js:
Using AI Code Generation
1const indexModel = require('@playwright/test/lib/indexModel');2const model = indexModel();3const testName = model.testInfo.name;4console.log(testName);5const { test } = require('@playwright/test');6test.describe('My test suite', () => {7 test('My test', async ({ page }) => {8 });9});
LambdaTest’s Playwright tutorial will give you a broader idea about the Playwright automation framework, its unique features, and use cases with examples to exceed your understanding of Playwright testing. This tutorial will give A to Z guidance, from installing the Playwright framework to some best practices and advanced concepts.
Get 100 minutes of automation test minutes FREE!!