import {Component, OnInit} from "@angular/core";
import {Stakeholder} from "../openaireLibrary/monitor/entities/stakeholder";
import {StakeholderService} from "../openaireLibrary/monitor/services/stakeholder.service";
import {ActivatedRoute, Router} from "@angular/router";
import {SEOService} from "../openaireLibrary/sharedComponents/SEO/SEO.service";
import {PiwikService} from "../openaireLibrary/utils/piwik/piwik.service";
import {Meta, Title} from "@angular/platform-browser";
import {SearchCustomFilter} from "../openaireLibrary/searchPages/searchUtils/searchUtils.class";
import {LinksResolver} from "../search/links-resolver";
import {CustomFilterService} from "../shared/customFilter.service";
import {StakeholderBaseComponent} from "../openaireLibrary/monitor-admin/utils/stakeholder-base.component";
import {LayoutService} from "../openaireLibrary/dashboard/sharedComponents/sidebar/layout.service";
@Component({
selector: 'rpo',
template: `
{{stakeholder.name}}
{{entities.organizations}}
`
})
export class RpoComponent extends StakeholderBaseComponent implements OnInit {
stakeholder: Stakeholder;
alias: string;
isSearch: boolean = false;
loading: boolean = false;
constructor(private stakeholderService: StakeholderService,
private _customFilterService: CustomFilterService,
private layoutService: LayoutService,
protected _router: Router,
protected _route: ActivatedRoute,
protected seoService: SEOService,
protected _piwikService: PiwikService,
protected _title: Title,
protected _meta: Meta) {
super();
super.initRouterParams(this._route, event => {
this.isSearch = event.url.includes('search');
});
}
ngOnInit() {
this.layoutService.setRootClass('organization');
this.title = 'RPOs';
this.description = 'RPOs';
this.setMetadata();
this.params.subscribe(params => {
this._customFilterService.setCustomFilter(null);
this.alias = params['stakeholder'];
if (this.alias) {
this.loading = true;
this.subscriptions.push(this.stakeholderService.getStakeholder(this.alias, true).subscribe(stakeholder => {
this.stakeholder = stakeholder;
if (this.stakeholder && this.stakeholder.type === 'organization') {
LinksResolver.resetProperties();
LinksResolver.setSearchAndResultLanding("rpo/" + this.stakeholder.alias);
let value = this.stakeholder.index_id + "||" + this.stakeholder.index_name + "||" + this.stakeholder.index_shortName;
this._customFilterService.setCustomFilter(
[new SearchCustomFilter("National", "country", "IE", "Irish National Monitor", false),
new SearchCustomFilter("RPO", "relorganizationid", this.stakeholder.index_id, this.stakeholder.index_name, true)
]);
this.loading = false;
} else {
this.navigateToError();
}
}));
} else {
this.stakeholder = null;
}
});
}
ngOnDestroy() {
super.ngOnDestroy();
this.layoutService.setRootClass(null);
}
}