import {Component, EventEmitter, Input, Output} from "@angular/core"; import {RouterHelper} from "../../utils/routerHelper.class"; import {properties} from "../../../../environments/environment"; import {StringUtils} from "../../utils/string-utils.class"; import {SearchFields} from "../../utils/properties/searchFields"; @Component({ selector: 'fos', template: `
{{title}} {{title}} ({{subjects.length}}) View all View all & suggest Suggest
{{title}}
View all
` }) export class FosComponent { @Input() subjects: {"id": string, "label": string}[]; @Input() viewAll: boolean = false; @Output() viewAllClicked = new EventEmitter(); @Output() suggestClicked = new EventEmitter(); public lessBtn: boolean = false; public threshold: number = 2; public routerHelper: RouterHelper = new RouterHelper(); public properties = properties; public title: string = "Fields of Science"; private searchFieldsHelper: SearchFields = new SearchFields(); public viewAllClick() { // if(this.subjects.length <= this.threshold*2) { // this.viewAll = true; // this.lessBtn = true; // } else { this.viewAll = true; this.viewAllClicked.emit('fos'); // } } public viewLessClick() { this.viewAll = false; this.viewAllClicked.emit(""); } public suggestClick() { this.suggestClicked.emit('fos'); } public urlEncodeAndQuote(str: string): string { return StringUtils.quote(StringUtils.URIEncode(str)); } public buildFosQueryParam(fos) { // return {'foslabel': this.urlEncodeAndQuote(fos.id+"||"+fos.label)}; return (this.searchFieldsHelper.getFosParameter() == 'foslabel' ? ({'foslabel': this.urlEncodeAndQuote(fos.id+"||"+fos.label)}) : ({'fos': this.urlEncodeAndQuote(fos.id)})); } public buildFosHrefParam(fos): string { // return ('foslabel='+this.urlEncodeAndQuote(fos.id+"||"+fos.label)); return (this.searchFieldsHelper.getFosParameter() == 'foslabel' ? ('foslabel='+this.urlEncodeAndQuote(fos.id+"||"+fos.label)) : ('fos='+this.urlEncodeAndQuote(fos.id))); } }