1 define([], function () {
4 angular.module('app.yangman').controller('YMListCtrl', YMListCtrl);
6 YMListCtrl.$inject = ['$scope', 'ListFilteringService', 'NodeWrapperService', 'constants'];
8 function YMListCtrl($scope, ListFilteringService, NodeWrapperService, constants){
11 $scope.actElement = null;
12 $scope.showListFilter = false;
13 $scope.filterListHover = 0;
14 yangList.constants = constants;
15 yangList.currentDisplayIndex = 1;
16 yangList.displayOffsets = [-1, 0, 1];
19 $scope.activeFilter = activeFilter;
20 $scope.applyFilter = applyFilter;
21 $scope.clearFilterData = clearFilterData;
22 $scope.createNewFilter = createNewFilter;
23 $scope.getFilterData = getFilterData;
24 $scope.showListFilterWin = showListFilterWin;
25 $scope.showModalWin = showModalWin;
26 $scope.switchFilter = switchFilter;
28 yangList.addListElem = addListElem;
29 yangList.getListName = getListName;
31 yangList.isActionMenu = isActionMenu;
32 yangList.removeListElem = removeListElem;
33 yangList.shiftDisplayNext = shiftDisplayNext;
34 yangList.shiftDisplayPrev = shiftDisplayPrev;
35 yangList.showNextButton = showNextButton;
36 yangList.showPrevButton = showPrevButton;
37 yangList.toggleExpanded = toggleExpanded;
40 $scope.$on(constants.EV_REFRESH_LIST_INDEX, function () {
41 yangList.currentDisplayIndex = 1;
44 $scope.$on(constants.YANGMAN_DISABLE_ADDING_LIST_ELEMENT, function() {
49 * Disable adding more then one element
52 yangList.disableAddingListElement = $scope.checkAddingListElement($scope.node);
54 if(yangList.disableAddingListElement &&
55 !$scope.node.listData.length &&
56 $scope.selectedDatastore.label === constants.DATA_STORE_CONFIG) {
58 yangList.addListElem();
61 if (!$scope.node.listData.length) {
62 yangList.currentDisplayIndex = 1;
67 * Add element into list
69 function addListElem() {
70 $scope.showListFilter = false;
71 $scope.showModal = false;
72 ListFilteringService.removeEmptyFilters($scope.node);
73 $scope.node.addListElem();
76 // TODO :: do method description
77 function removeListElem(elemIndex, fromFilter) {
78 $scope.node.removeListElem(elemIndex, fromFilter);
80 yangList.currentDisplayIndex =
81 Math.max(Math.min(yangList.currentDisplayIndex, $scope.node.listData.length - 2), 1);
82 if ($scope.node.listData.length === 0) {
83 $scope.$broadcast('hideInfoBox');
87 // TODO :: do method description
88 function toggleExpanded() {
89 $scope.node.expanded = !$scope.node.expanded;
92 // TODO :: do method description
93 function shiftDisplayNext(typeListData) {
94 yangList.currentDisplayIndex = Math.min(yangList.currentDisplayIndex + 3, $scope.node[typeListData].length - 2);
97 // TODO :: do method description
98 function shiftDisplayPrev() {
99 yangList.currentDisplayIndex = Math.max(yangList.currentDisplayIndex - 3, 1);
102 // TODO :: do method description
103 function showPrevButton() {
104 return yangList.currentDisplayIndex > 1;
107 // TODO :: do method description
108 function showNextButton(typeListData) {
109 // node is selected after view is loaded
110 return $scope.node[typeListData] && yangList.currentDisplayIndex < $scope.node[typeListData].length - 2;
113 // TODO :: do method description
114 function showModalWin() {
115 $scope.showModal = !$scope.showModal;
116 if ($scope.showListFilter){
117 $scope.showListFilter = !$scope.showListFilter;
121 // TODO :: do method description
122 function showListFilterWin() {
123 $scope.showListFilter = !$scope.showListFilter;
124 if ($scope.showModal){
125 $scope.showModal = !$scope.showModal;
127 ListFilteringService.showListFilterWin($scope.filterRootNode,$scope.node);
130 // TODO :: do method description
131 function getFilterData() {
132 ListFilteringService.getFilterData($scope.node);
135 // TODO :: do method description
136 function switchFilter(showedFilter) {
137 ListFilteringService.switchFilter($scope.node, showedFilter);
140 // TODO :: do method description
141 function createNewFilter() {
142 ListFilteringService.createNewFilter($scope.node);
145 // TODO :: do method description
146 function applyFilter() {
147 ListFilteringService.applyFilter($scope.node);
148 $scope.showListFilter = !$scope.showListFilter;
149 yangList.currentDisplayIndex = 1;
150 if ($scope.node.filteredListData.length){
151 $scope.node.doubleKeyIndexes =
152 NodeWrapperService.checkKeyDuplicity($scope.node.filteredListData, $scope.node.refKey);
154 $scope.node.doubleKeyIndexes =
155 NodeWrapperService.checkKeyDuplicity($scope.node.listData, $scope.node.refKey);
159 // TODO :: do method description
160 function clearFilterData(changeAct, filterForClear, removeFilters) {
161 ListFilteringService.clearFilterData($scope.node, changeAct, filterForClear, removeFilters);
163 $scope.showListFilter = !$scope.showListFilter;
165 $scope.node.doubleKeyIndexes =
166 NodeWrapperService.checkKeyDuplicity($scope.node.listData, $scope.node.refKey);
169 // TODO :: do method description
170 function activeFilter(filter) {
171 if (filter.active === 1){
178 // TODO :: do method description
179 function getListName(offset, config) {
180 var createdListItemName = $scope.node.createListName(yangList.currentDisplayIndex + offset);
182 if ( createdListItemName.length > 33 ) {
184 name: createdListItemName.substring(0, 30) + '...',
185 tooltip: createdListItemName,
189 name: config ? createdListItemName || '[' + (yangList.currentDisplayIndex + offset) + ']' : createdListItemName,
196 * Show hide action menu
197 * @returns {boolean|*}
199 function isActionMenu() {