[Library | Trunk]: Fix admin tools pages portal type configuration.

git-svn-id: https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-services-library/trunk/ng-openaire-library/src/app@60561 d315682c-612b-4755-9ff5-7f18f6832af3
This commit is contained in:
k.triantafyllou 2021-03-02 15:52:09 +00:00
parent 8acc64fc10
commit cd519aa1e5
10 changed files with 425 additions and 428 deletions

View File

@ -4,7 +4,7 @@ import {
Router,
CanActivate,
ActivatedRouteSnapshot,
RouterStateSnapshot,
RouterStateSnapshot, UrlTree, CanActivateChild,
} from '@angular/router';
import {Observable, Subscription} from 'rxjs';
@ -12,22 +12,27 @@ import {CommunityService} from '../community/community.service';
import {properties} from "../../../../environments/environment";
@Injectable()
export class ConnectCommunityGuard implements CanActivate {
export class ConnectCommunityGuard implements CanActivate, CanActivateChild {
sub: Subscription = null;
constructor(private router: Router,
private communityService: CommunityService) {
}
check(community: string): Observable<boolean> | boolean {
check(community: string, url: string): Observable<boolean> | boolean {
return this.communityService.isCommunityType(community).pipe(take(1), tap(isCommunity => {
if (!isCommunity) {
this.router.navigate(['errorcommunity']);
this.router.navigate(['/error'], {queryParams: {'page': url}});
}
}));
}
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean> | boolean {
return this.check(route.queryParams['communityId']);
return this.check(route.queryParams['communityId'], state.url);
}
canActivateChild(childRoute: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean | UrlTree> | Promise<boolean | UrlTree> | boolean | UrlTree {
let community = childRoute.params['community'];
return community && this.check(community, state.url);
}
}

View File

@ -1,55 +1,39 @@
import {tap} from 'rxjs/operators';
import {Injectable} from '@angular/core';
import {
Router,
CanActivate,
ActivatedRouteSnapshot,
CanActivate,
CanActivateChild,
Router,
RouterStateSnapshot,
CanLoad,
Route, UrlSegment, CanActivateChild, UrlTree
UrlTree
} from '@angular/router';
import {Observable, Subscription} from 'rxjs';
import {CommunityService} from '../community/community.service';
import { EnvironmentSpecificService} from '../../utils/properties/environment-specific.service';
import {ConnectHelper} from '../connectHelper';
import {properties} from "../../../../environments/environment";
@Injectable()
export class ConnectRIGuard implements CanActivate, CanLoad, CanActivateChild {
export class ConnectRIGuard implements CanActivate, CanActivateChild {
sub: Subscription = null;
constructor(private router: Router,
private communityService: CommunityService,
private propertiesService: EnvironmentSpecificService) {
private communityService: CommunityService) {
}
check(community: string): Observable<boolean> | boolean {
check(community: string, url: string): Observable<boolean> | boolean {
return this.communityService.isRIType(community).pipe(tap(authorized => {
if (!authorized) {
this.router.navigate(['errorcommunity']);
this.router.navigate(['/error'], {queryParams: {'page': url}});
}
}));
}
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean> | boolean {
let community = route.params['community'];
return community && this.check(community);
return community && this.check(community, state.url);
}
canActivateChild(childRoute: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean | UrlTree> | Promise<boolean | UrlTree> | boolean | UrlTree {
let community = childRoute.params['community'];
return community && this.check(community);
}
canLoad(route: Route, segments: UrlSegment[]): Observable<boolean> | Promise<boolean> | boolean {
const path = '/' + route.path + document.location.search;
return this.check(ConnectHelper.getCommunityFromPath(path));
}
canDeactivate() {
if(this.sub) {
this.sub.unsubscribe();
}
return true;
return community && this.check(community, state.url);
}
}

View File

@ -50,7 +50,7 @@
</div>
<!--<div *ngIf="checkboxes.length > 0" class=" uk-margin-remove-top uk-margin-small-left"
[attr.uk-tooltip]="getSelectedEntities().length == 0 ? 'pos:left; cls: uk-active' : 'cls: uk-invisible'"
title="Select at least one help text">
title="Select at least one entity">
<input id="checkAll" type="checkbox" (click)="selectAll()"
[ngModel]="getSelectedEntities().length ==checkboxes.length"/>
<a *ngIf="!isPortalAdministrator" class="uk-margin-left" [class.uk-disabled]="getSelectedEntities().length
@ -63,10 +63,10 @@
</div>-->
</div>
<div *ngIf="checkboxes.length > 0"
class="uk-margin-remove-top uk-margin-small-left uk-margin-small-bottom"
[attr.uk-tooltip]="getSelectedEntities().length == 0 ? 'pos:left; cls: uk-active' : 'cls: uk-invisible'"
title="Select at least one help text"><input id="checkAll" type="checkbox" (click)="selectAll()"
<div *ngIf="!showLoading && checkboxes.length > 0"
class="uk-margin-remove-top uk-margin-small-left uk-margin-small-bottom uk-display-inline"
[attr.uk-tooltip]="getSelectedEntities().length == 0 ? 'pos:left; cls: uk-active' : null"
title="Select at least one entity"><input id="checkAll" type="checkbox" (click)="selectAll()"
[ngModel]="getSelectedEntities().length ==checkboxes.length"/>
<span *ngIf="getSelectedEntities().length > 0" class="uk-margin-left uk-text-muted">
{{getSelectedEntities().length}} entities selected </span>
@ -74,7 +74,7 @@
<div uk-dropdown="mode: click">
<ul class="uk-nav uk-dropdown-nav"
[attr.uk-tooltip]="getSelectedEntities().length == 0 ? 'pos:left; cls: uk-active' : 'cls: uk-invisible'"
title="Select at least one help text">
title="Select at least one entity">
<li *ngIf="!isPortalAdministrator"><a [class]="getSelectedEntities().length == 0 ? 'uk-disabled' : ''"
(click)="toggleEntities(true,getSelectedEntities())"><i></i> Enable
</a></li>

View File

@ -74,9 +74,7 @@ export class EntitiesComponent implements OnInit {
}));
this.userManagementService.getUserInfo().subscribe(user => {
this.portal = (this.route.snapshot.data.portal) ? this.route.snapshot.data.portal : this.route.snapshot.params[this.route.snapshot.data.param];
if(this.portal === 'connect' || this.portal === 'openaire' || this.portal === 'monitor') {
ConnectHelper.setPortalTypeFromPid(this.portal);
}
this.applyPortalFilter(this.portal);
this.isPortalAdministrator = Session.isPortalAdministrator(user) && !this.portal;
});

View File

@ -1,14 +1,15 @@
<div page-content>
<div header>
<!-- <div class="uk-text-bold">
<span *ngIf="pageId && page">{{page.name}}</span>
</div>-->
<div class="uk-margin-top">
<a
routerLink="../" [queryParams]=" { 'pageId': pageId }" class="uk-text-secondary">
<span class="uk-icon-button small uk-icon uk-button-secondary">
<icon name="arrow_left"></icon></span>
Go back to helptexts list</a>
<a routerLink="../" [queryParams]=" { 'pageId': pageId }"
class="uk-text-secondary uk-text-uppercase uk-text-bold uk-text-small">
<span class="uk-icon-button uk-icon small uk-button-secondary">
<icon name="arrow_left"></icon>
</span>
<span class="space">
Go back to helptexts list
</span>
</a>
</div>
</div>
<div inner>

View File

@ -11,16 +11,16 @@ import {properties} from '../../../../environments/environment';
import {from, Observable, Subscriber, Subscription} from 'rxjs';
import {HelperFunctions} from '../../utils/HelperFunctions.class';
import {PageHelpContent} from '../../utils/entities/adminTool/page-help-content';
import {ConnectHelper} from "../../connect/connectHelper";
@Component({
selector: 'page-content-form',
templateUrl: './page-help-content-form.component.html',
})
export class PageContentFormComponent implements OnInit {
myForm: FormGroup;
communityPid: string;
portal: string;
pageId: string;
pageContentId: string;
page: Page;
@ -38,13 +38,16 @@ export class PageContentFormComponent implements OnInit{
@Input() updateErrorMessage: string = '';
private subs: Subscription[] = [];
private pageHelpContent: PageHelpContent;
constructor(private route: ActivatedRoute, private _router: Router, private _fb: FormBuilder, private _helpContentService: HelpContentService){}
constructor(private route: ActivatedRoute, private _router: Router, private _fb: FormBuilder, private _helpContentService: HelpContentService) {
}
ngOnInit() {
this.properties = properties;
this.subs.push(this.route.params.subscribe(params => {
this.communityPid = params['community'];
this.portal = (this.route.snapshot.data.portal) ? this.route.snapshot.data.portal : this.route.snapshot.params[this.route.snapshot.data.param];
ConnectHelper.setPortalTypeFromPid(this.portal);
this.subs.push(this.route.queryParams.subscribe(params => {
HelperFunctions.scroll();
this.pageId = params['pageId'];
@ -74,6 +77,7 @@ export class PageContentFormComponent implements OnInit{
}));
}));
}
ngOnDestroy() {
this.subs.forEach(value => {
if (value instanceof Subscriber) {
@ -81,9 +85,10 @@ export class PageContentFormComponent implements OnInit{
}
});
}
getInfo(pageId: string) {
this.showLoading = true;
let obs = Observable.zip(this._helpContentService.getPageByPortal(pageId,this.properties.adminToolsAPIURL, this.communityPid), this._helpContentService.getCommunityPageHelpContents(this.communityPid, this.properties.adminToolsAPIURL, pageId));
let obs = Observable.zip(this._helpContentService.getPageByPortal(pageId, this.properties.adminToolsAPIURL, this.portal), this._helpContentService.getCommunityPageHelpContents(this.portal, this.properties.adminToolsAPIURL, pageId));
this.subs.push(obs.subscribe(
results => {
this.page = results[0];
@ -115,6 +120,7 @@ export class PageContentFormComponent implements OnInit{
));
}
/*private getPage(pageId: string) {
this.subs.push(this._helpContentService.getPageByPortal(pageId,this.properties.adminToolsAPIURL, this.communityPid).subscribe(
page => {
@ -179,6 +185,7 @@ export class PageContentFormComponent implements OnInit{
this.myForm.markAsPristine();
}
initFormWithSelectOptions() {
if (this.placementsOptions.length == 1) {
this.myForm.get("placement").setValue(this.placementsOptions[0].value);
@ -191,6 +198,7 @@ export class PageContentFormComponent implements OnInit{
this.myForm.get('placement').disable()
}
}
public setOptions(page: Page, countContents: number) {
this.placementsOptions = [];
if (page.top) {
@ -211,7 +219,7 @@ export class PageContentFormComponent implements OnInit{
public get form() {
return this._fb.group({
page: [this.pageId, Validators.required],
portal : this.communityPid,
portal: this.portal,
placement: ['', Validators.required],
content: ['', Validators.required],
order: [1, Validators.required],
@ -224,7 +232,7 @@ export class PageContentFormComponent implements OnInit{
public reset() {
this.myForm.patchValue({
page: '',
portal : this.communityPid,
portal: this.portal,
placement: '',
content: [''],
order: 1,
@ -244,7 +252,12 @@ export class PageContentFormComponent implements OnInit{
public saveCustom() {
if (!Session.isLoggedIn()) {
this._router.navigate(['/user-info'], { queryParams: { "errorCode": LoginErrorCodes.NOT_VALID, "redirectUrl": this._router.url} });
this._router.navigate(['/user-info'], {
queryParams: {
"errorCode": LoginErrorCodes.NOT_VALID,
"redirectUrl": this._router.url
}
});
} else {
//this.errorMessage = null;
@ -254,7 +267,7 @@ export class PageContentFormComponent implements OnInit{
this.myForm.get('order').enable();
this.myForm.get('placement').enable();
let pageHelpContent: PageHelpContent = this.myForm.value;
this.subs.push(this._helpContentService.savePageHelpContent(pageHelpContent, this.properties.adminToolsAPIURL, this.communityPid).subscribe(
this.subs.push(this._helpContentService.savePageHelpContent(pageHelpContent, this.properties.adminToolsAPIURL, this.portal).subscribe(
_ => {
this._router.navigate(['../'], {queryParams: {"pageId": this.pageId}, relativeTo: this.route});
this.showLoading = false;
@ -285,6 +298,7 @@ export class PageContentFormComponent implements OnInit{
this.showLoading = false;
}
changeStatus() {
this.myForm.get('isActive').setValue(!this.myForm.get('isActive').value);
if (this.pageHelpContent && this.myForm.get('isActive').value != this.pageHelpContent.isActive || !this.pageHelpContent && !this.myForm.get('isActive').value) {
@ -293,6 +307,7 @@ export class PageContentFormComponent implements OnInit{
this.myForm.get('isActive').markAsPristine()
}
}
contentChanged() {
if (this.pageHelpContent && this.myForm.get('content').value != this.pageHelpContent.content || !this.pageHelpContent && this.myForm.get('content').value != '') {
this.myForm.get('content').markAsDirty();

View File

@ -8,11 +8,14 @@
<span *ngIf="selectedPageId && page">{{page.name}}</span>
</div>
<div class="uk-margin-top">
<a
routerLink="../pages/" class="uk-text-secondary">
<a routerLink="../pages/" class="uk-text-secondary uk-text-uppercase uk-text-bold uk-text-small">
<span class="uk-icon-button small uk-icon uk-button-secondary">
<icon name="arrow_left"></icon></span>
Go back to pages list</a>
<icon name="arrow_left"></icon>
</span>
<span class="space">
Go back to pages list
</span>
</a>
</div>
<div class="uk-width-1-1 uk-flex uk-flex-right@m uk-flex-center uk-flex-wrap uk-flex-middle uk-grid" uk-grid>
<div #searchInputComponent search-input [control]="filterForm" [showSearch]="false" placeholder="Search helptext"

View File

@ -24,7 +24,6 @@ import {ConnectHelper} from '../../connect/connectHelper';
selector: 'page-help-contents',
templateUrl: './page-help-contents.component.html',
})
export class PageHelpContentsComponent implements OnInit {
@ViewChild('AlertModalDeletePageHelpContents') alertModalDeletePageHelpContents;
@ -47,7 +46,7 @@ export class PageHelpContentsComponent implements OnInit {
public communities: Portal[] = [];
public selectedCommunityPid: string;
public portal: string;
public selectedPageId: string;
@ -78,17 +77,12 @@ export class PageHelpContentsComponent implements OnInit {
this.properties = properties;
this.subscriptions.push(this.route.params.subscribe(params => {
this.selectedCommunityPid = params['community'];
if(!this.selectedCommunityPid) {
this.selectedCommunityPid = (this.route.snapshot.data.portal) ? this.route.snapshot.data.portal : this.route.snapshot.params[this.route.snapshot.data.param];
if (this.selectedCommunityPid === 'connect' || this.selectedCommunityPid === 'openaire' || this.selectedCommunityPid === 'monitor') {
ConnectHelper.setPortalTypeFromPid(this.selectedCommunityPid);
}
}
this.portal = (this.route.snapshot.data.portal) ? this.route.snapshot.data.portal : this.route.snapshot.params[this.route.snapshot.data.param];
ConnectHelper.setPortalTypeFromPid(this.portal);
this.subscriptions.push(this.route.queryParams.subscribe(params => {
HelperFunctions.scroll();
this.selectedPageId = params['pageId'];
if (this.selectedCommunityPid && this.selectedPageId) {
if (this.portal && this.selectedPageId) {
this.getPage(this.selectedPageId);
}
if(!this.selectedPageId) {
@ -124,13 +118,13 @@ export class PageHelpContentsComponent implements OnInit {
this.showLoading = true;
this.updateErrorMessage = "";
this.errorMessage = "";
this.subscriptions.push(this._helpService.getPageByPortal(pageId, this.properties.adminToolsAPIURL, this.selectedCommunityPid).subscribe(
this.subscriptions.push(this._helpService.getPageByPortal(pageId, this.properties.adminToolsAPIURL, this.portal).subscribe(
page => {
if (this.properties.adminToolsPortalType != page.portalType) {
this.router.navigate(['./pageContents'], {queryParams: {"communityId": this.selectedCommunityPid}});
this.router.navigate(['./pageContents'], {queryParams: {"communityId": this.portal}});
} else {
this.page = page;
this.getPageHelpContents(this.selectedCommunityPid);
this.getPageHelpContents(this.portal);
}
},
error => this.handleError('System error retrieving page', error)));
@ -154,7 +148,7 @@ export class PageHelpContentsComponent implements OnInit {
this.subscriptions.push(this._helpService.getCommunityPagesWithPositions(community_pid,this.properties.adminToolsAPIURL).subscribe(
pages => {
this.pages = pages;
this.getPageHelpContents(this.selectedCommunityPid);
this.getPageHelpContents(this.portal);
this.selectOptions = [{label:'All pages', value: ''}];
for (let page of this.pages) {
this.selectOptions.push({label:page.name, value: page._id})
@ -271,7 +265,7 @@ export class PageHelpContentsComponent implements OnInit {
this.showLoading = true;
this.updateErrorMessage = "";
this.subscriptions.push(this._helpService.deletePageHelpContents(this.selectedPageContents, this.properties.adminToolsAPIURL, this.selectedCommunityPid).subscribe(
this.subscriptions.push(this._helpService.deletePageHelpContents(this.selectedPageContents, this.properties.adminToolsAPIURL, this.portal).subscribe(
_ => {
this.deletePageHelpContentsFromArray(this.selectedPageContents);
this.showLoading = false;
@ -297,7 +291,7 @@ export class PageHelpContentsComponent implements OnInit {
this.router.navigate(['edit/'], {
queryParams: {
"pageContentId": id,
"communityId": this.selectedCommunityPid,
"communityId": this.portal,
"pageId": this.selectedPageId
}, relativeTo: this.route
});
@ -305,7 +299,7 @@ export class PageHelpContentsComponent implements OnInit {
this.router.navigate(['edit/'], {
queryParams: {
"pageContentId": id,
"communityId": this.selectedCommunityPid
"communityId": this.portal
}, relativeTo: this.route
});
}
@ -322,7 +316,7 @@ export class PageHelpContentsComponent implements OnInit {
} else {
this.updateErrorMessage = "";
this.subscriptions.push(this._helpService.togglePageHelpContents(ids, status, this.properties.adminToolsAPIURL, this.selectedCommunityPid).subscribe(
this.subscriptions.push(this._helpService.togglePageHelpContents(ids, status, this.properties.adminToolsAPIURL, this.portal).subscribe(
() => {
for (let id of ids) {
let i = this.checkboxes.findIndex(_ => _.pageHelpContent._id == id);

View File

@ -28,11 +28,10 @@
</div>
</div>
</div>
<div *ngIf="checkboxes.length > 0"
class="uk-padding uk-padding-remove-bottom uk-padding-remove-top uk-margin-remove-top uk-margin-small-bottom"
[attr.uk-tooltip]="getSelectedPages().length == 0 ? 'pos:left; cls: uk-active' : 'cls: uk-invisible'"
title="Select at least one help text"><input id="checkAll" type="checkbox" (click)="selectAll()"
<div *ngIf="!showLoading && checkboxes.length > 0"
class="uk-padding uk-padding-remove-bottom uk-padding-remove-top uk-margin-remove-top uk-margin-small-bottom uk-display-inline"
[attr.uk-tooltip]="getSelectedPages().length == 0 ? 'pos:left; cls: uk-active' : null"
title="Select at least one page"><input id="checkAll" type="checkbox" (click)="selectAll()"
[ngModel]="getSelectedPages().length ==checkboxes.length"/>
<span *ngIf="getSelectedPages().length > 0" class="uk-margin-left uk-text-muted">
{{getSelectedPages().length}} pages selected </span>
@ -40,7 +39,7 @@
<div uk-dropdown="mode: click">
<ul class="uk-nav uk-dropdown-nav"
[attr.uk-tooltip]="getSelectedPages().length == 0 ? 'pos:left; cls: uk-active' : 'cls: uk-invisible'"
title="Select at least one help text">
title="Select at least one page">
<li *ngIf="!isPortalAdministrator"><a [class]="getSelectedPages().length == 0 ? 'uk-disabled' : ''"
(click)="togglePages(true,getSelectedPages())"><i></i> Enable
</a></li>

View File

@ -91,9 +91,7 @@ export class PagesComponent implements OnInit {
this.filterForm.get('type').setValue(params['type']);
}
this.portal = (this.route.snapshot.data.portal) ? this.route.snapshot.data.portal : this.route.snapshot.params[this.route.snapshot.data.param];
if (this.portal === 'connect' || this.portal === 'openaire' || this.portal === 'monitor') {
ConnectHelper.setPortalTypeFromPid(this.portal);
}
this.keyword = '';
this.subscriptions.push(this.userManagementService.getUserInfo().subscribe(user => {
this.applyPortalFilter(this.portal);