2018-06-26 05:16:59 +02:00
|
|
|
import {
|
|
|
|
Component,
|
|
|
|
OnInit,
|
|
|
|
} from '@angular/core';
|
|
|
|
|
2021-06-07 20:13:58 +02:00
|
|
|
import { ApiService } from 'jslib-common/abstractions/api.service';
|
|
|
|
import { I18nService } from 'jslib-common/abstractions/i18n.service';
|
2021-10-20 18:30:04 +02:00
|
|
|
import { LogService } from 'jslib-common/abstractions/log.service';
|
2021-12-07 20:41:45 +01:00
|
|
|
import { PlatformUtilsService } from 'jslib-common/abstractions/platformUtils.service';
|
2018-06-26 17:50:23 +02:00
|
|
|
|
2021-06-07 20:13:58 +02:00
|
|
|
import { UpdateDomainsRequest } from 'jslib-common/models/request/updateDomainsRequest';
|
2018-06-26 05:16:59 +02:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'app-domain-rules',
|
|
|
|
templateUrl: 'domain-rules.component.html',
|
|
|
|
})
|
|
|
|
export class DomainRulesComponent implements OnInit {
|
|
|
|
loading = true;
|
|
|
|
custom: string[] = [];
|
2018-06-26 17:50:23 +02:00
|
|
|
global: any[] = [];
|
2018-06-26 05:16:59 +02:00
|
|
|
formPromise: Promise<any>;
|
|
|
|
|
|
|
|
constructor(private apiService: ApiService, private i18nService: I18nService,
|
2021-12-07 20:41:45 +01:00
|
|
|
private platformUtilsService: PlatformUtilsService, private logService: LogService) { }
|
2018-06-26 05:16:59 +02:00
|
|
|
|
|
|
|
async ngOnInit() {
|
|
|
|
const response = await this.apiService.getSettingsDomains();
|
|
|
|
this.loading = false;
|
2018-06-26 17:50:23 +02:00
|
|
|
if (response.equivalentDomains != null) {
|
2021-02-03 18:41:33 +01:00
|
|
|
this.custom = response.equivalentDomains.map(d => d.join(', '));
|
2018-06-26 17:50:23 +02:00
|
|
|
}
|
|
|
|
if (response.globalEquivalentDomains != null) {
|
2021-02-03 18:41:33 +01:00
|
|
|
this.global = response.globalEquivalentDomains.map(d => {
|
2018-06-26 17:50:23 +02:00
|
|
|
return {
|
|
|
|
domains: d.domains.join(', '),
|
|
|
|
excluded: d.excluded,
|
|
|
|
key: d.type,
|
|
|
|
};
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
toggleExcluded(globalDomain: any) {
|
|
|
|
globalDomain.excluded = !globalDomain.excluded;
|
|
|
|
}
|
|
|
|
|
|
|
|
customize(globalDomain: any) {
|
|
|
|
globalDomain.excluded = true;
|
|
|
|
this.custom.push(globalDomain.domains);
|
|
|
|
}
|
|
|
|
|
|
|
|
remove(index: number) {
|
|
|
|
this.custom.splice(index, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
add() {
|
|
|
|
this.custom.push('');
|
2018-06-26 05:16:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
async submit() {
|
2018-06-26 17:50:23 +02:00
|
|
|
const request = new UpdateDomainsRequest();
|
2021-02-03 18:41:33 +01:00
|
|
|
request.excludedGlobalEquivalentDomains = this.global.filter(d => d.excluded)
|
|
|
|
.map(d => d.key);
|
2018-06-26 17:50:23 +02:00
|
|
|
if (request.excludedGlobalEquivalentDomains.length === 0) {
|
|
|
|
request.excludedGlobalEquivalentDomains = null;
|
|
|
|
}
|
2021-02-03 18:41:33 +01:00
|
|
|
request.equivalentDomains = this.custom.filter(d => d != null && d.trim() !== '')
|
|
|
|
.map(d => d.split(',').map(d2 => d2.trim()));
|
2018-06-26 17:50:23 +02:00
|
|
|
if (request.equivalentDomains.length === 0) {
|
|
|
|
request.equivalentDomains = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
this.formPromise = this.apiService.putSettingsDomains(request);
|
|
|
|
await this.formPromise;
|
2021-12-07 20:41:45 +01:00
|
|
|
this.platformUtilsService.showToast('success', null, this.i18nService.t('domainsUpdated'));
|
2021-10-20 18:30:04 +02:00
|
|
|
} catch (e) {
|
|
|
|
this.logService.error(e);
|
|
|
|
}
|
2018-06-26 17:50:23 +02:00
|
|
|
}
|
2018-06-26 05:16:59 +02:00
|
|
|
|
2018-06-26 17:50:23 +02:00
|
|
|
indexTrackBy(index: number, obj: any): any {
|
|
|
|
return index;
|
2018-06-26 05:16:59 +02:00
|
|
|
}
|
|
|
|
}
|