Skip to content

Commit

Permalink
feat(octavia): add pool edition view
Browse files Browse the repository at this point in the history
ref: MANAGER-12302

Signed-off-by: Jacques Larique <[email protected]>
  • Loading branch information
Jacques Larique committed Nov 30, 2023
1 parent 0f8a777 commit 6e3efc4
Show file tree
Hide file tree
Showing 23 changed files with 259 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,19 @@ export const DEFAULT_SESSION_PERSISTENCE_TYPE = 'sourceIP';

export const APP_COOKIE_SESSION_PERSISTENCE = 'appCookie';

export const PROTOCOL_SESSION_PERSISTENCE_TYPE_COMBINATION = {
http: ['sourceIP', 'httpCookie', 'appCookie'],
https: ['sourceIP', 'httpCookie', 'appCookie'],
tcp: ['sourceIP', 'httpCookie', 'appCookie'],
proxy: ['sourceIP', 'httpCookie', 'appCookie'],
proxyV2: ['sourceIP', 'httpCookie', 'appCookie'],
udp: ['sourceIP'],
sctp: ['sourceIP'],
};

export default {
DEFAULT_ALGORITHM,
DEFAULT_SESSION_PERSISTENCE_TYPE,
APP_COOKIE_SESSION_PERSISTENCE,
PROTOCOL_SESSION_PERSISTENCE_TYPE_COMBINATION,
};
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,32 @@ import {
DEFAULT_ALGORITHM,
DEFAULT_SESSION_PERSISTENCE_TYPE,
APP_COOKIE_SESSION_PERSISTENCE,
PROTOCOL_SESSION_PERSISTENCE_TYPE_COMBINATION,
} from './constants';

