Skip to content

Commit 507bc5b

Browse files
JisayJoffrey LEVEUGLE
authored andcommitted
feat(pci.projects.new): manage polling during project creation (#418)
1 parent 4562cc8 commit 507bc5b

File tree

7 files changed

+77
-5
lines changed

7 files changed

+77
-5
lines changed

packages/manager/modules/pci/src/projects/new/new.routing.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ export default /* @ngInject */ ($stateProvider) => {
8080
newProjectInfo: /* @ngInject */ PciProjectNewService => PciProjectNewService
8181
.getNewProjectInfo(),
8282
onProjectCreated: /* @ngInject */ $state => projectId => $state.go(
83-
'pci.projects.project.creating', {
83+
'pci.projects.project', {
8484
projectId,
8585
},
8686
),
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import template from './creating.html';
2+
import controller from './creating.controller';
3+
4+
export default {
5+
template,
6+
controller,
7+
bindings: {
8+
projectId: '<',
9+
onProjectCreated: '<',
10+
},
11+
};
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
export default class ProjectCreatingCtrl {
2+
/* @ngInject */
3+
constructor(Poller) {
4+
// dependencies injections
5+
this.Poller = Poller;
6+
7+
// other attributes
8+
this.pollingNamespace = 'pci.projects.creating';
9+
}
10+
11+
startCreationPolling() {
12+
return this.Poller.poll(`/cloud/project/${this.projectId}`, null, {
13+
namespace: this.pollingNamespace,
14+
successRule(details) {
15+
return details.status === 'ok';
16+
},
17+
})
18+
.then(() => this.onProjectCreated());
19+
}
20+
21+
stopCreationPolling() {
22+
return this.Poller.kill({
23+
namespace: this.pollingNamespace,
24+
});
25+
}
26+
27+
/* ============================
28+
= Hooks =
29+
============================= */
30+
31+
$onInit() {
32+
this.stopCreationPolling();
33+
return this.startCreationPolling();
34+
}
35+
36+
$onDestroy() {
37+
return this.stopCreationPolling();
38+
}
39+
40+
/* ----- End of Hooks ------ */
41+
}
Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
import angular from 'angular';
22
import '@ovh-ux/ng-translate-async-loader';
3+
import '@ovh-ux/ng-ovh-swimming-poll';
34
import '@uirouter/angularjs';
45
import 'angular-translate';
56

7+
68
import routing from './creating.routing';
9+
import component from './creating.component';
710

811
const moduleName = 'ovhManagerPciProjectsNewCreating';
912

@@ -12,8 +15,10 @@ angular
1215
'ui.router',
1316
'ngTranslateAsyncLoader',
1417
'pascalprecht.translate',
18+
'ngOvhSwimmingPoll',
1519
])
1620
.config(routing)
17-
.run(/* @ngTranslationsInject:json ./translations */);
21+
.run(/* @ngTranslationsInject:json ./translations */)
22+
.component('pciProjectCreating', component);
1823

1924
export default moduleName;
Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
import template from './creating.html';
2-
31
export default /* @ngInject */ ($stateProvider) => {
42
$stateProvider
53
.state('pci.projects.project.creating', {
64
url: '/creating',
7-
template,
5+
component: 'pciProjectCreating',
6+
resolve: {
7+
breadcrumb: () => null,
8+
onProjectCreated: /* @ngInject */ $state => () => $state.go('^'),
9+
},
810
});
911
};

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

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

99
import billing from './billing';
1010
import contacts from './contacts';
11+
import creating from './creating';
1112
import edit from './edit';
1213
import failoverIps from './failover-ips';
1314
import instances from './instances';
@@ -26,6 +27,7 @@ angular
2627
.module(moduleName, [
2728
billing,
2829
contacts,
30+
creating,
2931
edit,
3032
failoverIps,
3133
instances,

packages/manager/modules/pci/src/projects/project/project.routing.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,17 @@ export default /* @ngInject */ ($stateProvider) => {
1616
format: 'json',
1717
value: ['.'],
1818
},
19+
redirectTo: ($transitions) => {
20+
const projectPromise = $transitions.injector().getAsync('project');
21+
return projectPromise
22+
.then((project) => {
23+
if (project.status === 'creating') {
24+
return 'pci.projects.project.creating';
25+
}
26+
27+
return null;
28+
});
29+
},
1930
resolve: {
2031
projectId: /* @ngInject */ $transition$ => $transition$.params().projectId,
2132
project: /* @ngInject */ (OvhApiCloudProject, $transition$) => OvhApiCloudProject

0 commit comments

Comments
 (0)