+
+
+
+
+
+
+
+
+
+
Bulk Actions
+
+
+ Page help texts
+ Page help texts of page '{{page.name}}'
+
+
+
+
+
+ {{updateErrorMessage}}
+
+
+
+
+
+
+
{{errorMessage}}
+
+
+
+
+
+
+ Enable or disable help text to show or hide it from the dashboard
+
+
+
+
+
+
+
+
+
+
No page contents found
+
+
+
+
+
+
+
+
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 @@
+
+
+
+
+
+
{{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.
+
+
+
+
{{errorMessage}}
+
+
+
+
+
+
+
+
+
+
+ {{ modalErrorMessage }}
+
+
+
+
+
+
+
+
+
+
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 { }