add new feature: selection criteria by FoS and SDGs

This commit is contained in:
Alex Martzios 2023-03-15 11:56:28 +02:00
parent 88be699fd2
commit 070f9d369d
2 changed files with 369 additions and 567 deletions

View File

@ -22,17 +22,13 @@
<loading></loading> <loading></loading>
</div> </div>
<div *ngIf="!showLoading"> <div *ngIf="!showLoading">
<!-- TODO: Alter following if statement to match new functionality --> <div *ngIf="displayedSubjects?.length == 0 && displayedSdg?.length == 0 && displayedFos?.length == 0"
<div *ngIf="community.subjects.length == 0"
class="uk-card uk-card-default uk-padding-large uk-text-center uk-margin-bottom uk-text-bold"> class="uk-card uk-card-default uk-padding-large uk-text-center uk-margin-bottom uk-text-bold">
<div>No subjects <div>No subjects</div>
<span *ngIf="originalSubjects.length == 0; else: notFound">for {{community.shortTitle}}</span>
<ng-template #notFound>found</ng-template>
</div> </div>
</div> <div *ngIf="displayedSubjects?.length > 0 || displayedSdg?.length > 0 || displayedFos?.length > 0">
<div *ngIf="community.subjects.length > 0">
<ul uk-tab class="uk-tab uk-margin-bottom uk-flex uk-flex-center uk-flex-left@m"> <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"> <li class="uk-active" *ngIf="displayedAllSubjects?.length" (click)="groupSubjects(displayedAllSubjects, 'all')">
<a>All ({{displayedAllSubjects.length}})</a> <a>All ({{displayedAllSubjects.length}})</a>
</li> </li>
<li *ngIf="displayedSubjects?.length" (click)="groupSubjects(displayedSubjects, 'freeText')"> <li *ngIf="displayedSubjects?.length" (click)="groupSubjects(displayedSubjects, 'freeText')">
@ -46,18 +42,18 @@
</li> </li>
</ul> </ul>
<ul class="uk-switcher"> <ul class="uk-switcher">
<li> <li *ngIf="displayedAllSubjects?.length">
<ng-container *ngIf="groupedAllSubjects?.length"> <ng-container *ngIf="groupedAllSubjects?.length">
<div> <div>
<ul class="uk-nav uk-nav-default uk-flex uk-flex-wrap"> <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" <li *ngFor="let item of groupedAllSubjects; let i = index;" class="uk-margin-right" [class.uk-margin-left]="i != 0"
[class]="index == i ? 'uk-active':''" (click)="changeDisplayedSubjects(i, item)"> [class]="indexAll == i ? 'uk-active':''" (click)="changeDisplayedSubjects(i, item)">
<a class="uk-padding-remove">{{item.group}}</a> <a class="uk-padding-remove">{{item.group}}</a>
</li> </li>
</ul> </ul>
</div> </div>
<!-- View for 'All' --> <!-- View for 'All' -->
<div *ngIf="index == 0 && groupedAllSubjects.length > 1" 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 *ngFor="let item of groupedAllSubjects.slice(1); let i = index;">
<div> <div>
<h6>{{item.group}}</h6> <h6>{{item.group}}</h6>
@ -75,12 +71,12 @@
</div> </div>
</div> </div>
<!-- View for a single group --> <!-- View for a single group -->
<div *ngIf="index != 0 || groupedAllSubjects.length == 1" class="uk-margin-large-top"> <div *ngIf="indexAll != 0 || groupedAllSubjects.length == 1" class="uk-margin-large-top">
<div> <div>
<div> <div>
<h6>{{groupedAllSubjects[index].group}}</h6> <h6>{{groupedAllSubjects[indexAll].group}}</h6>
<ng-container *ngIf="subjectsColumns?.length == 0; else elseBlock"> <ng-container *ngIf="subjectsColumns?.length == 0; else elseBlock">
<div *ngFor="let subItem of groupedAllSubjects[index].data" class="uk-margin-small-bottom"> <div *ngFor="let subItem of groupedAllSubjects[indexAll].data" class="uk-margin-small-bottom">
<span [attr.uk-tooltip]="subItem.length > maxCharacters ? 'cls: uk-active' : 'cls: uk-invisible'" [title]="subItem"> <span [attr.uk-tooltip]="subItem.length > maxCharacters ? 'cls: uk-active' : 'cls: uk-invisible'" [title]="subItem">
{{subItem.length > maxCharacters ? subItem.substring(0,maxCharacters)+'...' : subItem}} {{subItem.length > maxCharacters ? subItem.substring(0,maxCharacters)+'...' : subItem}}
</span> </span>
@ -102,18 +98,18 @@
</div> </div>
</ng-container> </ng-container>
</li> </li>
<li> <li *ngIf="displayedSubjects?.length">
<ng-container *ngIf="groupedSubjects?.length"> <ng-container *ngIf="groupedSubjects?.length">
<div> <div>
<ul class="uk-nav uk-nav-default uk-flex uk-flex-wrap"> <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" <li *ngFor="let item of groupedSubjects; let i = index;" class="uk-margin-right" [class.uk-margin-left]="i != 0"
[class]="index == i ? 'uk-active':''" (click)="changeDisplayedSubjects(i, item)"> [class]="indexSubjects == i ? 'uk-active':''" (click)="changeDisplayedSubjects(i, item)">
<a class="uk-padding-remove">{{item.group}}</a> <a class="uk-padding-remove">{{item.group}}</a>
</li> </li>
</ul> </ul>
</div> </div>
<!-- View for 'All' --> <!-- 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="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 *ngFor="let item of groupedSubjects.slice(1); let i = index;">
<div> <div>
<h6>{{item.group}}</h6> <h6>{{item.group}}</h6>
@ -131,12 +127,12 @@
</div> </div>
</div> </div>
<!-- View for a single group --> <!-- View for a single group -->
<div *ngIf="index != 0 || groupedSubjects.length == 1" class="uk-margin-large-top"> <div *ngIf="indexSubjects != 0 || groupedSubjects.length == 1" class="uk-margin-large-top">
<div> <div>
<div> <div>
<h6>{{groupedSubjects[index].group}}</h6> <h6>{{groupedSubjects[indexSubjects]?.group}}</h6>
<ng-container *ngIf="subjectsColumns?.length == 0; else elseBlock"> <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">
<span [attr.uk-tooltip]="subItem.length > maxCharacters ? 'cls: uk-active' : 'cls: uk-invisible'" [title]="subItem"> <span [attr.uk-tooltip]="subItem.length > maxCharacters ? 'cls: uk-active' : 'cls: uk-invisible'" [title]="subItem">
{{subItem.length > maxCharacters ? subItem.substring(0,maxCharacters)+'...' : subItem}} {{subItem.length > maxCharacters ? subItem.substring(0,maxCharacters)+'...' : subItem}}
</span> </span>
@ -158,18 +154,18 @@
</div> </div>
</ng-container> </ng-container>
</li> </li>
<li> <li *ngIf="displayedSdg?.length">
<ng-container *ngIf="groupedSdg?.length"> <ng-container *ngIf="groupedSdg?.length">
<div> <div>
<ul class="uk-nav uk-nav-default uk-flex uk-flex-wrap"> <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" <li *ngFor="let item of groupedSdg; let i = index;" class="uk-margin-right" [class.uk-margin-left]="i != 0"
[class]="index == i ? 'uk-active':''" (click)="changeDisplayedSubjects(i, item)"> [class]="indexSdg == i ? 'uk-active':''" (click)="changeDisplayedSubjects(i, item)">
<a class="uk-padding-remove">{{item.group}}</a> <a class="uk-padding-remove">{{item.group}}</a>
</li> </li>
</ul> </ul>
</div> </div>
<!-- View for 'All' --> <!-- View for 'All' -->
<div *ngIf="index == 0 && groupedSdg.length > 1" class="uk-margin-large-top uk-grid uk-child-width-1-4@m" uk-grid> <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 *ngFor="let item of groupedSdg.slice(1); let i = index;">
<div> <div>
<h6>{{item.group}}</h6> <h6>{{item.group}}</h6>
@ -187,12 +183,12 @@
</div> </div>
</div> </div>
<!-- View for a single group --> <!-- View for a single group -->
<div *ngIf="index != 0 || groupedSdg.length == 1" class="uk-margin-large-top"> <div *ngIf="indexSdg != 0 || groupedSdg.length == 1" class="uk-margin-large-top">
<div> <div>
<div> <div>
<h6>{{groupedSdg[index].group}}</h6> <h6>{{groupedSdg[indexSdg].group}}</h6>
<ng-container *ngIf="subjectsColumns?.length == 0; else elseBlock"> <ng-container *ngIf="subjectsColumns?.length == 0; else elseBlock">
<div *ngFor="let subItem of groupedSdg[index].data" class="uk-margin-small-bottom"> <div *ngFor="let subItem of groupedSdg[indexSdg].data" class="uk-margin-small-bottom">
<span [attr.uk-tooltip]="subItem.length > maxCharacters ? 'cls: uk-active' : 'cls: uk-invisible'" [title]="subItem"> <span [attr.uk-tooltip]="subItem.length > maxCharacters ? 'cls: uk-active' : 'cls: uk-invisible'" [title]="subItem">
{{subItem.length > maxCharacters ? subItem.substring(0,maxCharacters)+'...' : subItem}} {{subItem.length > maxCharacters ? subItem.substring(0,maxCharacters)+'...' : subItem}}
</span> </span>
@ -214,18 +210,18 @@
</div> </div>
</ng-container> </ng-container>
</li> </li>
<li> <li *ngIf="displayedFos?.length">
<ng-container *ngIf="groupedFos?.length"> <ng-container *ngIf="groupedFos?.length">
<div> <div>
<ul class="uk-nav uk-nav-default uk-flex uk-flex-wrap"> <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" <li *ngFor="let item of groupedFos; let i = index;" class="uk-margin-right" [class.uk-margin-left]="i != 0"
[class]="index == i ? 'uk-active':''" (click)="changeDisplayedSubjects(i, item)"> [class]="indexFos == i ? 'uk-active':''" (click)="changeDisplayedSubjects(i, item)">
<a class="uk-padding-remove">{{item.group}}</a> <a class="uk-padding-remove">{{item.group}}</a>
</li> </li>
</ul> </ul>
</div> </div>
<!-- View for 'All' --> <!-- View for 'All' -->
<div *ngIf="index == 0 && groupedFos.length > 1" class="uk-margin-large-top uk-grid uk-child-width-1-4@m" uk-grid> <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 *ngFor="let item of groupedFos.slice(1); let i = index;">
<div> <div>
<h6>{{item.group}}</h6> <h6>{{item.group}}</h6>
@ -243,12 +239,12 @@
</div> </div>
</div> </div>
<!-- View for a single group --> <!-- View for a single group -->
<div *ngIf="index != 0 || groupedFos.length == 1" class="uk-margin-large-top"> <div *ngIf="indexFos != 0 || groupedFos.length == 1" class="uk-margin-large-top">
<div> <div>
<div> <div>
<h6>{{groupedFos[index].group}}</h6> <h6>{{groupedFos[indexFos].group}}</h6>
<ng-container *ngIf="subjectsColumns?.length == 0; else elseBlock"> <ng-container *ngIf="subjectsColumns?.length == 0; else elseBlock">
<div *ngFor="let subItem of groupedFos[index].data" class="uk-margin-small-bottom"> <div *ngFor="let subItem of groupedFos[indexFos].data" class="uk-margin-small-bottom">
<span [attr.uk-tooltip]="subItem.length > maxCharacters ? 'cls: uk-active' : 'cls: uk-invisible'" [title]="subItem"> <span [attr.uk-tooltip]="subItem.length > maxCharacters ? 'cls: uk-active' : 'cls: uk-invisible'" [title]="subItem">
{{subItem.length > maxCharacters ? subItem.substring(0,maxCharacters)+'...' : subItem}} {{subItem.length > maxCharacters ? subItem.substring(0,maxCharacters)+'...' : subItem}}
</span> </span>
@ -272,67 +268,21 @@
</li> </li>
</ul> </ul>
</div> </div>
<!-- <div *ngIf="community.subjects.length > 0">
<no-load-paging *ngIf="community.subjects.length > 0" [type]="'Subjects'"
[page]="page" [pageSize]="size" (pageChange)="updatePage($event)"
[totalResults]="community.subjects.length">
</no-load-paging>
<div class="uk-grid uk-grid-large uk-grid-match uk-child-width-1-1 uk-child-width-1-2@m uk-margin-top uk-margin-bottom" uk-grid>
<div *ngFor='let subject of currentPage; let i = index;'>
<div class="uk-card uk-card-default">
<div class="uk-card-body">
<h6 uk-tooltip="title:All the research results associated to this subjects will be automatically linked to the community dashboard."
class="uk-display-inline-block">
{{subject}}
</h6>
</div>
<div class="uk-card-footer uk-padding-remove-vertical">
<div class="uk-grid uk-grid-small uk-flex-nowrap uk-grid-divider uk-flex-right" uk-grid>
<div>
<div class="uk-padding-small uk-padding-remove-horizontal">
<a (click)="editSubject(subject)"
class="uk-button uk-button-link uk-flex uk-flex-middle">
<icon name="edit" [flex]="true"></icon>
<span class="uk-margin-xsmall-left">Edit</span>
</a>
</div>
</div>
<div>
<div class="uk-padding-small uk-padding-remove-horizontal">
<button class="uk-button uk-button-link uk-flex uk-flex-middle"
(click)="removeModalOpen(subject, i)">
<icon name="delete" [flex]="true"></icon>
<span class="uk-margin-xsmall-left">Delete</span>
</button>
</div> </div>
</div> </div>
</div> </div>
</div> </div>
</div>
</div>
</div>
<div class="uk-margin-small-top">
<paging-no-load [currentPage]="page" [totalResults]="community.subjects.length" [size]="size"
(pageChange)="updatePage($event)" customClasses="uk-flex-right@m uk-flex-center">
</paging-no-load>
</div>
</div> -->
</div>
</div>
</div>
</div>
<!-- <modal-alert #deleteModal (alertOutput)="saveSubjects()" [overflowBody]="false" classTitle="uk-background-primary uk-light"></modal-alert> -->
<fs-modal #fsModal classBody="uk-container-large" (okEmitter)="saveAllSubjects()" [okButtonDisabled]="!hasChanges && !sdgSelection.hasChanges && !fosSelection.hasChanges"> <fs-modal #fsModal classBody="uk-container-large" (okEmitter)="saveAllSubjects()" [okButtonDisabled]="!hasChanges && !sdgSelection.hasChanges && !fosSelection.hasChanges">
<div> <div>
<ul uk-tab #modalTabs class="uk-tab uk-margin-top uk-margin-large-bottom uk-flex uk-flex-center uk-flex-left@m"> <ul uk-tab #modalTabs class="uk-tab uk-margin-top uk-margin-large-bottom uk-flex uk-flex-center uk-flex-left@m">
<li class="uk-active"> <li class="uk-active" *ngIf="displayedSubjects?.length">
<a>Free Text ({{displayedSubjects.length}})</a> <a>Free Text ({{displayedSubjects.length}})<span *ngIf="hasChanges">*</span></a>
</li> </li>
<li> <li *ngIf="displayedSdg?.length">
<a>SDGs ({{sdgSelection.getSelectedSubjects().length}})</a> <a>SDGs ({{sdgSelection.getSelectedSubjects().length}})<span *ngIf="sdgSelection.hasChanges">*</span></a>
</li> </li>
<li> <li *ngIf="displayedFos?.length">
<a>Fields of Science ({{fosSelection.getSelectedSubjects().length}})</a> <a>Fields of Science ({{fosSelection.getSelectedSubjects().length}})<span *ngIf="fosSelection.hasChanges">*</span></a>
</li> </li>
</ul> </ul>
<ul class="uk-switcher"> <ul class="uk-switcher">
@ -345,28 +295,6 @@
</div> </div>
<div note class="uk-text-xsmall">Separate subjects with commas</div> <div note class="uk-text-xsmall">Separate subjects with commas</div>
</div> </div>
<!-- <form *ngIf="myForm">
<div class="uk-margin-top uk-flex-center uk-flex uk-margin-medium-bottom">
<a *ngIf="!isEditModal" (click)="addSubjectInForm()">
<button class="uk-button uk-button-primary uk-flex uk-flex-middle">
<icon name="add" [flex]="true"></icon>
<span class="uk-margin-xsmall-left">Add Subject</span>
</button>
</a>
</div>
<div class="uk-grid uk-child-width-1-1" uk-grid>
<div *ngFor=" let control of myForm.controls; index as i" class="uk-flex uk-flex-middle">
<div input [formInput]="myForm.controls[i]" type="text"
placeholder="Type subjects as free text keywords" class="uk-width-expand"></div>
<div *ngIf="!isEditModal" class="uk-width-auto uk-flex uk-flex-center uk-margin-left">
<button class="uk-close uk-icon" [class.uk-invisible]="myForm.length === 1"
(click)="removeSubjectInForm(i)">
<icon name="close" [flex]="true" [ratio]="1.5"></icon>
</button>
</div>
</div>
</div>
</form> -->
<div class="uk-margin-large-top"> <div class="uk-margin-large-top">
<span *ngFor="let subject of displayedSubjects; let i = index;" <span *ngFor="let subject of displayedSubjects; let i = index;"
class="uk-label uk-label-primary uk-flex-inline uk-flex-middle uk-margin-right uk-margin-bottom"> class="uk-label uk-label-primary uk-flex-inline uk-flex-middle uk-margin-right uk-margin-bottom">
@ -386,10 +314,3 @@
</ul> </ul>
</div> </div>
</fs-modal> </fs-modal>
<!--<modal-alert #enablePageModal (alertOutput)="enablePage()">
<div class="uk-padding uk-padding-remove-horizontal">
This information will be visible in <span class="uk-text-bold">Subjects page</span> of Research Community
Dashboard, which is <span class="uk-text-bold">disabled</span>.
Do you want to <span class="uk-text-bold">enable</span> it now?
</div>
</modal-alert>-->

