Skip to content

Commit 754a403

Browse files
Cyrille Bourgoisjleveugle
authored andcommitted
feat: add instance backups list
ref: MANAGER-2287
1 parent 622be41 commit 754a403

File tree

16 files changed

+506
-1
lines changed

16 files changed

+506
-1
lines changed

packages/manager/apps/public-cloud/src/sidebar/sidebar.constant.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export const MENU = [
3838
},
3939
{
4040
options: {
41-
state: 'pci.projects.project2',
41+
state: 'pci.projects.project.storages.instance-backups',
4242
},
4343
translation: 'cloud_sidebar_storage_instance_storage',
4444
},

packages/manager/modules/pci/src/projects/project/storages/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import 'ovh-ui-angular';
33

44
import blocks from './blocks';
55
import cloudArchive from './cloud-archives';
6+
import instanceBackups from './instance-backups';
67
import objects from './objects';
78
import snapshots from './snapshots';
89
import routing from './storages.routing';
@@ -13,6 +14,7 @@ angular
1314
.module(moduleName, [
1415
blocks,
1516
cloudArchive,
17+
instanceBackups,
1618
'oui',
1719
objects,
1820
snapshots,
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import angular from 'angular';
2+
import '@ovh-ux/manager-core';
3+
import '@ovh-ux/ng-translate-async-loader';
4+
import '@uirouter/angularjs';
5+
import 'angular-translate';
6+
import 'ovh-ui-angular';
7+
import 'ovh-api-services';
8+
import 'angular-ui-bootstrap';
9+
import '@ovh-ux/ng-ovh-user-pref';
10+
11+
import component from './instance-backups.component';
12+
import service from './instance-backups.service';
13+
14+
import instanceBackupDelete from './instance-backup/delete';
15+
16+
import routing from './instance-backups.routing';
17+
18+
const moduleName = 'ovhManagerPciStoragesInstanceBackups';
19+
20+
angular
21+
.module(moduleName, [
22+
instanceBackupDelete,
23+
'ngOvhUserPref',
24+
'ngTranslateAsyncLoader',
25+
'oui',
26+
'ovh-api-services',
27+
'ovhManagerCore',
28+
'pascalprecht.translate',
29+
'ui.router',
30+
'ui.bootstrap',
31+
])
32+
.config(routing)
33+
.component('pciProjectStorageInstanceBackups', component)
34+
.service('PciProjectStorageInstanceBackupService', service)
35+
.run(/* @ngTranslationsInject:json ./translations */);
36+
37+
export default moduleName;
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import includes from 'lodash/includes';
2+
3+
export default class InstanceBackup {
4+
constructor(resource) {
5+
Object.assign(this, resource);
6+
}
7+
8+
get statusGroup() {
9+
if (includes(['active'], this.status)) {
10+
return 'ACTIVE';
11+
}
12+
if (includes(['saving'], this.status)) {
13+
return 'SAVING';
14+
}
15+
return this.status.toUpperCase();
16+
}
17+
18+
isDeletable() {
19+
return this.statusGroup === 'ACTIVE';
20+
}
21+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import controller from './delete.controller';
2+
import template from './delete.html';
3+
4+
export default {
5+
controller,
6+
template,
7+
bindings: {
8+
projectId: '<',
9+
instanceBackupId: '<',
10+
goBack: '<',
11+
},
12+
};
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
import get from 'lodash/get';
2+
3+
export default class PciBlockStorageDetailsDeleteController {
4+
/* @ngInject */
5+
constructor(
6+
$translate,
7+
CucCloudMessage,
8+
PciProjectStorageInstanceBackupService,
9+
) {
10+
this.$translate = $translate;
11+
this.CucCloudMessage = CucCloudMessage;
12+
this.PciProjectStorageInstanceBackupService = PciProjectStorageInstanceBackupService;
13+
}
14+
15+
$onInit() {
16+
this.loadings = {
17+
init: false,
18+
save: false,
19+
};
20+
21+
this.initLoaders();
22+
}
23+
24+
initLoaders() {
25+
this.loadings.init = true;
26+
return this.$translate.refresh()
27+
.then(() => this.loadMessages())
28+
.then(() => this.PciProjectStorageInstanceBackupService
29+
.get(this.projectId, this.instanceBackupId))
30+
.then((instanceBackup) => {
31+
this.instanceBackup = instanceBackup;
32+
return this.instanceBackup;
33+
})
34+
.catch((err) => {
35+
this.CucCloudMessage.error(
36+
this.$translate.instant(
37+
'pci_projects_project_storages_volume-instances_volume-instance_delete_error_load',
38+
{ message: get(err, 'data.message', '') },
39+
),
40+
);
41+
})
42+
.finally(() => {
43+
this.loadings.init = false;
44+
});
45+
}
46+
47+
loadMessages() {
48+
return new Promise((resolve) => {
49+
this.CucCloudMessage.unSubscribe('pci.projects.project.storages.volume-instances.delete');
50+
this.messageHandler = this.CucCloudMessage.subscribe(
51+
'pci.projects.project.storages.volume-instances.delete',
52+
{
53+
onMessage: () => this.refreshMessages(),
54+
},
55+
);
56+
resolve();
57+
});
58+
}
59+
60+
refreshMessages() {
61+
this.messages = this.messageHandler.getMessages();
62+
}
63+
64+
deleteStorage() {
65+
this.loadings.save = true;
66+
return this.PciProjectStorageInstanceBackupService.delete(this.projectId, this.instanceBackup)
67+
.then(() => {
68+
this.CucCloudMessage.success(
69+
this.$translate.instant(
70+
'pci_projects_project_storages_volume-instances_volume-instance_delete_success_message',
71+
{
72+
snapshot: this.instanceBackup.name,
73+
},
74+
),
75+
'pci.projects.project.storages.instance-backups',
76+
);
77+
return this.goBack(true);
78+
})
79+
.catch((err) => {
80+
this.CucCloudMessage.error(
81+
this.$translate.instant(
82+
'pci_projects_project_storages_volume-instances_volume-instance_delete_error_delete',
83+
{
84+
message: get(err, 'data.message', null),
85+
snapshot: this.instanceBackup.name,
86+
},
87+
),
88+
);
89+
})
90+
.finally(() => {
91+
this.loadings.save = false;
92+
});
93+
}
94+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<oui-modal
2+
data-heading="{{ 'pci_projects_project_storages_volume-instances_volume-instance_delete_title' | translate }}"
3+
data-primary-action="$ctrl.deleteStorage()"
4+
data-primary-label="{{:: 'pci_projects_project_storages_volume-instances_volume-instance_delete_submit_label' | translate }}"
5+
data-primary-disabled="$ctrl.loadings.init || $ctrl.loadings.save || !$ctrl.instanceBackup.isDeletable()"
6+
data-secondary-action="$ctrl.goBack()"
7+
data-secondary-label="{{:: 'pci_projects_project_storages_volume-instances_volume-instance_delete_cancel_label' | translate }}"
8+
data-on-dismiss="$ctrl.goBack()"
9+
data-loading="$ctrl.loadings.init">
10+
11+
<cui-message-container data-messages="$ctrl.messages"></cui-message-container>
12+
13+
<div data-ng-if="$ctrl.instanceBackup.isDeletable()">
14+
<p data-translate="pci_projects_project_storages_volume-instances_volume-instance_delete_content"
15+
data-translate-values="{ snapshot: $ctrl.instanceBackup.name }"></p>
16+
<oui-message data-type="warning">
17+
<span data-translate="pci_projects_project_storages_volume-instances_volume-instance_delete_erase_message"></span>
18+
</oui-message>
19+
</div>
20+
<div data-ng-if="!$ctrl.instanceBackup.isDeletable()">
21+
<oui-message data-type="warning">
22+
<span data-translate="pci_projects_project_storages_volume-instances_volume-instance_delete_error_not_deletable"></span>
23+
</oui-message>
24+
</div>
25+
26+
<div data-ng-if="$ctrl.loadings.save" class="text-center">
27+
<oui-spinner></oui-spinner>
28+
</div>
29+
30+
</oui-modal>
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
export default /* @ngInject */($stateProvider) => {
2+
$stateProvider
3+
.state('pci.projects.project.storages.instance-backups.delete', {
4+
url: '/delete?instanceBackupId',
5+
views: {
6+
modal: {
7+
component: 'pciProjectStorageInstanceBackupsDelete',
8+
},
9+
},
10+
layout: 'modal',
11+
resolve: {
12+
instanceBackupId: /* @ngInject */$transition$ => $transition$.params().instanceBackupId,
13+
goBack: /* @ngInject */ ($rootScope, $state, projectId) => (reload = false) => {
14+
if (reload) {
15+
$rootScope.$emit('pci_storages_instance-backups_refresh');
16+
}
17+
return $state.go('pci.projects.project.storages.instance-backups', {
18+
projectId,
19+
});
20+
},
21+
},
22+
});
23+
};
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import angular from 'angular';
2+
import '@ovh-ux/ng-translate-async-loader';
3+
import '@uirouter/angularjs';
4+
import 'angular-translate';
5+
import 'ovh-ui-angular';
6+
import 'ovh-api-services';
7+
8+
import component from './delete.component';
9+
import routing from './delete.routing';
10+
11+
const moduleName = 'pciProjectStorageInstanceBackupsDelete';
12+
13+
angular
14+
.module(moduleName, [
15+
'ui.router',
16+
'oui',
17+
'ovh-api-services',
18+
'ngTranslateAsyncLoader',
19+
'pascalprecht.translate',
20+
])
21+
.config(routing)
22+
.component('pciProjectStorageInstanceBackupsDelete', component)
23+
.run(/* @ngTranslationsInject:json ./translations */);
24+
25+
export default moduleName;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"pci_projects_project_storages_volume-instances_volume-instance_delete_title": "Supprimer un backup",
3+
"pci_projects_project_storages_volume-instances_volume-instance_delete_submit_label": "Confirmer",
4+
"pci_projects_project_storages_volume-instances_volume-instance_delete_cancel_label": "Annuler",
5+
"pci_projects_project_storages_volume-instances_volume-instance_delete_content": "Supprimer définitivement {{ snapshot }}",
6+
"pci_projects_project_storages_volume-instances_volume-instance_delete_erase_message": "Toutes les données sur le backup d'instance seront perdues.",
7+
"pci_projects_project_storages_volume-instances_volume-instance_delete_error_not_deletable": "Il n'est pas possible de supprimer ce backup d'instance actuellement.",
8+
9+
"pci_projects_project_storages_volume-instances_volume-instance_delete_error_load": "Une erreur est survenue lors du chargement du backup d'instance : {{ message }}.",
10+
"pci_projects_project_storages_volume-instances_volume-instance_delete_success_message": "Le backup d'instance {{ snapshot }} a été supprimé.",
11+
"pci_projects_project_storages_volume-instances_volume-instance_delete_error_delete": "Une erreur est survenue lors de la suppression du backup d'instance {{ snapshot }} : {{ message }}."
12+
}

0 commit comments

Comments
 (0)