Skip to content

Commit 944bd5a

Browse files
Cyrille Bourgoisjleveugle
authored andcommitted
fix: update volume snapshots list
1 parent 8427078 commit 944bd5a

28 files changed

+293
-298
lines changed

packages/manager/modules/pci/src/projects/project/storages/blocks/block/edit/volume-edit/volume-edit.controller.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,12 @@ export default class PciProjectStorageVolumeEditController {
1010
constructor(
1111
$timeout,
1212
$translate,
13+
CucRegionService,
1314
PciProjectStorageBlockService,
1415
) {
1516
this.$timeout = $timeout;
1617
this.$translate = $translate;
18+
this.CucRegionService = CucRegionService;
1719
this.PciProjectStorageBlockService = PciProjectStorageBlockService;
1820
}
1921

packages/manager/modules/pci/src/projects/project/storages/blocks/block/edit/volume-edit/volume-edit.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ <h1 data-ng-bind="$ctrl.title"></h1>
1313
<div class="oui-field oui-field_error">
1414
<label for="storage-region" class="oui-field__label oui-label"
1515
data-translate="pci_projects_project_storages_blocks_block_volume-edit_region_label"></label>
16-
<div class="oui-field__control" data-ng-bind="$ctrl.storage.region"></div>
16+
<div class="oui-field__control" data-ng-bind="$ctrl.CucRegionService.getTranslatedMicroRegion($ctrl.storage.region)"></div>
1717
</div>
1818

1919
<div class="oui-field oui-field_error">

packages/manager/modules/pci/src/projects/project/storages/blocks/blocks.module.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import block from './block';
1414
import help from './help';
1515

1616
import component from './blocks.component';
17-
import service from './blocks.service';
1817

1918
import routing from './blocks.routing';
2019

@@ -36,7 +35,6 @@ angular
3635
])
3736
.config(routing)
3837
.component('pciProjectStorageBlocks', component)
39-
.service('PciProjectStorageBlockService', service)
4038
.run(/* @ngTranslationsInject:json ./translations */);
4139

4240
export default moduleName;

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import angular from 'angular';
22
import '@uirouter/angularjs';
33
import 'oclazyload';
44

5+
import service from './blocks.service';
6+
57
const moduleName = 'ovhManagerPciStoragesBlocksLazyLoading';
68

79
angular
@@ -19,6 +21,7 @@ angular
1921
.then(mod => $ocLazyLoad.inject(mod.default || mod));
2022
},
2123
});
22-
});
24+
})
25+
.service('PciProjectStorageBlockService', service);
2326

2427
export default moduleName;
Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,24 @@
11
import angular from 'angular';
2-
import '@ovh-ux/ng-translate-async-loader';
32
import '@uirouter/angularjs';
4-
import 'angular-translate';
5-
import 'ovh-ui-angular';
6-
import 'ovh-api-services';
3+
import 'oclazyload';
74

8-
import snapshot from './snapshot';
9-
10-
import component from './snapshots.component';
11-
import service from './snapshots.service';
12-
13-
import routing from './snapshots.routing';
14-
15-
const moduleName = 'ovhManagerPciStoragesSnapshots';
5+
const moduleName = 'ovhManagerPciStoragesSnapshotsLazyLoading';
166

177
angular
188
.module(moduleName, [
19-
'ngTranslateAsyncLoader',
20-
'oui',
21-
'ovh-api-services',
22-
'pascalprecht.translate',
239
'ui.router',
24-
snapshot,
10+
'oc.lazyLoad',
2511
])
26-
.config(routing)
27-
.component('pciProjectStoragesSnapshots', component)
28-
.service('PciProjectStorageSnapshotsService', service)
29-
.run(/* @ngTranslationsInject:json ./translations */);
12+
.config(/* @ngInject */($stateProvider) => {
13+
$stateProvider.state('pci.projects.project.storages.snapshots.**', {
14+
url: '/volume-snapshots',
15+
lazyLoad: ($transition$) => {
16+
const $ocLazyLoad = $transition$.injector().get('$ocLazyLoad');
17+
18+
return import('./snapshots.module')
19+
.then(mod => $ocLazyLoad.inject(mod.default || mod));
20+
},
21+
});
22+
});
3023

