From 6e57213928db6a204c3c725b8d127948425697e5 Mon Sep 17 00:00:00 2001 From: Ligre Date: Mon, 19 Sep 2022 13:39:12 +0200 Subject: [PATCH] Bugs corrected. --- package.json | 2 +- .../dialog-new-route.component.ts | 43 ++++---- .../dialog-new-rsu.component.html | 79 ++++++++------- .../dialog-new-rsu.component.ts | 99 ++++++++++--------- .../routes/architect/architect.component.html | 2 +- .../routes/architect/architect.component.ts | 41 ++++---- src/assets/i18n/en.json | 2 +- src/assets/i18n/es.json | 2 +- 8 files changed, 148 insertions(+), 122 deletions(-) diff --git a/package.json b/package.json index c8f5e78..cdd8431 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "king", - "version": "3.0.0", + "version": "3.0.1", "scripts": { "ng": "ng", "start": "ng serve", diff --git a/src/app/components/dialog-new-route/dialog-new-route.component.ts b/src/app/components/dialog-new-route/dialog-new-route.component.ts index 53dced5..6fc4e3a 100644 --- a/src/app/components/dialog-new-route/dialog-new-route.component.ts +++ b/src/app/components/dialog-new-route/dialog-new-route.component.ts @@ -450,6 +450,11 @@ export class DialogNewRouteComponent implements OnInit, OnDestroy { btnExp(transform, field, op, value): void { let out = ''; + + value = value.replace(/"/g, '').replace(/'/g, ''); + // Si no tiene comillas dobles las añado + value = '"' + value + '"'; + if (field && op && value) { if (transform) { out = transform; @@ -525,25 +530,6 @@ export class DialogNewRouteComponent implements OnInit, OnDestroy { body.tags = []; } - // Si es http o https no admite sources y destionations - if (body.protocols.includes('http') || body.protocols.includes('https')) { - delete body.sources; - delete body.destinations; - } - // En caso de tcp, tls o udp no puede llevar methods, headers, paths o hosts - if (body.protocols.includes('tcp') || body.protocols.includes('tls') || body.protocols.includes('udp')) { - delete body.hosts; - delete body.methods; - delete body.paths; - delete body.headers; - } - // Para estos no hay que enviar strip_path, sources ni destinations - if (body.protocols.includes('grpc') || body.protocols.includes('grpcs')) { - delete body.strip_path; - delete body.sources; - delete body.destinations; - } - // Dependiendo del modo de router if (!this.expressions) { if (this.currentHosts && this.currentHosts.length > 0) { @@ -585,6 +571,25 @@ export class DialogNewRouteComponent implements OnInit, OnDestroy { } } + // Si es http o https no admite sources y destionations + if (body.protocols.includes('http') || body.protocols.includes('https')) { + delete body.sources; + delete body.destinations; + } + // En caso de tcp, tls o udp no puede llevar methods, headers, paths o hosts + if (body.protocols.includes('tcp') || body.protocols.includes('tls') || body.protocols.includes('udp')) { + delete body.hosts; + delete body.methods; + delete body.paths; + delete body.headers; + } + // Para estos no hay que enviar strip_path, sources ni destinations + if (body.protocols.includes('grpc') || body.protocols.includes('grpcs')) { + delete body.strip_path; + delete body.sources; + delete body.destinations; + } + return body; } } diff --git a/src/app/components/dialog-new-rsu/dialog-new-rsu.component.html b/src/app/components/dialog-new-rsu/dialog-new-rsu.component.html index 1571ce3..3dbcc50 100644 --- a/src/app/components/dialog-new-rsu/dialog-new-rsu.component.html +++ b/src/app/components/dialog-new-rsu/dialog-new-rsu.component.html @@ -83,39 +83,6 @@

- - - {{'route.dialog.methods' | translate}} - - {{method}} - - info_outline - - - - -
- - - - {{path}} - cancel - - - - info_outline - - {{'route.dialog.hosts_hint' | translate}} - -
{{'route.dialog.strip_path' | translate}} @@ -124,6 +91,52 @@

+ +
+ + + + {{'route.dialog.transform_' + proto | translate}} + {{'route.dialog.transform_' + proto | translate}} + + + + + {{ 'route.dialog.field_' + proto | translate}} + + + + + {{proto}} + {{proto}} + + + + + + + + + + + info_outline + +
+
+ + + {{'route.dialog.expression' | translate}} + + + {{ 'error.field_required' | translate }} + + +

{{'service.label' | translate}}

diff --git a/src/app/components/dialog-new-rsu/dialog-new-rsu.component.ts b/src/app/components/dialog-new-rsu/dialog-new-rsu.component.ts index 6f46668..ac17a76 100644 --- a/src/app/components/dialog-new-rsu/dialog-new-rsu.component.ts +++ b/src/app/components/dialog-new-rsu/dialog-new-rsu.component.ts @@ -8,6 +8,8 @@ import { isEmpty as _isEmpty, max as _max, min as _min, sortedUniq as _sortedUni import { AutoUnsubscribe } from 'ngx-auto-unsubscribe'; import { forkJoin } from 'rxjs'; import { ApiService } from '../../services/api.service'; +import { DialogHelperService } from '../../services/dialog-helper.service'; +import { GlobalsService } from '../../services/globals.service'; import { ToastService } from '../../services/toast.service'; import { CustomValidators } from '../../shared/custom-validators'; @@ -21,20 +23,25 @@ export class DialogNewRsuComponent implements OnInit, OnDestroy { // Uso la variable para el estado del formulario formValid = false; validProtocols = ['http', 'https']; - validMethods = ['GET', 'POST', 'PATCH', 'PUT', 'DELETE', 'HEAD', 'CONNECT', 'OPTIONS', 'TRACE']; allTags = []; currentTags = []; - currentPaths = []; + expressions = true; readonly separatorKeysCodes: number[] = [ENTER, COMMA]; + validETransforms = []; + validETransformsStrings = ['lower']; + validEFields = ['http.method', 'http.host', 'http.path', 'http.headers.header_name', 'net.protocol', 'net.port', 'tls.sni']; + validEOpsStrings = ['==', '!=', '~', '^=', '=^', 'in', 'not in']; + validEOpsIntegers = ['==', '!=', '>', '>=', '<', '<=']; + eType = 'string'; + form = this.fb.group({ name: ['', [Validators.required, Validators.pattern(/^[a-zA-Z0-9\-._~]+$/)]], tags: [''], route: this.fb.group({ protocols: ['', [Validators.required, CustomValidators.isProtocolListValidForRoute(this.validProtocols)]], - methods: ['', []], - paths: [''], + expression: ['', [Validators.required]], strip_path: [true] }), service: this.fb.group({ @@ -52,8 +59,7 @@ export class DialogNewRsuComponent implements OnInit, OnDestroy { paths_validation: [''] }, {validators: [FinalFormValidator()]}); - constructor(@Inject(MAT_DIALOG_DATA) public routeIdEdit: any, private fb: FormBuilder, private api: ApiService, private toast: ToastService, - public dialogRef: MatDialogRef) { } + constructor(@Inject(MAT_DIALOG_DATA) public routeIdEdit: any, private fb: FormBuilder, private api: ApiService, private globals: GlobalsService, private toast: ToastService, public dialogRef: MatDialogRef, private dialogHelper: DialogHelperService) { } /* Getters de campos del formulario @@ -74,21 +80,27 @@ export class DialogNewRsuComponent implements OnInit, OnDestroy { get routeProtocolsField() { return this.form.get('route.protocols'); } - get routeMethodsField() { return this.form.get('route.methods'); } + get routeExpressionField() { return this.form.get('route.expression'); } get targetsField() { return this.form.get('upstream.targets');} ngOnInit(): void { - // Lista de tags - this.api.getTags() - .subscribe((res) => { - // Recojo las tags - res['data'].forEach(data => { - this.allTags.push(data.tag); + this.dialogHelper.getRouterMode().then(() => { + // Si no estoy en modo expressions cambio la tabla + if (this.globals.ROUTER_MODE !== 'expressions') { + this.expressions = false; + } + // Lista de tags + this.api.getTags() + .subscribe((res) => { + // Recojo las tags + res['data'].forEach(data => { + this.allTags.push(data.tag); + }); + this.allTags.sort(); + this.allTags = _sortedUniq(this.allTags); }); - this.allTags.sort(); - this.allTags = _sortedUniq(this.allTags); - }); + }).catch(() => this.toast.error('error.route_mode')); } ngOnDestroy(): void { @@ -147,33 +159,33 @@ export class DialogNewRsuComponent implements OnInit, OnDestroy { this.currentTags.push($event.option.viewValue); } - /* - Gestión de rutas - */ - addPath(event: MatChipInputEvent): void { - const input = event.chipInput.inputElement; - const value = event.value.trim(); + btnAppend(txt): void { + if (txt) { + this.form.get('route.expression').setValue(this.form.get('route.expression').value + txt); + } + } - // Add - if ((value || '') && /^\//.test(value) && !/\/\//.test(value)) { - this.currentPaths.push(value); - this.form.get('paths_validation').setValue('true'); + btnExp(transform, field, op, value): void { + let out = ''; - // Reset the input value - if (input) { - input.value = ''; + value = value.replace(/"/g, '').replace(/'/g, ''); + // Si no tiene comillas dobles las añado + value = '"' + value + '"'; + + if (field && op && value) { + if (transform) { + out = transform; } + out += field + ' ' + op + ' ' + value; + this.form.get('route.expression').setValue(this.form.get('route.expression').value + out); } } - removePath(host): void { - const index = this.currentPaths.indexOf(host); - if (index >= 0) { - this.currentPaths.splice(index, 1); - if (this.currentPaths.length === 0) { - // Para poder consultar este campo en la validación final del formulario y saber si tiene algo - this.form.get('paths_validation').setValue(null); - } + changeEField(newField) { + if (newField === 'net.port') { + this.eType = 'int'; + } else { + this.eType = 'string'; } } @@ -184,16 +196,6 @@ export class DialogNewRsuComponent implements OnInit, OnDestroy { body.tags = []; } - if (this.currentPaths && this.currentPaths.length > 0) { - body.route.paths = this.currentPaths; - } else { - body.route.paths = []; - } - - if (_isEmpty(this.routeMethodsField.value)) { - body.route.methods = []; - } - // Cálculo de slots del upstream let slotis = body.upstream.targets * 100; slotis = _max([10, slotis]); @@ -216,8 +218,7 @@ export class DialogNewRsuComponent implements OnInit, OnDestroy { name: body.name, service: {id: ''}, protocols: body.route.protocols, - methods: body.route.methods, - paths: body.route.paths, + expression: body.route.expression, strip_path: body.route.strip_path, tags: body.tags }, diff --git a/src/app/routes/architect/architect.component.html b/src/app/routes/architect/architect.component.html index fa3982b..c192dc8 100644 --- a/src/app/routes/architect/architect.component.html +++ b/src/app/routes/architect/architect.component.html @@ -81,7 +81,7 @@
{{'architect.global_actions' | translate}}
- +