|
| 1 | +/* |
| 2 | + * Copyright 2015-2019 Jeeva Kandasamy ([email protected]) |
| 3 | + * and other contributors as indicated by the @author tags. |
| 4 | + * |
| 5 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | + * you may not use this file except in compliance with the License. |
| 7 | + * You may obtain a copy of the License at |
| 8 | + * |
| 9 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | + * |
| 11 | + * Unless required by applicable law or agreed to in writing, software |
| 12 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | + * See the License for the specific language governing permissions and |
| 15 | + * limitations under the License. |
| 16 | + */ |
| 17 | +myControllerModule.controller('ExportControllerList', function(alertService, $scope, $filter, displayRestError, ExportImportFactory, $filter, mchelper, CommonServices, $uibModal) { |
| 18 | + //GUI page settings |
| 19 | + $scope.headerStringList = $filter('translate')('EXPORTS_DETAIL'); |
| 20 | + $scope.noItemsSystemMsg = $filter('translate')('NO_EXPORTS_SETUP'); |
| 21 | + $scope.noItemsSystemIcon = "fa fa-upload"; |
| 22 | + |
| 23 | + //load empty, configuration, etc., |
| 24 | + $scope.mchelper = mchelper; |
| 25 | + $scope.filteredList=[]; |
| 26 | + |
| 27 | + //data query details |
| 28 | + $scope.currentPage = 1; |
| 29 | + $scope.query = CommonServices.getQuery(); |
| 30 | + $scope.queryResponse = {}; |
| 31 | + |
| 32 | + //Get min number |
| 33 | + $scope.getMin = function(item1, item2){ |
| 34 | + return CommonServices.getMin(item1, item2); |
| 35 | + }; |
| 36 | + |
| 37 | + //get all items |
| 38 | + $scope.getAllItems = function(){ |
| 39 | + ExportImportFactory.getAll($scope.query, function(response) { |
| 40 | + $scope.queryResponse = response; |
| 41 | + $scope.filteredList = $scope.queryResponse.data; |
| 42 | + $scope.filterConfig.resultsCount = $scope.queryResponse.query.filteredCount; |
| 43 | + },function(error){ |
| 44 | + $scope.queryResponse.$resolved = true; |
| 45 | + displayRestError.display(error); |
| 46 | + }); |
| 47 | + } |
| 48 | + |
| 49 | + |
| 50 | + //Hold all the selected item ids |
| 51 | + $scope.itemIds = []; |
| 52 | + |
| 53 | + $scope.selectAllItems = function(){ |
| 54 | + CommonServices.selectAllItems($scope, 'name'); |
| 55 | + }; |
| 56 | + |
| 57 | + $scope.selectItem = function(item){ |
| 58 | + CommonServices.selectItem($scope, item, 'name'); |
| 59 | + }; |
| 60 | + |
| 61 | + //On page change |
| 62 | + $scope.pageChanged = function(newPage){ |
| 63 | + CommonServices.updatePageChange($scope, newPage); |
| 64 | + }; |
| 65 | + |
| 66 | + //Filter change method |
| 67 | + var filterChange = function (filters) { |
| 68 | + //Reset filter fields and update items |
| 69 | + CommonServices.updateFiltersChange($scope, filters); |
| 70 | + }; |
| 71 | + |
| 72 | + $scope.filterConfig = { |
| 73 | + fields: [ |
| 74 | + { |
| 75 | + id: 'name', |
| 76 | + title: $filter('translate')('NAME'), |
| 77 | + placeholder: $filter('translate')('FILTER_BY_NAME'), |
| 78 | + filterType: 'text' |
| 79 | + } |
| 80 | + ], |
| 81 | + resultsCount: $scope.filteredList.length, |
| 82 | + appliedFilters: [], |
| 83 | + onFilterChange: filterChange |
| 84 | + }; |
| 85 | + |
| 86 | + //Sort columns [*** NOT IN USE ***] |
| 87 | + var sortChange = function (sortId, isAscending) { |
| 88 | + //Reset sort type and update items |
| 89 | + CommonServices.updateSortChange($scope, sortId, isAscending); |
| 90 | + }; |
| 91 | + |
| 92 | + $scope.sortConfig = { |
| 93 | + fields: [ |
| 94 | + { |
| 95 | + id: 'name', |
| 96 | + title: $filter('translate')('NAME'), |
| 97 | + sortType: 'text' |
| 98 | + } |
| 99 | + ], |
| 100 | + onSortChange: sortChange |
| 101 | + }; |
| 102 | + |
| 103 | + //Pre load |
| 104 | + $scope.disableRunExport = false; |
| 105 | + |
| 106 | + //Delete item(s) |
| 107 | + $scope.delete = function (size) { |
| 108 | + var modalInstance = $uibModal.open({ |
| 109 | + templateUrl: 'partials/common-html/delete-modal.html', |
| 110 | + controller: 'ControllerDeleteModal', |
| 111 | + size: size, |
| 112 | + resolve: {} |
| 113 | + }); |
| 114 | + |
| 115 | + modalInstance.result.then(function () { |
| 116 | + ExportImportFactory.deleteIds($scope.itemIds, function(response) { |
| 117 | + alertService.success($filter('translate')('ITEMS_DELETED_SUCCESSFULLY')); |
| 118 | + //Update display table |
| 119 | + $scope.getAllItems(); |
| 120 | + $scope.itemIds = []; |
| 121 | + },function(error){ |
| 122 | + displayRestError.display(error); |
| 123 | + }); |
| 124 | + }), |
| 125 | + function () { |
| 126 | + //console.log('Modal dismissed at: ' + new Date()); |
| 127 | + } |
| 128 | + }; |
| 129 | + |
| 130 | + //export now |
| 131 | + $scope.exportNow = function(){ |
| 132 | + $scope.disableRunExport = true; |
| 133 | + ExportImportFactory.exportNow({"rowLimit": 1000}, function(){ |
| 134 | + $scope.getAllItems(); |
| 135 | + alertService.success($filter('translate')('EXPORT_TRIGGERED_SUCCESSFULLY')); |
| 136 | + $scope.disableRunExport = false; |
| 137 | + },function(error){ |
| 138 | + displayRestError.display(error); |
| 139 | + $scope.disableRunExport = false; |
| 140 | + }); |
| 141 | + }; |
| 142 | + |
| 143 | + //Import |
| 144 | + $scope.importItemFn = function (size) { |
| 145 | + var addModalInstance = $uibModal.open({ |
| 146 | + templateUrl: 'partials/export/import-confirmation-modal.html', |
| 147 | + controller: 'ExportControllerImport', |
| 148 | + size: size, |
| 149 | + resolve: {fileName: function () {return {'name': $scope.itemIds[0]}}} |
| 150 | + }); |
| 151 | + |
| 152 | + addModalInstance.result.then(function () { |
| 153 | + ExportImportFactory.importNow({"fileName": $scope.itemIds[0]}, function(response) { |
| 154 | + alertService.success($filter('translate')('IMPORT_INITIATED_SUCCESSFULLY')+' '+response.message); |
| 155 | + },function(error){ |
| 156 | + displayRestError.display(error); |
| 157 | + }); |
| 158 | + }), |
| 159 | + function () { |
| 160 | + //console.log('Modal dismissed at: ' + new Date()); |
| 161 | + } |
| 162 | + }; |
| 163 | + |
| 164 | +}); |
| 165 | + |
| 166 | +//restore Modal |
| 167 | +myControllerModule.controller('ExportControllerImport', function ($scope, $uibModalInstance, $filter, fileName) { |
| 168 | + $scope.header = $filter('translate')('IMPORT_CONFIRMATION_TITLE', fileName); |
| 169 | + $scope.rebootMsg = $filter('translate')('IMPORT_CONFIRMATION_MESSAGE', fileName); |
| 170 | + $scope.importNow = function() {$uibModalInstance.close(); }; |
| 171 | + $scope.cancel = function () { $uibModalInstance.dismiss('cancel'); } |
| 172 | +}); |
| 173 | + |
| 174 | +//Automatice export settings |
| 175 | +myControllerModule.controller('ExportControllerAutoSettings', function ($scope, ExportImportFactory, mchelper, alertService, displayRestError, $filter, CommonServices) { |
| 176 | + $scope.mchelper = mchelper; |
| 177 | + $scope.item = {}; |
| 178 | + $scope.item.enabled = false; |
| 179 | + $scope.cs = CommonServices; |
| 180 | + |
| 181 | + $scope.resetSettings = function(){ |
| 182 | + ExportImportFactory.getSettings(function(response) { |
| 183 | + $scope.item = response; |
| 184 | + //Update dropdown |
| 185 | + if($scope.item.interval % 86400000 == 0){ |
| 186 | + $scope.intervalLocal = $scope.item.interval / 86400000; |
| 187 | + $scope.intervalTimeConstant = "86400000"; |
| 188 | + $scope.intervalTimeConstantString = $filter('translate')('DAYS'); |
| 189 | + }else if($scope.item.interval % 3600000 == 0){ |
| 190 | + $scope.intervalLocal = $scope.item.interval / 3600000; |
| 191 | + $scope.intervalTimeConstant = "3600000"; |
| 192 | + $scope.intervalTimeConstantString = $filter('translate')('Hours'); |
| 193 | + }else if($scope.item.interval % 60000 == 0){ |
| 194 | + $scope.intervalLocal = $scope.item.interval / 60000; |
| 195 | + $scope.intervalTimeConstant = "60000"; |
| 196 | + $scope.intervalTimeConstantString = $filter('translate')('Minutes'); |
| 197 | + } |
| 198 | + },function(error){ |
| 199 | + displayRestError.display(error); |
| 200 | + }); |
| 201 | + } |
| 202 | + |
| 203 | + //GUI page settings |
| 204 | + $scope.saveProgress = false; |
| 205 | + |
| 206 | + //Load details |
| 207 | + $scope.resetSettings(); |
| 208 | + |
| 209 | + $scope.save = function(){ |
| 210 | + if($scope.item.enabled){ |
| 211 | + //Update time |
| 212 | + $scope.item.interval = $scope.intervalLocal * $scope.intervalTimeConstant; |
| 213 | + } |
| 214 | + $scope.saveProgress = true; |
| 215 | + ExportImportFactory.updateSettings($scope.item,function(response) { |
| 216 | + $scope.saveProgress = false; |
| 217 | + $scope.editEnable.exportSettings = false; |
| 218 | + $scope.resetSettings(); |
| 219 | + },function(error){ |
| 220 | + displayRestError.display(error); |
| 221 | + $scope.saveProgress = false; |
| 222 | + }); |
| 223 | + } |
| 224 | +}); |
0 commit comments