diff --git a/package.json b/package.json index 3d7f5ae..519b952 100644 --- a/package.json +++ b/package.json @@ -60,6 +60,7 @@ "eslint-plugin-prettier": "^4.0.0", "jasmine-core": "^4.0.1", "jasmine-spec-reporter": "^7.0.0", + "jsonc-parser": "^3.3.1", "karma": "^6.3.17", "karma-chrome-launcher": "^3.1.0", "karma-coverage-istanbul-reporter": "^3.0.3", diff --git a/src/app/gui/components/service/service.component.ts b/src/app/gui/components/service/service.component.ts index 8967d81..9a79809 100644 --- a/src/app/gui/components/service/service.component.ts +++ b/src/app/gui/components/service/service.component.ts @@ -93,7 +93,7 @@ export class ServiceComponent implements OnInit { this.api.gui.alert('

' + django.gettext('Launcher') + '

', message); } - async launch(transport: JSONTransport|null) { + async launch(transport: JSONTransport | null) { if (this.service.maintenance) { this.notifyNotLaunching(django.gettext('Service is in maintenance and cannot be launched')); } else if (this.service.not_accesible) { @@ -112,28 +112,29 @@ export class ServiceComponent implements OnInit { transport = this.service.transports[0]; } if (this.service.custom_message_text !== null && this.service.custom_message_text !== undefined) { + const tr = transport; if ((await this.api.gui.yesno(django.gettext('Service message'), this.service.custom_message_text)) === false) { return; } + console.debug('Launching service with transport', tr); } this.api.executeCustomJSForServiceLaunch(); this.api.launchURL(transport.link); } } - action(type: string) { + async action(type: string) { const title = (type === 'release' ? django.gettext('Release service: ') : django.gettext('Reset service: ')) + ' ' + this.serviceName; const action = type === 'release' ? django.gettext('Service released') : django.gettext('Service reseted'); - this.api.gui.yesno(title, django.gettext('Are you sure?')).then((val) => { - if (val) { - this.api.action(type, this.service.id).then((service) => { - if (service) { - this.api.gui.alert(title, action); - } - }); + if ((await this.api.gui.yesno(title, django.gettext('Are you sure?'))) === false) { + return; + } + this.api.action(type, this.service.id).then((service) => { + if (service) { + this.api.gui.alert(title, action); } }); } diff --git a/src/app/gui/modal/modal.component.ts b/src/app/gui/modal/modal.component.ts index aa63e17..ceb2eb6 100644 --- a/src/app/gui/modal/modal.component.ts +++ b/src/app/gui/modal/modal.component.ts @@ -1,7 +1,8 @@ /* eslint-disable no-shadow */ import { Component, OnInit, Inject } from '@angular/core'; import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog'; -import { interval, Subscription, Observable } from 'rxjs'; +import { interval } from 'rxjs'; +import { Future } from '../../helpers/tools'; export enum DialogType { alert = 0, @@ -25,19 +26,17 @@ export interface ModalData { }) export class ModalComponent implements OnInit { extra = ''; - subscription: Subscription | null = null; - yesno: Promise = new Promise((resolve) => (this.resolver = resolve)); + yesno: Future = new Future(); constructor(public dialogRef: MatDialogRef, @Inject(MAT_DIALOG_DATA) public data: ModalData) { // Notifies on case of yes or not to subscriber } resolveAndClose(value: boolean): void { - this.resolver(value); + this.yesno.resolve(value); this.close(); } - resolver: (value: boolean) => void = () => {}; - + close() { this.dialogRef.close(); } diff --git a/src/app/pages/login/login.component.ts b/src/app/pages/login/login.component.ts index 1fff293..81b1005 100644 --- a/src/app/pages/login/login.component.ts +++ b/src/app/pages/login/login.component.ts @@ -51,7 +51,7 @@ export class LoginComponent implements OnInit { // Ejecuted when custom auth selected const doCustomAuth = (data: string) => { // eslint-disable-next-line no-eval - eval(data); + this.api.eval(data); }; for (const l of this.auths) { diff --git a/src/app/services/uds-api.service.ts b/src/app/services/uds-api.service.ts index e016307..a4f97aa 100644 --- a/src/app/services/uds-api.service.ts +++ b/src/app/services/uds-api.service.ts @@ -24,6 +24,8 @@ const DARK_THEME = 'dark-theme'; const LIGHT_THEME = 'light-theme'; const TIMEOUT = 10000; +const EVAL_FNC = eval; + @Injectable() export class UDSApiService implements UDSApiServiceType { readonly user: User; @@ -158,8 +160,7 @@ export class UDSApiService implements UDSApiServiceType { // Executes a defined JS on launch servic event if defined // this is in fact a hook if (udsData.custom_js_for_service_launch !== undefined) { - // eslint-disable-next-line no-eval - eval(udsData.custom_js_for_service_launch); + this.eval(udsData.custom_js_for_service_launch); } } @@ -236,4 +237,9 @@ export class UDSApiService implements UDSApiServiceType { return null; } } + + eval(data: string): void { + // eslint-disable-next-line no-eval + EVAL_FNC(data); + } } diff --git a/src/styles.scss b/src/styles.scss index 64d0d9a..e949cac 100644 --- a/src/styles.scss +++ b/src/styles.scss @@ -5,9 +5,6 @@ /* Default, light theme */ @include mat.all-component-themes($angular-default-theme); -/* Cookie consent */ -@import 'cookieconsent/build/cookieconsent.min.css'; - // variables $font-family: 'Roboto', 'Helvetica', 'Arial', sans-serif; //$font-family: Verdana, Geneva, Tahoma, sans-serif;