mirror of
https://github.com/dkmstr/openuds-gui.git
synced 2024-10-26 08:55:23 +03:00
New way of launching html links
This commit is contained in:
parent
4aad0273e7
commit
9a316d2779
@ -15,6 +15,7 @@ export class UDSGuiService {
|
||||
data: { title: title, body: message, autoclose: autoclose, type: DialogType.alert },
|
||||
disableClose: true,
|
||||
});
|
||||
return dialogRef;
|
||||
}
|
||||
|
||||
yesno(title: string, message: string) {
|
||||
|
@ -1,3 +1,4 @@
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import { UDSApiServiceType } from '../uds-api.service-type';
|
||||
|
||||
declare var django: any;
|
||||
@ -13,25 +14,26 @@ enum BrowserType {
|
||||
}
|
||||
|
||||
export class Plugin {
|
||||
static transportsWindow: Window = null;
|
||||
static transportsWindow = {};
|
||||
|
||||
constructor(private api: UDSApiServiceType) {
|
||||
}
|
||||
|
||||
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) {
|
||||
this.api.gui.alert(
|
||||
django.gettext('Launching service'),
|
||||
'<p stype="font-size: 1.2rem;">' + django.gettext('Please wait') + '</p><p style="font-size: 0.8rem;">' +
|
||||
django.gettext('Remember that you will need the USD client on your platform to access the service') +
|
||||
'</p>',
|
||||
5000
|
||||
);
|
||||
|
||||
let elem = document.getElementById('hiddenUdsLauncherIFrame');
|
||||
if (elem === null) {
|
||||
const i = document.createElement('div');
|
||||
@ -44,10 +46,16 @@ export class Plugin {
|
||||
}
|
||||
|
||||
launchURL(url: string): void {
|
||||
// If uds url...
|
||||
if (url.substring(0, 7) === 'udsa://') {
|
||||
this.showAlert(
|
||||
django.gettext('Please wait'),
|
||||
django.gettext('Remember that you will need the USD client on your platform to access the service'),
|
||||
5000
|
||||
);
|
||||
const params = url.split('//')[1].split('/');
|
||||
this.api.enabler(params[0], params[1]).subscribe(data => {
|
||||
if (data.error !== undefined && data.error !== '') {
|
||||
if (data.error) {
|
||||
// TODO: show the error correctly
|
||||
this.api.gui.alert(django.gettext('Error launching service'), data.error);
|
||||
} else {
|
||||
@ -59,17 +67,39 @@ export class Plugin {
|
||||
}
|
||||
});
|
||||
} else {
|
||||
// If the url contains "o_n_w", will open the url on a new window ALWAYS
|
||||
if (url.indexOf('o_n_w') !== -1 ) {
|
||||
// Remove o_n_w from url
|
||||
window.open(url.replace('o_n_w', ''));
|
||||
} else {
|
||||
// Transport is http transport
|
||||
if (Plugin.transportsWindow !== null) {
|
||||
Plugin.transportsWindow.close();
|
||||
// Custom url, http/https
|
||||
const alert = this.showAlert(
|
||||
django.gettext('Please wait'),
|
||||
django.gettext('Your connection is being prepared. It will open on a new window when ready.'),
|
||||
10000
|
||||
);
|
||||
this.api.transportUrl(url).subscribe(data => {
|
||||
alert.close();
|
||||
if (data.url) {
|
||||
// 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
|
||||
alert.close();
|
||||
this.showAlert(
|
||||
django.gettext('The service is now being prepared. (It is at #).'.replace('#', '' + data.running + '%')),
|
||||
django.gettext('Please, tray again in a few moments.'),
|
||||
5000
|
||||
);
|
||||
} else { // error
|
||||
this.api.gui.alert(django.gettext('Error launching service'), data.error)
|
||||
}
|
||||
Plugin.transportsWindow = window.open(url, 'uds_transport_window');
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -47,3 +47,9 @@ export interface JSONEnabledService {
|
||||
url: string;
|
||||
error: string;
|
||||
}
|
||||
|
||||
export interface JSONTransportURLService {
|
||||
url?: string;
|
||||
running?: string;
|
||||
error?: string;
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
import { Observable } from 'rxjs';
|
||||
import { JSONServicesInformation, JSONEnabledService, JSONService } from './types/services';
|
||||
import { JSONServicesInformation, JSONEnabledService, JSONService, JSONTransportURLService } from './types/services';
|
||||
import { UDSGuiService } from './gui/uds-gui.service';
|
||||
|
||||
export interface UDSApiServiceType {
|
||||
@ -11,6 +11,8 @@ export interface UDSApiServiceType {
|
||||
/* Services resetter */
|
||||
action(action: string, serviceId: string): Observable<JSONService>;
|
||||
|
||||
/* transport url */
|
||||
transportUrl(url: string): Observable<JSONTransportURLService>;
|
||||
|
||||
/**
|
||||
* Gets services information
|
||||
|
@ -3,7 +3,7 @@ import { HttpClient } from '@angular/common/http';
|
||||
import { Router } from '@angular/router';
|
||||
import { User, UDSConfig, Downloadable, Info } from './types/config';
|
||||
import { Observable } from 'rxjs';
|
||||
import { JSONServicesInformation, JSONEnabledService, JSONService } from './types/services';
|
||||
import { JSONServicesInformation, JSONEnabledService, JSONService, JSONTransportURLService } from './types/services';
|
||||
import { UDSGuiService } from './gui/uds-gui.service';
|
||||
import { Plugin } from './helpers/plugin';
|
||||
|
||||
@ -77,6 +77,10 @@ export class UDSApiService implements UDSApiServiceType {
|
||||
return this.http.get<JSONService>(actionURL);
|
||||
}
|
||||
|
||||
transportUrl(url: string): Observable<JSONTransportURLService> {
|
||||
return this.http.get<JSONTransportURLService>(url);
|
||||
}
|
||||
|
||||
/* Images & static related */
|
||||
galleryImageURL(imageId: string) {
|
||||
return this.config.urls.galleryImage.replace('param1', imageId);
|
||||
|
Loading…
Reference in New Issue
Block a user