Skip to content

Commit 8972203

Browse files
jleveuglejleveugle
authored andcommitted
feat(project): user are now able to edit project and define default (#346)
1 parent e739da5 commit 8972203

File tree

10 files changed

+210
-9
lines changed

10 files changed

+210
-9
lines changed

packages/manager/modules/pci/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
},
1919
"dependencies": {
2020
"@ovh-ux/ng-ovh-cloud-universe-components": "^1.1.0-alpha.0",
21+
"@ovh-ux/ng-ovh-user-pref": "^1.0.0",
2122
"d3": "~3.5.13",
2223
"flag-icon-css": "~0.8.5",
2324
"jsplumb": "^2.9.2",
@@ -31,7 +32,6 @@
3132
"@ovh-ux/component-rollup-config": "5.0.1"
3233
},
3334
"peerDependencies": {
34-
"@ovh-ux/ng-ovh-uirouter-layout": "^0.0.0",
3535
"@ovh-ux/manager-cloud-styles": "^0.3.0-alpha.0",
3636
"@ovh-ux/manager-core": "^5.0.0",
3737
"@ovh-ux/manager-kubernetes": "^0.1.0-alpha.0",
@@ -46,6 +46,7 @@
4646
"@ovh-ux/ng-ovh-responsive-popover": "^5.0.0-beta.0",
4747
"@ovh-ux/ng-ovh-swimming-poll": "^4.0.0",
4848
"@ovh-ux/ng-ovh-toaster": "^1.0.2",
49+
"@ovh-ux/ng-ovh-uirouter-layout": "^0.0.0",
4950
"@ovh-ux/ng-ovh-user-pref": "^1.0.0",
5051
"@ovh-ux/ng-translate-async-loader": "^2.0.0",
5152
"@uirouter/angularjs": "^1.0.15",
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export const DEFAULT_PROJECT_KEY = 'PUBLIC_CLOUD_DEFAULT_PROJECT';
2+
export const MESSAGES_CONTAINER_NAME = 'pci.projects.project.edit';
3+
4+
export default {
5+
DEFAULT_PROJECT_KEY,
6+
MESSAGES_CONTAINER_NAME,
7+
};
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
import pick from 'lodash/pick';
2+
3+
import { DEFAULT_PROJECT_KEY, MESSAGES_CONTAINER_NAME } from './edit.constant';
4+
5+
export default class ProjectEditController {
6+
/* @ngInject */
7+
constructor($stateParams, $translate, CucCloudMessage, ovhUserPref, OvhApiCloudProject) {
8+
this.$stateParams = $stateParams;
9+
this.$translate = $translate;
10+
this.CucCloudMessage = CucCloudMessage;
11+
this.ovhUserPref = ovhUserPref;
12+
this.OvhApiCloudProject = OvhApiCloudProject;
13+
this.serviceName = this.$stateParams.projectId;
14+
15+
this.loading = {
16+
init: false,
17+
submit: false,
18+
};
19+
20+
this.$ngInit();
21+
}
22+
23+
$ngInit() {
24+
this.loading.init = true;
25+
this.messageHandler = this.CucCloudMessage.subscribe(MESSAGES_CONTAINER_NAME, {
26+
onMessage: () => this.refreshMessage(),
27+
});
28+
29+
return this.OvhApiCloudProject
30+
.v6()
31+
.get({
32+
serviceName: this.serviceName,
33+
})
34+
.$promise
35+
.then((project) => {
36+
this.project = project;
37+
})
38+
.then(() => this.ovhUserPref.getValue(DEFAULT_PROJECT_KEY))
39+
.then((defaultProject) => {
40+
this.defaultProject = defaultProject;
41+
this.isDefault = this.serviceName === defaultProject.projectId;
42+
})
43+
.catch((err) => {
44+
if (err.status === 404) {
45+
return null;
46+
}
47+
throw err;
48+
})
49+
.finally(() => {
50+
this.loading.init = false;
51+
});
52+
}
53+
54+
refreshMessage() {
55+
this.messages = this.messageHandler.getMessages();
56+
}
57+
58+
submit() {
59+
this.loading.submit = true;
60+
61+
return this.OvhApiCloudProject
62+
.v6()
63+
.put(
64+
{
65+
serviceName: this.serviceName,
66+
},
67+
pick(this.project, 'description'),
68+
)
69+
.$promise
70+
.then(() => {
71+
// isDefault is true, we want to define this project as default project
72+
if (this.isDefault) {
73+
return this.ovhUserPref.create(
74+
DEFAULT_PROJECT_KEY,
75+
{ projectId: this.serviceName },
76+
);
77+
}
78+
// isDefault is false, if the default project is this one, we should remove the key
79+
if (this.defaultProject.projectId === this.serviceName) {
80+
return this.ovhUserPref.remove(DEFAULT_PROJECT_KEY);
81+
}
82+
return null;
83+
})
84+
.then(() => {
85+
this.CucCloudMessage.success(
86+
this.$translate.instant('pci_projects_project_edit_update_success'),
87+
MESSAGES_CONTAINER_NAME,
88+
);
89+
})
90+
.catch(({ data }) => {
91+
this.CucCloudMessage.error(
92+
this.$translate.instant('pci_projects_project_edit_update_error', { error: data.message }),
93+
MESSAGES_CONTAINER_NAME,
94+
);
95+
})
96+
.finally(() => {
97+
this.loading.submit = false;
98+
});
99+
}
100+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<div class="text-center" data-ng-if="$ctrl.loading.init">
2+
<oui-spinner size="l"></oui-spinner>
3+
</div>
4+
<div data-ng-if="!$ctrl.loading.init">
5+
<form novalidate name="inputForm" data-ng-submit="$ctrl.submit()">
6+
<cui-message-container data-messages="$ctrl.messages"></cui-message-container>
7+
<oui-field label="{{ ::'pci_projects_project_edit_project_name' | translate }}" size="xl">
8+
<input class="oui-input" type="text" name="description" ng-model="$ctrl.project.description" required>
9+
</oui-field>
10+
<oui-field>
11+
<oui-checkbox
12+
name="isDefault"
13+
text="{{ ::'pci_projects_project_edit_default_project' | translate }}"
14+
description="{{ ::'pci_projects_project_edit_default_project_description' | translate }}"
15+
model="$ctrl.isDefault">
16+
</oui-checkbox>
17+
</oui-field>
18+
<oui-button variant="primary" type="submit" disabled="$ctrl.loading.submit">
19+
{{ ::'pci_projects_project_edit_update' | translate }}
20+
</oui-button>
21+
</form>
22+
<div class="mt-4 pt-4 border-top">
23+
<h2 data-translate="pci_projects_project_edit_remove"></h2>
24+
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla sit amet consequat turpis, at accumsan metus. Curabitur pellentesque condimentum mauris id iaculis. Sed id ex tristique, ornare tortor quis, bibendum lacus. Sed ornare elit eu malesuada auctor. Integer tempor nunc non tincidunt suscipit. Aenean faucibus, felis nec aliquet condimentum, est risus dapibus nibh, vel cursus massa mi sed nibh. Vivamus pulvinar arcu arcu, at consequat dui fermentum sed.</p>
25+
<oui-button variant="secondary" text="{{ ::'pci_projects_project_edit_remove' | translate }}" disabled="$ctrl.loading.submit"></oui-button>
26+
</div>
27+
</div>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import controller from './edit.controller';
2+
import template from './edit.html';
3+
4+
export default /* @ngInject */ ($stateProvider) => {
5+
$stateProvider
6+
.state('pci.projects.project.edit', {
7+
url: '/edit',
8+
views: {
9+
contentTab: {
10+
controller,
11+
controllerAs: '$ctrl',
12+
template,
13+
},
14+
},
15+
translations: {
16+
format: 'json',
17+
value: ['.'],
18+
},
19+
});
20+
};
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import angular from 'angular';
2+
3+
import '@ovh-ux/manager-core';
4+
import '@ovh-ux/ng-ovh-api-wrappers'; // should be a peer dependency of ovh-api-services
5+
import '@ovh-ux/ng-ovh-user-pref';
6+
import 'angular-translate';
7+
import 'ovh-api-services';
8+
import 'ovh-ui-angular';
9+
10+
import routing from './edit.routing';
11+
12+
const moduleName = 'ovhManagerPciProjectEdit';
13+
14+
angular
15+
.module(moduleName, [
16+
'ngOvhUserPref',
17+
'oui',
18+
'ovhManagerCore',
19+
'ovh-api-services',
20+
'pascalprecht.translate',
21+
])
22+
.config(routing);
23+
24+
export default moduleName;
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"pci_projects_project_edit_project_name": "Nom de projet",
3+
"pci_projects_project_edit_remove": "Supprimer le projet",
4+
"pci_projects_project_edit_default_project": "Projet par défaut",
5+
"pci_projects_project_edit_default_project_description": "Projet par défaut à chaque connexion à l'espace client Public Cloud",
6+
"pci_projects_project_edit_update": "Mettre à jour",
7+
"pci_projects_project_edit_update_success": "Le projet a été mis à jour.",
8+
"pci_projects_project_edit_update_error": "Une erreur est survenue lors de la mise à jour du projet ({{ error }})."
9+
}

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

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

99

10+
import edit from './edit';
1011
import instances from './instances';
1112
import kubernetes from './kubernetes';
1213
import legacy from './legacy';
@@ -17,6 +18,7 @@ const moduleName = 'ovhManagerPciProject';
1718

1819
angular
1920
.module(moduleName, [
21+
edit,
2022
instances,
2123
kubernetes,
2224
legacy,

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ import { ACTIONS, LINKS } from './project.constants';
22

33
export default class ProjectController {
44
/* @ngInject */
5-
constructor($stateParams, OvhApiCloudProject) {
5+
constructor($state, $stateParams, OvhApiCloudProject) {
6+
this.$state = $state;
67
this.$stateParams = $stateParams;
78
this.OvhApiCloudProject = OvhApiCloudProject;
89
this.loading = false;

packages/manager/modules/pci/src/projects/project/project.html

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,34 @@
22
<div data-ng-if="$ctrl.project">
33
<oui-page-header heading="{{ ::$ctrl.project.description }}">
44
<oui-header-tabs class="mt-3">
5-
<oui-header-tabs-item text="{{ ::'pci_projects_project_home' | translate }}" ui-sref="pci.projects.project({ serviceName: $ctrl.project.project_id })" active></oui-header-tabs-item>
6-
<oui-header-tabs-item text="{{ ::'pci_projects_project_parameters' | translate }}" ui-sref="pci.projects.project({ serviceName: $ctrl.project.project_id })" disabled></oui-header-tabs-item>
5+
<oui-header-tabs-item
6+
text="{{ ::'pci_projects_project_home' | translate }}"
7+
ui-sref="pci.projects.project({ serviceName: $ctrl.project.project_id })"
8+
active="$ctrl.$state.is('pci.projects.project')">
9+
</oui-header-tabs-item>
10+
<oui-header-tabs-item
11+
text="{{ ::'pci_projects_project_parameters' | translate }}"
12+
ui-sref="pci.projects.project.edit({ serviceName: $ctrl.project.project_id })"
13+
active="$ctrl.$state.is('pci.projects.project.edit', { serviceName: $ctrl.project.project_id })">
14+
</oui-header-tabs-item>
715
</oui-header-tabs>
816
</oui-page-header>
9-
<div class="p-5" data-ui-view>
17+
<div class="p-5" data-ui-view="contentTab">
1018
<div class="container-fluid px-0">
1119
<div class="row">
12-
<div class="col-sm-6 col-lg-4 col-xl mb-4 mb-xl-0" data-ng-repeat="action in $ctrl.actions track by $index">
20+
<div class="col-sm-6 col-lg-4 col-xl mb-4" data-ng-repeat="action in $ctrl.actions track by $index">
1321
<a class="text-center w-100 d-block oui-tile py-4" href="#">
1422
<span class="oui-icon oui-icon-add fa-2x" aria-hidden="true"></span>
1523
<div class="mt-3 w-100 text-truncate" data-ng-bind=":: action.translation | translate"></div>
1624
</a>
1725
</div>
1826
</div>
1927
<h2 data-translate="pci_projects_project_documentation"></h2>
20-
<oui-tile class="mt-xl-4" heading="{{ ::'' | translate }}">
21-
<oui-tile-button external data-ng-repeat="link in $ctrl.links track by $index" href="link.href">{{ ::link.translation | translate }}</oui-tile-button>
22-
</oui-tile>
28+
<ul>
29+
<li data-ng-repeat="link in $ctrl.links track by $index">
30+
<a data-ng-href="{{ ::link.href }}">{{ ::link.translation | translate }}</a>
31+
</li>
32+
</ul>
2333
</div>
2434
</div>
2535
</div>

0 commit comments

Comments
 (0)