Skip to content
This repository was archived by the owner on May 7, 2024. It is now read-only.

Commit 544b287

Browse files
committed
Implemented mass delete
1 parent 8122129 commit 544b287

File tree

1 file changed

+45
-1
lines changed

1 file changed

+45
-1
lines changed

assets/js/app/upstreams/upstreams-controller.js

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919

2020

2121
Upstream.setScope($scope, false, 'items', 'itemCount');
22+
$scope.deleteItem = deleteItem
23+
$scope.deleteChecked = deleteChecked
2224

2325
// Add default list configuration variable to current scope
2426
$scope = angular.extend($scope, angular.copy(ListConfig.getConfig()));
@@ -115,13 +117,55 @@
115117
});
116118
}
117119

120+
function deleteChecked() {
121+
122+
var items = []
123+
$scope.items.forEach(function(item){
124+
if(item.checked) items.push(item)
125+
})
126+
127+
if(!items.length) {
128+
MessageService.error('You have not selected any upstreams to delete')
129+
return false
130+
}
131+
132+
DialogService.prompt(
133+
"Delete Upstreams","Really want to delete the selected upstreams?",
134+
['No don\'t','Yes! delete them'],
135+
function accept(){
136+
deleteItems(items)
137+
},function decline(){})
138+
139+
}
140+
141+
function deleteItems(items) {
142+
143+
$scope.deleting = true;
144+
var promises = []
145+
items.forEach(function(item){
146+
promises.push(Upstream.delete(item.id))
147+
})
148+
149+
$q
150+
.all(promises)
151+
.finally(
152+
function onFinally() {
153+
$scope.deleting = false;
154+
_fetchData()
155+
}
156+
)
157+
;
158+
}
159+
118160

119161
// Listeners
120162
$scope.$on('kong.upstream.created',function(ev,data){
121163
_fetchData()
122164
})
123165

124-
$scope.deleteItem = function(item) {
166+
167+
168+
function deleteItem(item) {
125169
DialogService.prompt(
126170
"Delete Upstream","Really want to delete the selected upstream?",
127171
['No don\'t','Yes! delete it'],

0 commit comments

Comments
 (0)