subjects page: 'enter key' now adds subjects in the list, number of selected SDGs and FoS changes dynamically, 'save' button is enabled/disabled based on overall changes, update submodules

This commit is contained in:
Alex Martzios 2023-03-13 21:26:31 +02:00
parent f2bbf0fb85
commit 88be699fd2
3 changed files with 68 additions and 45 deletions

@ -1 +1 @@
Subproject commit cdd59b68abb368dc178e898ce3b336606cd499d1
Subproject commit e0a81273535091b8d1f4755acc8b6975c9904a02

View File

@ -1,24 +1,10 @@
<div page-content>
<!-- <div header>
<div class="uk-flex uk-flex-middle uk-margin-medium-top info">
<div>
<div class="uk-text-background uk-text-bold uk-text-small">Admin Dashboard - Manage Subjects
</div>
<h1 class="uk-h6 uk-margin-remove">{{community.shortTitle}}</h1>
</div>
</div>
</div> -->
<div actions class="uk-margin-top">
<div class="uk-section-xsmall">
<div class="uk-flex uk-flex-right@m uk-flex-center uk-flex-middle uk-grid uk-margin-top" uk-grid>
<div [disabled]="showLoading" search-input class="uk-width-1-3@xl uk-width-2-5@l uk-width-1-2@m uk-width-1-1"
[searchControl]="filterForm" [expandable]="true" placeholder="Search Subjects" searchInputClass="outer">
</div>
<!-- <a *ngIf="!subjectsEnabled" (click)="enablePage()" class="uk-link-heading uk-text-small uk-text-uppercase"
uk-tooltip="title:<div class='uk-padding-small'>This information will be visible in <b>Subjects page</b> of Research Community Dashboard, which is <b>disabled</b>. <br> Click to enable id.</div>">
<span class="uk-text-secondary"><icon name="check_circle_outlined"></icon></span>
Enable page
</a>-->
<div>
<button class="uk-button uk-button-default uk-flex uk-flex-middle"
[disabled]="showLoading" [class.uk-disabled]="showLoading"
@ -76,7 +62,9 @@
<div>
<h6>{{item.group}}</h6>
<div *ngFor="let subItem of item.data.slice(0, subjectsLimit)" class="uk-margin-small-bottom">
<span>{{subItem.length > maxCharacters ? subItem.substring(0,maxCharacters)+'...' : subItem}}</span>
<span [attr.uk-tooltip]="subItem.length > maxCharacters ? 'cls: uk-active' : 'cls: uk-invisible'" [title]="subItem">
{{subItem.length > maxCharacters ? subItem.substring(0,maxCharacters)+'...' : subItem}}
</span>
</div>
<div *ngIf="item.data.length > subjectsLimit">
<a (click)="changeDisplayedSubjects(i+1, item)" class="view-more-less-link">
@ -93,14 +81,18 @@
<h6>{{groupedAllSubjects[index].group}}</h6>
<ng-container *ngIf="subjectsColumns?.length == 0; else elseBlock">
<div *ngFor="let subItem of groupedAllSubjects[index].data" class="uk-margin-small-bottom">
<span>{{subItem.length > maxCharacters ? subItem.substring(0,maxCharacters)+'...' : subItem}}</span>
<span [attr.uk-tooltip]="subItem.length > maxCharacters ? 'cls: uk-active' : 'cls: uk-invisible'" [title]="subItem">
{{subItem.length > maxCharacters ? subItem.substring(0,maxCharacters)+'...' : subItem}}
</span>
</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">
<span>{{subItem.length > maxCharacters ? subItem.substring(0,maxCharacters)+'...' : subItem}}</span>
<span [attr.uk-tooltip]="subItem.length > maxCharacters ? 'cls: uk-active' : 'cls: uk-invisible'" [title]="subItem">
{{subItem.length > maxCharacters ? subItem.substring(0,maxCharacters)+'...' : subItem}}
</span>
</div>
</div>
</div>
@ -126,7 +118,9 @@
<div>
<h6>{{item.group}}</h6>
<div *ngFor="let subItem of item.data.slice(0, subjectsLimit)" class="uk-margin-small-bottom">
<span>{{subItem.length > maxCharacters ? subItem.substring(0,maxCharacters)+'...' : subItem}}</span>
<span [attr.uk-tooltip]="subItem.length > maxCharacters ? 'cls: uk-active' : 'cls: uk-invisible'" [title]="subItem">
{{subItem.length > maxCharacters ? subItem.substring(0,maxCharacters)+'...' : subItem}}
</span>
</div>
<div *ngIf="item.data.length > subjectsLimit">
<a (click)="changeDisplayedSubjects(i+1, item)" class="view-more-less-link">
@ -143,14 +137,18 @@
<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">
<span>{{subItem.length > maxCharacters ? subItem.substring(0,maxCharacters)+'...' : subItem}}</span>
<span [attr.uk-tooltip]="subItem.length > maxCharacters ? 'cls: uk-active' : 'cls: uk-invisible'" [title]="subItem">
{{subItem.length > maxCharacters ? subItem.substring(0,maxCharacters)+'...' : subItem}}
</span>
</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">
<span>{{subItem.length > maxCharacters ? subItem.substring(0,maxCharacters)+'...' : subItem}}</span>
<span [attr.uk-tooltip]="subItem.length > maxCharacters ? 'cls: uk-active' : 'cls: uk-invisible'" [title]="subItem">
{{subItem.length > maxCharacters ? subItem.substring(0,maxCharacters)+'...' : subItem}}
</span>
</div>
</div>
</div>
@ -176,7 +174,9 @@
<div>
<h6>{{item.group}}</h6>
<div *ngFor="let subItem of item.data.slice(0, subjectsLimit)" class="uk-margin-small-bottom">
<span>{{subItem.length > maxCharacters ? subItem.substring(0,maxCharacters)+'...' : subItem}}</span>
<span [attr.uk-tooltip]="subItem.length > maxCharacters ? 'cls: uk-active' : 'cls: uk-invisible'" [title]="subItem">
{{subItem.length > maxCharacters ? subItem.substring(0,maxCharacters)+'...' : subItem}}
</span>
</div>
<div *ngIf="item.data.length > subjectsLimit">
<a (click)="changeDisplayedSubjects(i+1, item)" class="view-more-less-link">
@ -193,14 +193,18 @@
<h6>{{groupedSdg[index].group}}</h6>
<ng-container *ngIf="subjectsColumns?.length == 0; else elseBlock">
<div *ngFor="let subItem of groupedSdg[index].data" class="uk-margin-small-bottom">
<span>{{subItem.length > maxCharacters ? subItem.substring(0,maxCharacters)+'...' : subItem}}</span>
<span [attr.uk-tooltip]="subItem.length > maxCharacters ? 'cls: uk-active' : 'cls: uk-invisible'" [title]="subItem">
{{subItem.length > maxCharacters ? subItem.substring(0,maxCharacters)+'...' : subItem}}
</span>
</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">
<span>{{subItem.length > maxCharacters ? subItem.substring(0,maxCharacters)+'...' : subItem}}</span>
<span [attr.uk-tooltip]="subItem.length > maxCharacters ? 'cls: uk-active' : 'cls: uk-invisible'" [title]="subItem">
{{subItem.length > maxCharacters ? subItem.substring(0,maxCharacters)+'...' : subItem}}
</span>
</div>
</div>
</div>
@ -245,7 +249,9 @@
<h6>{{groupedFos[index].group}}</h6>
<ng-container *ngIf="subjectsColumns?.length == 0; else elseBlock">
<div *ngFor="let subItem of groupedFos[index].data" class="uk-margin-small-bottom">
<span>{{subItem.length > maxCharacters ? subItem.substring(0,maxCharacters)+'...' : subItem}}</span>
<span [attr.uk-tooltip]="subItem.length > maxCharacters ? 'cls: uk-active' : 'cls: uk-invisible'" [title]="subItem">
{{subItem.length > maxCharacters ? subItem.substring(0,maxCharacters)+'...' : subItem}}
</span>
</div>
</ng-container>
<ng-template #elseBlock>
@ -315,28 +321,28 @@
</div>
</div>
</div>
<modal-alert #deleteModal (alertOutput)="saveAllSubjects()" [overflowBody]="false" classTitle="uk-background-primary uk-light"></modal-alert>
<fs-modal #fsModal classBody="uk-container-large" (okEmitter)="saveAllSubjects()">
<!-- TODO: add disabled button functionality again! -->
<!-- [okButtonDisabled]="myForm && (myForm.invalid || !myForm.dirty)" -->
<!-- <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">
<div>
<ul uk-tab 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">
<a>Free Text ({{displayedSubjects.length}})</a>
</li>
<li>
<a>SDGs ({{displayedSdg.length}})</a>
<a>SDGs ({{sdgSelection.getSelectedSubjects().length}})</a>
</li>
<li>
<a>Fields of Science ({{displayedFos.length}})</a>
<a>Fields of Science ({{fosSelection.getSelectedSubjects().length}})</a>
</li>
</ul>
<ul class="uk-switcher">
<li *ngIf="subjectsForm">
<div input [type]="'chips'" [formInput]="subjectsForm" [inputClass]="'flat'"
[separators]="[',']" [visibleChips]="3" class="uk-width-large@m"
<div input [type]="'chips'" [formInput]="subjectsForm" [inputClass]="'flat small'" [extendEnter]="onEnter"
[separators]="[',', 'enter']" [visibleChips]="3" class="uk-width-1-1 uk-width-xlarge@m"
[placeholder]="{static: true, label: 'Type subjects as free text keywords'}">
<button action (click)="addSubjectsIntoList()" class="uk-button uk-button-link uk-margin-xsmall-left uk-margin-right">add</button>
<div tools class="uk-flex uk-flex-right">
<button (click)="addSubjectsIntoList()" class="uk-button uk-button-link uk-margin-xsmall-left uk-margin-right">add</button>
</div>
<div note class="uk-text-xsmall">Separate subjects with commas</div>
</div>
<!-- <form *ngIf="myForm">
@ -375,7 +381,7 @@
<sdg-selection #sdgSelection [subjects]="displayedSdg" [isFeedback]="false"></sdg-selection>
</li>
<li>
<fos-selection #fosSelection [subjects]="displayedFos"></fos-selection>
<fos-selection #fosSelection [subjects]="displayedFos" [inModal]="true"></fos-selection>
</li>
</ul>
</div>

View File

@ -1,5 +1,5 @@
import {Component, ElementRef, OnInit, ViewChild} from '@angular/core';
import {FormArray, UntypedFormArray, UntypedFormBuilder, UntypedFormControl, UntypedFormGroup} from '@angular/forms';
import {UntypedFormArray, UntypedFormBuilder, UntypedFormControl} from '@angular/forms';
import {ActivatedRoute, Router} from '@angular/router';
import {CommunityService} from '../../../openaireLibrary/connect/community/community.service';
import {SubjectsService} from '../subjects.service';
@ -15,6 +15,9 @@ import {HelperFunctions} from 'src/app/openaireLibrary/utils/HelperFunctions.cla
import {NotificationHandler} from "../../../openaireLibrary/utils/notification-handler";
import {ClearCacheService} from "../../../openaireLibrary/services/clear-cache.service";
import {SdgSelectionComponent} from '../../../openaireLibrary/sdg/sdg-selection/sdg-selection.component';
import {FosSelectionComponent} from '../../../openaireLibrary/fos/fos-selection/fos-selection.component';
declare var UIkit: any;
@Component({
selector: 'subjects-edit-form',
@ -34,6 +37,7 @@ export class SubjectsEditFormComponent implements OnInit {
displayedSubjects = [];
displayedSdg = [];
displayedFos = [];
hasChanges: boolean = false;
myForm = new UntypedFormArray([]);
public showLoading = true;
@ -47,6 +51,7 @@ export class SubjectsEditFormComponent implements OnInit {
@ViewChild('editModal') editModal: AlertModal;
@ViewChild('deleteModal') deleteModal: AlertModal;
@ViewChild('fsModal', {static: true}) fullscreen: FullScreenModalComponent;
@ViewChild('modalTabs') modalTabs: ElementRef;
page = 1;
size = 10;
selectedSubjects = [];
@ -57,10 +62,15 @@ export class SubjectsEditFormComponent implements OnInit {
private subscriptions: any[] = [];
@ViewChild('sdgSelection') sdgSelection: SdgSelectionComponent;
@ViewChild('fosSelection') fosSelection: SdgSelectionComponent;
@ViewChild('fosSelection') fosSelection: FosSelectionComponent;
/*//Check again functionality to enable page
subjectsPage;
@ViewChild('enablePageModal') enablePageModal: AlertModal;*/
onEnter: () => void = () => {
this.addSubjectsIntoList();
}
constructor(private element: ElementRef,
private route: ActivatedRoute,
private _router: Router,
@ -77,7 +87,6 @@ export class SubjectsEditFormComponent implements OnInit {
ngOnInit() {
this.filterForm = this._fb.control('');
this.subscriptions.push(this.filterForm.valueChanges.subscribe(value => {
this.page = 1;
this.community.subjects = this.originalSubjects.filter(subject => {
return !value || subject.toLowerCase().indexOf(value.toLowerCase()) != -1
});
@ -104,7 +113,7 @@ export class SubjectsEditFormComponent implements OnInit {
return 0;
});
// assigning values
this.displayedSubjects = this.community.subjects;
this.displayedSubjects = HelperFunctions.copy(this.community.subjects);
this.displayedSdg = this.community.sdg;
this.displayedFos = this.community.fos;
this.displayedAllSubjects = [...this.displayedSubjects, ...this.displayedSdg, ...this.displayedFos];
@ -188,14 +197,13 @@ export class SubjectsEditFormComponent implements OnInit {
}
}
if(type === 'fos') {
// TODO: check second letter as well to group them in 01,02,03 etc.
this.groupedFos = Object.values(
subjects.reduce((acc, subject) => {
let firstLetter = subject[0].toLocaleUpperCase();
if(!acc[firstLetter]) {
acc[firstLetter] = {group: firstLetter, data: [subject]};
let key = subject.substring(0,2).toLocaleUpperCase();
if(!acc[key]) {
acc[key] = {group: key, data: [subject]};
} else {
acc[firstLetter].data.push(subject);
acc[key].data.push(subject);
}
return acc;
},{})
@ -246,6 +254,12 @@ export class SubjectsEditFormComponent implements OnInit {
}
public editAllSubjects() {
UIkit.tab(this.modalTabs.nativeElement).show(0);
this.displayedSubjects = HelperFunctions.copy(this.community.subjects);
this.sdgSelection.reset();
this.sdgSelection.sdgs.markAsPristine();
this.fosSelection.reset();
this.fosSelection.fosOptions.markAsPristine();
this.fullscreen.title = "Add/Edit Subjects";
this.fullscreen.okButtonText = "Save";
this.fullscreen.back = true;
@ -259,10 +273,12 @@ export class SubjectsEditFormComponent implements OnInit {
this.displayedSubjects.unshift(element);
});
this.subjectsForm.clear();
this.hasChanges = true;
}
public removeSubjectFromList(i) {
this.displayedSubjects.splice(i, 1);
this.hasChanges = true;
}
public saveAllSubjects() {
@ -440,6 +456,7 @@ export class SubjectsEditFormComponent implements OnInit {
this.selectedKeyword = null;
this.searchInputComponent.reset()
}
/*
//Check again functionality to enable page
private getSubjectsPageStatus() {