connect-admin/src/app/pages/content-providers/manage-content-providers.co...

80 lines
3.3 KiB
TypeScript

import {Component, ElementRef, Input, OnInit, ViewChild} from '@angular/core';
import {Router} from "@angular/router";
import {RemoveContentProvidersComponent} from './remove-content-providers.component';
import {Title} from '@angular/platform-browser';
import {
FullScreenModalComponent
} from "../../openaireLibrary/utils/modal/full-screen-modal/full-screen-modal.component";
import {StringUtils} from "../../openaireLibrary/utils/string-utils.class";
import {EnvProperties} from "../../openaireLibrary/utils/properties/env-properties";
import {properties} from "../../../environments/environment";
import {Subscriber} from "rxjs";
import {CommunityInfo} from "../../openaireLibrary/connect/community/communityInfo";
import {CommunityService} from "../../openaireLibrary/connect/community/community.service";
@Component({
selector: 'manage-content-providers',
template: `
<remove-content-providers #removeContentProvidersComponent (addContentProviders)="openAddContentProviders()" [communityContentProviders]="communityContentProviders"
[loading]="showLoadingInRemove" [community]="community" [disableAdd]="add.loading"
(communityContentProvidersChanged)="communityContentProvidersChanged($event)">
</remove-content-providers>
<fs-modal #fsModal>
<add-content-providers #add [communityContentProviders]="communityContentProviders" [community]="community"
(communityContentProvidersChanged)="communityContentProvidersChanged($event)"></add-content-providers>
</fs-modal>
`
})
export class ManageContentProvidersComponent implements OnInit {
@Input() communityContentProviders = [];
@ViewChild(RemoveContentProvidersComponent) removeContentProvidersComponent: RemoveContentProvidersComponent;
@ViewChild('fsModal', { static: true }) fullscreen: FullScreenModalComponent;
private subscriptions: any[] = [];
public showLoadingInRemove: boolean = true;
public body: string = "Send from page";
public properties: EnvProperties = properties;
public community: CommunityInfo;
constructor(private element: ElementRef,
private title: Title,
private communityService: CommunityService, private _router: Router) {
}
ngOnInit() {
this.subscriptions.push(this.communityService.getCommunityAsObservable().subscribe(community => {
this.community = community;
if (this.community) {
this.title.setTitle(this.community.shortTitle.toUpperCase() + ' | Content Providers');
this.body = "[Please write your message here]";
this.body = StringUtils.URIEncode(this.body);
}
}));
}
public ngOnDestroy() {
this.subscriptions.forEach(sub => {
if (sub instanceof Subscriber) {
sub.unsubscribe();
}
});
}
public openAddContentProviders() {
this.fullscreen.title = "Search and Add Content Providers";
this.fullscreen.okButtonText = "Done";
this.fullscreen.back = true;
this.fullscreen.okButton = true;
this.fullscreen.open();
}
public communityContentProvidersChanged($event) {
this.communityContentProviders = $event.value;
this.showLoadingInRemove = false;
if (this.fullscreen.isOpen) {
this.removeContentProvidersComponent.applyFilters();
}
}
}