From 10a0e7b407a6a1e67e9799dea52458f29cda64c0 Mon Sep 17 00:00:00 2001 From: Stefan Werfling Date: Thu, 29 Dec 2022 12:58:49 +0100 Subject: [PATCH] add "use as default" option for stream to stream pipe --- backend/src/Routes/Main/Route.ts | 3 +++ .../src/inc/Db/MariaDb/Entity/NginxStream.ts | 10 ++++++- backend/src/inc/Service/NginxService.ts | 2 +- frontend/src/inc/Api/Route.ts | 1 + frontend/src/inc/Pages/Routes.ts | 10 +++++-- .../inc/Pages/Routes/RouteHttpEditModal.ts | 2 +- .../inc/Pages/Routes/RouteStreamEditModal.ts | 27 +++++++++++++++++++ 7 files changed, 50 insertions(+), 5 deletions(-) diff --git a/backend/src/Routes/Main/Route.ts b/backend/src/Routes/Main/Route.ts index 76e7bca..f9ee1e0 100644 --- a/backend/src/Routes/Main/Route.ts +++ b/backend/src/Routes/Main/Route.ts @@ -46,6 +46,7 @@ export type RouteStream = { alias_name: string; index: number; isdefault: boolean; + use_as_default: boolean; load_balancing_algorithm: string; ssh_r_type: number; ssh?: RouteStreamSSH; @@ -237,6 +238,7 @@ export class Route { alias_name: tstream.alias_name, index: tstream.index, isdefault: tstream.isdefault, + use_as_default: tstream.use_as_default, load_balancing_algorithm: tstream.load_balancing_algorithm, destination_type: tstream.destination_type, ssh_r_type: tstream.ssh_r_type, @@ -647,6 +649,7 @@ export class Route { aStream.destination_type = request.stream.destination_type; aStream.destination_listen_id = request.stream.destination_listen_id; + aStream.use_as_default = request.stream.use_as_default; aStream.load_balancing_algorithm = request.stream.load_balancing_algorithm; aStream.ssh_r_type = NginxStreamSshR.none; aStream.sshport_id = 0; diff --git a/backend/src/inc/Db/MariaDb/Entity/NginxStream.ts b/backend/src/inc/Db/MariaDb/Entity/NginxStream.ts index d430495..5a748f6 100644 --- a/backend/src/inc/Db/MariaDb/Entity/NginxStream.ts +++ b/backend/src/inc/Db/MariaDb/Entity/NginxStream.ts @@ -93,13 +93,21 @@ export class NginxStream extends BaseEntity { public alias_name!: string; /** - * is default + * is default (by setup) */ @Column({ default: false }) public isdefault!: boolean; + /** + * use this stream as default + */ + @Column({ + default: false + }) + public use_as_default!: boolean; + /** * ssh r type */ diff --git a/backend/src/inc/Service/NginxService.ts b/backend/src/inc/Service/NginxService.ts index 900fe8d..60524fa 100644 --- a/backend/src/inc/Service/NginxService.ts +++ b/backend/src/inc/Service/NginxService.ts @@ -498,7 +498,7 @@ export class NginxService { } } - if (tstream.isdefault) { + if (tstream.isdefault || tstream.use_as_default) { defaultMapDomain = upstreamName; } else { aMap.addVariable(`${domainName}`, upstreamName); diff --git a/frontend/src/inc/Api/Route.ts b/frontend/src/inc/Api/Route.ts index 7c866f2..51c32f6 100644 --- a/frontend/src/inc/Api/Route.ts +++ b/frontend/src/inc/Api/Route.ts @@ -60,6 +60,7 @@ export type RouteStream = { alias_name: string; index: number; isdefault: boolean; + use_as_default: boolean; load_balancing_algorithm: string; ssh_r_type: number; ssh?: RouteStreamSSH; diff --git a/frontend/src/inc/Pages/Routes.ts b/frontend/src/inc/Pages/Routes.ts index 432fee0..da31314 100644 --- a/frontend/src/inc/Pages/Routes.ts +++ b/frontend/src/inc/Pages/Routes.ts @@ -116,6 +116,7 @@ export class Routes extends BasePage { listen_id: this._routeStreamDialog.getListen(), destination_listen_id: 0, destination_type: this._routeStreamDialog.getDestinatonType(), + use_as_default: this._routeStreamDialog.getUseAsDefault(), ssh_r_type: NginxStreamSshR.none, load_balancing_algorithm: this._routeStreamDialog.getLoadBalancingAlgorithm(), upstreams: [] @@ -485,8 +486,12 @@ export class Routes extends BasePage { // options td ---------------------------------------------------------------------------------- - // eslint-disable-next-line no-new - new Td(trbody, ''); + const soptionTd = new Td(trbody, ''); + + if (value.use_as_default) { + new Badge(soptionTd, 'D', BadgeType.danger); + soptionTd.append(' '); + } // action td ----------------------------------------------------------------------------------- @@ -512,6 +517,7 @@ export class Routes extends BasePage { this._routeStreamDialog.setListen(`${value.listen_id}`); this._routeStreamDialog.setAliasName(value.alias_name); this._routeStreamDialog.setDestinationType(value.destination_type); + this._routeStreamDialog.setUseAsDefault(value.use_as_default); this._routeStreamDialog.setLoadBalancingAlgorithm(value.load_balancing_algorithm); if (value.index > 0) { diff --git a/frontend/src/inc/Pages/Routes/RouteHttpEditModal.ts b/frontend/src/inc/Pages/Routes/RouteHttpEditModal.ts index 4e96f70..80ffad5 100644 --- a/frontend/src/inc/Pages/Routes/RouteHttpEditModal.ts +++ b/frontend/src/inc/Pages/Routes/RouteHttpEditModal.ts @@ -229,7 +229,7 @@ export class RouteHttpEditModal extends ModalDialog { const bodyCardSsl = jQuery('
').appendTo(tabSsl.body); const groupSslEnable = new FormGroup(bodyCardSsl, 'SSL Enable'); - this._switchSslEnable = new Switch(groupSslEnable.getElement(), 'ssl_enable'); + this._switchSslEnable = new Switch(groupSslEnable, 'ssl_enable'); const groupSslProvider = new FormGroup(bodyCardSsl, 'SSL Provider'); this._selectSslProvider = new SelectBottemBorderOnly2(groupSslProvider); diff --git a/frontend/src/inc/Pages/Routes/RouteStreamEditModal.ts b/frontend/src/inc/Pages/Routes/RouteStreamEditModal.ts index cd2b1b8..3a6cd01 100644 --- a/frontend/src/inc/Pages/Routes/RouteStreamEditModal.ts +++ b/frontend/src/inc/Pages/Routes/RouteStreamEditModal.ts @@ -7,6 +7,7 @@ import {Card, CardBodyType} from '../../Bambooo/Content/Card/Card'; import {FormGroup} from '../../Bambooo/Content/Form/FormGroup'; import {InputBottemBorderOnly2, InputType} from '../../Bambooo/Content/Form/InputBottemBorderOnly2'; import {SelectBottemBorderOnly2} from '../../Bambooo/Content/Form/SelectBottemBorderOnly2'; +import {Switch} from '../../Bambooo/Content/Form/Switch'; import {NavTab} from '../../Bambooo/Content/Tab/NavTab'; import {Element} from '../../Bambooo/Element'; import {ModalDialog, ModalDialogType} from '../../Bambooo/Modal/ModalDialog'; @@ -178,6 +179,12 @@ export class RouteStreamEditModal extends ModalDialog { */ protected _selectDestinationListen: SelectBottemBorderOnly2; + /** + * use the stream as default + * @protected + */ + protected _switchUseAsDefault: Switch; + /** * load balancing algorithm * @protected @@ -361,6 +368,10 @@ export class RouteStreamEditModal extends ModalDialog { // tab advanced ------------------------------------------------------------------------------------------------ const bodyCardAdvanced = jQuery('
').appendTo(tabAdvanced.body); + + const groupUseAsDefault = new FormGroup(bodyCardAdvanced, 'Use as default stream'); + this._switchUseAsDefault = new Switch(groupUseAsDefault, 'use_as_default'); + const groupLoadBalanceAlg = new FormGroup(bodyCardAdvanced, 'Load balancing algorithm'); this._selectLoadBalanceAlg = new SelectBottemBorderOnly2(groupLoadBalanceAlg); @@ -750,6 +761,21 @@ export class RouteStreamEditModal extends ModalDialog { return this._inputSshDesAddress.getValue(); } + /** + * setUseAsDefault + * @param asdefault + */ + public setUseAsDefault(asdefault: boolean): void { + this._switchUseAsDefault.setEnable(asdefault); + } + + /** + * getUseAsDefault + */ + public getUseAsDefault(): boolean { + return this._switchUseAsDefault.isEnable(); + } + /** * setLoadBalancingAlgorithm * @param alg @@ -776,6 +802,7 @@ export class RouteStreamEditModal extends ModalDialog { this.setListen('0'); this.setDestinationType(NginxStreamDestinationType.listen); this.setSshRType(NginxStreamSshR.none); + this.setUseAsDefault(false); this._inputSshPort.setValue(''); this._navTab.setTabSelect(0); this._inputSshPassword.setPlaceholder('');