This repository was archived by the owner on Sep 17, 2019. It is now read-only.
Repository navigation
Expand file tree
/
Copy pathpaths.js
More file actions
258 lines (242 loc) · 6.64 KB
/
Copy pathpaths.js
File metadata and controls
258 lines (242 loc) · 6.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
'use strict';
angular.module('ModuleAB.paths', ['ngRoute'])
.config(['$routeProvider', function($routeProvider) {
$routeProvider.when('/paths', {
templateUrl: 'paths/paths.html',
controller: 'paths'
});
}])
.controller('paths', ['$scope', '$http', '$uibModal', '$rootScope',
function($scope, $http, $uibModal, $rootScope) {
$scope.pathsGet = function() {
$http({
method: "GET",
url: "/api/v1/paths"
}).then(function(response) {
$scope.paths = response.data;
}, function(response) {
if (response.status == 404) {
$scope.paths = null;
}
});
};
$scope.pathsGet();
$scope.pathEdit = function(type, path) {
var modal = $uibModal.open({
templateUrl: 'pathModal.html',
controller: 'pathModal',
resolve: {
type: function() {
return type;
},
path: function() {
return path;
}
}
});
modal.result.then(function(d) {
$scope.pathsGet();
});
};
$scope.delete = function(path) {
var modal = $uibModal.open({
templateUrl: 'common/deleteModal.html',
controller: 'deletePathModal',
resolve: {
path: function() {
return path;
}
}
});
modal.result.then(function(d) {
$http({
method: "DELETE",
url: "/api/v1/paths/" + path.id
}).then(function(response) {
$scope.pathsGet();
}, function(response) {
$rootScope.alertType = 'alert-warning';
$rootScope.fadein = 'fadein-opacity';
switch (response.status) {
case 401:
window.location.href = "/login";
break;
case 403:
$rootScope.failMessage = "没有权限";
break;
case 404:
$rootScope.failMessage = "无此路径";
break;
case 500:
$rootScope.failMessage = "服务器错误,见控制台输出";
console.log(response.data);
break;
default:
$rootScope.failMessage = "通讯故障";
break;
}
});
});
};
}
])
.controller('deletePathModal', function($scope, $uibModalInstance, path) {
$scope.cancel = function() {
$uibModalInstance.dismiss('cancel');
};
$scope.doDelete = function() {
$uibModalInstance.close('delete');
}
$scope.modalDeleteObjName = path.path;
})
.controller('pathModal', function($scope, $http, $uibModalInstance, type,
path) {
if (path === undefined) {
path = {
path: "",
backupset: {
id: ""
},
appset: []
};
}
$scope.path = path;
$http({
method: "GET",
url: "/api/v1/backupSets"
}).then(function(response) {
$scope.backupSets = response.data;
}, function(response) {
// do nothing
});
$http({
method: "GET",
url: "/api/v1/appSets"
}).then(function(response) {
$scope.appSets = response.data;
}, function(response) {
// do nothing
});
switch (type) {
case 'new':
$scope.type = "新增";
$scope.jobType = "fa-plus";
$scope.job = "新增"
break;
case 'modify':
$scope.type = "修改";
$scope.jobType = "fa-pencil";
$scope.job = "修改";
break;
}
$scope.modalInfoFadein = "";
$scope.backupSetId = path.backupset.id;
$scope.appSetIds = [];
$scope.$watch('path.appset', function(s) {
if (!s) {
return;
}
angular.forEach(s, function(v) {
$scope.appSetIds.push(v.id.toString());
});
});
$scope.doJob = function() {
if (!$scope.path.path.match(/^\/.*[^\/]$/)) {
$scope.modalInfoFadein = "fadein-opacity";
$scope.modalInfoMsg = "路径应当是绝对路径,且不以'/'结尾";
return;
}
angular.forEach($scope.backupSets, function(s0) {
if ($scope.backupSetId == s0.id) {
$scope.path.backupset = s0;
return;
}
});
$scope.path.appset = [];
angular.forEach($scope.appSetIds, function(s0) {
angular.forEach($scope.appSets, function(s1) {
if (s1.id == s0) {
$scope.path.appset.push(s1);
}
});
});
if ($scope.path.backupset.id == "") {
$scope.modalInfoFadein = "fadein-opacity";
$scope.modalInfoMsg = "请指定一个备份集";
return;
}
if ($scope.path.appset.length == 0) {
$scope.modalInfoFadein = "fadein-opacity";
$scope.modalInfoMsg = "请指定至少一个应用集";
return;
}
switch (type) {
case 'new':
$http({
method: "POST",
url: "/api/v1/paths",
data: $scope.path
}).then(function(response) {
$uibModalInstance.close(response.data.id);
}, function(response) {
$scope.modalInfoFadein = "fadein-opacity";
switch (response.status) {
case 400:
$scope.modalInfoMsg = "数据错误";
break;
case 401:
$scope.modalInfoMsg = "未登录";
window.location.href = "/login";
break;
case 403:
$scope.modalInfoMsg = "访问被拒绝";
break;
case 500:
$scope.modalInfoMsg = "服务器错误,见控制台输出";
console.log(response.data);
break;
default:
$scope.modalInfoMsg = "通讯故障";
break;
}
});
break;
case 'modify':
$http({
method: "PUT",
url: "/api/v1/paths/" + $scope.path.id,
data: $scope.path
}).then(function(response) {
$uibModalInstance.close(response.status);
}, function(response) {
$scope.modalInfoFadein = "fadein-opacity";
switch (response.status) {
case 400:
$scope.modalInfoMsg = "数据错误";
break;
case 401:
$scope.modalInfoMsg = "未登录";
window.location.href = "/login";
break;
case 403:
$scope.modalInfoMsg = "访问被拒绝";
break;
case 404:
$scope.modalInfoMsg = "无此路径";
break;
case 500:
$scope.modalInfoMsg = "服务器错误,见控制台输出";
console.log(response.data);
break;
default:
$scope.modalInfoMsg = "通讯故障";
break;
}
});
break;
}
}
$scope.cancel = function() {
$uibModalInstance.dismiss('cancel');
}
});