1
0
mirror of https://github.com/dkmstr/openuds-gui.git synced 2024-10-26 08:55:23 +03:00

fixed all eslint "complains"

This commit is contained in:
Adolfo Gómez García 2021-04-07 14:05:55 +02:00
parent f26a0c2e68
commit ea13e330ea
20 changed files with 279 additions and 257 deletions

View File

@ -1,37 +0,0 @@
/* I prefer to use JavaScript file because i can write comment and other can understand it.
if you wish to use .eslintrc without js extension,then you need to remove all the comments and
its looks just like { ..eslint config as below} without module.export
*/
module.exports={
"root": true,
"parser": "@typescript-eslint/parser", // we are changing default parser
"parserOptions": {
"ecmaVersion": 2018,
"sourceType": "module",
"project": "./tsconfig.json" // path to tsconfig
},
/* A plugin provides you with a set of rules that you can
individually apply depending on your need.
Just having a plugin does not enforce any rule.
You have to choose which rules you need.
A plugin may provide you with zero, one, or more configuration files.
If the plugin provides a configuration file, then you can load
that in your extends section after adding the plugin in the plugins section.
*/
"plugins": ["@typescript-eslint"],
/* extends uses a config file which applies set of rules
when you add that to the extends options. */
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended",
],
"rules": {
},
"overrides": [
]
}

View File

@ -1,4 +1,6 @@
{ {
"python.linting.enabled": true, "python.linting.enabled": true,
"python.pythonPath": "/usr/bin/python3" "python.pythonPath": "/usr/bin/python3",
} "prettier.singleQuote": true,
"typescript.preferences.quoteStyle": "single"
}

View File

@ -124,17 +124,6 @@
"protractorConfig": "./protractor.conf.js", "protractorConfig": "./protractor.conf.js",
"devServerTarget": "uds:serve" "devServerTarget": "uds:serve"
} }
},
"lint": {
"builder": "@angular-devkit/build-angular:tslint",
"options": {
"tsConfig": [
"e2e/tsconfig.e2e.json"
],
"exclude": [
"**/node_modules/**"
]
}
} }
} }
} }

View File

