From 9ddb0b32c95cfed3b03bd0e45c77a4fcb1d5a467 Mon Sep 17 00:00:00 2001 From: "konstantina.galouni" Date: Tue, 13 Nov 2018 15:26:49 +0000 Subject: [PATCH] For every page: when Session is expired, redirect to '/user-info' page to show a proper message. git-svn-id: https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-admin-portal/trunk@53735 d315682c-612b-4755-9ff5-7f18f6832af3 --- .../pages/community/communities.component.ts | 97 +++++--- .../community-edit-form.component.ts | 49 ++-- .../add-content-providers.component.ts | 173 +++++++------- .../manage-content-providers.component.ts | 34 ++- .../remove-content-providers.component.ts | 209 +++++++++-------- .../projects/add-projects.component.ts | 195 +++++++++------- .../projects/manage-projects.component.ts | 36 +-- .../projects/remove-projects.component.ts | 214 ++++++++++-------- src/app/pages/divId/divId-form.component.ts | 116 ++++++---- src/app/pages/divId/divIds.component.ts | 97 +++++--- .../div-help-content-form.component.ts | 96 +++++--- .../div-help-contents.component.ts | 63 ++++-- .../edit-div-help-content.component.ts | 38 +++- .../new-div-help-content.component.ts | 8 + src/app/pages/entity/entities.component.ts | 143 +++++++----- .../edit-page-help-content.component.ts | 31 ++- .../new-page-help-content.component.ts | 9 +- .../page-help-content-form.component.ts | 23 +- .../page-help-contents.component.ts | 86 ++++--- .../edit-htmlpage-content.component.ts | 52 +++-- src/app/pages/page/page-form.component.ts | 110 +++++---- src/app/pages/page/pages.component.html | 4 +- src/app/pages/page/pages.component.ts | 117 ++++++---- src/app/pages/stats/stats.component.ts | 47 +++- .../subjects-edit-form.component.ts | 72 ++++-- .../manage-subscribers.component.ts | 22 ++ .../manage-zenodo-communities.component.ts | 44 ++-- 27 files changed, 1375 insertions(+), 810 deletions(-) diff --git a/src/app/pages/community/communities.component.ts b/src/app/pages/community/communities.component.ts index 621c9b3..756582a 100644 --- a/src/app/pages/community/communities.component.ts +++ b/src/app/pages/community/communities.component.ts @@ -2,7 +2,7 @@ * Created by stefania on 7/13/17. */ import { Component, ViewChild, OnInit } from '@angular/core'; -import { ActivatedRoute } from "@angular/router"; +import { ActivatedRoute, Router } from "@angular/router"; import { HelpContentService } from "../../services/help-content.service"; import { FormGroup } from "@angular/forms"; import { ModalFormComponent } from "../modal-form.component"; @@ -11,6 +11,9 @@ import { CommunityFormComponent } from "./community-form.component"; import { CheckCommunity, Community } from "../../domain/community"; import { EnvProperties } from '../../openaireLibrary/utils/properties/env-properties'; +import {Session} from '../../openaireLibrary/login/utils/helper.class'; +import {LoginErrorCodes} from '../../openaireLibrary/login/utils/guardHelper.class'; + @Component({ selector: 'communities', templateUrl: './communities.component.html', @@ -62,10 +65,14 @@ export class CommunitiesComponent implements OnInit { }); } - constructor(private route: ActivatedRoute, private _helpContentService: HelpContentService) {} + constructor(private route: ActivatedRoute, private _router: Router, private _helpContentService: HelpContentService) {} getCommunities() { + if(!Session.isLoggedIn()){ + console.info(this._router.url); + this._router.navigate(['/user-info'], { queryParams: { "errorCode": LoginErrorCodes.NOT_VALID, "redirectUrl": this._router.url} }); + } else { this.showLoading = true; this.updateErrorMessage = ""; this.errorMessage = ""; @@ -80,6 +87,7 @@ export class CommunitiesComponent implements OnInit { this.showLoading = false; }, error => this.handleError('System error retrieving communities', error)); + } } // public showModal():void { @@ -121,15 +129,24 @@ export class CommunitiesComponent implements OnInit { } private confirmModalOpen() { - this.alertModalDeleteCommunities.cancelButton = true; - this.alertModalDeleteCommunities.okButton = true; - this.alertModalDeleteCommunities.alertTitle = "Delete Confirmation"; - this.alertModalDeleteCommunities.message = "Are you sure you want to delete the selected community(-ies)?"; - this.alertModalDeleteCommunities.okButtonText = "Yes"; - this.alertModalDeleteCommunities.open(); + if(!Session.isLoggedIn()){ + console.info(this._router.url); + this._router.navigate(['/user-info'], { queryParams: { "errorCode": LoginErrorCodes.NOT_VALID, "redirectUrl": this._router.url} }); + } else { + this.alertModalDeleteCommunities.cancelButton = true; + this.alertModalDeleteCommunities.okButton = true; + this.alertModalDeleteCommunities.alertTitle = "Delete Confirmation"; + this.alertModalDeleteCommunities.message = "Are you sure you want to delete the selected community(-ies)?"; + this.alertModalDeleteCommunities.okButtonText = "Yes"; + this.alertModalDeleteCommunities.open(); + } } public confirmedDeleteCommunities(data: any) { + if(!Session.isLoggedIn()){ + console.info(this._router.url); + this._router.navigate(['/user-info'], { queryParams: { "errorCode": LoginErrorCodes.NOT_VALID, "redirectUrl": this._router.url} }); + } else { this.showLoading = true; this.updateErrorMessage = ""; @@ -140,6 +157,7 @@ export class CommunitiesComponent implements OnInit { }, error => this.handleUpdateError('System error deleting the selected communities', error) ); + } } public editCommunity(i : number) { @@ -157,39 +175,54 @@ export class CommunitiesComponent implements OnInit { } private communitiesModalOpen(modal: any, title: string, yesBtn: string) { - modal.cancelButton = true; - modal.okButton = true; - modal.alertTitle = title; - modal.okButtonText = yesBtn; - modal.open(); + if(!Session.isLoggedIn()){ + console.info(this._router.url); + 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 communitySaveConfirmed(data: any) { - if(!this.formGroup.valid) { - this.communitiesModalOpen(this.alertModalSaveCommunity, "Save", "Add a new Community"); - this.modalErrorMessage = "Please fill in all required fields marked with *"; + if(!Session.isLoggedIn()){ + console.info(this._router.url); + this._router.navigate(['/user-info'], { queryParams: { "errorCode": LoginErrorCodes.NOT_VALID, "redirectUrl": this._router.url} }); } else { - this.modalErrorMessage = ""; - this._helpContentService.saveCommunity( this.formGroup.value, this.properties.adminToolsAPIURL).subscribe( - community => { - this.communitySavedSuccessfully(community); - }, - error => this.handleUpdateError("System error creating community", error) - ); + if(!this.formGroup.valid) { + this.communitiesModalOpen(this.alertModalSaveCommunity, "Save", "Add a new Community"); + this.modalErrorMessage = "Please fill in all required fields marked with *"; + } else { + this.modalErrorMessage = ""; + this._helpContentService.saveCommunity( this.formGroup.value, this.properties.adminToolsAPIURL).subscribe( + community => { + this.communitySavedSuccessfully(community); + }, + error => this.handleUpdateError("System error creating community", error) + ); + } } } public communityUpdateConfirmed(data: any) { - if(!this.formGroup.valid) { - this.communitiesModalOpen(this.alertModalUpdateCommunity, "Update", "Update Community"); - this.modalErrorMessage = "Please fill in all required fields marked with *"; + if(!Session.isLoggedIn()){ + console.info(this._router.url); + this._router.navigate(['/user-info'], { queryParams: { "errorCode": LoginErrorCodes.NOT_VALID, "redirectUrl": this._router.url} }); } else { - this._helpContentService.updateCommunity( this.formGroup.value, this.properties.adminToolsAPIURL).subscribe( - community => { - this.communityUpdatedSuccessfully(community); - }, - error => this.handleUpdateError("System error updating community", error) - ); + if(!this.formGroup.valid) { + this.communitiesModalOpen(this.alertModalUpdateCommunity, "Update", "Update Community"); + this.modalErrorMessage = "Please fill in all required fields marked with *"; + } else { + this._helpContentService.updateCommunity( this.formGroup.value, this.properties.adminToolsAPIURL).subscribe( + community => { + this.communityUpdatedSuccessfully(community); + }, + error => this.handleUpdateError("System error updating community", error) + ); + } } } diff --git a/src/app/pages/community/community-edit-form/community-edit-form.component.ts b/src/app/pages/community/community-edit-form/community-edit-form.component.ts index 66b2d2b..bb13397 100644 --- a/src/app/pages/community/community-edit-form/community-edit-form.component.ts +++ b/src/app/pages/community/community-edit-form/community-edit-form.component.ts @@ -10,6 +10,9 @@ import {EnvProperties} from '../../../openaire import {CommunityInfo} from '../../../openaireLibrary/connect/community/communityInfo'; +import {Session} from '../../../openaireLibrary/login/utils/helper.class'; +import {LoginErrorCodes} from '../../../openaireLibrary/login/utils/guardHelper.class'; + @Component({ selector: 'community-edit-form', templateUrl: './community-edit-form.component.html', @@ -55,22 +58,27 @@ export class CommunityEditFormComponent implements OnInit{ communityId => { this.communityId = communityId['communityId']; - if (this.communityId != null && this.communityId != '') { - this.showLoading = true; - this.updateErrorMessage = ""; - this.errorMessage = ""; + if(!Session.isLoggedIn()){ + console.info(this._router.url); + this._router.navigate(['/user-info'], { queryParams: { "errorCode": LoginErrorCodes.NOT_VALID, "redirectUrl": this._router.url} }); + } else { + if (this.communityId != null && this.communityId != '') { + this.showLoading = true; + this.updateErrorMessage = ""; + this.errorMessage = ""; - this._communityService.getCommunity(this.properties, this.properties.communityAPI+this.communityId).subscribe ( - community => { - this.community = community; - this.params = {community: encodeURIComponent('"'+community.queryId+'"')}; - this.firstVersionOfManagers = community.managers.slice(); - console.log("First version of managers " + this.firstVersionOfManagers); - console.log(community); - this.showLoading = false; - }, - error => this.handleError('System error retrieving community profile', error) - ); + this._communityService.getCommunity(this.properties, this.properties.communityAPI+this.communityId).subscribe ( + community => { + this.community = community; + this.params = {community: encodeURIComponent('"'+community.queryId+'"')}; + this.firstVersionOfManagers = community.managers.slice(); + console.log("First version of managers " + this.firstVersionOfManagers); + console.log(community); + this.showLoading = false; + }, + error => this.handleError('System error retrieving community profile', error) + ); + } } }); }); @@ -93,6 +101,10 @@ export class CommunityEditFormComponent implements OnInit{ // } public resetForm(communityId: string) { + if(!Session.isLoggedIn()){ + console.info(this._router.url); + this._router.navigate(['/user-info'], { queryParams: { "errorCode": LoginErrorCodes.NOT_VALID, "redirectUrl": this._router.url} }); + } else { if (communityId != null && communityId != '') { this.showLoading = true; this.updateErrorMessage = ""; @@ -109,10 +121,14 @@ export class CommunityEditFormComponent implements OnInit{ ); } this.resetChange(); + } } public updateCommunity() { - + if(!Session.isLoggedIn()){ + console.info(this._router.url); + this._router.navigate(['/user-info'], { queryParams: { "errorCode": LoginErrorCodes.NOT_VALID, "redirectUrl": this._router.url} }); + } else { if (this.communityId != null && this.communityId != '') { this.showLoading = true; var community = this.parseUpdatedCommunity(); @@ -155,6 +171,7 @@ export class CommunityEditFormComponent implements OnInit{ } } this.resetChange(); + } } diff --git a/src/app/pages/community/content-providers/add-content-providers.component.ts b/src/app/pages/community/content-providers/add-content-providers.component.ts index c5b4c92..dec9f2e 100644 --- a/src/app/pages/community/content-providers/add-content-providers.component.ts +++ b/src/app/pages/community/content-providers/add-content-providers.component.ts @@ -1,5 +1,5 @@ import { Component, ViewChild, OnInit, ViewEncapsulation, Input, Output, EventEmitter } from '@angular/core'; -import { ActivatedRoute } from "@angular/router"; +import { ActivatedRoute, Router } from "@angular/router"; import {SearchResult} from '../../../openaireLibrary/utils/entities/searchResult'; import {ErrorCodes} from '../../../openaireLibrary/utils/properties/errorCodes'; import {SearchFields, FieldDetails} from '../../../openaireLibrary/utils/properties/searchFields'; @@ -9,6 +9,8 @@ import {SearchDataprovidersService} from '../../../openaireLibrary/services/sear import {RouterHelper} from '../../../openaireLibrary/utils/routerHelper.class'; import {DOI, StringUtils} from '../../../openaireLibrary/utils/string-utils.class'; import {ManageCommunityContentProvidersService} from '../../../services/manageContentProviders.service'; +import {Session} from '../../../openaireLibrary/login/utils/helper.class'; +import {LoginErrorCodes} from '../../../openaireLibrary/login/utils/guardHelper.class'; @Component({ selector: 'add-content-providers', @@ -62,7 +64,7 @@ export class AddContentProvidersComponent implements OnInit { }); } - constructor(private route: ActivatedRoute, private _searchContentProvidersService: SearchDataprovidersService, private _manageCommunityContentProvidersService: ManageCommunityContentProvidersService) { + constructor(private route: ActivatedRoute, private _router: Router, private _searchContentProvidersService: SearchDataprovidersService, private _manageCommunityContentProvidersService: ManageCommunityContentProvidersService) { this.errorCodes = new ErrorCodes(); this.openaireSearchUtils.status = this.errorCodes.LOADING; } @@ -80,39 +82,49 @@ export class AddContentProvidersComponent implements OnInit { } public addContentProvider(contenProvider: SearchResult) { - console.info("Add: "+ contenProvider.id); - this.subAdd = this._manageCommunityContentProvidersService.addContentProvider(this.properties, this.community, contenProvider).subscribe( - data => { - console.info("data ADD"); - console.info(data); - this.undo[contenProvider.id] = data.id; - }, - err => { - console.info("error ADD"); - console.log(err.status); - }, - () => { - console.info("completed ADD"); - } - ) + if(!Session.isLoggedIn()){ + console.info(this._router.url); + this._router.navigate(['/user-info'], { queryParams: { "errorCode": LoginErrorCodes.NOT_VALID, "redirectUrl": this._router.url} }); + } else { + console.info("Add: "+ contenProvider.id); + this.subAdd = this._manageCommunityContentProvidersService.addContentProvider(this.properties, this.community, contenProvider).subscribe( + data => { + console.info("data ADD"); + console.info(data); + this.undo[contenProvider.id] = data.id; + }, + err => { + console.info("error ADD"); + console.log(err.status); + }, + () => { + console.info("completed ADD"); + } + ) + } } public removeContentProvider(contentProviderId: string, communityContentProviderId: string) { - console.info("REMOVE: "+ contentProviderId); - this.subRemove = this._manageCommunityContentProvidersService.removeContentProvider(this.properties, this.community, contentProviderId).subscribe( - data => { - console.info("data REMOVE"); - console.info(data); - }, - err => { - console.info("error REMOVE"); - console.log(err); - }, - () => { - console.info("completed REMOVE"); - this.undo[communityContentProviderId] = ""; - } - ) + if(!Session.isLoggedIn()){ + console.info(this._router.url); + this._router.navigate(['/user-info'], { queryParams: { "errorCode": LoginErrorCodes.NOT_VALID, "redirectUrl": this._router.url} }); + } else { + console.info("REMOVE: "+ contentProviderId); + this.subRemove = this._manageCommunityContentProvidersService.removeContentProvider(this.properties, this.community, contentProviderId).subscribe( + data => { + console.info("data REMOVE"); + console.info(data); + }, + err => { + console.info("error REMOVE"); + console.log(err); + }, + () => { + console.info("completed REMOVE"); + this.undo[communityContentProviderId] = ""; + } + ) + } } public inCommunity(contentProvider: any): any { @@ -129,58 +141,63 @@ export class AddContentProvidersComponent implements OnInit { } private _getOpenaireContentProviders(parameters:string, page: number, size: number){ - console.info("_getOpenaireContentProviders"); - if(page > this.pagingLimit) { - size=0; - } + if(!Session.isLoggedIn()){ + console.info(this._router.url); + this._router.navigate(['/user-info'], { queryParams: { "errorCode": LoginErrorCodes.NOT_VALID, "redirectUrl": this._router.url} }); + } else { + console.info("_getOpenaireContentProviders"); + if(page > this.pagingLimit) { + size=0; + } - if(this.openaireSearchUtils.status == this.errorCodes.LOADING) { - this.openaireSearchUtils.status = this.errorCodes.LOADING; + if(this.openaireSearchUtils.status == this.errorCodes.LOADING) { + this.openaireSearchUtils.status = this.errorCodes.LOADING; - this.disableForms = true; - this.openaireContentProviders = []; - this.openaireSearchUtils.totalResults = 0; + this.disableForms = true; + this.openaireContentProviders = []; + this.openaireSearchUtils.totalResults = 0; - this.subResults = this._searchContentProvidersService.searchDataproviders(parameters, null, page, size, [], this.properties).subscribe( - data => { - this.undo = {}; - console.info("total openaire content providers = "+data[0]); - this.openaireSearchUtils.totalResults = data[0]; - this.openaireContentProviders = data[1]; + this.subResults = this._searchContentProvidersService.searchDataproviders(parameters, null, page, size, [], this.properties).subscribe( + data => { + this.undo = {}; + console.info("total openaire content providers = "+data[0]); + this.openaireSearchUtils.totalResults = data[0]; + this.openaireContentProviders = data[1]; - this.openaireSearchUtils.status = this.errorCodes.DONE; - if(this.openaireSearchUtils.totalResults == 0 ){ - this.openaireSearchUtils.status = this.errorCodes.NONE; - } - - this.disableForms = false; - - if(this.openaireSearchUtils.status == this.errorCodes.DONE) { - // Page out of limit!!! - let totalPages:any = this.openaireSearchUtils.totalResults/(this.openaireSearchUtils.size); - if(!(Number.isInteger(totalPages))) { - totalPages = (parseInt(totalPages, 10) + 1); + this.openaireSearchUtils.status = this.errorCodes.DONE; + if(this.openaireSearchUtils.totalResults == 0 ){ + this.openaireSearchUtils.status = this.errorCodes.NONE; } - if(totalPages < page) { - this.openaireSearchUtils.totalResults = 0; - this.openaireSearchUtils.status = this.errorCodes.OUT_OF_BOUND; - } - } - }, - err => { - console.log(err); - //TODO check erros (service not available, bad request) - if(err.status == '404') { - this.openaireSearchUtils.status = this.errorCodes.NOT_FOUND; - } else if(err.status == '500') { - this.openaireSearchUtils.status = this.errorCodes.ERROR; - } else { - this.openaireSearchUtils.status = this.errorCodes.NOT_AVAILABLE; - } - this.disableForms = false; - } - ); + this.disableForms = false; + + if(this.openaireSearchUtils.status == this.errorCodes.DONE) { + // Page out of limit!!! + let totalPages:any = this.openaireSearchUtils.totalResults/(this.openaireSearchUtils.size); + if(!(Number.isInteger(totalPages))) { + totalPages = (parseInt(totalPages, 10) + 1); + } + if(totalPages < page) { + this.openaireSearchUtils.totalResults = 0; + this.openaireSearchUtils.status = this.errorCodes.OUT_OF_BOUND; + } + } + }, + err => { + console.log(err); + //TODO check erros (service not available, bad request) + if(err.status == '404') { + this.openaireSearchUtils.status = this.errorCodes.NOT_FOUND; + } else if(err.status == '500') { + this.openaireSearchUtils.status = this.errorCodes.ERROR; + } else { + this.openaireSearchUtils.status = this.errorCodes.NOT_AVAILABLE; + } + + this.disableForms = false; + } + ); + } } } diff --git a/src/app/pages/community/content-providers/manage-content-providers.component.ts b/src/app/pages/community/content-providers/manage-content-providers.component.ts index 1947ee4..d67291d 100644 --- a/src/app/pages/community/content-providers/manage-content-providers.component.ts +++ b/src/app/pages/community/content-providers/manage-content-providers.component.ts @@ -1,9 +1,12 @@ import { Component, ViewChild, OnInit, ViewEncapsulation, Input } from '@angular/core'; -import { ActivatedRoute } from "@angular/router"; +import { ActivatedRoute, Router } from "@angular/router"; import {RemoveContentProvidersComponent} from './remove-content-providers.component'; import {AddContentProvidersComponent} from './add-content-providers.component'; +import {Session} from '../../../openaireLibrary/login/utils/helper.class'; +import {LoginErrorCodes} from '../../../openaireLibrary/login/utils/guardHelper.class'; + @Component({ selector: 'manage-content-providers', template: ` @@ -47,22 +50,29 @@ export class ManageContentProvidersComponent implements OnInit { }); } - constructor(private route: ActivatedRoute) {} + constructor(private route: ActivatedRoute, private _router: Router) {} public ngOnDestroy() {} public updateCommunityContentProviders() { - this.toggle = !this.toggle; - if(this.toggle) { - this.pageTitle = "Manage content providers"; - //this.toggleLinkMessage = "Missing content providers?"; - - this.removeContentProvidersComponent._getCommunityContentProviders(); - this.addContentProvidersComponent.undo = {}; + if(!Session.isLoggedIn()){ + console.info(this._router.url); + this._router.navigate(['/user-info'], { queryParams: { "errorCode": LoginErrorCodes.NOT_VALID, "redirectUrl": this._router.url} }); } else { - this.updateCommunityContentProvidersOnToggle = false; - this.pageTitle = "Search content providers"; - //this.toggleLinkMessage = "Manage content providers"; + this.toggle = !this.toggle; + if(this.toggle) { + this.pageTitle = "Manage content providers"; + //this.toggleLinkMessage = "Missing content providers?"; + + this.removeContentProvidersComponent._getCommunityContentProviders(); + this.addContentProvidersComponent.undo = {}; + console.info("In remove"); + } else { + this.updateCommunityContentProvidersOnToggle = false; + this.pageTitle = "Search content providers"; + //this.toggleLinkMessage = "Manage content providers"; + console.info("In add"); + } } } diff --git a/src/app/pages/community/content-providers/remove-content-providers.component.ts b/src/app/pages/community/content-providers/remove-content-providers.component.ts index a82fa6b..3014503 100644 --- a/src/app/pages/community/content-providers/remove-content-providers.component.ts +++ b/src/app/pages/community/content-providers/remove-content-providers.component.ts @@ -1,5 +1,5 @@ import { Component, ViewChild, OnInit, ViewEncapsulation, Input, Output, EventEmitter } from '@angular/core'; -import { ActivatedRoute } from "@angular/router"; +import { ActivatedRoute, Router } from "@angular/router"; import { Subject } from 'rxjs/Subject'; import { DataTableDirective } from 'angular-datatables'; @@ -11,6 +11,9 @@ import {SearchCommunityDataprovidersService} from '../../../openaireLibrary/conn import {RouterHelper} from '../../../openaireLibrary/utils/routerHelper.class'; import {DOI, StringUtils} from '../../../openaireLibrary/utils/string-utils.class'; +import {Session} from '../../../openaireLibrary/login/utils/helper.class'; +import {LoginErrorCodes} from '../../../openaireLibrary/login/utils/guardHelper.class'; + @Component({ selector: 'remove-content-providers', templateUrl: './remove-content-providers.component.html', @@ -85,7 +88,7 @@ export class RemoveContentProvidersComponent implements OnInit { this.communitySearchUtils.keyword = ""; } - constructor(private route: ActivatedRoute, + constructor(private route: ActivatedRoute, private _router: Router, private _manageCommunityContentProvidersService: ManageCommunityContentProvidersService, private _searchCommunityContentProvidersService: SearchCommunityDataprovidersService) { this.errorCodes = new ErrorCodes(); @@ -190,111 +193,127 @@ export class RemoveContentProvidersComponent implements OnInit { } public confirmedDeleteContentProvider(data : any) { - console.info("REMOVE: "+ this.selectedCommunityContentProvider.id); - this.subRemove = this._manageCommunityContentProvidersService.removeContentProvider(this.properties, this.community, this.selectedCommunityContentProvider.id).subscribe( - data => { - console.info("data REMOVE"); - console.info(data); - }, - err => { - console.info("error REMOVE"); - console.log(err); - }, - () => { - console.info("completed REMOVE"); - let index = this.communityContentProviders.indexOf(this.selectedCommunityContentProvider); - this.communityContentProviders.splice(index, 1); + if(!Session.isLoggedIn()){ + console.info(this._router.url); + this._router.navigate(['/user-info'], { queryParams: { "errorCode": LoginErrorCodes.NOT_VALID, "redirectUrl": this._router.url} }); + } else { + console.info("REMOVE: "+ this.selectedCommunityContentProvider.id); + this.subRemove = this._manageCommunityContentProvidersService.removeContentProvider(this.properties, this.community, this.selectedCommunityContentProvider.id).subscribe( + data => { + console.info("data REMOVE"); + console.info(data); + }, + err => { + console.info("error REMOVE"); + console.log(err); + }, + () => { + console.info("completed REMOVE"); + let index = this.communityContentProviders.indexOf(this.selectedCommunityContentProvider); + this.communityContentProviders.splice(index, 1); - this.communitySearchUtils.totalResults--; - this.communitySearchUtils.page=1; + this.communitySearchUtils.totalResults--; + this.communitySearchUtils.page=1; - this.rerender(); - } - ) + this.rerender(); + } + ) + } } public removeContentProvider(communityContentProvider: any) { - this.selectedCommunityContentProvider = communityContentProvider; - this.alertModalDeleteCommunity.cancelButton = true; - this.alertModalDeleteCommunity.okButton = true; - this.alertModalDeleteCommunity.alertTitle = "Remove content provider?"; - let title = ""; - if(communityContentProvider.name) { - title = communityContentProvider.name; + if(!Session.isLoggedIn()){ + console.info(this._router.url); + this._router.navigate(['/user-info'], { queryParams: { "errorCode": LoginErrorCodes.NOT_VALID, "redirectUrl": this._router.url} }); + } else { + this.selectedCommunityContentProvider = communityContentProvider; + this.alertModalDeleteCommunity.cancelButton = true; + this.alertModalDeleteCommunity.okButton = true; + this.alertModalDeleteCommunity.alertTitle = "Remove content provider?"; + let title = ""; + if(communityContentProvider.name) { + title = communityContentProvider.name; + } + if(communityContentProvider.name && communityContentProvider.acronym) { + title += " ("; + } + if(communityContentProvider.acronym) { + title += communityContentProvider.acronym; + } + if(communityContentProvider.name && communityContentProvider.acronym) { + title += ") "; + } + this.alertModalDeleteCommunity.message = "Content Provider"; + if(title) { + this.alertModalDeleteCommunity.message += " '"+title+"' "; + } + this.alertModalDeleteCommunity.message += "will be removed from your community. Are you sure?"; + this.alertModalDeleteCommunity.okButtonText = "Yes"; + this.alertModalDeleteCommunity.open(); } - if(communityContentProvider.name && communityContentProvider.acronym) { - title += " ("; - } - if(communityContentProvider.acronym) { - title += communityContentProvider.acronym; - } - if(communityContentProvider.name && communityContentProvider.acronym) { - title += ") "; - } - this.alertModalDeleteCommunity.message = "Content Provider"; - if(title) { - this.alertModalDeleteCommunity.message += " '"+title+"' "; - } - this.alertModalDeleteCommunity.message += "will be removed from your community. Are you sure?"; - this.alertModalDeleteCommunity.okButtonText = "Yes"; - this.alertModalDeleteCommunity.open(); } public _getCommunityContentProviders(){ - this.communitySearchUtils.status = this.errorCodes.LOADING; - this.disableForms = true; - this.communityContentProviders = []; - this.communitySearchUtils.totalResults = 0; - this.communitySearchUtils.page=1; - this.communitySearchUtils.keyword = ""; + if(!Session.isLoggedIn()){ + console.info(this._router.url); + this._router.navigate(['/user-info'], { queryParams: { "errorCode": LoginErrorCodes.NOT_VALID, "redirectUrl": this._router.url} }); + } else { + console.info("_getCommunityContentProviders"); + this.communitySearchUtils.status = this.errorCodes.LOADING; + this.disableForms = true; + this.communityContentProviders = []; + this.communitySearchUtils.totalResults = 0; + this.communitySearchUtils.page=1; + this.communitySearchUtils.keyword = ""; - this.subResults = this._searchCommunityContentProvidersService.searchDataproviders(this.properties, this.community).subscribe( - data => { - console.info(data); - console.info("search Content Providers [total communityContentProviders:"+data.length+"]"); - this.communityContentProviders = data; + this.subResults = this._searchCommunityContentProvidersService.searchDataproviders(this.properties, this.community).subscribe( + data => { + console.info(data); + console.info("search Content Providers [total communityContentProviders:"+data.length+"]"); + this.communityContentProviders = data; - this.communitySearchUtils.totalResults = data.length; - this.communitySearchUtils.status = this.errorCodes.DONE; - // if(this.communitySearchUtils.totalResults == 0 ){ - // this.communitySearchUtils.status = this.errorCodes.NONE; - // } - this.disableForms = false; - if(!this.triggered) { - this.triggerInitialLoad(); - } else { - var table = $('#dpTable').DataTable(); - table.clear(); + this.communitySearchUtils.totalResults = data.length; + this.communitySearchUtils.status = this.errorCodes.DONE; + // if(this.communitySearchUtils.totalResults == 0 ){ + // this.communitySearchUtils.status = this.errorCodes.NONE; + // } + this.disableForms = false; + if(!this.triggered) { + this.triggerInitialLoad(); + } else { + var table = $('#dpTable').DataTable(); + table.clear(); - this.rerender(); + this.rerender(); + } + + this.communityContentProvidersChanged.emit({ + value: this.communityContentProviders, + }); + }, + err => { + console.log(err); + //TODO check erros (service not available, bad request) + + if(err.status == '404') { + this.communitySearchUtils.status = this.errorCodes.NOT_FOUND; + } else if(err.status == '500') { + this.communitySearchUtils.status = this.errorCodes.ERROR; + } else { + this.communitySearchUtils.status = this.errorCodes.NOT_AVAILABLE; + } + + this.disableForms = false; + if(!this.triggered) { + this.triggerInitialLoad(); + } else { + var table = $('#dpTable').DataTable(); + table.clear(); + + this.rerender(); + } } - - this.communityContentProvidersChanged.emit({ - value: this.communityContentProviders, - }); - }, - err => { - console.log(err); - //TODO check erros (service not available, bad request) - - if(err.status == '404') { - this.communitySearchUtils.status = this.errorCodes.NOT_FOUND; - } else if(err.status == '500') { - this.communitySearchUtils.status = this.errorCodes.ERROR; - } else { - this.communitySearchUtils.status = this.errorCodes.NOT_AVAILABLE; - } - - this.disableForms = false; - if(!this.triggered) { - this.triggerInitialLoad(); - } else { - var table = $('#dpTable').DataTable(); - table.clear(); - - this.rerender(); - } - } - ); + ); + } } } diff --git a/src/app/pages/community/projects/add-projects.component.ts b/src/app/pages/community/projects/add-projects.component.ts index 8c39de9..e44c5d8 100644 --- a/src/app/pages/community/projects/add-projects.component.ts +++ b/src/app/pages/community/projects/add-projects.component.ts @@ -1,5 +1,5 @@ import { Component, ViewChild, OnInit, ViewEncapsulation, Input, Output, EventEmitter } from '@angular/core'; -import { ActivatedRoute } from "@angular/router"; +import { ActivatedRoute, Router } from "@angular/router"; //import { Subject } from 'rxjs/Subject'; import {SearchResult} from '../../../openaireLibrary/utils/entities/searchResult'; import {ErrorCodes} from '../../../openaireLibrary/utils/properties/errorCodes'; @@ -11,6 +11,9 @@ import {RouterHelper} from '../../../openaireLibrary/utils/routerHelper.class'; import {DOI, StringUtils} from '../../../openaireLibrary/utils/string-utils.class'; import {ManageCommunityProjectsService} from '../../../services/manageProjects.service'; +import {Session} from '../../../openaireLibrary/login/utils/helper.class'; +import {LoginErrorCodes} from '../../../openaireLibrary/login/utils/guardHelper.class'; + @Component({ selector: 'add-projects', templateUrl: './add-projects.component.html', @@ -69,7 +72,7 @@ export class AddProjectsComponent implements OnInit { }); } - constructor(private route: ActivatedRoute, private _searchProjectsService: SearchProjectsService, private _manageCommunityProjectsService: ManageCommunityProjectsService) { + constructor(private route: ActivatedRoute, private _router: Router, private _searchProjectsService: SearchProjectsService, private _manageCommunityProjectsService: ManageCommunityProjectsService) { this.errorCodes = new ErrorCodes(); this.openaireSearchUtils.status = this.errorCodes.LOADING; } @@ -90,39 +93,49 @@ export class AddProjectsComponent implements OnInit { } public addProject(project: SearchResult) { - console.info("Add: "+ project.id); - this.subAdd = this._manageCommunityProjectsService.addProject(this.properties, this.community, project).subscribe( - data => { - console.info("data ADD"); - console.info(data); - this.undo[project.id] = data.id; - }, - err => { - console.info("error ADD"); - console.log(err.status); - }, - () => { - console.info("completed ADD"); - } - ) + if(!Session.isLoggedIn()){ + console.info(this._router.url); + this._router.navigate(['/user-info'], { queryParams: { "errorCode": LoginErrorCodes.NOT_VALID, "redirectUrl": this._router.url} }); + } else { + console.info("Add: "+ project.id); + this.subAdd = this._manageCommunityProjectsService.addProject(this.properties, this.community, project).subscribe( + data => { + console.info("data ADD"); + console.info(data); + this.undo[project.id] = data.id; + }, + err => { + console.info("error ADD"); + console.log(err.status); + }, + () => { + console.info("completed ADD"); + } + ) + } } public removeProject(projectId: string, communityProjectId: string) { - console.info("REMOVE: "+ projectId); - this.subRemove = this._manageCommunityProjectsService.removeProject(this.properties, this.community, projectId).subscribe( - data => { - console.info("data REMOVE"); - console.info(data); - }, - err => { - console.info("error REMOVE"); - console.log(err); - }, - () => { - console.info("completed REMOVE"); - this.undo[communityProjectId] = ""; - } - ) + if(!Session.isLoggedIn()){ + console.info(this._router.url); + this._router.navigate(['/user-info'], { queryParams: { "errorCode": LoginErrorCodes.NOT_VALID, "redirectUrl": this._router.url} }); + } else { + console.info("REMOVE: "+ projectId); + this.subRemove = this._manageCommunityProjectsService.removeProject(this.properties, this.community, projectId).subscribe( + data => { + console.info("data REMOVE"); + console.info(data); + }, + err => { + console.info("error REMOVE"); + console.log(err); + }, + () => { + console.info("completed REMOVE"); + this.undo[communityProjectId] = ""; + } + ) + } } public inCommunity(project: any): any { @@ -144,70 +157,80 @@ export class AddProjectsComponent implements OnInit { } getFunders () { - console.info("Getting Funders...."); - this.subFunders = this._searchProjectsService.getFunders(this.properties).subscribe( - data => { - this.funders = data[1]; - }, - err => console.log(err) - ); + if(!Session.isLoggedIn()){ + console.info(this._router.url); + this._router.navigate(['/user-info'], { queryParams: { "errorCode": LoginErrorCodes.NOT_VALID, "redirectUrl": this._router.url} }); + } else { + console.info("Getting Funders...."); + this.subFunders = this._searchProjectsService.getFunders(this.properties).subscribe( + data => { + this.funders = data[1]; + }, + err => console.log(err) + ); + } } private _getOpenaireProjects(parameters:string, page: number, size: number){ - console.info("_getOpenaireProjects"); - if(page > this.pagingLimit) { - size=0; - } + if(!Session.isLoggedIn()){ + console.info(this._router.url); + this._router.navigate(['/user-info'], { queryParams: { "errorCode": LoginErrorCodes.NOT_VALID, "redirectUrl": this._router.url} }); + } else { + console.info("_getOpenaireProjects"); + if(page > this.pagingLimit) { + size=0; + } - if(this.openaireSearchUtils.status == this.errorCodes.LOADING) { - this.openaireSearchUtils.status = this.errorCodes.LOADING; + if(this.openaireSearchUtils.status == this.errorCodes.LOADING) { + this.openaireSearchUtils.status = this.errorCodes.LOADING; - this.disableForms = true; - this.openaireProjects = []; - this.openaireSearchUtils.totalResults = 0; + this.disableForms = true; + this.openaireProjects = []; + this.openaireSearchUtils.totalResults = 0; - this.subResults = this._searchProjectsService.searchProjects(parameters, null, page, size, [], this.properties).subscribe( - data => { - this.undo = {}; - console.info("total openaire projects = "+data[0]); - this.openaireSearchUtils.totalResults = data[0]; - this.openaireProjects = data[1]; + this.subResults = this._searchProjectsService.searchProjects(parameters, null, page, size, [], this.properties).subscribe( + data => { + this.undo = {}; + console.info("total openaire projects = "+data[0]); + this.openaireSearchUtils.totalResults = data[0]; + this.openaireProjects = data[1]; - //this.searchPage.checkSelectedFilters(this.filters); + //this.searchPage.checkSelectedFilters(this.filters); - this.openaireSearchUtils.status = this.errorCodes.DONE; - if(this.openaireSearchUtils.totalResults == 0 ){ - this.openaireSearchUtils.status = this.errorCodes.NONE; - } - - this.disableForms = false; - - if(this.openaireSearchUtils.status == this.errorCodes.DONE) { - // Page out of limit!!! - let totalPages:any = this.openaireSearchUtils.totalResults/(this.openaireSearchUtils.size); - if(!(Number.isInteger(totalPages))) { - totalPages = (parseInt(totalPages, 10) + 1); + this.openaireSearchUtils.status = this.errorCodes.DONE; + if(this.openaireSearchUtils.totalResults == 0 ){ + this.openaireSearchUtils.status = this.errorCodes.NONE; } - if(totalPages < page) { - this.openaireSearchUtils.totalResults = 0; - this.openaireSearchUtils.status = this.errorCodes.OUT_OF_BOUND; - } - } - }, - err => { - console.log(err); - //TODO check erros (service not available, bad request) - if(err.status == '404') { - this.openaireSearchUtils.status = this.errorCodes.NOT_FOUND; - } else if(err.status == '500') { - this.openaireSearchUtils.status = this.errorCodes.ERROR; - } else { - this.openaireSearchUtils.status = this.errorCodes.NOT_AVAILABLE; - } - this.disableForms = false; - } - ); + this.disableForms = false; + + if(this.openaireSearchUtils.status == this.errorCodes.DONE) { + // Page out of limit!!! + let totalPages:any = this.openaireSearchUtils.totalResults/(this.openaireSearchUtils.size); + if(!(Number.isInteger(totalPages))) { + totalPages = (parseInt(totalPages, 10) + 1); + } + if(totalPages < page) { + this.openaireSearchUtils.totalResults = 0; + this.openaireSearchUtils.status = this.errorCodes.OUT_OF_BOUND; + } + } + }, + err => { + console.log(err); + //TODO check erros (service not available, bad request) + if(err.status == '404') { + this.openaireSearchUtils.status = this.errorCodes.NOT_FOUND; + } else if(err.status == '500') { + this.openaireSearchUtils.status = this.errorCodes.ERROR; + } else { + this.openaireSearchUtils.status = this.errorCodes.NOT_AVAILABLE; + } + + this.disableForms = false; + } + ); + } } } diff --git a/src/app/pages/community/projects/manage-projects.component.ts b/src/app/pages/community/projects/manage-projects.component.ts index 02caa8c..385edd4 100644 --- a/src/app/pages/community/projects/manage-projects.component.ts +++ b/src/app/pages/community/projects/manage-projects.component.ts @@ -1,9 +1,12 @@ import { Component, ViewChild, OnInit, ViewEncapsulation, Input } from '@angular/core'; -import { ActivatedRoute } from "@angular/router"; +import { ActivatedRoute, Router } from "@angular/router"; import {RemoveProjectsComponent} from './remove-projects.component'; import {AddProjectsComponent} from './add-projects.component'; +import {Session} from '../../../openaireLibrary/login/utils/helper.class'; +import {LoginErrorCodes} from '../../../openaireLibrary/login/utils/guardHelper.class'; + @Component({ selector: 'manage-projects', template: ` @@ -48,24 +51,29 @@ export class ManageProjectsComponent implements OnInit { }); } - constructor(private route: ActivatedRoute) {} + constructor(private route: ActivatedRoute, private _router: Router) {} public ngOnDestroy() {} public updateCommunityProjects() { - this.toggle = !this.toggle; - if(this.toggle) { - this.pageTitle = "Manage projects"; - // this.toggleLinkMessage = "Missing projects?"; - - //if(this.updateCommunityProjectsOnToggle) { - this.removeProjectsComponent._getCommunityProjects(); - this.addProjectsComponent.undo = {}; - //} + if(!Session.isLoggedIn()){ + console.info(this._router.url); + this._router.navigate(['/user-info'], { queryParams: { "errorCode": LoginErrorCodes.NOT_VALID, "redirectUrl": this._router.url} }); } else { - this.updateCommunityProjectsOnToggle = false; - this.pageTitle = "Search projects"; - //this.toggleLinkMessage = "Manage projects"; + this.toggle = !this.toggle; + if(this.toggle) { + this.pageTitle = "Manage projects"; + // this.toggleLinkMessage = "Missing projects?"; + + //if(this.updateCommunityProjectsOnToggle) { + this.removeProjectsComponent._getCommunityProjects(); + this.addProjectsComponent.undo = {}; + //} + } else { + this.updateCommunityProjectsOnToggle = false; + this.pageTitle = "Search projects"; + //this.toggleLinkMessage = "Manage projects"; + } } } diff --git a/src/app/pages/community/projects/remove-projects.component.ts b/src/app/pages/community/projects/remove-projects.component.ts index bd92dfb..a724279 100644 --- a/src/app/pages/community/projects/remove-projects.component.ts +++ b/src/app/pages/community/projects/remove-projects.component.ts @@ -1,5 +1,5 @@ import { Component, ViewChild, OnInit, ViewEncapsulation, Input, Output, EventEmitter } from '@angular/core'; -import { ActivatedRoute } from "@angular/router"; +import { ActivatedRoute, Router } from "@angular/router"; import { Subject } from 'rxjs/Subject'; import { DataTableDirective } from 'angular-datatables'; @@ -11,6 +11,9 @@ import {SearchCommunityProjectsService} from '../../../openaireLibrary/connect/p import {RouterHelper} from '../../../openaireLibrary/utils/routerHelper.class'; import {DOI, StringUtils} from '../../../openaireLibrary/utils/string-utils.class'; +import {Session} from '../../../openaireLibrary/login/utils/helper.class'; +import {LoginErrorCodes} from '../../../openaireLibrary/login/utils/guardHelper.class'; + @Component({ selector: 'remove-projects', templateUrl: './remove-projects.component.html', @@ -95,7 +98,7 @@ export class RemoveProjectsComponent implements OnInit { this.communitySearchUtils.keyword = ""; } - constructor(private route: ActivatedRoute, private _manageCommunityProjectsService: ManageCommunityProjectsService, private _searchCommunityProjectsService: SearchCommunityProjectsService) { + constructor(private route: ActivatedRoute, private _router: Router, private _manageCommunityProjectsService: ManageCommunityProjectsService, private _searchCommunityProjectsService: SearchCommunityProjectsService) { this.errorCodes = new ErrorCodes(); this.communitySearchUtils.status = this.errorCodes.LOADING; } @@ -215,115 +218,130 @@ export class RemoveProjectsComponent implements OnInit { } public confirmedDeleteProject(data : any) { - console.info("REMOVE: "+ this.selectedCommunityProject.id); - this.subRemove = this._manageCommunityProjectsService.removeProject(this.properties, this.community, this.selectedCommunityProject.id).subscribe( - data => { - console.info("data REMOVE"); - console.info(data); - }, - err => { - console.info("error REMOVE"); - console.log(err); - }, - () => { - console.info("completed REMOVE"); - let index = this.communityProjects.indexOf(this.selectedCommunityProject); - this.communityProjects.splice(index, 1); + if(!Session.isLoggedIn()){ + console.info(this._router.url); + this._router.navigate(['/user-info'], { queryParams: { "errorCode": LoginErrorCodes.NOT_VALID, "redirectUrl": this._router.url} }); + } else { + console.info("REMOVE: "+ this.selectedCommunityProject.id); + this.subRemove = this._manageCommunityProjectsService.removeProject(this.properties, this.community, this.selectedCommunityProject.id).subscribe( + data => { + console.info("data REMOVE"); + console.info(data); + }, + err => { + console.info("error REMOVE"); + console.log(err); + }, + () => { + console.info("completed REMOVE"); + let index = this.communityProjects.indexOf(this.selectedCommunityProject); + this.communityProjects.splice(index, 1); - this.communitySearchUtils.totalResults--; - this.communitySearchUtils.page=1; + this.communitySearchUtils.totalResults--; + this.communitySearchUtils.page=1; - this.rerender(); - } - ) + this.rerender(); + } + ) + } } public removeProject(communityProject: any) { - this.selectedCommunityProject = communityProject; - this.alertModalDeleteCommunity.cancelButton = true; - this.alertModalDeleteCommunity.okButton = true; - this.alertModalDeleteCommunity.alertTitle = "Remove project?"; - let title = ""; - if(communityProject.name) { - title = communityProject.name; + if(!Session.isLoggedIn()){ + console.info(this._router.url); + this._router.navigate(['/user-info'], { queryParams: { "errorCode": LoginErrorCodes.NOT_VALID, "redirectUrl": this._router.url} }); + } else { + this.selectedCommunityProject = communityProject; + this.alertModalDeleteCommunity.cancelButton = true; + this.alertModalDeleteCommunity.okButton = true; + this.alertModalDeleteCommunity.alertTitle = "Remove project?"; + let title = ""; + if(communityProject.name) { + title = communityProject.name; + } + if(communityProject.name && communityProject.acronym) { + title += " ("; + } + if(communityProject.acronym) { + title += communityProject.acronym; + } + if(communityProject.name && communityProject.acronym) { + title += ")"; + } + this.alertModalDeleteCommunity.message = "Project"; + if(title) { + this.alertModalDeleteCommunity.message += " '"+title+"' "; + } + this.alertModalDeleteCommunity.message += "will be removed from your community. Are you sure?"; + this.alertModalDeleteCommunity.okButtonText = "Yes"; + this.alertModalDeleteCommunity.open(); } - if(communityProject.name && communityProject.acronym) { - title += " ("; - } - if(communityProject.acronym) { - title += communityProject.acronym; - } - if(communityProject.name && communityProject.acronym) { - title += ")"; - } - this.alertModalDeleteCommunity.message = "Project"; - if(title) { - this.alertModalDeleteCommunity.message += " '"+title+"' "; - } - this.alertModalDeleteCommunity.message += "will be removed from your community. Are you sure?"; - this.alertModalDeleteCommunity.okButtonText = "Yes"; - this.alertModalDeleteCommunity.open(); } public _getCommunityProjects(){ - this.communitySearchUtils.status = this.errorCodes.LOADING; - this.disableForms = true; - this.communityProjects = []; - this.communitySearchUtils.totalResults = 0; - this.communitySearchUtils.page=1; - this.communitySearchUtils.keyword = ""; - this.selectedFunder = ""; + if(!Session.isLoggedIn()){ + console.info(this._router.url); + this._router.navigate(['/user-info'], { queryParams: { "errorCode": LoginErrorCodes.NOT_VALID, "redirectUrl": this._router.url} }); + } else { + this.communitySearchUtils.status = this.errorCodes.LOADING; + this.disableForms = true; + this.communityProjects = []; + this.communitySearchUtils.totalResults = 0; + this.communitySearchUtils.page=1; + this.communitySearchUtils.keyword = ""; + this.selectedFunder = ""; - this.subResults = this._searchCommunityProjectsService.searchProjects(this.properties, this.community).subscribe( - data => { - console.info(data); - console.info("search Projects [total communityProjects:"+data.length+"]"); - this.communityProjects = data; + this.subResults = this._searchCommunityProjectsService.searchProjects(this.properties, this.community).subscribe( + data => { + console.info(data); + console.info("search Projects [total communityProjects:"+data.length+"]"); + this.communityProjects = data; - this.communitySearchUtils.totalResults = data.length; - this.communitySearchUtils.status = this.errorCodes.DONE; - // if(this.communitySearchUtils.totalResults == 0 ){ - // this.communitySearchUtils.status = this.errorCodes.NONE; - // } - this.disableForms = false; - if(!this.triggered) { - this.triggerInitialLoad(); - } else { - var table = $('#dpTable').DataTable(); - table.clear(); + this.communitySearchUtils.totalResults = data.length; + this.communitySearchUtils.status = this.errorCodes.DONE; + // if(this.communitySearchUtils.totalResults == 0 ){ + // this.communitySearchUtils.status = this.errorCodes.NONE; + // } + this.disableForms = false; + if(!this.triggered) { + this.triggerInitialLoad(); + } else { + var table = $('#dpTable').DataTable(); + table.clear(); - this.rerender(); + this.rerender(); + } + + this.communityProjectsChanged.emit({ + value: this.communityProjects, + }); + + this.createFunderFilter(); + }, + err => { + console.log(err); + //TODO check erros (service not available, bad request) + + if(err.status == '404') { + this.communitySearchUtils.status = this.errorCodes.NOT_FOUND; + } else if(err.status == '500') { + this.communitySearchUtils.status = this.errorCodes.ERROR; + } else { + this.communitySearchUtils.status = this.errorCodes.NOT_AVAILABLE; + } + + this.disableForms = false; + if(!this.triggered) { + this.triggerInitialLoad(); + } else { + var table = $('#dpTable').DataTable(); + table.clear(); + + this.rerender(); + } } - - this.communityProjectsChanged.emit({ - value: this.communityProjects, - }); - - this.createFunderFilter(); - }, - err => { - console.log(err); - //TODO check erros (service not available, bad request) - - if(err.status == '404') { - this.communitySearchUtils.status = this.errorCodes.NOT_FOUND; - } else if(err.status == '500') { - this.communitySearchUtils.status = this.errorCodes.ERROR; - } else { - this.communitySearchUtils.status = this.errorCodes.NOT_AVAILABLE; - } - - this.disableForms = false; - if(!this.triggered) { - this.triggerInitialLoad(); - } else { - var table = $('#dpTable').DataTable(); - table.clear(); - - this.rerender(); - } - } - ); + ); + } } private createFunderFilter(): Set { diff --git a/src/app/pages/divId/divId-form.component.ts b/src/app/pages/divId/divId-form.component.ts index db491cb..01bd161 100644 --- a/src/app/pages/divId/divId-form.component.ts +++ b/src/app/pages/divId/divId-form.component.ts @@ -1,10 +1,13 @@ import {Component, OnInit, Input} from '@angular/core'; -import { ActivatedRoute } from "@angular/router"; +import { ActivatedRoute, Router } from "@angular/router"; import {FormGroup, FormArray, FormBuilder, Validators} from "@angular/forms"; import { HelpContentService } from "../../services/help-content.service"; import { Page } from "../../domain/page"; import { EnvProperties } from '../../openaireLibrary/utils/properties/env-properties'; +import {Session} from '../../openaireLibrary/login/utils/helper.class'; +import {LoginErrorCodes} from '../../openaireLibrary/login/utils/guardHelper.class'; + @Component({ selector: 'divId-form', templateUrl: './divId-form.component.html', @@ -27,7 +30,7 @@ export class DivIdFormComponent implements OnInit{ public showLoading: boolean = false; public errorMessage: string = ''; selectedCommunityPid = null; - constructor(private route: ActivatedRoute, public _fb: FormBuilder, private _helpContentService: HelpContentService){} + constructor(private route: ActivatedRoute, private _router: Router, public _fb: FormBuilder, private _helpContentService: HelpContentService){} ngOnInit(): void { this.route.data @@ -44,49 +47,59 @@ export class DivIdFormComponent implements OnInit{ } getPages(includedPages: Set) { - this.showLoading = true; - this.errorMessage = ""; + if(!Session.isLoggedIn()){ + console.info(this._router.url); + this._router.navigate(['/user-info'], { queryParams: { "errorCode": LoginErrorCodes.NOT_VALID, "redirectUrl": this._router.url} }); + } else { + this.showLoading = true; + this.errorMessage = ""; - this._helpContentService.getPages(this.properties.adminToolsAPIURL,this.selectedCommunityPid).subscribe( - pages => { - //this.allPages = allPages; - for(let page of pages) { - if(includedPages.has(page._id)) { - this.allPages.set(page, true); - } else { - this.allPages.set(page, false); + this._helpContentService.getPages(this.properties.adminToolsAPIURL,this.selectedCommunityPid).subscribe( + pages => { + //this.allPages = allPages; + for(let page of pages) { + if(includedPages.has(page._id)) { + this.allPages.set(page, true); + } else { + this.allPages.set(page, false); + } } - } - this.showLoading = false; - }, - error => this.handleError('System error retrieving pages', error) - ); + this.showLoading = false; + }, + error => this.handleError('System error retrieving pages', error) + ); + } } public toggle() { - this.myForm.value.isCollapsed = !this.myForm.value.isCollapsed; -/////// - if(!this.myForm.value.isCollapsed) { - let includedPages: Set = new Set(); - for(let pageName of this.myForm.value.pages) { - includedPages.add(pageName._id); - } - - let allPages = this.allPages; - - let self = this; - allPages.forEach(function (status, page, map) { - if(includedPages.has(page._id)) { - self.allPages.set(page, true); - } else { - self.allPages.set(page, false); + if(!Session.isLoggedIn()){ + console.info(this._router.url); + this._router.navigate(['/user-info'], { queryParams: { "errorCode": LoginErrorCodes.NOT_VALID, "redirectUrl": this._router.url} }); + } else { + this.myForm.value.isCollapsed = !this.myForm.value.isCollapsed; + /////// + if(!this.myForm.value.isCollapsed) { + let includedPages: Set = new Set(); + for(let pageName of this.myForm.value.pages) { + includedPages.add(pageName._id); } - }); + + let allPages = this.allPages; + + let self = this; + allPages.forEach(function (status, page, map) { + if(includedPages.has(page._id)) { + self.allPages.set(page, true); + } else { + self.allPages.set(page, false); + } + }); - if(!this.gotPages) { - this.gotPages = true; - this.getPages(includedPages); + if(!this.gotPages) { + this.gotPages = true; + this.getPages(includedPages); + } } } ///// @@ -149,21 +162,26 @@ export class DivIdFormComponent implements OnInit{ } }*/ - let index: number = -1; - for(let i=0; i= 0) { - this.myForm.value.pages.splice(index, 1); + if(status && index<0) { + this.myForm.value.pages.push(page); + } else if(!status){ + if(index >= 0) { + this.myForm.value.pages.splice(index, 1); + } } } } diff --git a/src/app/pages/divId/divIds.component.ts b/src/app/pages/divId/divIds.component.ts index a632441..e807e7a 100644 --- a/src/app/pages/divId/divIds.component.ts +++ b/src/app/pages/divId/divIds.component.ts @@ -1,5 +1,5 @@ import { Component, ViewChild, OnInit } from '@angular/core'; -import { ActivatedRoute } from "@angular/router"; +import { ActivatedRoute, Router } from "@angular/router"; import { HelpContentService } from "../../services/help-content.service"; import { FormGroup } from "@angular/forms"; import { ModalFormComponent } from "../modal-form.component"; @@ -10,6 +10,9 @@ import { CheckDivId, DivId } from "../../domain/divId"; import { Page } from "../../domain/page"; import { EnvProperties } from '../../openaireLibrary/utils/properties/env-properties'; +import {Session} from '../../openaireLibrary/login/utils/helper.class'; +import {LoginErrorCodes} from '../../openaireLibrary/login/utils/guardHelper.class'; + @Component({ selector: 'divIds', templateUrl: './divIds.component.html', @@ -63,9 +66,13 @@ export class DivIdsComponent implements OnInit { }); } - constructor(private route: ActivatedRoute, private _helpContentService: HelpContentService) {} + constructor(private route: ActivatedRoute, private _router: Router, private _helpContentService: HelpContentService) {} getDivIds() { + if(!Session.isLoggedIn()){ + console.info(this._router.url); + this._router.navigate(['/user-info'], { queryParams: { "errorCode": LoginErrorCodes.NOT_VALID, "redirectUrl": this._router.url} }); + } else { this.showLoading = true; this.updateErrorMessage = ""; this.errorMessage = ""; @@ -83,6 +90,7 @@ export class DivIdsComponent implements OnInit { this.showLoading = false; }, error => this.handleError('System error retrieving classes', error)); + } } // public showModal():void { @@ -124,15 +132,24 @@ export class DivIdsComponent implements OnInit { } private confirmModalOpen() { - this.alertModalDeleteDivIds.cancelButton = true; - this.alertModalDeleteDivIds.okButton = true; - this.alertModalDeleteDivIds.alertTitle = "Delete Confirmation"; - this.alertModalDeleteDivIds.message = "Are you sure you want to delete the selected class(es)?"; - this.alertModalDeleteDivIds.okButtonText = "Yes"; - this.alertModalDeleteDivIds.open(); + if(!Session.isLoggedIn()){ + console.info(this._router.url); + this._router.navigate(['/user-info'], { queryParams: { "errorCode": LoginErrorCodes.NOT_VALID, "redirectUrl": this._router.url} }); + } else { + this.alertModalDeleteDivIds.cancelButton = true; + this.alertModalDeleteDivIds.okButton = true; + this.alertModalDeleteDivIds.alertTitle = "Delete Confirmation"; + this.alertModalDeleteDivIds.message = "Are you sure you want to delete the selected class(es)?"; + this.alertModalDeleteDivIds.okButtonText = "Yes"; + this.alertModalDeleteDivIds.open(); + } } public confirmedDeleteDivIds(data: any) { + if(!Session.isLoggedIn()){ + console.info(this._router.url); + this._router.navigate(['/user-info'], { queryParams: { "errorCode": LoginErrorCodes.NOT_VALID, "redirectUrl": this._router.url} }); + } else { this.showLoading = true; this.updateErrorMessage = ""; @@ -143,6 +160,7 @@ export class DivIdsComponent implements OnInit { }, error => this.handleUpdateError('System error deleting the selected classes', error) ); + } } public editDivId(i : number) { @@ -170,39 +188,54 @@ export class DivIdsComponent implements OnInit { } private divIdsModalOpen(modal: any, title: string, yesBtn: string) { - modal.cancelButton = true; - modal.okButton = true; - modal.alertTitle = title; - modal.okButtonText = yesBtn; - modal.open(); + if(!Session.isLoggedIn()){ + console.info(this._router.url); + 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 divIdSaveConfirmed(data: any) { - if(!this.formGroup.valid) { - this.divIdsModalOpen(this.alertModalSaveDivId, "Save", "Add a new Class"); - this.modalErrorMessage = "Please fill in all required fields marked with *"; + if(!Session.isLoggedIn()){ + console.info(this._router.url); + this._router.navigate(['/user-info'], { queryParams: { "errorCode": LoginErrorCodes.NOT_VALID, "redirectUrl": this._router.url} }); } else { - this.modalErrorMessage = ""; - this._helpContentService.saveDivId( this.formGroup.value, this.properties.adminToolsAPIURL).subscribe( - divId => { - this.divIdSavedSuccessfully(divId); - }, - error => this.handleUpdateError("System error creating class", error) - ); + if(!this.formGroup.valid) { + this.divIdsModalOpen(this.alertModalSaveDivId, "Save", "Add a new Class"); + this.modalErrorMessage = "Please fill in all required fields marked with *"; + } else { + this.modalErrorMessage = ""; + this._helpContentService.saveDivId( this.formGroup.value, this.properties.adminToolsAPIURL).subscribe( + divId => { + this.divIdSavedSuccessfully(divId); + }, + error => this.handleUpdateError("System error creating class", error) + ); + } } } public divIdUpdateConfirmed(data: any) { - if(!this.formGroup.valid) { - this.divIdsModalOpen(this.alertModalUpdateDivId, "Update", "Update Class"); - this.modalErrorMessage = "Please fill in all required fields marked with *"; + if(!Session.isLoggedIn()){ + console.info(this._router.url); + this._router.navigate(['/user-info'], { queryParams: { "errorCode": LoginErrorCodes.NOT_VALID, "redirectUrl": this._router.url} }); } else { - this._helpContentService.updateDivId( this.formGroup.value, this.properties.adminToolsAPIURL).subscribe( - divId => { - this.divIdUpdatedSuccessfully(divId); - }, - error => this.handleUpdateError("System error updating class", error) - ); + if(!this.formGroup.valid) { + this.divIdsModalOpen(this.alertModalUpdateDivId, "Update", "Update Class"); + this.modalErrorMessage = "Please fill in all required fields marked with *"; + } else { + this._helpContentService.updateDivId( this.formGroup.value, this.properties.adminToolsAPIURL).subscribe( + divId => { + this.divIdUpdatedSuccessfully(divId); + }, + error => this.handleUpdateError("System error updating class", error) + ); + } } } diff --git a/src/app/pages/divhelpcontent/div-help-content-form.component.ts b/src/app/pages/divhelpcontent/div-help-content-form.component.ts index 872e3d2..27865e5 100644 --- a/src/app/pages/divhelpcontent/div-help-content-form.component.ts +++ b/src/app/pages/divhelpcontent/div-help-content-form.component.ts @@ -1,11 +1,13 @@ import { Component, OnInit, Input } from '@angular/core'; -import { ActivatedRoute } from "@angular/router"; +import { ActivatedRoute, Router } from "@angular/router"; import { FormGroup, FormBuilder, Validators } from "@angular/forms"; import { Page } from "../../domain/page"; import { DivId } from "../../domain/divId"; import { HelpContentService } from "../../services/help-content.service"; import { EnvProperties } from '../../openaireLibrary/utils/properties/env-properties'; +import {Session} from '../../openaireLibrary/login/utils/helper.class'; +import {LoginErrorCodes} from '../../openaireLibrary/login/utils/guardHelper.class'; @Component({ selector: 'div-content-form', @@ -41,7 +43,7 @@ export class DivContentFormComponent implements OnInit{ public errorMessage: string = ''; @Input() updateErrorMessage: string = ''; - constructor(private route: ActivatedRoute, private _fb: FormBuilder, private _helpContentService: HelpContentService){} + constructor(private route: ActivatedRoute, private _router: Router, private _fb: FormBuilder, private _helpContentService: HelpContentService){} ngOnInit() { this.myForm = this.form; @@ -50,28 +52,38 @@ export class DivContentFormComponent implements OnInit{ this.properties = data.envSpecific; this.route.queryParams.subscribe(params => { - if(this.pageId) { - this.showPageSelect = false; - this.getDivs(this.pageId); + if(!Session.isLoggedIn()){ + console.info(this._router.url); + this._router.navigate(['/user-info'], { queryParams: { "errorCode": LoginErrorCodes.NOT_VALID, "redirectUrl": this._router.url} }); } 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)); - } - } + 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); + this.getCommunity(this.communityPid); + } }); }); } public pageSelected(event) { - this.getDivs(event.target.value); + if(!Session.isLoggedIn()){ + console.info(this._router.url); + this._router.navigate(['/user-info'], { queryParams: { "errorCode": LoginErrorCodes.NOT_VALID, "redirectUrl": this._router.url} }); + } else { + this.getDivs(event.target.value); + } } public divIdSelected(div: DivId) { @@ -79,34 +91,44 @@ export class DivContentFormComponent implements OnInit{ } public getCommunity(communityPid: string) { - this.showLoading = true; - this.errorMessage = ''; + if(!Session.isLoggedIn()){ + console.info(this._router.url); + 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._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) - ); + this.myForm.patchValue({ + community: this.communityId + }); + this.showLoading = false; + }, + error => this.handleError('System error retrieving community', error) + ); + } } public getDivs(pageId: string) { - this.showLoading = true; - this.errorMessage = ''; + if(!Session.isLoggedIn()){ + console.info(this._router.url); + 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).subscribe( - divs => { - this.availableDivs = divs; - this.pageId = pageId; + this._helpContentService.getDivIdsFull(pageId, this.properties.adminToolsAPIURL).subscribe( + divs => { + this.availableDivs = divs; + this.pageId = pageId; - this.showLoading = false; - }, - error => this.handleError('System error retrieving pages', error)); + this.showLoading = false; + }, + error => this.handleError('System error retrieving pages', error)); + } } // public selectedDiv(event) { diff --git a/src/app/pages/divhelpcontent/div-help-contents.component.ts b/src/app/pages/divhelpcontent/div-help-contents.component.ts index 22c94eb..ecce306 100644 --- a/src/app/pages/divhelpcontent/div-help-contents.component.ts +++ b/src/app/pages/divhelpcontent/div-help-contents.component.ts @@ -10,6 +10,9 @@ import { DivId } from "../../domain/divId"; import { EnvProperties } from '../../openaireLibrary/utils/properties/env-properties'; import {SafeHtmlPipe} from '../../openaireLibrary/utils/pipes/safeHTML.pipe'; +import {Session} from '../../openaireLibrary/login/utils/helper.class'; +import {LoginErrorCodes} from '../../openaireLibrary/login/utils/guardHelper.class'; + @Component({ selector: 'div-help-contents', templateUrl: './div-help-contents.component.html', @@ -75,19 +78,28 @@ export class DivHelpContentsComponent implements OnInit { constructor(private route: ActivatedRoute, private _helpService: HelpContentService, private router : Router) {} getPage(pageId: string) { - this.showLoading = true; - this.updateErrorMessage = ""; - this.errorMessage = ""; + if(!Session.isLoggedIn()){ + console.info(this.router.url); + 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 => { - this.page = page; - this.getDivHelpContents(this.selectedCommunityPid); - }, - error => this.handleError('System error retrieving page', error)); + this._helpService.getPage(pageId, this.properties.adminToolsAPIURL).subscribe( + page => { + this.page = page; + this.getDivHelpContents(this.selectedCommunityPid); + }, + error => this.handleError('System error retrieving page', error)); + } } getPages(community_pid: string) { + if(!Session.isLoggedIn()){ + console.info(this.router.url); + this.router.navigate(['/user-info'], { queryParams: { "errorCode": LoginErrorCodes.NOT_VALID, "redirectUrl": this.router.url} }); + } else { this.showLoading = true; this.updateErrorMessage = ""; this.errorMessage = ""; @@ -98,6 +110,7 @@ export class DivHelpContentsComponent implements OnInit { this.getDivHelpContents(this.selectedCommunityPid); }, error => this.handleError('System error retrieving pages', error)); + } } public countDivHelpContents() { @@ -114,6 +127,10 @@ export class DivHelpContentsComponent implements OnInit { } getDivHelpContents(community_pid: string) { + if(!Session.isLoggedIn()){ + console.info(this.router.url); + 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; @@ -137,6 +154,7 @@ export class DivHelpContentsComponent implements OnInit { this.showLoading = false; }, error => this.handleError('System error retrieving page contents', error)); + } } public toggleCheckBoxes(event) { @@ -169,15 +187,24 @@ export class DivHelpContentsComponent implements OnInit { } private confirmModalOpen() { - 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(); + if(!Session.isLoggedIn()){ + console.info(this.router.url); + 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()){ + console.info(this.router.url); + this.router.navigate(['/user-info'], { queryParams: { "errorCode": LoginErrorCodes.NOT_VALID, "redirectUrl": this.router.url} }); + } else { this.showLoading = true; this.updateErrorMessage = ""; @@ -188,6 +215,7 @@ export class DivHelpContentsComponent implements OnInit { }, error => this.handleUpdateError('System error deleting the selected class content(s)', error) ); + } } private deleteDivHelpContentsFromArray(ids : string[]) : void { @@ -210,6 +238,10 @@ export class DivHelpContentsComponent implements OnInit { } public toggleDivHelpContents(status : boolean, ids : string[]) { + if(!Session.isLoggedIn()){ + console.info(this.router.url); + this.router.navigate(['/user-info'], { queryParams: { "errorCode": LoginErrorCodes.NOT_VALID, "redirectUrl": this.router.url} }); + } else { this.showLoading = true; this.updateErrorMessage = ""; @@ -226,6 +258,7 @@ export class DivHelpContentsComponent implements OnInit { }, error => this.handleUpdateError('System error changing the status of the selected page content(s)', error) ); + } } public divHelpContentSavedSuccessfully(divHelpContent: DivHelpContent) { diff --git a/src/app/pages/divhelpcontent/edit-div-help-content.component.ts b/src/app/pages/divhelpcontent/edit-div-help-content.component.ts index 7f15e3c..8dc27d8 100644 --- a/src/app/pages/divhelpcontent/edit-div-help-content.component.ts +++ b/src/app/pages/divhelpcontent/edit-div-help-content.component.ts @@ -6,6 +6,9 @@ import { DivHelpContent } from "../../domain/div-help-content"; import { ActivatedRoute, Router } from "@angular/router"; import { EnvProperties } from '../../openaireLibrary/utils/properties/env-properties'; +import {Session} from '../../openaireLibrary/login/utils/helper.class'; +import {LoginErrorCodes} from '../../openaireLibrary/login/utils/guardHelper.class'; + @Component({ selector: 'edit-div-help-content', templateUrl: 'edit-div-help-content.component.html', @@ -65,19 +68,28 @@ export class EditDivHelpContentComponent implements OnInit, OnDestroy{ } private getDivHelpContent(divContentId: string) { - this.showLoading = true; - this.errorMessage = ""; - this.updateErrorMessage = ""; + if(!Session.isLoggedIn()){ + console.info(this.router.url); + 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 => { - this.updateForm(divHelpContent); - this.showLoading = false; - }, - error => this.handleError('System error retrieving class help content', error)); + this._helpContentService.getDivHelpContent(divContentId, this.properties.adminToolsAPIURL).subscribe( + divHelpContent => { + this.updateForm(divHelpContent); + this.showLoading = false; + }, + error => this.handleError('System error retrieving class help content', error)); + } } getDivId(divId: string) { + if(!Session.isLoggedIn()){ + console.info(this.router.url); + 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( @@ -87,11 +99,12 @@ export class EditDivHelpContentComponent implements OnInit, OnDestroy{ if(!this.pageId) { this.formComponent.getDivs(""); } - + this.showLoading = false; }, error => this.handleError('System error retrieving class', error) ); + } } private updateForm(divHelpContent : DivHelpContent) { @@ -103,6 +116,10 @@ export class EditDivHelpContentComponent implements OnInit, OnDestroy{ } private saveCustom() { + if(!Session.isLoggedIn()){ + console.info(this.router.url); + 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 = ""; @@ -124,6 +141,7 @@ export class EditDivHelpContentComponent implements OnInit, OnDestroy{ } else { this.errorMessage = "Please fill all required fields"; } + } } private cancelCustom() { diff --git a/src/app/pages/divhelpcontent/new-div-help-content.component.ts b/src/app/pages/divhelpcontent/new-div-help-content.component.ts index 4995754..f49461c 100644 --- a/src/app/pages/divhelpcontent/new-div-help-content.component.ts +++ b/src/app/pages/divhelpcontent/new-div-help-content.component.ts @@ -5,6 +5,9 @@ import { DivHelpContent } from "../../domain/div-help-content"; import { HelpContentService } from "../../services/help-content.service"; import { EnvProperties } from '../../openaireLibrary/utils/properties/env-properties'; +import {Session} from '../../openaireLibrary/login/utils/helper.class'; +import {LoginErrorCodes} from '../../openaireLibrary/login/utils/guardHelper.class'; + @Component({ selector: 'new-div-help-content', templateUrl: 'new-div-help-content.component.html', @@ -43,6 +46,10 @@ export class NewDivHelpContentComponent { } private saveCustom() { + if(!Session.isLoggedIn()){ + console.info(this.router.url); + 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 = ""; @@ -64,6 +71,7 @@ export class NewDivHelpContentComponent { } else { this.errorMessage = "Please fill all required fields"; } + } } private cancelCustom() { diff --git a/src/app/pages/entity/entities.component.ts b/src/app/pages/entity/entities.component.ts index f302253..deff8fb 100644 --- a/src/app/pages/entity/entities.component.ts +++ b/src/app/pages/entity/entities.component.ts @@ -1,5 +1,5 @@ import { Component, ViewChild, OnInit } from '@angular/core'; -import { ActivatedRoute } from "@angular/router"; +import { ActivatedRoute, Router } from "@angular/router"; import { HelpContentService } from "../../services/help-content.service"; import { FormGroup } from "@angular/forms"; import { ModalFormComponent } from "../modal-form.component"; @@ -9,6 +9,7 @@ import { CheckEntity, Entity } from "../../domain/entity"; import { Community } from "../../domain/community"; import { EnvProperties } from '../../openaireLibrary/utils/properties/env-properties'; import {Session} from '../../openaireLibrary/login/utils/helper.class'; +import {LoginErrorCodes} from '../../openaireLibrary/login/utils/guardHelper.class'; @Component({ selector: 'entities', @@ -68,8 +69,12 @@ export class EntitiesComponent implements OnInit { } - constructor(private route: ActivatedRoute, private _helpContentService: HelpContentService) {} + constructor(private route: ActivatedRoute, private _router: Router, private _helpContentService: HelpContentService) {} getEntities(community_pid: string) { + if(!Session.isLoggedIn()){ + console.info(this._router.url); + this._router.navigate(['/user-info'], { queryParams: { "errorCode": LoginErrorCodes.NOT_VALID, "redirectUrl": this._router.url} }); + } else { this.showLoading = true; this.updateErrorMessage = ""; this.errorMessage = ""; @@ -87,6 +92,7 @@ export class EntitiesComponent implements OnInit { this.showLoading = false; }, error => this.handleError('System error retrieving entities', error)); + } } // public showModal():void { @@ -128,15 +134,24 @@ export class EntitiesComponent implements OnInit { } private confirmDeleteEntitiesModalOpen() { - this.alertModalDeleteEntities.cancelButton = true; - this.alertModalDeleteEntities.okButton = true; - this.alertModalDeleteEntities.alertTitle = "Delete Confirmation"; - this.alertModalDeleteEntities.message = "Are you sure you want to delete the selected entity(-ies)?"; - this.alertModalDeleteEntities.okButtonText = "Yes"; - this.alertModalDeleteEntities.open(); + if(!Session.isLoggedIn()){ + console.info(this._router.url); + this._router.navigate(['/user-info'], { queryParams: { "errorCode": LoginErrorCodes.NOT_VALID, "redirectUrl": this._router.url} }); + } else { + this.alertModalDeleteEntities.cancelButton = true; + this.alertModalDeleteEntities.okButton = true; + this.alertModalDeleteEntities.alertTitle = "Delete Confirmation"; + this.alertModalDeleteEntities.message = "Are you sure you want to delete the selected entity(-ies)?"; + this.alertModalDeleteEntities.okButtonText = "Yes"; + this.alertModalDeleteEntities.open(); + } } public confirmedDeleteEntities(data: any) { + if(!Session.isLoggedIn()){ + console.info(this._router.url); + this._router.navigate(['/user-info'], { queryParams: { "errorCode": LoginErrorCodes.NOT_VALID, "redirectUrl": this._router.url} }); + } else { this.showLoading = true; this.updateErrorMessage = ""; @@ -147,6 +162,7 @@ export class EntitiesComponent implements OnInit { }, error => this.handleUpdateError('System error deleting the selected entities', error) ); + } } public editEntity(i : number) { @@ -164,39 +180,54 @@ export class EntitiesComponent implements OnInit { } private entitiesModalOpen(modal: any, title: string, yesBtn: string) { - modal.cancelButton = true; - modal.okButton = true; - modal.alertTitle = title; - modal.okButtonText = yesBtn; - modal.open(); + if(!Session.isLoggedIn()){ + console.info(this._router.url); + 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 entitySaveConfirmed(data: any) { - if(!this.formGroup.valid) { - this.entitiesModalOpen(this.alertModalSaveEntity, "Save", "Add a new Entity"); - this.modalErrorMessage = "Please fill in all required fields marked with *"; + if(!Session.isLoggedIn()){ + console.info(this._router.url); + this._router.navigate(['/user-info'], { queryParams: { "errorCode": LoginErrorCodes.NOT_VALID, "redirectUrl": this._router.url} }); } else { - this.modalErrorMessage = ""; - this._helpContentService.saveEntity( this.formGroup.value, this.properties.adminToolsAPIURL).subscribe( - entity => { - this.entitySavedSuccessfully(entity); - }, - error => this.handleUpdateError("System error creating entity", error) - ); + if(!this.formGroup.valid) { + this.entitiesModalOpen(this.alertModalSaveEntity, "Save", "Add a new Entity"); + this.modalErrorMessage = "Please fill in all required fields marked with *"; + } else { + this.modalErrorMessage = ""; + this._helpContentService.saveEntity( this.formGroup.value, this.properties.adminToolsAPIURL).subscribe( + entity => { + this.entitySavedSuccessfully(entity); + }, + error => this.handleUpdateError("System error creating entity", error) + ); + } } } public entityUpdateConfirmed(data: any) { - if(!this.formGroup.valid) { - this.entitiesModalOpen(this.alertModalUpdateEntity, "Update", "Update Entity"); - this.modalErrorMessage = "Please fill in all required fields marked with *"; + if(!Session.isLoggedIn()){ + console.info(this._router.url); + this._router.navigate(['/user-info'], { queryParams: { "errorCode": LoginErrorCodes.NOT_VALID, "redirectUrl": this._router.url} }); } else { - this._helpContentService.updateEntity( this.formGroup.value, this.properties.adminToolsAPIURL).subscribe( - entity => { - this.entityUpdatedSuccessfully(entity); - }, - error => this.handleUpdateError("System error updating entity", error) - ); + if(!this.formGroup.valid) { + this.entitiesModalOpen(this.alertModalUpdateEntity, "Update", "Update Entity"); + this.modalErrorMessage = "Please fill in all required fields marked with *"; + } else { + this._helpContentService.updateEntity( this.formGroup.value, this.properties.adminToolsAPIURL).subscribe( + entity => { + this.entityUpdatedSuccessfully(entity); + }, + error => this.handleUpdateError("System error updating entity", error) + ); + } } } @@ -257,29 +288,39 @@ export class EntitiesComponent implements OnInit { } private confirmRelatedPagesModalOpen() { - this.alertModalRelatedPages.cancelButton = true; - this.alertModalRelatedPages.okButton = true; - this.alertModalRelatedPages.alertTitle = "Warning"; - this.alertModalRelatedPages.message = "This action will affect all search pages related to this entity! Pages' status will change to entity's status! Do you want to continue?"; - this.alertModalRelatedPages.okButtonText = "Yes"; - this.alertModalRelatedPages.open(); + if(!Session.isLoggedIn()){ + console.info(this._router.url); + this._router.navigate(['/user-info'], { queryParams: { "errorCode": LoginErrorCodes.NOT_VALID, "redirectUrl": this._router.url} }); + } else { + this.alertModalRelatedPages.cancelButton = true; + this.alertModalRelatedPages.okButton = true; + this.alertModalRelatedPages.alertTitle = "Warning"; + this.alertModalRelatedPages.message = "This action will affect all search pages related to this entity! Pages' status will change to entity's status! Do you want to continue?"; + this.alertModalRelatedPages.okButtonText = "Yes"; + this.alertModalRelatedPages.open(); + } } public continueToggling(event: any) { - this.showLoading = true; - this.updateErrorMessage = ""; + if(!Session.isLoggedIn()){ + console.info(this._router.url); + this._router.navigate(['/user-info'], { queryParams: { "errorCode": LoginErrorCodes.NOT_VALID, "redirectUrl": this._router.url} }); + } else { + this.showLoading = true; + this.updateErrorMessage = ""; - this._helpContentService.toggleEntities(this.selectedCommunityPid,this.toggleIds,this.toggleStatus, this.properties.adminToolsAPIURL).subscribe( - () => { - for(let id of this.toggleIds) { - let i = this.checkboxes.findIndex(_ => _.entity._id == id); - this.checkboxes[i].entity.isEnabled=this.toggleStatus; - } - this.applyCheck(false); - this.showLoading = false; - }, - error => this.handleUpdateError('System error changing the status of the selected entity(-ies)', error) - ); + this._helpContentService.toggleEntities(this.selectedCommunityPid,this.toggleIds,this.toggleStatus, this.properties.adminToolsAPIURL).subscribe( + () => { + for(let id of this.toggleIds) { + let i = this.checkboxes.findIndex(_ => _.entity._id == id); + this.checkboxes[i].entity.isEnabled=this.toggleStatus; + } + this.applyCheck(false); + this.showLoading = false; + }, + error => this.handleUpdateError('System error changing the status of the selected entity(-ies)', error) + ); + } } } diff --git a/src/app/pages/helpcontent/edit-page-help-content.component.ts b/src/app/pages/helpcontent/edit-page-help-content.component.ts index 6b9de4b..b6d4ec2 100644 --- a/src/app/pages/helpcontent/edit-page-help-content.component.ts +++ b/src/app/pages/helpcontent/edit-page-help-content.component.ts @@ -9,6 +9,9 @@ import { PageHelpContent } from "../../domain/page-help-content"; import { ActivatedRoute, Router } from "@angular/router"; import { EnvProperties } from '../../openaireLibrary/utils/properties/env-properties'; +import {Session} from '../../openaireLibrary/login/utils/helper.class'; +import {LoginErrorCodes} from '../../openaireLibrary/login/utils/guardHelper.class'; + @Component({ selector: 'edit-page-help-content', templateUrl: 'edit-page-help-content.component.html', @@ -69,16 +72,21 @@ export class EditPageHelpContentComponent implements OnInit, OnDestroy{ } private getPageHelpContent(pageContentId: string) { - this.showLoading = true; - this.errorMessage = ""; - this.updateErrorMessage = ""; + if(!Session.isLoggedIn()){ + console.info(this.router.url); + 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 => { - this.updateForm(pageHelpContent); - this.showLoading = false; - }, - error => this.handleError('System error retrieving page help content', error)); + this._helpContentService.getPageHelpContent(pageContentId as string, this.properties.adminToolsAPIURL).subscribe( + pageHelpContent => { + this.updateForm(pageHelpContent); + this.showLoading = false; + }, + error => this.handleError('System error retrieving page help content', error)); + } } private updateForm(pageHelpContent : PageHelpContent) { @@ -89,6 +97,10 @@ export class EditPageHelpContentComponent implements OnInit, OnDestroy{ } private saveCustom() { + if(!Session.isLoggedIn()){ + console.info(this.router.url); + 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 = ""; @@ -109,6 +121,7 @@ export class EditPageHelpContentComponent implements OnInit, OnDestroy{ } else { this.errorMessage = "Please fill all required fields"; } + } } private cancelCustom() { diff --git a/src/app/pages/helpcontent/new-page-help-content.component.ts b/src/app/pages/helpcontent/new-page-help-content.component.ts index d18d4c7..4ebb9b4 100644 --- a/src/app/pages/helpcontent/new-page-help-content.component.ts +++ b/src/app/pages/helpcontent/new-page-help-content.component.ts @@ -8,6 +8,9 @@ import { PageHelpContent } from "../../domain/page-help-content"; import { HelpContentService } from "../../services/help-content.service"; import { EnvProperties } from '../../openaireLibrary/utils/properties/env-properties'; +import {Session} from '../../openaireLibrary/login/utils/helper.class'; +import {LoginErrorCodes} from '../../openaireLibrary/login/utils/guardHelper.class'; + @Component({ selector: 'new-page-help-content', templateUrl: 'new-page-help-content.component.html', @@ -46,7 +49,10 @@ export class NewPageHelpContentComponent { } private saveCustom() { - + if(!Session.isLoggedIn()){ + console.info(this.router.url); + this.router.navigate(['/user-info'], { queryParams: { "errorCode": LoginErrorCodes.NOT_VALID, "redirectUrl": this.router.url} }); + } else { //this.errorMessage = null; if(this.formComponent.myForm.valid) { @@ -69,6 +75,7 @@ export class NewPageHelpContentComponent { } else { this.errorMessage = "Please fill all required fields"; } + } } private cancelCustom() { diff --git a/src/app/pages/helpcontent/page-help-content-form.component.ts b/src/app/pages/helpcontent/page-help-content-form.component.ts index 56d25c8..570308b 100644 --- a/src/app/pages/helpcontent/page-help-content-form.component.ts +++ b/src/app/pages/helpcontent/page-help-content-form.component.ts @@ -1,10 +1,12 @@ import { Component, OnInit, Input } from '@angular/core'; -import { ActivatedRoute } from "@angular/router"; +import { ActivatedRoute, Router } from "@angular/router"; import { FormGroup, FormBuilder, Validators } from "@angular/forms"; import { Page } from "../../domain/page"; import { HelpContentService } from "../../services/help-content.service"; import { EnvProperties } from '../../openaireLibrary/utils/properties/env-properties'; +import {Session} from '../../openaireLibrary/login/utils/helper.class'; +import {LoginErrorCodes} from '../../openaireLibrary/login/utils/guardHelper.class'; @Component({ selector: 'page-content-form', @@ -30,7 +32,7 @@ export class PageContentFormComponent implements OnInit{ public errorMessage: string = ''; @Input() updateErrorMessage: string = ''; - constructor(private route: ActivatedRoute,private _fb: FormBuilder, private _helpContentService: HelpContentService){} + constructor(private route: ActivatedRoute, private _router: Router, private _fb: FormBuilder, private _helpContentService: HelpContentService){} ngOnInit() { this.myForm = this.form; @@ -38,12 +40,17 @@ export class PageContentFormComponent implements OnInit{ .subscribe((data: { envSpecific: EnvProperties }) => { this.properties = data.envSpecific; - this._helpContentService.getPages(this.properties.adminToolsAPIURL, this.communityPid).subscribe( - pages => { - this.availablePages = pages; - this.showLoading = false; - }, - error => this.handleError('System error retrieving pages', error)); + if(!Session.isLoggedIn()){ + console.info(this._router.url); + this._router.navigate(['/user-info'], { queryParams: { "errorCode": LoginErrorCodes.NOT_VALID, "redirectUrl": this._router.url} }); + } else { + this._helpContentService.getPages(this.properties.adminToolsAPIURL, this.communityPid).subscribe( + pages => { + this.availablePages = pages; + this.showLoading = false; + }, + error => this.handleError('System error retrieving pages', error)); + } }); } diff --git a/src/app/pages/helpcontent/page-help-contents.component.ts b/src/app/pages/helpcontent/page-help-contents.component.ts index 6ffe902..c25d47c 100644 --- a/src/app/pages/helpcontent/page-help-contents.component.ts +++ b/src/app/pages/helpcontent/page-help-contents.component.ts @@ -3,16 +3,18 @@ */ import { Component, ViewChild, OnInit } from '@angular/core'; import { FormGroup } from "@angular/forms"; -import { ActivatedRoute } from "@angular/router"; +import { ActivatedRoute, Router } from "@angular/router"; import { DeleteConfirmationDialogComponent } from "../delete-confirmation-dialog.component"; import { HelpContentService } from "../../services/help-content.service"; import { PageHelpContent, CheckPageHelpContent, PageHelpContentFilterOptions } from "../../domain/page-help-content"; import { Page } from "../../domain/page"; -import {Router} from "@angular/router"; import { Community } from "../../domain/community"; import { EnvProperties } from '../../openaireLibrary/utils/properties/env-properties'; import {SafeHtmlPipe} from '../../openaireLibrary/utils/pipes/safeHTML.pipe'; +import {Session} from '../../openaireLibrary/login/utils/helper.class'; +import {LoginErrorCodes} from '../../openaireLibrary/login/utils/guardHelper.class'; + @Component({ selector: 'page-help-contents', templateUrl: './page-help-contents.component.html', @@ -86,32 +88,42 @@ export class PageHelpContentsComponent implements OnInit { // this.formGroup = this.formComponent.form; } - constructor(private route: ActivatedRoute, private _helpService: HelpContentService, private router : Router) {} + constructor(private route: ActivatedRoute, private router : Router, private _helpService: HelpContentService) {} getPage(pageId: string) { - this.showLoading = true; - this.updateErrorMessage = ""; - this.errorMessage = ""; + if(!Session.isLoggedIn()){ + console.info(this.router.url); + 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 => { - this.page = page; - this.getPageHelpContents(this.selectedCommunityPid); - }, - error => this.handleError('System error retrieving page', error)); + this._helpService.getPage(pageId, this.properties.adminToolsAPIURL).subscribe( + page => { + this.page = page; + this.getPageHelpContents(this.selectedCommunityPid); + }, + error => this.handleError('System error retrieving page', error)); + } } getPages(community_pid: string) { - this.showLoading = true; - this.updateErrorMessage = ""; - this.errorMessage = ""; + if(!Session.isLoggedIn()){ + console.info(this.router.url); + 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( - pages => { - this.pages = pages; - this.getPageHelpContents(this.selectedCommunityPid); - }, - error => this.handleError('System error retrieving pages', error)); + this._helpService.getCommunityPages(community_pid, "", this.properties.adminToolsAPIURL).subscribe( + pages => { + this.pages = pages; + this.getPageHelpContents(this.selectedCommunityPid); + }, + error => this.handleError('System error retrieving pages', error)); + } } public countPageHelpContents() { @@ -128,6 +140,10 @@ export class PageHelpContentsComponent implements OnInit { } getPageHelpContents(community_pid: string) { + if(!Session.isLoggedIn()){ + console.info(this.router.url); + 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; @@ -148,6 +164,7 @@ export class PageHelpContentsComponent implements OnInit { this.showLoading = false; }, error => this.handleError('System error retrieving page contents', error)); + } } // public showModal():void { @@ -184,15 +201,24 @@ export class PageHelpContentsComponent implements OnInit { } private confirmModalOpen() { - 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(); + if(!Session.isLoggedIn()){ + console.info(this.router.url); + 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()){ + console.info(this.router.url); + this.router.navigate(['/user-info'], { queryParams: { "errorCode": LoginErrorCodes.NOT_VALID, "redirectUrl": this.router.url} }); + } else { this.showLoading = true; this.updateErrorMessage = ""; @@ -203,6 +229,7 @@ export class PageHelpContentsComponent implements OnInit { }, error => this.handleUpdateError('System error deleting the selected page content(s)', error) ); + } } private deletePageHelpContentsFromArray(ids : string[]) : void { @@ -225,6 +252,10 @@ export class PageHelpContentsComponent implements OnInit { } public togglePageHelpContents(status : boolean, ids : string[]) { + if(!Session.isLoggedIn()){ + console.info(this.router.url); + this.router.navigate(['/user-info'], { queryParams: { "errorCode": LoginErrorCodes.NOT_VALID, "redirectUrl": this.router.url} }); + } else { this.showLoading = true; this.updateErrorMessage = ""; @@ -242,6 +273,7 @@ export class PageHelpContentsComponent implements OnInit { }, error => this.handleUpdateError('System error changing the status of the selected page content(s)', error) ); + } } public pageHelpContentSavedSuccessfully(pageHelpContent: PageHelpContent) { diff --git a/src/app/pages/htmlpagecontent/edit-htmlpage-content.component.ts b/src/app/pages/htmlpagecontent/edit-htmlpage-content.component.ts index 463e200..019f8ef 100644 --- a/src/app/pages/htmlpagecontent/edit-htmlpage-content.component.ts +++ b/src/app/pages/htmlpagecontent/edit-htmlpage-content.component.ts @@ -10,6 +10,9 @@ import { HtmlPageContentFormComponent } from "./html-page-content-form.component import { EnvProperties } from '../../openaireLibrary/utils/properties/env-properties'; import { Subscription } from "rxjs/Subscription"; +import {Session} from '../../openaireLibrary/login/utils/helper.class'; +import {LoginErrorCodes} from '../../openaireLibrary/login/utils/guardHelper.class'; + @Component({ selector: 'edit-htmlpage-content', templateUrl: './edit-htmlpage-content.component.html', @@ -74,27 +77,37 @@ export class EditHtmlPageContentComponent implements OnInit { } private getPage(communityId: string, pageId: string) { - this._helpContentService.getPage(pageId, this.properties.adminToolsAPIURL).subscribe( - page => { - this.pageName = page.name; - this.getHtmlPageContent(communityId, page.route); - }, - error => this.handleError('System error retrieving page', error)); + if(!Session.isLoggedIn()){ + console.info(this.router.url); + this.router.navigate(['/user-info'], { queryParams: { "errorCode": LoginErrorCodes.NOT_VALID, "redirectUrl": this.router.url} }); + } else { + this._helpContentService.getPage(pageId, this.properties.adminToolsAPIURL).subscribe( + page => { + this.pageName = page.name; + this.getHtmlPageContent(communityId, page.route); + }, + error => this.handleError('System error retrieving page', error)); + } } private getHtmlPageContent(communityId: string, pageRoute: string) { - this.showLoading = true; - this.errorMessage = ""; - this.updateErrorMessage = ""; + if(!Session.isLoggedIn()){ + console.info(this.router.url); + this.router.navigate(['/user-info'], { queryParams: { "errorCode": LoginErrorCodes.NOT_VALID, "redirectUrl": this.router.url} }); + } else { + this.showLoading = true; + this.errorMessage = ""; + this.updateErrorMessage = ""; - this._htmlContentService.getHtmlPageContent(communityId, pageRoute, this.properties.adminToolsAPIURL).subscribe( - htmlPageContent => { - if(htmlPageContent.length > 0) { - this.updateForm(htmlPageContent[0]); - } - this.showLoading = false; - }, - error => this.handleError('System error retrieving page help content', error)); + this._htmlContentService.getHtmlPageContent(communityId, pageRoute, this.properties.adminToolsAPIURL).subscribe( + htmlPageContent => { + if(htmlPageContent.length > 0) { + this.updateForm(htmlPageContent[0]); + } + this.showLoading = false; + }, + error => this.handleError('System error retrieving page help content', error)); + } } private updateForm(htmlPageContent : HtmlPageContent) { @@ -103,6 +116,10 @@ export class EditHtmlPageContentComponent implements OnInit { } private saveCustom() { + if(!Session.isLoggedIn()){ + console.info(this.router.url); + 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 = ""; @@ -124,6 +141,7 @@ export class EditHtmlPageContentComponent implements OnInit { this.mode = "edit"; this.errorMessage = "Please fill all required fields"; } + } } private cancelCustom() { diff --git a/src/app/pages/page/page-form.component.ts b/src/app/pages/page/page-form.component.ts index c69715f..a624c12 100644 --- a/src/app/pages/page/page-form.component.ts +++ b/src/app/pages/page/page-form.component.ts @@ -2,12 +2,15 @@ * Created by stefania on 7/13/17. */ import {Component, OnInit, Input} from '@angular/core'; -import { ActivatedRoute } from "@angular/router"; +import { ActivatedRoute, Router } from "@angular/router"; import {FormGroup, FormArray, FormBuilder, Validators} from "@angular/forms"; import {Entity} from '../../domain/entity'; import { HelpContentService } from "../../services/help-content.service"; import { EnvProperties } from '../../openaireLibrary/utils/properties/env-properties'; +import {Session} from '../../openaireLibrary/login/utils/helper.class'; +import {LoginErrorCodes} from '../../openaireLibrary/login/utils/guardHelper.class'; + @Component({ selector: 'page-form', templateUrl: './page-form.component.html', @@ -29,7 +32,7 @@ export class PageFormComponent implements OnInit{ public showLoading: boolean = false; public errorMessage: string = ''; - constructor(private route: ActivatedRoute,public _fb: FormBuilder, private _helpContentService: HelpContentService){} + constructor(private route: ActivatedRoute, private _router: Router, public _fb: FormBuilder, private _helpContentService: HelpContentService){} ngOnInit(): void { this.route.data @@ -39,49 +42,59 @@ export class PageFormComponent implements OnInit{ } public toggle() { - this.myForm.value.isCollapsed = !this.myForm.value.isCollapsed; + if(!Session.isLoggedIn()){ + console.info(this._router.url); + this._router.navigate(['/user-info'], { queryParams: { "errorCode": LoginErrorCodes.NOT_VALID, "redirectUrl": this._router.url} }); + } else { + this.myForm.value.isCollapsed = !this.myForm.value.isCollapsed; - if(!this.myForm.value.isCollapsed) { - let includedEntities: Set = new Set(); - for(let entityName of this.myForm.value.entities) { - includedEntities.add(entityName._id); - } - - let allEntities = this.allEntities; - - let self = this; - allEntities.forEach(function (status, entity, map) { - if(includedEntities.has(entity._id)) { - self.allEntities.set(entity, true); - } else { - self.allEntities.set(entity, false); + if(!this.myForm.value.isCollapsed) { + let includedEntities: Set = new Set(); + for(let entityName of this.myForm.value.entities) { + includedEntities.add(entityName._id); } - }); + + let allEntities = this.allEntities; + + let self = this; + allEntities.forEach(function (status, entity, map) { + if(includedEntities.has(entity._id)) { + self.allEntities.set(entity, true); + } else { + self.allEntities.set(entity, false); + } + }); - if(!this.gotEntities) { - this.gotEntities = true; - this.getEntities(includedEntities); + if(!this.gotEntities) { + this.gotEntities = true; + this.getEntities(includedEntities); + } } } } public getEntities(includedEntities: Set) { - this.showLoading = true; - this.errorMessage = ""; + if(!Session.isLoggedIn()){ + console.info(this._router.url); + this._router.navigate(['/user-info'], { queryParams: { "errorCode": LoginErrorCodes.NOT_VALID, "redirectUrl": this._router.url} }); + } else { + this.showLoading = true; + this.errorMessage = ""; - this._helpContentService.getEntities(this.properties.adminToolsAPIURL).subscribe( - entities => { - for(let entity of entities) { - if(includedEntities.has(entity._id)) { - this.allEntities.set(entity, true); - } else { - this.allEntities.set(entity, false); + this._helpContentService.getEntities(this.properties.adminToolsAPIURL).subscribe( + entities => { + for(let entity of entities) { + if(includedEntities.has(entity._id)) { + this.allEntities.set(entity, true); + } else { + this.allEntities.set(entity, false); + } } - } - this.showLoading = false; - }, - error => this.handleError('System error retrieving community entities', error)); + this.showLoading = false; + }, + error => this.handleError('System error retrieving community entities', error)); + } } public getKeys( map) { @@ -128,21 +141,26 @@ export class PageFormComponent implements OnInit{ } public toggleEntity(status : boolean, id : string, entity: Entity) { - let index: number = -1; - for(let i=0; i= 0) { - this.myForm.value.entities.splice(index, 1); + if(status && index<0) { + this.myForm.value.entities.push(entity); + } else if(!status){ + if(index >= 0) { + this.myForm.value.entities.splice(index, 1); + } } } } diff --git a/src/app/pages/page/pages.component.html b/src/app/pages/page/pages.component.html index 0002c6e..e94400c 100644 --- a/src/app/pages/page/pages.component.html +++ b/src/app/pages/page/pages.component.html @@ -134,10 +134,10 @@ - - + -->