diff --git a/dashboard/divId/divIds.component.html b/dashboard/divId/divIds.component.html index c976200c..70764705 100644 --- a/dashboard/divId/divIds.component.html +++ b/dashboard/divId/divIds.component.html @@ -4,7 +4,7 @@
search -
+
@@ -85,14 +85,15 @@ + +
+
No classes found
+
add
-
-
No classes found
-
diff --git a/dashboard/divId/divIds.component.ts b/dashboard/divId/divIds.component.ts index 37bfea64..1245f727 100644 --- a/dashboard/divId/divIds.component.ts +++ b/dashboard/divId/divIds.component.ts @@ -197,7 +197,7 @@ export class DivIdsComponent implements OnInit { this.pagesCtrl = this._fb.array([]); this.myForm = this._fb.group({ _id: divId._id, - name: divId.name, + name: [divId.name,Validators.required], pages: this.pagesCtrl, openaire: divId.openaire, connect: divId.connect, diff --git a/dashboard/divhelpcontent/div-help-content-form.component.html b/dashboard/divhelpcontent/div-help-content-form.component.html new file mode 100644 index 00000000..618a90e2 --- /dev/null +++ b/dashboard/divhelpcontent/div-help-content-form.component.html @@ -0,0 +1,56 @@ + + + +
+ + Create or edit help text +
+ Select the class to be displayed, add the content and click active to make it visible to dashboard +
+ +
+
+
+
Class content displayed in page(s): {{page.name}},
+ +
+ + +
+ +
+ + +
+ +
+
+ +
+ + + +
+
+
+ + +
+ +
+ diff --git a/dashboard/divhelpcontent/div-help-content-form.component.ts b/dashboard/divhelpcontent/div-help-content-form.component.ts new file mode 100644 index 00000000..03291357 --- /dev/null +++ b/dashboard/divhelpcontent/div-help-content-form.component.ts @@ -0,0 +1,161 @@ +import { Component, OnInit, Input } from '@angular/core'; +import { ActivatedRoute, Router } from "@angular/router"; +import { FormGroup, FormBuilder, Validators } from "@angular/forms"; +import { Page } from "../../utils/entities/adminTool/page"; +import { DivId } from "../../utils/entities/adminTool/divId"; +import { HelpContentService } from "../../services/help-content.service"; +import { EnvProperties } from '../../utils/properties/env-properties'; + +import {Session} from '../../login/utils/helper.class'; +import {LoginErrorCodes} from '../../login/utils/guardHelper.class'; + +@Component({ + selector: 'div-content-form', + templateUrl: './div-help-content-form.component.html', +}) + +export class DivContentFormComponent implements OnInit{ + + @Input('group') + myForm: FormGroup; + @Input('communityPid') + communityPid: string; + @Input('pageId') + pageId: string; + @Input('editMode') + editMode: boolean = false; + + //public divIdName: string = ''; + + private communityId: string = ''; + + showPageSelect: boolean = true; + selectedDiv: DivId; + + private availablePages : Page[] = []; + private availableDivs : DivId[] = []; + + private ckeditorContent : string; + + public properties:EnvProperties = null; + + public showLoading: boolean = true; + public errorMessage: string = ''; + @Input() updateErrorMessage: string = ''; + + constructor(private route: ActivatedRoute, private _router: Router, private _fb: FormBuilder, private _helpContentService: HelpContentService){} + + ngOnInit() { + this.myForm = this.form; + this.route.data + .subscribe((data: { envSpecific: EnvProperties }) => { + this.properties = data.envSpecific; + this.route.queryParams.subscribe(params => { + + if(!Session.isLoggedIn()){ + this._router.navigate(['/user-info'], { queryParams: { "errorCode": LoginErrorCodes.NOT_VALID, "redirectUrl": this._router.url} }); + } else { + if(this.pageId) { + this.showPageSelect = false; + this.getDivs(this.pageId); + } else { + if(!this.editMode) { + this._helpContentService.getCommunityPagesWithDivId(this.communityPid, this.properties.adminToolsAPIURL).subscribe( + pages => { + this.availablePages = pages; + this.showLoading = false; + }, + error => this.handleError('System error retrieving pages', error)); + } + } + + this.getCommunity(this.communityPid); + } + }); + }); + + } + + public pageSelected(event) { + if(!Session.isLoggedIn()){ + this._router.navigate(['/user-info'], { queryParams: { "errorCode": LoginErrorCodes.NOT_VALID, "redirectUrl": this._router.url} }); + } else { + this.getDivs(event.target.value); + } + } + + public divIdSelected(div: DivId) { + this.selectedDiv = div; + } + + public getCommunity(communityPid: string) { + if(!Session.isLoggedIn()){ + this._router.navigate(['/user-info'], { queryParams: { "errorCode": LoginErrorCodes.NOT_VALID, "redirectUrl": this._router.url} }); + } else { + this.showLoading = true; + this.errorMessage = ''; + + this._helpContentService.getCommunity(this.communityPid, this.properties.adminToolsAPIURL).subscribe( + community => { + this.communityId = community._id; + + this.myForm.patchValue({ + community: this.communityId + }); + this.showLoading = false; + }, + error => this.handleError('System error retrieving community', error) + ); + } + } + + public getDivs(pageId: string) { + if(!Session.isLoggedIn()){ + this._router.navigate(['/user-info'], { queryParams: { "errorCode": LoginErrorCodes.NOT_VALID, "redirectUrl": this._router.url} }); + } else { + //this.showLoading = true; + this.errorMessage = ''; + + this._helpContentService.getDivIdsFull(pageId, this.properties.adminToolsAPIURL, this.communityPid).subscribe( + divs => { + this.availableDivs = divs; + this.pageId = pageId; + + this.showLoading = false; + }, + error => this.handleError('System error retrieving pages', error)); + } + } + + // public selectedDiv(event) { + // console.info(event.target.value); + // } + + public get form() { + return this._fb.group({ + divId: ['', Validators.required], + content: ['', Validators.required], + isActive: true, + community: '', + _id : '', + }); + } + + public reset() { + this.myForm.patchValue({ + divId: '', + content: '', + isActive: true, + community: '', + _id : '' + }); + this.myForm.markAsPristine(); + } + + handleError(message: string, error) { + this.errorMessage = message; + console.log('Server responded: ' + error); + + this.showLoading = false; + } +} diff --git a/dashboard/divhelpcontent/div-help-content-form.module.ts b/dashboard/divhelpcontent/div-help-content-form.module.ts new file mode 100644 index 00000000..421788a3 --- /dev/null +++ b/dashboard/divhelpcontent/div-help-content-form.module.ts @@ -0,0 +1,20 @@ +import { NgModule } from '@angular/core'; +import {CommonModule} from '@angular/common'; +import {FormsModule, ReactiveFormsModule} from '@angular/forms'; +import {AlertModalModule} from '../../utils/modal/alertModal.module'; +import {SafeHtmlPipeModule} from '../../utils/pipes/safeHTMLPipe.module'; +import {DivContentFormComponent} from './div-help-content-form.component'; +import {CKEditorModule} from 'ng2-ckeditor'; + +@NgModule({ + imports: [ + CommonModule, FormsModule, + SafeHtmlPipeModule, CKEditorModule, + AlertModalModule, ReactiveFormsModule + ], + declarations: [ + DivContentFormComponent + ], + exports: [DivContentFormComponent] +}) +export class DivHelpContentFormModule { } diff --git a/dashboard/divhelpcontent/div-help-contents-routing.module.ts b/dashboard/divhelpcontent/div-help-contents-routing.module.ts new file mode 100644 index 00000000..8fdd7280 --- /dev/null +++ b/dashboard/divhelpcontent/div-help-contents-routing.module.ts @@ -0,0 +1,14 @@ +import { NgModule } from '@angular/core'; +import {RouterModule} from '@angular/router'; +import {IsCommunity} from '../../connect/communityGuard/isCommunity.guard'; +import {ConnectAdminLoginGuard} from '../../connect/communityGuard/connectAdminLoginGuard.guard'; +import {DivHelpContentsComponent} from './div-help-contents.component'; + +@NgModule({ + imports: [ + RouterModule.forChild([ + { path: '', canActivate: [IsCommunity, ConnectAdminLoginGuard], component: DivHelpContentsComponent} + ]) + ] +}) +export class DivHelpContentsRoutingModule { } diff --git a/dashboard/divhelpcontent/div-help-contents.component.html b/dashboard/divhelpcontent/div-help-contents.component.html new file mode 100644 index 00000000..0250a855 --- /dev/null +++ b/dashboard/divhelpcontent/div-help-contents.component.html @@ -0,0 +1,157 @@ +
+
+
+
+
+
+
+ search +
+
+
+
+ + +
+ + + +
+ +
+ + + +
+ +
+ + Enable or disable help text to show or hide it from the dashboard + +
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + +
PageClassContentChange statusActions
+ + +
+ {{page.name}}, +
+
+
{{check.divHelpContent.divId.name}}
+
+ +
{{check.divHelpContent.content}}
+
+ + + +
+ + delete +
+
+
+
+ add +
+
+
+
No class help texts found
+
+
+
+
+ + Go back to {{page.type}} pages +
+
+ +
+
+
+ diff --git a/dashboard/divhelpcontent/div-help-contents.component.ts b/dashboard/divhelpcontent/div-help-contents.component.ts new file mode 100644 index 00000000..c9b771cf --- /dev/null +++ b/dashboard/divhelpcontent/div-help-contents.component.ts @@ -0,0 +1,438 @@ +import {Component, ViewChild, OnInit, ElementRef} from '@angular/core'; +import {Router, ActivatedRoute} from "@angular/router"; +import {FormBuilder, FormControl, FormGroup} from "@angular/forms"; +import {HelpContentService} from "../../services/help-content.service"; +import { + DivHelpContent, + CheckDivHelpContent, + DivHelpContentFilterOptions +} from "../../utils/entities/adminTool/div-help-content"; +import {Page} from "../../utils/entities/adminTool/page"; +import {Community} from "../../utils/entities/adminTool/community"; +import {DivId} from "../../utils/entities/adminTool/divId"; +import {EnvProperties} from '../../utils/properties/env-properties'; + +import {Session} from '../../login/utils/helper.class'; +import {LoginErrorCodes} from '../../login/utils/guardHelper.class'; +import {HelperFunctions} from "../../utils/HelperFunctions.class"; +import {Subscriber} from "rxjs"; + +@Component({ + selector: 'div-help-contents', + templateUrl: './div-help-contents.component.html', +}) + +export class DivHelpContentsComponent implements OnInit { + // @ViewChild('deleteConfirmationModal') + // public deleteConfirmationModal : DeleteConfirmationDialogComponent; + @ViewChild('AlertModalDeleteDivHelpContents') alertModalDeleteDivHelpContents; + private selectedDivContents: string[] = []; + + public checkboxes: CheckDivHelpContent[] = []; + + public divHelpContents: DivHelpContent[] = []; + + //public errorMessage: string; + + public formGroup: FormGroup; + + public pages: Page[]; + + public checkboxAll: boolean = false; + + public filters: DivHelpContentFilterOptions = {id: '', active: null, text: new RegExp('')}; + public keyword: string = ""; + + public counter = {all: 0, active: 0, inactive: 0}; + + public communities: Community[] = []; + + public selectedCommunityPid: string; + + public selectedPageId: string; + + public community: Community; + + public page: Page; + public properties: EnvProperties = null; + + public showLoading: boolean = true; + public errorMessage: string = ''; + public updateErrorMessage: string = ''; + public filterForm: FormControl; + public selectForm: FormControl; + public selectOptions = []; + private subscriptions: any[] = []; + + ngOnInit() { + this.filterForm = this._fb.control(''); + this.selectForm = this._fb.control(''); + this.subscriptions.push(this.filterForm.valueChanges.subscribe(value => { + this.filterBySearch(value); + })); + this.subscriptions.push(this.selectForm.valueChanges.subscribe(value => { + this.filterByPage(value); + })); + + this.route.data + .subscribe((data: { envSpecific: EnvProperties }) => { + this.properties = data.envSpecific; + + this.route.queryParams.subscribe(params => { + HelperFunctions.scroll(); + + this.selectedCommunityPid = params['communityId']; + this.selectedPageId = params['pageId']; + + if (this.selectedCommunityPid && this.selectedPageId) { + this.getPage(this.selectedPageId); + } else if (this.selectedCommunityPid) { + this.selectedPageId = ""; + this.getPages(this.selectedCommunityPid); + } + }); + }); + } + + constructor(private element: ElementRef, private route: ActivatedRoute, private _helpService: HelpContentService, private router: Router, private _fb: FormBuilder) { + } + + ngOnDestroy(): void { + this.subscriptions.forEach(value => { + if (value instanceof Subscriber) { + value.unsubscribe(); + } else if (value instanceof Function) { + value(); + } + }); + } + + getPage(pageId: string) { + if (!Session.isLoggedIn()) { + this.router.navigate(['/user-info'], { + queryParams: { + "errorCode": LoginErrorCodes.NOT_VALID, + "redirectUrl": this.router.url + } + }); + } else { + this.showLoading = true; + this.updateErrorMessage = ""; + this.errorMessage = ""; + + this._helpService.getPage(pageId, this.properties.adminToolsAPIURL).subscribe( + page => { + if ((this.selectedCommunityPid == 'openaire' && !page.openaire) + || (this.selectedCommunityPid == 'connect' && !page.connect) + || (this.selectedCommunityPid != 'openaire' && this.selectedCommunityPid != 'connect' && !page.communities)) { + this.router.navigate(['/classContents'], {queryParams: {"communityId": this.selectedCommunityPid}}); + } else { + this.page = page; + this.getDivHelpContents(this.selectedCommunityPid); + } + }, + error => this.handleError('System error retrieving page', error)); + } + } + + getPages(community_pid: string) { + if (!Session.isLoggedIn()) { + this.router.navigate(['/user-info'], { + queryParams: { + "errorCode": LoginErrorCodes.NOT_VALID, + "redirectUrl": this.router.url + } + }); + } else { + this.showLoading = true; + this.updateErrorMessage = ""; + this.errorMessage = ""; + + this._helpService.getCommunityPagesWithDivId(community_pid, this.properties.adminToolsAPIURL).subscribe( + //this._helpService.getPagesWithDivIds(community_pid, this.properties.adminToolsAPIURL).subscribe( + pages => { + this.pages = pages; + this.getDivHelpContents(this.selectedCommunityPid); + this.selectOptions = [{label:'All pages', value: ''}]; + for (let page of this.pages) { + this.selectOptions.push({label:page.name, value: page._id}) + } + }, + error => this.handleError('System error retrieving pages', error)); + } + } + + public countDivHelpContents() { + this.counter = {all: 0, active: 0, inactive: 0}; + let filter = Object.assign({}, this.filters); + filter.active = null; + this.divHelpContents.forEach(_ => { + if (this.filterDivHelpContent(_, filter)) { + if (_.isActive == true) this.counter.active++; + else this.counter.inactive++ + } + }); + this.counter.all = this.counter.active + this.counter.inactive; + } + + getDivHelpContents(community_pid: string) { + if (!Session.isLoggedIn()) { + this.router.navigate(['/user-info'], { + queryParams: { + "errorCode": LoginErrorCodes.NOT_VALID, + "redirectUrl": this.router.url + } + }); + } else { + this._helpService.getCommunityDivHelpContents(community_pid, this.properties.adminToolsAPIURL).subscribe( + divHelpContents => { + this.divHelpContents = divHelpContents as Array; + this.counter.all = this.divHelpContents.length; + this.checkboxes = []; + + for (let i = this.divHelpContents.length - 1; i >= 0; i -= 1) { + //for (let i = 0; i < this.divHelpContents.length; i++) { + let divId: DivId = this.divHelpContents[i].divId as DivId; + let pages: Page[] = divId.pages as Page[]; + const pageIds = pages.map(x => x._id); + + if (!this.selectedPageId || pageIds.includes(this.selectedPageId)) { + this.cutContent(this.divHelpContents[i]); + this.checkboxes.unshift({divHelpContent: this.divHelpContents[i], checked: false}); + } else { + this.divHelpContents.splice(i, 1); + } + } + + this.countDivHelpContents(); + + this.showLoading = false; + }, + error => this.handleError('System error retrieving page contents', error)); + } + } + + public toggleCheckBoxes(event) { + this.checkboxes.forEach(_ => _.checked = event.target.checked); + this.checkboxAll = event.target.checked; + } + + public applyCheck(flag: boolean) { + this.checkboxes.forEach(_ => _.checked = flag); + this.checkboxAll = false; + } + + public getSelectedDivHelpContents(): string[] { + return this.checkboxes.filter(divHelpContent => divHelpContent.checked == true) + .map(checkedDivHelpContent => checkedDivHelpContent.divHelpContent).map(res => res._id); + } + + public confirmDeleteDivHelpContent(id: string) { + //this.deleteConfirmationModal.ids = [id]; + //this.deleteConfirmationModal.showModal(); + this.selectedDivContents = [id]; + this.confirmModalOpen(); + } + + public confirmDeleteSelectedDivHelpContents() { + //this.deleteConfirmationModal.ids = this.getSelectedDivHelpContents(); + //this.deleteConfirmationModal.showModal(); + this.selectedDivContents = this.getSelectedDivHelpContents(); + this.confirmModalOpen(); + } + + private confirmModalOpen() { + if (!Session.isLoggedIn()) { + this.router.navigate(['/user-info'], { + queryParams: { + "errorCode": LoginErrorCodes.NOT_VALID, + "redirectUrl": this.router.url + } + }); + } else { + this.alertModalDeleteDivHelpContents.cancelButton = true; + this.alertModalDeleteDivHelpContents.okButton = true; + this.alertModalDeleteDivHelpContents.alertTitle = "Delete Confirmation"; + this.alertModalDeleteDivHelpContents.message = "Are you sure you want to delete the help text(s)?"; + this.alertModalDeleteDivHelpContents.okButtonText = "Yes"; + this.alertModalDeleteDivHelpContents.open(); + } + } + + public confirmedDeleteDivHelpContents(data: any) { + if (!Session.isLoggedIn()) { + this.router.navigate(['/user-info'], { + queryParams: { + "errorCode": LoginErrorCodes.NOT_VALID, + "redirectUrl": this.router.url + } + }); + } else { + this.showLoading = true; + this.updateErrorMessage = ""; + + this._helpService.deleteDivHelpContents(this.selectedDivContents, this.properties.adminToolsAPIURL).subscribe( + _ => { + this.deleteDivHelpContentsFromArray(this.selectedDivContents); + this.showLoading = false; + }, + error => this.handleUpdateError('System error deleting the selected class content(s)', error) + ); + } + } + + private deleteDivHelpContentsFromArray(ids: string[]): void { + for (let id of ids) { + let iqc = this.checkboxes.findIndex(_ => _.divHelpContent._id == id); + let iq = this.divHelpContents.findIndex(_ => _._id == id); + this.checkboxes.splice(iqc, 1); + this.divHelpContents.splice(iqc, 1); + } + this.countDivHelpContents(); + } + + public editDivHelpContent(id: string) { + //this.router.navigate(['/pageContents/edit/', _id]); + if (this.selectedPageId) { + this.router.navigate(['/classContents/edit/'], { + queryParams: { + "classContentId": id, + "communityId": this.selectedCommunityPid, + "pageId": this.selectedPageId + } + }); + } else { + this.router.navigate(['/classContents/edit/'], { + queryParams: { + "classContentId": id, + "communityId": this.selectedCommunityPid + } + }); + } + } + + public toggleDivHelpContents(status: boolean, ids: string[]) { + if (!Session.isLoggedIn()) { + this.router.navigate(['/user-info'], { + queryParams: { + "errorCode": LoginErrorCodes.NOT_VALID, + "redirectUrl": this.router.url + } + }); + } else { + this.updateErrorMessage = ""; + + this._helpService.toggleDivHelpContents(ids, status, this.properties.adminToolsAPIURL).subscribe( + () => { + for (let id of ids) { + let i = this.checkboxes.findIndex(_ => _.divHelpContent._id == id); + this.checkboxes[i].divHelpContent.isActive = status; + } + this.countDivHelpContents(); + this.applyCheck(false); + }, + error => this.handleUpdateError('System error changing the status of the selected page content(s)', error) + ); + } + } + + public divHelpContentSavedSuccessfully(divHelpContent: DivHelpContent) { + this.cutContent(divHelpContent); + this.checkboxes.push({divHelpContent: divHelpContent, checked: false}); + this.divHelpContents.push(divHelpContent); + this.applyCheck(false); + this.countDivHelpContents(); + } + + public divHelpContentUpdatedSuccessfully(divHelpContent: DivHelpContent) { + this.checkboxes.find(checkItem => checkItem.divHelpContent._id == divHelpContent._id).divHelpContent = divHelpContent; + let index = this.divHelpContents.findIndex(checkItem => checkItem._id == divHelpContent._id); + this.divHelpContents[index] = divHelpContent; + this.applyCheck(false); + this.countDivHelpContents(); + } + + + public filterDivHelpContent(divHelpContent: DivHelpContent, filters: DivHelpContentFilterOptions): boolean { + let divId: DivId = divHelpContent.divId as DivId; + let pages: Page[] = divId.pages; + let pageIds: string[] = pages.map(x => x._id); + + let idFlag = filters.id == '' || /*(divId.pages)._id == filters.id*/ pageIds.includes(filters.id); + let activeFlag = filters.active == null || divHelpContent.isActive == filters.active; + let textFlag = filters.text.toString() == '' || (divHelpContent.content).match(filters.text) != null + || ((divHelpContent.divId).name).match(filters.text) != null; + return idFlag && activeFlag && textFlag; + } + + public cutContent(divHelpContent: DivHelpContent) { + divHelpContent.content = divHelpContent.content.replace(/<[^>]*>/g, ''); + divHelpContent.content = divHelpContent.content.replace(/(\r\n|\n|\r| +(?= ))|\s\s+/gm, " "); + if (divHelpContent.content.length > 200) { + divHelpContent.content = divHelpContent.content.substr(0, 200) + "..."; + } + } + + public applyFilter() { + this.checkboxes = []; + this.divHelpContents.filter(item => this.filterDivHelpContent(item, this.filters)).forEach( + _ => { + this.cutContent(_); + this.checkboxes.push({divHelpContent: _, checked: false}) + } + ); + this.countDivHelpContents(); + } + + public filterByPage(value: any) { + this.filters.id = value; + this.applyFilter(); + } + + public displayAllDivHelpContents() { + this.filters.active = null; + this.applyFilter(); + } + + public displayActiveDivHelpContents() { + this.filters.active = true; + this.applyFilter(); + } + + public filterBySearch(text: string) { + this.filters.text = new RegExp(text, "i"); + this.applyFilter(); + } + + public displayInactiveDivHelpContents() { + this.filters.active = false; + this.applyFilter(); + } + + handleError(message: string, error) { + this.errorMessage = message; + console.log('Server responded: ' + error); + + this.showLoading = false; + } + + handleUpdateError(message: string, error) { + this.updateErrorMessage = message; + console.log('Server responded: ' + error); + + this.showLoading = false; + } + + public newClassContent() { + if (this.selectedPageId) { + this.router.navigate(['/classContents/new'], { + queryParams: { + communityId: this.selectedCommunityPid, + pageId: this.selectedPageId + } + }); + } else { + this.router.navigate(['/classContents/new'], {queryParams: {communityId: this.selectedCommunityPid}}); + } + } +} diff --git a/dashboard/divhelpcontent/div-help-contents.module.ts b/dashboard/divhelpcontent/div-help-contents.module.ts new file mode 100644 index 00000000..e2d57851 --- /dev/null +++ b/dashboard/divhelpcontent/div-help-contents.module.ts @@ -0,0 +1,26 @@ +import { NgModule } from '@angular/core'; +import {RouterModule} from '@angular/router'; +import {CommonModule} from '@angular/common'; +import {IsCommunity} from '../../connect/communityGuard/isCommunity.guard'; +import {ConnectAdminLoginGuard} from '../../connect/communityGuard/connectAdminLoginGuard.guard'; +import {FormsModule, ReactiveFormsModule} from '@angular/forms'; +import {AlertModalModule} from '../../utils/modal/alertModal.module'; +import {DivHelpContentsRoutingModule} from './div-help-contents-routing.module'; +import {SafeHtmlPipeModule} from '../../utils/pipes/safeHTMLPipe.module'; +import {DivHelpContentsComponent} from './div-help-contents.component'; +import {MatSlideToggleModule} from '@angular/material'; +import {AdminToolServiceModule} from "../../services/adminToolService.module"; +import {InputModule} from "../../../library/sharedComponents/input/input.module"; + +@NgModule({ + imports: [ + CommonModule, RouterModule, FormsModule, SafeHtmlPipeModule, + AlertModalModule, ReactiveFormsModule, DivHelpContentsRoutingModule, MatSlideToggleModule, AdminToolServiceModule, InputModule + ], + declarations: [ + DivHelpContentsComponent + ], + providers: [IsCommunity, ConnectAdminLoginGuard], + exports: [DivHelpContentsComponent] +}) +export class DivHelpContentsModule { } diff --git a/dashboard/divhelpcontent/edit-div-help-content-routing.module.ts b/dashboard/divhelpcontent/edit-div-help-content-routing.module.ts new file mode 100644 index 00000000..9600e158 --- /dev/null +++ b/dashboard/divhelpcontent/edit-div-help-content-routing.module.ts @@ -0,0 +1,14 @@ +import { NgModule } from '@angular/core'; +import {RouterModule} from '@angular/router'; +import {IsCommunity} from '../../connect/communityGuard/isCommunity.guard'; +import {ConnectAdminLoginGuard} from '../../connect/communityGuard/connectAdminLoginGuard.guard'; +import {EditDivHelpContentComponent} from './edit-div-help-content.component'; + +@NgModule({ + imports: [ + RouterModule.forChild([ + { path: '', canActivate: [IsCommunity, ConnectAdminLoginGuard], component: EditDivHelpContentComponent} + ]) + ] +}) +export class EditDivHelpContentRoutingModule { } diff --git a/dashboard/divhelpcontent/edit-div-help-content.component.html b/dashboard/divhelpcontent/edit-div-help-content.component.html new file mode 100644 index 00000000..e2fde7c4 --- /dev/null +++ b/dashboard/divhelpcontent/edit-div-help-content.component.html @@ -0,0 +1,26 @@ +
+
+ + +
+ +
+ + + + + + +
+
+
+
diff --git a/dashboard/divhelpcontent/edit-div-help-content.component.ts b/dashboard/divhelpcontent/edit-div-help-content.component.ts new file mode 100644 index 00000000..b1c50964 --- /dev/null +++ b/dashboard/divhelpcontent/edit-div-help-content.component.ts @@ -0,0 +1,182 @@ +import { Component, ViewChild, OnInit, OnDestroy, ElementRef } from '@angular/core'; +import { DivContentFormComponent } from "./div-help-content-form.component"; +import { Subscription } from "rxjs"; +import { HelpContentService } from "../../services/help-content.service"; +import { DivHelpContent } from "../../utils/entities/adminTool/div-help-content"; +import { ActivatedRoute, Router } from "@angular/router"; +import { EnvProperties } from '../../utils/properties/env-properties'; + +import {Session} from '../../login/utils/helper.class'; +import {LoginErrorCodes} from '../../login/utils/guardHelper.class'; +import {HelperFunctions} from "../../utils/HelperFunctions.class"; +import {Page} from "../../utils/entities/adminTool/page"; + +@Component({ + selector: 'edit-div-help-content', + templateUrl: 'edit-div-help-content.component.html', +}) + +export class EditDivHelpContentComponent implements OnInit, OnDestroy{ + + @ViewChild(DivContentFormComponent) + public formComponent : DivContentFormComponent; + + public communityPid: string; + public pageId: string; + public page: Page; + + private sub: Subscription; + + private divHelpContent: DivHelpContent; + + public properties:EnvProperties = null; + + public showLoading: boolean = true; + public errorMessage: string = ''; + public updateErrorMessage: string = ''; + + constructor( + private element: ElementRef, + private route: ActivatedRoute, + private router: Router, + private _helpContentService: HelpContentService) {} + + ngOnInit() { + this.route.data + .subscribe((data: { envSpecific: EnvProperties }) => { + this.properties = data.envSpecific; + this.sub = this.route.queryParams.subscribe(params => { + HelperFunctions.scroll(); + + //let id = params['id']; + let divContentId = params['classContentId']; + this.communityPid = params['communityId']; + this.pageId = params['pageId']; + + if(!divContentId) { + this.router.navigate(['/classContents'], { queryParams: { "communityId": this.communityPid} }); + } + + this.getDivHelpContent(divContentId); + }); + }); + } + ngOnDestroy() { + this.sub.unsubscribe(); + } + + handleError(message: string, error) { + this.errorMessage = message; + console.log('Server responded: ' + error); + this.showLoading = false; + } + + handleUpdateError(message: string, error) { + this.updateErrorMessage = message; + console.log('Server responded: ' + error); + this.showLoading = false; + } + + private getPage(pageId: string) { + this._helpContentService.getPage(pageId,this.properties.adminToolsAPIURL).subscribe( + page => { + if( (this.communityPid == 'openaire' && !page.openaire) + || (this.communityPid == 'connect' && !page.connect) + || (this.communityPid != 'openaire' && this.communityPid != 'connect' && !page.communities)) { + this.router.navigate(['/classContents'], { queryParams: { "communityId": this.communityPid} }); + } else { + this.page = page; + this.showLoading = false; + } + }, + error => this.handleError('System error retrieving page with id: '+pageId, error) + ); + } + + private getDivHelpContent(divContentId: string) { + if(!Session.isLoggedIn()){ + this.router.navigate(['/user-info'], { queryParams: { "errorCode": LoginErrorCodes.NOT_VALID, "redirectUrl": this.router.url} }); + } else { + this.showLoading = true; + this.errorMessage = ""; + this.updateErrorMessage = ""; + + this._helpContentService.getDivHelpContent(divContentId, this.properties.adminToolsAPIURL).subscribe( + divHelpContent => { + if(this.pageId) { + this.getPage(this.pageId); + } + this.updateForm(divHelpContent); + this.showLoading = false; + }, + error => this.handleError('System error retrieving class help content', error)); + } + } + + getDivId(divId: string) { + if(!Session.isLoggedIn()){ + this.router.navigate(['/user-info'], { queryParams: { "errorCode": LoginErrorCodes.NOT_VALID, "redirectUrl": this.router.url} }); + } else { + this.showLoading = true; + + this._helpContentService.getDivIdFull(divId, this.properties.adminToolsAPIURL).subscribe( + div => { + this.formComponent.selectedDiv = div; + + if(!this.pageId) { + this.formComponent.getDivs(""); + } + + this.showLoading = false; + }, + error => this.handleError('System error retrieving class', error) + ); + } + } + + private updateForm(divHelpContent : DivHelpContent) { + this.divHelpContent = divHelpContent; + + this.getDivId(divHelpContent.divId as string); + + this.formComponent.myForm.patchValue((divHelpContent)); + } + + public saveCustom() { + if(!Session.isLoggedIn()){ + this.router.navigate(['/user-info'], { queryParams: { "errorCode": LoginErrorCodes.NOT_VALID, "redirectUrl": this.router.url} }); + } else { + if(this.formComponent.myForm.valid) { + this.showLoading = true; + this.updateErrorMessage = ""; + + let divHelpContent : DivHelpContent = this.formComponent.myForm.value; + + this._helpContentService.insertOrUpdateDivHelpContent(divHelpContent, this.properties.adminToolsAPIURL).subscribe( + _ => { + if(this.pageId) { + this.router.navigate( ['/classContents/'], { queryParams: { "communityId": this.communityPid, "pageId": this.pageId } } ); + } else { + this.router.navigate(['/classContents'], { queryParams: { "communityId": this.communityPid } } ); + } + this.showLoading = false; + }, + err => this.handleUpdateError('System error updating class content', err) + ); + } else { + this.errorMessage = "Please fill all required fields"; + } + } + } + + public cancelCustom() { + this.errorMessage = ""; + this.updateErrorMessage = ""; + + if(this.pageId) { + this.router.navigate( ['/classContents/'], { queryParams: { "communityId": this.communityPid, "pageId": this.pageId } } ); + } else { + this.router.navigate(['/classContents'], { queryParams: { "communityId": this.communityPid } } ); + } + } +} diff --git a/dashboard/divhelpcontent/edit-div-help-content.module.ts b/dashboard/divhelpcontent/edit-div-help-content.module.ts new file mode 100644 index 00000000..86f44b6b --- /dev/null +++ b/dashboard/divhelpcontent/edit-div-help-content.module.ts @@ -0,0 +1,22 @@ +import {NgModule} from '@angular/core'; +import {RouterModule} from '@angular/router'; +import {CommonModule} from '@angular/common'; +import {IsCommunity} from '../../connect/communityGuard/isCommunity.guard'; +import {ConnectAdminLoginGuard} from '../../connect/communityGuard/connectAdminLoginGuard.guard'; +import {EditDivHelpContentRoutingModule} from './edit-div-help-content-routing.module'; +import {EditDivHelpContentComponent} from './edit-div-help-content.component'; +import {DivHelpContentFormModule} from './div-help-content-form.module'; +import {AdminToolServiceModule} from "../../services/adminToolService.module"; + +@NgModule({ + imports: [ + CommonModule, RouterModule, + DivHelpContentFormModule, EditDivHelpContentRoutingModule, AdminToolServiceModule + ], + declarations: [ + EditDivHelpContentComponent + ], + providers: [IsCommunity, ConnectAdminLoginGuard], + exports: [EditDivHelpContentComponent] +}) +export class EditDivHelpContentModule { } diff --git a/dashboard/divhelpcontent/new-div-help-content-routing.module.ts b/dashboard/divhelpcontent/new-div-help-content-routing.module.ts new file mode 100644 index 00000000..0d38786a --- /dev/null +++ b/dashboard/divhelpcontent/new-div-help-content-routing.module.ts @@ -0,0 +1,14 @@ +import { NgModule } from '@angular/core'; +import {RouterModule} from '@angular/router'; +import {IsCommunity} from '../../connect/communityGuard/isCommunity.guard'; +import {ConnectAdminLoginGuard} from '../../connect/communityGuard/connectAdminLoginGuard.guard'; +import {NewDivHelpContentComponent} from './new-div-help-content.component'; + +@NgModule({ + imports: [ + RouterModule.forChild([ + { path: '', canActivate: [IsCommunity, ConnectAdminLoginGuard], component: NewDivHelpContentComponent} + ]) + ] +}) +export class NewDivHelpContentRoutingModule { } diff --git a/dashboard/divhelpcontent/new-div-help-content.component.html b/dashboard/divhelpcontent/new-div-help-content.component.html new file mode 100644 index 00000000..23e25058 --- /dev/null +++ b/dashboard/divhelpcontent/new-div-help-content.component.html @@ -0,0 +1,32 @@ +
+
+ +
+
+ + +
+ +
+ + + + + + +
+
+
+
+
+
diff --git a/dashboard/divhelpcontent/new-div-help-content.component.ts b/dashboard/divhelpcontent/new-div-help-content.component.ts new file mode 100644 index 00000000..33003e63 --- /dev/null +++ b/dashboard/divhelpcontent/new-div-help-content.component.ts @@ -0,0 +1,125 @@ +import { Component, ViewChild, ElementRef } from '@angular/core'; +import { ActivatedRoute, Router } from "@angular/router"; +import { DivContentFormComponent } from "./div-help-content-form.component"; +import { DivHelpContent } from "../../utils/entities/adminTool/div-help-content"; +import { HelpContentService } from "../../services/help-content.service"; +import { EnvProperties } from '../../utils/properties/env-properties'; + +import {Session} from '../../login/utils/helper.class'; +import {LoginErrorCodes} from '../../login/utils/guardHelper.class'; +import {HelperFunctions} from "../../utils/HelperFunctions.class"; +import {Page} from "../../utils/entities/adminTool/page"; + +@Component({ + selector: 'new-div-help-content', + templateUrl: 'new-div-help-content.component.html', +}) + +export class NewDivHelpContentComponent { + + @ViewChild(DivContentFormComponent) + public formComponent : DivContentFormComponent; + + //private errorMessage : string = null; + + public communityPid: string; + + public pageId: string; + public page: Page; + + public properties:EnvProperties = null; + + public showLoading: boolean = true; + public errorMessage: string = ''; + public updateErrorMessage: string = ''; + + constructor( + private element: ElementRef, + private route: ActivatedRoute, + private router: Router, + private _helpContentService: HelpContentService) {} + + ngOnInit() { + this.route.data + .subscribe((data: { envSpecific: EnvProperties }) => { + this.properties = data.envSpecific; + this.route.queryParams.subscribe(params => { + HelperFunctions.scroll(); + + this.communityPid = params['communityId']; + this.pageId = params['pageId']; + + + if(this.pageId) { + this.getPage(this.pageId); + } else { + this.showLoading = false; + } + }); + }); + } + + private getPage(pageId: string) { + this._helpContentService.getPage(pageId,this.properties.adminToolsAPIURL).subscribe( + page => { + if( (this.communityPid == 'openaire' && !page.openaire) + || (this.communityPid == 'connect' && !page.connect) + || (this.communityPid != 'openaire' && this.communityPid != 'connect' && !page.communities)) { + this.router.navigate(['/classContents'], { queryParams: { "communityId": this.communityPid} }); + } else { + this.page = page; + this.showLoading = false; + console.info(this.page); + } + }, + error => this.handleError('System error retrieving page with id: '+pageId, error) + ); + } + + public saveCustom() { + if(!Session.isLoggedIn()){ + this.router.navigate(['/user-info'], { queryParams: { "errorCode": LoginErrorCodes.NOT_VALID, "redirectUrl": this.router.url} }); + } else { + if(this.formComponent.myForm.valid) { + this.showLoading = true; + this.updateErrorMessage = ""; + + let divHelpContent : DivHelpContent = this.formComponent.myForm.value; + + this._helpContentService.insertOrUpdateDivHelpContent(divHelpContent, this.properties.adminToolsAPIURL).subscribe( + _ => { + if(this.pageId) { + this.router.navigate( ['/classContents/'], { queryParams: { "communityId": this.communityPid, "pageId": this.pageId } } ); + } else { + this.router.navigate(['/classContents'], { queryParams: { "communityId": this.communityPid } } ); + } + this.showLoading = false; + }, + err => this.handleUpdateError('System error saving page content', err) + ); + } else { + this.errorMessage = "Please fill all required fields"; + } + } + } + + public cancelCustom() { + if(this.pageId) { + this.router.navigate( ['/classContents/'], { queryParams: { "communityId": this.communityPid, "pageId": this.pageId } } ); + } else { + this.router.navigate(['/classContents'], { queryParams: { "communityId": this.communityPid } } ); + } + } + + handleUpdateError(message: string, error) { + this.errorMessage = message; + console.log('Server responded: ' + error); + this.showLoading = false; + } + + handleError(message: string, error) { + this.errorMessage = message; + console.log('Server responded: ' + error); + this.showLoading = false; + } +} diff --git a/dashboard/divhelpcontent/new-div-help-content.module.ts b/dashboard/divhelpcontent/new-div-help-content.module.ts new file mode 100644 index 00000000..8f03ef8d --- /dev/null +++ b/dashboard/divhelpcontent/new-div-help-content.module.ts @@ -0,0 +1,22 @@ +import { NgModule } from '@angular/core'; +import {RouterModule} from '@angular/router'; +import {CommonModule} from '@angular/common'; +import {IsCommunity} from '../../connect/communityGuard/isCommunity.guard'; +import {ConnectAdminLoginGuard} from '../../connect/communityGuard/connectAdminLoginGuard.guard'; +import {NewDivHelpContentRoutingModule} from './new-div-help-content-routing.module'; +import {NewDivHelpContentComponent} from './new-div-help-content.component'; +import {DivHelpContentFormModule} from './div-help-content-form.module'; +import {AdminToolServiceModule} from "../../services/adminToolService.module"; + +@NgModule({ + imports: [ + CommonModule, RouterModule, + DivHelpContentFormModule, NewDivHelpContentRoutingModule, AdminToolServiceModule + ], + declarations: [ + NewDivHelpContentComponent + ], + providers: [IsCommunity, ConnectAdminLoginGuard], + exports: [NewDivHelpContentComponent] +}) +export class NewDivHelpContentModule { } diff --git a/dashboard/entity/entities.component.ts b/dashboard/entity/entities.component.ts index 12682a64..e681dbcc 100644 --- a/dashboard/entity/entities.component.ts +++ b/dashboard/entity/entities.component.ts @@ -196,9 +196,9 @@ export class EntitiesComponent implements OnInit { public editEntity(i: number) { const entity: Entity = this.checkboxes[i].entity; this.myForm = this._fb.group({ - name: entity.name, + name: [entity.name, Validators.required], _id: entity._id, - pid: entity.pid + pid: [entity.pid, Validators.required], }); this.modalErrorMessage = ''; this.entitiesModalOpen(this.alertModalSaveEntity, '', 'Save Changes'); diff --git a/dashboard/helpTexts/edit-page-help-content-routing.module.ts b/dashboard/helpTexts/edit-page-help-content-routing.module.ts new file mode 100644 index 00000000..9d61365b --- /dev/null +++ b/dashboard/helpTexts/edit-page-help-content-routing.module.ts @@ -0,0 +1,14 @@ +import { NgModule } from '@angular/core'; +import {RouterModule} from '@angular/router'; +import {IsCommunity} from '../../connect/communityGuard/isCommunity.guard'; +import {ConnectAdminLoginGuard} from '../../connect/communityGuard/connectAdminLoginGuard.guard'; +import {EditPageHelpContentComponent} from './edit-page-help-content.component'; + +@NgModule({ + imports: [ + RouterModule.forChild([ + { path: '', canActivate: [IsCommunity, ConnectAdminLoginGuard], component: EditPageHelpContentComponent} + ]) + ] +}) +export class EditPageHelpContentRoutingModule { } diff --git a/dashboard/helpTexts/edit-page-help-content.component.html b/dashboard/helpTexts/edit-page-help-content.component.html new file mode 100644 index 00000000..7394f4be --- /dev/null +++ b/dashboard/helpTexts/edit-page-help-content.component.html @@ -0,0 +1,30 @@ +
+ +
+
+ + +
+ +
+ + + + + + +
+
+
+
+
diff --git a/dashboard/helpTexts/edit-page-help-content.component.ts b/dashboard/helpTexts/edit-page-help-content.component.ts new file mode 100644 index 00000000..fbaf981f --- /dev/null +++ b/dashboard/helpTexts/edit-page-help-content.component.ts @@ -0,0 +1,164 @@ +import { Component, ViewChild, OnInit, OnDestroy, ElementRef } from '@angular/core'; +import { PageContentFormComponent } from "./page-help-content-form.component"; +import { Subscription } from "rxjs"; +import { HelpContentService } from "../../services/help-content.service"; +import { PageHelpContent } from "../../utils/entities/adminTool/page-help-content"; +import { ActivatedRoute, Router } from "@angular/router"; +import { EnvProperties } from '../../utils/properties/env-properties'; + +import {Session} from '../../login/utils/helper.class'; +import {LoginErrorCodes} from '../../login/utils/guardHelper.class'; +import {HelperFunctions} from "../../utils/HelperFunctions.class"; +import {Page} from "../../utils/entities/adminTool/page"; + +@Component({ + selector: 'edit-page-help-content', + templateUrl: 'edit-page-help-content.component.html', +}) + +export class EditPageHelpContentComponent implements OnInit, OnDestroy{ + + @ViewChild(PageContentFormComponent) + public formComponent : PageContentFormComponent; + + public communityPid: string; + + public pageId: string; + public page: Page; + + private sub: Subscription; + + private pageHelpContent: PageHelpContent; + + //private errorMessage : string = null; + public properties:EnvProperties = null; + + public showLoading: boolean = true; + public errorMessage: string = ''; + public updateErrorMessage: string = ''; + + constructor( + private element: ElementRef, + private route: ActivatedRoute, + private router: Router, + private _helpContentService: HelpContentService) {} + + ngOnInit() { + this.route.data + .subscribe((data: { envSpecific: EnvProperties }) => { + this.properties = data.envSpecific; + this.sub = this.route.queryParams.subscribe(params => { + HelperFunctions.scroll(); + + let pageContentId = params['pageContentId']; + this.communityPid = params['communityId']; + this.pageId = params['pageId']; + + if(!pageContentId) { + this.router.navigate(['/pageContents'], { queryParams: { "communityId": this.communityPid} }); + } + + this.getPageHelpContent(pageContentId); + }); + }); + } + ngOnDestroy() { + this.sub.unsubscribe(); + } + + handleError(message: string, error) { + this.errorMessage = message; + console.log('Server responded: ' + error); + this.showLoading = false; + } + + handleUpdateError(message: string, error) { + this.updateErrorMessage = message; + console.log('Server responded: ' + error); + this.showLoading = false; + } + + private getPage(pageId: string) { + this._helpContentService.getPage(pageId,this.properties.adminToolsAPIURL).subscribe( + page => { + if( (this.communityPid == 'openaire' && !page.openaire) + || (this.communityPid == 'connect' && !page.connect) + || (this.communityPid != 'openaire' && this.communityPid != 'connect' && !page.communities)) { + this.router.navigate(['/pageContents'], { queryParams: { "communityId": this.communityPid} }); + } else { + this.page = page; + this.formComponent.setPlacements(this.page); + this.showLoading = false; + } + }, + error => this.handleError('System error retrieving page with id: '+pageId, error) + ); + } + + private getPageHelpContent(pageContentId: string) { + if(!Session.isLoggedIn()){ + this.router.navigate(['/user-info'], { queryParams: { "errorCode": LoginErrorCodes.NOT_VALID, "redirectUrl": this.router.url} }); + } else { + this.showLoading = true; + this.errorMessage = ""; + this.updateErrorMessage = ""; + + this._helpContentService.getPageHelpContent(pageContentId as string, this.properties.adminToolsAPIURL).subscribe( + pageHelpContent => { + if(this.pageId && this.pageId != pageHelpContent.page) { + this.router.navigate(['/pageContents'], { queryParams: { "communityId": this.communityPid} }); + } else if(this.pageId) { + this.getPage(this.pageId); + } else { + this.getPage(pageHelpContent.page); + } + this.updateForm(pageHelpContent); + //this.showLoading = false; + }, + error => this.handleError('System error retrieving page help content', error)); + } + } + + private updateForm(pageHelpContent : PageHelpContent) { + this.pageHelpContent = pageHelpContent; + this.formComponent.myForm.patchValue((pageHelpContent)); + // console.log("patching",pageHelpContent); + } + + public saveCustom() { + if(!Session.isLoggedIn()){ + this.router.navigate(['/user-info'], { queryParams: { "errorCode": LoginErrorCodes.NOT_VALID, "redirectUrl": this.router.url} }); + } else { + if(this.formComponent.myForm.valid) { + this.showLoading = true; + this.updateErrorMessage = ""; + + let pageHelpContent : PageHelpContent = this.formComponent.myForm.value; + this._helpContentService.updatePageHelpContent(pageHelpContent, this.properties.adminToolsAPIURL).subscribe( + _ => { + if(this.pageId) { + this.router.navigate( ['/pageContents/'], { queryParams: { "communityId": this.communityPid, "pageId": this.pageId } } ); + } else { + this.router.navigate(['/pageContents'], { queryParams: { "communityId": this.communityPid} } ); + } + this.showLoading = false; + }, + err => this.handleUpdateError('System error updating page content', err) + ); + } else { + this.errorMessage = "Please fill all required fields"; + } + } + } + + public cancelCustom() { + this.errorMessage = ""; + this.updateErrorMessage = ""; + + if(this.pageId) { + this.router.navigate( ['/helptexts/'], { queryParams: { "communityId": this.communityPid, "pageId": this.pageId } } ); + } else { + this.router.navigate(['/helptexts'], { queryParams: { "communityId": this.communityPid} } ); + } + } +} diff --git a/dashboard/helpTexts/edit-page-help-content.module.ts b/dashboard/helpTexts/edit-page-help-content.module.ts new file mode 100644 index 00000000..bbef4e1d --- /dev/null +++ b/dashboard/helpTexts/edit-page-help-content.module.ts @@ -0,0 +1,22 @@ +import { NgModule } from '@angular/core'; +import {RouterModule} from '@angular/router'; +import {CommonModule} from '@angular/common'; +import {IsCommunity} from '../../connect/communityGuard/isCommunity.guard'; +import {ConnectAdminLoginGuard} from '../../connect/communityGuard/connectAdminLoginGuard.guard'; +import {EditPageHelpContentRoutingModule} from './edit-page-help-content-routing.module'; +import {EditPageHelpContentComponent} from './edit-page-help-content.component'; +import {PageHelpContentFormModule} from './page-help-content-form.module'; +import {AdminToolServiceModule} from "../../services/adminToolService.module"; + +@NgModule({ + imports: [ + CommonModule, RouterModule, + PageHelpContentFormModule, EditPageHelpContentRoutingModule, AdminToolServiceModule + ], + declarations: [ + EditPageHelpContentComponent + ], + providers: [IsCommunity, ConnectAdminLoginGuard], + exports: [EditPageHelpContentComponent] +}) +export class EditPageHelpContentModule { } diff --git a/dashboard/helpTexts/new-page-help-content-routing.module.ts b/dashboard/helpTexts/new-page-help-content-routing.module.ts new file mode 100644 index 00000000..92898003 --- /dev/null +++ b/dashboard/helpTexts/new-page-help-content-routing.module.ts @@ -0,0 +1,14 @@ +import { NgModule } from '@angular/core'; +import {RouterModule} from '@angular/router'; +import {IsCommunity} from '../../connect/communityGuard/isCommunity.guard'; +import {ConnectAdminLoginGuard} from '../../connect/communityGuard/connectAdminLoginGuard.guard'; +import {NewPageHelpContentComponent} from './new-page-help-content.component'; + +@NgModule({ + imports: [ + RouterModule.forChild([ + { path: '', canActivate: [IsCommunity, ConnectAdminLoginGuard], component: NewPageHelpContentComponent} + ]) + ] +}) +export class NewPageHelpContentRoutingModule { } diff --git a/dashboard/helpTexts/new-page-help-content.component.html b/dashboard/helpTexts/new-page-help-content.component.html new file mode 100644 index 00000000..da8098ff --- /dev/null +++ b/dashboard/helpTexts/new-page-help-content.component.html @@ -0,0 +1,31 @@ +
+ +
+
+ + +
+ +
+ + + + + + + +
+
+
+
+
diff --git a/dashboard/helpTexts/new-page-help-content.component.ts b/dashboard/helpTexts/new-page-help-content.component.ts new file mode 100644 index 00000000..7a672667 --- /dev/null +++ b/dashboard/helpTexts/new-page-help-content.component.ts @@ -0,0 +1,128 @@ +import { Component, ViewChild, ElementRef } from '@angular/core'; +import { ActivatedRoute, Router } from "@angular/router"; +import { PageContentFormComponent } from "./page-help-content-form.component"; +import { PageHelpContent } from "../../utils/entities/adminTool/page-help-content"; +import { HelpContentService } from "../../services/help-content.service"; +import { EnvProperties } from '../../utils/properties/env-properties'; + +import {Session} from '../../login/utils/helper.class'; +import {LoginErrorCodes} from '../../login/utils/guardHelper.class'; +import {HelperFunctions} from "../../utils/HelperFunctions.class"; +import {Page} from "../../utils/entities/adminTool/page"; + +@Component({ + selector: 'new-page-help-content', + templateUrl: 'new-page-help-content.component.html', +}) + +export class NewPageHelpContentComponent { + + @ViewChild(PageContentFormComponent) + public formComponent : PageContentFormComponent; + + //private errorMessage : string = null; + + public communityPid: string; + + public pageId: string; + public page: Page; + + public properties:EnvProperties = null; + + public showLoading: boolean = true; + public errorMessage: string = ''; + public updateErrorMessage: string = ''; + + constructor( + private element: ElementRef, + private route: ActivatedRoute, + private router: Router, + private _helpContentService: HelpContentService) {} + + ngOnInit() { + this.route.data + .subscribe((data: { envSpecific: EnvProperties }) => { + this.properties = data.envSpecific; + this.route.queryParams.subscribe(params => { + HelperFunctions.scroll(); + + this.communityPid = params['communityId']; + this.pageId = params['pageId']; + + if(this.pageId) { + this.getPage(this.pageId); + } else { + this.showLoading = false; + } + }); + }); + } + + private getPage(pageId: string) { + this._helpContentService.getPage(pageId,this.properties.adminToolsAPIURL).subscribe( + page => { + if( (this.communityPid == 'openaire' && !page.openaire) + || (this.communityPid == 'connect' && !page.connect) + || (this.communityPid != 'openaire' && this.communityPid != 'connect' && !page.communities)) { + this.router.navigate(['/pageContents'], { queryParams: { "communityId": this.communityPid} }); + } else { + this.page = page; + this.formComponent.setPlacements(this.page); + this.showLoading = false; + console.info(this.page); + } + }, + error => this.handleError('System error retrieving page with id: '+pageId, error) + ); + } + + public saveCustom() { + if(!Session.isLoggedIn()){ + this.router.navigate(['/user-info'], { queryParams: { "errorCode": LoginErrorCodes.NOT_VALID, "redirectUrl": this.router.url} }); + } else { + //this.errorMessage = null; + + if(this.formComponent.myForm.valid) { + this.showLoading = true; + this.updateErrorMessage = ""; + + let pageHelpContent : PageHelpContent = this.formComponent.myForm.value; + + this._helpContentService.savePageHelpContent(pageHelpContent, this.properties.adminToolsAPIURL).subscribe( + _ => { + if(this.pageId) { + this.router.navigate( ['/helptexts/'], { queryParams: { "communityId": this.communityPid, "pageId": this.pageId } } ); + } else { + this.router.navigate(['/helptexts'], { queryParams: { "communityId": this.communityPid} }); + } + this.showLoading = false; + }, + err => this.handleUpdateError('System error saving page content', err) + ); + } else { + this.errorMessage = "Please fill all required fields"; + } + } + } + + public cancelCustom() { + if(this.pageId) { + this.router.navigate( ['/helptexts/'], { queryParams: { "communityId": this.communityPid, "pageId": this.pageId } } ); + } else { + this.router.navigate(['/helptexts'], { queryParams: { "communityId": this.communityPid} } ); + } + } + + handleUpdateError(message: string, error) { + this.updateErrorMessage = message; + console.log('Server responded: ' + error); + + this.showLoading = false; + } + + handleError(message: string, error) { + this.errorMessage = message; + console.log('Server responded: ' + error); + this.showLoading = false; + } +} diff --git a/dashboard/helpTexts/new-page-help-content.module.ts b/dashboard/helpTexts/new-page-help-content.module.ts new file mode 100644 index 00000000..11a286d2 --- /dev/null +++ b/dashboard/helpTexts/new-page-help-content.module.ts @@ -0,0 +1,22 @@ +import { NgModule } from '@angular/core'; +import {RouterModule} from '@angular/router'; +import {CommonModule} from '@angular/common'; +import {IsCommunity} from '../../connect/communityGuard/isCommunity.guard'; +import {ConnectAdminLoginGuard} from '../../connect/communityGuard/connectAdminLoginGuard.guard'; +import {NewPageHelpContentComponent} from './new-page-help-content.component'; +import {NewPageHelpContentRoutingModule} from './new-page-help-content-routing.module'; +import {PageHelpContentFormModule} from './page-help-content-form.module'; +import {AdminToolServiceModule} from "../../services/adminToolService.module"; + +@NgModule({ + imports: [ + CommonModule, RouterModule, + PageHelpContentFormModule, NewPageHelpContentRoutingModule, AdminToolServiceModule + ], + declarations: [ + NewPageHelpContentComponent + ], + providers: [IsCommunity, ConnectAdminLoginGuard], + exports: [NewPageHelpContentComponent] +}) +export class NewPageHelpContentModule { } diff --git a/dashboard/helpTexts/page-help-content-form.component.html b/dashboard/helpTexts/page-help-content-form.component.html new file mode 100644 index 00000000..1106e65f --- /dev/null +++ b/dashboard/helpTexts/page-help-content-form.component.html @@ -0,0 +1,82 @@ + + + +
+ + Create or edit help text +
+ Select the page to be displayed, select position of the page +
+ +
+
+
+ + +
+
+ + +
+
+ +
+ + + + + + + + + + + + +
+ + +
+
+ + +
+ +
+ + +
+ +
+ + + + diff --git a/dashboard/helpTexts/page-help-content-form.component.ts b/dashboard/helpTexts/page-help-content-form.component.ts new file mode 100644 index 00000000..9ec3c3d5 --- /dev/null +++ b/dashboard/helpTexts/page-help-content-form.component.ts @@ -0,0 +1,107 @@ +import { Component, OnInit, Input } from '@angular/core'; +import { ActivatedRoute, Router } from "@angular/router"; +import { FormGroup, FormBuilder, Validators } from "@angular/forms"; +import { Page } from "../../utils/entities/adminTool/page"; +import { HelpContentService } from "../../services/help-content.service"; +import { EnvProperties } from '../../utils/properties/env-properties'; + +import {Session} from '../../login/utils/helper.class'; +import {LoginErrorCodes} from '../../login/utils/guardHelper.class'; + +@Component({ + selector: 'page-content-form', + templateUrl: './page-help-content-form.component.html', +}) + +export class PageContentFormComponent implements OnInit{ + + @Input('group') + myForm: FormGroup; + @Input('communityPid') + communityPid: string; + @Input('pageId') + pageId: string; + @Input('page') + page: Page; + placements = {"top": false, "bottom": false, "left": false, "right": false} + + private availablePages : Page[] = []; + //private errorMessage: string; + + private ckeditorContent : string; + public properties:EnvProperties = null; + + public showLoading: boolean = true; + public errorMessage: string = ''; + @Input() updateErrorMessage: string = ''; + + constructor(private route: ActivatedRoute, private _router: Router, private _fb: FormBuilder, private _helpContentService: HelpContentService){} + + ngOnInit() { + this.myForm = this.form; + this.route.data + .subscribe((data: { envSpecific: EnvProperties }) => { + this.properties = data.envSpecific; + + if(!Session.isLoggedIn()){ + this._router.navigate(['/user-info'], { queryParams: { "errorCode": LoginErrorCodes.NOT_VALID, "redirectUrl": this._router.url} }); + } else { + if(!this.pageId) { + this.myForm.valueChanges.subscribe(value => { + let pageId = value.page; + this._helpContentService.getPage(pageId, this.properties.adminToolsAPIURL).subscribe(page => { + this.setPlacements(page); + }); + }); + } + this._helpContentService.getPages(this.properties.adminToolsAPIURL, this.communityPid, true).subscribe( + pages => { + this.availablePages = pages; + this.showLoading = false; + }, + error => this.handleError('System error retrieving pages', error)); + } + }); + } + + public setPlacements(page: Page) { + this.placements.top = page.top; + this.placements.bottom = page.bottom; + this.placements.left = page.left; + this.placements.right = page.right; + } + + public get form() { + return this._fb.group({ + page : [this.pageId, Validators.required], + community : this.communityPid, + placement : ['', Validators.required], + content : ['', Validators.required], + order : [1, Validators.required], + isActive : true, + //isPriorTo : false, + _id : '', + }); + } + + public reset() { + this.myForm.patchValue({ + page : '', + community : this.communityPid, + placement : '', + content : [''], + order : 1, + isActive : true, + //isPriorTo : false, + _id : '' + }); + this.myForm.markAsPristine(); + } + + handleError(message: string, error) { + this.errorMessage = message; + console.log('Server responded: ' + error); + + this.showLoading = false; + } +} diff --git a/dashboard/helpTexts/page-help-content-form.module.ts b/dashboard/helpTexts/page-help-content-form.module.ts new file mode 100644 index 00000000..66ce8814 --- /dev/null +++ b/dashboard/helpTexts/page-help-content-form.module.ts @@ -0,0 +1,20 @@ +import { NgModule } from '@angular/core'; +import {CommonModule} from '@angular/common'; +import {FormsModule, ReactiveFormsModule} from '@angular/forms'; +import {AlertModalModule} from '../../utils/modal/alertModal.module'; +import {SafeHtmlPipeModule} from '../../utils/pipes/safeHTMLPipe.module'; +import {CKEditorModule} from 'ng2-ckeditor'; +import {PageContentFormComponent} from './page-help-content-form.component'; + +@NgModule({ + imports: [ + CommonModule, FormsModule, + SafeHtmlPipeModule, CKEditorModule, + AlertModalModule, ReactiveFormsModule + ], + declarations: [ + PageContentFormComponent + ], + exports: [PageContentFormComponent] +}) +export class PageHelpContentFormModule { } diff --git a/dashboard/helpTexts/page-help-contents-routing.module.ts b/dashboard/helpTexts/page-help-contents-routing.module.ts new file mode 100644 index 00000000..734aca2d --- /dev/null +++ b/dashboard/helpTexts/page-help-contents-routing.module.ts @@ -0,0 +1,14 @@ +import { NgModule } from '@angular/core'; +import {RouterModule} from '@angular/router'; +import {IsCommunity} from '../../connect/communityGuard/isCommunity.guard'; +import {ConnectAdminLoginGuard} from '../../connect/communityGuard/connectAdminLoginGuard.guard'; +import {PageHelpContentsComponent} from './page-help-contents.component'; + +@NgModule({ + imports: [ + RouterModule.forChild([ + { path: '', canActivate: [IsCommunity, ConnectAdminLoginGuard], component: PageHelpContentsComponent} + ]) + ] +}) +export class PageHelpContentsRoutingModule { } diff --git a/dashboard/helpTexts/page-help-contents.component.html b/dashboard/helpTexts/page-help-contents.component.html new file mode 100644 index 00000000..00a6b4f3 --- /dev/null +++ b/dashboard/helpTexts/page-help-contents.component.html @@ -0,0 +1,166 @@ +
+
+
+
+
+
+
+ search +
+
+
+
+ + +
+
+ +
+ + + + +

+ Page help texts + Page help texts of page '{{page.name}}' +

+
+
+
+ + {{updateErrorMessage}} +
+ + +
+
+
+ + + + +
+
+ + Enable or disable help text to show or hide it from the dashboard + +
+ +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ PageCommunityContentPlacementOrderChange statusActions
+ +
{{check.pageHelpContent.page.name}}
+
+
{{check.pageHelpContent.community.name}}
+
+ +
{{check.pageHelpContent.content}}
+
+
{{check.pageHelpContent.placement}}
+
+
{{check.pageHelpContent.order}} +
+
+ + + + + + + +
+ + delete +
+
+ +
+
No page contents found
+
+
+
+ add +
+
+
+
+
+ + + Go back to {{page.type}} pages +
+
+
+
+ +
+ + + diff --git a/dashboard/helpTexts/page-help-contents.component.ts b/dashboard/helpTexts/page-help-contents.component.ts new file mode 100644 index 00000000..80a75c85 --- /dev/null +++ b/dashboard/helpTexts/page-help-contents.component.ts @@ -0,0 +1,431 @@ +import {Component, ViewChild, OnInit, ElementRef} from '@angular/core'; +import {FormBuilder, FormControl, FormGroup} from "@angular/forms"; +import {ActivatedRoute, Router} from "@angular/router"; +import {HelpContentService} from "../../services/help-content.service"; +import { + PageHelpContent, + CheckPageHelpContent, + PageHelpContentFilterOptions +} from "../../utils/entities/adminTool/page-help-content"; +import {Page} from "../../utils/entities/adminTool/page"; +import {Community} from "../../utils/entities/adminTool/community"; +import {EnvProperties} from '../../utils/properties/env-properties'; +import {Session} from '../../login/utils/helper.class'; +import {LoginErrorCodes} from '../../login/utils/guardHelper.class'; +import {HelperFunctions} from "../../utils/HelperFunctions.class"; +import {Subscriber} from "rxjs"; + +@Component({ + selector: 'page-help-contents', + templateUrl: './page-help-contents.component.html', +}) + +export class PageHelpContentsComponent implements OnInit { + + @ViewChild('AlertModalDeletePageHelpContents') alertModalDeletePageHelpContents; + private selectedPageContents: string[] = []; + + public checkboxes: CheckPageHelpContent[] = []; + + public pageHelpContents: PageHelpContent[] = []; + + public formGroup: FormGroup; + + public pages: Page[]; + + public checkboxAll: boolean = false; + + public filters: PageHelpContentFilterOptions = {id: '', active: null, text: new RegExp('')}; + public keyword: string = ""; + + public counter = {all: 0, active: 0, inactive: 0}; + + public communities: Community[] = []; + + public selectedCommunityPid: string; + + public selectedPageId: string; + + public community: Community; + + public page: Page; + public properties: EnvProperties = null; + + public showLoading: boolean = true; + public errorMessage: string = ''; + public updateErrorMessage: string = ''; + public filterForm: FormControl; + public selectForm: FormControl; + public selectOptions = []; + private subscriptions: any[] = []; + + ngOnInit() { + this.filterForm = this._fb.control(''); + this.selectForm = this._fb.control(''); + this.subscriptions.push(this.filterForm.valueChanges.subscribe(value => { + this.filterBySearch(value); + })); + this.subscriptions.push(this.selectForm.valueChanges.subscribe(value => { + this.filterByPage(value); + })); + this.route.data + .subscribe((data: { envSpecific: EnvProperties }) => { + this.properties = data.envSpecific; + this.route.queryParams.subscribe(params => { + HelperFunctions.scroll(); + + this.selectedCommunityPid = params['communityId']; + this.selectedPageId = params['pageId']; + + if (this.selectedCommunityPid && this.selectedPageId) { + this.getPage(this.selectedPageId); + } else if (this.selectedCommunityPid) { + this.selectedPageId = ""; + this.getPages(this.selectedCommunityPid); + } + }); + }); + // this.myForm = this.formComponent.form; + } + + constructor(private element: ElementRef, private route: ActivatedRoute, private router: Router, private _helpService: HelpContentService, private _fb: FormBuilder) { + } + ngOnDestroy(): void { + this.subscriptions.forEach(value => { + if (value instanceof Subscriber) { + value.unsubscribe(); + } else if (value instanceof Function) { + value(); + } + }); + } + getPage(pageId: string) { + if (!Session.isLoggedIn()) { + this.router.navigate(['/user-info'], { + queryParams: { + "errorCode": LoginErrorCodes.NOT_VALID, + "redirectUrl": this.router.url + } + }); + } else { + this.showLoading = true; + this.updateErrorMessage = ""; + this.errorMessage = ""; + + this._helpService.getPage(pageId, this.properties.adminToolsAPIURL).subscribe( + page => { + if ((this.selectedCommunityPid == 'openaire' && !page.openaire) + || (this.selectedCommunityPid == 'connect' && !page.connect) + || (this.selectedCommunityPid != 'openaire' && this.selectedCommunityPid != 'connect' && !page.communities)) { + this.router.navigate(['/pageContents'], {queryParams: {"communityId": this.selectedCommunityPid}}); + } else { + this.page = page; + this.getPageHelpContents(this.selectedCommunityPid); + } + }, + error => this.handleError('System error retrieving page', error)); + } + } + + getPages(community_pid: string) { + if (!Session.isLoggedIn()) { + this.router.navigate(['/user-info'], { + queryParams: { + "errorCode": LoginErrorCodes.NOT_VALID, + "redirectUrl": this.router.url + } + }); + } else { + this.showLoading = true; + this.updateErrorMessage = ""; + this.errorMessage = ""; + + //this._helpService.getCommunityPages(community_pid, "", this.properties.adminToolsAPIURL).subscribe( + this._helpService.getPages(this.properties.adminToolsAPIURL, community_pid, true).subscribe( + pages => { + this.pages = pages; + this.getPageHelpContents(this.selectedCommunityPid); + this.selectOptions = [{label:'All pages', value: ''}]; + for (let page of this.pages) { + this.selectOptions.push({label:page.name, value: page._id}) + } + }, + error => this.handleError('System error retrieving pages', error)); + } + } + + public countPageHelpContents() { + this.counter = {all: 0, active: 0, inactive: 0}; + let filter = Object.assign({}, this.filters); + filter.active = null; + this.pageHelpContents.forEach(_ => { + if (this.filterPageHelpContent(_, filter)) { + if (_.isActive == true) this.counter.active++; + else this.counter.inactive++ + } + }); + this.counter.all = this.counter.active + this.counter.inactive; + } + + getPageHelpContents(community_pid: string) { + if (!Session.isLoggedIn()) { + this.router.navigate(['/user-info'], { + queryParams: { + "errorCode": LoginErrorCodes.NOT_VALID, + "redirectUrl": this.router.url + } + }); + } else { + this._helpService.getCommunityPageHelpContents(community_pid, this.properties.adminToolsAPIURL).subscribe( + pageHelpContents => { + this.pageHelpContents = pageHelpContents as Array; + this.counter.all = this.pageHelpContents.length; + this.checkboxes = []; + + for (let i = this.pageHelpContents.length - 1; i >= 0; i -= 1) { + //for (let i = 0; i < this.pageHelpContents.length; i++) { + let page: Page = this.pageHelpContents[i].page as Page; + if (!this.selectedPageId || (page._id == this.selectedPageId)) { + this.cutContent(this.pageHelpContents[i]); + this.checkboxes.unshift({ + pageHelpContent: this.pageHelpContents[i], + checked: false + }); + } else { + this.pageHelpContents.splice(i, 1); + } + } + + this.countPageHelpContents(); + + this.showLoading = false; + }, + error => this.handleError('System error retrieving page contents', error)); + } + } + + // public showModal():void { + // this.modal.showModal(); + // } + + public toggleCheckBoxes(event) { + this.checkboxes.forEach(_ => _.checked = event.target.checked); + this.checkboxAll = event.target.checked; + } + + public applyCheck(flag: boolean) { + this.checkboxes.forEach(_ => _.checked = flag); + this.checkboxAll = false; + } + + public getSelectedPageHelpContents(): string[] { + return this.checkboxes.filter(pageHelpContent => pageHelpContent.checked == true) + .map(checkedPageHelpContent => checkedPageHelpContent.pageHelpContent).map(res => res._id); + } + + public confirmDeletePageHelpContent(id: string) { + //this.deleteConfirmationModal.ids = [id]; + //this.deleteConfirmationModal.showModal(); + this.selectedPageContents = [id]; + this.confirmModalOpen(); + } + + public confirmDeleteSelectedPageHelpContents() { + //this.deleteConfirmationModal.ids = this.getSelectedPageHelpContents(); + //this.deleteConfirmationModal.showModal(); + this.selectedPageContents = this.getSelectedPageHelpContents(); + this.confirmModalOpen(); + } + + private confirmModalOpen() { + if (!Session.isLoggedIn()) { + this.router.navigate(['/user-info'], { + queryParams: { + "errorCode": LoginErrorCodes.NOT_VALID, + "redirectUrl": this.router.url + } + }); + } else { + this.alertModalDeletePageHelpContents.cancelButton = true; + this.alertModalDeletePageHelpContents.okButton = true; + this.alertModalDeletePageHelpContents.alertTitle = "Delete Confirmation"; + this.alertModalDeletePageHelpContents.message = "Are you sure you want to delete the selected page content(s)?"; + this.alertModalDeletePageHelpContents.okButtonText = "Yes"; + this.alertModalDeletePageHelpContents.open(); + } + } + + public confirmedDeletePageHelpContents(data: any) { + if (!Session.isLoggedIn()) { + this.router.navigate(['/user-info'], { + queryParams: { + "errorCode": LoginErrorCodes.NOT_VALID, + "redirectUrl": this.router.url + } + }); + } else { + this.showLoading = true; + this.updateErrorMessage = ""; + + this._helpService.deletePageHelpContents(this.selectedPageContents, this.properties.adminToolsAPIURL).subscribe( + _ => { + this.deletePageHelpContentsFromArray(this.selectedPageContents); + this.showLoading = false; + }, + error => this.handleUpdateError('System error deleting the selected page content(s)', error) + ); + } + } + + private deletePageHelpContentsFromArray(ids: string[]): void { + for (let id of ids) { + let iqc = this.checkboxes.findIndex(_ => _.pageHelpContent._id == id); + let iq = this.pageHelpContents.findIndex(_ => _._id == id); + this.checkboxes.splice(iqc, 1); + this.pageHelpContents.splice(iqc, 1); + } + this.countPageHelpContents(); + } + + public editPageHelpContent(id: string) { + //this.router.navigate(['/pageContents/edit/', _id]); + if (this.selectedPageId) { + this.router.navigate(['/helptexts/edit/'], { + queryParams: { + "pageContentId": id, + "communityId": this.selectedCommunityPid, + "pageId": this.selectedPageId + } + }); + } else { + this.router.navigate(['/helptexts/edit/'], { + queryParams: { + "pageContentId": id, + "communityId": this.selectedCommunityPid + } + }); + } + } + + public togglePageHelpContents(status: boolean, ids: string[]) { + if (!Session.isLoggedIn()) { + this.router.navigate(['/user-info'], { + queryParams: { + "errorCode": LoginErrorCodes.NOT_VALID, + "redirectUrl": this.router.url + } + }); + } else { + this.updateErrorMessage = ""; + + this._helpService.togglePageHelpContents(ids, status, this.properties.adminToolsAPIURL).subscribe( + () => { + for (let id of ids) { + let i = this.checkboxes.findIndex(_ => _.pageHelpContent._id == id); + this.checkboxes[i].pageHelpContent.isActive = status; + } + this.countPageHelpContents(); + this.applyCheck(false); + }, + error => this.handleUpdateError('System error changing the status of the selected page content(s)', error) + ); + } + } + + public pageHelpContentSavedSuccessfully(pageHelpContent: PageHelpContent) { + this.cutContent(pageHelpContent); + this.checkboxes.push({pageHelpContent: pageHelpContent, checked: false}); + this.pageHelpContents.push(pageHelpContent); + this.applyCheck(false); + this.countPageHelpContents(); + } + + public pageHelpContentUpdatedSuccessfully(pageHelpContent: PageHelpContent) { + this.checkboxes.find(checkItem => checkItem.pageHelpContent._id == pageHelpContent._id).pageHelpContent = pageHelpContent; + let index = this.pageHelpContents.findIndex(checkItem => checkItem._id == pageHelpContent._id); + this.pageHelpContents[index] = pageHelpContent; + this.applyCheck(false); + this.countPageHelpContents(); + } + + + public filterPageHelpContent(pageHelpContent: PageHelpContent, filters: PageHelpContentFilterOptions): boolean { + let idFlag = filters.id == '' || (pageHelpContent.page)._id == filters.id; + let activeFlag = filters.active == null || pageHelpContent.isActive == filters.active; + let textFlag = filters.text.toString() == '' || (pageHelpContent.content).match(filters.text) != null + || ((pageHelpContent.page).name).match(filters.text) != null; + return idFlag && activeFlag && textFlag; + } + + public cutContent(pageHelpContent: PageHelpContent) { + pageHelpContent.content = pageHelpContent.content.replace(/<[^>]*>/g, ''); + pageHelpContent.content = pageHelpContent.content.replace(/(\r\n|\n|\r| +(?= ))|\s\s+/gm, " "); + + if (pageHelpContent.content.length > 200) { + pageHelpContent.content = pageHelpContent.content.substr(0, 200) + "..."; + } + } + + public applyFilter() { + this.checkboxes = []; + this.pageHelpContents.filter(item => this.filterPageHelpContent(item, this.filters)).forEach( + _ => { + this.cutContent(_); + this.checkboxes.push({pageHelpContent: _, checked: false}) + } + ); + this.countPageHelpContents(); + } + + public filterByPage(event: any) { + this.filters.id = event.target.value; + this.applyFilter(); + } + + public displayAllPageHelpContents() { + this.filters.active = null; + this.applyFilter(); + } + + public displayActivePageHelpContents() { + this.filters.active = true; + this.applyFilter(); + } + + public filterBySearch(text: string) { + this.filters.text = new RegExp(text, "i"); + this.applyFilter(); + } + + public displayInactivePageHelpContents() { + this.filters.active = false; + this.applyFilter(); + } + + handleError(message: string, error) { + this.errorMessage = message; + console.log('Server responded: ' + error); + + this.showLoading = false; + } + + handleUpdateError(message: string, error) { + this.updateErrorMessage = message; + console.log('Server responded: ' + error); + + this.showLoading = false; + } + + public newPageContent() { + if (this.selectedPageId) { + this.router.navigate(['/helptexts/new'], { + queryParams: { + communityId: this.selectedCommunityPid, + pageId: this.selectedPageId + } + }); + } else { + this.router.navigate(['/helptexts/new'], {queryParams: {communityId: this.selectedCommunityPid}}); + } + } +} diff --git a/dashboard/helpTexts/page-help-contents.module.ts b/dashboard/helpTexts/page-help-contents.module.ts new file mode 100644 index 00000000..fcb07e77 --- /dev/null +++ b/dashboard/helpTexts/page-help-contents.module.ts @@ -0,0 +1,26 @@ +import { NgModule } from '@angular/core'; +import {RouterModule} from '@angular/router'; +import {CommonModule} from '@angular/common'; +import {IsCommunity} from '../../connect/communityGuard/isCommunity.guard'; +import {ConnectAdminLoginGuard} from '../../connect/communityGuard/connectAdminLoginGuard.guard'; +import {FormsModule, ReactiveFormsModule} from '@angular/forms'; +import {AlertModalModule} from '../../utils/modal/alertModal.module'; +import {PageHelpContentsRoutingModule} from './page-help-contents-routing.module'; +import {PageHelpContentsComponent} from './page-help-contents.component'; +import {SafeHtmlPipeModule} from '../../utils/pipes/safeHTMLPipe.module'; +import {MatSlideToggleModule} from '@angular/material'; +import {AdminToolServiceModule} from "../../services/adminToolService.module"; +import {InputModule} from "../../../library/sharedComponents/input/input.module"; + +@NgModule({ + imports: [ + CommonModule, RouterModule, FormsModule, SafeHtmlPipeModule, + AlertModalModule, ReactiveFormsModule, PageHelpContentsRoutingModule, MatSlideToggleModule, AdminToolServiceModule, InputModule + ], + declarations: [ + PageHelpContentsComponent + ], + providers: [IsCommunity, ConnectAdminLoginGuard], + exports: [PageHelpContentsComponent] +}) +export class PageHelpContentsModule { } diff --git a/dashboard/page/pages-routing.module.ts b/dashboard/page/pages-routing.module.ts new file mode 100644 index 00000000..7a131a4e --- /dev/null +++ b/dashboard/page/pages-routing.module.ts @@ -0,0 +1,14 @@ +import { NgModule } from '@angular/core'; +import {RouterModule} from '@angular/router'; +import {ConnectAdminLoginGuard} from '../../connect/communityGuard/connectAdminLoginGuard.guard'; +import {PagesComponent} from './pages.component'; +import {IsCommunityOrAdmin} from '../../connect/communityGuard/isCommunityOrAdmin'; + +@NgModule({ + imports: [ + RouterModule.forChild([ + { path: '', canActivate: [IsCommunityOrAdmin, ConnectAdminLoginGuard], component: PagesComponent} + ]) + ] +}) +export class PagesRoutingModule { } diff --git a/dashboard/page/pages.component.html b/dashboard/page/pages.component.html new file mode 100644 index 00000000..4bb69d09 --- /dev/null +++ b/dashboard/page/pages.component.html @@ -0,0 +1,287 @@ +
+
+ +
+
+ search +
+
+ +
+
+ +
+
+
+
+ + +
+
+
+

{{pagesType}} Pages

+
+ + {{updateErrorMessage}} +
+ +
+
+
+ + +
+
+ + Disable a page to hide it from community dashboard portal. +
+
If the page is disabled, a message "Can't find that page" will appear in case the url of that page is loaded. If the disabled page belongs to the menu, the link will be removed from menu, too. +
+ +
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameChange statusTypeRelated EntitiesRouteActionsPage help textsClass help texts +
+ +
{{check.page.name}}
+
+ + +
{{check.page.type}}
+
+
+ {{entity.name}}, +
+
+
{{check.page.route}}
+
+
+ + delete +
+
+ + add help texts + + - + + add class contents + - +
+ +
+
No pages found
+
+
+
+ add +
+
+
+
+
+
+
+
+
+
+ + + + +
+ +
+
+ +
+
+ +
+
+ + + + {{entity.name}} + cancel + + + + + + {{entity.name}} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
Select if this page exists in:
+ + + + + + + + + +
+
+ +
Select if this page exists in:
+ + + + + + +
+ + +
+ +
+ + + + + + + diff --git a/dashboard/page/pages.component.ts b/dashboard/page/pages.component.ts new file mode 100644 index 00000000..467520f1 --- /dev/null +++ b/dashboard/page/pages.component.ts @@ -0,0 +1,546 @@ +import {Component, ElementRef, OnInit, ViewChild} from '@angular/core'; +import {ActivatedRoute, Router} from '@angular/router'; +import {HelpContentService} from '../../services/help-content.service'; +import {FormArray, FormBuilder, FormControl, FormGroup, Validators} from '@angular/forms'; +import {CheckPage, Page} from '../../utils/entities/adminTool/page'; +import {Community} from '../../utils/entities/adminTool/community'; +import {Entity} from '../../utils/entities/adminTool/entity'; +import {EnvProperties} from '../../utils/properties/env-properties'; +import {Session} from '../../login/utils/helper.class'; +import {LoginErrorCodes} from '../../login/utils/guardHelper.class'; +import {HelperFunctions} from '../../utils/HelperFunctions.class'; +import {UserManagementService} from '../../services/user-management.service'; +import {Observable, Subscriber} from "rxjs"; +import {map, startWith} from "rxjs/operators"; +import {MatAutocompleteSelectedEvent} from "@angular/material"; + +@Component({ + selector: 'pages', + templateUrl: './pages.component.html', +}) + +export class PagesComponent implements OnInit { + + @ViewChild('AlertModalSavePage') alertModalSavePage; + @ViewChild('AlertModalDeletePages') alertModalDeletePages; + private selectedPages: string[] = []; + + public checkboxes: CheckPage[] = []; + + public pages: Page[] = []; + public pageWithDivIds: string[] = []; + + //public errorMessage: string; + + public myForm: FormGroup; + + private searchText: RegExp = new RegExp(''); + public keyword: string = ''; + + public communities: Community[] = []; + + public selectedCommunityPid: string; + + public pagesType: string; + public properties: EnvProperties = null; + + public showLoading: boolean = true; + public errorMessage: string = ''; + public updateErrorMessage: string = ''; + public modalErrorMessage: string = ''; + public isPortalAdministrator = null; + public filterForm: FormControl; + public typeOptions = [{label: 'Search', value: 'search'}, {label: 'Link', value: 'link'}, { + label: 'Share', + value: 'share' + }, {label: 'Landing', value: 'landing'}, {label: 'HTML', value: 'html'}, { + label: 'Link', + value: 'link' + }, {label: 'Other', value: 'other'}] + public entitiesCtrl: FormArray; + @ViewChild('PageInput') pageInput: ElementRef; + public entitiesSearchCtrl: FormControl; + filteredEntities: Observable; + selectedEntities: Entity[] = []; + allEntities: Entity[] = []; + + private subscriptions: any[] = []; + + constructor(private element: ElementRef, private route: ActivatedRoute, + private _router: Router, private _helpContentService: HelpContentService, + private userManagementService: UserManagementService, private _fb: FormBuilder) { + } + + ngOnInit() { + this.filterForm = this._fb.control(''); + this.subscriptions.push(this.filterForm.valueChanges.subscribe(value => { + this.filterBySearch(value); + })); + this.entitiesSearchCtrl = this._fb.control(''); + this.myForm = this._fb.group({ + route: ['', Validators.required], + name: ['', Validators.required], + isEnabled: true, + openaire: true, + connect: false, + communities: true, + top: true, + bottom: true, + left: true, + right: true, + type: ['', Validators.required], + entities: this.entitiesCtrl, + _id: '', + }); + this.route.data + .subscribe((data: { envSpecific: EnvProperties }) => { + this.properties = data.envSpecific; + + this.route.queryParams.subscribe(params => { + HelperFunctions.scroll(); + + this.pagesType = ''; + if (params['type']) { + this.pagesType = params['type']; + } + + this.keyword = ''; + this.userManagementService.getUserInfo(this.properties.userInfoUrl).subscribe(user => { + this.selectedCommunityPid = params['communityId']; + this.applyCommunityFilter(this.selectedCommunityPid); + this.isPortalAdministrator = Session.isPortalAdministrator(user) && !this.selectedCommunityPid; + }); + //this.getCommunities(); + }); + + this._helpContentService.getEntities(this.properties.adminToolsAPIURL).subscribe( + entities => { + this.allEntities = entities; + this.showLoading = false; + }, + error => this.handleError('System error retrieving community entities', error)); + + + }); + } + + ngOnDestroy(): void { + this.subscriptions.forEach(value => { + if (value instanceof Subscriber) { + value.unsubscribe(); + } else if (value instanceof Function) { + value(); + } + }); + } + + getPages(community_pid: string) { + if (!Session.isLoggedIn()) { + this._router.navigate(['/user-info'], { + queryParams: { + 'errorCode': LoginErrorCodes.NOT_VALID, + 'redirectUrl': this._router.url + } + }); + } else { + this.showLoading = true; + this.updateErrorMessage = ''; + this.errorMessage = ''; + + this.pageWithDivIds = []; + + let parameters = ''; + if (this.pagesType) { + parameters = '?page_type=' + this.pagesType; + } + if (community_pid) { + this._helpContentService.getCommunityPages(community_pid, parameters, this.properties.adminToolsAPIURL).subscribe( + pages => { + this.pagesReturned(pages); + //if(!this.pagesType || this.pagesType == "link") { + this.getPagesWithDivIds(community_pid); + //} else { + //this.showLoading = false; + //} + }, + error => this.handleError('System error retrieving pages', error) + ); + } else { + this._helpContentService.getPagesFull(this.properties.adminToolsAPIURL, null).subscribe( + pages => { + this.pagesReturned(pages); + this.showLoading = false; + }, + error => this.handleError('System error retrieving pages', error) + ); + } + } + } + + getPagesWithDivIds(community_pid: string) { + if (!Session.isLoggedIn()) { + this._router.navigate(['/user-info'], { + queryParams: { + 'errorCode': LoginErrorCodes.NOT_VALID, + 'redirectUrl': this._router.url + } + }); + } else { + this._helpContentService.getPagesWithDivIds(community_pid, this.properties.adminToolsAPIURL).subscribe( + pages => { + this.pageWithDivIds = pages; + this.showLoading = false; + }, + error => this.handleError('System error retrieving information about pages\' classes', error)); + } + } + + pagesReturned(pages: Page[]) { + this.pages = pages; + this.checkboxes = []; + + if (pages) { + pages.forEach(_ => { + this.checkboxes.push({page: _, checked: false}); + }); + } + } + + /* + getCommunities() { + this._helpContentService.getCommunities(this.properties.adminToolsAPIURL).subscribe( + communities => { + this.communities = communities; + this.selectedCommunityPid = this.communities[0].pid; + this.getPages(this.selectedCommunityPid); + this.getPagesWithDivIds(this.selectedCommunityPid); + }, + error => this.handleError('System error retrieving communities', error)); + } + */ + + public toggleCheckBoxes(event) { + this.checkboxes.forEach(_ => _.checked = event.target.checked); + } + + public applyCheck(flag: boolean) { + this.checkboxes.forEach(_ => _.checked = flag); + } + + public getSelectedPages(): string[] { + return this.checkboxes.filter(page => page.checked == true).map(checkedPage => checkedPage.page).map(res => res._id); + } + + private deletePagesFromArray(ids: string[]): void { + for (let id of ids) { + let i = this.checkboxes.findIndex(_ => _.page._id == id); + this.checkboxes.splice(i, 1); + } + } + + public confirmDeletePage(id: string) { + //this.deleteConfirmationModal.ids = [id]; + //this.deleteConfirmationModal.showModal(); + this.selectedPages = [id]; + this.confirmModalOpen(); + } + + public confirmDeleteSelectedPages() { + //this.deleteConfirmationModal.ids = this.getSelectedPages(); + //this.deleteConfirmationModal.showModal(); + this.selectedPages = this.getSelectedPages(); + this.confirmModalOpen(); + } + + private confirmModalOpen() { + if (!Session.isLoggedIn()) { + this._router.navigate(['/user-info'], { + queryParams: { + 'errorCode': LoginErrorCodes.NOT_VALID, + 'redirectUrl': this._router.url + } + }); + } else { + this.alertModalDeletePages.cancelButton = true; + this.alertModalDeletePages.okButton = true; + this.alertModalDeletePages.alertTitle = 'Delete Confirmation'; + this.alertModalDeletePages.message = 'Are you sure you want to delete the selected page(s)?'; + this.alertModalDeletePages.okButtonText = 'Yes'; + this.alertModalDeletePages.open(); + } + } + + public confirmedDeletePages(data: any) { + if (!Session.isLoggedIn()) { + this._router.navigate(['/user-info'], { + queryParams: { + 'errorCode': LoginErrorCodes.NOT_VALID, + 'redirectUrl': this._router.url + } + }); + } else { + this.showLoading = true; + this.updateErrorMessage = ''; + + this._helpContentService.deletePages(this.selectedPages, this.properties.adminToolsAPIURL).subscribe( + _ => { + this.deletePagesFromArray(this.selectedPages); + this.showLoading = false; + }, + error => this.handleUpdateError('System error deleting the selected pages', error) + ); + } + } + + public editPage(i: number) { + this.entitiesCtrl = this._fb.array([]); + let page: Page = this.checkboxes[i].page; + this.myForm = this._fb.group({ + route: [page.route, Validators.required], + name: [page.name, Validators.required], + isEnabled: page.isEnabled, + openaire: page.openaire, + connect: page.connect, + communities: page.communities, + top: page.top, + bottom: page.bottom, + left: page.left, + right: page.right, + type: [page.type, Validators.required], + entities: this.entitiesCtrl, + _id: page._id, + }); + + for (let i = 0; i < page.entities.length; i++) { + this.entitiesCtrl.push(this._fb.control(page.entities[i])); + } + this.filteredEntities = this.entitiesSearchCtrl.valueChanges.pipe(startWith(''), + map(page => this._filter(page))); + this.selectedEntities = JSON.parse(JSON.stringify(page.entities)); + this.modalErrorMessage = ''; + this.pagesModalOpen(this.alertModalSavePage, '', 'Save changes'); + } + + private _filter(value: string): Entity[] { + if (!value || value.length == 0) { + return this.allEntities.slice(); + } + const filterValue = value.toString().toLowerCase(); + return this.allEntities.filter(page => page.name.toLowerCase().indexOf(filterValue) != -1); + } + + public newPage() { + this.entitiesCtrl = this._fb.array([]); + this.myForm = this._fb.group({ + route: ['', Validators.required], + name: ['', Validators.required], + isEnabled: true, + openaire: true, + connect: false, + communities: true, + top: true, + bottom: true, + left: true, + right: true, + type: [this.typeOptions[0].value, Validators.required], + entities: this._fb.array([]), + _id: '', + }); + this.selectedEntities = []; + this.modalErrorMessage = ''; + this.filteredEntities = this.entitiesSearchCtrl.valueChanges.pipe(startWith(''), + map(page => this._filter(page))); + this.pagesModalOpen(this.alertModalSavePage, '', 'Save'); + } + + private pagesModalOpen(modal: any, title: string, yesBtn: string) { + if (!Session.isLoggedIn()) { + this._router.navigate(['/user-info'], { + queryParams: { + 'errorCode': LoginErrorCodes.NOT_VALID, + 'redirectUrl': this._router.url + } + }); + } else { + modal.cancelButton = true; + modal.okButton = true; + modal.alertTitle = title; + modal.okButtonText = yesBtn; + modal.open(); + } + } + + public pageSaveConfirmed(data: any) { + if (!Session.isLoggedIn()) { + this._router.navigate(['/user-info'], { + queryParams: { + 'errorCode': LoginErrorCodes.NOT_VALID, + 'redirectUrl': this._router.url + } + }); + } else { + console.log(this.myForm.value) + if (this.myForm.value['_id'].length == 0) { + this.modalErrorMessage = ''; + this._helpContentService.savePage(this.myForm.value, this.properties.adminToolsAPIURL).subscribe( + page => { + this.pageSavedSuccessfully(page, true); + }, + error => this.handleUpdateError('System error creating page', error) + ); + } else { + this._helpContentService.updatePage(this.myForm.value, this.properties.adminToolsAPIURL).subscribe( + page => { + this.pageSavedSuccessfully(page, false); + }, + error => this.handleUpdateError('System error updating page', error) + ); + } + + } + } + + /* public pageUpdateConfirmed(data: any) { + if (!Session.isLoggedIn()) { + this._router.navigate(['/user-info'], {queryParams: {'errorCode': LoginErrorCodes.NOT_VALID, 'redirectUrl': this._router.url}}); + } else { + if (!this.myForm.valid) { + this.pagesModalOpen(this.alertModalSavePage, 'Update', 'Update Page'); + this.modalErrorMessage = 'Please fill in all required fields marked with *'; + } else { + this._helpContentService.updatePage(this.myForm.value, this.properties.adminToolsAPIURL).subscribe( + page => { + this.pageUpdatedSuccessfully(page); + }, + error => this.handleUpdateError('System error updating page', error) + ); + } + } + }*/ + + public pageSavedSuccessfully(page: Page, isNew: boolean) { + if (isNew) { + this.checkboxes.push({page: page, checked: false}); + } else { + this.checkboxes.find(checkItem => checkItem.page._id == page._id).page = page; + } + this.applyCheck(false); + } + + + public filterBySearch(text: string) { + this.searchText = new RegExp(text, 'i'); + this.applyFilter(); + } + + public applyFilter() { + this.checkboxes = []; + this.pages.filter(item => this.filterPages(item)).forEach( + _ => this.checkboxes.push({page: _, checked: false}) + ); + } + + public filterPages(page: Page): boolean { + let textFlag = this.searchText.toString() == '' || (page.route + ' ' + page.name).match(this.searchText) != null; + return textFlag; + } + + handleError(message: string, error) { + // if(error == null) { + // this.formComponent.reset(); + // } else { + this.errorMessage = message;// + ' (Server responded: ' + error + ')'; + console.log('Server responded: ' + error); + //} + + this.showLoading = false; + } + + handleUpdateError(message: string, error) { + if (error == null) { + // this.formComponent.reset(); + this.myForm = this._fb.group({ + route: ['', Validators.required], + name: ['', Validators.required], + isEnabled: true, + openaire: true, + connect: false, + communities: true, + top: true, + bottom: true, + left: true, + right: true, + type: ['', Validators.required], + entities: this._fb.array([]), + _id: '', + }); + } else { + this.updateErrorMessage = message;// + ' (Server responded: ' + error + ')'; + console.log('Server responded: ' + error); + } + + this.showLoading = false; + } + + // public filterByCommunity(event: any) { + // this.selectedCommunityPid = event.target.value; + // this.applyCommunityFilter(this.selectedCommunityPid); + // } + + public applyCommunityFilter(community_pid: string) { + this.getPages(community_pid); + } + + public togglePages(status: boolean, ids: string[]) { + if (!Session.isLoggedIn()) { + this._router.navigate(['/user-info'], { + queryParams: { + 'errorCode': LoginErrorCodes.NOT_VALID, + 'redirectUrl': this._router.url + } + }); + } else { + this.updateErrorMessage = ''; + + this._helpContentService.togglePages(this.selectedCommunityPid, ids, status, this.properties.adminToolsAPIURL).subscribe( + () => { + for (let id of ids) { + let i = this.checkboxes.findIndex(_ => _.page._id == id); + this.checkboxes[i].page.isEnabled = status; + } + this.applyCheck(false); + }, + error => this.handleUpdateError('System error changing the status of the selected page(s)', error) + ); + } + } + + public capitalizeFirstLetter(str: string) { + return str.charAt(0).toUpperCase() + str.slice(1); + } + + remove(entity): void { + let index = this.selectedEntities.indexOf(entity); + console.log(entity); + console.log(this.selectedEntities); + console.log(index) + if (index >= 0) { + this.selectedEntities.splice(index, 1); + this.entitiesCtrl.value.splice(index, 1); + this.entitiesCtrl.markAsDirty(); + } + } + + selected(event: MatAutocompleteSelectedEvent): void { + + let newEntity = event.option.value; + + if (this.selectedEntities.indexOf(newEntity) == -1) { + this.selectedEntities.push(event.option.value); + this.entitiesCtrl.push(this._fb.control(newEntity)); + this.entitiesCtrl.markAsDirty(); + } + this.pageInput.nativeElement.value = ''; + this.entitiesSearchCtrl.setValue(''); + } +} diff --git a/dashboard/page/pages.module.ts b/dashboard/page/pages.module.ts new file mode 100644 index 00000000..7bc1bd0c --- /dev/null +++ b/dashboard/page/pages.module.ts @@ -0,0 +1,23 @@ +import { NgModule } from '@angular/core'; +import {RouterModule} from '@angular/router'; +import {CommonModule} from '@angular/common'; +import {ConnectAdminLoginGuard} from '../../connect/communityGuard/connectAdminLoginGuard.guard'; +import {FormsModule, ReactiveFormsModule} from '@angular/forms'; +import {AlertModalModule} from '../../utils/modal/alertModal.module'; +import {PagesComponent} from './pages.component'; +import {PagesRoutingModule} from './pages-routing.module'; +import {MatAutocompleteModule, MatChipsModule, MatFormFieldModule, MatSlideToggleModule} from '@angular/material'; +import {IsCommunityOrAdmin} from '../../connect/communityGuard/isCommunityOrAdmin'; +import {AdminToolServiceModule} from "../../services/adminToolService.module"; +import {InputModule} from "../../../library/sharedComponents/input/input.module"; + +@NgModule({ + imports: [ + CommonModule, RouterModule, FormsModule, AlertModalModule, ReactiveFormsModule, PagesRoutingModule, MatSlideToggleModule, AdminToolServiceModule, InputModule, + MatAutocompleteModule, MatFormFieldModule, MatChipsModule + ], + declarations: [PagesComponent], + providers: [IsCommunityOrAdmin, ConnectAdminLoginGuard], + exports: [PagesComponent] +}) +export class PagesModule { }