finish admin - subjects page

This commit is contained in:
Alex Martzios 2022-07-04 15:13:33 +03:00
parent dc2aa3b764
commit 25c8cc29a6
4 changed files with 181 additions and 168 deletions

@ -1 +1 @@
Subproject commit de493c84923348f8289d4e507c04cfec80c30d69 Subproject commit e61d4495aee212f7e991f0ad9c54c0429cf01757

View File

@ -1,102 +1,115 @@
<div page-content> <div page-content (stickyEmitter)="stickyPageHeader = $event">
<div header> <div header>
<community-info tab="subjects"></community-info> <div class="uk-flex uk-flex-middle uk-margin-top info" [class.uk-active]="stickyPageHeader">
<div class="uk-width-1-1 uk-flex uk-flex-right@m uk-flex-center uk-flex-wrap uk-flex-middle uk-grid" uk-grid>
<div #searchInputComponent search-input [control]="filterForm" [showSearch]="false" placeholder="Search subjects"
[selected]="selectedKeyword" (closeEmitter)="onSearchClose()" (resetEmitter)="resetInput()"
[bordered]="true" colorClass="uk-text-secondary"
class="uk-width-1-3@xl uk-width-2-5@l uk-width-1-2@m uk-width-1-1"></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> <div>
<a (click)="newSubject()" <div class="uk-margin-remove uk-text-background uk-text-bold uk-h6">Admin Dashboard - Manage Subjects
uk-tooltip="title:<div class='uk-padding-small'><div class='uk-margin-bottom uk-text-bold'>Add new subjects</div> All the research results associated to the subjects specified here will be automatically linked to the community dashboard in the next run of OpenAIRE workflows.</div>" </div>
class="uk-flex uk-flex-middle uk-text-uppercase"> <h1 class="uk-h4 uk-margin-remove">{{community.shortTitle}}</h1>
<button class="large uk-icon-button uk-button-secondary">
<icon name="add"></icon>
</button>
<button class="uk-button uk-button-link uk-margin-small-left uk-text-secondary">Add new subject</button>
</a>
</div> </div>
</div> </div>
<community-info tab="subjects"></community-info>
</div> </div>
<div inner> <div inner>
<div *ngIf="showLoading" class="uk-position-center"> <div class="uk-grid uk-margin-top" uk-grid>
<loading *ngIf="showLoading"></loading> <div class="uk-width-1-2@m"></div>
</div> <div class="uk-width-expand@m uk-width-1-1 uk-grid uk-flex-middle uk-flex-right@m uk-flex-center uk-margin-remove-left" uk-grid>
<div *ngIf="community && community.subjects && !showLoading"> <div [disabled]="showLoading" search-input class="uk-width-expand@l uk-width-1-1"
<div *ngIf="community.subjects.length == 0" [searchControl]="filterForm" [expandable]="true" placeholder="Search Subjects" searchInputClass="outer">
class="uk-card uk-card-default uk-padding-large uk-text-center uk-margin-bottom uk-text-bold"> </div>
<div>No subjects found</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"
(click)="newSubject()"
uk-tooltip="title:<div><div class='uk-margin-small-bottom uk-text-bold'>Add new subjects</div> All the research results associated to the subjects specified here will be automatically linked to the community dashboard in the next run of OpenAIRE workflows.</div>">
<icon name="add" [flex]="true"></icon>
<span class="uk-margin-small-left">New Subject</span>
</button>
</div>
</div>
</div>
<div class="uk-section uk-section-small uk-position-relative" style="min-height: 60vh">
<div *ngIf="showLoading" class="uk-position-center">
<loading></loading>
</div> </div>
<div *ngIf="community.subjects.length > 0"> <div *ngIf="!showLoading">
<no-load-paging *ngIf="community.subjects.length > 0" [type]="'Subjects'" <div *ngIf="community.subjects.length == 0"
[page]="page" [pageSize]="size" (pageChange)="page = $event.value" class="uk-card uk-card-default uk-padding-large uk-text-center uk-margin-bottom uk-text-bold">
[totalResults]="community.subjects.length"> <div>No subjects found</div>
</no-load-paging> </div>
<ul class="uk-list"> <div *ngIf="community.subjects.length > 0">
<li *ngFor='let subject of community.subjects; let i = index;' <no-load-paging *ngIf="community.subjects.length > 0" [type]="'Subjects'"
class="uk-card uk-card-default uk-margin-bottom" [class.uk-hidden]="i > page * size || [page]="page" [pageSize]="size" (pageChange)="updatePage($event)"
i < (page - 1) * size"> [totalResults]="community.subjects.length">
<div class="uk-grid uk-padding uk-grid-divider uk-flex uk-flex-middle" uk-grid> </no-load-paging>
<div class="uk-width-expand uk-text-large"> <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>
<span <div *ngFor='let subject of currentPage; let i = index;'>
uk-tooltip="title:<div class='uk-padding-small'> All the research results associated to this subjects will be automatically linked to the community dashboard. </div>"> <div class="uk-card uk-card-default">
{{subject}} <div class="uk-card-body">
</span> <h6 uk-tooltip="title:All the research results associated to this subjects will be automatically linked to the community dashboard."
</div> class="uk-display-inline-block">
<div class="uk-width-auto"> {{subject}}
<div class="uk-flex-center uk-flex"> </h6>
<div class="uk-padding-small uk-padding-remove-horizontal"> </div>
<a (click)="editSubject(subject)" class="uk-button action uk-flex uk-flex-middle"> <div class="uk-card-footer uk-padding-remove-vertical">
<icon name="edit"></icon> <div class="uk-grid uk-grid-small uk-flex-nowrap uk-grid-divider uk-flex-right" uk-grid>
<span class="uk-margin-small-left">Edit</span> <div>
</a> <div class="uk-padding-small uk-padding-remove-horizontal">
<a (click)="removeModalOpen(subject, i)" <a (click)="editSubject(subject)"
class="uk-button action uk-margin-small-top uk-flex uk-flex-middle "> class="uk-button uk-button-link uk-flex uk-flex-middle">
<icon name="remove" ratio="0.9"></icon> <icon name="edit" [flex]="true"></icon>
<span class="uk-margin-small-left">Delete</span> <span class="uk-margin-xsmall-left">Edit</span>
</a> </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>
</li> </div>
</ul> </div>
</div> </div>
</div> </div>
</div> </div>
</div> </div>
<modal-alert #editModal (alertOutput)="saveSubjects()" <modal-alert #deleteModal (alertOutput)="saveSubjects()" [overflowBody]="false" classTitle="uk-background-primary uk-light"></modal-alert>
[okDisabled]="myForm && (myForm.invalid || !myForm.dirty)"> <fs-modal #fsModal classBody="uk-container-small" (okEmitter)="saveSubjects()" [okButtonDisabled]="myForm && (myForm.invalid || !myForm.dirty)">
<div class="uk-height-medium uk-overflow-auto" style="margin-right: -30px"> <form *ngIf="myForm">
<form *ngIf="myForm" class="uk-grid uk-child-width-1-1 uk-margin-right" uk-grid> <div class="uk-margin-top uk-flex-center uk-flex uk-margin-medium-bottom">
<div *ngFor=" let control of myForm.controls; index as i" class="uk-flex-middle uk-grid uk-grid-small" uk-grid> <a *ngIf="!isEditModal" (click)="addSubjectInForm()">
<div dashboard-input [formInput]="myForm.controls[i]" type="text" <button class="uk-button uk-button-primary">
placeholder="Type subjects as free text keywords" class="uk-width-expand "></div> <icon name="add"></icon>
<div *ngIf="!isEditModal" class="uk-width-auto"> <span class="uk-margin-xsmall-left">Add Subject</span>
<a class="uk-link-heading" [class.uk-invisible]="myForm.length === 1" </button>
(click)="removeSubjectInForm(i)"> </a>
<icon name="close"></icon> </div>
</a> <div class="uk-grid uk-child-width-1-1" uk-grid>
</div> <div *ngFor=" let control of myForm.controls; index as i" class="uk-flex uk-flex-middle">
</div> <div input [formInput]="myForm.controls[i]" type="text"
<div class="uk-margin-top uk-flex-center uk-flex"> placeholder="Type subjects as free text keywords" class="uk-width-expand"></div>
<a *ngIf="!isEditModal" (click)="addSubjectInForm()"> <div *ngIf="!isEditModal" class="uk-width-auto uk-flex uk-flex-center uk-margin-left">
<button class="uk-icon-button uk-button-secondary"> <a class="uk-close" [class.uk-invisible]="myForm.length === 1"
<icon name="add"></icon> (click)="removeSubjectInForm(i)">
</button> <icon name="close" [flex]="true" [ratio]="1.5"></icon>
</a> </a>
</div> </div>
</form> </div>
</div> </div>
</modal-alert> </form>
<modal-alert #deleteModal (alertOutput)="saveSubjects()"></modal-alert> </fs-modal>
<!--<modal-alert #enablePageModal (alertOutput)="enablePage()"> <!--<modal-alert #enablePageModal (alertOutput)="enablePage()">
<div class="uk-padding uk-padding-remove-horizontal"> <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 This information will be visible in <span class="uk-text-bold">Subjects page</span> of Research Community

View File

@ -13,6 +13,8 @@ import {SearchInputComponent} from '../../../openaireLibrary/sharedComponents/se
import {Subscription, zip} from 'rxjs'; import {Subscription, zip} from 'rxjs';
import {CommunityInfo} from '../../../openaireLibrary/connect/community/communityInfo'; import {CommunityInfo} from '../../../openaireLibrary/connect/community/communityInfo';
import {concat} from 'rxjs/operators'; import {concat} from 'rxjs/operators';
import {FullScreenModalComponent} from 'src/app/openaireLibrary/utils/modal/full-screen-modal/full-screen-modal.component';
import {HelperFunctions} from 'src/app/openaireLibrary/utils/HelperFunctions.class';
declare var UIkit; declare var UIkit;
@ -33,6 +35,7 @@ export class SubjectsEditFormComponent implements OnInit {
public originalSubjects = []; public originalSubjects = [];
@ViewChild('editModal') editModal: AlertModal; @ViewChild('editModal') editModal: AlertModal;
@ViewChild('deleteModal') deleteModal: AlertModal; @ViewChild('deleteModal') deleteModal: AlertModal;
@ViewChild('fsModal', {static: true}) fullscreen: FullScreenModalComponent;
page = 1; page = 1;
size = 10; size = 10;
selectedSubjects = []; selectedSubjects = [];
@ -41,6 +44,7 @@ export class SubjectsEditFormComponent implements OnInit {
@ViewChild('searchInputComponent') searchInputComponent: SearchInputComponent; @ViewChild('searchInputComponent') searchInputComponent: SearchInputComponent;
public filterForm: FormControl; public filterForm: FormControl;
private subscriptions: any[] = []; private subscriptions: any[] = [];
public stickyPageHeader: boolean = false;
/*//Check again functionality to enable page /*//Check again functionality to enable page
subjectsPage; subjectsPage;
@ViewChild('enablePageModal') enablePageModal: AlertModal;*/ @ViewChild('enablePageModal') enablePageModal: AlertModal;*/
@ -61,7 +65,7 @@ export class SubjectsEditFormComponent implements OnInit {
this.subscriptions.push(this.filterForm.valueChanges.subscribe(value => { this.subscriptions.push(this.filterForm.valueChanges.subscribe(value => {
this.page = 1; this.page = 1;
this.community.subjects = this.originalSubjects.filter(subject => { this.community.subjects = this.originalSubjects.filter(subject => {
return subject.toLowerCase().indexOf(value.toLowerCase()) != -1 return !value || subject.toLowerCase().indexOf(value.toLowerCase()) != -1
}); });
})); }));
this.subscriptions.push(this.route.params.subscribe( this.subscriptions.push(this.route.params.subscribe(
@ -111,24 +115,15 @@ export class SubjectsEditFormComponent implements OnInit {
} }
private removeModalOpen(subject: string, i: any) { private removeModalOpen(subject: string, i: any) {
if (!Session.isLoggedIn()) { this.selectedSubjects = [subject];
this._router.navigate(['/user-info'], { this.reset(['']);
queryParams: { this.deleteModal.cancelButton = true;
"errorCode": LoginErrorCodes.NOT_VALID, this.deleteModal.okButton = true;
"redirectUrl": this._router.url this.deleteModal.alertTitle = 'Delete Subject';
} this.deleteModal.message = 'Are you sure you want to delete this subject?';
}); this.deleteModal.okButtonText = 'Yes';
} else { this.deleteModal.cancelButtonText = 'No';
this.selectedSubjects = [subject]; this.deleteModal.open();
this.reset(['']);
this.deleteModal.cancelButton = true;
this.deleteModal.okButton = true;
this.deleteModal.alertTitle = 'Delete Confirmation';
this.deleteModal.message = 'Are you sure you want to delete this subject?';
this.deleteModal.okButtonText = 'Yes';
this.deleteModal.cancelButtonText = 'No';
this.deleteModal.open();
}
} }
@ -144,44 +139,36 @@ export class SubjectsEditFormComponent implements OnInit {
} }
public saveSubjects() { public saveSubjects() {
if (!Session.isLoggedIn()) { if (this.communityId != null && this.communityId !== '') {
this._router.navigate(['/user-info'], this.showLoading = true;
{queryParams: {'errorCode': LoginErrorCodes.NOT_VALID, 'redirectUrl': this._router.url}}); const subjectsToDeleteAr = this.getSubjectsExistOnlyInFirst(this.selectedSubjects, this.myForm.getRawValue());
} else { const subjectsToAddAr = this.getSubjectsExistOnlyInFirst(this.myForm.getRawValue(), this.selectedSubjects);
if (this.communityId != null && this.communityId !== '') { const subjectsToDelete = this.getNonEmptyItems(subjectsToDeleteAr);
this.showLoading = true; const subjectsToAdd = this.getNonEmptyItems(subjectsToAddAr);
const subjectsToDeleteAr = this.getSubjectsExistOnlyInFirst(this.selectedSubjects, this.myForm.getRawValue()); if (subjectsToAdd.length > 0 && subjectsToDelete.length > 0) {
const subjectsToAddAr = this.getSubjectsExistOnlyInFirst(this.myForm.getRawValue(), this.selectedSubjects); this.subscriptions.push(this._subjectsService.removeSubjects(
const subjectsToDelete = this.getNonEmptyItems(subjectsToDeleteAr); this.properties.communityAPI + this.communityId + '/subjects', subjectsToDelete).subscribe(res =>{
const subjectsToAdd = this.getNonEmptyItems(subjectsToAddAr); this.subscriptions.push(this._subjectsService.addSubjects(
if (subjectsToAdd.length > 0 && subjectsToDelete.length > 0) { this.properties.communityAPI + this.communityId + '/subjects', subjectsToAdd).subscribe(res => {
this.subscriptions.push(this._subjectsService.removeSubjects( this.afterUpdateActions(res, "added");
this.properties.communityAPI + this.communityId + '/subjects', subjectsToDelete).subscribe(res =>{ }));
this.subscriptions.push(this._subjectsService.addSubjects( }));
this.properties.communityAPI + this.communityId + '/subjects', subjectsToAdd).subscribe(res => { } else if (subjectsToAdd.length > 0) {
this.afterUpdateActions(res, "added"); this.subscriptions.push(this._subjectsService.addSubjects(
})); this.properties.communityAPI + this.communityId + '/subjects', subjectsToAdd).subscribe(res => {
})); this.afterUpdateActions(res, "added");
} else if (subjectsToAdd.length > 0) { },
this.subscriptions.push(this._subjectsService.addSubjects( error => this.handleUpdateError('System error updating subjects', error)
this.properties.communityAPI + this.communityId + '/subjects', subjectsToAdd).subscribe(res => { ));
this.afterUpdateActions(res, "added"); } else if (subjectsToDelete.length > 0) {
}, this.subscriptions.push(this._subjectsService.removeSubjects(
error => this.handleUpdateError('System error updating subjects', error) this.properties.communityAPI + this.communityId + '/subjects', subjectsToDelete).subscribe(res => {
)); this.afterUpdateActions(res, "deleted");
} else if (subjectsToDelete.length > 0) { },
this.subscriptions.push(this._subjectsService.removeSubjects( error => this.handleUpdateError('System error updating subjects', error)
this.properties.communityAPI + this.communityId + '/subjects', subjectsToDelete).subscribe(res => { ));
this.afterUpdateActions(res, "deleted"); }
}, }
error => this.handleUpdateError('System error updating subjects', error)
));
}
/* if(!this.subjectsEnabled) {
this.curatorsEnabledOpen();
}*/
}
}
} }
handleUpdateError(message: string, error) { handleUpdateError(message: string, error) {
@ -211,9 +198,9 @@ export class SubjectsEditFormComponent implements OnInit {
}); });
this.page = 1; this.page = 1;
this.community.subjects = this.originalSubjects.filter(subject => { this.community.subjects = this.originalSubjects.filter(subject => {
return subject.toLowerCase().indexOf(this.filterForm.value.toLowerCase()) != -1 return !this.filterForm.value || subject.toLowerCase().indexOf(this.filterForm.value.toLowerCase()) != -1
}).sort(); }).sort();
UIkit.notification('Subjects successfully ' + message + '!', { UIkit.notification('Subject successfully ' + message + '!', {
status: 'success', status: 'success',
timeout: 6000, timeout: 6000,
pos: 'bottom-right' pos: 'bottom-right'
@ -273,33 +260,45 @@ export class SubjectsEditFormComponent implements OnInit {
this.isEditModal = false; this.isEditModal = false;
this.selectedSubjects = []; this.selectedSubjects = [];
this.reset([""]); this.reset([""]);
this.formModalOpen('Add Subject', 'Save'); this.fullscreen.title = "Add Subject";
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) { public editSubject(subject: string) {
this.isEditModal = true; this.isEditModal = true;
this.selectedSubjects = [subject]; this.selectedSubjects = [subject];
this.reset([subject]); this.reset([subject]);
this.formModalOpen('Edit Subject', 'Save'); 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) { private formModalOpen(title: string, yesBtn: string) {
if (!Session.isLoggedIn()) { this.editModal.okButtonLeft = false;
this._router.navigate(['/user-info'], { this.editModal.cancelButton = true;
queryParams: { this.editModal.okButton = true;
"errorCode": LoginErrorCodes.NOT_VALID, this.editModal.alertTitle = title;
"redirectUrl": this._router.url this.editModal.okButtonText = yesBtn;
} this.editModal.open();
});
} else {
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() { public onSearchClose() {

View File

@ -17,10 +17,11 @@ import {LoadingModule} from '../../../openaireLibrary/utils/loading/loading.modu
import {InputModule} from '../../../openaireLibrary/sharedComponents/input/input.module'; import {InputModule} from '../../../openaireLibrary/sharedComponents/input/input.module';
import {CommunityInfoModule} from '../../community-info/community-info.module'; import {CommunityInfoModule} from '../../community-info/community-info.module';
import {SearchInputModule} from '../../../openaireLibrary/sharedComponents/search-input/search-input.module'; import {SearchInputModule} from '../../../openaireLibrary/sharedComponents/search-input/search-input.module';
import {FullScreenModalModule} from 'src/app/openaireLibrary/utils/modal/full-screen-modal/full-screen-modal.module';
@NgModule({ @NgModule({
imports: [ imports: [
SubjectsEditFormRoutingModule, CommonModule, FormsModule, RouterModule, PageContentModule, IconsModule, AlertModalModule, NoLoadPaging, LoadingModule, InputModule, CommunityInfoModule, SearchInputModule SubjectsEditFormRoutingModule, CommonModule, FormsModule, RouterModule, PageContentModule, IconsModule, AlertModalModule, NoLoadPaging, LoadingModule, InputModule, CommunityInfoModule, SearchInputModule, FullScreenModalModule
], ],
declarations: [ declarations: [
SubjectsEditFormComponent SubjectsEditFormComponent