export default class OctaviaLoadBalancerPoolFormCtrl {
$onInit() {
this.APP_COOKIE_SESSION_PERSISTENCE = APP_COOKIE_SESSION_PERSISTENCE;
this.model.algorithm =
this.model.algorithm ||
this.algorithms.find(
(algorithm) => algorithm.value === DEFAULT_ALGORITHM,
this.model.algorithm = this.algorithms.find((algorithm) =>
this.model.algorithm
? algorithm.value ===
(this.model.algorithm.value || this.model.algorithm)
: algorithm.value === DEFAULT_ALGORITHM,
);
if (this.model.persistentSession && this.model.persistentSession.type) {
this.model.persistentSession = this.sessionPersistenceTypes.find(
(session) => session.value === this.model.persistentSession.type,
);
}
this.availableSessionPersistenceTypes = this.getFilteredSessionPersistenceTypes(
this.model.protocol,
);
}

onProtocolChange(protocol) {
this.availableSessionPersistenceTypes = this.getFilteredSessionPersistenceTypes(
protocol,
);
}

onHasSessionChange(hasSession) {
Expand All @@ -29,4 +45,15 @@ export default class OctaviaLoadBalancerPoolFormCtrl {
this.model.cookieName = undefined;
}
}

getFilteredSessionPersistenceTypes(protocol) {
return this.sessionPersistenceTypes.filter(
(type) =>
type.value !== 'disabled' &&
(!protocol ||
PROTOCOL_SESSION_PERSISTENCE_TYPE_COMBINATION[protocol].includes(
type.value,
)),
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
<oui-select
name="algorithm"
data-required
data-disabled="$ctrl.isEditing"
data-match="label"
data-model="$ctrl.model.algorithm"
data-items="$ctrl.algorithms"
Expand All @@ -51,6 +50,7 @@
data-disabled="$ctrl.isEditing"
data-model="$ctrl.model.protocol"
data-items="$ctrl.protocols"
data-on-change="$ctrl.onProtocolChange(modelValue)"
data-placeholder="{{:: 'octavia_load_balancer_pools_create_protocol_default' | translate }}"
>
</oui-select>
Expand Down Expand Up @@ -79,7 +79,7 @@
data-required
data-model="$ctrl.model.persistentSession"
data-match="label"
data-items="$ctrl.sessionPersistenceTypes"
data-items="$ctrl.availableSessionPersistenceTypes"
data-on-change="$ctrl.onPersistentSessionTypeChange(modelValue)"
>
</oui-select>
Expand Down Expand Up @@ -108,7 +108,7 @@
</fieldset>
<oui-form-actions
data-disabled="!listener.$valid"
data-submit-text="{{:: 'octavia_load_balancer_pools_create_submit' | translate }}"
data-submit-text="{{:: 'octavia_load_balancer_pools_create_submit' + ($ctrl.isEditing ? '_edition' : '') | translate }}"
data-cancel-text="{{:: 'octavia_load_balancer_pools_create_cancel' | translate }}"
data-on-submit="$ctrl.onSubmit()"
data-on-cancel="$ctrl.onCancel()"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@
"octavia_load_balancer_pools_create_persistent_session_appCookie": "Persistance de session basée sur le cookie d'application.",
"octavia_load_balancer_pools_create_persistent_session_cookie_name": "Nom du cookie",
"octavia_load_balancer_pools_create_cancel": "Annuler",
"octavia_load_balancer_pools_create_submit": "Ajouter"
"octavia_load_balancer_pools_create_submit": "Ajouter",
"octavia_load_balancer_pools_create_submit_edition": "Editer"
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ export default {
projectId: '<',
region: '<',
loadbalancerId: '<',
pools: '<',
algorithms: '<',
poolProtocols: '<',
sessionPersistenceTypes: '<',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export default {
bindings: {
pool: '<',
listener: '<',
goToPoolEdition: '<',
goToEditName: '<',
goToDelete: '<',
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export default class OctaviaLoadBalancerEditNameCtrl {

update() {
this.isLoading = true;
this.OctaviaLoadBalancerPoolsService.updateName(
this.OctaviaLoadBalancerPoolsService.editPool(
this.projectId,
this.region,
this.pool.id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ export default /* @ngInject */ ($stateProvider) => {
loadbalancerPoolsDetailView: 'octaviaLoadBalancerPoolsDetailOverview',
},
resolve: {
breadcrumb: /* @ngInject */ () => 'General informations',
breadcrumb: /* @ngInject */ ($translate) =>
$translate.instant('load_balancer_pools_detail_info_tab_title'),
goToEditName: /* @ngInject */ ($state) => () =>
$state.go(
'octavia-load-balancer.loadbalancer.pools.detail.general-information.edit-name',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
<oui-tile
data-heading="{{ 'octavia_load_balancer_pools_detail_overview_management_title' | translate }}"
>
<oui-tile-button data-on-click="$ctrl.goToEdit()">
<oui-tile-button
data-on-click="$ctrl.goToPoolEdition($ctrl.pool)"
>
<span
data-translate="octavia_load_balancer_pools_detail_overview_management_edit"
></span>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import controller from './controller';
import template from './template.html';

export default {
bindings: {
projectId: '<',
region: '<',
poolId: '<',
pool: '<',
algorithms: '<',
poolProtocols: '<',
sessionPersistenceTypes: '<',
trackEditAction: '<',
trackEditPage: '<',
goBack: '<',
},
controller,
template,
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export const TRACKING_HIT_PREFIX = 'edit';

export default {
TRACKING_HIT_PREFIX,
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
export default class OctaviaLoadBalancerPoolsEditCtrl {
/* @ngInject */
constructor(OctaviaLoadBalancerPoolsService, Alerter, $translate) {
this.OctaviaLoadBalancerPoolsService = OctaviaLoadBalancerPoolsService;
this.Alerter = Alerter;
this.$translate = $translate;
}

$onInit() {
this.loading = false;
this.model = {
name: this.pool.name,
algorithm: this.pool.algorithm,
protocol: this.pool.protocol,
persistentSession: this.pool.sessionPersistence,
cookieName: this.pool.sessionPersistence.cookieName,
hasSession: this.pool.sessionPersistence.type !== 'disabled',
};
}

submit() {
this.loading = true;
this.trackEditAction('confirm');
const sessionPersistence = this.model.hasSession
? {
type: this.model.persistentSession.value,
cookieName: this.model.cookieName,
}
: undefined;
this.OctaviaLoadBalancerPoolsService.editPool(
this.projectId,
this.region,
this.poolId,
this.model.name,
this.model.algorithm.value,
sessionPersistence,
)
.then(async () => {
this.trackEditPage('success');
this.Alerter.set(
'alert-success',
this.$translate.instant('octavia_load_balancer_pools_edit_success', {
pool: this.model.name,
}),
null,
'octavia.alerts.global',
);
await this.goBack(true);
})
.catch((error) => {
this.trackEditPage('error');
this.Alerter.error(
this.$translate.instant('octavia_load_balancer_global_error', {
message: error.data?.message,
requestId: error.headers('X-Ovh-Queryid'),
}),
'octavia.alerts.global',
);
})
.finally(() => {
this.loading = false;
});
}

cancel() {
this.trackEditAction('cancel');
this.goBack();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import angular from 'angular';
import '@uirouter/angularjs';
import 'oclazyload';

const moduleName = 'ovhManagerOctaviaLoadBalancerDashboardPoolsEditLazyLoading';

angular.module(moduleName, ['ui.router', 'oc.lazyLoad']).config(
/* @ngInject */ ($stateProvider) => {
$stateProvider.state('octavia-load-balancer.loadbalancer.pools.edit.**', {
url: '/:poolId/edit',
lazyLoad: ($transition$) => {
const $ocLazyLoad = $transition$.injector().get('$ocLazyLoad');

return import('./module').then((mod) =>
$ocLazyLoad.inject(mod.default || mod),
);
},
});
},
);

export default moduleName;
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import angular from 'angular';

import component from './component';
import routing from './routing';

import poolComponents from '../components';

const moduleName = 'ovhManagerOctaviaLoadBalancerPoolsEdit';

angular
.module(moduleName, [poolComponents])
.config(routing)
.component('octaviaLoadBalancerPoolsEdit', component);

export default moduleName;
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { TRACKING_HIT_PREFIX } from './constants';
import { TRACKING_SUFFIX } from '../constants';
import { TRACKING_NAME } from '../../constants';

export default /* @ngInject */ ($stateProvider) => {
$stateProvider.state('octavia-load-balancer.loadbalancer.pools.edit', {
url: '/:poolId/edit',
views: {
loadbalancerPoolsView: 'octaviaLoadBalancerPoolsEdit',
},
resolve: {
breadcrumb: () => null,
poolId: /* @ngInject */ ($transition$) => $transition$.params().poolId,
pool: /* @ngInject */ (
OctaviaLoadBalancerPoolsService,
projectId,
region,
poolId,
) => OctaviaLoadBalancerPoolsService.getPool(projectId, region, poolId),
goBack: /* @ngInject */ ($state, poolId) => (reload) =>
$state.go(
'octavia-load-balancer.loadbalancer.pools.detail',
{
poolId,
},
reload
? { reload: 'octavia-load-balancer.loadbalancer.pools.detail' }
: null,
),
trackEditAction: /* @ngInject */ (trackAction) => (hit) =>
trackAction(`${TRACKING_HIT_PREFIX}::${hit}`),
trackEditPage: /* @ngInject */ (trackPage) => (hit) =>
trackPage(`${TRACKING_HIT_PREFIX}-${hit}`),
},
atInternet: {
rename: `${TRACKING_NAME}::${TRACKING_SUFFIX}::${TRACKING_HIT_PREFIX}`,
},
});
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<div class="text-center" data-ng-if="$ctrl.loading">
<oui-spinner></oui-spinner>
</div>

<octavia-load-balancer-pool-form
data-ng-if="!$ctrl.loading"
data-algorithms="$ctrl.algorithms"
data-protocols="$ctrl.poolProtocols"
data-session-persistence-types="$ctrl.sessionPersistenceTypes"
data-model="$ctrl.model"
data-is-editing="true"
data-on-submit="$ctrl.submit()"
data-on-cancel="$ctrl.cancel()"
></octavia-load-balancer-pool-form>
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@ import template from './template.html';

export default {
bindings: {
projectId: '<',
region: '<',
pools: '<',
goToPoolCreation: '<',
getPoolDetailLink: '<',
goToPoolEdition: '<',
goToPoolDeletion: '<',
},
controller,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@
></span>
</oui-datagrid-column>
<oui-action-menu compact data-placement="end">
<oui-action-menu-item data-on-click="$ctrl.goToPoolFromElipsis($row)"
<oui-action-menu-item data-on-click="$ctrl.goToPoolEdition($row)"
><span
data-translate="octavia_load_balancer_pools_actions_detail"
data-translate="octavia_load_balancer_pools_actions_edit"
></span>
</oui-action-menu-item>
<oui-action-menu-item data-on-click="$ctrl.goToManageMembers($row)"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"octavia_load_balancer_pools_provisioning_status_deleting": "en cours de suppression",
"octavia_load_balancer_pools_provisioning_status_error": "erreur",
"octavia_load_balancer_pools_provisioning_status_updating": "en cours de mise à jour",
"octavia_load_balancer_pools_actions_detail": "Editer/Voir",
"octavia_load_balancer_pools_actions_edit": "Editer",
"octavia_load_balancer_pools_actions_manage_members": "Gérer les membres",
"octavia_load_balancer_pools_actions_delete": "Supprimer"
}
Loading

0 comments on commit 6e3efc4

Please sign in to comment.