3124
export default moduleName;

packages/manager/modules/pci/src/projects/project/storages/snapshots/snapshot/create-volume/create-volume.component.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export default {
77
bindings: {
88
projectId: '<',
99
snapshotId: '<',
10+
snapshot: '<',
1011
goBack: '<',
1112
},
1213
};

packages/manager/modules/pci/src/projects/project/storages/snapshots/snapshot/create-volume/create-volume.controller.js

Lines changed: 21 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -20,35 +20,25 @@ export default class PciBlockStorageSnapshotsCreateVolumeController {
2020
}
2121

2222
$onInit() {
23-
this.loadings = {
24-
init: false,
25-
save: false,
26-
};
23+
this.isLoading = false;
24+
this.loadMessages();
2725

28-
this.initLoaders();
29-
}
30-
31-
initLoaders() {
32-
this.loadings.init = true;
33-
34-
this.$translate.refresh()
35-
.then(() => this.loadMessages())
36-
.then(() => this.getSnapshot())
37-
.catch((err) => {
38-
this.CucCloudMessage.error(
39-
this.$translate.instant(
40-
'pci_projects_project_storages_snapshots_snapshot_create-volume_error_load',
41-
{ message: get(err, 'data.message', '') },
42-
),
43-
);
44-
})
45-
.finally(() => {
46-
this.loadings.init = false;
47-
});
26+
this.storage = new BlockStorage({
27+
...pick(
28+
this.snapshot,
29+
[
30+
'region',
31+
'name',
32+
'size',
33+
'bootable',
34+
],
35+
),
36+
type: this.snapshot.volume.type,
37+
snapshotId: this.snapshot.id,
38+
});
4839
}
4940

5041
loadMessages() {
51-
this.CucCloudMessage.unSubscribe('pci.projects.project.storages.snapshots.snapshot.create-volume');
5242
this.messageHandler = this.CucCloudMessage.subscribe(
5343
'pci.projects.project.storages.snapshots.snapshot.create-volume',
5444
{
@@ -61,42 +51,14 @@ export default class PciBlockStorageSnapshotsCreateVolumeController {
6151
this.messages = this.messageHandler.getMessages();
6252
}
6353

64-
getSnapshot() {
65-
return this.PciProjectStorageSnapshotsService
66-
.get(this.projectId, this.snapshotId)
67-
.then((snapshot) => {
68-
this.storage = new BlockStorage({
69-
...pick(
70-
snapshot,
71-
[
72-
'region',
73-
'name',
74-
'size',
75-
'bootable',
76-
],
77-
),
78-
type: snapshot.volume.type,
79-
snapshotId: snapshot.id,
80-
});
81-
return this.editStorage;
82-
});
83-
}
84-
8554
save() {
86-
this.loadings.save = true;
55+
this.isLoading = true;
8756
return this.PciProjectStorageSnapshotsService
8857
.createVolume(this.projectId, this.storage)
89-
.then(() => {
90-
this.CucCloudMessage.success(
91-
this.$translate.instant(
92-
'pci_projects_project_storages_snapshots_snapshot_create-volume_success_message',
93-
{ volume: this.storage.name },
94-
),
95-
'pci.projects.project.storages.snapshots.snapshot',
96-
);
97-
98-
return this.goBack(true);
99-
})
58+
.then(() => this.goBack(this.$translate.instant(
59+
'pci_projects_project_storages_snapshots_snapshot_create-volume_success_message',
60+
{ volume: this.storage.name },
61+
)))
10062
.catch((err) => {
10163
this.CucCloudMessage.error(
10264
this.$translate.instant(
@@ -107,7 +69,7 @@ export default class PciBlockStorageSnapshotsCreateVolumeController {
10769
);
10870
})
10971
.finally(() => {
110-
this.loadings.save = false;
72+
this.isLoading = false;
11173
});
11274
}
11375
}
Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,14 @@
1-
<div class="p-5">
2-
<div data-ng-if="$ctrl.loading" class="text-center">
3-
<oui-spinner></oui-spinner>
4-
</div>
5-
<section data-ng-if="!$ctrl.loading">
6-
<oui-back-button
7-
data-on-click="$ctrl.goBack()">{{:: 'pci_projects_project_storages_snapshots_snapshot_create-volume_back_label' | translate }}</oui-back-button>
1+
<section>
2+
<cui-message-container data-messages="$ctrl.messages"></cui-message-container>
83

9-
<cui-message-container data-messages="$ctrl.messages"></cui-message-container>
10-
11-
<pci-project-storage-volume-edit
12-
data-ng-if="$ctrl.storage"
13-
data-storage="$ctrl.storage"
14-
data-project-id="$ctrl.projectId"
15-
data-title="'pci_projects_project_storages_snapshots_snapshot_create-volume_title' | translate"
16-
data-submit-label="'pci_projects_project_storages_snapshots_snapshot_create-volume_submit_label' | translate"
17-
data-on-cancel="$ctrl.goBack()"
18-
data-on-submit="$ctrl.save()"
19-
data-show-loading="$ctrl.loadings.save">
20-
</pci-project-storage-volume-edit>
21-
</section>
22-
</div>
4+
<pci-project-storage-volume-edit
5+
data-ng-if="$ctrl.storage"
6+
data-storage="$ctrl.storage"
7+
data-project-id="$ctrl.projectId"
8+
data-title="'pci_projects_project_storages_snapshots_snapshot_create-volume_title' | translate"
9+
data-submit-label="'pci_projects_project_storages_snapshots_snapshot_create-volume_submit_label' | translate"
10+
data-on-cancel="$ctrl.goBack()"
11+
data-on-submit="$ctrl.save()"
12+
data-show-loading="$ctrl.isLoading">
13+
</pci-project-storage-volume-edit>
14+
</section>
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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 blockStorages from '../../../blocks';
9+
import volumeEdit from '../../../blocks/block/edit/volume-edit';
10+
import component from './create-volume.component';
11+
import routing from './create-volume.routing';
12+
13+
const moduleName = 'ovhManagerPciStoragesSnapshotsCreateVolume';
14+
15+
angular
16+
.module(moduleName, [
17+
'ui.router',
18+
'oui',
19+
'ovh-api-services',
20+
'ngTranslateAsyncLoader',
21+
'pascalprecht.translate',
22+
blockStorages,
23+
volumeEdit,
24+
])
25+
.config(routing)
26+
.component('pciProjectStoragesSnapshotsCreateVolume', component)
27+
.run(/* @ngTranslationsInject:json ./translations */);
28+
29+
export default moduleName;

packages/manager/modules/pci/src/projects/project/storages/snapshots/snapshot/create-volume/create-volume.routing.js

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,28 @@ export default /* @ngInject */ ($stateProvider) => {
44
url: '/new-volume',
55
component: 'pciProjectStoragesSnapshotsCreateVolume',
66
resolve: {
7-
goBack: /* @ngInject */ ($rootScope, $state, projectId) => (reload = false) => {
8-
if (reload) {
9-
$rootScope.$emit('pci_storages_blocks_refresh');
10-
}
11-
return $state.go('pci.projects.project.storages.snapshots', {
7+
goBack: /* @ngInject */ ($rootScope, CucCloudMessage, $state, projectId) => (message = false, type = 'success') => {
8+
const reload = message && type === 'success';
9+
10+
const promise = $state.go(reload ? 'pci.projects.project.storages.blocks' : 'pci.projects.project.storages.snapshots', {
1211
projectId,
12+
},
13+
{
14+
reload,
1315
});
16+
17+
if (message) {
18+
promise.then(() => CucCloudMessage[type](message, reload ? 'pci.projects.project.storages.blocks' : 'pci.projects.project.storages.snapshots'));
19+
}
20+
21+
return promise;
1422
},
1523
cancelLink: /* @ngInject */ ($state, projectId) => $state.href('pci.projects.project.storages.snapshots', {
1624
projectId,
1725
}),
26+
breadcrumb: /* @ngInject */ $translate => $translate
27+
.refresh()
28+
.then(() => $translate.instant('pci_projects_project_storages_snapshots_snapshot_create-volume_title')),
1829
},
1930
});
2031
};

0 commit comments

Comments
 (0)