[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:
parent
1b1e0170e1
commit
8ca5f8e411
|
@ -30,8 +30,10 @@ export class ConnectRIGuard implements CanActivate, CanLoad {
|
|||
}
|
||||
}));
|
||||
}
|
||||
|
||||
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 {
|
||||
|
|
|
@ -11,6 +11,7 @@ import {HelperFunctions} from "../../utils/HelperFunctions.class";
|
|||
import {UserManagementService} from '../../services/user-management.service';
|
||||
import {Subscriber} from "rxjs";
|
||||
import {properties} from "../../../../environments/environment";
|
||||
import {ConnectHelper} from "../../connect/connectHelper";
|
||||
|
||||
@Component({
|
||||
selector: 'entities',
|
||||
|
@ -18,29 +19,29 @@ import {properties} from "../../../../environments/environment";
|
|||
})
|
||||
|
||||
export class EntitiesComponent implements OnInit {
|
||||
|
||||
|
||||
@ViewChild('AlertModalSaveEntity') alertModalSaveEntity;
|
||||
@ViewChild('AlertModalDeleteEntities') alertModalDeleteEntities;
|
||||
private selectedEntities: string[] = [];
|
||||
|
||||
|
||||
public checkboxes: CheckEntity[] = [];
|
||||
|
||||
|
||||
public entities: Entity[] = [];
|
||||
|
||||
|
||||
public myForm: FormGroup;
|
||||
|
||||
|
||||
private searchText: RegExp = new RegExp('');
|
||||
public keyword = '';
|
||||
|
||||
|
||||
public communities: Portal[] = [];
|
||||
public selectedCommunityPid: string;
|
||||
|
||||
|
||||
@ViewChild('AlertModalRelatedPages') alertModalRelatedPages;
|
||||
|
||||
|
||||
public toggleIds: string[];
|
||||
public toggleStatus: boolean;
|
||||
public properties: EnvProperties = null;
|
||||
|
||||
public properties: EnvProperties = properties;
|
||||
|
||||
public showLoading = true;
|
||||
public errorMessage = '';
|
||||
public updateErrorMessage = '';
|
||||
|
@ -48,18 +49,19 @@ export class EntitiesComponent implements OnInit {
|
|||
public isPortalAdministrator = null;
|
||||
public filterForm: FormGroup;
|
||||
private subscriptions: any[] = [];
|
||||
|
||||
|
||||
constructor(private element: ElementRef, private route: ActivatedRoute,
|
||||
private _router: Router,
|
||||
private _helpContentService: HelpContentService,
|
||||
private userManagementService: UserManagementService, private _fb: FormBuilder) {
|
||||
}
|
||||
|
||||
|
||||
ngOnInit() {
|
||||
this.filterForm = this._fb.group({
|
||||
keyword: [''],
|
||||
status: ['all', Validators.required]});
|
||||
|
||||
status: ['all', Validators.required]
|
||||
});
|
||||
|
||||
this.myForm = this._fb.group({
|
||||
pid: ['', 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.applyStatusFilter();
|
||||
}));
|
||||
|
||||
this.properties = properties;
|
||||
this.subscriptions.push(this.route.queryParams.subscribe(params => {
|
||||
HelperFunctions.scroll();
|
||||
this.userManagementService.getUserInfo().subscribe(user => {
|
||||
this.selectedCommunityPid = params['communityId'];
|
||||
this.applyCommunityFilter(this.selectedCommunityPid);
|
||||
this.isPortalAdministrator = Session.isPortalAdministrator(user) && !this.selectedCommunityPid;
|
||||
});
|
||||
}));
|
||||
|
||||
|
||||
this.userManagementService.getUserInfo().subscribe(user => {
|
||||
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.applyCommunityFilter(this.selectedCommunityPid);
|
||||
this.isPortalAdministrator = Session.isPortalAdministrator(user) && !this.selectedCommunityPid;
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
|
||||
ngOnDestroy(): void {
|
||||
this.subscriptions.forEach(value => {
|
||||
if (value instanceof Subscriber) {
|
||||
|
@ -94,6 +93,7 @@ export class EntitiesComponent implements OnInit {
|
|||
}
|
||||
});
|
||||
}
|
||||
|
||||
getEntities(community_pid: string) {
|
||||
if (!Session.isLoggedIn()) {
|
||||
this._router.navigate(['/user-info'],
|
||||
|
@ -107,12 +107,12 @@ export class EntitiesComponent implements OnInit {
|
|||
entities => {
|
||||
this.entities = entities;
|
||||
this.checkboxes = [];
|
||||
|
||||
|
||||
let self = this;
|
||||
entities.forEach(_ => {
|
||||
self.checkboxes.push(<CheckEntity>{entity: _, checked: false});
|
||||
});
|
||||
|
||||
|
||||
this.showLoading = false;
|
||||
},
|
||||
error => this.handleError('System error retrieving entities', error));
|
||||
|
@ -121,7 +121,7 @@ export class EntitiesComponent implements OnInit {
|
|||
entities => {
|
||||
this.entities = entities;
|
||||
this.checkboxes = [];
|
||||
|
||||
|
||||
let self = this;
|
||||
entities.forEach(_ => {
|
||||
self.checkboxes.push(<CheckEntity>{entity: _, checked: false});
|
||||
|
@ -132,40 +132,40 @@ export class EntitiesComponent implements OnInit {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public toggleCheckBoxes(event) {
|
||||
this.checkboxes.forEach(_ => _.checked = event.target.checked);
|
||||
}
|
||||
|
||||
|
||||
public applyCheck(flag: boolean) {
|
||||
this.checkboxes.forEach(_ => _.checked = flag);
|
||||
}
|
||||
|
||||
|
||||
public getSelectedEntities(): string[] {
|
||||
return this.checkboxes.filter(entity => entity.checked === true).map(checkedEntity => checkedEntity.entity).map(res => res._id);
|
||||
}
|
||||
|
||||
|
||||
private deleteEntitiesFromArray(ids: string[]): void {
|
||||
for (let id of ids) {
|
||||
const i = this.checkboxes.findIndex(_ => _.entity._id === id);
|
||||
this.checkboxes.splice(i, 1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public confirmDeleteEntity(id: string) {
|
||||
// this.deleteConfirmationModal.ids = [id];
|
||||
// this.deleteConfirmationModal.showModal();
|
||||
this.selectedEntities = [id];
|
||||
this.confirmDeleteEntitiesModalOpen();
|
||||
}
|
||||
|
||||
|
||||
public confirmDeleteSelectedEntities() {
|
||||
// this.deleteConfirmationModal.ids = this.getSelectedEntities();
|
||||
// this.deleteConfirmationModal.showModal();
|
||||
this.selectedEntities = this.getSelectedEntities();
|
||||
this.confirmDeleteEntitiesModalOpen();
|
||||
}
|
||||
|
||||
|
||||
private confirmDeleteEntitiesModalOpen() {
|
||||
if (!Session.isLoggedIn()) {
|
||||
this._router.navigate(['/user-info'],
|
||||
|
@ -179,7 +179,7 @@ export class EntitiesComponent implements OnInit {
|
|||
this.alertModalDeleteEntities.open();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public confirmedDeleteEntities(data: any) {
|
||||
if (!Session.isLoggedIn()) {
|
||||
this._router.navigate(['/user-info'],
|
||||
|
@ -187,7 +187,7 @@ export class EntitiesComponent implements OnInit {
|
|||
} else {
|
||||
this.showLoading = true;
|
||||
this.updateErrorMessage = '';
|
||||
|
||||
|
||||
this._helpContentService.deleteEntities(this.selectedEntities, this.properties.adminToolsAPIURL).subscribe(
|
||||
_ => {
|
||||
this.deleteEntitiesFromArray(this.selectedEntities);
|
||||
|
@ -197,7 +197,7 @@ export class EntitiesComponent implements OnInit {
|
|||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public editEntity(i: number) {
|
||||
const entity: Entity = this.checkboxes[i].entity;
|
||||
this.myForm = this._fb.group({
|
||||
|
@ -208,7 +208,7 @@ export class EntitiesComponent implements OnInit {
|
|||
this.modalErrorMessage = '';
|
||||
this.entitiesModalOpen(this.alertModalSaveEntity, '', 'Save Changes');
|
||||
}
|
||||
|
||||
|
||||
public newEntity() {
|
||||
this.myForm = this._fb.group({
|
||||
pid: ['', Validators.required],
|
||||
|
@ -219,7 +219,7 @@ export class EntitiesComponent implements OnInit {
|
|||
this.modalErrorMessage = '';
|
||||
this.entitiesModalOpen(this.alertModalSaveEntity, '', 'Save');
|
||||
}
|
||||
|
||||
|
||||
private entitiesModalOpen(modal: any, title: string, yesBtn: string) {
|
||||
if (!Session.isLoggedIn()) {
|
||||
this._router.navigate(['/user-info'],
|
||||
|
@ -232,7 +232,7 @@ export class EntitiesComponent implements OnInit {
|
|||
modal.open();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public entitySaveConfirmed(data: any) {
|
||||
if (!Session.isLoggedIn()) {
|
||||
this._router.navigate(['/user-info'],
|
||||
|
@ -257,54 +257,54 @@ export class EntitiesComponent implements OnInit {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public entitySavedSuccessfully(entity: Entity) {
|
||||
this.checkboxes.push(<CheckEntity>{entity: entity, checked: false});
|
||||
this.applyCheck(false);
|
||||
}
|
||||
|
||||
|
||||
public entityUpdatedSuccessfully(entity: Entity) {
|
||||
this.checkboxes.find(checkItem => checkItem.entity._id === entity._id).entity = entity;
|
||||
this.applyCheck(false);
|
||||
}
|
||||
|
||||
|
||||
public filterBySearch(text: string) {
|
||||
this.searchText = new RegExp(text, 'i');
|
||||
this.applyFilter();
|
||||
}
|
||||
|
||||
|
||||
public applyFilter() {
|
||||
this.checkboxes = [];
|
||||
this.entities.filter(item => this.filterEntities(item)).forEach(
|
||||
_ => this.checkboxes.push(<CheckEntity>{entity: _, checked: false})
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
public filterEntities(entity: Entity): boolean {
|
||||
const textFlag = this.searchText.toString() === '' || (entity.name).match(this.searchText) != null;
|
||||
return textFlag;
|
||||
}
|
||||
|
||||
|
||||
public applyStatusFilter() {
|
||||
this.checkboxes = [];
|
||||
this.entities.filter(item => this.filterEntitiesByStatus(item)).forEach(
|
||||
_ => this.checkboxes.push(<CheckEntity>{entity: _, checked: false})
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
public filterEntitiesByStatus(entity: Entity): boolean {
|
||||
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) {
|
||||
this.errorMessage = message;
|
||||
console.log('Server responded: ' + error);
|
||||
|
||||
|
||||
this.showLoading = false;
|
||||
}
|
||||
|
||||
|
||||
handleUpdateError(message: string, error) {
|
||||
if (error == null) {
|
||||
this.myForm = this._fb.group({
|
||||
|
@ -317,21 +317,21 @@ export class EntitiesComponent implements OnInit {
|
|||
this.updateErrorMessage = message;
|
||||
console.log('Server responded: ' + error);
|
||||
}
|
||||
|
||||
|
||||
this.showLoading = false;
|
||||
}
|
||||
|
||||
|
||||
public applyCommunityFilter(community_pid: string) {
|
||||
this.getEntities(community_pid);
|
||||
}
|
||||
|
||||
|
||||
public toggleEntities(status: boolean, ids: string[]) {
|
||||
// this.okModal.showModal();
|
||||
this.toggleIds = ids;
|
||||
this.toggleStatus = status;
|
||||
this.confirmRelatedPagesModalOpen();
|
||||
}
|
||||
|
||||
|
||||
private confirmRelatedPagesModalOpen() {
|
||||
if (!Session.isLoggedIn()) {
|
||||
this._router.navigate(['/user-info'],
|
||||
|
@ -345,7 +345,7 @@ export class EntitiesComponent implements OnInit {
|
|||
this.alertModalRelatedPages.open();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public continueToggling(event: any) {
|
||||
if (!Session.isLoggedIn()) {
|
||||
this._router.navigate(['/user-info'],
|
||||
|
|
|
@ -15,6 +15,7 @@ import {map, startWith} from "rxjs/operators";
|
|||
import {MatAutocompleteSelectedEvent} from "@angular/material";
|
||||
import {PortalUtils} from "../portal/portalHelper";
|
||||
import {properties} from "../../../../environments/environment";
|
||||
import {ConnectHelper} from "../../connect/connectHelper";
|
||||
|
||||
@Component({
|
||||
selector: 'pages',
|
||||
|
@ -100,20 +101,18 @@ export class PagesComponent implements OnInit {
|
|||
|
||||
this.properties = properties;
|
||||
this.subscriptions.push(this.route.queryParams.subscribe(params => {
|
||||
HelperFunctions.scroll();
|
||||
|
||||
this.pagesType = '';
|
||||
if (params['type']) {
|
||||
// this.pagesType = 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.subscriptions.push(this.userManagementService.getUserInfo().subscribe(user => {
|
||||
this.applyCommunityFilter(this.selectedCommunityPid);
|
||||
this.isPortalAdministrator = Session.isPortalAdministrator(user) && !this.selectedCommunityPid;
|
||||
}));
|
||||
//this.getCommunities();
|
||||
}));
|
||||
|
||||
this.subscriptions.push(this._helpContentService.getEntities(this.properties.adminToolsAPIURL).subscribe(
|
||||
|
|
|
@ -20,15 +20,15 @@
|
|||
<button class="uk-button uk-button-secondary">Bulk Actions</button>
|
||||
<div uk-dropdown="mode: click">
|
||||
<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">
|
||||
<li><a [class]="getSelectedCommunities().length == 0 ? 'uk-disabled' : ''"
|
||||
(click)="confirmDeleteSelectedCommunities()"><i></i> Delete </a></li>
|
||||
<li><a [class]="getSelectedPortals().length == 0 ? 'uk-disabled' : ''"
|
||||
(click)="confirmDeleteSelectedPortals()"><i></i> Delete </a></li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<a (click)="newCommunity()"
|
||||
<a (click)="newPortal()"
|
||||
class="uk-flex uk-flex-middle uk-text-uppercase">
|
||||
<button class="large uk-icon-button uk-button-secondary">
|
||||
<icon name="add"></icon>
|
||||
|
@ -66,20 +66,20 @@
|
|||
</thead>
|
||||
<tbody>
|
||||
<tr *ngFor="let check of checkboxes; let i=index">
|
||||
<td><input id="{{check.community._id}}" class="checkBox" type="checkbox"
|
||||
name="communitiescb[]" value="{{check.community._id}}" [(ngModel)]="check.checked">
|
||||
<td><input id="{{check.portal._id}}" class="checkBox" type="checkbox"
|
||||
name="communitiescb[]" value="{{check.portal._id}}" [(ngModel)]="check.checked">
|
||||
</td>
|
||||
<td>
|
||||
<div class="name" href="#">{{check.community.name}}</div>
|
||||
<div class="name" href="#">{{check.portal.name}}</div>
|
||||
</td>
|
||||
<td>
|
||||
<div class="type" href="#">{{check.community.type}}</div>
|
||||
<div class="type" href="#">{{check.portal.type}}</div>
|
||||
</td>
|
||||
<td>
|
||||
<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"
|
||||
(click)="confirmDeleteCommunity(check.community._id)"></i>
|
||||
(click)="confirmDeletePortal(check.portal._id)"></i>
|
||||
</div>
|
||||
</td>
|
||||
|
||||
|
@ -101,26 +101,18 @@
|
|||
</div>
|
||||
</div>
|
||||
|
||||
<modal-alert #AlertModalSaveCommunity (alertOutput)="communitySaveConfirmed($event)"
|
||||
<modal-alert #portalModal (alertOutput)="portalSaveConfirmed($event)"
|
||||
[okDisabled]="portalFG && (portalFG.invalid || !portalFG.dirty)">
|
||||
|
||||
<div *ngIf="modalErrorMessage" class="uk-alert-danger" uk-alert aria-hidden="true">{{ modalErrorMessage }}</div>
|
||||
<form [formGroup]="portalFG">
|
||||
<div dashboard-input class="uk-margin-small-left" [formInput]="portalFG.controls.name"
|
||||
type="text"
|
||||
label="Portal Name">
|
||||
<form [formGroup]="portalFG" class="uk-grid uk-child-width-1-1" uk-grid>
|
||||
<div dashboard-input [formInput]="portalFG.get('name')" type="text" label="Portal Name" placeholder="Write a name">
|
||||
</div>
|
||||
<div [ngClass]="{'has-error':!portalFG.controls.type.valid && portalFG.controls.type.dirty}">
|
||||
<label for="portalTypeTag">*Portal Type</label>
|
||||
<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"
|
||||
<div dashboard-input type="select" label="Portal Type" placeholder="Choose a type" [formInput]="portalFG.get('type')" [options]="portalUtils.portalTypes"></div>
|
||||
<div dashboard-input [formInput]="portalFG.get('pid')"
|
||||
type="text"
|
||||
label="Portal persistent id for portal">
|
||||
</div>
|
||||
<div dashboard-input class="uk-margin-small-left" [formInput]="portalFG.controls.piwik"
|
||||
<div dashboard-input [formInput]="portalFG.get('piwik')"
|
||||
type="text"
|
||||
label="Piwik id">
|
||||
</div>
|
||||
|
@ -128,4 +120,4 @@
|
|||
</form>
|
||||
|
||||
</modal-alert>
|
||||
<modal-alert #AlertModalDeleteCommunities (alertOutput)="confirmedDeleteCommunities($event)"></modal-alert>
|
||||
<modal-alert #deleteModal (alertOutput)="confirmedDeletePortals($event)"></modal-alert>
|
||||
|
|
|
@ -12,6 +12,7 @@ import {CheckPortal, Portal} from "../../utils/entities/adminTool/portal";
|
|||
import {PortalUtils} from "./portalHelper";
|
||||
import {properties} from "../../../../environments/environment";
|
||||
import {CheckPage, Page} from "../../utils/entities/adminTool/page";
|
||||
import {AlertModal} from "../../utils/modal/alert";
|
||||
|
||||
@Component({
|
||||
selector: 'portals',
|
||||
|
@ -19,57 +20,59 @@ import {CheckPage, Page} from "../../utils/entities/adminTool/page";
|
|||
})
|
||||
|
||||
export class PortalsComponent implements OnInit {
|
||||
|
||||
@ViewChild('AlertModalSaveCommunity') alertModalSaveCommunity;
|
||||
@ViewChild('AlertModalDeleteCommunities') alertModalDeleteCommunities;
|
||||
private selectedCommunities: string[] = [];
|
||||
|
||||
|
||||
@ViewChild('portalModal') portalModal: AlertModal;
|
||||
@ViewChild('deleteModal') deleteModal: AlertModal;
|
||||
private selectedPortals: string[] = [];
|
||||
|
||||
public checkboxes: CheckPortal[] = [];
|
||||
public communities: Portal[] = [];
|
||||
|
||||
public portals: Portal[] = [];
|
||||
|
||||
public portalFG: FormGroup;
|
||||
public filterForm: FormGroup;
|
||||
private subscriptions: any[] = [];
|
||||
|
||||
|
||||
private searchText: RegExp = new RegExp('');
|
||||
public keyword = '';
|
||||
|
||||
|
||||
public properties: EnvProperties = null;
|
||||
|
||||
|
||||
public showLoading = true;
|
||||
public errorMessage = '';
|
||||
public updateErrorMessage = '';
|
||||
public modalErrorMessage = '';
|
||||
public portalUtils:PortalUtils = new PortalUtils();
|
||||
public portalUtils: PortalUtils = new PortalUtils();
|
||||
|
||||
ngOnInit() {
|
||||
this.portalFG = this._fb.group({
|
||||
name: '',
|
||||
_id: '',
|
||||
pid: '',
|
||||
piwik:'',
|
||||
type: ''
|
||||
name: this._fb.control('', Validators.required),
|
||||
_id: this._fb.control(''),
|
||||
pid: this._fb.control('', Validators.required),
|
||||
piwik: this._fb.control(''),
|
||||
type: this._fb.control('', Validators.required),
|
||||
});
|
||||
this.filterForm = this._fb.group({
|
||||
this.filterForm = this._fb.group({
|
||||
keyword: [''],
|
||||
type: ['all', Validators.required]});
|
||||
type: ['all', Validators.required]
|
||||
});
|
||||
this.subscriptions.push(this.filterForm.get('keyword').valueChanges.subscribe(value => {
|
||||
this.filterBySearch(value);
|
||||
}));
|
||||
this.subscriptions.push(this.filterForm.get('type').valueChanges.subscribe(value => {
|
||||
this.applyTypeFilter();
|
||||
}));
|
||||
|
||||
|
||||
HelperFunctions.scroll();
|
||||
this.properties = properties;
|
||||
this.getCommunities();
|
||||
|
||||
this.getPortals();
|
||||
|
||||
}
|
||||
|
||||
|
||||
constructor(private element: ElementRef, private route: ActivatedRoute,
|
||||
private _router: Router, private _helpContentService: HelpContentService, private _fb: FormBuilder) {
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
ngOnDestroy(): void {
|
||||
this.subscriptions.forEach(value => {
|
||||
if (value instanceof Subscriber) {
|
||||
|
@ -79,8 +82,8 @@ export class PortalsComponent implements OnInit {
|
|||
}
|
||||
});
|
||||
}
|
||||
|
||||
getCommunities() {
|
||||
|
||||
getPortals() {
|
||||
if (!Session.isLoggedIn()) {
|
||||
this._router.navigate(['/user-info'], {
|
||||
queryParams: {'errorCode': LoginErrorCodes.NOT_VALID, 'redirectUrl': this._router.url}
|
||||
|
@ -89,14 +92,14 @@ export class PortalsComponent implements OnInit {
|
|||
this.showLoading = true;
|
||||
this.updateErrorMessage = '';
|
||||
this.errorMessage = '';
|
||||
|
||||
|
||||
|
||||
|
||||
this.subscriptions.push(this._helpContentService.getPortalsFull(this.properties.adminToolsAPIURL).subscribe(
|
||||
communities => {
|
||||
this.communities = communities;
|
||||
if(communities) {
|
||||
communities.forEach(_ => {
|
||||
this.checkboxes.push(<CheckPortal>{community: _, checked: false});
|
||||
portals => {
|
||||
this.portals = portals;
|
||||
if (portals) {
|
||||
portals.forEach(_ => {
|
||||
this.checkboxes.push(<CheckPortal>{portal: _, checked: false});
|
||||
});
|
||||
}
|
||||
this.showLoading = false;
|
||||
|
@ -104,54 +107,48 @@ export class PortalsComponent implements OnInit {
|
|||
error => this.handleError('System error retrieving portals', error)));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public toggleCheckBoxes(event) {
|
||||
this.checkboxes.forEach(_ => _.checked = event.target.checked);
|
||||
}
|
||||
|
||||
|
||||
public applyCheck(flag: boolean) {
|
||||
this.checkboxes.forEach(_ => _.checked = flag);
|
||||
}
|
||||
|
||||
public getSelectedCommunities(): string[] {
|
||||
return this.checkboxes.filter(community => community.checked === true).map(checkedCommunity => checkedCommunity.community).map(res => res._id);
|
||||
|
||||
public getSelectedPortals(): string[] {
|
||||
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) {
|
||||
let i = this.checkboxes.findIndex(_ => _.community._id === id);
|
||||
let i = this.checkboxes.findIndex(_ => _.portal._id === id);
|
||||
this.checkboxes.splice(i, 1);
|
||||
}
|
||||
}
|
||||
|
||||
public confirmDeleteCommunity(id: string) {
|
||||
|
||||
public confirmDeletePortal(id: string) {
|
||||
// this.deleteConfirmationModal.ids = [id];
|
||||
// this.deleteConfirmationModal.showModal();
|
||||
this.selectedCommunities = [id];
|
||||
this.selectedPortals = [id];
|
||||
this.confirmModalOpen();
|
||||
}
|
||||
|
||||
public confirmDeleteSelectedCommunities() {
|
||||
this.selectedCommunities = this.getSelectedCommunities();
|
||||
|
||||
public confirmDeleteSelectedPortals() {
|
||||
this.selectedPortals = this.getSelectedPortals();
|
||||
this.confirmModalOpen();
|
||||
}
|
||||
|
||||
|
||||
private confirmModalOpen() {
|
||||
if (!Session.isLoggedIn()) {
|
||||
this._router.navigate(['/user-info'], {
|
||||
queryParams: {'errorCode': LoginErrorCodes.NOT_VALID, 'redirectUrl': this._router.url}
|
||||
});
|
||||
} else {
|
||||
this.alertModalDeleteCommunities.cancelButton = true;
|
||||
this.alertModalDeleteCommunities.okButton = true;
|
||||
this.alertModalDeleteCommunities.alertTitle = 'Delete Confirmation';
|
||||
this.alertModalDeleteCommunities.message = 'Are you sure you want to delete the selected portal(-ies)?';
|
||||
this.alertModalDeleteCommunities.okButtonText = 'Yes';
|
||||
this.alertModalDeleteCommunities.open();
|
||||
}
|
||||
this.deleteModal.cancelButton = true;
|
||||
this.deleteModal.okButton = true;
|
||||
this.deleteModal.alertTitle = 'Delete Confirmation';
|
||||
this.deleteModal.message = 'Are you sure you want to delete the selected portal(-ies)?';
|
||||
this.deleteModal.okButtonText = 'Yes';
|
||||
this.deleteModal.open();
|
||||
}
|
||||
|
||||
public confirmedDeleteCommunities(data: any) {
|
||||
|
||||
public confirmedDeletePortals(data: any) {
|
||||
if (!Session.isLoggedIn()) {
|
||||
this._router.navigate(['/user-info'], {
|
||||
queryParams: {'errorCode': LoginErrorCodes.NOT_VALID, 'redirectUrl': this._router.url}
|
||||
|
@ -159,89 +156,76 @@ export class PortalsComponent implements OnInit {
|
|||
} else {
|
||||
this.showLoading = true;
|
||||
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;
|
||||
},
|
||||
error => this.handleUpdateError('System error deleting the selected communities', error)
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
public editCommunity(i: number) {
|
||||
const community: Portal = this.checkboxes[i].community;
|
||||
|
||||
public editPortal(i: number) {
|
||||
const portal: Portal = this.checkboxes[i].portal;
|
||||
this.portalFG = this._fb.group({
|
||||
name: community.name,
|
||||
_id: community._id,
|
||||
type: community.type,
|
||||
piwik:community.piwik,
|
||||
pid: community.pid
|
||||
name: this._fb.control(portal.name, Validators.required),
|
||||
_id: this._fb.control(portal._id),
|
||||
pid: this._fb.control(portal.pid, Validators.required),
|
||||
piwik: this._fb.control(portal.piwik),
|
||||
type: this._fb.control(portal.type, Validators.required),
|
||||
});
|
||||
this.portalFG.controls['type'].disable();
|
||||
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 = this._fb.group({
|
||||
name: '',
|
||||
_id: '',
|
||||
type: '',
|
||||
piwik: '',
|
||||
pid: ''
|
||||
name: this._fb.control('', Validators.required),
|
||||
_id: this._fb.control(''),
|
||||
pid: this._fb.control('', Validators.required),
|
||||
piwik: this._fb.control(''),
|
||||
type: this._fb.control('', Validators.required),
|
||||
});
|
||||
this.modalErrorMessage = '';
|
||||
this.communitiesModalOpen(this.alertModalSaveCommunity, '', 'Save');
|
||||
this.portalModalOpen('Create Portal', 'Save');
|
||||
}
|
||||
|
||||
private communitiesModalOpen(modal: any, title: string, yesBtn: string) {
|
||||
if (!Session.isLoggedIn()) {
|
||||
this._router.navigate(['/user-info'], {
|
||||
queryParams: {'errorCode': LoginErrorCodes.NOT_VALID, 'redirectUrl': this._router.url}
|
||||
});
|
||||
} else {
|
||||
modal.cancelButton = true;
|
||||
modal.okButton = true;
|
||||
modal.alertTitle = title;
|
||||
modal.okButtonText = yesBtn;
|
||||
modal.open();
|
||||
}
|
||||
|
||||
private portalModalOpen(title: string, yesBtn: string) {
|
||||
this.portalModal.okButtonLeft = false;
|
||||
this.portalModal.cancelButton = true;
|
||||
this.portalModal.okButton = true;
|
||||
this.portalModal.alertTitle = title;
|
||||
this.portalModal.okButtonText = yesBtn;
|
||||
this.portalModal.open();
|
||||
}
|
||||
|
||||
public communitySaveConfirmed(data: any) {
|
||||
if (!Session.isLoggedIn()) {
|
||||
this._router.navigate(['/user-info'], {
|
||||
queryParams: {'errorCode': LoginErrorCodes.NOT_VALID, 'redirectUrl': this._router.url}
|
||||
});
|
||||
} else {
|
||||
|
||||
|
||||
public portalSaveConfirmed(data: any) {
|
||||
this.modalErrorMessage = '';
|
||||
if (this.portalFG.getRawValue()['_id'].length > 0) {
|
||||
this.portalFG.controls['type'].enable();
|
||||
this.subscriptions.push(this._helpContentService.updateCommunity(<Portal>this.portalFG.value,
|
||||
this.properties.adminToolsAPIURL).subscribe(
|
||||
community => {
|
||||
this.communityUpdatedSuccessfully(community);
|
||||
portal => {
|
||||
this.portalUpdatedSuccessfully(portal);
|
||||
},
|
||||
error => this.handleUpdateError('System error updating portal', error)
|
||||
));
|
||||
}else{
|
||||
} else {
|
||||
this.subscriptions.push(this._helpContentService.saveCommunity(<Portal>this.portalFG.value,
|
||||
this.properties.adminToolsAPIURL).subscribe(
|
||||
community => {
|
||||
this.communitySavedSuccessfully(community);
|
||||
portal => {
|
||||
this.portalSavedSuccessfully(portal);
|
||||
},
|
||||
error => this.handleUpdateError('System error creating portal', error)
|
||||
));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public communityUpdateConfirmed(data: any) {
|
||||
|
||||
public portalUpdateConfirmed(data: any) {
|
||||
if (!Session.isLoggedIn()) {
|
||||
this._router.navigate(['/user-info'], {
|
||||
queryParams: {'errorCode': LoginErrorCodes.NOT_VALID, 'redirectUrl': this._router.url}
|
||||
|
@ -250,72 +234,74 @@ export class PortalsComponent implements OnInit {
|
|||
this.portalFG.controls['type'].enable();
|
||||
this.subscriptions.push(this._helpContentService.updateCommunity(<Portal>this.portalFG.value,
|
||||
this.properties.adminToolsAPIURL).subscribe(
|
||||
community => {
|
||||
this.communityUpdatedSuccessfully(community);
|
||||
portal => {
|
||||
this.portalUpdatedSuccessfully(portal);
|
||||
},
|
||||
error => this.handleUpdateError('System error updating portal', error)
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
public communitySavedSuccessfully(community: Portal) {
|
||||
this.checkboxes.push(<CheckPortal>{community: community, checked: false});
|
||||
|
||||
public portalSavedSuccessfully(portal: Portal) {
|
||||
this.checkboxes.push(<CheckPortal>{portal: portal, checked: false});
|
||||
this.applyCheck(false);
|
||||
}
|
||||
|
||||
public communityUpdatedSuccessfully(community: Portal) {
|
||||
this.checkboxes.find(checkItem => checkItem.community._id === community._id).community = community;
|
||||
|
||||
public portalUpdatedSuccessfully(portal: Portal) {
|
||||
this.checkboxes.find(checkItem => checkItem.portal._id === portal._id).portal = portal;
|
||||
this.applyCheck(false);
|
||||
}
|
||||
|
||||
|
||||
public filterBySearch(text: string) {
|
||||
this.searchText = new RegExp(text, 'i');
|
||||
this.applyFilter();
|
||||
}
|
||||
|
||||
|
||||
public applyFilter() {
|
||||
this.checkboxes = [];
|
||||
this.communities.filter(item => this.filterCommunities(item)).forEach(
|
||||
_ => this.checkboxes.push(<CheckPortal>{community: _, checked: false})
|
||||
this.portals.filter(item => this.filterPortals(item)).forEach(
|
||||
_ => this.checkboxes.push(<CheckPortal>{portal: _, checked: false})
|
||||
);
|
||||
}
|
||||
|
||||
public applyTypeFilter() {
|
||||
this.checkboxes = [];
|
||||
this.communities.filter(item => this.filterByType(item)).forEach(
|
||||
_ => this.checkboxes.push(<CheckPortal>{community: _, checked: false})
|
||||
this.portals.filter(item => this.filterByType(item)).forEach(
|
||||
_ => this.checkboxes.push(<CheckPortal>{portal: _, checked: false})
|
||||
);
|
||||
}
|
||||
|
||||
public filterByType(community: Portal): boolean {
|
||||
|
||||
public filterByType(portal: Portal): boolean {
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
handleUpdateError(message: string, error) {
|
||||
if (error == null) {
|
||||
this.portalFG = this._fb.group({
|
||||
name: '',
|
||||
_id: '',
|
||||
pid: '',
|
||||
piwik:'',
|
||||
piwik: '',
|
||||
type: ''
|
||||
});
|
||||
} else {
|
||||
this.updateErrorMessage = message;
|
||||
console.log('Server responded: ' + error);
|
||||
}
|
||||
|
||||
|
||||
this.showLoading = false;
|
||||
}
|
||||
|
||||
|
||||
handleError(message: string, error) {
|
||||
this.errorMessage = message;
|
||||
console.log('Server responded: ' + error);
|
||||
|
||||
|
||||
this.showLoading = false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,11 +9,10 @@ import {HelperFunctions} from "../../../utils/HelperFunctions.class";
|
|||
selector: 'admin-tabs',
|
||||
template: `
|
||||
<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 [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" [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">Class Ids</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 === 'entity'"><a routerLink="../entities"><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>
|
||||
</ul>
|
||||
`
|
||||
})
|
||||
|
@ -35,12 +34,6 @@ export class AdminTabsComponent implements OnInit {
|
|||
ngOnInit() {
|
||||
this.subscriptions.push(this.userManagementService.getUserInfo().subscribe(user => {
|
||||
this.user = user;
|
||||
|
||||
}));
|
||||
this.subscriptions.push(this.route.queryParams.subscribe(params => {
|
||||
HelperFunctions.scroll();
|
||||
this.portal = params['communityId'];
|
||||
|
||||
}));
|
||||
}
|
||||
ngOnDestroy(): void {
|
||||
|
|
|
@ -40,7 +40,7 @@ export interface Option {
|
|||
</textarea>
|
||||
</ng-template>
|
||||
<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-select #select *ngIf="type === 'select'" [required]="required" [value]="null"
|
||||
(openedChange)="stopPropagation()" [formControl]="formControl" [disableOptionCentering]="true">
|
||||
|
|
|
@ -195,7 +195,7 @@ export class Portal {
|
|||
}
|
||||
|
||||
export interface CheckPortal {
|
||||
community: Portal;
|
||||
portal: Portal;
|
||||
checked: boolean;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue