-
Notifications
You must be signed in to change notification settings - Fork 120
Expand file tree
/
Copy pathgr-un-delete-image.js
More file actions
58 lines (50 loc) · 1.9 KB
/
Copy pathgr-un-delete-image.js
File metadata and controls
58 lines (50 loc) · 1.9 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
import angular from 'angular';
import '../gr-confirm-delete/gr-confirm-delete';
export const undeleteImage = angular.module('gr.undeleteImage', [
'gr.confirmDelete',
'util.async'
]);
undeleteImage.controller('grUnDeleteImageCtrl', [
'$rootScope', '$q', 'mediaApi', 'apiPoll',
function ($rootScope, $q, mediaApi, apiPoll) {
var ctrl = this;
ctrl.$onInit = () => {
function pollUndeleted (image) {
const findImage = () => mediaApi.find(image.data.id).then(
(i) => i.data.softDeletedMetadata === undefined && i.data.userMetadata?.data?.archived
? $q.resolve()
: $q.reject()
);
return apiPoll(findImage);
}
ctrl.unDeleteImage = function (image) {
return mediaApi.undelete(image.data.id)
.then(() => pollUndeleted(image))
.catch((err) => {
$rootScope.$emit('image-undelete-failure', err, image);
});
};
ctrl.unDeleteSelected = function () {
// HACK to wait for thrall to process the message so that when we
// poll the api, it will be up to date.
return $q.all(Array.from(ctrl.images.values()).map(image => ctrl.unDeleteImage(image)))
.then(() => $rootScope.$emit('images-undeleted', ctrl.images));
};
};
}
]);
undeleteImage.directive('grUnDeleteImage', [function () {
return {
restrict: 'E',
template: `
<gr-confirm-delete class="gr-delete-image"
gr-on-confirm="ctrl.unDeleteSelected()" gr-label="Undelete" gr-confirm="Confirm Undelete" gr-tooltip="Undelete image" >
</gr-confirm-delete>`,
controller: 'grUnDeleteImageCtrl',
controllerAs: 'ctrl',
bindToController: true,
scope: {
images: '='
}
};
}]);