2018-04-04 15:47:43 +02:00
|
|
|
import {
|
|
|
|
EventEmitter,
|
|
|
|
Output,
|
|
|
|
} from '@angular/core';
|
|
|
|
|
|
|
|
import { Angulartics2 } from 'angulartics2';
|
|
|
|
|
|
|
|
import { EnvironmentService } from '../../abstractions/environment.service';
|
|
|
|
import { I18nService } from '../../abstractions/i18n.service';
|
2018-10-03 05:09:19 +02:00
|
|
|
import { PlatformUtilsService } from '../../abstractions/platformUtils.service';
|
2018-04-04 15:47:43 +02:00
|
|
|
|
|
|
|
export class EnvironmentComponent {
|
|
|
|
@Output() onSaved = new EventEmitter();
|
|
|
|
|
|
|
|
iconsUrl: string;
|
|
|
|
identityUrl: string;
|
|
|
|
apiUrl: string;
|
|
|
|
webVaultUrl: string;
|
2018-08-20 19:45:32 +02:00
|
|
|
notificationsUrl: string;
|
2018-04-04 15:47:43 +02:00
|
|
|
baseUrl: string;
|
|
|
|
showCustom = false;
|
|
|
|
|
2018-10-03 05:09:19 +02:00
|
|
|
constructor(protected analytics: Angulartics2, protected platformUtilsService: PlatformUtilsService,
|
2018-04-04 15:47:43 +02:00
|
|
|
protected environmentService: EnvironmentService, protected i18nService: I18nService) {
|
|
|
|
this.baseUrl = environmentService.baseUrl || '';
|
|
|
|
this.webVaultUrl = environmentService.webVaultUrl || '';
|
|
|
|
this.apiUrl = environmentService.apiUrl || '';
|
|
|
|
this.identityUrl = environmentService.identityUrl || '';
|
|
|
|
this.iconsUrl = environmentService.iconsUrl || '';
|
2018-08-20 19:45:32 +02:00
|
|
|
this.notificationsUrl = environmentService.notificationsUrl || '';
|
2018-04-04 15:47:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
async submit() {
|
|
|
|
const resUrls = await this.environmentService.setUrls({
|
|
|
|
base: this.baseUrl,
|
|
|
|
api: this.apiUrl,
|
|
|
|
identity: this.identityUrl,
|
|
|
|
webVault: this.webVaultUrl,
|
|
|
|
icons: this.iconsUrl,
|
2018-08-20 19:45:32 +02:00
|
|
|
notifications: this.notificationsUrl,
|
2018-04-04 15:47:43 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
// re-set urls since service can change them, ex: prefixing https://
|
|
|
|
this.baseUrl = resUrls.base;
|
|
|
|
this.apiUrl = resUrls.api;
|
|
|
|
this.identityUrl = resUrls.identity;
|
|
|
|
this.webVaultUrl = resUrls.webVault;
|
|
|
|
this.iconsUrl = resUrls.icons;
|
2018-08-20 19:45:32 +02:00
|
|
|
this.notificationsUrl = resUrls.notifications;
|
2018-04-04 15:47:43 +02:00
|
|
|
|
|
|
|
this.analytics.eventTrack.next({ action: 'Set Environment URLs' });
|
2018-10-03 05:09:19 +02:00
|
|
|
this.platformUtilsService.showToast('success', null, this.i18nService.t('environmentSaved'));
|
2018-04-04 15:47:43 +02:00
|
|
|
this.saved();
|
|
|
|
}
|
|
|
|
|
|
|
|
toggleCustom() {
|
|
|
|
this.showCustom = !this.showCustom;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected saved() {
|
|
|
|
this.onSaved.emit();
|
|
|
|
}
|
|
|
|
}
|