mirror of
https://github.com/dkmstr/openuds-gui.git
synced 2024-12-21 13:33:48 +03:00
fixed all eslint "complains"
This commit is contained in:
parent
f26a0c2e68
commit
ea13e330ea
37
.eslintrc.js
37
.eslintrc.js
@ -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": [
|
||||
]
|
||||
}
|
||||
|
4
.vscode/settings.json
vendored
4
.vscode/settings.json
vendored
@ -1,4 +1,6 @@
|
||||
{
|
||||
"python.linting.enabled": true,
|
||||
"python.pythonPath": "/usr/bin/python3"
|
||||
"python.pythonPath": "/usr/bin/python3",
|
||||
"prettier.singleQuote": true,
|
||||
"typescript.preferences.quoteStyle": "single"
|
||||
}
|
11
angular.json
11
angular.json
@ -124,17 +124,6 @@
|
||||
"protractorConfig": "./protractor.conf.js",
|
||||
"devServerTarget": "uds:serve"
|
||||
}
|
||||
},
|
||||
"lint": {
|
||||
"builder": "@angular-devkit/build-angular:tslint",
|
||||
"options": {
|
||||
"tsConfig": [
|
||||
"e2e/tsconfig.e2e.json"
|
||||
],
|
||||
"exclude": [
|
||||
"**/node_modules/**"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -5,9 +5,9 @@
|
||||
"scripts": {
|
||||
"ng": "ng",
|
||||
"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",
|
||||
"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",
|
||||
"test": "ng test",
|
||||
"lint": "ng lint",
|
||||
|
@ -1,8 +1,8 @@
|
||||
import { Component, OnInit } from '@angular/core';
|
||||
|
||||
// External
|
||||
declare var django: any;
|
||||
declare var cookieconsent: any;
|
||||
declare const django: any;
|
||||
declare const cookieconsent: any;
|
||||
|
||||
|
||||
@Component({
|
||||
@ -15,19 +15,19 @@ export class AppComponent implements OnInit {
|
||||
|
||||
ngOnInit() {
|
||||
cookieconsent.initialise({
|
||||
'palette': {
|
||||
'popup': {
|
||||
'background': '#343c66',
|
||||
'text': '#cfcfe8'
|
||||
palette: {
|
||||
popup: {
|
||||
background: '#343c66',
|
||||
text: '#cfcfe8'
|
||||
},
|
||||
'button': {
|
||||
'background': '#f71559'
|
||||
button: {
|
||||
background: '#f71559'
|
||||
}
|
||||
},
|
||||
'content': {
|
||||
'message': django.gettext('We use cookies to track usage and preferences'),
|
||||
'dismiss': django.gettext('I Understand'),
|
||||
'link': django.gettext('Learn more')
|
||||
content: {
|
||||
message: django.gettext('We use cookies to track usage and preferences'),
|
||||
dismiss: django.gettext('I Understand'),
|
||||
link: django.gettext('Learn more')
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -22,7 +22,7 @@ export class FilterComponent implements AfterViewInit {
|
||||
filter(Boolean),
|
||||
debounceTime(600),
|
||||
distinctUntilChanged(),
|
||||
tap(() => { this.update(this.input.nativeElement.value); })
|
||||
tap(() => this.update(this.input.nativeElement.value))
|
||||
).subscribe();
|
||||
}
|
||||
|
||||
|
@ -2,23 +2,21 @@ import { Component, OnInit, Input } from '@angular/core';
|
||||
import { JSONService, JSONTransport } from '../../../types/services';
|
||||
import { UDSApiService } from '../../../uds-api.service';
|
||||
|
||||
declare var django: any;
|
||||
declare const django: any;
|
||||
|
||||
const MAX_NAME_LENGTH = 32;
|
||||
|
||||
@Component({
|
||||
selector: 'uds-service',
|
||||
templateUrl: './service.component.html',
|
||||
styleUrls: ['./service.component.css']
|
||||
styleUrls: ['./service.component.css'],
|
||||
})
|
||||
export class ServiceComponent implements OnInit {
|
||||
|
||||
constructor(private api: UDSApiService) { }
|
||||
|
||||
@Input() service: JSONService;
|
||||
|
||||
ngOnInit() {
|
||||
}
|
||||
constructor(private api: UDSApiService) {}
|
||||
|
||||
ngOnInit() {}
|
||||
|
||||
get serviceImage() {
|
||||
return this.api.galleryImageURL(this.service.imageId);
|
||||
@ -66,7 +64,10 @@ export class ServiceComponent implements OnInit {
|
||||
|
||||
get serviceNameClass() {
|
||||
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) {
|
||||
klass.push('small-' + len.toString());
|
||||
}
|
||||
@ -86,27 +87,39 @@ export class ServiceComponent implements OnInit {
|
||||
}
|
||||
|
||||
hasMenu() {
|
||||
return this.service.maintenance === false &&
|
||||
return (
|
||||
this.service.maintenance === false &&
|
||||
this.service.not_accesible === false &&
|
||||
(this.hasActions() || this.showTransportsMenu())
|
||||
;
|
||||
);
|
||||
}
|
||||
|
||||
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) {
|
||||
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) {
|
||||
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">' +
|
||||
django.gettext('This service is currently not accesible due to schedule restrictions.') +
|
||||
'</p><p align="center"><b>' + calendarDeniedText +
|
||||
'</b></p><p align="center">' +
|
||||
'</p>'
|
||||
this.notifyNotLaunching(
|
||||
'<p align="center">' +
|
||||
django.gettext(
|
||||
'This service is currently not accesible due to schedule restrictions.'
|
||||
) +
|
||||
'</p><p align="center"><b>' +
|
||||
calendarDeniedText +
|
||||
'</b></p><p align="center">' +
|
||||
'</p>'
|
||||
);
|
||||
} else {
|
||||
if (transport === null || this.service.show_transports === false) {
|
||||
@ -118,23 +131,26 @@ export class ServiceComponent implements OnInit {
|
||||
}
|
||||
|
||||
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?')
|
||||
).subscribe((val) => {
|
||||
if (val) {
|
||||
this.api.action(type, this.service.id).subscribe((service) => {
|
||||
if (service) {
|
||||
this.api.gui.alert(
|
||||
title,
|
||||
action
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
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?'))
|
||||
.subscribe((val) => {
|
||||
if (val) {
|
||||
this.api.action(type, this.service.id).subscribe((service) => {
|
||||
if (service) {
|
||||
this.api.gui.alert(title, action);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -1,8 +1,9 @@
|
||||
/* 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';
|
||||
|
||||
declare var django: any;
|
||||
declare const django: any;
|
||||
|
||||
export enum DialogType {
|
||||
alert = 0,
|
||||
@ -49,16 +50,13 @@ export class ModalComponent implements OnInit {
|
||||
observer.complete();
|
||||
};
|
||||
const self = this;
|
||||
return {unsubscribe() {
|
||||
self.resetCallbacks();
|
||||
}};
|
||||
return {unsubscribe: () => self.resetCallbacks()};
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
resetCallbacks() {
|
||||
this.yes = this.no = () => { this.close(); };
|
||||
this.close = () => { this.doClose(); };
|
||||
this.yes = this.no = () => this.close();
|
||||
this.close = () => this.doClose();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -77,6 +75,7 @@ export class ModalComponent implements OnInit {
|
||||
|
||||
/**
|
||||
* Sets extra information on close button
|
||||
*
|
||||
* @param miliseconds miliseconds to inform (will be converted to seconds)
|
||||
*/
|
||||
setExtra(miliseconds: number) {
|
||||
|
@ -11,8 +11,8 @@ export class UDSGuiService {
|
||||
alert(title: string, message: string, autoclose = 0 ) {
|
||||
const width = window.innerWidth < 800 ? '80%' : '40%';
|
||||
const dialogRef = this.dialog.open(ModalComponent, {
|
||||
width: width,
|
||||
data: { title: title, body: message, autoclose: autoclose, type: DialogType.alert },
|
||||
width,
|
||||
data: { title, body: message, autoclose, type: DialogType.alert },
|
||||
disableClose: true,
|
||||
});
|
||||
return dialogRef;
|
||||
@ -21,8 +21,8 @@ export class UDSGuiService {
|
||||
yesno(title: string, message: string) {
|
||||
const width = window.innerWidth < 800 ? '80%' : '40%';
|
||||
const dialogRef = this.dialog.open(ModalComponent, {
|
||||
width: width,
|
||||
data: { title: title, body: message, type: DialogType.yesno },
|
||||
width,
|
||||
data: { title, body: message, type: DialogType.yesno },
|
||||
disableClose: true,
|
||||
});
|
||||
|
||||
|
@ -1,108 +1,135 @@
|
||||
import { UDSApiServiceType } from '../uds-api.service-type';
|
||||
|
||||
declare const django: { gettext: (arg0: string) => string; };
|
||||
declare const django: any;
|
||||
|
||||
/**
|
||||
* Plugin manipulation class
|
||||
*/
|
||||
|
||||
export class Plugin {
|
||||
static transportsWindow = {};
|
||||
delay: number;
|
||||
static transportsWindow = {};
|
||||
delay: number;
|
||||
|
||||
constructor(private api: UDSApiServiceType) {
|
||||
this.delay = api.config.launcher_wait_time;
|
||||
}
|
||||
constructor(private api: UDSApiServiceType) {
|
||||
this.delay = api.config.launcher_wait_time;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
});
|
||||
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 {
|
||||
// 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);
|
||||
}
|
||||
});
|
||||
// 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 {
|
||||
// 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;
|
||||
}
|
||||
}
|
||||
|
@ -2,7 +2,7 @@ import { Component, OnInit } from '@angular/core';
|
||||
import { UDSApiService } from '../../uds-api.service';
|
||||
import { Downloadable } from '../../types/config';
|
||||
|
||||
declare var django: any;
|
||||
declare const django: any;
|
||||
|
||||
@Component({
|
||||
selector: 'uds-client-download',
|
||||
|
@ -1,8 +1,8 @@
|
||||
import { Component, OnInit } from '@angular/core';
|
||||
import { ActivatedRoute } from '@angular/router';
|
||||
|
||||
declare var django: any;
|
||||
declare var udsData: any;
|
||||
declare const django: any;
|
||||
declare const udsData: any;
|
||||
|
||||
@Component({
|
||||
selector: 'uds-error',
|
||||
@ -21,7 +21,7 @@ export class ErrorComponent implements OnInit {
|
||||
getError(): void {
|
||||
const id = this.route.snapshot.paramMap.get('id');
|
||||
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);
|
||||
udsData.error = this.error;
|
||||
} catch (e) {
|
||||
|
@ -1,20 +1,20 @@
|
||||
// eslint-disable-next-line @typescript-eslint/quotes
|
||||
import { Component, OnInit } from '@angular/core';
|
||||
import { UDSApiService } from '../../uds-api.service';
|
||||
import { Authenticator } from '../../types/config';
|
||||
|
||||
declare var django: any;
|
||||
declare const django: any;
|
||||
|
||||
@Component({
|
||||
selector: 'uds-login',
|
||||
templateUrl: './login.component.html',
|
||||
styleUrls: ['./login.component.css']
|
||||
styleUrls: ['./login.component.css'],
|
||||
})
|
||||
export class LoginComponent implements OnInit {
|
||||
auths: Authenticator[];
|
||||
auth: HTMLInputElement;
|
||||
title = 'UDS Enterprise';
|
||||
|
||||
|
||||
constructor(public api: UDSApiService) {
|
||||
this.title = api.config.site_name;
|
||||
this.auths = api.config.authenticators.slice(0);
|
||||
@ -25,22 +25,24 @@ export class LoginComponent implements OnInit {
|
||||
ngOnInit() {
|
||||
// We want to keep compatibility right now with previous UDS templates, so we
|
||||
// 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;
|
||||
const input = (<HTMLInputElement>document.getElementById('token'));
|
||||
const input = document.getElementById('token') as HTMLInputElement;
|
||||
input.name = this.api.config.csrf_field;
|
||||
input.value = this.api.config.csrf;
|
||||
|
||||
this.auth = (<HTMLInputElement>document.getElementById('authenticator'));
|
||||
this.auth = document.getElementById('authenticator') as HTMLInputElement;
|
||||
if (this.auths.length > 0) {
|
||||
this.auth.value = this.auths[0].id;
|
||||
this.changeAuth(this.auth.value);
|
||||
}
|
||||
|
||||
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) {
|
||||
@ -53,20 +55,23 @@ export class LoginComponent implements OnInit {
|
||||
|
||||
for (const l of this.auths) {
|
||||
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
|
||||
document.getElementsByClassName('login-form')[0].setAttribute('style', 'display: none;');
|
||||
this.api.getAuthCustomHtml(l.id)
|
||||
.subscribe(result => doCustomAuth(result));
|
||||
document
|
||||
.getElementsByClassName('login-form')[0]
|
||||
.setAttribute('style', 'display: none;');
|
||||
this.api
|
||||
.getAuthCustomHtml(l.id)
|
||||
.subscribe((result) => doCustomAuth(result));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
launch(): boolean {
|
||||
const form = <HTMLFormElement>document.getElementById('loginform');
|
||||
const form = document.getElementById('loginform') as HTMLFormElement;
|
||||
form.submit();
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,8 +1,12 @@
|
||||
import { Component, OnInit } from '@angular/core';
|
||||
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 {
|
||||
services: JSONService[];
|
||||
@ -15,13 +19,24 @@ class GroupedServices {
|
||||
@Component({
|
||||
selector: 'uds-services-page',
|
||||
templateUrl: './services.component.html',
|
||||
styleUrls: ['./services.component.css']
|
||||
styleUrls: ['./services.component.css'],
|
||||
})
|
||||
export class ServicesComponent implements OnInit {
|
||||
servicesInformation: JSONServicesInformation;
|
||||
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 {
|
||||
// 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) {
|
||||
this.api.executeCustomJSForServiceLaunch();
|
||||
// Launch url
|
||||
this.api.launchURL(this.servicesInformation.services[0].transports[0].link);
|
||||
this.api.launchURL(
|
||||
this.servicesInformation.services[0].transports[0].link
|
||||
);
|
||||
return true;
|
||||
} 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
|
||||
this.api.getServicesInformation().subscribe((result: JSONServicesInformation) => {
|
||||
this.servicesInformation = result;
|
||||
this.autorun();
|
||||
this.api
|
||||
.getServicesInformation()
|
||||
.subscribe((result: JSONServicesInformation) => {
|
||||
this.servicesInformation = result;
|
||||
this.autorun();
|
||||
|
||||
this.updateServices();
|
||||
});
|
||||
this.updateServices();
|
||||
});
|
||||
}
|
||||
|
||||
private updateServices(filter: string = '') {
|
||||
@ -65,10 +90,14 @@ export class ServicesComponent implements OnInit {
|
||||
this.group = [];
|
||||
|
||||
let current: GroupedServices = null;
|
||||
this.servicesInformation.services.filter(
|
||||
(value) => !filter || value.visual_name.toLowerCase().includes(filter) || value.group.name.toLowerCase().includes(filter)
|
||||
).sort(
|
||||
(a, b) => {
|
||||
this.servicesInformation.services
|
||||
.filter(
|
||||
(value) =>
|
||||
!filter ||
|
||||
value.visual_name.toLowerCase().includes(filter) ||
|
||||
value.group.name.toLowerCase().includes(filter)
|
||||
)
|
||||
.sort((a, b) => {
|
||||
if (a.group.priority !== b.group.priority) {
|
||||
return a.group.priority - b.group.priority;
|
||||
} else {
|
||||
@ -79,7 +108,8 @@ export class ServicesComponent implements OnInit {
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}).forEach(element => {
|
||||
})
|
||||
.forEach((element) => {
|
||||
if (current === null || element.group.id !== current.group.id) {
|
||||
if (current !== null) {
|
||||
this.group.push(current);
|
||||
@ -92,17 +122,4 @@ export class ServicesComponent implements OnInit {
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { Directive, OnInit, ElementRef } from '@angular/core';
|
||||
|
||||
declare var django: any;
|
||||
declare const django: any;
|
||||
|
||||
@Directive({
|
||||
// eslint-disable-next-line @angular-eslint/directive-selector
|
||||
|
@ -1,3 +1,4 @@
|
||||
/* eslint-disable @typescript-eslint/naming-convention */
|
||||
// Types definition for configuration from js
|
||||
|
||||
export interface Lang {
|
||||
|
@ -1,3 +1,4 @@
|
||||
/* eslint-disable @typescript-eslint/naming-convention */
|
||||
// Types definition for services json
|
||||
|
||||
export interface JSONGroup {
|
||||
|
@ -11,7 +11,7 @@ import { UDSApiServiceType } from './uds-api.service-type';
|
||||
|
||||
import { environment } from '../environments/environment';
|
||||
|
||||
declare var udsData: any;
|
||||
declare const udsData: any;
|
||||
|
||||
|
||||
@Injectable()
|
||||
@ -131,6 +131,7 @@ export class UDSApiService implements UDSApiServiceType {
|
||||
|
||||
/**
|
||||
* Gets auth custom html code
|
||||
*
|
||||
* @param authId if of the authenticator
|
||||
* @returns Observable
|
||||
*/
|
||||
|
3
src/typings.d.ts
vendored
3
src/typings.d.ts
vendored
@ -1,9 +1,10 @@
|
||||
/* SystemJS module definition */
|
||||
// eslint-disable-next-line no-var
|
||||
declare var module: NodeModule;
|
||||
interface NodeModule {
|
||||
id: string;
|
||||
}
|
||||
/* UDS injected modules */
|
||||
// declare var django: any;
|
||||
// declare const django: any;
|
||||
// declare var udsData: any;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user