Skip to content

Commit

Permalink
add "use as default" option for stream to stream pipe
Browse files Browse the repository at this point in the history
  • Loading branch information
Stefan Werfling committed Dec 29, 2022
1 parent e7b319d commit 10a0e7b
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 5 deletions.
3 changes: 3 additions & 0 deletions backend/src/Routes/Main/Route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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;
Expand Down
10 changes: 9 additions & 1 deletion backend/src/inc/Db/MariaDb/Entity/NginxStream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
2 changes: 1 addition & 1 deletion backend/src/inc/Service/NginxService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,7 @@ export class NginxService {
}
}

if (tstream.isdefault) {
if (tstream.isdefault || tstream.use_as_default) {
defaultMapDomain = upstreamName;
} else {
aMap.addVariable(`${domainName}`, upstreamName);
Expand Down
1 change: 1 addition & 0 deletions frontend/src/inc/Api/Route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
10 changes: 8 additions & 2 deletions frontend/src/inc/Pages/Routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: []
Expand Down Expand Up @@ -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 -----------------------------------------------------------------------------------

Expand All @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/inc/Pages/Routes/RouteHttpEditModal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ export class RouteHttpEditModal extends ModalDialog {
const bodyCardSsl = jQuery('<div class="card-body"/>').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);
Expand Down
27 changes: 27 additions & 0 deletions frontend/src/inc/Pages/Routes/RouteStreamEditModal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -361,6 +368,10 @@ export class RouteStreamEditModal extends ModalDialog {
// tab advanced ------------------------------------------------------------------------------------------------

const bodyCardAdvanced = jQuery('<div class="card-body"/>').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);

Expand Down Expand Up @@ -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
Expand All @@ -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('');
Expand Down

0 comments on commit 10a0e7b

Please sign in to comment.