diff --git a/connect/community/community.service.ts b/connect/community/community.service.ts index 27c14538..55201250 100644 --- a/connect/community/community.service.ts +++ b/connect/community/community.service.ts @@ -4,6 +4,7 @@ import { CommunityInfo } from './communityInfo'; import {EnvProperties} from '../../utils/properties/env-properties'; import {map} from "rxjs/operators"; import {BehaviorSubject, from} from "rxjs"; +import {properties} from "../../../../environments/environment"; @Injectable({ providedIn: 'root' }) export class CommunityService { @@ -127,7 +128,7 @@ export class CommunityService { * @deprecated */ isSubscribedToCommunity(pid: string, email: string, url: string) { - return this.http.get(url + '/community/' + pid + '/subscribers') + return this.http.get(url + '/'+ properties.adminToolsPortalType +'/' + pid + '/subscribers') //.map(res => ((res === '') ? {} : res.json())) .pipe(map(res => { if (res['subscribers'] && res['subscribers'] != null) { diff --git a/connect/connectHelper.ts b/connect/connectHelper.ts index b3839a85..682cbd8d 100644 --- a/connect/connectHelper.ts +++ b/connect/connectHelper.ts @@ -1,4 +1,5 @@ import {HttpParams} from '@angular/common/http'; +import {properties} from "../../../environments/environment"; export class ConnectHelper { @@ -30,4 +31,14 @@ export class ConnectHelper { return null; } } + + public static setPortalTypeFromPid(pid: string): void { + if(pid == "openaire") { + properties.adminToolsPortalType = "explore"; + } else if(pid == "connect") { + properties.adminToolsPortalType = "connect"; + } else { + properties.adminToolsPortalType = "community"; + } + } } diff --git a/dashboard/divId/divIds.component.html b/dashboard/divId/divIds.component.html index d088c567..92b89015 100644 --- a/dashboard/divId/divIds.component.html +++ b/dashboard/divId/divIds.component.html @@ -56,6 +56,7 @@ Name Page + Portal Type Actions @@ -67,7 +68,9 @@
{{check.divId.name}}
- + +
{{check.divId.portalType}}
+
{{page.name}} -
-
Select if this class exists in:
- - - - - - - - - - - +
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + diff --git a/dashboard/divId/divIds.component.ts b/dashboard/divId/divIds.component.ts index 1245f727..61e2f634 100644 --- a/dashboard/divId/divIds.component.ts +++ b/dashboard/divId/divIds.component.ts @@ -58,9 +58,7 @@ export class DivIdsComponent implements OnInit { _id: '', name: ['', Validators.required], pages: this.pagesCtrl, - openaire: true, - connect: false, - communities: true + portalType: ['', Validators.required] }); this.route.data @@ -199,10 +197,10 @@ export class DivIdsComponent implements OnInit { _id: divId._id, name: [divId.name,Validators.required], pages: this.pagesCtrl, - openaire: divId.openaire, - connect: divId.connect, - communities: divId.communities + portalType: [divId.portalType, Validators.required] }); + this.myForm.controls['portalType'].disable(); + for(let i = 0; i < divId.pages.length; i++) { this.pagesCtrl.push(this._fb.control(divId.pages[i])); } @@ -213,14 +211,15 @@ export class DivIdsComponent implements OnInit { } public newDivId() { + this.myForm.controls['portalType'].enable(); + this.pagesCtrl = this._fb.array([]); this.myForm = this._fb.group({ _id: '', name: ['', Validators.required], pages: this.pagesCtrl, - openaire: this._fb.control(true), - connect: false, - communities: true + //openaire: this._fb.control(true), + portalType: ['', Validators.required] }); this.filteredPages = this.pageSearchCtrl.valueChanges.pipe(startWith(''), map(page => this._filter(page))); @@ -257,6 +256,8 @@ export class DivIdsComponent implements OnInit { } else { console.log(this.myForm.value) if (this.myForm.value['_id'].length == 0) { + this.myForm.controls['portalType'].enable(); + this.modalErrorMessage = ""; this._helpContentService.saveDivId(this.myForm.value, this.properties.adminToolsAPIURL).subscribe( @@ -300,7 +301,7 @@ export class DivIdsComponent implements OnInit { } public filterDivIds(divId: DivId): boolean { - let textFlag = this.searchText.toString() == '' || (divId.name).match(this.searchText) != null; + let textFlag = this.searchText.toString() == '' || (divId.name + ' ' + divId.portalType).match(this.searchText) != null; return textFlag; } diff --git a/dashboard/divhelpcontent/div-help-content-form.component.ts b/dashboard/divhelpcontent/div-help-content-form.component.ts index 03291357..8778d822 100644 --- a/dashboard/divhelpcontent/div-help-content-form.component.ts +++ b/dashboard/divhelpcontent/div-help-content-form.component.ts @@ -136,7 +136,7 @@ export class DivContentFormComponent implements OnInit{ divId: ['', Validators.required], content: ['', Validators.required], isActive: true, - community: '', + portal: '', _id : '', }); } @@ -146,7 +146,7 @@ export class DivContentFormComponent implements OnInit{ divId: '', content: '', isActive: true, - community: '', + portal: '', _id : '' }); this.myForm.markAsPristine(); diff --git a/dashboard/divhelpcontent/div-help-contents.component.ts b/dashboard/divhelpcontent/div-help-contents.component.ts index c9b771cf..ee709c3a 100644 --- a/dashboard/divhelpcontent/div-help-contents.component.ts +++ b/dashboard/divhelpcontent/div-help-contents.component.ts @@ -8,7 +8,7 @@ import { DivHelpContentFilterOptions } from "../../utils/entities/adminTool/div-help-content"; import {Page} from "../../utils/entities/adminTool/page"; -import {Community} from "../../utils/entities/adminTool/community"; +import {Portal} from "../../utils/entities/adminTool/portal"; import {DivId} from "../../utils/entities/adminTool/divId"; import {EnvProperties} from '../../utils/properties/env-properties'; @@ -45,13 +45,13 @@ export class DivHelpContentsComponent implements OnInit { public counter = {all: 0, active: 0, inactive: 0}; - public communities: Community[] = []; + public communities: Portal[] = []; public selectedCommunityPid: string; public selectedPageId: string; - public community: Community; + public community: Portal; public page: Page; public properties: EnvProperties = null; @@ -122,9 +122,7 @@ export class DivHelpContentsComponent implements OnInit { this._helpService.getPage(pageId, this.properties.adminToolsAPIURL).subscribe( page => { - if ((this.selectedCommunityPid == 'openaire' && !page.openaire) - || (this.selectedCommunityPid == 'connect' && !page.connect) - || (this.selectedCommunityPid != 'openaire' && this.selectedCommunityPid != 'connect' && !page.communities)) { + if (this.properties.adminToolsPortalType != page.portalType) { this.router.navigate(['/classContents'], {queryParams: {"communityId": this.selectedCommunityPid}}); } else { this.page = page; diff --git a/dashboard/divhelpcontent/edit-div-help-content.component.ts b/dashboard/divhelpcontent/edit-div-help-content.component.ts index b1c50964..a1551c31 100644 --- a/dashboard/divhelpcontent/edit-div-help-content.component.ts +++ b/dashboard/divhelpcontent/edit-div-help-content.component.ts @@ -80,9 +80,7 @@ export class EditDivHelpContentComponent implements OnInit, OnDestroy{ private getPage(pageId: string) { this._helpContentService.getPage(pageId,this.properties.adminToolsAPIURL).subscribe( page => { - if( (this.communityPid == 'openaire' && !page.openaire) - || (this.communityPid == 'connect' && !page.connect) - || (this.communityPid != 'openaire' && this.communityPid != 'connect' && !page.communities)) { + if(this.properties.adminToolsPortalType != page.portalType) { this.router.navigate(['/classContents'], { queryParams: { "communityId": this.communityPid} }); } else { this.page = page; diff --git a/dashboard/divhelpcontent/new-div-help-content.component.ts b/dashboard/divhelpcontent/new-div-help-content.component.ts index 33003e63..d29fa8f4 100644 --- a/dashboard/divhelpcontent/new-div-help-content.component.ts +++ b/dashboard/divhelpcontent/new-div-help-content.component.ts @@ -62,9 +62,7 @@ export class NewDivHelpContentComponent { private getPage(pageId: string) { this._helpContentService.getPage(pageId,this.properties.adminToolsAPIURL).subscribe( page => { - if( (this.communityPid == 'openaire' && !page.openaire) - || (this.communityPid == 'connect' && !page.connect) - || (this.communityPid != 'openaire' && this.communityPid != 'connect' && !page.communities)) { + if(this.properties.adminToolsPortalType != page.portalType) { this.router.navigate(['/classContents'], { queryParams: { "communityId": this.communityPid} }); } else { this.page = page; diff --git a/dashboard/entity/entities.component.ts b/dashboard/entity/entities.component.ts index 77b91902..04b80137 100644 --- a/dashboard/entity/entities.component.ts +++ b/dashboard/entity/entities.component.ts @@ -3,7 +3,7 @@ import {ActivatedRoute, Router} from '@angular/router'; import {HelpContentService} from '../../services/help-content.service'; import {FormBuilder, FormControl, FormGroup, Validators} from '@angular/forms'; import {CheckEntity, Entity} from '../../utils/entities/adminTool/entity'; -import {Community} from '../../utils/entities/adminTool/community'; +import {Portal} from '../../utils/entities/adminTool/portal'; import {EnvProperties} from '../../utils/properties/env-properties'; import {Session} from '../../login/utils/helper.class'; import {LoginErrorCodes} from '../../login/utils/guardHelper.class'; @@ -31,7 +31,7 @@ export class EntitiesComponent implements OnInit { private searchText: RegExp = new RegExp(''); public keyword = ''; - public communities: Community[] = []; + public communities: Portal[] = []; public selectedCommunityPid: string; @ViewChild('AlertModalRelatedPages') alertModalRelatedPages; diff --git a/dashboard/helpTexts/edit-page-help-content.component.ts b/dashboard/helpTexts/edit-page-help-content.component.ts index 911193e1..acbff512 100644 --- a/dashboard/helpTexts/edit-page-help-content.component.ts +++ b/dashboard/helpTexts/edit-page-help-content.component.ts @@ -82,9 +82,7 @@ export class EditPageHelpContentComponent implements OnInit, OnDestroy{ private getPage(pageId: string) { this._helpContentService.getPage(pageId,this.properties.adminToolsAPIURL).subscribe( page => { - if( (this.communityPid == 'openaire' && !page.openaire) - || (this.communityPid == 'connect' && !page.connect) - || (this.communityPid != 'openaire' && this.communityPid != 'connect' && !page.communities)) { + if(this.properties.adminToolsPortalType != page.portalType) { this.router.navigate(['/pageContents'], { queryParams: { "communityId": this.communityPid} }); } else { this.page = page; diff --git a/dashboard/helpTexts/new-page-help-content.component.ts b/dashboard/helpTexts/new-page-help-content.component.ts index 8b2fb4d2..861c6e19 100644 --- a/dashboard/helpTexts/new-page-help-content.component.ts +++ b/dashboard/helpTexts/new-page-help-content.component.ts @@ -62,9 +62,7 @@ export class NewPageHelpContentComponent { private getPage(pageId: string) { this._helpContentService.getPage(pageId,this.properties.adminToolsAPIURL).subscribe( page => { - if( (this.communityPid == 'openaire' && !page.openaire) - || (this.communityPid == 'connect' && !page.connect) - || (this.communityPid != 'openaire' && this.communityPid != 'connect' && !page.communities)) { + if(this.properties.adminToolsPortalType != page.portalType) { this.router.navigate(['/pageContents'], { queryParams: { "communityId": this.communityPid} }); } else { this.page = page; diff --git a/dashboard/helpTexts/page-help-content-form.component.ts b/dashboard/helpTexts/page-help-content-form.component.ts index 9ec3c3d5..3f4ba51e 100644 --- a/dashboard/helpTexts/page-help-content-form.component.ts +++ b/dashboard/helpTexts/page-help-content-form.component.ts @@ -74,7 +74,7 @@ export class PageContentFormComponent implements OnInit{ public get form() { return this._fb.group({ page : [this.pageId, Validators.required], - community : this.communityPid, + portal : this.communityPid, placement : ['', Validators.required], content : ['', Validators.required], order : [1, Validators.required], @@ -87,7 +87,7 @@ export class PageContentFormComponent implements OnInit{ public reset() { this.myForm.patchValue({ page : '', - community : this.communityPid, + portal : this.communityPid, placement : '', content : [''], order : 1, diff --git a/dashboard/helpTexts/page-help-contents.component.html b/dashboard/helpTexts/page-help-contents.component.html index 00a6b4f3..bd4295b6 100644 --- a/dashboard/helpTexts/page-help-contents.component.html +++ b/dashboard/helpTexts/page-help-contents.component.html @@ -100,7 +100,7 @@
{{check.pageHelpContent.page.name}}
-
{{check.pageHelpContent.community.name}}
+
{{check.pageHelpContent.portal.name}}
diff --git a/dashboard/helpTexts/page-help-contents.component.ts b/dashboard/helpTexts/page-help-contents.component.ts index f7a3bf35..4fe55bb6 100644 --- a/dashboard/helpTexts/page-help-contents.component.ts +++ b/dashboard/helpTexts/page-help-contents.component.ts @@ -8,7 +8,7 @@ import { PageHelpContentFilterOptions } from "../../utils/entities/adminTool/page-help-content"; import {Page} from "../../utils/entities/adminTool/page"; -import {Community} from "../../utils/entities/adminTool/community"; +import {Portal} from "../../utils/entities/adminTool/portal"; import {EnvProperties} from '../../utils/properties/env-properties'; import {Session} from '../../login/utils/helper.class'; import {LoginErrorCodes} from '../../login/utils/guardHelper.class'; @@ -41,13 +41,13 @@ export class PageHelpContentsComponent implements OnInit { public counter = {all: 0, active: 0, inactive: 0}; - public communities: Community[] = []; + public communities: Portal[] = []; public selectedCommunityPid: string; public selectedPageId: string; - public community: Community; + public community: Portal; public page: Page; public properties: EnvProperties = null; @@ -115,9 +115,7 @@ export class PageHelpContentsComponent implements OnInit { this._helpService.getPage(pageId, this.properties.adminToolsAPIURL).subscribe( page => { - if ((this.selectedCommunityPid == 'openaire' && !page.openaire) - || (this.selectedCommunityPid == 'connect' && !page.connect) - || (this.selectedCommunityPid != 'openaire' && this.selectedCommunityPid != 'connect' && !page.communities)) { + if (this.properties.adminToolsPortalType != page.portalType) { this.router.navigate(['/pageContents'], {queryParams: {"communityId": this.selectedCommunityPid}}); } else { this.page = page; diff --git a/dashboard/page/pages.component.html b/dashboard/page/pages.component.html index 4bb69d09..6588edc2 100644 --- a/dashboard/page/pages.component.html +++ b/dashboard/page/pages.component.html @@ -69,6 +69,7 @@ Type Related Entities Route + Portal Type Actions Page help texts
{{check.page.route}}
+ +
{{check.page.portalType}}
+
@@ -257,21 +261,42 @@
-
+ -
Select if this page exists in:
- - - - - - + + + + + + + + + + + + + + + +
+ + + +
diff --git a/dashboard/page/pages.component.ts b/dashboard/page/pages.component.ts index 6d00acd3..60edb3cf 100644 --- a/dashboard/page/pages.component.ts +++ b/dashboard/page/pages.component.ts @@ -3,7 +3,7 @@ import {ActivatedRoute, Router} from '@angular/router'; import {HelpContentService} from '../../services/help-content.service'; import {FormArray, FormBuilder, FormControl, FormGroup, Validators} from '@angular/forms'; import {CheckPage, Page} from '../../utils/entities/adminTool/page'; -import {Community} from '../../utils/entities/adminTool/community'; +import {Portal} from '../../utils/entities/adminTool/portal'; import {Entity} from '../../utils/entities/adminTool/entity'; import {EnvProperties} from '../../utils/properties/env-properties'; import {Session} from '../../login/utils/helper.class'; @@ -37,7 +37,7 @@ export class PagesComponent implements OnInit { private searchText: RegExp = new RegExp(''); public keyword: string = ''; - public communities: Community[] = []; + public communities: Portal[] = []; public selectedCommunityPid: string; @@ -81,9 +81,7 @@ export class PagesComponent implements OnInit { route: ['', Validators.required], name: ['', Validators.required], isEnabled: true, - openaire: true, - connect: false, - communities: true, + portalType: ['', Validators.required], top: true, bottom: true, left: true, @@ -299,9 +297,7 @@ export class PagesComponent implements OnInit { route: [page.route, Validators.required], name: [page.name, Validators.required], isEnabled: page.isEnabled, - openaire: page.openaire, - connect: page.connect, - communities: page.communities, + portalType: ['', Validators.required], top: page.top, bottom: page.bottom, left: page.left, @@ -310,6 +306,7 @@ export class PagesComponent implements OnInit { entities: this.entitiesCtrl, _id: page._id, }); + this.myForm.controls['portalType'].disable(); for (let i = 0; i < page.entities.length; i++) { this.entitiesCtrl.push(this._fb.control(page.entities[i])); @@ -330,14 +327,14 @@ export class PagesComponent implements OnInit { } public newPage() { + this.myForm.controls['portalType'].enable(); + this.entitiesCtrl = this._fb.array([]); this.myForm = this._fb.group({ route: ['', Validators.required], name: ['', Validators.required], isEnabled: true, - openaire: true, - connect: false, - communities: true, + portalType: ['', Validators.required], top: true, bottom: true, left: true, @@ -381,6 +378,8 @@ export class PagesComponent implements OnInit { } else { console.log(this.myForm.value) if (this.myForm.value['_id'].length == 0) { + this.myForm.controls['portalType'].enable(); + this.modalErrorMessage = ''; this._helpContentService.savePage(this.myForm.value, this.properties.adminToolsAPIURL).subscribe( page => { @@ -441,7 +440,7 @@ export class PagesComponent implements OnInit { } public filterPages(page: Page): boolean { - let textFlag = this.searchText.toString() == '' || (page.route + ' ' + page.name).match(this.searchText) != null; + let textFlag = this.searchText.toString() == '' || (page.route + ' ' + page.name + ' ' + page.portalType).match(this.searchText) != null; return textFlag; } @@ -463,9 +462,7 @@ export class PagesComponent implements OnInit { route: ['', Validators.required], name: ['', Validators.required], isEnabled: true, - openaire: true, - connect: false, - communities: true, + portalType: ['', Validators.required], top: true, bottom: true, left: true, diff --git a/dashboard/portal/communities.component.html b/dashboard/portal/communities.component.html index ee3b42b4..718bf582 100644 --- a/dashboard/portal/communities.component.html +++ b/dashboard/portal/communities.component.html @@ -37,7 +37,7 @@
    + title="Select at least one portal">
  • Delete
@@ -55,6 +55,7 @@ Name + Type Actions @@ -66,6 +67,9 @@
{{check.community.name}}
+ +
{{check.community.type}}
+
@@ -86,7 +90,7 @@
-
No communities found
+
No portals found
@@ -105,11 +109,20 @@
+ label="Portal Name"> +
+
+ +
+ label="Portal persistent id for portal">
diff --git a/dashboard/portal/communities.component.ts b/dashboard/portal/communities.component.ts index fcf354c0..9a2bb8b8 100644 --- a/dashboard/portal/communities.component.ts +++ b/dashboard/portal/communities.component.ts @@ -2,7 +2,7 @@ import {Component, ViewChild, OnInit, ElementRef} from '@angular/core'; import {ActivatedRoute, Router} from '@angular/router'; import {HelpContentService} from '../../services/help-content.service'; import {FormBuilder, FormControl, FormGroup} from '@angular/forms'; -import {CheckCommunity, Community} from '../../utils/entities/adminTool/community'; +import {CheckPortal, Portal} from '../../utils/entities/adminTool/portal'; import {EnvProperties} from '../../utils/properties/env-properties'; import {Session} from '../../login/utils/helper.class'; @@ -21,8 +21,8 @@ export class CommunitiesComponent implements OnInit { @ViewChild('AlertModalDeleteCommunities') alertModalDeleteCommunities; private selectedCommunities: string[] = []; - public checkboxes: CheckCommunity[] = []; - public communities: Community[] = []; + public checkboxes: CheckPortal[] = []; + public communities: Portal[] = []; public portalFG: FormGroup; public formControl: FormControl; @@ -42,7 +42,8 @@ export class CommunitiesComponent implements OnInit { this.portalFG = this._fb.group({ name: '', _id: '', - pid: '' + pid: '', + type: '' }); this.formControl = this._fb.control(''); this.subscriptions.push(this.formControl.valueChanges.subscribe(value => { @@ -88,7 +89,7 @@ export class CommunitiesComponent implements OnInit { communities => { this.communities = communities; communities.forEach(_ => { - this.checkboxes.push({community: _, checked: false}); + this.checkboxes.push({community: _, checked: false}); }); this.showLoading = false; }, @@ -162,20 +163,24 @@ export class CommunitiesComponent implements OnInit { } public editCommunity(i: number) { - const community: Community = this.checkboxes[i].community; + const community: Portal = this.checkboxes[i].community; this.portalFG = this._fb.group({ name: community.name, _id: community._id, + type: community.type, pid: community.pid }); + this.portalFG.controls['type'].disable(); this.modalErrorMessage = ''; this.communitiesModalOpen(this.alertModalSaveCommunity, 'Update', 'Update Community'); } public newCommunity() { + this.portalFG.controls['type'].enable(); this.portalFG = this._fb.group({ name: '', _id: '', + type: '', pid: '' }); this.modalErrorMessage = ''; @@ -205,7 +210,8 @@ export class CommunitiesComponent implements OnInit { this.modalErrorMessage = ''; if (this.portalFG.getRawValue()['_id'].length > 0) { - this._helpContentService.updateCommunity(this.portalFG.value, + this.portalFG.controls['type'].enable(); + this._helpContentService.updateCommunity(this.portalFG.value, this.properties.adminToolsAPIURL).subscribe( community => { this.communityUpdatedSuccessfully(community); @@ -213,7 +219,7 @@ export class CommunitiesComponent implements OnInit { error => this.handleUpdateError('System error updating portal', error) ); }else{ - this._helpContentService.saveCommunity(this.portalFG.value, + this._helpContentService.saveCommunity(this.portalFG.value, this.properties.adminToolsAPIURL).subscribe( community => { this.communitySavedSuccessfully(community); @@ -231,7 +237,8 @@ export class CommunitiesComponent implements OnInit { queryParams: {'errorCode': LoginErrorCodes.NOT_VALID, 'redirectUrl': this._router.url} }); } else { - this._helpContentService.updateCommunity(this.portalFG.value, + this.portalFG.controls['type'].enable(); + this._helpContentService.updateCommunity(this.portalFG.value, this.properties.adminToolsAPIURL).subscribe( community => { this.communityUpdatedSuccessfully(community); @@ -241,12 +248,12 @@ export class CommunitiesComponent implements OnInit { } } - public communitySavedSuccessfully(community: Community) { - this.checkboxes.push({community: community, checked: false}); + public communitySavedSuccessfully(community: Portal) { + this.checkboxes.push({community: community, checked: false}); this.applyCheck(false); } - public communityUpdatedSuccessfully(community: Community) { + public communityUpdatedSuccessfully(community: Portal) { this.checkboxes.find(checkItem => checkItem.community._id === community._id).community = community; this.applyCheck(false); } @@ -259,12 +266,12 @@ export class CommunitiesComponent implements OnInit { public applyFilter() { this.checkboxes = []; this.communities.filter(item => this.filterCommunities(item)).forEach( - _ => this.checkboxes.push({community: _, checked: false}) + _ => this.checkboxes.push({community: _, checked: false}) ); } - public filterCommunities(community: Community): boolean { - const textFlag = this.searchText.toString() === '' || (community.name).match(this.searchText) != null; + public filterCommunities(community: Portal): boolean { + const textFlag = this.searchText.toString() === '' || (community.name || community.type).match(this.searchText) != null; return textFlag; } @@ -273,7 +280,8 @@ export class CommunitiesComponent implements OnInit { this.portalFG = this._fb.group({ name: '', _id: '', - pid: '' + pid: '', + type: '' }); } else { this.updateErrorMessage = message; diff --git a/error/errorPage.component.ts b/error/errorPage.component.ts index e3844506..08521448 100644 --- a/error/errorPage.component.ts +++ b/error/errorPage.component.ts @@ -5,6 +5,7 @@ import {Title, Meta} from '@angular/platform-browser'; import {RESPONSE} from "@nguniversal/express-engine/tokens"; import {EnvProperties} from "../utils/properties/env-properties"; import {SEOService} from "../sharedComponents/SEO/SEO.service"; +import {properties} from "../../../environments/environment"; @Component({ selector: 'error', @@ -60,9 +61,9 @@ export class ErrorPageComponent { this.response.statusCode = 404; this.response.statusMessage = '404 - Page not found'; } - this.route.data - .subscribe((data: { envSpecific: EnvProperties }) => { - let properties = data.envSpecific; + //this.route.data + //.subscribe((data: { envSpecific: EnvProperties }) => { + //let properties = data.envSpecific; this.seoService.createLinkForCanonicalURL(properties.domain + properties.baseLink + "/error"); this.route.queryParams.subscribe(data => { @@ -97,6 +98,6 @@ export class ErrorPageComponent { } } }); - }); + //}); } } diff --git a/services/clear-cache.service.ts b/services/clear-cache.service.ts new file mode 100644 index 00000000..7ad6dead --- /dev/null +++ b/services/clear-cache.service.ts @@ -0,0 +1,18 @@ +import {Injectable} from "@angular/core"; +import {HttpClient} from "@angular/common/http"; +import {properties} from "../../../environments/environment"; + +@Injectable({ + providedIn: 'root' +}) +export class ClearCacheService { + + constructor(private http: HttpClient) {} + + clearCache(message: string = null) { + this.http.get(properties.deleteCacheUrl).subscribe( + res => console.log((message ? message+": " : "") + "Cache cleared!"), + err => console.log((message ? message+": " : "") + "Cache could not be cleared ", err) + ); + } +} diff --git a/services/help-content.service.ts b/services/help-content.service.ts index 07b9b6a2..96cc6642 100644 --- a/services/help-content.service.ts +++ b/services/help-content.service.ts @@ -6,393 +6,399 @@ import {HttpClient, HttpErrorResponse, HttpHeaders} from "@angular/common/http"; import { Observable } from 'rxjs'; import { Page } from "../utils/entities/adminTool/page"; import { PageHelpContent } from "../utils/entities/adminTool/page-help-content"; -import { Community } from "../utils/entities/adminTool/community"; +import { Portal } from "../utils/entities/adminTool/portal"; import { Entity } from "../utils/entities/adminTool/entity"; import { DivId } from "../utils/entities/adminTool/divId"; import { DivHelpContent } from "../utils/entities/adminTool/div-help-content"; import {StatisticsDisplay, StatisticsSummary} from '../connect/statistics/statisticsEntities'; import { CustomOptions } from './servicesUtils/customOptions.class'; import {catchError, map} from "rxjs/operators"; +import {properties} from "../../../environments/environment"; @Injectable() export class HelpContentService { - constructor(private http:HttpClient) { - } + constructor(private http:HttpClient) { + } - static removeNulls(obj){ - var isArray = obj instanceof Array; - for (var k in obj){ - if (obj[k]===null || obj[k]==='') isArray ? obj.splice(k,1) : delete obj[k]; - else if (typeof obj[k]=="object") HelpContentService.removeNulls(obj[k]); - } + static removeNulls(obj){ + var isArray = obj instanceof Array; + for (var k in obj){ + if (obj[k]===null || obj[k]==='') isArray ? obj.splice(k,1) : delete obj[k]; + else if (typeof obj[k]=="object") HelpContentService.removeNulls(obj[k]); } + } - getDivIdsFull(page_id: string, helpContentUrl:string, pid: string = null) { - let parameters: string = ""; - if(page_id || pid) { - parameters = "?"; - if(page_id) { - parameters += "&page="+page_id; - } - if(pid) { - parameters += "&communityId="+pid; - } + getDivIdsFull(page_id: string, helpContentUrl:string, pid: string = null) { + let parameters: string = ""; + if(page_id || pid) { + parameters = "?"; + if(page_id) { + parameters += "&page="+page_id; + } + if(pid) { + parameters += "&portal="+pid; } - - return this.http.get>(helpContentUrl + '/divFull'+parameters) - //.map(res => > res.json()) - .pipe(catchError(this.handleError)); } - updateDivId(divId: DivId, helpContentUrl:string) { - HelpContentService.removeNulls(divId); + return this.http.get>(helpContentUrl + 'divFull'+parameters) + //.map(res => > res.json()) + .pipe(catchError(this.handleError)); + } - return this.http.post(helpContentUrl + '/div/update', JSON.stringify(divId), CustomOptions.getAuthOptionsWithBody()) - //.map(res => res.json()) - .pipe(catchError(this.handleError)); - } - - getDivId(divId: string, helpContentUrl:string) { - return this.http.get(helpContentUrl + '/div/'+divId) - //.map(res => res.json()) - .pipe(catchError(this.handleError)); - } - - getDivIdFull(divId: string, helpContentUrl:string) { - return this.http.get(helpContentUrl + '/divFull/'+divId) - //.map(res => res.json()) - .pipe(catchError(this.handleError)); - } - - saveDivId(divId: DivId, helpContentUrl:string) { - HelpContentService.removeNulls(divId); - - return this.http.post(helpContentUrl + '/div/save', JSON.stringify(divId), CustomOptions.getAuthOptionsWithBody()) - //.map(res => res.json()) - .pipe(catchError(this.handleError)); - } -/* - getCommunitiesWithDivId(helpContentUrl:string) { - return this.http.get(helpContentUrl + 'community?div=true') - .map(res => > res.json()) - .catch(this.handleError); - } -*/ - getCommunityPagesWithDivId(community_pid: string, helpContentUrl:string) { - return this.http.get>(helpContentUrl + '/community/'+community_pid+'/pages?div=true') - //.map(res => > res.json()) - .pipe(catchError(this.handleError)); - } - - getCommunityDivHelpContents(community_pid: string, helpContentUrl:string) { - return this.http.get>(helpContentUrl + '/divhelpcontent?community='+community_pid) - //.map(res => > res.json()) - .pipe(catchError(this.handleError)); - } - - getDivHelpContent(id : string, helpContentUrl:string) { - return this.http.get(helpContentUrl + '/divhelpcontent/' + id) - //.map(res => res.json()) - .pipe(catchError(this.handleError)); - } - - insertOrUpdateDivHelpContent(divHelpContent: DivHelpContent, helpContentUrl:string) { - HelpContentService.removeNulls(divHelpContent); - - return this.http.post(helpContentUrl + '/divhelpcontent', JSON.stringify(divHelpContent), CustomOptions.getAuthOptionsWithBody()) - //.map(res => res.json()) - .pipe(catchError(this.handleError)); - } - - deleteDivIds(ids : string[], helpContentUrl:string) { - return this.http.post(helpContentUrl + '/div/delete',JSON.stringify(ids), CustomOptions.getAuthOptionsWithBody()) - .pipe(catchError(this.handleError)); - } - - deleteDivHelpContents(ids : string[], helpContentUrl:string) { - return this.http.post(helpContentUrl + '/divhelpcontent/delete',JSON.stringify(ids), CustomOptions.getAuthOptionsWithBody()) - .pipe(catchError(this.handleError)); - } - - toggleDivHelpContents(ids : string[],status : boolean, helpContentUrl:string) { - - return this.http.post(helpContentUrl + '/divhelpcontent/toggle?status='+ status.toString(), JSON.stringify(ids), CustomOptions.getAuthOptionsWithBody()) - //.map( res => res.json()) - .pipe(catchError(this.handleError)); - } - - getPagesWithDivIds(community_pid: string, helpContentUrl:string) { - let parameters = (community_pid ? "?communityId="+community_pid : ""); - return this.http.get>(helpContentUrl + '/div/pages'+parameters) - //.map(res => >> res.json()) - .pipe(catchError(this.handleError)); - } - - getPages(helpContentUrl:string,pid:string,with_positions:boolean=null) { - let parameters: string = ""; - if(pid || with_positions == true || with_positions == false) { - parameters = "?"; - if(pid) { - parameters += "&pid="+pid; - } - if(with_positions == true || with_positions == false) { - parameters += "&with_positions="+with_positions; - } - } - return this.http.get>(helpContentUrl + '/page'+parameters) - //.map(res => > res.json()) - .pipe(catchError(this.handleError)); - } - - getPagesFull(helpContentUrl:string,pid:string) { - return this.http.get>(helpContentUrl + '/pageFull'+(pid?("?pid="+pid):"")) - //.map(res => > res.json()) - .pipe(catchError(this.handleError)); - } - - getPage(pageId:string, helpContentUrl:string) { - return this.http.get(helpContentUrl + '/page/'+pageId) - //.map(res => res.json()) - .pipe(catchError(this.handleError)); - } - - getPageByRoute(route:string, helpContentUrl:string) { - return this.http.get(helpContentUrl + '/page/?page_route='+route) - .pipe(catchError(this.handleError)); - } - - getCommunities( helpContentUrl:string) { - return this.http.get>(helpContentUrl + '/community') - //.map(res => > res.json()) - .pipe(catchError(this.handleError)); - } - - getCommunity(community_pid: string, helpContentUrl:string) { - return this.http.get(helpContentUrl + '/community/'+community_pid) - //.map(res => res.json()) - .pipe(catchError(this.handleError)); - } - - getCommunitiesFull( helpContentUrl:string) { - return this.http.get>(helpContentUrl + '/communityFull') - //.map(res => > res.json()) - .pipe(catchError(this.handleError)); - } - - getCommunityFull(community_pid: string, helpContentUrl:string) { - return this.http.get(helpContentUrl + '/communityFull/'+community_pid) - //.map(res => res.json()) - .pipe(catchError(this.handleError)); - } - - saveCommunity(community: Community, helpContentUrl:string) { - // let headers = new Headers({'Content-Type': 'application/json'}); - // let options = new RequestOptions({headers: headers}); - - HelpContentService.removeNulls(community); - - return this.http.post(helpContentUrl + '/community/save', JSON.stringify(community), CustomOptions.getAuthOptionsWithBody()) - //.map(res => res.json()) - .pipe(catchError(this.handleError)); - } - - updateCommunity(community: Community, helpContentUrl:string) { - // let headers = new Headers({'Content-Type': 'application/json'}); - // let options = new RequestOptions({headers: headers}); - - HelpContentService.removeNulls(community); - - return this.http.post(helpContentUrl + '/community/update', JSON.stringify(community), CustomOptions.getAuthOptionsWithBody()) - //.map(res => res.json()) - .pipe(catchError(this.handleError)); - } - - deleteCommunities(ids : string[], helpContentUrl:string) { - // let headers = new Headers({'Content-Type': 'application/json'}); - // let options = new RequestOptions({headers: headers}); - - return this.http.post(helpContentUrl + '/community/delete',JSON.stringify(ids), CustomOptions.getAuthOptionsWithBody()) - .pipe(catchError(this.handleError)); - } - - getCommunityPages(community_pid: string, params: string, helpContentUrl:string) { - return this.http.get>(helpContentUrl + '/community/'+community_pid+'/pages'+params) - //.map(res => > res.json()) - .pipe(catchError(this.handleError)); - } - - getEntities(helpContentUrl:string) { - return this.http.get>(helpContentUrl + '/entity') - //.map(res => > res.json()) - .pipe(catchError(this.handleError)); - } - - getCommunityEntities(community_pid: string, helpContentUrl:string) { - return this.http.get>(helpContentUrl + '/community/'+community_pid+'/entities') - //.map(res => > res.json()) - .pipe(catchError(this.handleError)); - } - - - saveEntity(entity: Entity, helpContentUrl:string) { - HelpContentService.removeNulls(entity); - - return this.http.post(helpContentUrl + '/entity/save', JSON.stringify(entity), CustomOptions.getAuthOptionsWithBody()) - //.map(res => res.json()) - .pipe(catchError(this.handleError)); - } - - updateEntity(entity: Entity, helpContentUrl:string) { - HelpContentService.removeNulls(entity); - - return this.http.post(helpContentUrl + '/entity/update', JSON.stringify(entity), CustomOptions.getAuthOptionsWithBody()) - //.map(res => res.json()) - .pipe(catchError(this.handleError)); - } - - // toggleEntity(selectedCommunityId: string, id : string,status : boolean) { - // let headers = new Headers({'Content-Type': 'application/json'}); - // let options = new RequestOptions({headers: headers}); - // - // return this.http.post(helpContentUrl + 'community/'+selectedCommunityId+'/entity/toggle?status='+ status.toString()+'&entityId='+id.toString(), options) - // .catch(this.handleError); - // } - - toggleEntities(selectedCommunityPid: string, ids : string[],status : boolean, helpContentUrl:string) { - - return this.http.post(helpContentUrl +'/community/'+selectedCommunityPid+ '/entity/toggle?status='+ status.toString(), JSON.stringify(ids), CustomOptions.getAuthOptionsWithBody()) - //.map( res => res.json()) - .pipe(catchError(this.handleError)); - } - - deleteEntities(ids : string[], helpContentUrl:string) { - return this.http.post(helpContentUrl + '/entity/delete',JSON.stringify(ids), CustomOptions.getAuthOptionsWithBody()) - .pipe(catchError(this.handleError)); - } - - - toggleEntityOfPage(pageId: string, entityId : string,status : boolean, helpContentUrl:string) { - return this.http.post(helpContentUrl + '/page/'+pageId+'/entity/toggle?status='+ status.toString()+'&entityId='+entityId.toString(), CustomOptions.getAuthOptionsWithBody()) - .pipe(catchError(this.handleError)); - } - - savePage(page: Page, helpContentUrl:string) { - HelpContentService.removeNulls(page); - - return this.http.post(helpContentUrl + '/page/save', JSON.stringify(page), CustomOptions.getAuthOptionsWithBody()) - //.map(res => res.json()) - .pipe(catchError(this.handleError)); - } - - updatePage(page: Page, helpContentUrl:string) { - - HelpContentService.removeNulls(page); - - return this.http.post(helpContentUrl + '/page/update', JSON.stringify(page), CustomOptions.getAuthOptionsWithBody()) - //.map(res => res.json()) - .pipe(catchError(this.handleError)); - } - - togglePages(selectedCommunityPid: string, ids : string[],status : boolean, helpContentUrl:string) { - - return this.http.post(helpContentUrl + '/community/'+selectedCommunityPid+'/page/toggle?status='+ status.toString(),JSON.stringify(ids), CustomOptions.getAuthOptionsWithBody()) - .pipe(catchError(this.handleError)); - } - - deletePages(ids : string[], helpContentUrl:string) { - - return this.http.post(helpContentUrl + '/page/delete',JSON.stringify(ids), CustomOptions.getAuthOptionsWithBody()) - .pipe(catchError(this.handleError)); - } - - getPageHelpContents(helpContentUrl:string) { - return this.http.get>(helpContentUrl + 'pagehelpcontent') - //.map(res => > res.json()) - .pipe(catchError(this.handleError)); - } - - getCommunityPageHelpContents(community_pid: string, helpContentUrl:string) { - return this.http.get>(helpContentUrl + '/pagehelpcontent?community='+community_pid) - //.map(res => > res.json()) - .pipe(catchError(this.handleError)); - } - - getPageHelpContent(id : string, helpContentUrl:string) { - return this.http.get(helpContentUrl + '/pagehelpcontent/' + id) - //.map(res => res.json()) - .pipe(catchError(this.handleError)); - } - - savePageHelpContent(pageHelpContent: PageHelpContent, helpContentUrl:string) { - HelpContentService.removeNulls(pageHelpContent); - - return this.http.post(helpContentUrl + '/pagehelpcontent/save', JSON.stringify(pageHelpContent), CustomOptions.getAuthOptionsWithBody()) - //.map(res => res.json()) - .pipe(catchError(this.handleError)); - } - - updatePageHelpContent(pageHelpContent: PageHelpContent, helpContentUrl:string) { - HelpContentService.removeNulls(pageHelpContent); - - return this.http.post(helpContentUrl + '/pagehelpcontent/update', JSON.stringify(pageHelpContent), CustomOptions.getAuthOptionsWithBody()) - //.map(res => res.json()) - .pipe(catchError(this.handleError)); - } - - deletePageHelpContents(ids : string[], helpContentUrl:string) { - return this.http.post(helpContentUrl + 'pagehelpcontent/delete',JSON.stringify(ids), CustomOptions.getAuthOptionsWithBody()) - .pipe(catchError(this.handleError)); - } - - togglePageHelpContents(ids : string[],status : boolean, helpContentUrl:string) { - return this.http.post(helpContentUrl + '/pagehelpcontent/toggle?status='+ status.toString(), JSON.stringify(ids), CustomOptions.getAuthOptionsWithBody()) - //.map( res => res.json()) - .pipe(catchError(this.handleError)); - } - - private handleError(error: HttpErrorResponse) { - // in a real world app, we may send the error to some remote logging infrastructure - // instead of just logging it to the console - console.error(error); - return Observable.throw(error.error || 'Server error'); - } - - // getDataProviders() { - // return this.http.get('https://beta.services.openaire.eu/search/v2/api/datasources?format=json').map(res => res.json()).map(res => res.results).do(res => {console.log(res)}).catch(this.handleError); - // } - - getCommunityStatistics(apiUrl: string, communityId: string): Observable { - const url = `${apiUrl}communities/${communityId}`; - //console.log(`getting statistics summary from: ${url}`); - return this.http.get(url) - //.map(res => res.json()) - .pipe(map(res => res['statistics'])); - } - - getCommunityAdminStatisticsChoices(apiUrl: string, communityId: string): Observable { - const url = `${apiUrl}/statistics/${communityId}`; - //console.log(`getting admin choices for statistics from: ${url}`); - return this.http.get(url) - //.map(stats => stats.json()) - .pipe(catchError(this.handleError)); - } - - postCommunityAdminStatisticsChoices(apiUrl: string, - communityId: string, - entity: string, - chartsOrNumbers: string, - title: string, - status: boolean, - monitor: boolean): Observable { - const url = `${apiUrl}/statistics/${communityId}/${entity}/${chartsOrNumbers}?status=${status.toString()}&monitor=${monitor.toString()}`; - //console.log(`getting admin choices for statistics from: ${url}`); - - return this.http.post(url, title, CustomOptions.getAuthOptionsWithBody()) - //.map(stats => stats.json()) - .pipe(catchError(this.handleError)); + updateDivId(divId: DivId, helpContentUrl:string) { + HelpContentService.removeNulls(divId); + + return this.http.post(helpContentUrl + 'div/update', JSON.stringify(divId), CustomOptions.getAuthOptionsWithBody()) + //.map(res => res.json()) + .pipe(catchError(this.handleError)); + } + + getDivId(divId: string, helpContentUrl:string) { + return this.http.get(helpContentUrl + 'div/'+divId) + //.map(res => res.json()) + .pipe(catchError(this.handleError)); + } + + getDivIdFull(divId: string, helpContentUrl:string) { + return this.http.get(helpContentUrl + 'divFull/'+divId) + //.map(res => res.json()) + .pipe(catchError(this.handleError)); + } + + saveDivId(divId: DivId, helpContentUrl:string) { + HelpContentService.removeNulls(divId); + + return this.http.post(helpContentUrl + 'div/save', JSON.stringify(divId), CustomOptions.getAuthOptionsWithBody()) + //.map(res => res.json()) + .pipe(catchError(this.handleError)); + } + /* + getCommunitiesWithDivId(helpContentUrl:string) { + return this.http.get(helpContentUrl + 'community?div=true') + .map(res => > res.json()) + .catch(this.handleError); + } + */ + getCommunityPagesWithDivId(portal_pid: string, helpContentUrl:string) { + return this.http.get>(helpContentUrl + properties.adminToolsPortalType + '/'+portal_pid+'/pages?div=true') + //.map(res => > res.json()) + .pipe(catchError(this.handleError)); + } + + getCommunityDivHelpContents(portal_pid: string, helpContentUrl:string) { + return this.http.get>(helpContentUrl + 'divhelpcontent?portal='+portal_pid) + //.map(res => > res.json()) + .pipe(catchError(this.handleError)); + } + + getDivHelpContent(id : string, helpContentUrl:string) { + return this.http.get(helpContentUrl + 'divhelpcontent/' + id) + //.map(res => res.json()) + .pipe(catchError(this.handleError)); + } + + insertOrUpdateDivHelpContent(divHelpContent: DivHelpContent, helpContentUrl:string) { + HelpContentService.removeNulls(divHelpContent); + + return this.http.post(helpContentUrl + 'divhelpcontent', JSON.stringify(divHelpContent), CustomOptions.getAuthOptionsWithBody()) + //.map(res => res.json()) + .pipe(catchError(this.handleError)); + } + + deleteDivIds(ids : string[], helpContentUrl:string) { + return this.http.post(helpContentUrl + 'div/delete',JSON.stringify(ids), CustomOptions.getAuthOptionsWithBody()) + .pipe(catchError(this.handleError)); + } + + deleteDivHelpContents(ids : string[], helpContentUrl:string) { + return this.http.post(helpContentUrl + 'divhelpcontent/delete',JSON.stringify(ids), CustomOptions.getAuthOptionsWithBody()) + .pipe(catchError(this.handleError)); + } + + toggleDivHelpContents(ids : string[],status : boolean, helpContentUrl:string) { + + return this.http.post(helpContentUrl + 'divhelpcontent/toggle?status='+ status.toString(), JSON.stringify(ids), CustomOptions.getAuthOptionsWithBody()) + //.map( res => res.json()) + .pipe(catchError(this.handleError)); + } + + getPagesWithDivIds(portal_pid: string, helpContentUrl:string) { + let parameters = (portal_pid ? "?portal="+portal_pid : ""); + return this.http.get>(helpContentUrl + 'div/pages'+parameters) + //.map(res => >> res.json()) + .pipe(catchError(this.handleError)); + } + + getPages(helpContentUrl:string,pid:string,with_positions:boolean=null) { + let parameters: string = ""; + if(pid || with_positions == true || with_positions == false) { + parameters = "?"; + if(pid) { + parameters += "&pid="+pid; + } + if(with_positions == true || with_positions == false) { + parameters += "&with_positions="+with_positions; + } } + return this.http.get>(helpContentUrl + 'page'+parameters) + //.map(res => > res.json()) + .pipe(catchError(this.handleError)); + } + + getPagesFull(helpContentUrl:string,pid:string) { + return this.http.get>(helpContentUrl + 'pageFull'+(pid?("?pid="+pid):"")) + //.map(res => > res.json()) + .pipe(catchError(this.handleError)); + } + + getPage(pageId:string, helpContentUrl:string) { + return this.http.get(helpContentUrl + 'page/'+pageId) + //.map(res => res.json()) + .pipe(catchError(this.handleError)); + } + + getPageByRoute(route:string, helpContentUrl:string) { + return this.http.get(helpContentUrl + 'page/?page_route='+route) + .pipe(catchError(this.handleError)); + } + + getCommunities( helpContentUrl:string) { + return this.http.get>(helpContentUrl + properties.adminToolsPortalType) + //.map(res => > res.json()) + .pipe(catchError(this.handleError)); + } + + getCommunity(portal_pid: string, helpContentUrl:string) { + return this.http.get(helpContentUrl + properties.adminToolsPortalType + '/'+portal_pid) + //.map(res => res.json()) + .pipe(catchError(this.handleError)); + } + + getCommunitiesFull( helpContentUrl:string) { + return this.http.get>(helpContentUrl + properties.adminToolsPortalType + 'Full') + //.map(res => > res.json()) + .pipe(catchError(this.handleError)); + } + + getCommunityFull(portal_pid: string, helpContentUrl:string) { + return this.http.get(helpContentUrl + properties.adminToolsPortalType + 'Full/'+portal_pid) + //.map(res => res.json()) + .pipe(catchError(this.handleError)); + } + + saveCommunity(portal: Portal, helpContentUrl:string) { + // let headers = new Headers({'Content-Type': 'application/json'}); + // let options = new RequestOptions({headers: headers}); + + HelpContentService.removeNulls(portal); + + return this.http.post(helpContentUrl + portal.type + '/save', JSON.stringify(portal), CustomOptions.getAuthOptionsWithBody()) + //.map(res => res.json()) + .pipe(catchError(this.handleError)); + } + + updateCommunity(portal: Portal, helpContentUrl:string) { + // let headers = new Headers({'Content-Type': 'application/json'}); + // let options = new RequestOptions({headers: headers}); + + HelpContentService.removeNulls(portal); + + return this.http.post(helpContentUrl + portal.type + '/update', JSON.stringify(portal), CustomOptions.getAuthOptionsWithBody()) + //.map(res => res.json()) + .pipe(catchError(this.handleError)); + } + + deleteCommunities(ids : string[], helpContentUrl:string) { + // let headers = new Headers({'Content-Type': 'application/json'}); + // let options = new RequestOptions({headers: headers}); + + return this.http.post(helpContentUrl + properties.adminToolsPortalType + '/delete',JSON.stringify(ids), CustomOptions.getAuthOptionsWithBody()) + .pipe(catchError(this.handleError)); + } + + getCommunityPages(portal_pid: string, params: string, helpContentUrl:string) { + return this.http.get>(helpContentUrl + properties.adminToolsPortalType + '/'+portal_pid+'/pages'+params) + //.map(res => > res.json()) + .pipe(catchError(this.handleError)); + } + + getEntities(helpContentUrl:string) { + return this.http.get>(helpContentUrl + 'entity') + //.map(res => > res.json()) + .pipe(catchError(this.handleError)); + } + + getCommunityEntities(portal_pid: string, helpContentUrl:string) { + return this.http.get>(helpContentUrl + properties.adminToolsPortalType + '/'+portal_pid+'/entities') + //.map(res => > res.json()) + .pipe(catchError(this.handleError)); + } + + + saveEntity(entity: Entity, helpContentUrl:string) { + HelpContentService.removeNulls(entity); + + return this.http.post(helpContentUrl + 'entity/save', JSON.stringify(entity), CustomOptions.getAuthOptionsWithBody()) + //.map(res => res.json()) + .pipe(catchError(this.handleError)); + } + + updateEntity(entity: Entity, helpContentUrl:string) { + HelpContentService.removeNulls(entity); + + return this.http.post(helpContentUrl + 'entity/update', JSON.stringify(entity), CustomOptions.getAuthOptionsWithBody()) + //.map(res => res.json()) + .pipe(catchError(this.handleError)); + } + + // toggleEntity(selectedCommunityId: string, id : string,status : boolean) { + // let headers = new Headers({'Content-Type': 'application/json'}); + // let options = new RequestOptions({headers: headers}); + // + // return this.http.post(helpContentUrl + 'community/'+selectedCommunityId+'/entity/toggle?status='+ status.toString()+'&entityId='+id.toString(), options) + // .catch(this.handleError); + // } + + toggleEntities(selectedPortalPid: string, ids : string[],status : boolean, helpContentUrl:string) { + + return this.http.post(helpContentUrl + properties.adminToolsPortalType + '/'+selectedPortalPid+ '/entity/toggle?status='+ status.toString(), JSON.stringify(ids), CustomOptions.getAuthOptionsWithBody()) + //.map( res => res.json()) + .pipe(catchError(this.handleError)); + } + + deleteEntities(ids : string[], helpContentUrl:string) { + return this.http.post(helpContentUrl + 'entity/delete',JSON.stringify(ids), CustomOptions.getAuthOptionsWithBody()) + .pipe(catchError(this.handleError)); + } + + + toggleEntityOfPage(pageId: string, entityId : string,status : boolean, helpContentUrl:string) { + return this.http.post(helpContentUrl + 'page/'+pageId+'/entity/toggle?status='+ status.toString()+'&entityId='+entityId.toString(), CustomOptions.getAuthOptionsWithBody()) + .pipe(catchError(this.handleError)); + } + + savePage(page: Page, helpContentUrl:string) { + HelpContentService.removeNulls(page); + + return this.http.post(helpContentUrl + 'page/save', JSON.stringify(page), CustomOptions.getAuthOptionsWithBody()) + //.map(res => res.json()) + .pipe(catchError(this.handleError)); + } + + updatePage(page: Page, helpContentUrl:string) { + + HelpContentService.removeNulls(page); + + return this.http.post(helpContentUrl + 'page/update', JSON.stringify(page), CustomOptions.getAuthOptionsWithBody()) + //.map(res => res.json()) + .pipe(catchError(this.handleError)); + } + + togglePages(selectedPortalPid: string, ids : string[],status : boolean, helpContentUrl:string) { + + return this.http.post(helpContentUrl + properties.adminToolsPortalType + '/'+selectedPortalPid+'/page/toggle?status='+ status.toString(),JSON.stringify(ids), CustomOptions.getAuthOptionsWithBody()) + .pipe(catchError(this.handleError)); + } + + deletePages(ids : string[], helpContentUrl:string) { + + return this.http.post(helpContentUrl + 'page/delete',JSON.stringify(ids), CustomOptions.getAuthOptionsWithBody()) + .pipe(catchError(this.handleError)); + } + + getPageHelpContents(helpContentUrl:string) { + return this.http.get>(helpContentUrl + 'pagehelpcontent') + //.map(res => > res.json()) + .pipe(catchError(this.handleError)); + } + + getCommunityPageHelpContents(portal_pid: string, helpContentUrl:string) { + return this.http.get>(helpContentUrl + 'pagehelpcontent?portal='+portal_pid) + //.map(res => > res.json()) + .pipe(catchError(this.handleError)); + } + + getPageHelpContent(id : string, helpContentUrl:string) { + return this.http.get(helpContentUrl + 'pagehelpcontent/' + id) + //.map(res => res.json()) + .pipe(catchError(this.handleError)); + } + + savePageHelpContent(pageHelpContent: PageHelpContent, helpContentUrl:string) { + HelpContentService.removeNulls(pageHelpContent); + + return this.http.post(helpContentUrl + 'pagehelpcontent/save', JSON.stringify(pageHelpContent), CustomOptions.getAuthOptionsWithBody()) + //.map(res => res.json()) + .pipe(catchError(this.handleError)); + } + + updatePageHelpContent(pageHelpContent: PageHelpContent, helpContentUrl:string) { + HelpContentService.removeNulls(pageHelpContent); + + return this.http.post(helpContentUrl + 'pagehelpcontent/update', JSON.stringify(pageHelpContent), CustomOptions.getAuthOptionsWithBody()) + //.map(res => res.json()) + .pipe(catchError(this.handleError)); + } + + deletePageHelpContents(ids : string[], helpContentUrl:string) { + return this.http.post(helpContentUrl + 'pagehelpcontent/delete',JSON.stringify(ids), CustomOptions.getAuthOptionsWithBody()) + .pipe(catchError(this.handleError)); + } + + togglePageHelpContents(ids : string[],status : boolean, helpContentUrl:string) { + return this.http.post(helpContentUrl + 'pagehelpcontent/toggle?status='+ status.toString(), JSON.stringify(ids), CustomOptions.getAuthOptionsWithBody()) + //.map( res => res.json()) + .pipe(catchError(this.handleError)); + } + + private handleError(error: HttpErrorResponse) { + // in a real world app, we may send the error to some remote logging infrastructure + // instead of just logging it to the console + console.error(error); + return Observable.throw(error.error || 'Server error'); + } + + // getDataProviders() { + // return this.http.get('https://beta.services.openaire.eu/search/v2/api/datasources?format=json').map(res => res.json()).map(res => res.results).do(res => {console.log(res)}).catch(this.handleError); + // } + + getCommunityStatistics(apiUrl: string, portalId: string): Observable { + const url = `${apiUrl}communities/${portalId}`; + //console.log(`getting statistics summary from: ${url}`); + return this.http.get(url) + //.map(res => res.json()) + .pipe(map(res => res['statistics'])); + } + + getCommunityAdminStatisticsChoices(apiUrl: string, portalId: string): Observable { + const url = `${apiUrl}statistics/${portalId}`; + //console.log(`getting admin choices for statistics from: ${url}`); + return this.http.get(url) + //.map(stats => stats.json()) + .pipe(catchError(this.handleError)); + } + + postCommunityAdminStatisticsChoices(apiUrl: string, + portalId: string, + entity: string, + chartsOrNumbers: string, + title: string, + status: boolean, + monitor: boolean): Observable { + const url = `${apiUrl}statistics/${portalId}/${entity}/${chartsOrNumbers}?status=${status.toString()}&monitor=${monitor.toString()}`; + //console.log(`getting admin choices for statistics from: ${url}`); + + return this.http.post(url, title, CustomOptions.getAuthOptionsWithBody()) + //.map(stats => stats.json()) + .pipe(catchError(this.handleError)); + } + + statisticsIsActiveToggle(apiURL: string, id: string): Observable { + const url = apiURL + '/statistics/' + encodeURIComponent(id) + '/toggle'; + return this.http.post(url, {}, CustomOptions.getAuthOptionsWithBody()).pipe(catchError(this.handleError)); + } statisticsIsActiveToggle(apiURL: string, id: string): Observable { const url = apiURL + '/statistics/' + encodeURIComponent(id) + '/toggle'; diff --git a/services/layout.service.ts b/services/layout.service.ts index e4088c65..6083532a 100644 --- a/services/layout.service.ts +++ b/services/layout.service.ts @@ -4,6 +4,7 @@ import {Observable, throwError} from 'rxjs'; import {CustomOptions} from './servicesUtils/customOptions.class'; import {CustomizationOptions} from '../connect/community/CustomizationOptions'; import {EnvProperties} from "../utils/properties/env-properties"; +import {properties} from "../../../environments/environment"; @Injectable() export class LayoutService { @@ -23,12 +24,13 @@ export class LayoutService { saveLayout(properties: EnvProperties, pid: string, layout: CustomizationOptions): Observable { LayoutService.removeNulls(layout); - return this.http.post(properties.adminToolsAPIURL + 'community/' + return this.http.post(properties.adminToolsAPIURL + '/' + properties.adminToolsPortalType + '/' + pid + '/layout', layout, CustomOptions.getAuthOptionsWithBody()); } getLayout(properties: EnvProperties, pid: string): Observable { - return this.http.get(properties.adminToolsAPIURL+"/community/" + pid + '/layout'); + return this.http.get(properties.adminToolsAPIURL+"/" + properties.adminToolsPortalType + '/' + + pid + '/layout'); } mockLayout(): any { diff --git a/services/servicesUtils/customOptions.class.ts b/services/servicesUtils/customOptions.class.ts index be56ba77..3c6934f7 100644 --- a/services/servicesUtils/customOptions.class.ts +++ b/services/servicesUtils/customOptions.class.ts @@ -21,7 +21,7 @@ export class CustomOptions { }; } - public static getAuthOptions():any { + public static getAuthOptions():{} { const httpOptions = { headers: new HttpHeaders({ 'X-XSRF-TOKEN': (COOKIE.getCookie(COOKIE.cookieName_id))?COOKIE.getCookie(COOKIE.cookieName_id):'' diff --git a/utils/configuration/configuration.service.ts b/utils/configuration/configuration.service.ts index f308c330..d9e21b8f 100644 --- a/utils/configuration/configuration.service.ts +++ b/utils/configuration/configuration.service.ts @@ -8,14 +8,14 @@ import {BehaviorSubject, from, Observable, Subscription} from 'rxjs'; // import 'rxjs/add/operator/share'; import {map, mapTo} from 'rxjs/operators'; import {EnvProperties} from "../properties/env-properties"; -import {Community} from "../entities/adminTool/community"; +import {Portal} from "../entities/adminTool/portal"; import {Page} from "../entities/adminTool/page"; @Injectable({ providedIn: 'root' }) export class ConfigurationService { - private communityInformation: BehaviorSubject = new BehaviorSubject(null); + private communityInformation: BehaviorSubject = new BehaviorSubject(null); private sub: Subscription = null; - private source: Observable = null; + private source: Observable = null; private promise: Promise = null; constructor(private http: HttpClient ) {} @@ -30,7 +30,7 @@ export class ConfigurationService { * @deprecated */ getCommunityInformation(properties:EnvProperties, community:string){ - let url = properties.adminToolsAPIURL +"/communityFull/" + community; + let url = properties.adminToolsAPIURL +"/"+properties.adminToolsPortalType+"/" + community + '/full'; return this.http.get((properties.useLongCache) ? (properties.cacheUrl + encodeURIComponent(url)) : url); //.map(res => res.json()); } @@ -38,13 +38,13 @@ export class ConfigurationService { public initCommunityInformation(properties:EnvProperties, community:string) { if(community == null) return; - let url = properties.adminToolsAPIURL +"/communityFull/" + community; + let url = properties.adminToolsAPIURL +"/" + properties.adminToolsPortalType + "/" + community + "/full"; this.promise = new Promise((resolve => { - this.source = this.http.get((properties.useLongCache) ? (properties.cacheUrl + encodeURIComponent(url)) : url); + this.source = this.http.get((properties.useLongCache) ? (properties.cacheUrl + encodeURIComponent(url)) : url); this.sub = this.source .subscribe( - (communityInformation: Community) => { + (communityInformation: Portal) => { this.communityInformation.next(communityInformation); resolve(); }, @@ -56,7 +56,7 @@ export class ConfigurationService { } - public get communityInformationState(): Observable { + public get communityInformationState(): Observable { return this.communityInformation.asObservable(); } @@ -81,7 +81,7 @@ export class ConfigurationService { isPageEnabled(properties:EnvProperties, community:string,router: string){ let page_route: string = router.split('?')[0].substring(1); - let url = properties.adminToolsAPIURL + "/community/" + community+"/pages?page_route="+page_route; + let url = properties.adminToolsAPIURL + "/"+properties.adminToolsPortalType+"/" + community+"/pages?page_route="+page_route; return this.http.get((properties.useLongCache) ? (properties.cacheUrl + encodeURIComponent(url)) : url) //.map(res => res.json()) .pipe(map(res => { @@ -109,7 +109,7 @@ export class ConfigurationService { } filtering(page_route: string) { - let community: Community = this.communityInformation.getValue(); + let community: Portal = this.communityInformation.getValue(); let pages: Page[] = community.pages; pages = pages.filter(function (page: Page) { diff --git a/utils/entities/adminTool/div-help-content.ts b/utils/entities/adminTool/div-help-content.ts index ed948a1e..b93d530e 100644 --- a/utils/entities/adminTool/div-help-content.ts +++ b/utils/entities/adminTool/div-help-content.ts @@ -1,10 +1,10 @@ import { DivId } from './divId'; -import {Community} from './community'; +import {Portal} from './portal'; export interface DivHelpContent { _id: string; divId: DivId | string; - community: string | Community; + portal: string | Portal; content: string; isActive: boolean; } diff --git a/utils/entities/adminTool/divId.ts b/utils/entities/adminTool/divId.ts index 3cca9078..2db4e991 100644 --- a/utils/entities/adminTool/divId.ts +++ b/utils/entities/adminTool/divId.ts @@ -4,9 +4,7 @@ export interface DivId { _id: string; name: string; pages: Page[] | String[]; - connect: boolean; - communities: boolean; - openaire: boolean; + portalType: string; } export interface CheckDivId { diff --git a/utils/entities/adminTool/html-page-content.ts b/utils/entities/adminTool/html-page-content.ts index 40643561..3e353e91 100644 --- a/utils/entities/adminTool/html-page-content.ts +++ b/utils/entities/adminTool/html-page-content.ts @@ -1,10 +1,10 @@ import { Page } from "./page"; -import { Community } from "./community"; +import { Portal } from "./portal"; export interface HtmlPageContent { _id: string; page: Page | string; - community: Community | string; + portal: Portal | string; content: string; } diff --git a/utils/entities/adminTool/page-help-content.ts b/utils/entities/adminTool/page-help-content.ts index 8fe047be..43130a1f 100644 --- a/utils/entities/adminTool/page-help-content.ts +++ b/utils/entities/adminTool/page-help-content.ts @@ -2,12 +2,12 @@ * Created by stefania on 7/13/17. */ import { Page } from './page'; -import { Community } from './community'; +import {Portal} from "./portal"; export interface PageHelpContent { _id: string; page: Page | string; - community: Community | string; + portal: Portal | string; placement: string; order: number; content: string; diff --git a/utils/entities/adminTool/page.ts b/utils/entities/adminTool/page.ts index 6768486e..e9676e8c 100644 --- a/utils/entities/adminTool/page.ts +++ b/utils/entities/adminTool/page.ts @@ -6,9 +6,7 @@ export interface Page { name: string; type: string; isEnabled: boolean; - connect: boolean; - communities: boolean; - openaire: boolean; + portalType: string; entities: Entity[] | string[]; top: boolean; bottom: boolean; diff --git a/utils/entities/adminTool/community.ts b/utils/entities/adminTool/portal.ts similarity index 67% rename from utils/entities/adminTool/community.ts rename to utils/entities/adminTool/portal.ts index 9dd3177c..a82887df 100644 --- a/utils/entities/adminTool/community.ts +++ b/utils/entities/adminTool/portal.ts @@ -1,15 +1,16 @@ import {Page} from './page'; import {Entity} from './entity'; -export interface Community { +export interface Portal { _id: string; pid: string; name: string; + type: string; entities: string[] | Entity[]; pages: string[] | Page[]; } -export interface CheckCommunity { - community: Community; +export interface CheckPortal { + community: Portal; checked: boolean; } diff --git a/utils/helper/helper.service.ts b/utils/helper/helper.service.ts index 4c1ae517..1ef9929b 100644 --- a/utils/helper/helper.service.ts +++ b/utils/helper/helper.service.ts @@ -35,7 +35,7 @@ export class HelperService { } let page_route: string = router.split('?')[0].substring(0); let url = properties.adminToolsAPIURL; - url += '/community/' + communityId + '/pagehelpcontent?active=true&page='+page_route; + url += '/'+properties.adminToolsPortalType+'/' + communityId + '/pagehelpcontent/grouped?active=true&page='+page_route; return this.http.get((properties.useLongCache)? (properties.cacheUrl+encodeURIComponent(url)): url); } @@ -45,7 +45,7 @@ export class HelperService { } let page_route: string = router.split('?')[0].substring(0); let url = properties.adminToolsAPIURL; - url += '/community/' + communityId + '/divhelpcontent?active=true&page='+page_route; + url += '/'+properties.adminToolsPortalType+'/' + communityId + '/divhelpcontent/grouped?active=true&page='+page_route; return this.http.get((properties.useLongCache)? (properties.cacheUrl+encodeURIComponent(url)): url); } diff --git a/utils/properties/env-properties.ts b/utils/properties/env-properties.ts index 144115ec..2ef687f1 100644 --- a/utils/properties/env-properties.ts +++ b/utils/properties/env-properties.ts @@ -1,8 +1,10 @@ export type Environment = "development" | "test" | "beta" | "production"; export type Dashboard = "explore" | "connect" | "monitor"; +export type PortalType = "explore" | "connect" | "community" | "monitor"; export interface EnvProperties { environment?: Environment; + adminToolsPortalType?: PortalType; dashboard?: Dashboard; isDashboard?: boolean; domain?: string; @@ -57,6 +59,7 @@ export interface EnvProperties { feedbackmail?: string; feedbackmailForMissingEntities?: string; cacheUrl?: string; + deleteCacheUrl?: string; monitorServiceAPIURL?: string; adminToolsAPIURL?: string; adminToolsCommunity?: string; diff --git a/utils/subscribe/subscribe.service.ts b/utils/subscribe/subscribe.service.ts index 593045bb..d4ea983f 100644 --- a/utils/subscribe/subscribe.service.ts +++ b/utils/subscribe/subscribe.service.ts @@ -5,6 +5,7 @@ import {CustomOptions} from "../../services/servicesUtils/customOptions.class"; import {EnvProperties} from "../properties/env-properties"; import {COOKIE} from "../../login/utils/helper.class"; import {BehaviorSubject, Observable} from "rxjs"; +import {properties} from "../../../../environments/environment"; @Injectable() export class SubscribeService { @@ -13,7 +14,7 @@ export class SubscribeService { constructor(private http: HttpClient) {} public initIsSubscribedToCommunity(properties: EnvProperties, pid: string) { - let url = properties.adminToolsAPIURL + "/community/" + pid + "/is-subscriber/"; + let url = properties.adminToolsAPIURL + "/"+ properties.adminToolsPortalType +"/" + pid + "/is-subscriber/"; this.http.get(url, CustomOptions.getAuthOptionsWithBody()).subscribe((isSubscribed) => { this.isSubscribedSubject.next(isSubscribed); }, error => { @@ -26,17 +27,17 @@ export class SubscribeService { } getCommunitySubscribers(properties: EnvProperties, pid: string) { - let url = properties.adminToolsAPIURL + "/community/" + pid + "/subscribers"; + let url = properties.adminToolsAPIURL + "/" + properties.adminToolsPortalType + "/" + pid + "/subscribers"; return this.http.get((properties.useCache) ? (properties.cacheUrl + encodeURIComponent(url)) : url); } getNumberOfCommunitySubscribers(properties: EnvProperties, pid: string) { - let url = properties.adminToolsAPIURL + "/community/" + pid + "/subscribers/count"; + let url = properties.adminToolsAPIURL + "/"+ properties.adminToolsPortalType +"/" + pid + "/subscribers/count"; return this.http.get((properties.useCache) ? (properties.cacheUrl + encodeURIComponent(url)) : url); } isSubscribedToCommunity(properties: EnvProperties, pid: string) { - let url = properties.adminToolsAPIURL + "/community/" + pid + "/is-subscriber/"; + let url = properties.adminToolsAPIURL + "/"+ properties.adminToolsPortalType +"/" + pid + "/is-subscriber/"; return this.http.get(url, CustomOptions.getAuthOptionsWithBody()) .pipe(map(res => { // if (res['status'] && res['status'] != 200) { @@ -56,24 +57,24 @@ export class SubscribeService { } subscribeToCommunity(properties: EnvProperties, pid: string) { - return this.http.post(properties.adminToolsAPIURL + "/community/" + pid + "/subscriber", {}, CustomOptions.getAuthOptionsWithBody()) + return this.http.post(properties.adminToolsAPIURL + "/"+ properties.adminToolsPortalType +"/" + pid + "/subscriber", {}, CustomOptions.getAuthOptionsWithBody()) .pipe(tap(isSubscribed => { this.isSubscribedSubject.next(isSubscribed);})); } unSubscribeToCommunity(properties: EnvProperties, pid: string) { - return this.http.post(properties.adminToolsAPIURL + "/community/" + pid + "/subscriber/delete", {}, CustomOptions.getAuthOptionsWithBody()) + return this.http.post(properties.adminToolsAPIURL + "/"+ properties.adminToolsPortalType+"/" + pid + "/subscriber/delete", {}, CustomOptions.getAuthOptionsWithBody()) .pipe(tap(unSubscribed => { this.isSubscribedSubject.next(!unSubscribed);})); } subscribeToCommunityByEmail(properties: EnvProperties, pid: string, email: string) { let subscriber = {"email": email}; - return this.http.post(properties.adminToolsAPIURL + "/community/" + pid + "/subscribers", JSON.stringify(subscriber), CustomOptions.getAuthOptionsWithBody()); + return this.http.post(properties.adminToolsAPIURL + "/"+ properties.adminToolsPortalType+"/" + pid + "/subscribers", JSON.stringify(subscriber), CustomOptions.getAuthOptionsWithBody()); } unSubscribeToCommunityByEmail(properties: EnvProperties, pid: string, email: string) { - return this.http.post(properties.adminToolsAPIURL + "/community/" + pid + "/subscribers/delete", JSON.stringify([email]), CustomOptions.getAuthOptionsWithBody()); + return this.http.post(properties.adminToolsAPIURL + "/"+ properties.adminToolsPortalType+"/" + pid + "/subscribers/delete", JSON.stringify([email]), CustomOptions.getAuthOptionsWithBody()); } getCommunitiesSubscribedTo(properties: EnvProperties/*, email: string*/) {