Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(dedicated): add tags column and pop up #14837

Merged
merged 1 commit into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import template from './nodes.html';
import controller from './nodes.controller.js';

export default {
bindings: {
nodes: '<',
getNodeDashboardLink: '<',
},
template,
controller,
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import {
CONTROLLER_NAME as DISPLAY_TAG_POPUP_CONTROLLER,
TEMPLATE_CACHE_KEY as DISPLAY_TAG_POPUP_TEMPLATE,
} from '../../display-tags/display-tags.constants';

export default class ServersCtrl {
/* @ngInject */
constructor($uibModal) {
this.$uibModal = $uibModal;
}

getTags(tags) {
if (tags) {
this.tags = Object.keys(tags)
.filter((key) => !key.startsWith('ovh:'))
.map((key) => `${key}:${tags[key]}`);
}
return this.tags;
}

goToTagsModal(iamDetails) {
this.server_name = iamDetails.displayName;
this.server_tags = this.getTags(iamDetails.tags);
this.$uibModal.open({
templateUrl: DISPLAY_TAG_POPUP_TEMPLATE,
controller: DISPLAY_TAG_POPUP_CONTROLLER,
controllerAs: '$ctrl',
resolve: {
hasDefaultMeansOfPayment: () => this.hasDefaultMeansOfPayment,
itemName: () => this.servicePackToOrder?.displayName,
itemRef: () => this.servicePackToOrder?.name,
serverName: () => this.server_name,
serverTags: () => this.server_tags,
},
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@
class="oui-table__header"
data-translate="dedicated_servers_status"
></th>
<th
class="oui-table__header"
data-translate="dedicated_servers_tags"
></th>
</tr>
</thead>
<tbody>
Expand Down Expand Up @@ -58,6 +62,22 @@
data-translate="{{:: 'dedicated_servers_state_' + node.state }}"
></span>
</td>
<td class="oui-table__cell">
<span
data-ng-repeat="tag in $ctrl.getTags(node.iam.tags) | limitTo: 2"
>
<span class="oui-badge oui-badge_info" data-ng-bind="tag">
</span>
</span>
<button
type="button"
class="oui-link"
data-ng-if="$ctrl.getTags(node.iam.tags).length > 1"
data-ng-click="$ctrl.goToTagsModal(node.iam)"
>
...
</button>
</td>
</tr>
</tbody>
</table>
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export default {
currentActiveLink: '<',
clustersLink: '<',
allServersLink: '<',
editDetails: '<',
},
template,
};
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,19 @@ export default /* @ngInject */ ($stateProvider) => {
isMultiAZFeatureAvailable && clusters.data.length !== 0,
);
},
editDetails: /* @ngInject */ ($uibModal) => (data) => {
return $uibModal.open({
animation: true,
templateUrl: './components/name-edition/name-edition.html',
controller: 'NameEditionCtrl',
controllerAs: '$ctrl',
resolve: {
data: () => ({
...data,
}),
},
});
},
currentActiveLink: /* @ngInject */ ($transition$, $state) => () =>
$state.href($state.current.name, $transition$.params()),
allServersLink: /* @ngInject */ ($transition$, $state) =>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export const CONTROLLER_NAME = 'ovhManagerDedicatedServerDisplayTags';
export const TEMPLATE_CACHE_KEY = 'ovhManagerDedicatedServerDisplayTags.html';

export default {
CONTROLLER_NAME,
TEMPLATE_CACHE_KEY,
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
export default class {
/* @ngInject */
constructor($uibModalInstance, serverName, serverTags) {
this.$uibModalInstance = $uibModalInstance;
this.serverName = serverName;
this.serverTags = serverTags;
}

$onInit() {
this.serverTagList = this.serverTags;
}

onEditTags() {
this.$uibModalInstance.close();
this.$state.go('app.dedicated-server.server.tags');
}

onSearchServerTags(value) {
this.serverTagList = this.serverTags.filter((tag) =>
tag.toLowerCase().includes(value.toLowerCase()),
);
}

onSearchReset() {
this.serverTagList = [...this.serverTags];
}

back() {
this.$uibModalInstance.dismiss();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import controller from './display-tags.controller';
import template from './template.html';

import { CONTROLLER_NAME, TEMPLATE_CACHE_KEY } from './display-tags.constants';

const moduleName = 'ovhManagerDedicatedServerDisplayTags';

angular
.module(moduleName, [])
.controller(CONTROLLER_NAME, controller)
.run(/* @ngTranslationsInject:json ./translations */)
.run(
/* @ngInject */ ($templateCache) => {
$templateCache.put(TEMPLATE_CACHE_KEY, template);
},
);

export default moduleName;
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<oui-modal
data-on-dismiss="$ctrl.$uibModalInstance.dismiss()"
data-primary-action="$ctrl.onEditTags()"
data-primary-label="{{:: 'display_tags_popup_edit' | translate }}"
data-secondary-action="$ctrl.back()"
data-secondary-label="{{:: 'display_tags_popup_back' | translate }}"
data-heading="{{:: 'display_tags_popup_title' | translate:{ 'serverName': $ctrl.serverName } }}"
>
<div class="mb-4">
<oui-search
model="$ctrl.searchTag"
on-change="$ctrl.onSearchServerTags(modelValue)"
on-reset="$ctrl.onSearchReset()"
placeholder="{{ ::'display_tags_popup_search'| translate}}"
>
</oui-search>
</div>
<span data-ng-repeat="tag in $ctrl.serverTagList">
<span class="oui-badge oui-badge_info" data-ng-bind="tag"> </span>
</span>
</oui-modal>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"display_tags_popup_edit": "Modifier les balises",
"display_tags_popup_back": "Retour",
"display_tags_popup_search": "Rechercher",
"display_tags_popup_title": "Tags:"
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import angular from 'angular';

import displayTags from '../display-tags/index.js';
import '@ovh-ux/ng-translate-async-loader';
import '@uirouter/angularjs';
import 'oclazyload';
Expand All @@ -9,7 +9,7 @@ import onboarding from './onboarding';
const moduleName = 'ovhManagerDedicatedServerServersLazyLoading';

angular
.module(moduleName, ['ui.router', 'oc.lazyLoad', onboarding])
.module(moduleName, ['ui.router', 'oc.lazyLoad', onboarding, displayTags])
.config(
/* @ngInject */ ($stateProvider) => {
$stateProvider
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,18 @@ import set from 'lodash/set';
import snakeCase from 'lodash/snakeCase';

import { DC_2_ISO, MONITORING_STATUSES } from './servers.constants';
import {
CONTROLLER_NAME as DISPLAY_TAG_POPUP_CONTROLLER,
TEMPLATE_CACHE_KEY as DISPLAY_TAG_POPUP_TEMPLATE,
} from '../display-tags/display-tags.constants';

export default class ServersCtrl {
/* @ngInject */
constructor($q, $translate, ouiDatagridService) {
constructor($q, $state, $translate, $uibModal, ouiDatagridService) {
this.$q = $q;
this.$state = $state;
this.$translate = $translate;
this.$uibModal = $uibModal;
this.ouiDatagridService = ouiDatagridService;
}
// comment to use staging
Expand Down Expand Up @@ -40,6 +46,10 @@ export default class ServersCtrl {
this.dedicatedServers.data,
'commercialRange',
);

this.tagEnumFilter = this.getTagEnumFilterFromCustomerData(
this.dedicatedServers.data,
);
}

static toUpperSnakeCase(str) {
Expand Down Expand Up @@ -91,6 +101,19 @@ export default class ServersCtrl {
);
}

getTagEnumFilterFromCustomerData(data, prefix = null) {
return this.getEnumFilter(
data
.filter((server) => server.iam?.tags)
.map((server) => Object.keys(server.iam?.tags))
.filter((value, index, self) => {
return self.indexOf(value) === index;
}),
prefix,
false,
);
}

getEnumFilter(list, translationPrefix, toUpperSnakeCaseFlag = true) {
if (translationPrefix === null) {
return {
Expand Down Expand Up @@ -124,6 +147,32 @@ export default class ServersCtrl {
};
}

getTags(tags) {
if (tags) {
this.tags = Object.keys(tags)
.filter((key) => !key.startsWith('ovh:'))
.map((key) => `${key}:${tags[key]}`);
}
return this.tags;
}

goToTagsModal(iamDetails) {
this.server_name = iamDetails.displayName;
this.server_tags = this.getTags(iamDetails.tags);
this.$uibModal.open({
templateUrl: DISPLAY_TAG_POPUP_TEMPLATE,
controller: DISPLAY_TAG_POPUP_CONTROLLER,
controllerAs: '$ctrl',
resolve: {
hasDefaultMeansOfPayment: () => this.hasDefaultMeansOfPayment,
itemName: () => this.servicePackToOrder?.displayName,
itemRef: () => this.servicePackToOrder?.name,
serverName: () => this.server_name,
serverTags: () => this.server_tags,
},
});
}

loadServers() {
const currentOffset = this.paginationNumber * this.paginationSize;
set(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,25 @@
data-translate="{{:: 'server_configuration_state_' + $ctrl.constructor.toUpperSnakeCase($value) }}"
></span>
</oui-datagrid-column>
<oui-datagrid-column
data-title=":: 'dedicated_servers_tags' | translate"
data-property="iam.tags"
>
<span
class="oui-badge oui-badge_info"
data-ng-repeat="tag in $ctrl.getTags($row.iam.tags) | limitTo: 2"
data-ng-bind="tag"
>
</span>
<button
type="button"
class="oui-link"
data-ng-if="$ctrl.getTags($row.iam.tags).length > 1"
data-ng-click="$ctrl.goToTagsModal($row.iam)"
>
...
</button>
</oui-datagrid-column>
<oui-datagrid-column
data-title=":: 'dedicated_servers_monitoring' | translate"
data-property="monitoringStatus"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"dedicated_servers_datacenter": "Datacenter",
"dedicated_servers_country": "Pays",
"dedicated_servers_region": "Région",
"dedicated_servers_tags": "Tags",
"dedicated_servers_monitoring": "État Monitoring",
"dedicated_servers_popover_details": "Détails",
"dedicated_servers_button_server_order": "Commander un serveur dédié",
Expand Down
Loading