display new subjects (sdg/fos) in home and subjects pages of the community gateways
This commit is contained in:
parent
8c7933a1ea
commit
6e6676003d
|
@ -635,17 +635,17 @@
|
|||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div *ngIf="isRouteEnabled('/subjects') && community.subjects && community.subjects.length > 0" class="uk-width-1-3@m">
|
||||
<div *ngIf="isRouteEnabled('/subjects') && displayedAllSubjects && displayedAllSubjects.length > 0" class="uk-width-1-3@m">
|
||||
<div>
|
||||
<div class="uk-text-meta uk-margin-small-bottom">Subjects</div>
|
||||
<span *ngFor="let subject of community.subjects.slice(0,20) let i=index">
|
||||
<span *ngIf="subject != ''">
|
||||
<span *ngFor="let item of displayedAllSubjects.slice(0,20) let i=index">
|
||||
<span *ngIf="item.value != ''">
|
||||
<a class="portal-link"
|
||||
[queryParams]="{f0:'resultsubject',fv0:createParams(subject)}"
|
||||
[queryParams]="{f0:item.type,fv0:createParams(item.value)}"
|
||||
routerLinkActive="router-link-active" [routerLink]="searchLinkToAdvancedResults">
|
||||
<span>{{subject}}</span>
|
||||
<span>{{item.value}}</span>
|
||||
</a>
|
||||
<span *ngIf="i < community.subjects.length-1 && i != 19">, </span>
|
||||
<span *ngIf="i < displayedAllSubjects.length-1 && i != 19">, </span>
|
||||
</span>
|
||||
</span>
|
||||
<div class="uk-animation-fade uk-margin-top">
|
||||
|
|
|
@ -93,6 +93,11 @@ export class CommunityComponent {
|
|||
|
||||
subs: Subscription[] = [];
|
||||
|
||||
displayedAllSubjects = [];
|
||||
displayedSubjects = [];
|
||||
displayedSdg = [];
|
||||
displayedFos = [];
|
||||
|
||||
@ViewChild(StatisticsForDashboardComponent) statistics: StatisticsForDashboardComponent = null;
|
||||
public activeTab = "summary";
|
||||
public show: string = 'overview';
|
||||
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -37,18 +37,100 @@ import {Subscriber, Subscription} from "rxjs";
|
|||
[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)">
|
||||
<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="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 *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>
|
||||
|
@ -68,15 +150,15 @@ import {Subscriber, Subscription} from "rxjs";
|
|||
</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 *ngIf="indexSubjects != 0 || groupedSubjects.length == 1" class="uk-margin-large-top">
|
||||
<div>
|
||||
<div>
|
||||
<h6>{{groupedSubjects[index].group}}</h6>
|
||||
<h6>{{groupedSubjects[indexSubjects]?.group}}</h6>
|
||||
<ng-container *ngIf="subjectsColumns?.length == 0; else elseBlock">
|
||||
<div *ngFor="let subItem of groupedSubjects[index].data" class="uk-margin-small-bottom">
|
||||
<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">
|
||||
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>
|
||||
|
@ -86,7 +168,8 @@ import {Subscriber, Subscription} from "rxjs";
|
|||
<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">
|
||||
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>
|
||||
|
@ -97,33 +180,168 @@ import {Subscriber, Subscription} from "rxjs";
|
|||
</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.displayedSubjects = community.subjects;
|
||||
this.displayedSdg = community.sdg;
|
||||
this.displayedFos = community.fos;
|
||||
this.displayedSubjects.forEach(element => {
|
||||
this.displayedAllSubjects.push({value: element, type: 'resultsubject'});
|
||||
});
|
||||
this.groupSubjects();
|
||||
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,22 +402,35 @@ export class SubjectsComponent {
|
|||
}));
|
||||
}
|
||||
|
||||
private getDivContents() {
|
||||
this.subs.push(this.helper.getDivHelpContents(this.properties, this.communityId, this._router.url).subscribe(contents => {
|
||||
this.divContents = contents;
|
||||
}));
|
||||
}
|
||||
|
||||
// private sortSubjects(a, b) {
|
||||
|
||||
// }
|
||||
|
||||
private groupSubjects() {
|
||||
if(this.subjects.length === 0) {
|
||||
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(
|
||||
this.subjects.reduce((acc, subject) => {
|
||||
subjects.reduce((acc, subject) => {
|
||||
let firstLetter = subject[0].toLocaleUpperCase();
|
||||
if(!acc[firstLetter]) {
|
||||
acc[firstLetter] = {group: firstLetter, data: [subject]};
|
||||
|
@ -207,14 +440,61 @@ export class SubjectsComponent {
|
|||
return acc;
|
||||
},{})
|
||||
)
|
||||
if(this.subjects.length > 1) {
|
||||
this.groupedSubjects.unshift({group: 'All', data: this.subjects});
|
||||
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});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public changeDisplayedSubjects(i, group) {
|
||||
this.subjectsColumns = [];
|
||||
this.index = i;
|
||||
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);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue