display new subjects (sdg/fos) in home and subjects pages of the community gateways

This commit is contained in:
Alex Martzios 2023-03-16 16:38:37 +02:00
parent 8c7933a1ea
commit 6e6676003d
3 changed files with 1193 additions and 896 deletions

File diff suppressed because it is too large Load Diff

View File

@ -29,20 +29,20 @@ import {OpenaireEntities} from '../openaireLibrary/utils/properties/searchFields
@Component({
selector: 'community',
templateUrl: 'community.component.html',
styles: [
styles: [
`
#mytabs .uk-tab::before {
border-bottom: none;
}
#mytabs::before {
content: "";
position: absolute;
bottom: 0;
left: 0;
right: 0;
border-bottom: 1px solid #eaeaea;
}
`
#mytabs .uk-tab::before {
border-bottom: none;
}
#mytabs::before {
content: "";
position: absolute;
bottom: 0;
left: 0;
right: 0;
border-bottom: 1px solid #eaeaea;
}
`
]
})
@ -86,13 +86,18 @@ export class CommunityComponent {
public thresholdDescription: number = 500;
public descriptionDiff: number = 100;
page = 1;
size = 5;
page = 1;
size = 5;
subscribers: number = 0;
subs: Subscription[] = [];
displayedAllSubjects = [];
displayedSubjects = [];
displayedSdg = [];
displayedFos = [];
@ViewChild(StatisticsForDashboardComponent) statistics: StatisticsForDashboardComponent = null;
public activeTab = "summary";
public show: string = 'overview';
@ -110,7 +115,7 @@ export class CommunityComponent {
selectedEntity = 'result';
selectedEntitySimpleUrl;
selectedEntityAdvancedUrl;
resultTypes: Filter = {
resultTypes: Filter = {
values: [],
filterId: "type",
countSelectedValues: 0,
@ -120,7 +125,7 @@ export class CommunityComponent {
title: "Type",
filterOperator: "or"
};
showPublications: boolean = false;
showPublications: boolean = false;
showDatasets: boolean = false;
showSoftware: boolean = false;
showOrp: boolean = false;
@ -135,9 +140,9 @@ export class CommunityComponent {
filterId: "resultbestaccessright",
value: "Open Access"
};
disableSelect: boolean = true;
openaireEntities= OpenaireEntities;
piwikSiteId;
disableSelect: boolean = true;
openaireEntities= OpenaireEntities;
piwikSiteId;
constructor(
private element: ElementRef,
@ -156,9 +161,9 @@ export class CommunityComponent {
private _zenodoCommunitieService: ZenodoCommunitiesService,
private seoService: SEOService,
private userManagementService: UserManagementService,
private _renderer2: Renderer2,
private cdr: ChangeDetectorRef,
@Inject(DOCUMENT) private _document: Document) {
private _renderer2: Renderer2,
private cdr: ChangeDetectorRef,
@Inject(DOCUMENT) private _document: Document) {
var description = "OpenAIRE - Connect, Community Dashboard, research community";
var title = "OpenAIRE - Connect";
@ -192,6 +197,18 @@ export class CommunityComponent {
community => {
this.community = community;
if(community && !ConnectHelper.isPrivate(community, this.user)) {
this.displayedSubjects = community.subjects;
this.displayedSdg = community.sdg;
this.displayedFos = community.fos;
this.displayedSubjects.forEach(element => {
this.displayedAllSubjects.push({value: element, type: 'resultsubject'});
});
this.displayedSdg.forEach(element => {
this.displayedAllSubjects.push({value: element, type: 'sdg'});
});
this.displayedFos.forEach(element => {
this.displayedAllSubjects.push({value: element, type: 'fos'});
});
if (community.description != null && (community.description.length - this.thresholdDescription <= this.descriptionDiff)) {
this.thresholdDescription = community.description.length;
}
@ -204,12 +221,12 @@ export class CommunityComponent {
this._meta.updateTag({content: community.title}, "property='og:title'");
this._title.setTitle(community.title);
if (this.properties.enablePiwikTrack && (typeof document !== 'undefined')) {
this.subs.push(this.config.communityInformationState.subscribe(portal => {
if(portal && portal.piwik) {
this.piwikSiteId = portal.piwik;
this.subs.push(this._piwikService.trackView(this.properties, community.title, this.piwikSiteId).subscribe());
}
}));
this.subs.push(this.config.communityInformationState.subscribe(portal => {
if(portal && portal.piwik) {
this.piwikSiteId = portal.piwik;
this.subs.push(this._piwikService.trackView(this.properties, community.title, this.piwikSiteId).subscribe());
}
}));
}
if (this.community.zenodoCommunity) {
this.subs.push(this._zenodoCommunitieService.getZenodoCommunityById(this.properties, this.properties.zenodoCommunities + this.community.zenodoCommunity, null).subscribe(
@ -283,47 +300,47 @@ export class CommunityComponent {
this.handleError("Error getting community with id: " + this.communityId, error);
}
));
this.subs.push(this.config.communityInformationState.subscribe(data => {
if (data) {
var showEntity = {};
for (var i = 0; i < data['entities'].length; i++) {
showEntity["" + data['entities'][i]["pid"] + ""] = data['entities'][i]["isEnabled"];
}
this.showPublications = !!showEntity["publication"];
this.showDatasets = !!showEntity["dataset"];
this.showSoftware = !!showEntity["software"];
this.showOrp = !!showEntity["orp"];
this.showProjects = !!showEntity["project"];
this.showDataProviders = !!showEntity["datasource"];
if (this.showPublications) {
this.resultTypes.values.push({
name: this.openaireEntities.PUBLICATIONS,
id: "publications",
selected: false,
number: 0
});
}
if (this.showDatasets) {
this.resultTypes.values.push({
name: this.openaireEntities.DATASETS,
id: "datasets",
selected: false,
number: 0
});
}
if (this.showSoftware) {
this.resultTypes.values.push({
name: this.openaireEntities.SOFTWARE,
id: "software",
selected: false,
number: 0
});
}
if (this.showOrp) {
this.resultTypes.values.push({name: this.openaireEntities.OTHER, id: "other", selected: false, number: 0});
}
}
}));
this.subs.push(this.config.communityInformationState.subscribe(data => {
if (data) {
var showEntity = {};
for (var i = 0; i < data['entities'].length; i++) {
showEntity["" + data['entities'][i]["pid"] + ""] = data['entities'][i]["isEnabled"];
}
this.showPublications = !!showEntity["publication"];
this.showDatasets = !!showEntity["dataset"];
this.showSoftware = !!showEntity["software"];
this.showOrp = !!showEntity["orp"];
this.showProjects = !!showEntity["project"];
this.showDataProviders = !!showEntity["datasource"];
if (this.showPublications) {
this.resultTypes.values.push({
name: this.openaireEntities.PUBLICATIONS,
id: "publications",
selected: false,
number: 0
});
}
if (this.showDatasets) {
this.resultTypes.values.push({
name: this.openaireEntities.DATASETS,
id: "datasets",
selected: false,
number: 0
});
}
if (this.showSoftware) {
this.resultTypes.values.push({
name: this.openaireEntities.SOFTWARE,
id: "software",
selected: false,
number: 0
});
}
if (this.showOrp) {
this.resultTypes.values.push({name: this.openaireEntities.OTHER, id: "other", selected: false, number: 0});
}
}
}));
}
private searchPublications(page: number, size: number) {
@ -385,7 +402,7 @@ export class CommunityComponent {
)
) {
this.fetchFeaturedDatasets.getAllResultsForCommunity("dataset", this.communityId, page, size, this.properties, "enermaps::selection");
// console.log(this.fetchFeaturedDatasets);
// console.log(this.fetchFeaturedDatasets);
}
this.reloadFeaturedDatasets = false;
}
@ -522,9 +539,9 @@ export class CommunityComponent {
return tooltipContent;
}
public buildContentProvidersTooltip(): string {
public buildContentProvidersTooltip(): string {
let tooltipContent: string = "<div>";
if (this.contentProviderTotal != null && this.contentProviderTotal > 0 && this.isEntityEnabled('datasource') && this.isRouteEnabled(this.searchLinkToDataProviders)) {
tooltipContent += "<span class='uk-text-bold'>Content Providers</span>";
}
@ -541,7 +558,7 @@ export class CommunityComponent {
tooltipContent += "<span class='uk-text-bold'>Zenodo</span> is a catch-all repository for OpenAIRE.";
tooltipContent += "<div class='uk-margin-small-top'>A <span class='uk-text-bold'>Zenodo Community</span> is created and curated by Zenodo users.</div>";
tooltipContent += "</div>";
return tooltipContent;
}
@ -643,24 +660,24 @@ export class CommunityComponent {
this.activeTab = 'mapping';
} else if (activeTabId == 'enermaps') {
this.show = 'enermaps';
this.activeTab = 'enermaps';
this.activeTab = 'enermaps';
this.searchFeaturedDatasets(1, this.fetchFeaturedDatasets.searchUtils.totalResults);
} else if (activeTabId == 'twitter') {
this.show = 'twitter';
this.activeTab = 'twitter';
}
this.show = 'twitter';
this.activeTab = 'twitter';
}
}
}
isPrivate(){
return ConnectHelper.isPrivate(this.community, this.user);
}
disableSelectChange(event: boolean) {
disableSelectChange(event: boolean) {
this.disableSelect = event;
this.cdr.detectChanges();
}
public updatePage(event) {
public updatePage(event) {
this.page = event.value;
}
}

View File

@ -18,112 +18,330 @@ import {Subscriber, Subscription} from "rxjs";
<schema2jsonld *ngIf="url" [URL]="url" [name]="pageTitle" type="other"></schema2jsonld>
<div style="min-height: 650px;">
<div class="uk-container uk-container-large uk-section uk-section-small uk-padding-remove-bottom">
<div class="uk-padding-small uk-padding-remove-horizontal">
<breadcrumbs [breadcrumbs]="breadcrumbs"></breadcrumbs>
</div>
</div>
<div class="uk-container uk-container-large uk-section uk-section-small">
<div *ngIf="showLoading" class="uk-margin-large">
<div class="uk-animation-fade uk-margin-top uk-width-1-1" role="alert">
<span class="loading-gif uk-align-center"></span>
</div>
</div>
<div *ngIf="!showLoading">
<h1 class="uk-margin-top">
Subjects
</h1>
<div *ngIf="pageContents && pageContents['top'] && pageContents['top'].length > 0">
<helper *ngIf="pageContents && pageContents['top'] && pageContents['top'].length > 0"
[texts]="pageContents['top']">
</helper>
</div>
<ng-container *ngIf="groupedSubjects?.length">
<div class="uk-padding uk-margin-top">
<ul class="uk-nav uk-nav-default uk-flex uk-flex-center uk-flex-wrap">
<li *ngFor="let item of groupedSubjects; let i = index;" class="uk-margin-left uk-margin-right"
[class]="index == i ? 'uk-active':''" (click)="changeDisplayedSubjects(i, item)">
<a class="uk-padding-remove">{{item.group}}</a>
</li>
</ul>
</div>
<!-- View for 'All' -->
<div *ngIf="index == 0 && groupedSubjects.length > 1" class="uk-margin-large-top uk-grid uk-child-width-1-4@m" uk-grid>
<!-- <div *ngIf="index == 0" class="uk-margin-large-top uk-grid uk-child-width-1-4@m" uk-grid>-->
<div *ngFor="let item of groupedSubjects.slice(1); let i = index;">
<div>
<h6>{{item.group}}</h6>
<div *ngFor="let subItem of item.data.slice(0, subjectsLimit)" class="uk-margin-small-bottom">
<a [queryParams]="{f0:'resultsubject',fv0:createParams(subItem)}" class="uk-link-text"
routerLinkActive="router-link-active" [routerLink]="properties.searchLinkToAdvancedResults"
[attr.uk-tooltip]="subItem.length > maxCharacters ? subItem :''">
<span>{{subItem.length > maxCharacters ? subItem.substring(0,maxCharacters)+'...' : subItem}}</span>
</a>
</div>
<div *ngIf="item.data.length > subjectsLimit">
<a (click)="changeDisplayedSubjects(i+1, item)" class="view-more-less-link">
View all
</a>
</div>
</div>
</div>
</div>
<!-- View for a single group -->
<div *ngIf="index != 0 || groupedSubjects.length == 1" class="uk-margin-large-top">
<!-- <div *ngIf="index != 0" class="uk-margin-large-top">-->
<div>
<div>
<h6>{{groupedSubjects[index].group}}</h6>
<ng-container *ngIf="subjectsColumns?.length == 0; else elseBlock">
<div *ngFor="let subItem of groupedSubjects[index].data" class="uk-margin-small-bottom">
<a [queryParams]="{f0:'resultsubject',fv0:createParams(subItem)}" class="uk-link-text"
routerLinkActive="router-link-active" [routerLink]="properties.searchLinkToAdvancedResults">
<span>{{subItem.length > maxCharacters ? subItem.substring(0,maxCharacters)+'...' : subItem}}</span>
</a>
</div>
</ng-container>
<ng-template #elseBlock>
<div class="uk-grid uk-child-width-1-4@m" uk-grid>
<div *ngFor="let group of subjectsColumns">
<div *ngFor="let subItem of group" class="uk-margin-small-bottom">
<a [queryParams]="{f0:'resultsubject',fv0:createParams(subItem)}" class="uk-link-text"
routerLinkActive="router-link-active" [routerLink]="properties.searchLinkToAdvancedResults">
<span>{{subItem.length > maxCharacters ? subItem.substring(0,maxCharacters)+'...' : subItem}}</span>
</a>
</div>
</div>
</div>
</ng-template>
</div>
</div>
</div>
</ng-container>
</div>
</div>
</div>
<div class="uk-padding-small uk-padding-remove-horizontal">
<breadcrumbs [breadcrumbs]="breadcrumbs"></breadcrumbs>
</div>
</div>
<div class="uk-container uk-container-large uk-section uk-section-small">
<div *ngIf="showLoading" class="uk-margin-large">
<div class="uk-animation-fade uk-margin-top uk-width-1-1" role="alert">
<span class="loading-gif uk-align-center"></span>
</div>
</div>
<div *ngIf="!showLoading">
<h1 class="uk-margin-top">
Subjects
</h1>
<div *ngIf="pageContents && pageContents['top'] && pageContents['top'].length > 0">
<helper *ngIf="pageContents && pageContents['top'] && pageContents['top'].length > 0"
[texts]="pageContents['top']">
</helper>
</div>
<div class="uk-margin-large-top" *ngIf="displayedSubjects?.length == 0 && displayedSdg?.length == 0 && displayedFos?.length == 0"
class="uk-card uk-card-default uk-padding-large uk-text-center uk-margin-bottom uk-text-bold">
<div>No subjects</div>
</div>
<div class="uk-margin-large-top" *ngIf="displayedSubjects?.length > 0 || displayedSdg?.length > 0 || displayedFos?.length > 0">
<ul uk-tab class="uk-tab uk-margin-bottom uk-flex uk-flex-center uk-flex-left@m">
<li class="uk-active" *ngIf="displayedAllSubjects?.length" (click)="groupSubjects(displayedAllSubjects, 'all')">
<a>All ({{displayedAllSubjects.length}})</a>
</li>
<li *ngIf="displayedSubjects?.length" (click)="groupSubjects(displayedSubjects, 'freeText')">
<a>Free Text ({{displayedSubjects.length}})</a>
</li>
<li *ngIf="displayedSdg?.length" (click)="groupSubjects(displayedSdg, 'sdg')">
<a>SDGs ({{displayedSdg.length}})</a>
</li>
<li *ngIf="displayedFos?.length" (click)="groupSubjects(displayedFos, 'fos')">
<a>Fields of Science ({{displayedFos.length}})</a>
</li>
</ul>
<ul class="uk-switcher">
<li *ngIf="displayedAllSubjects?.length">
<ng-container *ngIf="groupedAllSubjects?.length">
<div>
<ul class="uk-nav uk-nav-default uk-flex uk-flex-wrap">
<li *ngFor="let item of groupedAllSubjects; let i = index;" class="uk-margin-right" [class.uk-margin-left]="i != 0"
[class]="indexAll == i ? 'uk-active':''" (click)="changeDisplayedSubjects(i, item)">
<a class="uk-padding-remove">{{item.group}}</a>
</li>
</ul>
</div>
<!-- View for 'All' -->
<div *ngIf="indexAll == 0 && groupedAllSubjects.length > 1" class="uk-margin-large-top uk-grid uk-child-width-1-4@m" uk-grid>
<div *ngFor="let item of groupedAllSubjects.slice(1); let i = index;">
<div>
<h6>{{item.group}}</h6>
<div *ngFor="let subItem of item.data.slice(0, subjectsLimit)" class="uk-margin-small-bottom">
<a [queryParams]="{f0:subItem.type,fv0:createParams(subItem.value)}" class="uk-link-text"
routerLinkActive="router-link-active" [routerLink]="properties.searchLinkToAdvancedResults"
[attr.uk-tooltip]="subItem.value.length > maxCharacters ? subItem.value :''">
<span>{{subItem.value.length > maxCharacters ? subItem.value.substring(0,maxCharacters)+'...' : subItem.value}}</span>
</a>
</div>
<div *ngIf="item.data.length > subjectsLimit">
<a (click)="changeDisplayedSubjects(i+1, item)" class="view-more-less-link">
View all
</a>
</div>
</div>
</div>
</div>
<!-- View for a single group -->
<div *ngIf="indexAll != 0 || groupedAllSubjects.length == 1" class="uk-margin-large-top">
<div>
<div>
<h6>{{groupedAllSubjects[indexAll].group}}</h6>
<ng-container *ngIf="subjectsColumns?.length == 0; else elseBlock">
<div *ngFor="let subItem of groupedAllSubjects[indexAll].data" class="uk-margin-small-bottom">
<a [queryParams]="{f0:subItem.type,fv0:createParams(subItem.value)}" class="uk-link-text"
routerLinkActive="router-link-active" [routerLink]="properties.searchLinkToAdvancedResults"
[attr.uk-tooltip]="subItem.value.length > maxCharacters ? subItem.value :''">
<span>{{subItem.value.length > maxCharacters ? subItem.value.substring(0,maxCharacters)+'...' : subItem.value}}</span>
</a>
</div>
</ng-container>
<ng-template #elseBlock>
<div class="uk-grid uk-child-width-1-4@m" uk-grid>
<div *ngFor="let group of subjectsColumns">
<div *ngFor="let subItem of group" class="uk-margin-small-bottom">
<a [queryParams]="{f0:subItem.type,fv0:createParams(subItem.value)}" class="uk-link-text"
routerLinkActive="router-link-active" [routerLink]="properties.searchLinkToAdvancedResults"
[attr.uk-tooltip]="subItem.value.length > maxCharacters ? subItem.value :''">
<span>{{subItem.value.length > maxCharacters ? subItem.value.substring(0,maxCharacters)+'...' : subItem.value}}</span>
</a>
</div>
</div>
</div>
</ng-template>
</div>
</div>
</div>
</ng-container>
</li>
<li *ngIf="displayedSubjects?.length">
<ng-container *ngIf="groupedSubjects?.length">
<div>
<ul class="uk-nav uk-nav-default uk-flex uk-flex-wrap">
<li *ngFor="let item of groupedSubjects; let i = index;" class="uk-margin-right" [class.uk-margin-left]="i != 0"
[class]="indexSubjects == i ? 'uk-active':''" (click)="changeDisplayedSubjects(i, item)">
<a class="uk-padding-remove">{{item.group}}</a>
</li>
</ul>
</div>
<!-- View for 'All' -->
<div *ngIf="indexSubjects == 0 && groupedSubjects.length > 1" class="uk-margin-large-top uk-grid uk-child-width-1-4@m" uk-grid>
<div *ngFor="let item of groupedSubjects.slice(1); let i = index;">
<div>
<h6>{{item.group}}</h6>
<div *ngFor="let subItem of item.data.slice(0, subjectsLimit)" class="uk-margin-small-bottom">
<a [queryParams]="{f0:'resultsubject',fv0:createParams(subItem)}" class="uk-link-text"
routerLinkActive="router-link-active" [routerLink]="properties.searchLinkToAdvancedResults"
[attr.uk-tooltip]="subItem.length > maxCharacters ? subItem :''">
<span>{{subItem.length > maxCharacters ? subItem.substring(0,maxCharacters)+'...' : subItem}}</span>
</a>
</div>
<div *ngIf="item.data.length > subjectsLimit">
<a (click)="changeDisplayedSubjects(i+1, item)" class="view-more-less-link">
View all
</a>
</div>
</div>
</div>
</div>
<!-- View for a single group -->
<div *ngIf="indexSubjects != 0 || groupedSubjects.length == 1" class="uk-margin-large-top">
<div>
<div>
<h6>{{groupedSubjects[indexSubjects]?.group}}</h6>
<ng-container *ngIf="subjectsColumns?.length == 0; else elseBlock">
<div *ngFor="let subItem of groupedSubjects[indexSubjects]?.data" class="uk-margin-small-bottom">
<a [queryParams]="{f0:'resultsubject',fv0:createParams(subItem)}" class="uk-link-text"
routerLinkActive="router-link-active" [routerLink]="properties.searchLinkToAdvancedResults"
[attr.uk-tooltip]="subItem.length > maxCharacters ? subItem :''">
<span>{{subItem.length > maxCharacters ? subItem.substring(0,maxCharacters)+'...' : subItem}}</span>
</a>
</div>
</ng-container>
<ng-template #elseBlock>
<div class="uk-grid uk-child-width-1-4@m" uk-grid>
<div *ngFor="let group of subjectsColumns">
<div *ngFor="let subItem of group" class="uk-margin-small-bottom">
<a [queryParams]="{f0:'resultsubject',fv0:createParams(subItem)}" class="uk-link-text"
routerLinkActive="router-link-active" [routerLink]="properties.searchLinkToAdvancedResults"
[attr.uk-tooltip]="subItem.length > maxCharacters ? subItem :''">
<span>{{subItem.length > maxCharacters ? subItem.substring(0,maxCharacters)+'...' : subItem}}</span>
</a>
</div>
</div>
</div>
</ng-template>
</div>
</div>
</div>
</ng-container>
</li>
<li *ngIf="displayedSdg?.length">
<ng-container *ngIf="groupedSdg?.length">
<div>
<ul class="uk-nav uk-nav-default uk-flex uk-flex-wrap">
<li *ngFor="let item of groupedSdg; let i = index;" class="uk-margin-right" [class.uk-margin-left]="i != 0"
[class]="indexSdg == i ? 'uk-active':''" (click)="changeDisplayedSubjects(i, item)">
<a class="uk-padding-remove">{{item.group}}</a>
</li>
</ul>
</div>
<!-- View for 'All' -->
<div *ngIf="indexSdg == 0 && groupedSdg.length > 1" class="uk-margin-large-top uk-grid uk-child-width-1-4@m" uk-grid>
<div *ngFor="let item of groupedSdg.slice(1); let i = index;">
<div>
<h6>{{item.group}}</h6>
<div *ngFor="let subItem of item.data.slice(0, subjectsLimit)" class="uk-margin-small-bottom">
<a [queryParams]="{f0:'sdg',fv0:createParams(subItem)}" class="uk-link-text"
routerLinkActive="router-link-active" [routerLink]="properties.searchLinkToAdvancedResults"
[attr.uk-tooltip]="subItem.length > maxCharacters ? subItem :''">
<span>{{subItem.length > maxCharacters ? subItem.substring(0,maxCharacters)+'...' : subItem}}</span>
</a>
</div>
<div *ngIf="item.data.length > subjectsLimit">
<a (click)="changeDisplayedSubjects(i+1, item)" class="view-more-less-link">
View all
</a>
</div>
</div>
</div>
</div>
<!-- View for a single group -->
<div *ngIf="indexSdg != 0 || groupedSdg.length == 1" class="uk-margin-large-top">
<div>
<div>
<h6>{{groupedSdg[indexSdg].group}}</h6>
<ng-container *ngIf="subjectsColumns?.length == 0; else elseBlock">
<div *ngFor="let subItem of groupedSdg[indexSdg].data" class="uk-margin-small-bottom">
<a [queryParams]="{f0:'sdg',fv0:createParams(subItem)}" class="uk-link-text"
routerLinkActive="router-link-active" [routerLink]="properties.searchLinkToAdvancedResults"
[attr.uk-tooltip]="subItem.length > maxCharacters ? subItem :''">
<span>{{subItem.length > maxCharacters ? subItem.substring(0,maxCharacters)+'...' : subItem}}</span>
</a>
</div>
</ng-container>
<ng-template #elseBlock>
<div class="uk-grid uk-child-width-1-4@m" uk-grid>
<div *ngFor="let group of subjectsColumns">
<div *ngFor="let subItem of group" class="uk-margin-small-bottom">
<a [queryParams]="{f0:'sdg',fv0:createParams(subItem)}" class="uk-link-text"
routerLinkActive="router-link-active" [routerLink]="properties.searchLinkToAdvancedResults"
[attr.uk-tooltip]="subItem.length > maxCharacters ? subItem :''">
<span>{{subItem.length > maxCharacters ? subItem.substring(0,maxCharacters)+'...' : subItem}}</span>
</a>
</div>
</div>
</div>
</ng-template>
</div>
</div>
</div>
</ng-container>
</li>
<li *ngIf="displayedFos?.length">
<ng-container *ngIf="groupedFos?.length">
<div>
<ul class="uk-nav uk-nav-default uk-flex uk-flex-wrap">
<li *ngFor="let item of groupedFos; let i = index;" class="uk-margin-right" [class.uk-margin-left]="i != 0"
[class]="indexFos == i ? 'uk-active':''" (click)="changeDisplayedSubjects(i, item)">
<a class="uk-padding-remove">{{item.group}}</a>
</li>
</ul>
</div>
<!-- View for 'All' -->
<div *ngIf="indexFos == 0 && groupedFos.length > 1" class="uk-margin-large-top uk-grid uk-child-width-1-4@m" uk-grid>
<div *ngFor="let item of groupedFos.slice(1); let i = index;">
<div>
<h6>{{item.group}}</h6>
<div *ngFor="let subItem of item.data.slice(0, subjectsLimit)" class="uk-margin-small-bottom">
<a [queryParams]="{f0:'fos',fv0:createParams(subItem)}" class="uk-link-text"
routerLinkActive="router-link-active" [routerLink]="properties.searchLinkToAdvancedResults"
[attr.uk-tooltip]="subItem.length > maxCharacters ? subItem :''">
<span>{{subItem.length > maxCharacters ? subItem.substring(0,maxCharacters)+'...' : subItem}}</span>
</a>
</div>
<div *ngIf="item.data.length > subjectsLimit">
<a (click)="changeDisplayedSubjects(i+1, item)" class="view-more-less-link">
View all
</a>
</div>
</div>
</div>
</div>
<!-- View for a single group -->
<div *ngIf="indexFos != 0 || groupedFos.length == 1" class="uk-margin-large-top">
<div>
<div>
<h6>{{groupedFos[indexFos].group}}</h6>
<ng-container *ngIf="subjectsColumns?.length == 0; else elseBlock">
<div *ngFor="let subItem of groupedFos[indexFos].data" class="uk-margin-small-bottom">
<a [queryParams]="{f0:'fos',fv0:createParams(subItem)}" class="uk-link-text"
routerLinkActive="router-link-active" [routerLink]="properties.searchLinkToAdvancedResults"
[attr.uk-tooltip]="subItem.length > maxCharacters ? subItem :''">
<span>{{subItem.length > maxCharacters ? subItem.substring(0,maxCharacters)+'...' : subItem}}</span>
</a>
</div>
</ng-container>
<ng-template #elseBlock>
<div class="uk-grid uk-child-width-1-4@m" uk-grid>
<div *ngFor="let group of subjectsColumns">
<div *ngFor="let subItem of group" class="uk-margin-small-bottom">
<a [queryParams]="{f0:'fos',fv0:createParams(subItem)}" class="uk-link-text"
routerLinkActive="router-link-active" [routerLink]="properties.searchLinkToAdvancedResults"
[attr.uk-tooltip]="subItem.length > maxCharacters ? subItem :''">
<span>{{subItem.length > maxCharacters ? subItem.substring(0,maxCharacters)+'...' : subItem}}</span>
</a>
</div>
</div>
</div>
</ng-template>
</div>
</div>
</div>
</ng-container>
</li>
</ul>
</div>
</div>
</div>
</div>
`
})
export class SubjectsComponent {
public subjects: string[];
public communityId = null;
public showLoading = true;
public properties: EnvProperties = properties;
public pageContents = null;
public divContents = null;
public groupedSubjects = [];
public index: number = 0;
public subjectsLimit: number = 6;
public viewAll: boolean = false;
public maxCharacters: number = 25;
public subjectsColumns = [];
public url: string = null;
public pageTitle: string = "Subjects";
public breadcrumbs: Breadcrumb[] = [{name: 'Home', route: '/'}, {name: 'About - Subjects'}];
properties: EnvProperties = properties;
breadcrumbs: Breadcrumb[] = [{name: 'Home', route: '/'}, {name: 'About - Subjects'}];
pageContents = null;
divContents = null;
url: string = null;
pageTitle: string = "Subjects";
communityId = null;
showLoading = true;
subs: Subscription[] = [];
displayedAllSubjects = [];
displayedSubjects = [];
displayedSdg = [];
displayedFos = [];
groupedAllSubjects = [];
groupedSubjects = [];
groupedSdg = [];
groupedFos = [];
subjectsColumns = [];
subjectsLimit: number = 6;
maxCharacters: number = 25;
activeTab: 'all' | 'freeText' | 'sdg' | 'fos' = 'all';
indexAll: number = 0;
indexSubjects: number = 0;
indexSdg: number = 0;
indexFos: number = 0;
viewAll: boolean = false;
constructor(private route: ActivatedRoute,
private communityService: CommunityService,
private _router: Router,
@ -147,18 +365,20 @@ export class SubjectsComponent {
if (this.properties.enablePiwikTrack && (typeof document !== 'undefined')) {
this.subs.push(this._piwikService.trackView(this.properties, this.pageTitle, PiwikHelper.getSiteId(this.communityId)).subscribe());
}
//this.getDivContents();
this.getPageContents();
this.subjects = community.subjects;
this.subjects.sort((a,b) => {
if(!a || a.toLocaleUpperCase() < b.toLocaleUpperCase()) {
return -1;
} else if (!b || a.toLocaleUpperCase() > b.toLocaleUpperCase()) {
return 1;
}
return 0;
});
this.groupSubjects();
this.displayedSubjects = community.subjects;
this.displayedSdg = community.sdg;
this.displayedFos = community.fos;
this.displayedSubjects.forEach(element => {
this.displayedAllSubjects.push({value: element, type: 'resultsubject'});
});
this.displayedSdg.forEach(element => {
this.displayedAllSubjects.push({value: element, type: 'sdg'});
});
this.displayedFos.forEach(element => {
this.displayedAllSubjects.push({value: element, type: 'fos'});
});
this.groupSubjects(this.displayedAllSubjects, 'all');
this.showLoading = false;
}
}));
@ -182,51 +402,111 @@ export class SubjectsComponent {
}));
}
private getDivContents() {
this.subs.push(this.helper.getDivHelpContents(this.properties, this.communityId, this._router.url).subscribe(contents => {
this.divContents = contents;
}));
public groupSubjects(subjects: string[], type: string) {
if(subjects.length === 0) {
return [];
}
if(type === 'all') {
subjects.sort((a, b) => a['value'].localeCompare(b['value']));
this.indexAll = 0;
this.activeTab = 'all';
this.groupedAllSubjects = Object.values(
subjects.reduce((acc, subject) => {
let firstLetter = subject['value'][0].toLocaleUpperCase();
if(!acc[firstLetter]) {
acc[firstLetter] = {group: firstLetter, data: [subject]};
} else {
acc[firstLetter].data.push(subject);
}
return acc;
},{})
)
if(subjects.length > 1) {
this.groupedAllSubjects.unshift({group: 'All', data: subjects});
}
}
if(type === 'freeText') {
subjects.sort((a, b) => a.localeCompare(b));
this.indexSubjects = 0;
this.activeTab = 'freeText';
this.groupedSubjects = Object.values(
subjects.reduce((acc, subject) => {
let firstLetter = subject[0].toLocaleUpperCase();
if(!acc[firstLetter]) {
acc[firstLetter] = {group: firstLetter, data: [subject]};
} else {
acc[firstLetter].data.push(subject);
}
return acc;
},{})
)
if(subjects.length > 1) {
this.groupedSubjects.unshift({group: 'All', data: subjects});
}
}
if(type === 'sdg') {
subjects.sort((a, b) => a.localeCompare(b));
this.indexSdg = 0;
this.activeTab = 'sdg';
this.groupedSdg = Object.values(
subjects.reduce((acc, subject) => {
let firstLetter = subject[0].toLocaleUpperCase();
if(!acc[firstLetter]) {
acc[firstLetter] = {group: firstLetter, data: [subject]};
} else {
acc[firstLetter].data.push(subject);
}
return acc;
},{})
)
if(subjects.length > 1) {
this.groupedSdg.unshift({group: 'All', data: subjects});
}
}
if(type === 'fos') {
subjects.sort((a, b) => a.localeCompare(b));
this.indexFos = 0;
this.activeTab = 'fos';
this.groupedFos = Object.values(
subjects.reduce((acc, subject) => {
let key = subject.substring(0,2).toLocaleUpperCase();
if(!acc[key]) {
acc[key] = {group: key, data: [subject]};
} else {
acc[key].data.push(subject);
}
return acc;
},{})
)
if(subjects.length > 1) {
this.groupedFos.unshift({group: 'All', data: subjects});
}
}
}
// private sortSubjects(a, b) {
public changeDisplayedSubjects(i, group) {
this.subjectsColumns = [];
if(this.activeTab === 'all') {
this.indexAll = i;
} else if(this.activeTab === 'freeText') {
this.indexSubjects = i;
} else if(this.activeTab === 'sdg') {
this.indexSdg = i;
} else if(this.activeTab === 'fos') {
this.indexFos = i;
}
if(group.data.length > this.subjectsLimit && group.group != 'All') {
this.divideSubjects(group);
}
}
// }
private groupSubjects() {
if(this.subjects.length === 0) {
return [];
}
this.groupedSubjects = Object.values(
this.subjects.reduce((acc, subject) => {
let firstLetter = subject[0].toLocaleUpperCase();
if(!acc[firstLetter]) {
acc[firstLetter] = {group: firstLetter, data: [subject]};
} else {
acc[firstLetter].data.push(subject);
}
return acc;
},{})
)
if(this.subjects.length > 1) {
this.groupedSubjects.unshift({group: 'All', data: this.subjects});
}
}
public changeDisplayedSubjects(i, group) {
this.subjectsColumns = [];
this.index = i;
if(group.data.length > this.subjectsLimit && group.group != 'All') {
this.divideSubjects(group);
}
}
public divideSubjects(group) {
let columns = [];
for(let i = 0; i < (group.data.length / this.subjectsLimit); i++) {
columns.push(group.data.slice(i * this.subjectsLimit, ((i + 1) * this.subjectsLimit)));
}
this.subjectsColumns = columns;
}
public divideSubjects(group) {
let columns = [];
for(let i = 0; i < (group.data.length / this.subjectsLimit); i++) {
columns.push(group.data.slice(i * this.subjectsLimit, ((i + 1) * this.subjectsLimit)));
}
this.subjectsColumns = columns;
}
private updateDescription(description: string) {
this._meta.updateTag({content: description}, "name='description'");