1 define([], function () {
4 angular.module('app.yangman').controller('ListCtrl', ListCtrl);
6 ListCtrl.$inject = ['$scope', 'ListFilteringService', 'NodeWrapperService', 'constants'];
8 function ListCtrl($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();
63 * Add element into list
65 function addListElem() {
66 $scope.showListFilter = false;
67 $scope.showModal = false;
68 ListFilteringService.removeEmptyFilters($scope.node);
69 $scope.node.addListElem();
72 // TODO :: do method description
73 function removeListElem(elemIndex, fromFilter) {
74 $scope.node.removeListElem(elemIndex, fromFilter);
76 yangList.currentDisplayIndex =
77 Math.max(Math.min(yangList.currentDisplayIndex, $scope.node.listData.length - 2), 1);
78 if ($scope.node.listData.length === 0) {
79 $scope.$broadcast('hideInfoBox');
83 // TODO :: do method description
84 function toggleExpanded() {
85 $scope.node.expanded = !$scope.node.expanded;
88 // TODO :: do method description
89 function shiftDisplayNext(typeListData) {
90 yangList.currentDisplayIndex = Math.min(yangList.currentDisplayIndex + 3, $scope.node[typeListData].length - 2);
93 // TODO :: do method description
94 function shiftDisplayPrev() {
95 yangList.currentDisplayIndex = Math.max(yangList.currentDisplayIndex - 3, 1);
98 // TODO :: do method description
99 function showPrevButton() {
100 return yangList.currentDisplayIndex > 1;
103 // TODO :: do method description
104 function showNextButton(typeListData) {
105 // node is selected after view is loaded
106 return $scope.node[typeListData] && yangList.currentDisplayIndex < $scope.node[typeListData].length - 2;
109 // TODO :: do method description
110 function showModalWin() {
111 $scope.showModal = !$scope.showModal;
112 if ($scope.showListFilter){
113 $scope.showListFilter = !$scope.showListFilter;
117 // TODO :: do method description
118 function showListFilterWin() {
119 $scope.showListFilter = !$scope.showListFilter;
120 if ($scope.showModal){
121 $scope.showModal = !$scope.showModal;
123 ListFilteringService.showListFilterWin($scope.filterRootNode,$scope.node);
126 // TODO :: do method description
127 function getFilterData() {
128 ListFilteringService.getFilterData($scope.node);
131 // TODO :: do method description
132 function switchFilter(showedFilter) {
133 ListFilteringService.switchFilter($scope.node, showedFilter);
136 // TODO :: do method description
137 function createNewFilter() {
138 ListFilteringService.createNewFilter($scope.node);
141 // TODO :: do method description
142 function applyFilter() {
143 ListFilteringService.applyFilter($scope.node);
144 $scope.showListFilter = !$scope.showListFilter;
145 yangList.currentDisplayIndex = 1;
146 if ($scope.node.filteredListData.length){
147 $scope.node.doubleKeyIndexes =
148 NodeWrapperService.checkKeyDuplicity($scope.node.filteredListData, $scope.node.refKey);
150 $scope.node.doubleKeyIndexes =
151 NodeWrapperService.checkKeyDuplicity($scope.node.listData, $scope.node.refKey);
155 // TODO :: do method description
156 function clearFilterData(changeAct, filterForClear, removeFilters) {
157 ListFilteringService.clearFilterData($scope.node, changeAct, filterForClear, removeFilters);
159 $scope.showListFilter = !$scope.showListFilter;
161 $scope.node.doubleKeyIndexes =
162 NodeWrapperService.checkKeyDuplicity($scope.node.listData, $scope.node.refKey);
165 // TODO :: do method description
166 function activeFilter(filter) {
167 if (filter.active === 1){
174 // TODO :: do method description
175 function getListName(offset, config) {
176 var createdListItemName = $scope.node.createListName(yangList.currentDisplayIndex + offset);
178 if ( createdListItemName.length > 33 ) {
180 name: createdListItemName.substring(0, 30) + '...',
181 tooltip: createdListItemName,
185 name: config ? createdListItemName || '[' + (yangList.currentDisplayIndex + offset) + ']' : createdListItemName,
192 * Show hide action menu
193 * @returns {boolean|*}
195 function isActionMenu() {