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 header>
<community-info tab="subjects"></community-info>
<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 page-content (stickyEmitter)="stickyPageHeader = $event">
<div header>
<div class="uk-flex uk-flex-middle uk-margin-top info" [class.uk-active]="stickyPageHeader">
<div>
<a (click)="newSubject()"
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>"
class="uk-flex uk-flex-middle uk-text-uppercase">
<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 class="uk-margin-remove uk-text-background uk-text-bold uk-h6">Admin Dashboard - Manage Subjects
</div>
<h1 class="uk-h4 uk-margin-remove">{{community.shortTitle}}</h1>
</div>
</div>
<community-info tab="subjects"></community-info>
</div>
<div inner>
<div *ngIf="showLoading" class="uk-position-center">
<loading *ngIf="showLoading"></loading>
</div>
<div *ngIf="community && community.subjects && !showLoading">
<div *ngIf="community.subjects.length == 0"
class="uk-card uk-card-default uk-padding-large uk-text-center uk-margin-bottom uk-text-bold">
<div>No subjects found</div>
<div class="uk-grid uk-margin-top" uk-grid>
<div class="uk-width-1-2@m"></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 [disabled]="showLoading" search-input class="uk-width-expand@l 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"
(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 *ngIf="community.subjects.length > 0">
<no-load-paging *ngIf="community.subjects.length > 0" [type]="'Subjects'"
[page]="page" [pageSize]="size" (pageChange)="page = $event.value"
[totalResults]="community.subjects.length">
</no-load-paging>
<ul class="uk-list">
<li *ngFor='let subject of community.subjects; let i = index;'
class="uk-card uk-card-default uk-margin-bottom" [class.uk-hidden]="i > page * size ||
i < (page - 1) * size">
<div class="uk-grid uk-padding uk-grid-divider uk-flex uk-flex-middle" uk-grid>
<div class="uk-width-expand uk-text-large">
<span
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>">
{{subject}}
</span>
</div>
<div class="uk-width-auto">
<div class="uk-flex-center uk-flex">
<div class="uk-padding-small uk-padding-remove-horizontal">
<a (click)="editSubject(subject)" class="uk-button action uk-flex uk-flex-middle">
<icon name="edit"></icon>
<span class="uk-margin-small-left">Edit</span>
</a>
<a (click)="removeModalOpen(subject, i)"
class="uk-button action uk-margin-small-top uk-flex uk-flex-middle ">
<icon name="remove" ratio="0.9"></icon>
<span class="uk-margin-small-left">Delete</span>
</a>
<div *ngIf="!showLoading">
<div *ngIf="community.subjects.length == 0"
class="uk-card uk-card-default uk-padding-large uk-text-center uk-margin-bottom uk-text-bold">
<div>No subjects found</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>
</li>
</ul>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<modal-alert #editModal (alertOutput)="saveSubjects()"
[okDisabled]="myForm && (myForm.invalid || !myForm.dirty)">
<div class="uk-height-medium uk-overflow-auto" style="margin-right: -30px">
<form *ngIf="myForm" class="uk-grid uk-child-width-1-1 uk-margin-right" uk-grid>
<div *ngFor=" let control of myForm.controls; index as i" class="uk-flex-middle uk-grid uk-grid-small" uk-grid>
<div dashboard-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">
<a class="uk-link-heading" [class.uk-invisible]="myForm.length === 1"
(click)="removeSubjectInForm(i)">
<icon name="close"></icon>
</a>
</div>
</div>
<div class="uk-margin-top uk-flex-center uk-flex">
<a *ngIf="!isEditModal" (click)="addSubjectInForm()">
<button class="uk-icon-button uk-button-secondary">
<icon name="add"></icon>
</button>
</a>
</div>
</form>
</div>
</modal-alert>
<modal-alert #deleteModal (alertOutput)="saveSubjects()"></modal-alert>
<modal-alert #deleteModal (alertOutput)="saveSubjects()" [overflowBody]="false" classTitle="uk-background-primary uk-light"></modal-alert>
<fs-modal #fsModal classBody="uk-container-small" (okEmitter)="saveSubjects()" [okButtonDisabled]="myForm && (myForm.invalid || !myForm.dirty)">
<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">
<icon name="add"></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">
<a class="uk-close" [class.uk-invisible]="myForm.length === 1"
(click)="removeSubjectInForm(i)">
<icon name="close" [flex]="true" [ratio]="1.5"></icon>
</a>
</div>
</div>
</div>
</form>
</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

View File

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

View File

@ -17,10 +17,11 @@ import {LoadingModule} from '../../../openaireLibrary/utils/loading/loading.modu
import {InputModule} from '../../../openaireLibrary/sharedComponents/input/input.module';
import {CommunityInfoModule} from '../../community-info/community-info.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({
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: [
SubjectsEditFormComponent