[Library | Trunk]: Change admin tools pages to get portal from path param

git-svn-id: https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-services-library/trunk/ng-openaire-library/src/app@60294 d315682c-612b-4755-9ff5-7f18f6832af3
This commit is contained in:
k.triantafyllou 2021-01-26 16:21:55 +00:00
parent 1b1e0170e1
commit 8ca5f8e411
8 changed files with 210 additions and 238 deletions

View File

@ -30,8 +30,10 @@ export class ConnectRIGuard implements CanActivate, CanLoad {
} }
})); }));
} }
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean> | boolean { canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean> | boolean {
return this.check(route.queryParams['communityId']); let community = route.params['community']?route.params['community']:route.queryParams['communityId'];
return community && this.check(community);
} }
canLoad(route: Route, segments: UrlSegment[]): Observable<boolean> | Promise<boolean> | boolean { canLoad(route: Route, segments: UrlSegment[]): Observable<boolean> | Promise<boolean> | boolean {

View File

@ -11,6 +11,7 @@ import {HelperFunctions} from "../../utils/HelperFunctions.class";
import {UserManagementService} from '../../services/user-management.service'; import {UserManagementService} from '../../services/user-management.service';
import {Subscriber} from "rxjs"; import {Subscriber} from "rxjs";
import {properties} from "../../../../environments/environment"; import {properties} from "../../../../environments/environment";
import {ConnectHelper} from "../../connect/connectHelper";
@Component({ @Component({
selector: 'entities', selector: 'entities',
@ -18,29 +19,29 @@ import {properties} from "../../../../environments/environment";
}) })
export class EntitiesComponent implements OnInit { export class EntitiesComponent implements OnInit {
@ViewChild('AlertModalSaveEntity') alertModalSaveEntity; @ViewChild('AlertModalSaveEntity') alertModalSaveEntity;
@ViewChild('AlertModalDeleteEntities') alertModalDeleteEntities; @ViewChild('AlertModalDeleteEntities') alertModalDeleteEntities;
private selectedEntities: string[] = []; private selectedEntities: string[] = [];
public checkboxes: CheckEntity[] = []; public checkboxes: CheckEntity[] = [];
public entities: Entity[] = []; public entities: Entity[] = [];
public myForm: FormGroup; public myForm: FormGroup;
private searchText: RegExp = new RegExp(''); private searchText: RegExp = new RegExp('');
public keyword = ''; public keyword = '';
public communities: Portal[] = []; public communities: Portal[] = [];
public selectedCommunityPid: string; public selectedCommunityPid: string;
@ViewChild('AlertModalRelatedPages') alertModalRelatedPages; @ViewChild('AlertModalRelatedPages') alertModalRelatedPages;
public toggleIds: string[]; public toggleIds: string[];
public toggleStatus: boolean; public toggleStatus: boolean;
public properties: EnvProperties = null; public properties: EnvProperties = properties;
public showLoading = true; public showLoading = true;
public errorMessage = ''; public errorMessage = '';
public updateErrorMessage = ''; public updateErrorMessage = '';
@ -48,18 +49,19 @@ export class EntitiesComponent implements OnInit {
public isPortalAdministrator = null; public isPortalAdministrator = null;
public filterForm: FormGroup; public filterForm: FormGroup;
private subscriptions: any[] = []; private subscriptions: any[] = [];
constructor(private element: ElementRef, private route: ActivatedRoute, constructor(private element: ElementRef, private route: ActivatedRoute,
private _router: Router, private _router: Router,
private _helpContentService: HelpContentService, private _helpContentService: HelpContentService,
private userManagementService: UserManagementService, private _fb: FormBuilder) { private userManagementService: UserManagementService, private _fb: FormBuilder) {
} }
ngOnInit() { ngOnInit() {
this.filterForm = this._fb.group({ this.filterForm = this._fb.group({
keyword: [''], keyword: [''],
status: ['all', Validators.required]}); status: ['all', Validators.required]
});
this.myForm = this._fb.group({ this.myForm = this._fb.group({
pid: ['', Validators.required], pid: ['', Validators.required],
name: ['', Validators.required], name: ['', Validators.required],
@ -72,19 +74,16 @@ export class EntitiesComponent implements OnInit {
this.subscriptions.push(this.filterForm.get('status').valueChanges.subscribe(value => { this.subscriptions.push(this.filterForm.get('status').valueChanges.subscribe(value => {
this.applyStatusFilter(); this.applyStatusFilter();
})); }));
this.userManagementService.getUserInfo().subscribe(user => {
this.properties = properties; this.selectedCommunityPid = (this.route.snapshot.data.portal) ? this.route.snapshot.data.portal : this.route.snapshot.params[this.route.snapshot.data.param];
this.subscriptions.push(this.route.queryParams.subscribe(params => { ConnectHelper.setPortalTypeFromPid(this.selectedCommunityPid );
HelperFunctions.scroll(); this.applyCommunityFilter(this.selectedCommunityPid);
this.userManagementService.getUserInfo().subscribe(user => { this.isPortalAdministrator = Session.isPortalAdministrator(user) && !this.selectedCommunityPid;
this.selectedCommunityPid = params['communityId']; });
this.applyCommunityFilter(this.selectedCommunityPid);
this.isPortalAdministrator = Session.isPortalAdministrator(user) && !this.selectedCommunityPid;
});
}));
} }
ngOnDestroy(): void { ngOnDestroy(): void {
this.subscriptions.forEach(value => { this.subscriptions.forEach(value => {
if (value instanceof Subscriber) { if (value instanceof Subscriber) {
@ -94,6 +93,7 @@ export class EntitiesComponent implements OnInit {
} }
}); });
} }
getEntities(community_pid: string) { getEntities(community_pid: string) {
if (!Session.isLoggedIn()) { if (!Session.isLoggedIn()) {
this._router.navigate(['/user-info'], this._router.navigate(['/user-info'],
@ -107,12 +107,12 @@ export class EntitiesComponent implements OnInit {
entities => { entities => {
this.entities = entities; this.entities = entities;
this.checkboxes = []; this.checkboxes = [];
let self = this; let self = this;
entities.forEach(_ => { entities.forEach(_ => {
self.checkboxes.push(<CheckEntity>{entity: _, checked: false}); self.checkboxes.push(<CheckEntity>{entity: _, checked: false});
}); });
this.showLoading = false; this.showLoading = false;
}, },
error => this.handleError('System error retrieving entities', error)); error => this.handleError('System error retrieving entities', error));
@ -121,7 +121,7 @@ export class EntitiesComponent implements OnInit {
entities => { entities => {
this.entities = entities; this.entities = entities;
this.checkboxes = []; this.checkboxes = [];
let self = this; let self = this;
entities.forEach(_ => { entities.forEach(_ => {
self.checkboxes.push(<CheckEntity>{entity: _, checked: false}); self.checkboxes.push(<CheckEntity>{entity: _, checked: false});
@ -132,40 +132,40 @@ export class EntitiesComponent implements OnInit {
} }
} }
} }
public toggleCheckBoxes(event) { public toggleCheckBoxes(event) {
this.checkboxes.forEach(_ => _.checked = event.target.checked); this.checkboxes.forEach(_ => _.checked = event.target.checked);
} }
public applyCheck(flag: boolean) { public applyCheck(flag: boolean) {
this.checkboxes.forEach(_ => _.checked = flag); this.checkboxes.forEach(_ => _.checked = flag);
} }
public getSelectedEntities(): string[] { public getSelectedEntities(): string[] {
return this.checkboxes.filter(entity => entity.checked === true).map(checkedEntity => checkedEntity.entity).map(res => res._id); return this.checkboxes.filter(entity => entity.checked === true).map(checkedEntity => checkedEntity.entity).map(res => res._id);
} }
private deleteEntitiesFromArray(ids: string[]): void { private deleteEntitiesFromArray(ids: string[]): void {
for (let id of ids) { for (let id of ids) {
const i = this.checkboxes.findIndex(_ => _.entity._id === id); const i = this.checkboxes.findIndex(_ => _.entity._id === id);
this.checkboxes.splice(i, 1); this.checkboxes.splice(i, 1);
} }
} }
public confirmDeleteEntity(id: string) { public confirmDeleteEntity(id: string) {
// this.deleteConfirmationModal.ids = [id]; // this.deleteConfirmationModal.ids = [id];
// this.deleteConfirmationModal.showModal(); // this.deleteConfirmationModal.showModal();
this.selectedEntities = [id]; this.selectedEntities = [id];
this.confirmDeleteEntitiesModalOpen(); this.confirmDeleteEntitiesModalOpen();
} }
public confirmDeleteSelectedEntities() { public confirmDeleteSelectedEntities() {
// this.deleteConfirmationModal.ids = this.getSelectedEntities(); // this.deleteConfirmationModal.ids = this.getSelectedEntities();
// this.deleteConfirmationModal.showModal(); // this.deleteConfirmationModal.showModal();
this.selectedEntities = this.getSelectedEntities(); this.selectedEntities = this.getSelectedEntities();
this.confirmDeleteEntitiesModalOpen(); this.confirmDeleteEntitiesModalOpen();
} }
private confirmDeleteEntitiesModalOpen() { private confirmDeleteEntitiesModalOpen() {
if (!Session.isLoggedIn()) { if (!Session.isLoggedIn()) {
this._router.navigate(['/user-info'], this._router.navigate(['/user-info'],
@ -179,7 +179,7 @@ export class EntitiesComponent implements OnInit {
this.alertModalDeleteEntities.open(); this.alertModalDeleteEntities.open();
} }
} }
public confirmedDeleteEntities(data: any) { public confirmedDeleteEntities(data: any) {
if (!Session.isLoggedIn()) { if (!Session.isLoggedIn()) {
this._router.navigate(['/user-info'], this._router.navigate(['/user-info'],
@ -187,7 +187,7 @@ export class EntitiesComponent implements OnInit {
} else { } else {
this.showLoading = true; this.showLoading = true;
this.updateErrorMessage = ''; this.updateErrorMessage = '';
this._helpContentService.deleteEntities(this.selectedEntities, this.properties.adminToolsAPIURL).subscribe( this._helpContentService.deleteEntities(this.selectedEntities, this.properties.adminToolsAPIURL).subscribe(
_ => { _ => {
this.deleteEntitiesFromArray(this.selectedEntities); this.deleteEntitiesFromArray(this.selectedEntities);
@ -197,7 +197,7 @@ export class EntitiesComponent implements OnInit {
); );
} }
} }
public editEntity(i: number) { public editEntity(i: number) {
const entity: Entity = this.checkboxes[i].entity; const entity: Entity = this.checkboxes[i].entity;
this.myForm = this._fb.group({ this.myForm = this._fb.group({
@ -208,7 +208,7 @@ export class EntitiesComponent implements OnInit {
this.modalErrorMessage = ''; this.modalErrorMessage = '';
this.entitiesModalOpen(this.alertModalSaveEntity, '', 'Save Changes'); this.entitiesModalOpen(this.alertModalSaveEntity, '', 'Save Changes');
} }
public newEntity() { public newEntity() {
this.myForm = this._fb.group({ this.myForm = this._fb.group({
pid: ['', Validators.required], pid: ['', Validators.required],
@ -219,7 +219,7 @@ export class EntitiesComponent implements OnInit {
this.modalErrorMessage = ''; this.modalErrorMessage = '';
this.entitiesModalOpen(this.alertModalSaveEntity, '', 'Save'); this.entitiesModalOpen(this.alertModalSaveEntity, '', 'Save');
} }
private entitiesModalOpen(modal: any, title: string, yesBtn: string) { private entitiesModalOpen(modal: any, title: string, yesBtn: string) {
if (!Session.isLoggedIn()) { if (!Session.isLoggedIn()) {
this._router.navigate(['/user-info'], this._router.navigate(['/user-info'],
@ -232,7 +232,7 @@ export class EntitiesComponent implements OnInit {
modal.open(); modal.open();
} }
} }
public entitySaveConfirmed(data: any) { public entitySaveConfirmed(data: any) {
if (!Session.isLoggedIn()) { if (!Session.isLoggedIn()) {
this._router.navigate(['/user-info'], this._router.navigate(['/user-info'],
@ -257,54 +257,54 @@ export class EntitiesComponent implements OnInit {
} }
} }
} }
public entitySavedSuccessfully(entity: Entity) { public entitySavedSuccessfully(entity: Entity) {
this.checkboxes.push(<CheckEntity>{entity: entity, checked: false}); this.checkboxes.push(<CheckEntity>{entity: entity, checked: false});
this.applyCheck(false); this.applyCheck(false);
} }
public entityUpdatedSuccessfully(entity: Entity) { public entityUpdatedSuccessfully(entity: Entity) {
this.checkboxes.find(checkItem => checkItem.entity._id === entity._id).entity = entity; this.checkboxes.find(checkItem => checkItem.entity._id === entity._id).entity = entity;
this.applyCheck(false); this.applyCheck(false);
} }
public filterBySearch(text: string) { public filterBySearch(text: string) {
this.searchText = new RegExp(text, 'i'); this.searchText = new RegExp(text, 'i');
this.applyFilter(); this.applyFilter();
} }
public applyFilter() { public applyFilter() {
this.checkboxes = []; this.checkboxes = [];
this.entities.filter(item => this.filterEntities(item)).forEach( this.entities.filter(item => this.filterEntities(item)).forEach(
_ => this.checkboxes.push(<CheckEntity>{entity: _, checked: false}) _ => this.checkboxes.push(<CheckEntity>{entity: _, checked: false})
); );
} }
public filterEntities(entity: Entity): boolean { public filterEntities(entity: Entity): boolean {
const textFlag = this.searchText.toString() === '' || (entity.name).match(this.searchText) != null; const textFlag = this.searchText.toString() === '' || (entity.name).match(this.searchText) != null;
return textFlag; return textFlag;
} }
public applyStatusFilter() { public applyStatusFilter() {
this.checkboxes = []; this.checkboxes = [];
this.entities.filter(item => this.filterEntitiesByStatus(item)).forEach( this.entities.filter(item => this.filterEntitiesByStatus(item)).forEach(
_ => this.checkboxes.push(<CheckEntity>{entity: _, checked: false}) _ => this.checkboxes.push(<CheckEntity>{entity: _, checked: false})
); );
} }
public filterEntitiesByStatus(entity: Entity): boolean { public filterEntitiesByStatus(entity: Entity): boolean {
let status = this.filterForm.get("status").value; let status = this.filterForm.get("status").value;
return status == "all" || (status == "disabled" && !entity.isEnabled) || (status == "enabled" && entity.isEnabled); return status == "all" || (status == "disabled" && !entity.isEnabled) || (status == "enabled" && entity.isEnabled);
} }
handleError(message: string, error) { handleError(message: string, error) {
this.errorMessage = message; this.errorMessage = message;
console.log('Server responded: ' + error); console.log('Server responded: ' + error);
this.showLoading = false; this.showLoading = false;
} }
handleUpdateError(message: string, error) { handleUpdateError(message: string, error) {
if (error == null) { if (error == null) {
this.myForm = this._fb.group({ this.myForm = this._fb.group({
@ -317,21 +317,21 @@ export class EntitiesComponent implements OnInit {
this.updateErrorMessage = message; this.updateErrorMessage = message;
console.log('Server responded: ' + error); console.log('Server responded: ' + error);
} }
this.showLoading = false; this.showLoading = false;
} }
public applyCommunityFilter(community_pid: string) { public applyCommunityFilter(community_pid: string) {
this.getEntities(community_pid); this.getEntities(community_pid);
} }
public toggleEntities(status: boolean, ids: string[]) { public toggleEntities(status: boolean, ids: string[]) {
// this.okModal.showModal(); // this.okModal.showModal();
this.toggleIds = ids; this.toggleIds = ids;
this.toggleStatus = status; this.toggleStatus = status;
this.confirmRelatedPagesModalOpen(); this.confirmRelatedPagesModalOpen();
} }
private confirmRelatedPagesModalOpen() { private confirmRelatedPagesModalOpen() {
if (!Session.isLoggedIn()) { if (!Session.isLoggedIn()) {
this._router.navigate(['/user-info'], this._router.navigate(['/user-info'],
@ -345,7 +345,7 @@ export class EntitiesComponent implements OnInit {
this.alertModalRelatedPages.open(); this.alertModalRelatedPages.open();
} }
} }
public continueToggling(event: any) { public continueToggling(event: any) {
if (!Session.isLoggedIn()) { if (!Session.isLoggedIn()) {
this._router.navigate(['/user-info'], this._router.navigate(['/user-info'],

View File

@ -15,6 +15,7 @@ import {map, startWith} from "rxjs/operators";
import {MatAutocompleteSelectedEvent} from "@angular/material"; import {MatAutocompleteSelectedEvent} from "@angular/material";
import {PortalUtils} from "../portal/portalHelper"; import {PortalUtils} from "../portal/portalHelper";
import {properties} from "../../../../environments/environment"; import {properties} from "../../../../environments/environment";
import {ConnectHelper} from "../../connect/connectHelper";
@Component({ @Component({
selector: 'pages', selector: 'pages',
@ -100,20 +101,18 @@ export class PagesComponent implements OnInit {
this.properties = properties; this.properties = properties;
this.subscriptions.push(this.route.queryParams.subscribe(params => { this.subscriptions.push(this.route.queryParams.subscribe(params => {
HelperFunctions.scroll();
this.pagesType = ''; this.pagesType = '';
if (params['type']) { if (params['type']) {
// this.pagesType = params['type']; // this.pagesType = params['type'];
this.filterForm.get('type').setValue(params['type']); this.filterForm.get('type').setValue(params['type']);
} }
this.selectedCommunityPid = params['communityId']; this.selectedCommunityPid = (this.route.snapshot.data.portal)?this.route.snapshot.data.portal:this.route.snapshot.params[this.route.snapshot.data.param];
ConnectHelper.setPortalTypeFromPid(this.selectedCommunityPid);
this.keyword = ''; this.keyword = '';
this.subscriptions.push(this.userManagementService.getUserInfo().subscribe(user => { this.subscriptions.push(this.userManagementService.getUserInfo().subscribe(user => {
this.applyCommunityFilter(this.selectedCommunityPid); this.applyCommunityFilter(this.selectedCommunityPid);
this.isPortalAdministrator = Session.isPortalAdministrator(user) && !this.selectedCommunityPid; this.isPortalAdministrator = Session.isPortalAdministrator(user) && !this.selectedCommunityPid;
})); }));
//this.getCommunities();
})); }));
this.subscriptions.push(this._helpContentService.getEntities(this.properties.adminToolsAPIURL).subscribe( this.subscriptions.push(this._helpContentService.getEntities(this.properties.adminToolsAPIURL).subscribe(

View File

@ -20,15 +20,15 @@
<button class="uk-button uk-button-secondary">Bulk Actions</button> <button class="uk-button uk-button-secondary">Bulk Actions</button>
<div uk-dropdown="mode: click"> <div uk-dropdown="mode: click">
<ul class="uk-nav uk-dropdown-nav" <ul class="uk-nav uk-dropdown-nav"
[attr.uk-tooltip]="getSelectedCommunities().length == 0 ? 'pos:left; cls: uk-active' : 'cls: uk-invisible'" [attr.uk-tooltip]="getSelectedPortals().length == 0 ? 'pos:left; cls: uk-active' : 'cls: uk-invisible'"
title="Select at least one portal"> title="Select at least one portal">
<li><a [class]="getSelectedCommunities().length == 0 ? 'uk-disabled' : ''" <li><a [class]="getSelectedPortals().length == 0 ? 'uk-disabled' : ''"
(click)="confirmDeleteSelectedCommunities()"><i></i> Delete </a></li> (click)="confirmDeleteSelectedPortals()"><i></i> Delete </a></li>
</ul> </ul>
</div> </div>
</div> </div>
<div> <div>
<a (click)="newCommunity()" <a (click)="newPortal()"
class="uk-flex uk-flex-middle uk-text-uppercase"> class="uk-flex uk-flex-middle uk-text-uppercase">
<button class="large uk-icon-button uk-button-secondary"> <button class="large uk-icon-button uk-button-secondary">
<icon name="add"></icon> <icon name="add"></icon>
@ -66,20 +66,20 @@
</thead> </thead>
<tbody> <tbody>
<tr *ngFor="let check of checkboxes; let i=index"> <tr *ngFor="let check of checkboxes; let i=index">
<td><input id="{{check.community._id}}" class="checkBox" type="checkbox" <td><input id="{{check.portal._id}}" class="checkBox" type="checkbox"
name="communitiescb[]" value="{{check.community._id}}" [(ngModel)]="check.checked"> name="communitiescb[]" value="{{check.portal._id}}" [(ngModel)]="check.checked">
</td> </td>
<td> <td>
<div class="name" href="#">{{check.community.name}}</div> <div class="name" href="#">{{check.portal.name}}</div>
</td> </td>
<td> <td>
<div class="type" href="#">{{check.community.type}}</div> <div class="type" href="#">{{check.portal.type}}</div>
</td> </td>
<td> <td>
<div class="actions" href="#"> <div class="actions" href="#">
<i class="clickable" uk-icon="pencil" (click)="editCommunity(i)"></i> <i class="clickable" uk-icon="pencil" (click)="editPortal(i)"></i>
<i class="clickable uk-text-danger" uk-icon="trash" <i class="clickable uk-text-danger" uk-icon="trash"
(click)="confirmDeleteCommunity(check.community._id)"></i> (click)="confirmDeletePortal(check.portal._id)"></i>
</div> </div>
</td> </td>
@ -101,26 +101,18 @@
</div> </div>
</div> </div>
<modal-alert #AlertModalSaveCommunity (alertOutput)="communitySaveConfirmed($event)" <modal-alert #portalModal (alertOutput)="portalSaveConfirmed($event)"
[okDisabled]="portalFG && (portalFG.invalid || !portalFG.dirty)"> [okDisabled]="portalFG && (portalFG.invalid || !portalFG.dirty)">
<div *ngIf="modalErrorMessage" class="uk-alert-danger" uk-alert aria-hidden="true">{{ modalErrorMessage }}</div> <div *ngIf="modalErrorMessage" class="uk-alert-danger" uk-alert aria-hidden="true">{{ modalErrorMessage }}</div>
<form [formGroup]="portalFG"> <form [formGroup]="portalFG" class="uk-grid uk-child-width-1-1" uk-grid>
<div dashboard-input class="uk-margin-small-left" [formInput]="portalFG.controls.name" <div dashboard-input [formInput]="portalFG.get('name')" type="text" label="Portal Name" placeholder="Write a name">
type="text"
label="Portal Name">
</div> </div>
<div [ngClass]="{'has-error':!portalFG.controls.type.valid && portalFG.controls.type.dirty}"> <div dashboard-input type="select" label="Portal Type" placeholder="Choose a type" [formInput]="portalFG.get('type')" [options]="portalUtils.portalTypes"></div>
<label for="portalTypeTag">*Portal Type</label> <div dashboard-input [formInput]="portalFG.get('pid')"
<select formControlName="type" id="portalTypeTag" class="form-control uk-select">
<option *ngFor="let option of portalUtils.portalTypes" [value]="option.value">{{option.label}}</option>
</select>
</div>
<div dashboard-input class="uk-margin-small-left " [formInput]="portalFG.controls.pid"
type="text" type="text"
label="Portal persistent id for portal"> label="Portal persistent id for portal">
</div> </div>
<div dashboard-input class="uk-margin-small-left" [formInput]="portalFG.controls.piwik" <div dashboard-input [formInput]="portalFG.get('piwik')"
type="text" type="text"
label="Piwik id"> label="Piwik id">
</div> </div>
@ -128,4 +120,4 @@
</form> </form>
</modal-alert> </modal-alert>
<modal-alert #AlertModalDeleteCommunities (alertOutput)="confirmedDeleteCommunities($event)"></modal-alert> <modal-alert #deleteModal (alertOutput)="confirmedDeletePortals($event)"></modal-alert>

View File

@ -12,6 +12,7 @@ import {CheckPortal, Portal} from "../../utils/entities/adminTool/portal";
import {PortalUtils} from "./portalHelper"; import {PortalUtils} from "./portalHelper";
import {properties} from "../../../../environments/environment"; import {properties} from "../../../../environments/environment";
import {CheckPage, Page} from "../../utils/entities/adminTool/page"; import {CheckPage, Page} from "../../utils/entities/adminTool/page";
import {AlertModal} from "../../utils/modal/alert";
@Component({ @Component({
selector: 'portals', selector: 'portals',
@ -19,57 +20,59 @@ import {CheckPage, Page} from "../../utils/entities/adminTool/page";
}) })
export class PortalsComponent implements OnInit { export class PortalsComponent implements OnInit {
@ViewChild('AlertModalSaveCommunity') alertModalSaveCommunity; @ViewChild('portalModal') portalModal: AlertModal;
@ViewChild('AlertModalDeleteCommunities') alertModalDeleteCommunities; @ViewChild('deleteModal') deleteModal: AlertModal;
private selectedCommunities: string[] = []; private selectedPortals: string[] = [];
public checkboxes: CheckPortal[] = []; public checkboxes: CheckPortal[] = [];
public communities: Portal[] = []; public portals: Portal[] = [];
public portalFG: FormGroup; public portalFG: FormGroup;
public filterForm: FormGroup; public filterForm: FormGroup;
private subscriptions: any[] = []; private subscriptions: any[] = [];
private searchText: RegExp = new RegExp(''); private searchText: RegExp = new RegExp('');
public keyword = ''; public keyword = '';
public properties: EnvProperties = null; public properties: EnvProperties = null;
public showLoading = true; public showLoading = true;
public errorMessage = ''; public errorMessage = '';
public updateErrorMessage = ''; public updateErrorMessage = '';
public modalErrorMessage = ''; public modalErrorMessage = '';
public portalUtils:PortalUtils = new PortalUtils(); public portalUtils: PortalUtils = new PortalUtils();
ngOnInit() { ngOnInit() {
this.portalFG = this._fb.group({ this.portalFG = this._fb.group({
name: '', name: this._fb.control('', Validators.required),
_id: '', _id: this._fb.control(''),
pid: '', pid: this._fb.control('', Validators.required),
piwik:'', piwik: this._fb.control(''),
type: '' type: this._fb.control('', Validators.required),
}); });
this.filterForm = this._fb.group({ this.filterForm = this._fb.group({
keyword: [''], keyword: [''],
type: ['all', Validators.required]}); type: ['all', Validators.required]
});
this.subscriptions.push(this.filterForm.get('keyword').valueChanges.subscribe(value => { this.subscriptions.push(this.filterForm.get('keyword').valueChanges.subscribe(value => {
this.filterBySearch(value); this.filterBySearch(value);
})); }));
this.subscriptions.push(this.filterForm.get('type').valueChanges.subscribe(value => { this.subscriptions.push(this.filterForm.get('type').valueChanges.subscribe(value => {
this.applyTypeFilter(); this.applyTypeFilter();
})); }));
HelperFunctions.scroll(); HelperFunctions.scroll();
this.properties = properties; this.properties = properties;
this.getCommunities(); this.getPortals();
} }
constructor(private element: ElementRef, private route: ActivatedRoute, constructor(private element: ElementRef, private route: ActivatedRoute,
private _router: Router, private _helpContentService: HelpContentService, private _fb: FormBuilder) { private _router: Router, private _helpContentService: HelpContentService, private _fb: FormBuilder) {
} }
ngOnDestroy(): void { ngOnDestroy(): void {
this.subscriptions.forEach(value => { this.subscriptions.forEach(value => {
if (value instanceof Subscriber) { if (value instanceof Subscriber) {
@ -79,8 +82,8 @@ export class PortalsComponent implements OnInit {
} }
}); });
} }
getCommunities() { getPortals() {
if (!Session.isLoggedIn()) { if (!Session.isLoggedIn()) {
this._router.navigate(['/user-info'], { this._router.navigate(['/user-info'], {
queryParams: {'errorCode': LoginErrorCodes.NOT_VALID, 'redirectUrl': this._router.url} queryParams: {'errorCode': LoginErrorCodes.NOT_VALID, 'redirectUrl': this._router.url}
@ -89,14 +92,14 @@ export class PortalsComponent implements OnInit {
this.showLoading = true; this.showLoading = true;
this.updateErrorMessage = ''; this.updateErrorMessage = '';
this.errorMessage = ''; this.errorMessage = '';
this.subscriptions.push(this._helpContentService.getPortalsFull(this.properties.adminToolsAPIURL).subscribe( this.subscriptions.push(this._helpContentService.getPortalsFull(this.properties.adminToolsAPIURL).subscribe(
communities => { portals => {
this.communities = communities; this.portals = portals;
if(communities) { if (portals) {
communities.forEach(_ => { portals.forEach(_ => {
this.checkboxes.push(<CheckPortal>{community: _, checked: false}); this.checkboxes.push(<CheckPortal>{portal: _, checked: false});
}); });
} }
this.showLoading = false; this.showLoading = false;
@ -104,54 +107,48 @@ export class PortalsComponent implements OnInit {
error => this.handleError('System error retrieving portals', error))); error => this.handleError('System error retrieving portals', error)));
} }
} }
public toggleCheckBoxes(event) { public toggleCheckBoxes(event) {
this.checkboxes.forEach(_ => _.checked = event.target.checked); this.checkboxes.forEach(_ => _.checked = event.target.checked);
} }
public applyCheck(flag: boolean) { public applyCheck(flag: boolean) {
this.checkboxes.forEach(_ => _.checked = flag); this.checkboxes.forEach(_ => _.checked = flag);
} }
public getSelectedCommunities(): string[] { public getSelectedPortals(): string[] {
return this.checkboxes.filter(community => community.checked === true).map(checkedCommunity => checkedCommunity.community).map(res => res._id); return this.checkboxes.filter(portal => portal.checked === true).map(checkedPortal => checkedPortal.portal).map(res => res._id);
} }
private deleteCommunitiesFromArray(ids: string[]): void { private deletePortalsFromArray(ids: string[]): void {
for (let id of ids) { for (let id of ids) {
let i = this.checkboxes.findIndex(_ => _.community._id === id); let i = this.checkboxes.findIndex(_ => _.portal._id === id);
this.checkboxes.splice(i, 1); this.checkboxes.splice(i, 1);
} }
} }
public confirmDeleteCommunity(id: string) { public confirmDeletePortal(id: string) {
// this.deleteConfirmationModal.ids = [id]; // this.deleteConfirmationModal.ids = [id];
// this.deleteConfirmationModal.showModal(); // this.deleteConfirmationModal.showModal();
this.selectedCommunities = [id]; this.selectedPortals = [id];
this.confirmModalOpen(); this.confirmModalOpen();
} }
public confirmDeleteSelectedCommunities() { public confirmDeleteSelectedPortals() {
this.selectedCommunities = this.getSelectedCommunities(); this.selectedPortals = this.getSelectedPortals();
this.confirmModalOpen(); this.confirmModalOpen();
} }
private confirmModalOpen() { private confirmModalOpen() {
if (!Session.isLoggedIn()) { this.deleteModal.cancelButton = true;
this._router.navigate(['/user-info'], { this.deleteModal.okButton = true;
queryParams: {'errorCode': LoginErrorCodes.NOT_VALID, 'redirectUrl': this._router.url} this.deleteModal.alertTitle = 'Delete Confirmation';
}); this.deleteModal.message = 'Are you sure you want to delete the selected portal(-ies)?';
} else { this.deleteModal.okButtonText = 'Yes';
this.alertModalDeleteCommunities.cancelButton = true; this.deleteModal.open();
this.alertModalDeleteCommunities.okButton = true;
this.alertModalDeleteCommunities.alertTitle = 'Delete Confirmation';
this.alertModalDeleteCommunities.message = 'Are you sure you want to delete the selected portal(-ies)?';
this.alertModalDeleteCommunities.okButtonText = 'Yes';
this.alertModalDeleteCommunities.open();
}
} }
public confirmedDeleteCommunities(data: any) { public confirmedDeletePortals(data: any) {
if (!Session.isLoggedIn()) { if (!Session.isLoggedIn()) {
this._router.navigate(['/user-info'], { this._router.navigate(['/user-info'], {
queryParams: {'errorCode': LoginErrorCodes.NOT_VALID, 'redirectUrl': this._router.url} queryParams: {'errorCode': LoginErrorCodes.NOT_VALID, 'redirectUrl': this._router.url}
@ -159,89 +156,76 @@ export class PortalsComponent implements OnInit {
} else { } else {
this.showLoading = true; this.showLoading = true;
this.updateErrorMessage = ''; this.updateErrorMessage = '';
this.subscriptions.push(this._helpContentService.deleteCommunities(this.selectedCommunities, this.properties.adminToolsAPIURL).subscribe( this.subscriptions.push(this._helpContentService.deleteCommunities(this.selectedPortals, this.properties.adminToolsAPIURL).subscribe(
_ => { _ => {
this.deleteCommunitiesFromArray(this.selectedCommunities); this.deletePortalsFromArray(this.selectedPortals);
this.showLoading = false; this.showLoading = false;
}, },
error => this.handleUpdateError('System error deleting the selected communities', error) error => this.handleUpdateError('System error deleting the selected communities', error)
)); ));
} }
} }
public editCommunity(i: number) { public editPortal(i: number) {
const community: Portal = this.checkboxes[i].community; const portal: Portal = this.checkboxes[i].portal;
this.portalFG = this._fb.group({ this.portalFG = this._fb.group({
name: community.name, name: this._fb.control(portal.name, Validators.required),
_id: community._id, _id: this._fb.control(portal._id),
type: community.type, pid: this._fb.control(portal.pid, Validators.required),
piwik:community.piwik, piwik: this._fb.control(portal.piwik),
pid: community.pid type: this._fb.control(portal.type, Validators.required),
}); });
this.portalFG.controls['type'].disable(); this.portalFG.controls['type'].disable();
this.modalErrorMessage = ''; this.modalErrorMessage = '';
this.communitiesModalOpen(this.alertModalSaveCommunity, 'Update', 'Update Community'); this.portalModalOpen('Update Portal', 'Update');
} }
public newCommunity() { public newPortal() {
this.portalFG.controls['type'].enable(); this.portalFG.controls['type'].enable();
this.portalFG = this._fb.group({ this.portalFG = this._fb.group({
name: '', name: this._fb.control('', Validators.required),
_id: '', _id: this._fb.control(''),
type: '', pid: this._fb.control('', Validators.required),
piwik: '', piwik: this._fb.control(''),
pid: '' type: this._fb.control('', Validators.required),
}); });
this.modalErrorMessage = ''; this.modalErrorMessage = '';
this.communitiesModalOpen(this.alertModalSaveCommunity, '', 'Save'); this.portalModalOpen('Create Portal', 'Save');
} }
private communitiesModalOpen(modal: any, title: string, yesBtn: string) { private portalModalOpen(title: string, yesBtn: string) {
if (!Session.isLoggedIn()) { this.portalModal.okButtonLeft = false;
this._router.navigate(['/user-info'], { this.portalModal.cancelButton = true;
queryParams: {'errorCode': LoginErrorCodes.NOT_VALID, 'redirectUrl': this._router.url} this.portalModal.okButton = true;
}); this.portalModal.alertTitle = title;
} else { this.portalModal.okButtonText = yesBtn;
modal.cancelButton = true; this.portalModal.open();
modal.okButton = true;
modal.alertTitle = title;
modal.okButtonText = yesBtn;
modal.open();
}
} }
public communitySaveConfirmed(data: any) { public portalSaveConfirmed(data: any) {
if (!Session.isLoggedIn()) {
this._router.navigate(['/user-info'], {
queryParams: {'errorCode': LoginErrorCodes.NOT_VALID, 'redirectUrl': this._router.url}
});
} else {
this.modalErrorMessage = ''; this.modalErrorMessage = '';
if (this.portalFG.getRawValue()['_id'].length > 0) { if (this.portalFG.getRawValue()['_id'].length > 0) {
this.portalFG.controls['type'].enable(); this.portalFG.controls['type'].enable();
this.subscriptions.push(this._helpContentService.updateCommunity(<Portal>this.portalFG.value, this.subscriptions.push(this._helpContentService.updateCommunity(<Portal>this.portalFG.value,
this.properties.adminToolsAPIURL).subscribe( this.properties.adminToolsAPIURL).subscribe(
community => { portal => {
this.communityUpdatedSuccessfully(community); this.portalUpdatedSuccessfully(portal);
}, },
error => this.handleUpdateError('System error updating portal', error) error => this.handleUpdateError('System error updating portal', error)
)); ));
}else{ } else {
this.subscriptions.push(this._helpContentService.saveCommunity(<Portal>this.portalFG.value, this.subscriptions.push(this._helpContentService.saveCommunity(<Portal>this.portalFG.value,
this.properties.adminToolsAPIURL).subscribe( this.properties.adminToolsAPIURL).subscribe(
community => { portal => {
this.communitySavedSuccessfully(community); this.portalSavedSuccessfully(portal);
}, },
error => this.handleUpdateError('System error creating portal', error) error => this.handleUpdateError('System error creating portal', error)
)); ));
} }
}
} }
public communityUpdateConfirmed(data: any) { public portalUpdateConfirmed(data: any) {
if (!Session.isLoggedIn()) { if (!Session.isLoggedIn()) {
this._router.navigate(['/user-info'], { this._router.navigate(['/user-info'], {
queryParams: {'errorCode': LoginErrorCodes.NOT_VALID, 'redirectUrl': this._router.url} queryParams: {'errorCode': LoginErrorCodes.NOT_VALID, 'redirectUrl': this._router.url}
@ -250,72 +234,74 @@ export class PortalsComponent implements OnInit {
this.portalFG.controls['type'].enable(); this.portalFG.controls['type'].enable();
this.subscriptions.push(this._helpContentService.updateCommunity(<Portal>this.portalFG.value, this.subscriptions.push(this._helpContentService.updateCommunity(<Portal>this.portalFG.value,
this.properties.adminToolsAPIURL).subscribe( this.properties.adminToolsAPIURL).subscribe(
community => { portal => {
this.communityUpdatedSuccessfully(community); this.portalUpdatedSuccessfully(portal);
}, },
error => this.handleUpdateError('System error updating portal', error) error => this.handleUpdateError('System error updating portal', error)
)); ));
} }
} }
public communitySavedSuccessfully(community: Portal) { public portalSavedSuccessfully(portal: Portal) {
this.checkboxes.push(<CheckPortal>{community: community, checked: false}); this.checkboxes.push(<CheckPortal>{portal: portal, checked: false});
this.applyCheck(false); this.applyCheck(false);
} }
public communityUpdatedSuccessfully(community: Portal) { public portalUpdatedSuccessfully(portal: Portal) {
this.checkboxes.find(checkItem => checkItem.community._id === community._id).community = community; this.checkboxes.find(checkItem => checkItem.portal._id === portal._id).portal = portal;
this.applyCheck(false); this.applyCheck(false);
} }
public filterBySearch(text: string) { public filterBySearch(text: string) {
this.searchText = new RegExp(text, 'i'); this.searchText = new RegExp(text, 'i');
this.applyFilter(); this.applyFilter();
} }
public applyFilter() { public applyFilter() {
this.checkboxes = []; this.checkboxes = [];
this.communities.filter(item => this.filterCommunities(item)).forEach( this.portals.filter(item => this.filterPortals(item)).forEach(
_ => this.checkboxes.push(<CheckPortal>{community: _, checked: false}) _ => this.checkboxes.push(<CheckPortal>{portal: _, checked: false})
); );
} }
public applyTypeFilter() { public applyTypeFilter() {
this.checkboxes = []; this.checkboxes = [];
this.communities.filter(item => this.filterByType(item)).forEach( this.portals.filter(item => this.filterByType(item)).forEach(
_ => this.checkboxes.push(<CheckPortal>{community: _, checked: false}) _ => this.checkboxes.push(<CheckPortal>{portal: _, checked: false})
); );
} }
public filterByType(community: Portal): boolean { public filterByType(portal: Portal): boolean {
let type = this.filterForm.get("type").value; let type = this.filterForm.get("type").value;
return type == "all" || (type == community.type); return type == "all" || (type == portal.type);
} }
public filterCommunities(community: Portal): boolean {
const textFlag = this.searchText.toString() === '' || (community.name || community.type).match(this.searchText) != null; public filterPortals(portal: Portal): boolean {
const textFlag = this.searchText.toString() === '' || (portal.name || portal.type).match(this.searchText) != null;
return textFlag; return textFlag;
} }
handleUpdateError(message: string, error) { handleUpdateError(message: string, error) {
if (error == null) { if (error == null) {
this.portalFG = this._fb.group({ this.portalFG = this._fb.group({
name: '', name: '',
_id: '', _id: '',
pid: '', pid: '',
piwik:'', piwik: '',
type: '' type: ''
}); });
} else { } else {
this.updateErrorMessage = message; this.updateErrorMessage = message;
console.log('Server responded: ' + error); console.log('Server responded: ' + error);
} }
this.showLoading = false; this.showLoading = false;
} }
handleError(message: string, error) { handleError(message: string, error) {
this.errorMessage = message; this.errorMessage = message;
console.log('Server responded: ' + error); console.log('Server responded: ' + error);
this.showLoading = false; this.showLoading = false;
} }
} }

View File

@ -9,11 +9,10 @@ import {HelperFunctions} from "../../../utils/HelperFunctions.class";
selector: 'admin-tabs', selector: 'admin-tabs',
template: ` template: `
<ul class="uk-tab customTabs admin uk-flex uk-flex-center uk-flex-left@m"> <ul class="uk-tab customTabs admin uk-flex uk-flex-center uk-flex-left@m">
<li *ngIf="isPortalAdmin && (!portal )" class="uk-disabled" > <span class = "uk-margin-small-right" uk-icon="cog"></span></li> <li *ngIf="isPortalAdmin && !portal" [class.uk-active]="tab === 'portal'"><a routerLink="../portals"><span class="title">Portals</span></a></li>
<li *ngIf="isPortalAdmin && !portal" [class.uk-active]="tab === 'portal'"><a routerLink="../../portals"><span class="title">Portals</span></a></li> <li [class.uk-active]="tab === 'page'"><a routerLink="../pages"><span class="title">Pages</span></a></li>
<li [class.uk-active]="tab === 'page'"><a routerLink="../../pages" [queryParams]="(portal? {communityId:portal}:{})" ><span class="title">Pages</span></a></li> <li [class.uk-active]="tab === 'entity'"><a routerLink="../entities"><span class="title">Entities</span></a></li>
<li [class.uk-active]="tab === 'entity'"><a routerLink="../../entities" [queryParams]="(portal? {communityId:portal}:{})"><span class="title">Entities</span></a></li> <li *ngIf="isPortalAdmin && !portal" [class.uk-active]="tab === 'class'"><a routerLink="../classes"><span class="title">Classes</span></a></li>
<li *ngIf="isPortalAdmin && !portal" [class.uk-active]="tab === 'class'"><a routerLink="../../classes"><span class="title">Class Ids</span></a></li>
</ul> </ul>
` `
}) })
@ -35,12 +34,6 @@ export class AdminTabsComponent implements OnInit {
ngOnInit() { ngOnInit() {
this.subscriptions.push(this.userManagementService.getUserInfo().subscribe(user => { this.subscriptions.push(this.userManagementService.getUserInfo().subscribe(user => {
this.user = user; this.user = user;
}));
this.subscriptions.push(this.route.queryParams.subscribe(params => {
HelperFunctions.scroll();
this.portal = params['communityId'];
})); }));
} }
ngOnDestroy(): void { ngOnDestroy(): void {

View File

@ -40,7 +40,7 @@ export interface Option {
</textarea> </textarea>
</ng-template> </ng-template>
<ng-template [ngIf]="type === 'select'"> <ng-template [ngIf]="type === 'select'">
<div class="input-box" [attr.uk-tooltip]="formControl.disabled?'title: This field is not editable; pos: bottom-left':''" [class.clickable]="formControl.enabled" [class.uk-form-danger]="formControl.invalid && formControl.touched" (click)="openSelect()"> <div class="input-box" [attr.uk-tooltip]="formControl.disabled?'title: This field is not editable; pos: bottom-left':null" [class.clickable]="formControl.enabled" [class.uk-form-danger]="formControl.invalid && formControl.touched" (click)="openSelect()">
<mat-form-field class="uk-width-1-1"> <mat-form-field class="uk-width-1-1">
<mat-select #select *ngIf="type === 'select'" [required]="required" [value]="null" <mat-select #select *ngIf="type === 'select'" [required]="required" [value]="null"
(openedChange)="stopPropagation()" [formControl]="formControl" [disableOptionCentering]="true"> (openedChange)="stopPropagation()" [formControl]="formControl" [disableOptionCentering]="true">

View File

@ -195,7 +195,7 @@ export class Portal {
} }
export interface CheckPortal { export interface CheckPortal {
community: Portal; portal: Portal;
checked: boolean; checked: boolean;
} }