|
1 | 1 | angular.module('blogAdmin').controller('DashboardController', ["$rootScope", "$scope", "$location", "$log", "$filter", "dataService", function ($rootScope, $scope, $location, $log, $filter, dataService) { |
2 | 2 | $scope.vm = {}; |
3 | | - $scope.trash = []; |
4 | | - $scope.logItems = []; |
5 | 3 | $scope.itemToPurge = {}; |
6 | 4 | $scope.security = $rootScope.security; |
7 | 5 | $scope.pager = {}; |
|
10 | 8 | $scope.focusInput = false; |
11 | 9 |
|
12 | 10 | $scope.openLogFile = function () { |
13 | | - dataService.getItems('/api/logs/getlog/file') |
14 | | - .success(function (data) { |
15 | | - angular.copy(data, $scope.logItems); |
16 | | - $("#modal-log-file").modal(); |
17 | | - return false; |
18 | | - }) |
19 | | - .error(function (data) { |
20 | | - toastr.error($rootScope.lbl.errorGettingLogFile); |
21 | | - }); |
| 11 | + $("#modal-log-file").modal(); |
| 12 | + return false; |
22 | 13 | } |
23 | | - |
24 | 14 | $scope.purgeLog = function () { |
25 | 15 | dataService.updateItem('/api/logs/purgelog/file', $scope.itemToPurge) |
26 | 16 | .success(function (data) { |
27 | | - $scope.logItems = []; |
| 17 | + $scope.vm.Logs = []; |
28 | 18 | $("#modal-log-file").modal('hide'); |
29 | 19 | toastr.success($rootScope.lbl.purged); |
30 | 20 | return false; |
|
36 | 26 |
|
37 | 27 | $scope.purge = function (id) { |
38 | 28 | if (id) { |
39 | | - $scope.itemToPurge = findInArray($scope.trash.Items, "Id", id); |
| 29 | + $scope.itemToPurge = findInArray($scope.vm.Trash, "Id", id); |
40 | 30 | } |
41 | 31 | dataService.updateItem('/api/trash/purge/' + id, $scope.itemToPurge) |
42 | 32 | .success(function (data) { |
43 | | - $scope.loadTrash(); |
| 33 | + for (var i = 0; i < $scope.vm.Trash.length; i++) |
| 34 | + if ($scope.vm.Trash[i].Id === id) { |
| 35 | + $scope.vm.Trash.splice(i, 1); |
| 36 | + break; |
| 37 | + } |
44 | 38 | toastr.success($rootScope.lbl.purged); |
45 | 39 | return false; |
46 | 40 | }) |
47 | 41 | .error(function (data) { |
48 | 42 | toastr.error($rootScope.lbl.errorPurging); |
49 | 43 | }); |
50 | 44 | } |
51 | | - |
52 | 45 | $scope.purgeAll = function () { |
53 | 46 | dataService.updateItem('/api/trash/purgeall/all') |
54 | 47 | .success(function (data) { |
55 | | - $scope.loadTrash(); |
| 48 | + $scope.vm.Trash = []; |
56 | 49 | toastr.success($rootScope.lbl.purged); |
57 | 50 | return false; |
58 | 51 | }) |
59 | 52 | .error(function (data) { |
60 | 53 | toastr.error($rootScope.lbl.errorPurging); |
61 | 54 | }); |
62 | 55 | } |
63 | | - |
64 | 56 | $scope.restore = function (id) { |
65 | 57 | if (id) { |
66 | | - $scope.itemToPurge = findInArray($scope.trash.Items, "Id", id); |
| 58 | + $scope.itemToPurge = findInArray($scope.vm.Trash, "Id", id); |
67 | 59 | } |
68 | 60 | dataService.updateItem('/api/trash/restore/' + id, $scope.itemToPurge) |
69 | 61 | .success(function (data) { |
70 | | - $scope.loadTrash(); |
| 62 | + for (var i = 0; i < $scope.vm.Trash.length; i++) |
| 63 | + if ($scope.vm.Trash[i].Id === id) { |
| 64 | + $scope.vm.Trash.splice(i, 1); |
| 65 | + break; |
| 66 | + } |
71 | 67 | toastr.success($rootScope.lbl.restored); |
72 | 68 | return false; |
73 | 69 | }) |
|
86 | 82 | $scope.loadPackages(); |
87 | 83 |
|
88 | 84 | dataService.getItems('/api/dashboard') |
89 | | - .success(function (data) { angular.copy(data, $scope.vm); }) |
90 | | - .error(function (data) { toastr.success($rootScope.lbl.errorGettingStats); }); |
91 | | - |
92 | | - dataService.getItems('/api/logs/getlog/file') |
93 | | - .success(function (data) { |
94 | | - angular.copy(data, $scope.logItems); |
95 | | - if ($scope.logItems.length > 0) { $('#tr-log-spinner').hide(); } |
96 | | - else { $('#div-log-spinner').html($rootScope.lbl.empty); } |
97 | | - }) |
98 | | - .error(function (data) { toastr.error($rootScope.lbl.errorGettingLogFile); }); |
99 | | - |
100 | | - $scope.loadTrash(); |
101 | | - $scope.loadNotes(); |
102 | | - } |
103 | | - |
104 | | - $scope.loadNotes = function () { |
105 | | - dataService.getItems('/api/quicknotes', { type: 0, take: 5, skip: 0 }) |
106 | | - .success(function (data) { |
107 | | - angular.copy(data, $scope.pager.items); |
108 | | - listPagerInit($scope.pager); |
109 | | - }) |
110 | | - .error(function () { toastr.error($rootScope.lbl.errorLoadingTrash); }); |
| 85 | + .success(function (data) { |
| 86 | + angular.copy(data, $scope.vm); |
| 87 | + $scope.pager.items = $scope.vm.Notes; |
| 88 | + listPagerInit($scope.pager); |
| 89 | + }) |
| 90 | + .error(function (data) { toastr.success($rootScope.lbl.errorGettingStats); }); |
111 | 91 | } |
112 | 92 |
|
113 | 93 | $scope.loadPackages = function () { |
|
148 | 128 | }); |
149 | 129 | } |
150 | 130 |
|
151 | | - $scope.loadTrash = function () { |
152 | | - dataService.getItems('/api/trash', { type: 0, take: 5, skip: 0 }) |
153 | | - .success(function (data) { angular.copy(data, $scope.trash); }) |
154 | | - .error(function () { toastr.error($rootScope.lbl.errorLoadingTrash); }); |
155 | | - } |
156 | | - |
157 | | - $(document).ready(function () { |
158 | | - |
159 | | - }); |
160 | | - |
161 | 131 | $scope.load(); |
162 | 132 |
|
163 | 133 | $scope.noteId = ''; |
|
0 commit comments