2018-03-31 03:30:30 +08:00
|
|
|
import {Component} from '@angular/core';
|
|
|
|
import {SettingsComponent} from '../_abstract/abstract.settings.component';
|
|
|
|
import {AuthenticationService} from '../../model/network/authentication.service';
|
|
|
|
import {NavigationService} from '../../model/navigation.service';
|
|
|
|
import {NotificationService} from '../../model/notification.service';
|
|
|
|
import {BasicSettingsService} from './basic.settings.service';
|
|
|
|
import {BasicConfigDTO} from '../../../../common/entities/settings/BasicConfigDTO';
|
|
|
|
import {I18n} from '@ngx-translate/i18n-polyfill';
|
2017-07-15 22:09:48 +08:00
|
|
|
|
|
|
|
@Component({
|
2018-05-04 07:17:08 +08:00
|
|
|
selector: 'app-settings-basic',
|
2017-07-15 22:09:48 +08:00
|
|
|
templateUrl: './basic.settings.component.html',
|
|
|
|
styleUrls: ['./basic.settings.component.css',
|
|
|
|
'./../_abstract/abstract.settings.component.css'],
|
|
|
|
providers: [BasicSettingsService],
|
|
|
|
})
|
|
|
|
export class BasicSettingsComponent extends SettingsComponent<BasicConfigDTO> {
|
|
|
|
|
|
|
|
urlPlaceholder = location.origin;
|
2018-05-18 07:58:14 +08:00
|
|
|
urlBaseChanged = false;
|
|
|
|
urlError = false;
|
2017-07-15 22:09:48 +08:00
|
|
|
|
|
|
|
constructor(_authService: AuthenticationService,
|
|
|
|
_navigation: NavigationService,
|
|
|
|
_settingsService: BasicSettingsService,
|
2018-03-30 08:30:23 +08:00
|
|
|
notification: NotificationService,
|
|
|
|
i18n: I18n) {
|
2018-03-31 03:30:30 +08:00
|
|
|
super(i18n('Basic'), _authService, _navigation, _settingsService, notification, i18n, s => ({
|
2017-07-15 23:29:40 +08:00
|
|
|
port: s.Server.port,
|
|
|
|
imagesFolder: s.Server.imagesFolder,
|
|
|
|
applicationTitle: s.Client.applicationTitle,
|
2018-05-13 00:19:51 +08:00
|
|
|
publicUrl: s.Client.publicUrl,
|
|
|
|
urlBase: s.Client.urlBase
|
2017-07-15 23:29:40 +08:00
|
|
|
}));
|
2018-05-18 07:58:14 +08:00
|
|
|
this.checkUrlError();
|
2017-07-15 22:09:48 +08:00
|
|
|
}
|
|
|
|
|
2017-07-15 22:31:43 +08:00
|
|
|
public async save(): Promise<boolean> {
|
|
|
|
const val = await super.save();
|
2018-05-04 07:17:08 +08:00
|
|
|
if (val === true) {
|
2018-05-14 04:59:57 +08:00
|
|
|
this.notification.info(this.i18n('Restart the server to apply the new settings'));
|
2017-07-15 22:31:43 +08:00
|
|
|
}
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
2018-05-18 07:58:14 +08:00
|
|
|
calcBaseUrl(): string {
|
|
|
|
console.log(this.settings.publicUrl.replace(new RegExp('\\\\', 'g'), '/'));
|
|
|
|
console.log(this.settings.publicUrl.replace(new RegExp('\\\\', 'g'), '/')
|
|
|
|
.replace(new RegExp('http://', 'g'), ''));
|
|
|
|
console.log(this.settings.publicUrl.replace(new RegExp('\\\\', 'g'), '/')
|
|
|
|
.replace(new RegExp('http://', 'g'), '')
|
|
|
|
.replace(new RegExp('https://', 'g'), ''));
|
|
|
|
const url = this.settings.publicUrl.replace(new RegExp('\\\\', 'g'), '/')
|
|
|
|
.replace(new RegExp('http://', 'g'), '')
|
|
|
|
.replace(new RegExp('https://', 'g'), '');
|
|
|
|
if (url.indexOf('/') !== -1) {
|
|
|
|
return url.substring(url.indexOf('/'));
|
|
|
|
}
|
|
|
|
return '';
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
checkUrlError() {
|
|
|
|
this.urlError = this.settings.urlBase !== this.calcBaseUrl();
|
|
|
|
}
|
|
|
|
|
|
|
|
onUrlChanged() {
|
|
|
|
if (this.urlBaseChanged === false) {
|
|
|
|
this.settings.urlBase = this.calcBaseUrl();
|
|
|
|
} else {
|
|
|
|
this.checkUrlError();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
onUrlBaseChanged() {
|
|
|
|
this.urlBaseChanged = true;
|
|
|
|
|
|
|
|
this.checkUrlError();
|
|
|
|
}
|
|
|
|
|
2017-07-15 22:09:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|