import { ChangeDetectorRef, Component, ElementRef, EventEmitter, HostListener, Input, Output, QueryList, ViewChild, ViewChildren } from '@angular/core'; import {properties} from "../../../../environments/environment"; @Component({ selector: 'showSubjects', template: `
Subjects by Vocabulary
View all
Keywords
View all

{{subjects.join(', ')}}

{{key}}: {{subject}}

EOSC: {{subject.value}}

` }) export class ShowSubjectsComponent { @Input() isMobile: boolean = false; @Input() subjects: string[]; @Input() otherSubjects: Map; @Input() classifiedSubjects: Map; @Input() eoscSubjects: any[]; isLarge: boolean = false; isClassifiedLarge: boolean = false; @Input() viewAllSubjects: boolean = false; @Input() viewAllClassifiedSubjects: boolean = false; @Output() viewAllClicked = new EventEmitter(); properties = properties; specialSubjects = []; @ViewChildren("content", { read: ElementRef }) content: QueryList; @ViewChildren("classifiedContent", { read: ElementRef }) classifiedContent: QueryList; @ViewChild('subjectsModal') subjectsModal; @ViewChild('subjectsByVocabularyModal') subjectsByVocabularyModal; @HostListener('window:resize', ['$event']) onResize(event) { this.checkLarge(); this.checkLargeClassified(); } constructor(private cdr: ChangeDetectorRef) { if(properties.dashboard == "explore") { this.specialSubjects = [ // "Physics::Optics", // "Astrophysics::Cosmology and Extragalactic Astrophysics", // "Computer Science::Information Theory", // "Physics::Accelerator Physics", // "Condensed Matter::Superconductivity", "Physics::Atomic Physics", // "Computer Science::Robotics", // "Computer Science::Computer Science and Game Theory", // "Computer Science::Neural and Evolutionary Computation", "Mathematics::Combinatorics", // "Mathematics::Probability", // "Computer Science::Operating Systems", // "lcsh:Medicine", // "lcsh:Science", // "lcsh:Biology (General)", // "lcsh:Chemistry", // "lcsh:Engineering (General). Civil engineering (General)", // "lcsh:Technology" ]; } } ngOnInit() { } ngAfterViewInit() { setTimeout(() => { this.checkLarge(); this.checkLargeClassified(); }) } checkLarge() { let overflow = 42; if(typeof document !== "undefined" && this.content) { let element = this.content.find(content => content.nativeElement.id === "content"); this.isLarge = (element && element.nativeElement.offsetHeight > overflow); } } checkLargeClassified() { this.isClassifiedLarge = false; let overflow = 69; // 2 * label height (27): 54 + grid margin: 15 if(typeof document !== "undefined" && this.classifiedSubjects && this.classifiedContent) { this.getKeys(this.classifiedSubjects).forEach(key => { let tag = this.classifiedContent.find(tag => tag.nativeElement.id === "content_"+key); if(tag && tag.nativeElement.offsetHeight > overflow) { this.isClassifiedLarge = true; } }); } if(typeof document !== "undefined" && this.eoscSubjects && this.classifiedContent) { let tag = this.classifiedContent.find(tag => tag.nativeElement.id === "content_eosc"); if(tag && tag.nativeElement.offsetHeight > overflow) { this.isClassifiedLarge = true; } } } public getKeys(map) { return map ? Array.from(map.keys()) : []; } getSubjectParameter(param){ return {'f0':'resultsubject','fv0':'"' +(param)+'"', size:50}; } public openSubjectsModal() { this.subjectsModal.cancelButton = false; this.subjectsModal.okButton = false; this.subjectsModal.alertTitle = "Subjects"; this.subjectsModal.open(); } public openSubjectsByVocabularyModal() { this.subjectsByVocabularyModal.cancelButton = false; this.subjectsByVocabularyModal.okButton = false; this.subjectsByVocabularyModal.alertTitle = "Subjects by Vocabulary"; this.subjectsByVocabularyModal.open(); } public viewAllSubjectsClicked() { if(this.isMobile) { this.viewAllSubjects = true; this.viewAllClicked.emit({ subtitle: 'Keywords', id: 'subjects' }); } else { this.openSubjectsModal(); } } public viewAllSubjectsByVocabularyClicked() { if(this.isMobile) { this.viewAllClassifiedSubjects = true; this.viewAllClicked.emit({ subtitle: 'Subjects by Vocabulary', id: 'classifiedSubjects' }); } else { this.openSubjectsByVocabularyModal(); } } }