@ -5,9 +5,9 @@
"scripts": { "scripts": {
"ng": "ng", "ng": "ng",
"f4xstart": "ng serve --host 0.0.0.0 --port 9000 --proxy-config proxy.conf.json", "f4xstart": "ng serve --host 0.0.0.0 --port 9000 --proxy-config proxy.conf.json",
"f4xbuild": "ng build --prod --output-hashing=none --aot=false --deleteOutputPath --build-optimizer=false --deploy-url /uds/res/modern/ --base-href /uds/page && yarn postbuild", "f4xbuild": "ng build --prod --output-hashing=none --aot=false --delete-output-path --build-optimizer=false --deploy-url /uds/res/modern/ --base-href /uds/page && yarn postbuild",
"start": "ng serve --host 0.0.0.0 --port 9000 --proxy-config proxy.conf.json", "start": "ng serve --host 0.0.0.0 --port 9000 --proxy-config proxy.conf.json",
"build": "ng build --prod --output-hashing=none --aot --deleteOutputPath --build-optimizer --deploy-url /uds/res/modern/ --base-href /uds/page", "build": "ng build --prod --output-hashing=none --aot --delete-output-path --build-optimizer --deploy-url /uds/res/modern/ --base-href /uds/page",
"postbuild": "python3 toUDS.py", "postbuild": "python3 toUDS.py",
"test": "ng test", "test": "ng test",
"lint": "ng lint", "lint": "ng lint",

View File

@ -1,8 +1,8 @@
import { Component, OnInit } from '@angular/core'; import { Component, OnInit } from '@angular/core';
// External // External
declare var django: any; declare const django: any;
declare var cookieconsent: any; declare const cookieconsent: any;
@Component({ @Component({
@ -15,19 +15,19 @@ export class AppComponent implements OnInit {
ngOnInit() { ngOnInit() {
cookieconsent.initialise({ cookieconsent.initialise({
'palette': { palette: {
'popup': { popup: {
'background': '#343c66', background: '#343c66',
'text': '#cfcfe8' text: '#cfcfe8'
}, },
'button': { button: {
'background': '#f71559' background: '#f71559'
} }
}, },
'content': { content: {
'message': django.gettext('We use cookies to track usage and preferences'), message: django.gettext('We use cookies to track usage and preferences'),
'dismiss': django.gettext('I Understand'), dismiss: django.gettext('I Understand'),
'link': django.gettext('Learn more') link: django.gettext('Learn more')
} }
}); });
} }

View File

@ -22,7 +22,7 @@ export class FilterComponent implements AfterViewInit {
filter(Boolean), filter(Boolean),
debounceTime(600), debounceTime(600),
distinctUntilChanged(), distinctUntilChanged(),
tap(() => { this.update(this.input.nativeElement.value); }) tap(() => this.update(this.input.nativeElement.value))
).subscribe(); ).subscribe();
} }

View File

@ -2,23 +2,21 @@ import { Component, OnInit, Input } from '@angular/core';
import { JSONService, JSONTransport } from '../../../types/services'; import { JSONService, JSONTransport } from '../../../types/services';
import { UDSApiService } from '../../../uds-api.service'; import { UDSApiService } from '../../../uds-api.service';
declare var django: any; declare const django: any;
const MAX_NAME_LENGTH = 32; const MAX_NAME_LENGTH = 32;
@Component({ @Component({
selector: 'uds-service', selector: 'uds-service',
templateUrl: './service.component.html', templateUrl: './service.component.html',
styleUrls: ['./service.component.css'] styleUrls: ['./service.component.css'],
}) })
export class ServiceComponent implements OnInit { export class ServiceComponent implements OnInit {
constructor(private api: UDSApiService) { }
@Input() service: JSONService; @Input() service: JSONService;
ngOnInit() { constructor(private api: UDSApiService) {}
}
ngOnInit() {}
get serviceImage() { get serviceImage() {
return this.api.galleryImageURL(this.service.imageId); return this.api.galleryImageURL(this.service.imageId);
@ -66,7 +64,10 @@ export class ServiceComponent implements OnInit {
get serviceNameClass() { get serviceNameClass() {
const klass = []; const klass = [];
const len = Math.min(Math.floor((this.service.visual_name.length - 1) / 4) * 4, 28); const len = Math.min(
Math.floor((this.service.visual_name.length - 1) / 4) * 4,
28
);
if (len >= 16) { if (len >= 16) {
klass.push('small-' + len.toString()); klass.push('small-' + len.toString());
} }
@ -86,27 +87,39 @@ export class ServiceComponent implements OnInit {
} }
hasMenu() { hasMenu() {
return this.service.maintenance === false && return (
this.service.maintenance === false &&
this.service.not_accesible === false && this.service.not_accesible === false &&
(this.hasActions() || this.showTransportsMenu()) (this.hasActions() || this.showTransportsMenu())
; );
} }
notifyNotLaunching(message: string) { notifyNotLaunching(message: string) {
this.api.gui.alert('<p align="center"><b>' + django.gettext('Launcher') + '</b></p>', message); this.api.gui.alert(
'<p align="center"><b>' + django.gettext('Launcher') + '</b></p>',
message
);
} }
launch(transport: JSONTransport) { launch(transport: JSONTransport) {
if (this.service.maintenance) { if (this.service.maintenance) {
this.notifyNotLaunching(django.gettext('Service is in maintenance and cannot be launched')); this.notifyNotLaunching(
django.gettext('Service is in maintenance and cannot be launched')
);
} else if (this.service.not_accesible) { } else if (this.service.not_accesible) {
const calendarDeniedText = this.service.custom_calendar_text || this.api.config.messages.calendarDenied; const calendarDeniedText =
this.service.custom_calendar_text ||
this.api.config.messages.calendarDenied;
this.notifyNotLaunching('<p align="center">' + this.notifyNotLaunching(
django.gettext('This service is currently not accesible due to schedule restrictions.') + '<p align="center">' +
'</p><p align="center"><b>' + calendarDeniedText + django.gettext(
'</b></p><p align="center">' + 'This service is currently not accesible due to schedule restrictions.'
'</p>' ) +
'</p><p align="center"><b>' +
calendarDeniedText +
'</b></p><p align="center">' +
'</p>'
); );
} else { } else {
if (transport === null || this.service.show_transports === false) { if (transport === null || this.service.show_transports === false) {
@ -118,23 +131,26 @@ export class ServiceComponent implements OnInit {
} }
action(type: string) { action(type: string) {
const title = (type === 'release' ? django.gettext('Release service: ') : django.gettext('Reset service: ')) + ' ' + this.serviceName; const title =
const action = type === 'release' ? django.gettext('Service released') : django.gettext('Service reseted'); (type === 'release'
this.api.gui.yesno( ? django.gettext('Release service: ')
title, : django.gettext('Reset service: ')) +
django.gettext('Are you sure?') ' ' +
).subscribe((val) => { this.serviceName;
if (val) { const action =
this.api.action(type, this.service.id).subscribe((service) => { type === 'release'
if (service) { ? django.gettext('Service released')
this.api.gui.alert( : django.gettext('Service reseted');
title, this.api.gui
action .yesno(title, django.gettext('Are you sure?'))
); .subscribe((val) => {
} if (val) {
}); this.api.action(type, this.service.id).subscribe((service) => {
} if (service) {
}); this.api.gui.alert(title, action);
}
});
}
});
} }
} }

View File

@ -1,8 +1,9 @@
/* eslint-disable no-shadow */
import { Component, OnInit, Inject } from '@angular/core'; import { Component, OnInit, Inject } from '@angular/core';
import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog'; import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog';
import { interval, Subscription, Observable } from 'rxjs'; import { interval, Subscription, Observable } from 'rxjs';
declare var django: any; declare const django: any;
export enum DialogType { export enum DialogType {
alert = 0, alert = 0,
@ -49,16 +50,13 @@ export class ModalComponent implements OnInit {
observer.complete(); observer.complete();
}; };
const self = this; const self = this;
return {unsubscribe() { return {unsubscribe: () => self.resetCallbacks()};
self.resetCallbacks();
}};
}); });
} }
resetCallbacks() { resetCallbacks() {
this.yes = this.no = () => { this.close(); }; this.yes = this.no = () => this.close();
this.close = () => { this.doClose(); }; this.close = () => this.doClose();
} }
/** /**
@ -77,6 +75,7 @@ export class ModalComponent implements OnInit {
/** /**
* Sets extra information on close button * Sets extra information on close button
*
* @param miliseconds miliseconds to inform (will be converted to seconds) * @param miliseconds miliseconds to inform (will be converted to seconds)
*/ */
setExtra(miliseconds: number) { setExtra(miliseconds: number) {

View File

@ -11,8 +11,8 @@ export class UDSGuiService {
alert(title: string, message: string, autoclose = 0 ) { alert(title: string, message: string, autoclose = 0 ) {
const width = window.innerWidth < 800 ? '80%' : '40%'; const width = window.innerWidth < 800 ? '80%' : '40%';
const dialogRef = this.dialog.open(ModalComponent, { const dialogRef = this.dialog.open(ModalComponent, {
width: width, width,
data: { title: title, body: message, autoclose: autoclose, type: DialogType.alert }, data: { title, body: message, autoclose, type: DialogType.alert },
disableClose: true, disableClose: true,
}); });
return dialogRef; return dialogRef;
@ -21,8 +21,8 @@ export class UDSGuiService {
yesno(title: string, message: string) { yesno(title: string, message: string) {
const width = window.innerWidth < 800 ? '80%' : '40%'; const width = window.innerWidth < 800 ? '80%' : '40%';
const dialogRef = this.dialog.open(ModalComponent, { const dialogRef = this.dialog.open(ModalComponent, {
width: width, width,
data: { title: title, body: message, type: DialogType.yesno }, data: { title, body: message, type: DialogType.yesno },
disableClose: true, disableClose: true,
}); });

View File

@ -1,108 +1,135 @@
import { UDSApiServiceType } from '../uds-api.service-type'; import { UDSApiServiceType } from '../uds-api.service-type';
declare const django: { gettext: (arg0: string) => string; }; declare const django: any;
/** /**
* Plugin manipulation class * Plugin manipulation class
*/ */
export class Plugin { export class Plugin {
static transportsWindow = {}; static transportsWindow = {};
delay: number; delay: number;
constructor(private api: UDSApiServiceType) { constructor(private api: UDSApiServiceType) {
this.delay = api.config.launcher_wait_time; this.delay = api.config.launcher_wait_time;
} }
private showAlert(text: string, info: string, waitTime: number) { launchURL(url: string): void {
return this.api.gui.alert( // If uds url...
django.gettext('Launching service'), if (url.substring(0, 7) === 'udsa://') {
'<p stype="font-size: 1.2rem;">' + text + '</p><p style="font-size: 0.8rem;">' + this.showAlert(
info + '</p>', django.gettext('Please wait until the service is launched.'),
waitTime django.gettext(
); 'Remember that you will need the UDS client on your platform to access the service.'
} ),
this.delay
/** );
* Launches an UDS related url const params = url.split('//')[1].split('/');
* @param url uds url to be lauhcned this.api.enabler(params[0], params[1]).subscribe((data) => {
* if (data.error) {
*/ // TODO: show the error correctly
private doLaunch(url: string) { this.api.gui.alert(
let elem: HTMLIFrameElement = document.getElementById('hiddenUdsLauncherIFrame') as HTMLIFrameElement; django.gettext('Error launching service'),
if (elem === null) { data.error
const i = document.createElement('div'); );
i.id = 'testID';
i.innerHTML = '<iframe id="hiddenUdsLauncherIFrame" src="about:blank" style="display:none"></iframe>';
document.body.appendChild(i);
elem = document.getElementById('hiddenUdsLauncherIFrame') as HTMLIFrameElement;
}
elem.contentWindow.location.href = url;
}
launchURL(url: string): void {
// If uds url...
if (url.substring(0, 7) === 'udsa://') {
this.showAlert(
django.gettext('Please wait until the service is launched.'),
django.gettext('Remember that you will need the UDS client on your platform to access the service.'),
this.delay
);
const params = url.split('//')[1].split('/');
this.api.enabler(params[0], params[1]).subscribe(data => {
if (data.error) {
// TODO: show the error correctly
this.api.gui.alert(django.gettext('Error launching service'), data.error);
} else {
// Is HTTP access the service returned, or for UDS client?
if (data.url.startsWith('/')) {
this.launchURL(data.url);
return;
}
if (window.location.protocol === 'https:') {
// Ensures that protocol is https also for plugin, fixing if needed UDS provided info
data.url = data.url.replace('uds://', 'udss://');
}
this.doLaunch(data.url);
}
});
} else { } else {
// Custom url, http/https // Is HTTP access the service returned, or for UDS client?
const alert = this.showAlert( if (data.url.startsWith('/')) {
django.gettext('Please wait until the service is launched.'), this.launchURL(data.url);
django.gettext('Your connection is being prepared. It will open on a new window when ready.'), return;
this.delay * 2 }
); if (window.location.protocol === 'https:') {
this.api.transportUrl(url).subscribe(data => { // Ensures that protocol is https also for plugin, fixing if needed UDS provided info
alert.close(); data.url = data.url.replace('uds://', 'udss://');
if (data.url) { }
if (data.url.indexOf('o_s_w=') !== -1) { this.doLaunch(data.url);
window.location.href = data.url;
} else {
// If the url contains "o_n_w", will open the url on a new window ALWAYS
let name = 'global';
if (data.url.indexOf('o_n_w=') !== -1) {
// Extract window name from o_n_w parameter if present
const onw = /.*o_n_w=([a-zA-Z0-9._-]*)/.exec(data.url);
if (onw) {
name = onw[1];
}
}
if (Plugin.transportsWindow[name]) {
Plugin.transportsWindow[name].close();
}
Plugin.transportsWindow[name] = window.open(data.url, 'uds_trans_' + name);
}
} else if (data.running) { // Already preparing, show some info and request wait a bit to user
this.showAlert(
django.gettext('The service is now being prepared. (It is at #).'.replace('#', '' + data.running + '%')),
django.gettext('Please, try again in a few moments.'),
this.delay
);
} else { // error
this.api.gui.alert(django.gettext('Error launching service'), data.error);
}
});
} }
});
} else {
// Custom url, http/https
const alert = this.showAlert(
django.gettext('Please wait until the service is launched.'),
django.gettext(
'Your connection is being prepared. It will open on a new window when ready.'
),
this.delay * 2
);
this.api.transportUrl(url).subscribe((data) => {
alert.close();
if (data.url) {
if (data.url.indexOf('o_s_w=') !== -1) {
window.location.href = data.url;
} else {
// If the url contains "o_n_w", will open the url on a new window ALWAYS
let name = 'global';
if (data.url.indexOf('o_n_w=') !== -1) {
// Extract window name from o_n_w parameter if present
const onw = /.*o_n_w=([a-zA-Z0-9._-]*)/.exec(data.url);
if (onw) {
name = onw[1];
}
}
if (Plugin.transportsWindow[name]) {
Plugin.transportsWindow[name].close();
}
Plugin.transportsWindow[name] = window.open(
data.url,
'uds_trans_' + name
);
}
} else if (data.running) {
// Already preparing, show some info and request wait a bit to user
this.showAlert(
django.gettext(
'The service is now being prepared. (It is at #).'.replace(
'#',
'' + data.running + '%'
)
),
django.gettext('Please, try again in a few moments.'),
this.delay
);
} else {
// error
this.api.gui.alert(
django.gettext('Error launching service'),
data.error
);
}
});
} }
}
private showAlert(text: string, info: string, waitTime: number) {
return this.api.gui.alert(
django.gettext('Launching service'),
'<p stype="font-size: 1.2rem;">' +
text +
'</p><p style="font-size: 0.8rem;">' +
info +
'</p>',
waitTime
);
}
/**
* Launches an UDS related url
*
* @param url uds url to be lauhcned
*/
private doLaunch(url: string) {
let elem: HTMLIFrameElement = document.getElementById(
'hiddenUdsLauncherIFrame'
) as HTMLIFrameElement;
if (elem === null) {
const i = document.createElement('div');
i.id = 'testID';
i.innerHTML =
'<iframe id="hiddenUdsLauncherIFrame" src="about:blank" style="display:none"></iframe>';
document.body.appendChild(i);
elem = document.getElementById(
'hiddenUdsLauncherIFrame'
) as HTMLIFrameElement;
}
elem.contentWindow.location.href = url;
}
} }

View File

@ -2,7 +2,7 @@ import { Component, OnInit } from '@angular/core';
import { UDSApiService } from '../../uds-api.service'; import { UDSApiService } from '../../uds-api.service';
import { Downloadable } from '../../types/config'; import { Downloadable } from '../../types/config';
declare var django: any; declare const django: any;
@Component({ @Component({
selector: 'uds-client-download', selector: 'uds-client-download',

View File

@ -1,8 +1,8 @@
import { Component, OnInit } from '@angular/core'; import { Component, OnInit } from '@angular/core';
import { ActivatedRoute } from '@angular/router'; import { ActivatedRoute } from '@angular/router';
declare var django: any; declare const django: any;
declare var udsData: any; declare const udsData: any;
@Component({ @Component({
selector: 'uds-error', selector: 'uds-error',
@ -21,7 +21,7 @@ export class ErrorComponent implements OnInit {
getError(): void { getError(): void {
const id = this.route.snapshot.paramMap.get('id'); const id = this.route.snapshot.paramMap.get('id');
try { try {
this.error = new TextDecoder().decode(Uint8Array.from(<any>window.atob(id), c => (<any>c).charCodeAt(c))).replace('\n', '<br/>'); this.error = new TextDecoder().decode(Uint8Array.from(window.atob(id), c => (c as any).charCodeAt(c))).replace('\n', '<br/>');
console.log(this.error); console.log(this.error);
udsData.error = this.error; udsData.error = this.error;
} catch (e) { } catch (e) {

View File

@ -1,19 +1,19 @@
// eslint-disable-next-line @typescript-eslint/quotes
import { Component, OnInit } from '@angular/core'; import { Component, OnInit } from '@angular/core';
import { UDSApiService } from '../../uds-api.service'; import { UDSApiService } from '../../uds-api.service';
import { Authenticator } from '../../types/config'; import { Authenticator } from '../../types/config';
declare var django: any; declare const django: any;
@Component({ @Component({
selector: 'uds-login', selector: 'uds-login',
templateUrl: './login.component.html', templateUrl: './login.component.html',
styleUrls: ['./login.component.css'] styleUrls: ['./login.component.css'],
}) })
export class LoginComponent implements OnInit { export class LoginComponent implements OnInit {
auths: Authenticator[]; auths: Authenticator[];
auth: HTMLInputElement; auth: HTMLInputElement;
title = 'UDS Enterprise'; title = 'UDS Enterprise';
constructor(public api: UDSApiService) { constructor(public api: UDSApiService) {
this.title = api.config.site_name; this.title = api.config.site_name;
@ -25,22 +25,24 @@ export class LoginComponent implements OnInit {
ngOnInit() { ngOnInit() {
// We want to keep compatibility right now with previous UDS templates, so we // We want to keep compatibility right now with previous UDS templates, so we
// adapt form to post the correct values the correct way // adapt form to post the correct values the correct way
const form = <HTMLFormElement>document.getElementById('loginform'); const form = document.getElementById('loginform') as HTMLFormElement;
form.action = this.api.config.urls.login; form.action = this.api.config.urls.login;
const input = (<HTMLInputElement>document.getElementById('token')); const input = document.getElementById('token') as HTMLInputElement;
input.name = this.api.config.csrf_field; input.name = this.api.config.csrf_field;
input.value = this.api.config.csrf; input.value = this.api.config.csrf;
this.auth = (<HTMLInputElement>document.getElementById('authenticator')); this.auth = document.getElementById('authenticator') as HTMLInputElement;
if (this.auths.length > 0) { if (this.auths.length > 0) {
this.auth.value = this.auths[0].id; this.auth.value = this.auths[0].id;
this.changeAuth(this.auth.value); this.changeAuth(this.auth.value);
} }
if (this.api.errors.length > 0) { if (this.api.errors.length > 0) {
this.api.gui.alert(django.gettext('Errors found'), '<div>' + this.api.errors.join('</div><div>') + '</div>' ); this.api.gui.alert(
django.gettext('Errors found'),
'<div>' + this.api.errors.join('</div><div>') + '</div>'
);
} }
} }
changeAuth(auth: string) { changeAuth(auth: string) {
@ -53,20 +55,23 @@ export class LoginComponent implements OnInit {
for (const l of this.auths) { for (const l of this.auths) {
if (l.id === auth) { if (l.id === auth) {
if (l.is_custom) { // If is custom, we should get the code from server to authentication if (l.is_custom) {
// If is custom, we should get the code from server to authentication
// Instant hide form // Instant hide form
document.getElementsByClassName('login-form')[0].setAttribute('style', 'display: none;'); document
this.api.getAuthCustomHtml(l.id) .getElementsByClassName('login-form')[0]
.subscribe(result => doCustomAuth(result)); .setAttribute('style', 'display: none;');
this.api
.getAuthCustomHtml(l.id)
.subscribe((result) => doCustomAuth(result));
} }
} }
} }
} }
launch(): boolean { launch(): boolean {
const form = <HTMLFormElement>document.getElementById('loginform'); const form = document.getElementById('loginform') as HTMLFormElement;
form.submit(); form.submit();
return true; return true;
} }
} }

View File

@ -1,8 +1,12 @@
import { Component, OnInit } from '@angular/core'; import { Component, OnInit } from '@angular/core';
import { UDSApiService } from '../../uds-api.service'; import { UDSApiService } from '../../uds-api.service';
import { JSONServicesInformation, JSONGroup, JSONService } from '../../types/services'; import {
JSONServicesInformation,
JSONGroup,
JSONService,
} from '../../types/services';
declare var django: any; declare const django: any;
class GroupedServices { class GroupedServices {
services: JSONService[]; services: JSONService[];
@ -15,13 +19,24 @@ class GroupedServices {
@Component({ @Component({
selector: 'uds-services-page', selector: 'uds-services-page',
templateUrl: './services.component.html', templateUrl: './services.component.html',
styleUrls: ['./services.component.css'] styleUrls: ['./services.component.css'],
}) })
export class ServicesComponent implements OnInit { export class ServicesComponent implements OnInit {
servicesInformation: JSONServicesInformation; servicesInformation: JSONServicesInformation;
group: GroupedServices[]; group: GroupedServices[];
constructor(public api: UDSApiService) { constructor(public api: UDSApiService) {}
update(filter: string) {
this.updateServices(filter);
}
ngOnInit() {
if (this.api.config.urls.launch) {
this.api.logout();
} else {
this.loadServices(); // Loads service related data
}
} }
/** /**
@ -29,14 +44,22 @@ export class ServicesComponent implements OnInit {
*/ */
private autorun(): boolean { private autorun(): boolean {
// If autorun, and there is only one service, launch it // If autorun, and there is only one service, launch it
if (this.servicesInformation.autorun && this.servicesInformation.services.length === 1) { if (
this.servicesInformation.autorun &&
this.servicesInformation.services.length === 1
) {
if (!this.servicesInformation.services[0].maintenance) { if (!this.servicesInformation.services[0].maintenance) {
this.api.executeCustomJSForServiceLaunch(); this.api.executeCustomJSForServiceLaunch();
// Launch url // Launch url
this.api.launchURL(this.servicesInformation.services[0].transports[0].link); this.api.launchURL(
this.servicesInformation.services[0].transports[0].link
);
return true; return true;
} else { } else {
this.api.gui.alert(django.gettext('Warning'), django.gettext('Service is in maintenance and cannot be executed')); this.api.gui.alert(
django.gettext('Warning'),
django.gettext('Service is in maintenance and cannot be executed')
);
} }
} }
@ -52,12 +75,14 @@ export class ServicesComponent implements OnInit {
} }
// Obtain services list // Obtain services list
this.api.getServicesInformation().subscribe((result: JSONServicesInformation) => { this.api
this.servicesInformation = result; .getServicesInformation()
this.autorun(); .subscribe((result: JSONServicesInformation) => {
this.servicesInformation = result;
this.autorun();
this.updateServices(); this.updateServices();
}); });
} }
private updateServices(filter: string = '') { private updateServices(filter: string = '') {
@ -65,10 +90,14 @@ export class ServicesComponent implements OnInit {
this.group = []; this.group = [];
let current: GroupedServices = null; let current: GroupedServices = null;
this.servicesInformation.services.filter( this.servicesInformation.services
(value) => !filter || value.visual_name.toLowerCase().includes(filter) || value.group.name.toLowerCase().includes(filter) .filter(
).sort( (value) =>
(a, b) => { !filter ||
value.visual_name.toLowerCase().includes(filter) ||
value.group.name.toLowerCase().includes(filter)
)
.sort((a, b) => {
if (a.group.priority !== b.group.priority) { if (a.group.priority !== b.group.priority) {
return a.group.priority - b.group.priority; return a.group.priority - b.group.priority;
} else { } else {
@ -79,7 +108,8 @@ export class ServicesComponent implements OnInit {
} }
} }
return 0; return 0;
}).forEach(element => { })
.forEach((element) => {
if (current === null || element.group.id !== current.group.id) { if (current === null || element.group.id !== current.group.id) {
if (current !== null) { if (current !== null) {
this.group.push(current); this.group.push(current);
@ -92,17 +122,4 @@ export class ServicesComponent implements OnInit {
this.group.push(current); this.group.push(current);
} }
} }
update(filter: string) {
this.updateServices(filter);
}
ngOnInit() {
if (this.api.config.urls.launch) {
this.api.logout();
} else {
this.loadServices(); // Loads service related data
}
}
} }

View File

@ -1,6 +1,6 @@
import { Directive, OnInit, ElementRef } from '@angular/core'; import { Directive, OnInit, ElementRef } from '@angular/core';
declare var django: any; declare const django: any;
@Directive({ @Directive({
// eslint-disable-next-line @angular-eslint/directive-selector // eslint-disable-next-line @angular-eslint/directive-selector

View File

@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/naming-convention */
// Types definition for configuration from js // Types definition for configuration from js
export interface Lang { export interface Lang {

View File

@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/naming-convention */
// Types definition for services json // Types definition for services json
export interface JSONGroup { export interface JSONGroup {

View File

@ -11,7 +11,7 @@ import { UDSApiServiceType } from './uds-api.service-type';
import { environment } from '../environments/environment'; import { environment } from '../environments/environment';
declare var udsData: any; declare const udsData: any;
@Injectable() @Injectable()
@ -131,6 +131,7 @@ export class UDSApiService implements UDSApiServiceType {
/** /**
* Gets auth custom html code * Gets auth custom html code
*
* @param authId if of the authenticator * @param authId if of the authenticator
* @returns Observable * @returns Observable
*/ */

3
src/typings.d.ts vendored
View File

@ -1,9 +1,10 @@
/* SystemJS module definition */ /* SystemJS module definition */
// eslint-disable-next-line no-var
declare var module: NodeModule; declare var module: NodeModule;
interface NodeModule { interface NodeModule {
id: string; id: string;
} }
/* UDS injected modules */ /* UDS injected modules */
// declare var django: any; // declare const django: any;
// declare var udsData: any; // declare var udsData: any;