View File

@ -1,6 +1,6 @@
import {Component, ElementRef, OnInit, ViewChild} from '@angular/core'; import {Component, ElementRef, OnInit, ViewChild} from '@angular/core';
import {UntypedFormArray, UntypedFormBuilder, UntypedFormControl} from '@angular/forms'; import {UntypedFormArray, UntypedFormBuilder, UntypedFormControl} from '@angular/forms';
import {ActivatedRoute, Router} from '@angular/router'; import {ActivatedRoute} from '@angular/router';
import {CommunityService} from '../../../openaireLibrary/connect/community/community.service'; import {CommunityService} from '../../../openaireLibrary/connect/community/community.service';
import {SubjectsService} from '../subjects.service'; import {SubjectsService} from '../subjects.service';
import {EnvProperties} from '../../../openaireLibrary/utils/properties/env-properties'; import {EnvProperties} from '../../../openaireLibrary/utils/properties/env-properties';
@ -24,72 +24,81 @@ declare var UIkit: any;
templateUrl: './subjects-edit-form.component.html', templateUrl: './subjects-edit-form.component.html',
}) })
export class SubjectsEditFormComponent implements OnInit { export class SubjectsEditFormComponent implements OnInit {
properties: EnvProperties = properties;
communityId: string = null;
community: CommunityInfo = null;
showLoading = true;
params: any;
private subscriptions: any[] = [];
filterForm: UntypedFormControl;
subjectsForm = new UntypedFormArray([]); subjectsForm = new UntypedFormArray([]);
hasChanges: boolean = false;
originalAllSubjects = [];
originalSubjects = [];
originalSdg = [];
originalFos = [];
displayedAllSubjects = [];
displayedSubjects = [];
displayedSdg = [];
displayedFos = [];
groupedAllSubjects = []; groupedAllSubjects = [];
groupedSubjects = []; groupedSubjects = [];
groupedSdg = []; groupedSdg = [];
groupedFos = []; groupedFos = [];
subjectsColumns = []; subjectsColumns = [];
index: number = 0;
subjectsLimit: number = 6; subjectsLimit: number = 6;
public maxCharacters: number = 25; maxCharacters: number = 25;
displayedAllSubjects = []; activeTab: 'all' | 'freeText' | 'sdg' | 'fos' = 'all';
displayedSubjects = []; indexAll: number = 0;
displayedSdg = []; indexSubjects: number = 0;
displayedFos = []; indexSdg: number = 0;
hasChanges: boolean = false; indexFos: number = 0;
myForm = new UntypedFormArray([]); @ViewChild('searchInputComponent') searchInputComponent: SearchInputComponent;
public showLoading = true;
public res = [];
params: any;
public communityId: string = null;
public community: CommunityInfo = null;
public properties: EnvProperties = properties;
public edit = null;
public originalSubjects = [];
@ViewChild('editModal') editModal: AlertModal; @ViewChild('editModal') editModal: AlertModal;
@ViewChild('deleteModal') deleteModal: AlertModal; @ViewChild('deleteModal') deleteModal: AlertModal;
@ViewChild('fsModal', {static: true}) fullscreen: FullScreenModalComponent; @ViewChild('fsModal', {static: true}) fullscreen: FullScreenModalComponent;
@ViewChild('modalTabs') modalTabs: ElementRef; @ViewChild('modalTabs') modalTabs: ElementRef;
page = 1;
size = 10;
selectedSubjects = [];
isEditModal: boolean = false;
public selectedKeyword: string;
@ViewChild('searchInputComponent') searchInputComponent: SearchInputComponent;
public filterForm: UntypedFormControl;
private subscriptions: any[] = [];
@ViewChild('sdgSelection') sdgSelection: SdgSelectionComponent; @ViewChild('sdgSelection') sdgSelection: SdgSelectionComponent;
@ViewChild('fosSelection') fosSelection: FosSelectionComponent; @ViewChild('fosSelection') fosSelection: FosSelectionComponent;
/*//Check again functionality to enable page
subjectsPage;
@ViewChild('enablePageModal') enablePageModal: AlertModal;*/
onEnter: () => void = () => { onEnter: () => void = () => {
this.addSubjectsIntoList(); this.addSubjectsIntoList();
} }
constructor(private element: ElementRef, constructor(private route: ActivatedRoute,
private route: ActivatedRoute,
private _router: Router,
public _fb: UntypedFormBuilder, public _fb: UntypedFormBuilder,
private title: Title, private title: Title,
// private _helpContentService: HelpContentService,
private _communityService: CommunityService, private _communityService: CommunityService,
private _subjectsService: SubjectsService, private _subjectsService: SubjectsService,
private _clearCacheService: ClearCacheService private _clearCacheService: ClearCacheService) {
) {
} }
ngOnInit() { ngOnInit() {
this.filterForm = this._fb.control(''); this.filterForm = this._fb.control('');
this.subscriptions.push(this.filterForm.valueChanges.subscribe(value => { this.subscriptions.push(this.filterForm.valueChanges.subscribe(value => {
this.community.subjects = this.originalSubjects.filter(subject => { this.displayedAllSubjects = this.originalAllSubjects.filter(subject => {
return !value || subject.toLowerCase().indexOf(value.toLowerCase()) != -1 return !value || subject.toLowerCase().indexOf(value.toLowerCase()) != -1
}); });
this.displayedSubjects = this.originalSubjects.filter(subject => {
return !value || subject.toLowerCase().indexOf(value.toLowerCase()) != -1
});
this.displayedSdg = this.originalSdg.filter(subject => {
return !value || subject.toLowerCase().indexOf(value.toLowerCase()) != -1
});
this.displayedFos = this.originalFos.filter(subject => {
return !value || subject.toLowerCase().indexOf(value.toLowerCase()) != -1
});
if(this.activeTab === 'all') {
this.groupSubjects(this.displayedAllSubjects, 'all');
} else if(this.activeTab === 'freeText') {
this.groupSubjects(this.displayedSubjects, 'freeText');
} else if(this.activeTab === 'sdg') {
this.groupSubjects(this.displayedSdg, 'sdg');
} else if(this.activeTab === 'fos') {
this.groupSubjects(this.displayedFos, 'fos');
}
})); }));
this.subscriptions.push(this.route.params.subscribe( this.subscriptions.push(this.route.params.subscribe(
params => { params => {
@ -112,21 +121,15 @@ export class SubjectsEditFormComponent implements OnInit {
} }
return 0; return 0;
}); });
// assigning values
this.displayedSubjects = HelperFunctions.copy(this.community.subjects); this.displayedSubjects = HelperFunctions.copy(this.community.subjects);
this.displayedSdg = this.community.sdg; this.displayedSdg = this.community.sdg;
this.displayedFos = this.community.fos; this.displayedFos = this.community.fos;
this.displayedAllSubjects = [...this.displayedSubjects, ...this.displayedSdg, ...this.displayedFos]; this.displayedAllSubjects = [...this.displayedSubjects, ...this.displayedSdg, ...this.displayedFos];
// grouping eveything for 'All' view
this.groupSubjects(this.displayedAllSubjects, 'all'); this.groupSubjects(this.displayedAllSubjects, 'all');
this.originalAllSubjects = HelperFunctions.copy(this.displayedAllSubjects);
this.originalSubjects = []; this.originalSubjects = HelperFunctions.copy(this.displayedSubjects);
for (let i = 0; i < this.community.subjects.length; i++) { this.originalSdg = HelperFunctions.copy(this.displayedSdg);
this.originalSubjects.push(this.community.subjects[i]); this.originalFos = HelperFunctions.copy(this.displayedFos);
}
if (this.community.subjects.length === 0) {
this.community.subjects.push('');
}
this.showLoading = false; this.showLoading = false;
}, },
error => this.handleUpdateError('System error retrieving community profile', error) error => this.handleUpdateError('System error retrieving community profile', error)
@ -149,6 +152,8 @@ export class SubjectsEditFormComponent implements OnInit {
} }
subjects.sort((a, b) => a.localeCompare(b)); subjects.sort((a, b) => a.localeCompare(b));
if(type === 'all') { if(type === 'all') {
this.indexAll = 0;
this.activeTab = 'all';
this.groupedAllSubjects = Object.values( this.groupedAllSubjects = Object.values(
subjects.reduce((acc, subject) => { subjects.reduce((acc, subject) => {
let firstLetter = subject[0].toLocaleUpperCase(); let firstLetter = subject[0].toLocaleUpperCase();
@ -165,6 +170,8 @@ export class SubjectsEditFormComponent implements OnInit {
} }
} }
if(type === 'freeText') { if(type === 'freeText') {
this.indexSubjects = 0;
this.activeTab = 'freeText';
this.groupedSubjects = Object.values( this.groupedSubjects = Object.values(
subjects.reduce((acc, subject) => { subjects.reduce((acc, subject) => {
let firstLetter = subject[0].toLocaleUpperCase(); let firstLetter = subject[0].toLocaleUpperCase();
@ -181,6 +188,8 @@ export class SubjectsEditFormComponent implements OnInit {
} }
} }
if(type === 'sdg') { if(type === 'sdg') {
this.indexSdg = 0;
this.activeTab = 'sdg';
this.groupedSdg = Object.values( this.groupedSdg = Object.values(
subjects.reduce((acc, subject) => { subjects.reduce((acc, subject) => {
let firstLetter = subject[0].toLocaleUpperCase(); let firstLetter = subject[0].toLocaleUpperCase();
@ -197,6 +206,8 @@ export class SubjectsEditFormComponent implements OnInit {
} }
} }
if(type === 'fos') { if(type === 'fos') {
this.indexFos = 0;
this.activeTab = 'fos';
this.groupedFos = Object.values( this.groupedFos = Object.values(
subjects.reduce((acc, subject) => { subjects.reduce((acc, subject) => {
let key = subject.substring(0,2).toLocaleUpperCase(); let key = subject.substring(0,2).toLocaleUpperCase();
@ -216,7 +227,15 @@ export class SubjectsEditFormComponent implements OnInit {
public changeDisplayedSubjects(i, group) { public changeDisplayedSubjects(i, group) {
this.subjectsColumns = []; 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') { if(group.data.length > this.subjectsLimit && group.group != 'All') {
this.divideSubjects(group); this.divideSubjects(group);
} }
@ -230,19 +249,6 @@ export class SubjectsEditFormComponent implements OnInit {
this.subjectsColumns = columns; this.subjectsColumns = columns;
} }
private removeModalOpen(subject: string, i: any) {
this.selectedSubjects = [subject];
this.reset(['']);
this.deleteModal.cancelButton = true;
this.deleteModal.okButton = true;
this.deleteModal.alertTitle = 'Delete Subject';
this.deleteModal.message = 'Are you sure you want to delete this subject?';
this.deleteModal.okButtonText = 'Yes';
this.deleteModal.cancelButtonText = 'No';
this.deleteModal.open();
}
public getSubjectsExistOnlyInFirst(firstArray: string[], secondArray: string[]): string[] { public getSubjectsExistOnlyInFirst(firstArray: string[], secondArray: string[]): string[] {
const difference = []; const difference = [];
for (let i = 0; i < firstArray.length; i++) { for (let i = 0; i < firstArray.length; i++) {
@ -333,24 +339,7 @@ export class SubjectsEditFormComponent implements OnInit {
} }
}); });
this._communityService.updateSubjects(this.community.subjects, this.community.fos, this.community.sdg); this._communityService.updateSubjects(this.community.subjects, this.community.fos, this.community.sdg);
this._clearCacheService.purgeBrowserCache("Subjects "+message, this.communityId);
// this.originalSubjects = [];
// for (let i = 0; i < this.community.subjects.length; i++) {
// this.originalSubjects.push(this.community.subjects[i]);
// }
// this.originalSubjects.sort((n1,n2)=> {
// if (n1.toLowerCase() > n2.toLowerCase()) {
// return 1;
// }
// if (n1.toLowerCase() < n2.toLowerCase()) {
// return -1;
// }
// return 0;
// });
// this.community.subjects = this.originalSubjects.filter(subject => {
// return !this.filterForm.value || subject.toLowerCase().indexOf(this.filterForm.value.toLowerCase()) != -1
// }).sort();
// this._clearCacheService.purgeBrowserCache("Subjects "+message, this.communityId);
NotificationHandler.rise('Subjects successfully ' + message + '!') NotificationHandler.rise('Subjects successfully ' + message + '!')
this.showLoading = false; this.showLoading = false;
} }
@ -386,112 +375,4 @@ export class SubjectsEditFormComponent implements OnInit {
return false; return false;
} }
} }
public addSubjectInForm() {
this.myForm.push(new UntypedFormControl(''));
}
public removeSubjectInForm(i: number) {
this.myForm.removeAt(i);
}
public reset(subjects: string[]) {
this.myForm = new UntypedFormArray([]);
for (let subject in subjects) {
this.myForm.push(new UntypedFormControl(''));
}
this.myForm.patchValue(subjects);
}
newSubject() {
this.isEditModal = false;
this.selectedSubjects = [];
this.reset([]);
this.fullscreen.title = "Add/Edit Subjects";
this.fullscreen.okButtonText = "Save";
this.fullscreen.back = true;
this.fullscreen.okButton = true;
this.fullscreen.open();
}
get currentPage() {
if(this.community.subjects) {
return this.community.subjects.slice((this.page - 1) * this.size, this.page * this.size);
} else {
return [];
}
}
public updatePage(event) {
this.page = event.value;
HelperFunctions.scroll();
}
public editSubject(subject: string) {
this.isEditModal = true;
this.selectedSubjects = [subject];
this.reset([subject]);
this.fullscreen.title = "Edit Subject";
this.fullscreen.okButtonText = "Save";
this.fullscreen.back = true;
this.fullscreen.okButton = true;
this.fullscreen.open();
}
private formModalOpen(title: string, yesBtn: string) {
this.editModal.okButtonLeft = false;
this.editModal.cancelButton = true;
this.editModal.okButton = true;
this.editModal.alertTitle = title;
this.editModal.okButtonText = yesBtn;
this.editModal.open();
}
public onSearchClose() {
this.selectedKeyword = this.filterForm.value;
}
public resetInput() {
this.selectedKeyword = null;
this.searchInputComponent.reset()
}
/*
//Check again functionality to enable page
private getSubjectsPageStatus() {
this._helpContentService.getCommunityPagesByRoute(this.communityId, '/subjects', this.properties.adminToolsAPIURL).subscribe((page) => {
this.subjectsPage = page;
});
}
public get subjectsEnabled(): boolean {
return !this.subjectsPage || this.subjectsPage.isEnabled;
}
enablePage() {
this._helpContentService.togglePages(this.communityId, [this.subjectsPage._id], true, this.properties.adminToolsAPIURL).subscribe(() => {
this.subjectsPage.isEnabled = true;
UIkit.notification('Curators Page has been <b>enabled successfully</b>', {
status: 'success',
timeout: 6000,
pos: 'bottom-right'
});
},error => {
this.subjectsPage.isEnabled = false;
UIkit.notification('An error occured', {
status: 'danger',
timeout: 6000,
pos: 'bottom-right'
});
});
}
private curatorsEnabledOpen() {
this.enablePageModal.okButtonLeft = false;
this.enablePageModal.alertTitle = 'Enable Subjects Page';
this.enablePageModal.okButtonText = 'Yes';
this.enablePageModal.cancelButtonText = 'No';
this.enablePageModal.open();
}*/
} }