[Library| Trunk]

Transfer admin tool components in library & update the theme 
        - divId
        - entity
        - portals/communities



git-svn-id: https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-services-library/trunk/ng-openaire-library/src/app@57916 d315682c-612b-4755-9ff5-7f18f6832af3
deprecated-master
argiro.kokogiannaki 4 years ago
parent 75a9265c23
commit e955a799e5

@ -0,0 +1,13 @@
import { NgModule } from '@angular/core';
import {RouterModule} from '@angular/router';
import {DivIdsComponent} from './divIds.component';
import {AdminLoginGuard} from "../../login/adminLoginGuard.guard";
@NgModule({
imports: [
RouterModule.forChild([
{ path: '', canActivate: [AdminLoginGuard], component: DivIdsComponent}
])
]
})
export class DivIdsRoutingModule { }

@ -0,0 +1,163 @@
<div id="page_content" click-outside-or-esc targetId="page_content">
<div class="uk-padding-small md-bg-white" uk-grid>
<div class="uk-width-expand@m uk-width-1-1 uk-flex uk-flex-middle uk-flex-right">
<div class="uk-inline uk-width-medium">
<span class="uk-position-center-right"><i class="material-icons">search</i></span>
<div dashboard-input label="Locate indicator" [formInput]="filterForm" label="Find class"></div>
</div>
</div>
</div>
<div id="page_content_inner">
<div class="menubar ">
<h4 class="uk-text-bold">Predefined classes for contents</h4>
<div *ngIf="updateErrorMessage" class="uk-alert-danger" uk-alert>
<a class="uk-alert-close" uk-close></a>
{{updateErrorMessage}}
</div>
</div>
<div class="content-wrapper" id="contentWrapper">
<div>
<div class="contentPanel">
<div *ngIf="errorMessage" class="uk-alert uk-alert-danger uk-margin-large-top"
role="alert">{{errorMessage}}</div>
<div [style.display]="showLoading ? 'inline' : 'none'"
class="uk-animation-fade uk-margin-large-top uk-width-1-1" role="alert"><img
class="uk-align-center loading-gif"></div>
<div *ngIf="!errorMessage && !showLoading" class="page-controls">
<div class=" filters ">
<div class="show-options uk-float-right">
<button class="uk-button" type="button">Bulk Actions</button>
<div uk-dropdown="mode: click">
<ul class="uk-nav uk-navbar-dropdown-nav"
[attr.uk-tooltip]="getSelectedDivIds().length == 0 ? 'pos:left; cls: uk-active' : 'cls: uk-invisible'"
title="Select at least one class">
<li><a [class]="getSelectedDivIds().length == 0 ? 'uk-disabled' : ''"
(click)="confirmDeleteSelectedDivIds()"><i></i> Delete </a></li>
</ul>
</div>
</div>
</div>
</div>
<div class="md-card uk-margin-medium-bottom" *ngIf="!errorMessage && !showLoading">
<div class="md-card-content">
<div class="uk-overflow-container">
<table class="uk-table uk-table-striped">
<thead>
<tr>
<th><input id="allDivIdCheckbox" type="checkbox" (change)="toggleCheckBoxes($event)"></th>
<th>Name</th>
<th>Page</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<tr *ngFor="let check of checkboxes; let i=index">
<td><input id="{{check.divId._id}}" class="checkBox" type="checkbox"
name="divIdscb[]" value="{{check.divId._id}}" [(ngModel)]="check.checked">
</td>
<td>
<div class="name" href="#">{{check.divId.name}}</div>
</td>
<td>
<div class="pages" href="#">
<span *ngFor="let page of check.divId.pages let i=index">{{page.name}}<span
*ngIf="i<(check.divId.pages.length-1)">, </span></span>
</div>
</td>
<td>
<div class="actions" href="#">
<i class="md-icon material-icons" (click)="editDivId(i)"></i>
<i class="material-icons md-icon"
(click)="confirmDeleteDivId(check.divId._id)">delete</i>
</div>
</td>
</tr>
</tbody>
</table>
<div class="uk-width-1-1 uk-flex uk-flex-center ">
<div class="uk-width-small uk-flex uk-flex-center uk-button" (click)="newDivId()">
<i class="material-icons md-48">add</i>
</div>
</div>
<div *ngIf="checkboxes.length==0" class="col-md-12">
<div class="uk-alert-warning uk-alert" >No classes found</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<modal-alert #AlertModalSaveDivId (alertOutput)="divIdSaveConfirmed($event)"
[okDisabled]="myForm && (myForm.invalid || !myForm.dirty)">
<div *ngIf="modalErrorMessage" class="uk-alert-danger" uk-alert aria-hidden="true">{{ modalErrorMessage }}</div>
<form [formGroup]="myForm">
<div dashboard-input class="uk-margin-small-left" [formInput]="myForm.get('name')"
type="text"
label="Class Name">
</div>
<mat-form-field class="example-chip-list uk-width-1-1 uk-margin-small-left">
<mat-chip-list #chipList aria-label="Page selection">
<mat-chip
*ngFor="let page of selectedPages"
[selectable]="true"
[removable]="true">
{{page.name}}
<span (click)="remove(page)"
class="mat-icon notranslate mat-chip-remove mat-chip-trailing-icon material-icons mat-icon-no-color ng-star-inserted">cancel</span>
</mat-chip>
<input placeholder="Add in pages..." #PageInput
[formControl]="pageSearchCtrl" [matAutocomplete]="auto" [matChipInputFor]="chipList">
</mat-chip-list>
<mat-autocomplete #auto="matAutocomplete" (optionSelected)="selected($event)">
<mat-option *ngFor="let page of filteredPages| async" [value]="page">
{{page.name}}
</mat-option>
</mat-autocomplete>
</mat-form-field>
<div class="form-group uk-margin-small-left">
<div class="uk-text-muted"> Select if this class exists in:</div>
<span dashboard-input class="" [formInput]="myForm.get('openaire')"
type="checkbox"
label="Explore Portal">
</span>
<span dashboard-input class="uk-margin-small-left" [formInput]="myForm.get('connect')"
type="checkbox"
label="Connect Portal">
</span>
<span dashboard-input class="uk-margin-small-left" [formInput]="myForm.get('communities')"
type="checkbox"
label="Communities Dashboards">
</span>
<!-- <mat-checkbox [formControl]="myForm.get('openaire')" >Explore Portal</mat-checkbox>-->
<!-- <input type="checkbox" id="openaire" formControlName="openaire"/> Explore Portal-->
<!-- <input type="checkbox" [formControl]="myForm.get('connect')" formControlName="connect"/> Connect Portal-->
<!-- <input type="checkbox" [formControl]="myForm.controls.communities"-->
<!-- formControlName="communities"/>Communities Dashboards-->
</div>
<input type="hidden" formControlName="_id">
</form>
</modal-alert>
<modal-alert #AlertModalDeleteDivIds (alertOutput)="confirmedDeleteDivIds($event)"></modal-alert>

@ -0,0 +1,365 @@
import {Component, ElementRef, OnInit, ViewChild} from '@angular/core';
import {ActivatedRoute, Router} from "@angular/router";
import {HelpContentService} from "../../services/help-content.service";
import {FormArray, FormBuilder, FormControl, FormGroup, Validators} from "@angular/forms";
import {CheckDivId, DivId} from "../../utils/entities/adminTool/divId";
import {Page} from "../../utils/entities/adminTool/page";
import {EnvProperties} from '../../utils/properties/env-properties';
import {Session} from '../../login/utils/helper.class';
import {LoginErrorCodes} from '../../login/utils/guardHelper.class';
import {HelperFunctions} from "../../utils/HelperFunctions.class";
import {Observable, Subscriber} from "rxjs";
import {map, startWith} from "rxjs/operators";
import {MatAutocompleteSelectedEvent, MatChipInputEvent} from "@angular/material";
@Component({
selector: 'divIds',
templateUrl: './divIds.component.html',
})
export class DivIdsComponent implements OnInit {
@ViewChild('AlertModalSaveDivId') alertModalSaveDivId;
@ViewChild('AlertModalDeleteDivIds') alertModalDeleteDivIds;
private selectedDivIds: string[] = [];
public checkboxes: CheckDivId[] = [];
public divIds: DivId[] = [];
public myForm: FormGroup;
public pageSearchCtrl: FormControl;
public pagesCtrl: FormArray;
private searchText: RegExp = new RegExp('');
public keyword: string = "";
public properties: EnvProperties = null;
public formPages: Page[] = [];
public showLoading: boolean = true;
public errorMessage: string = '';
public updateErrorMessage: string = '';
public modalErrorMessage: string = '';
public filterForm: FormControl;
private subscriptions: any[] = [];
public allPages: Page[] = [];
filteredPages: Observable<Page[]>;
@ViewChild('PageInput') pageInput: ElementRef<HTMLInputElement>;
selectedPages: Page[] = [];
selectedCommunityPid = null;
ngOnInit() {
this.filterForm = this._fb.control('');
this.pageSearchCtrl = this._fb.control('');
this.subscriptions.push(this.filterForm.valueChanges.subscribe(value => {
this.filterBySearch(value);
}));
this.pagesCtrl = this._fb.array([]);
this.myForm = this._fb.group({
_id: '',
name: ['', Validators.required],
pages: this.pagesCtrl,
openaire: true,
connect: false,
communities: true
});
this.route.data
.subscribe((data: { envSpecific: EnvProperties }) => {
HelperFunctions.scroll();
this.properties = data.envSpecific;
this.getDivIds();
this.route.queryParams.subscribe(params => {
this.selectedCommunityPid = params['communityId'];
this.getPages();
});
});
}
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) {
value.unsubscribe();
} else if (value instanceof Function) {
value();
}
});
}
getDivIds() {
if (!Session.isLoggedIn()) {
this._router.navigate(['/user-info'], {
queryParams: {
"errorCode": LoginErrorCodes.NOT_VALID,
"redirectUrl": this._router.url
}
});
} else {
this.showLoading = true;
this.updateErrorMessage = "";
this.errorMessage = "";
this._helpContentService.getDivIdsFull(null, this.properties.adminToolsAPIURL).subscribe(
divIds => {
this.divIds = divIds;
this.checkboxes = [];
let self = this;
divIds.forEach(_ => {
self.checkboxes.push(<CheckDivId>{divId: _, checked: false});
});
this.showLoading = false;
},
error => this.handleError('System error retrieving classes', error));
}
}
// public showModal():void {
// this.modal.showModal();
// }
public toggleCheckBoxes(event) {
this.checkboxes.forEach(_ => _.checked = event.target.checked);
}
public applyCheck(flag: boolean) {
this.checkboxes.forEach(_ => _.checked = flag);
}
public getSelectedDivIds(): string[] {
return this.checkboxes.filter(divId => divId.checked == true).map(checkedDivId => checkedDivId.divId).map(res => res._id);
}
private deleteDivIdsFromArray(ids: string[]): void {
for (let id of ids) {
let i = this.checkboxes.findIndex(_ => _.divId._id == id);
this.checkboxes.splice(i, 1);
}
}
public confirmDeleteDivId(id: string) {
this.selectedDivIds = [id];
this.confirmModalOpen();
}
public confirmDeleteSelectedDivIds() {
this.selectedDivIds = this.getSelectedDivIds();
this.confirmModalOpen();
}
private confirmModalOpen() {
if (!Session.isLoggedIn()) {
this._router.navigate(['/user-info'], {
queryParams: {
"errorCode": LoginErrorCodes.NOT_VALID,
"redirectUrl": this._router.url
}
});
} else {
this.alertModalDeleteDivIds.cancelButton = true;
this.alertModalDeleteDivIds.okButton = true;
this.alertModalDeleteDivIds.alertTitle = "Delete Confirmation";
this.alertModalDeleteDivIds.message = "Are you sure you want to delete the selected class(es)?";
this.alertModalDeleteDivIds.okButtonText = "Yes";
this.alertModalDeleteDivIds.open();
}
}
public confirmedDeleteDivIds(data: any) {
if (!Session.isLoggedIn()) {
this._router.navigate(['/user-info'], {
queryParams: {
"errorCode": LoginErrorCodes.NOT_VALID,
"redirectUrl": this._router.url
}
});
} else {
this.showLoading = true;
this.updateErrorMessage = "";
this._helpContentService.deleteDivIds(this.selectedDivIds, this.properties.adminToolsAPIURL).subscribe(
_ => {
this.deleteDivIdsFromArray(this.selectedDivIds);
this.showLoading = false;
},
error => this.handleUpdateError('System error deleting the selected classes', error)
);
}
}
public editDivId(i: number) {
let divId: DivId = this.checkboxes[i].divId;
this.formPages = <Page[]>divId.pages;
this.pagesCtrl = this._fb.array([]);
this.myForm = this._fb.group({
_id: divId._id,
name: divId.name,
pages: this.pagesCtrl,
openaire: divId.openaire,
connect: divId.connect,
communities: divId.communities
});
for(let i = 0; i < divId.pages.length; i++) {
this.pagesCtrl.push(this._fb.control(divId.pages[i]));
}
this.filteredPages = this.pageSearchCtrl.valueChanges.pipe(startWith(''),
map(page => this._filter(page)));
this.selectedPages = JSON.parse(JSON.stringify(divId.pages));
this.divIdsModalOpen(this.alertModalSaveDivId, "", "Save Changes");
}
public newDivId() {
this.pagesCtrl = this._fb.array([]);
this.myForm = this._fb.group({
_id: '',
name: ['', Validators.required],
pages: this.pagesCtrl,
openaire: this._fb.control(true),
connect: false,
communities: true
});
this.filteredPages = this.pageSearchCtrl.valueChanges.pipe(startWith(''),
map(page => this._filter(page)));
this.modalErrorMessage = "";
this.selectedPages = [];
this.divIdsModalOpen(this.alertModalSaveDivId, "", "Save");
}
private divIdsModalOpen(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();
}
}
public divIdSaveConfirmed(data: any) {
if (!Session.isLoggedIn()) {
this._router.navigate(['/user-info'], {
queryParams: {
"errorCode": LoginErrorCodes.NOT_VALID,
"redirectUrl": this._router.url
}
});
} else {
console.log(this.myForm.value)
if (this.myForm.value['_id'].length == 0) {
this.modalErrorMessage = "";
this._helpContentService.saveDivId(<DivId>this.myForm.value, this.properties.adminToolsAPIURL).subscribe(
divId => {
this.divIdSavedSuccessfully(divId);
},
error => this.handleUpdateError("System error creating class", error)
);
} else {
this._helpContentService.updateDivId(<DivId>this.myForm.value, this.properties.adminToolsAPIURL).subscribe(
divId => {
this.divIdUpdatedSuccessfully(divId);
},
error => this.handleUpdateError("System error updating class", error)
);
}
}
}
public divIdSavedSuccessfully(divId: DivId) {
this.checkboxes.push(<CheckDivId>{divId: divId, checked: false});
this.applyCheck(false);
}
public divIdUpdatedSuccessfully(divId: DivId) {
this.checkboxes.find(checkItem => checkItem.divId._id == divId._id).divId = divId;
this.applyCheck(false);
}
public filterBySearch(text: string) {
this.searchText = new RegExp(text, 'i');
this.applyFilter();
}
public applyFilter() {
this.checkboxes = [];
this.divIds.filter(item => this.filterDivIds(item)).forEach(
_ => this.checkboxes.push(<CheckDivId>{divId: _, checked: false})
);
}
public filterDivIds(divId: DivId): boolean {
let textFlag = this.searchText.toString() == '' || (divId.name).match(this.searchText) != null;
return textFlag;
}
handleUpdateError(message: string, error) {
if (error == null) {
// this.formComponent.reset();
} 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;
}
getPages() {
this.showLoading = true;
this.errorMessage = "";
this._helpContentService.getPages(this.properties.adminToolsAPIURL, this.selectedCommunityPid).subscribe(
pages => {
this.allPages = pages;
this.showLoading = false;
},
error => this.handleError('System error retrieving pages', error)
);
}
remove(page): void {
let index = this.selectedPages.indexOf(page);
if (index >= 0) {
this.selectedPages.splice(index, 1);
this.pagesCtrl.value.splice(index, 1);
this.pagesCtrl.markAsDirty();
}
}
selected(event: MatAutocompleteSelectedEvent): void {
let newPage = event.option.value;
if (this.selectedPages.indexOf(newPage) == -1) {
this.selectedPages.push(event.option.value);
this.pagesCtrl.push(this._fb.control(newPage));
this.pagesCtrl.markAsDirty();
}
this.pageInput.nativeElement.value = '';
this.pageSearchCtrl.setValue('');
}
private _filter(value: string): Page[] {
if (!value || value.length == 0) {
return this.allPages.slice();
}
const filterValue = value.toString().toLowerCase();
return this.allPages.filter(page => page.name.toLowerCase().indexOf(filterValue) != -1);
}
}

@ -0,0 +1,28 @@
import { NgModule } from '@angular/core';
import {RouterModule} from '@angular/router';
import {CommonModule} from '@angular/common';
import {FormsModule, ReactiveFormsModule} from '@angular/forms';
import {AlertModalModule} from '../../utils/modal/alertModal.module';
import {DivIdsComponent} from './divIds.component';
import {DivIdsRoutingModule} from './divIds-routing.module';
import {AdminLoginGuard} from "../../login/adminLoginGuard.guard";
import {AdminToolServiceModule} from "../../services/adminToolService.module";
import {InputModule} from "../../../library/sharedComponents/input/input.module";
import {MatAutocompleteModule} from '@angular/material/autocomplete';
import {MatCheckboxModule, MatFormFieldModule} from "@angular/material";
import {MatChipsModule} from '@angular/material/chips';
@NgModule({
imports: [
CommonModule, RouterModule, FormsModule,
AlertModalModule, ReactiveFormsModule, DivIdsRoutingModule, AdminToolServiceModule, InputModule, MatAutocompleteModule, MatFormFieldModule, MatChipsModule,
MatCheckboxModule
],
declarations: [DivIdsComponent],
providers: [AdminLoginGuard],
exports: [DivIdsComponent]
})
export class DivIdsModule { }

@ -0,0 +1,14 @@
import { NgModule } from '@angular/core';
import {RouterModule} from '@angular/router';
import {ConnectAdminLoginGuard} from '../../connect/communityGuard/connectAdminLoginGuard.guard';
import {EntitiesComponent} from './entities.component';
import {IsCommunityOrAdmin} from '../../connect/communityGuard/isCommunityOrAdmin';
@NgModule({
imports: [
RouterModule.forChild([
{ path: '', canActivate: [], component: EntitiesComponent}
])
]
})
export class EntitiesRoutingModule { }

@ -0,0 +1,139 @@
<div id="page_content" click-outside-or-esc targetId="page_content">
<!-- [escClose]="false"-->
<!-- (clickOutside)="toggleOpen($event)">-->
<div class="uk-padding-small md-bg-white" uk-grid>
<div class="uk-width-expand@m uk-width-1-1 uk-flex uk-flex-middle uk-flex-right">
<div class="uk-inline uk-width-medium">
<span class="uk-position-center-right"><i class="material-icons">search</i></span>
<div dashboard-input label="Locate indicator" [formInput]="filterForm" label="Locate entity"></div>
</div>
</div>
</div>
<div id="page_content_inner">
<div class="menubar ">
<div *ngIf="!errorMessage && !showLoading" class="page-controls">
<div class=" filters ">
<div class="show-options uk-float-right">
<button class="uk-button uk-button-primary" type="button">Bulk Actions</button>
<div uk-dropdown="mode: click">
<ul class="uk-nav uk-navbar-dropdown-nav uk-margin-left"
[attr.uk-tooltip]="getSelectedEntities().length == 0 ? 'pos:left; cls: uk-active' : 'cls: uk-invisible'"
title="Select at least one entity">
<li *ngIf="!isPortalAdministrator"><a [class]="getSelectedEntities().length == 0 ? 'uk-disabled' : ''"
(click)="toggleEntities(true, getSelectedEntities())"><i></i> Activate
</a></li>
<li *ngIf="!isPortalAdministrator"><a [class]="getSelectedEntities().length == 0 ? 'uk-disabled' : ''"
(click)="toggleEntities(false, getSelectedEntities())"><i></i> Deactivate
</a></li>
<li *ngIf="isPortalAdministrator"><a [class]="getSelectedEntities().length == 0 ? 'uk-disabled' : ''"
(click)="confirmDeleteSelectedEntities()"><i></i> Delete </a></li>
</ul>
</div>
</div>
</div>
</div>
<h4 class="uk-text-bold">Entities</h4>
<div *ngIf="updateErrorMessage" class="uk-alert-danger" uk-alert>
<a class="uk-alert-close" uk-close></a>
{{updateErrorMessage}}
</div>
</div>
<div class="content-wrapper" id="contentWrapper">
<div>
<div class="contentPanel uk-margin-top">
<div *ngIf="!isPortalAdministrator" class="uk-alert uk-alert-primary uk-margin-top-large">
<div>
<span class="uk-margin-small-right uk-icon" uk-icon="warning"></span>
Disable an entity to hide it from community dashboard portal.
</div>
<div
class="uk-text-small">If an entity is disabled, all related search and advanced search pages will be hidden from the community dashborad and a message "Can't find that page" will appear in case the url of that page is loaded. If the related page belongs to the menu the link will be removed from menu, too.
</div>
</div>
<div *ngIf="errorMessage" class="uk-alert uk-alert-danger uk-margin-large-top"
role="alert">{{errorMessage}}</div>
<div [style.display]="showLoading ? 'inline' : 'none'"
class="uk-animation-fade uk-margin-large-top uk-width-1-1" role="alert"><img
class="uk-align-center loading-gif"></div>
<div class="md-card uk-margin-medium-bottom" *ngIf="!errorMessage && !showLoading">
<div class="md-card-content">
<div class="uk-overflow-container">
<table class="uk-table uk-table-striped uk-table-hover">
<thead>
<tr>
<th><input id="allEntityCheckbox" type="checkbox" (change)="toggleCheckBoxes($event)"></th>
<th>Name</th>
<th *ngIf="!isPortalAdministrator">Change status</th>
<th *ngIf="isPortalAdministrator">Actions</th>
</tr>
</thead>
<tbody>
<tr *ngFor="let check of checkboxes; let i=index">
<td><input id="{{check.entity._id}}" class="checkBox" type="checkbox"
name="entitiescb[]" value="{{check.entity._id}}" [(ngModel)]="check.checked">
</td>
<td>
<div class="name" href="#">{{check.entity.name}}</div>
</td>
<td *ngIf="!isPortalAdministrator">
<mat-slide-toggle [checked]="check.entity.isEnabled"
(change)="($event.source.checked = check.entity.isEnabled);toggleEntities(!check.entity.isEnabled,[check.entity._id])"></mat-slide-toggle>
</td>
<td *ngIf="isPortalAdministrator">
<div class="actions" href="#">
<i class="md-icon material-icons" (click)="editEntity(i)"></i>
<i class="material-icons md-icon"
(click)="confirmDeleteEntity(check.entity._id)">delete</i>
</div>
</td>
</tr>
</tbody>
</table>
<div class="uk-width-1-1 uk-flex uk-flex-center " *ngIf="isPortalAdministrator">
<div class="uk-width-small uk-flex uk-flex-center uk-button" (click)="newEntity()">
<i class="material-icons md-48">add</i>
</div>
</div>
<div *ngIf="checkboxes.length==0" class="col-md-12">
<div class="uk-alert-warning" uk-alert>No entities found</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<modal-alert #AlertModalSaveEntity (alertOutput)="entitySaveConfirmed($event)"
[okDisabled]="myForm && (myForm.invalid || !myForm.dirty)">
<div *ngIf="modalErrorMessage" class="uk-alert-danger" uk-alert aria-hidden="true">{{ modalErrorMessage }}</div>
<form [formGroup]="myForm">
<div dashboard-input class="uk-margin-small-left" [formInput]="myForm.controls.name"
type="text"
label="Entity Name">
</div>
<div dashboard-input class="uk-margin-small-left" [formInput]="myForm.controls.pid"
type="text"
label="Entity Pid">
</div>
<input type="hidden" formControlName="_id">
</form>
</modal-alert>
<modal-alert #AlertModalRelatedPages (alertOutput)="continueToggling($event)"></modal-alert>
<modal-alert #AlertModalDeleteEntities (alertOutput)="confirmedDeleteEntities($event)"></modal-alert>

@ -0,0 +1,351 @@
import {Component, ViewChild, OnInit, ElementRef} from '@angular/core';
import {ActivatedRoute, Router} from '@angular/router';
import {HelpContentService} from '../../services/help-content.service';
import {FormBuilder, FormControl, FormGroup, Validators} from '@angular/forms';
import {CheckEntity, Entity} from '../../utils/entities/adminTool/entity';
import {Community} from '../../utils/entities/adminTool/community';
import {EnvProperties} from '../../utils/properties/env-properties';
import {Session} from '../../login/utils/helper.class';
import {LoginErrorCodes} from '../../login/utils/guardHelper.class';
import {HelperFunctions} from "../../utils/HelperFunctions.class";
import {UserManagementService} from '../../services/user-management.service';
import {Subscriber} from "rxjs";
@Component({
selector: 'entities',
templateUrl: './entities.component.html',
})
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: Community[] = [];
public selectedCommunityPid: string;
@ViewChild('AlertModalRelatedPages') alertModalRelatedPages;
public toggleIds: string[];
public toggleStatus: boolean;
public properties: EnvProperties = null;
public showLoading = true;
public errorMessage = '';
public updateErrorMessage = '';
public modalErrorMessage = '';
public isPortalAdministrator = null;
public filterForm: FormControl;
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.control('');
this.myForm = this._fb.group({
pid: ['', Validators.required],
name: ['', Validators.required],
isEnabled: '',
_id: ''
});
this.subscriptions.push(this.filterForm.valueChanges.subscribe(value => {
this.filterBySearch(value);
}));
this.route.data
.subscribe((data: { envSpecific: EnvProperties }) => {
this.properties = data.envSpecific;
this.route.queryParams.subscribe(params => {
HelperFunctions.scroll();
this.userManagementService.getUserInfo(this.properties.userInfoUrl).subscribe(user => {
this.selectedCommunityPid = params['communityId'];
this.applyCommunityFilter(this.selectedCommunityPid);
this.isPortalAdministrator = Session.isPortalAdministrator(user) && !this.selectedCommunityPid;
});
});
});
}
ngOnDestroy(): void {
this.subscriptions.forEach(value => {
if (value instanceof Subscriber) {
value.unsubscribe();
} else if (value instanceof Function) {
value();
}
});
}
getEntities(community_pid: string) {
if (!Session.isLoggedIn()) {
this._router.navigate(['/user-info'],
{queryParams: {'errorCode': LoginErrorCodes.NOT_VALID, 'redirectUrl': this._router.url}});
} else {
this.showLoading = true;
this.updateErrorMessage = '';
this.errorMessage = '';
if (community_pid) {
this._helpContentService.getCommunityEntities(community_pid, this.properties.adminToolsAPIURL).subscribe(
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));
} else {
this._helpContentService.getEntities(this.properties.adminToolsAPIURL).subscribe(
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 community entities', error));
}
}
}
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'],
{queryParams: {'errorCode': LoginErrorCodes.NOT_VALID, 'redirectUrl': this._router.url}});
} else {
this.alertModalDeleteEntities.cancelButton = true;
this.alertModalDeleteEntities.okButton = true;
this.alertModalDeleteEntities.alertTitle = 'Delete Confirmation';
this.alertModalDeleteEntities.message = 'Are you sure you want to delete the selected entity(-ies)?';
this.alertModalDeleteEntities.okButtonText = 'Yes';
this.alertModalDeleteEntities.open();
}
}
public confirmedDeleteEntities(data: any) {
if (!Session.isLoggedIn()) {
this._router.navigate(['/user-info'],
{queryParams: {'errorCode': LoginErrorCodes.NOT_VALID, 'redirectUrl': this._router.url}});
} else {
this.showLoading = true;
this.updateErrorMessage = '';
this._helpContentService.deleteEntities(this.selectedEntities, this.properties.adminToolsAPIURL).subscribe(
_ => {
this.deleteEntitiesFromArray(this.selectedEntities);
this.showLoading = false;
},
error => this.handleUpdateError('System error deleting the selected entities', error)
);
}
}
public editEntity(i: number) {
const entity: Entity = this.checkboxes[i].entity;
this.myForm = this._fb.group({
name: entity.name,
_id: entity._id,
pid: entity.pid
});
this.modalErrorMessage = '';
this.entitiesModalOpen(this.alertModalSaveEntity, '', 'Save Changes');
}
public newEntity() {
this.myForm = this._fb.group({
pid: ['', Validators.required],
name: ['', Validators.required],
isEnabled: '',
_id: ''
});
this.modalErrorMessage = '';
this.entitiesModalOpen(this.alertModalSaveEntity, '', 'Save');
}
private entitiesModalOpen(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();
}
}
public entitySaveConfirmed(data: any) {
if (!Session.isLoggedIn()) {
this._router.navigate(['/user-info'],
{queryParams: {'errorCode': LoginErrorCodes.NOT_VALID, 'redirectUrl': this._router.url}});
} else {
this.modalErrorMessage = '';
if (this.myForm.getRawValue()['_id'].length > 0) {
this._helpContentService.updateEntity(
<Entity>this.myForm.value, this.properties.adminToolsAPIURL).subscribe(
entity => {
this.entityUpdatedSuccessfully(entity);
},
error => this.handleUpdateError('System error updating entity', error)
);
} else {
this._helpContentService.saveEntity(<Entity>this.myForm.value, this.properties.adminToolsAPIURL).subscribe(
entity => {
this.entitySavedSuccessfully(entity);
},
error => this.handleUpdateError('System error creating entity', error)
);
}
}
}
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;
}
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({
pid: ['', Validators.required],
name: ['', Validators.required],
isEnabled: '',
_id: ''
});
} else {
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'],
{queryParams: {'errorCode': LoginErrorCodes.NOT_VALID, 'redirectUrl': this._router.url}});
} else {
this.alertModalRelatedPages.cancelButton = true;
this.alertModalRelatedPages.okButton = true;
this.alertModalRelatedPages.alertTitle = 'Warning';
this.alertModalRelatedPages.message = "This action will affect all search pages related to this entity! Pages' status will change to entity's status! Do you want to continue?";
this.alertModalRelatedPages.okButtonText = 'Yes';
this.alertModalRelatedPages.open();
}
}
public continueToggling(event: any) {
if (!Session.isLoggedIn()) {
this._router.navigate(['/user-info'],
{queryParams: {'errorCode': LoginErrorCodes.NOT_VALID, 'redirectUrl': this._router.url}});
} else {
this.updateErrorMessage = '';
this._helpContentService.toggleEntities(
this.selectedCommunityPid, this.toggleIds, this.toggleStatus, this.properties.adminToolsAPIURL).subscribe(
() => {
for (let id of this.toggleIds) {
const i = this.checkboxes.findIndex(_ => _.entity._id === id);
this.checkboxes[i].entity.isEnabled = this.toggleStatus;
}
this.applyCheck(false);
},
error => this.handleUpdateError('System error changing the status of the selected entity(-ies)', error)
);
}
}
}

@ -0,0 +1,22 @@
import { NgModule } from '@angular/core';
import {RouterModule} from '@angular/router';
import {CommonModule} from '@angular/common';
import {EntitiesComponent} from './entities.component';
import {FormsModule, ReactiveFormsModule} from '@angular/forms';
import {AlertModalModule} from '../../utils/modal/alertModal.module';
import {EntitiesRoutingModule} from './entities-routing.module';
import {MatSlideToggleModule} from '@angular/material';
import {IsCommunityOrAdmin} from '../../connect/communityGuard/isCommunityOrAdmin';
import {AdminToolServiceModule} from "../../services/adminToolService.module";
import {InputModule} from "../../../library/sharedComponents/input/input.module";
@NgModule({
imports: [
CommonModule, RouterModule, FormsModule, AdminToolServiceModule,
AlertModalModule, ReactiveFormsModule, EntitiesRoutingModule, MatSlideToggleModule, InputModule
],
declarations: [EntitiesComponent],
providers: [IsCommunityOrAdmin],
exports: [EntitiesComponent]
})
export class EntitiesModule { }

@ -0,0 +1,13 @@
import { NgModule } from '@angular/core';
import {RouterModule} from '@angular/router';
import {CommunitiesComponent} from './communities.component';
import {AdminLoginGuard} from '../../login/adminLoginGuard.guard';
@NgModule({
imports: [
RouterModule.forChild([
{ path: '', canActivate: [AdminLoginGuard], component: CommunitiesComponent}
])
]
})
export class CommunitiesRoutingModule { }

@ -0,0 +1,121 @@
<div id="page_content" click-outside-or-esc targetId="page_content">
<!-- [escClose]="false"-->
<!-- (clickOutside)="toggleOpen($event)">-->
<div class="uk-padding-small md-bg-white" uk-grid>
<div class="uk-width-expand@m uk-width-1-1 uk-flex uk-flex-middle uk-flex-right">
<div class="uk-inline uk-width-medium">
<span class="uk-position-center-right"><i class="material-icons">search</i></span>
<div dashboard-input label="Locate indicator" [formInput]="formControl" label="Locate portal"></div>
</div>
</div>
</div>
<div id="page_content_inner">
<div class="menubar ">
<h4 class="uk-text-bold">Portals</h4>
<div *ngIf="updateErrorMessage" class="uk-alert-danger" uk-alert>
<a class="uk-alert-close" uk-close></a>
{{updateErrorMessage}}
</div>
</div>
<div class="content-wrapper" id="contentWrapper">
<div class="contentPanel">
<div *ngIf="errorMessage" class="uk-alert uk-alert-danger uk-margin-large-top"
role="alert">{{errorMessage}}</div>
<div [style.display]="showLoading ? 'inline' : 'none'"
class="uk-animation-fade uk-margin-large-top uk-width-1-1" role="alert"><img
class="uk-align-center loading-gif"></div>
<div *ngIf="!errorMessage && !showLoading" class="page-controls">
<div class=" filters ">
<div class="show-options uk-float-right">
<button class="uk-button" type="button">Bulk Actions</button>
<div uk-dropdown="mode: click">
<ul class="uk-nav uk-navbar-dropdown-nav"
[attr.uk-tooltip]="getSelectedCommunities().length == 0 ? 'pos:left; cls: uk-active' : 'cls: uk-invisible'"
title="Select at least one community">
<li><a [class]="getSelectedCommunities().length == 0 ? 'uk-disabled' : ''"
(click)="confirmDeleteSelectedCommunities()"><i></i> Delete </a></li>
</ul>
</div>
</div>
</div>
</div>
<div class="md-card uk-margin-medium-bottom" *ngIf="!errorMessage && !showLoading">
<div class="md-card-content">
<div class="uk-overflow-container">
<table class="uk-table uk-table-striped uk-table-hover">
<thead>
<tr>
<th><input id="allCommunityCheckbox" type="checkbox" (change)="toggleCheckBoxes($event)"></th>
<th>Name</th>
<th>Actions</th>
</tr>
</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>
<td>
<div class="name" href="#">{{check.community.name}}</div>
</td>
<td>
<div class="actions" href="#">
<i class="md-icon material-icons" (click)="editCommunity(i)"></i>
<i class="material-icons md-icon"
(click)="confirmDeleteCommunity(check.community._id)">delete</i>
</div>
</td>
</tr>
</tbody>
</table>
<div class="uk-width-1-1 uk-flex uk-flex-center ">
<div class="uk-width-small uk-flex uk-flex-center uk-button" (click)="newCommunity()">
<i class="material-icons md-48">add</i>
</div>
</div>
<div *ngIf="checkboxes.length==0" class="col-md-12">
<div class="uk-alert-warning" uk-alert>No communities found</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<modal-alert #AlertModalSaveCommunity (alertOutput)="communitySaveConfirmed($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="Community Name">
</div>
<div dashboard-input class="uk-margin-small-left " [formInput]="portalFG.controls.pid"
type="text"
label="Community persistent id for portal">
</div>
<input type="hidden" formControlName="_id">
</form>
</modal-alert>
<modal-alert #AlertModalDeleteCommunities (alertOutput)="confirmedDeleteCommunities($event)"></modal-alert>
</div>

@ -0,0 +1,292 @@
import {Component, ViewChild, OnInit, ElementRef} from '@angular/core';
import {ActivatedRoute, Router} from '@angular/router';
import {HelpContentService} from '../../services/help-content.service';
import {FormBuilder, FormControl, FormGroup} from '@angular/forms';
import {CheckCommunity, Community} from '../../utils/entities/adminTool/community';
import {EnvProperties} from '../../utils/properties/env-properties';
import {Session} from '../../login/utils/helper.class';
import {LoginErrorCodes} from '../../login/utils/guardHelper.class';
import {HelperFunctions} from "../../utils/HelperFunctions.class";
import {Subscriber} from "rxjs";
@Component({
selector: 'communities',
templateUrl: './communities.component.html',
})
export class CommunitiesComponent implements OnInit {
@ViewChild('AlertModalSaveCommunity') alertModalSaveCommunity;
@ViewChild('AlertModalDeleteCommunities') alertModalDeleteCommunities;
private selectedCommunities: string[] = [];
public checkboxes: CheckCommunity[] = [];
public communities: Community[] = [];
public portalFG: FormGroup;
public formControl: FormControl;
private subscriptions: any[] = [];
private searchText: RegExp = new RegExp('');
public keyword = '';
public properties: EnvProperties = null;
public showLoading = true;
public errorMessage = '';
public updateErrorMessage = '';
public modalErrorMessage = '';
ngOnInit() {
this.portalFG = this._fb.group({
name: '',
_id: '',
pid: ''
});
this.formControl = this._fb.control('');
this.subscriptions.push(this.formControl.valueChanges.subscribe(value => {
this.filterBySearch(value);
}));
this.route.data
.subscribe((data: { envSpecific: EnvProperties }) => {
HelperFunctions.scroll();
this.properties = data.envSpecific;
this.getCommunities();
});
}
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) {
value.unsubscribe();
} else if (value instanceof Function) {
value();
}
});
}
getCommunities() {
if (!Session.isLoggedIn()) {
this._router.navigate(['/user-info'], {
queryParams: {'errorCode': LoginErrorCodes.NOT_VALID, 'redirectUrl': this._router.url}
});
} else {
this.showLoading = true;
this.updateErrorMessage = '';
this.errorMessage = '';
this._helpContentService.getCommunitiesFull(this.properties.adminToolsAPIURL).subscribe(
communities => {
this.communities = communities;
communities.forEach(_ => {
this.checkboxes.push(<CheckCommunity>{community: _, checked: false});
});
this.showLoading = false;
},
error => this.handleError('System error retrieving communities', 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);
}
private deleteCommunitiesFromArray(ids: string[]): void {
for (let id of ids) {
let i = this.checkboxes.findIndex(_ => _.community._id === id);
this.checkboxes.splice(i, 1);
}
}
public confirmDeleteCommunity(id: string) {
// this.deleteConfirmationModal.ids = [id];
// this.deleteConfirmationModal.showModal();
this.selectedCommunities = [id];
this.confirmModalOpen();
}
public confirmDeleteSelectedCommunities() {
this.selectedCommunities = this.getSelectedCommunities();
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();
}
}
public confirmedDeleteCommunities(data: any) {
if (!Session.isLoggedIn()) {
this._router.navigate(['/user-info'], {
queryParams: {'errorCode': LoginErrorCodes.NOT_VALID, 'redirectUrl': this._router.url}
});
} else {
this.showLoading = true;
this.updateErrorMessage = '';
this._helpContentService.deleteCommunities(this.selectedCommunities, this.properties.adminToolsAPIURL).subscribe(
_ => {
this.deleteCommunitiesFromArray(this.selectedCommunities);
this.showLoading = false;
},
error => this.handleUpdateError('System error deleting the selected communities', error)
);
}
}
public editCommunity(i: number) {
const community: Community = this.checkboxes[i].community;
this.portalFG = this._fb.group({
name: community.name,
_id: community._id,
pid: community.pid
});
this.modalErrorMessage = '';
this.communitiesModalOpen(this.alertModalSaveCommunity, 'Update', 'Update Community');
}
public newCommunity() {
this.portalFG = this._fb.group({
name: '',
_id: '',
pid: ''
});
this.modalErrorMessage = '';
this.communitiesModalOpen(this.alertModalSaveCommunity, '', '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();
}
}
public communitySaveConfirmed(data: any) {
if (!Session.isLoggedIn()) {
this._router.navigate(['/user-info'], {
queryParams: {'errorCode': LoginErrorCodes.NOT_VALID, 'redirectUrl': this._router.url}
});
} else {
this.modalErrorMessage = '';
if (this.portalFG.getRawValue()['_id'].length > 0) {
this._helpContentService.updateCommunity(<Community>this.portalFG.value,
this.properties.adminToolsAPIURL).subscribe(
community => {
this.communityUpdatedSuccessfully(community);
},
error => this.handleUpdateError('System error updating portal', error)
);
}else{
this._helpContentService.saveCommunity(<Community>this.portalFG.value,
this.properties.adminToolsAPIURL).subscribe(
community => {
this.communitySavedSuccessfully(community);
},
error => this.handleUpdateError('System error creating portal', error)
);
}
}
}
public communityUpdateConfirmed(data: any) {
if (!Session.isLoggedIn()) {
this._router.navigate(['/user-info'], {
queryParams: {'errorCode': LoginErrorCodes.NOT_VALID, 'redirectUrl': this._router.url}
});
} else {
this._helpContentService.updateCommunity(<Community>this.portalFG.value,
this.properties.adminToolsAPIURL).subscribe(
community => {
this.communityUpdatedSuccessfully(community);
},
error => this.handleUpdateError('System error updating portal', error)
);
}
}
public communitySavedSuccessfully(community: Community) {
this.checkboxes.push(<CheckCommunity>{community: community, checked: false});
this.applyCheck(false);
}
public communityUpdatedSuccessfully(community: Community) {
this.checkboxes.find(checkItem => checkItem.community._id === community._id).community = community;
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(<CheckCommunity>{community: _, checked: false})
);
}
public filterCommunities(community: Community): boolean {
const textFlag = this.searchText.toString() === '' || (community.name).match(this.searchText) != null;
return textFlag;
}
handleUpdateError(message: string, error) {
if (error == null) {
this.portalFG = this._fb.group({
name: '',
_id: '',
pid: ''
});
} 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;
}
}

@ -0,0 +1,22 @@
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import {CommunitiesComponent} from './communities.component';
import {CommunitiesRoutingModule} from './communities-routing.module';
import {RouterModule} from '@angular/router';
import {FormsModule, ReactiveFormsModule} from '@angular/forms';
import {AlertModalModule} from '../../utils/modal/alertModal.module';
import {AdminLoginGuard} from '../../login/adminLoginGuard.guard';
import {AdminToolServiceModule} from "../../services/adminToolService.module";
import {InputModule} from "../../../library/sharedComponents/input/input.module";
@NgModule({
imports: [
CommonModule, FormsModule, AlertModalModule,
ReactiveFormsModule,
CommunitiesRoutingModule, RouterModule, AdminToolServiceModule, InputModule
],
declarations: [CommunitiesComponent],
providers: [AdminLoginGuard],
exports: [CommunitiesComponent]
})
export class CommunitiesModule { }

@ -0,0 +1,15 @@
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import {HelpContentService} from "./help-content.service";
@NgModule({
imports: [
CommonModule,
],
declarations:[ ],
providers: [HelpContentService],
})
export class AdminToolServiceModule { }

@ -0,0 +1,396 @@
/**
* Created by stefania on 7/13/17.
*/
import { Injectable } from '@angular/core';
import {HttpClient, HttpErrorResponse, HttpHeaders} from "@angular/common/http";
import { Observable } from 'rxjs';
import { Page } from "../utils/entities/adminTool/page";
import { PageHelpContent } from "../utils/entities/adminTool/page-help-content";
import { Community } from "../utils/entities/adminTool/community";
import { Entity } from "../utils/entities/adminTool/entity";
import { DivId } from "../utils/entities/adminTool/divId";
import { DivHelpContent } from "../utils/entities/adminTool/div-help-content";
import {StatisticsDisplay, StatisticsSummary} from '../connect/statistics/statisticsEntities';
import { CustomOptions } from './servicesUtils/customOptions.class';
import {catchError, map} from "rxjs/operators";
@Injectable()
export class HelpContentService {
constructor(private http:HttpClient) {
}
static removeNulls(obj){
var isArray = obj instanceof Array;
for (var k in obj){
if (obj[k]===null || obj[k]==='') isArray ? obj.splice(k,1) : delete obj[k];
else if (typeof obj[k]=="object") HelpContentService.removeNulls(obj[k]);
}
}
getDivIdsFull(page_id: string, helpContentUrl:string, pid: string = null) {
let parameters: string = "";
if(page_id || pid) {
parameters = "?";
if(page_id) {
parameters += "&page="+page_id;
}
if(pid) {
parameters += "&communityId="+pid;
}
}
return this.http.get<Array<DivId>>(helpContentUrl + '/divFull'+parameters)
//.map(res => <Array<DivId>> res.json())
.pipe(catchError(this.handleError));
}
updateDivId(divId: DivId, helpContentUrl:string) {
HelpContentService.removeNulls(divId);
return this.http.post<DivId>(helpContentUrl + '/div/update', JSON.stringify(divId), CustomOptions.getAuthOptionsWithBody())
//.map(res => <DivId> res.json())
.pipe(catchError(this.handleError));
}
getDivId(divId: string, helpContentUrl:string) {
return this.http.get<DivId>(helpContentUrl + '/div/'+divId)
//.map(res => <DivId> res.json())
.pipe(catchError(this.handleError));
}
getDivIdFull(divId: string, helpContentUrl:string) {
return this.http.get<DivId>(helpContentUrl + '/divFull/'+divId)
//.map(res => <DivId> res.json())
.pipe(catchError(this.handleError));
}
saveDivId(divId: DivId, helpContentUrl:string) {
HelpContentService.removeNulls(divId);
return this.http.post<DivId>(helpContentUrl + '/div/save', JSON.stringify(divId), CustomOptions.getAuthOptionsWithBody())
//.map(res => <DivId> res.json())
.pipe(catchError(this.handleError));
}
/*
getCommunitiesWithDivId(helpContentUrl:string) {
return this.http.get(helpContentUrl + 'community?div=true')
.map(res => <Array<Community>> res.json())
.catch(this.handleError);
}
*/
getCommunityPagesWithDivId(community_pid: string, helpContentUrl:string) {
return this.http.get<Array<Page>>(helpContentUrl + '/community/'+community_pid+'/pages?div=true')
//.map(res => <Array<Page>> res.json())
.pipe(catchError(this.handleError));
}
getCommunityDivHelpContents(community_pid: string, helpContentUrl:string) {
return this.http.get<Array<DivHelpContent>>(helpContentUrl + '/divhelpcontent?community='+community_pid)
//.map(res => <Array<DivHelpContent>> res.json())
.pipe(catchError(this.handleError));
}
getDivHelpContent(id : string, helpContentUrl:string) {
return this.http.get<DivHelpContent>(helpContentUrl + '/divhelpcontent/' + id)
//.map(res => <DivHelpContent> res.json())
.pipe(catchError(this.handleError));
}
insertOrUpdateDivHelpContent(divHelpContent: DivHelpContent, helpContentUrl:string) {
HelpContentService.removeNulls(divHelpContent);
return this.http.post<DivHelpContent>(helpContentUrl + '/divhelpcontent', JSON.stringify(divHelpContent), CustomOptions.getAuthOptionsWithBody())
//.map(res => <DivHelpContent> res.json())
.pipe(catchError(this.handleError));
}
deleteDivIds(ids : string[], helpContentUrl:string) {
return this.http.post(helpContentUrl + '/div/delete',JSON.stringify(ids), CustomOptions.getAuthOptionsWithBody())
.pipe(catchError(this.handleError));
}
deleteDivHelpContents(ids : string[], helpContentUrl:string) {
return this.http.post(helpContentUrl + '/divhelpcontent/delete',JSON.stringify(ids), CustomOptions.getAuthOptionsWithBody())
.pipe(catchError(this.handleError));
}
toggleDivHelpContents(ids : string[],status : boolean, helpContentUrl:string) {
return this.http.post(helpContentUrl + '/divhelpcontent/toggle?status='+ status.toString(), JSON.stringify(ids), CustomOptions.getAuthOptionsWithBody())
//.map( res => <string[]> res.json())
.pipe(catchError(this.handleError));
}
getPagesWithDivIds(community_pid: string, helpContentUrl:string) {
let parameters = (community_pid ? "?communityId="+community_pid : "");
return this.http.get<Array<string>>(helpContentUrl + '/div/pages'+parameters)
//.map(res => <Map<string, Set<string>>> res.json())
.pipe(catchError(this.handleError));
}
getPages(helpContentUrl:string,pid:string,with_positions:boolean=null) {
let parameters: string = "";
if(pid || with_positions == true || with_positions == false) {
parameters = "?";
if(pid) {
parameters += "&pid="+pid;
}
if(with_positions == true || with_positions == false) {
parameters += "&with_positions="+with_positions;
}
}
return this.http.get<Array<Page>>(helpContentUrl + '/page'+parameters)
//.map(res => <Array<Page>> res.json())
.pipe(catchError(this.handleError));
}
getPagesFull(helpContentUrl:string,pid:string) {
return this.http.get<Array<Page>>(helpContentUrl + '/pageFull'+(pid?("?pid="+pid):""))
//.map(res => <Array<Page>> res.json())
.pipe(catchError(this.handleError));
}
getPage(pageId:string, helpContentUrl:string) {
return this.http.get<Page>(helpContentUrl + '/page/'+pageId)
//.map(res => <Page> res.json())
.pipe(catchError(this.handleError));
}
getPageByRoute(route:string, helpContentUrl:string) {
return this.http.get<Page>(helpContentUrl + '/page/?page_route='+route)
.pipe(catchError(this.handleError));
}
getCommunities( helpContentUrl:string) {
return this.http.get<Array<Community>>(helpContentUrl + '/community')
//.map(res => <Array<Community>> res.json())
.pipe(catchError(this.handleError));
}
getCommunity(community_pid: string, helpContentUrl:string) {
return this.http.get<Community>(helpContentUrl + '/community/'+community_pid)
//.map(res => <Community> res.json())
.pipe(catchError(this.handleError));
}
getCommunitiesFull( helpContentUrl:string) {
return this.http.get<Array<Community>>(helpContentUrl + '/communityFull')
//.map(res => <Array<Community>> res.json())
.pipe(catchError(this.handleError));
}
getCommunityFull(community_pid: string, helpContentUrl:string) {
return this.http.get<Community>(helpContentUrl + '/communityFull/'+community_pid)
//.map(res => <Community> res.json())
.pipe(catchError(this.handleError));
}
saveCommunity(community: Community, helpContentUrl:string) {
// let headers = new Headers({'Content-Type': 'application/json'});
// let options = new RequestOptions({headers: headers});
HelpContentService.removeNulls(community);
return this.http.post<Community>(helpContentUrl + '/community/save', JSON.stringify(community), CustomOptions.getAuthOptionsWithBody())
//.map(res => <Community> res.json())
.pipe(catchError(this.handleError));
}
updateCommunity(community: Community, helpContentUrl:string) {
// let headers = new Headers({'Content-Type': 'application/json'});
// let options = new RequestOptions({headers: headers});
HelpContentService.removeNulls(community);
return this.http.post<Community>(helpContentUrl + '/community/update', JSON.stringify(community), CustomOptions.getAuthOptionsWithBody())
//.map(res => <Community> res.json())
.pipe(catchError(this.handleError));
}
deleteCommunities(ids : string[], helpContentUrl:string) {
// let headers = new Headers({'Content-Type': 'application/json'});
// let options = new RequestOptions({headers: headers});
return this.http.post(helpContentUrl + '/community/delete',JSON.stringify(ids), CustomOptions.getAuthOptionsWithBody())
.pipe(catchError(this.handleError));
}
getCommunityPages(community_pid: string, params: string, helpContentUrl:string) {
return this.http.get<Array<Page>>(helpContentUrl + '/community/'+community_pid+'/pages'+params)
//.map(res => <Array<Page>> res.json())
.pipe(catchError(this.handleError));
}
getEntities(helpContentUrl:string) {
return this.http.get<Array<Entity>>(helpContentUrl + '/entity')
//.map(res => <Array<Entity>> res.json())
.pipe(catchError(this.handleError));
}
getCommunityEntities(community_pid: string, helpContentUrl:string) {
return this.http.get<Array<Entity>>(helpContentUrl + '/community/'+community_pid+'/entities')
//.map(res => <Array<Entity>> res.json())
.pipe(catchError(this.handleError));
}
saveEntity(entity: Entity, helpContentUrl:string) {
HelpContentService.removeNulls(entity);
return this.http.post<Entity>(helpContentUrl + '/entity/save', JSON.stringify(entity), CustomOptions.getAuthOptionsWithBody())
//.map(res => <Entity> res.json())
.pipe(catchError(this.handleError));
}
updateEntity(entity: Entity, helpContentUrl:string) {
HelpContentService.removeNulls(entity);
return this.http.post<Entity>(helpContentUrl + '/entity/update', JSON.stringify(entity), CustomOptions.getAuthOptionsWithBody())
//.map(res => <Entity> res.json())
.pipe(catchError(this.handleError));
}
// toggleEntity(selectedCommunityId: string, id : string,status : boolean) {
// let headers = new Headers({'Content-Type': 'application/json'});
// let options = new RequestOptions({headers: headers});
//
// return this.http.post(helpContentUrl + 'community/'+selectedCommunityId+'/entity/toggle?status='+ status.toString()+'&entityId='+id.toString(), options)
// .catch(this.handleError);
// }
toggleEntities(selectedCommunityPid: string, ids : string[],status : boolean, helpContentUrl:string) {
return this.http.post(helpContentUrl +'/community/'+selectedCommunityPid+ '/entity/toggle?status='+ status.toString(), JSON.stringify(ids), CustomOptions.getAuthOptionsWithBody())
//.map( res => <string[]> res.json())
.pipe(catchError(this.handleError));
}
deleteEntities(ids : string[], helpContentUrl:string) {
return this.http.post(helpContentUrl + '/entity/delete',JSON.stringify(ids), CustomOptions.getAuthOptionsWithBody())
.pipe(catchError(this.handleError));
}
toggleEntityOfPage(pageId: string, entityId : string,status : boolean, helpContentUrl:string) {
return this.http.post(helpContentUrl + '/page/'+pageId+'/entity/toggle?status='+ status.toString()+'&entityId='+entityId.toString(), CustomOptions.getAuthOptionsWithBody())
.pipe(catchError(this.handleError));
}
savePage(page: Page, helpContentUrl:string) {
HelpContentService.removeNulls(page);
return this.http.post<Page>(helpContentUrl + '/page/save', JSON.stringify(page), CustomOptions.getAuthOptionsWithBody())
//.map(res => <Page> res.json())
.pipe(catchError(this.handleError));
}
updatePage(page: Page, helpContentUrl:string) {
HelpContentService.removeNulls(page);
return this.http.post<Page>(helpContentUrl + '/page/update', JSON.stringify(page), CustomOptions.getAuthOptionsWithBody())
//.map(res => <Page> res.json())
.pipe(catchError(this.handleError));
}
togglePages(selectedCommunityPid: string, ids : string[],status : boolean, helpContentUrl:string) {
return this.http.post(helpContentUrl + '/community/'+selectedCommunityPid+'/page/toggle?status='+ status.toString(),JSON.stringify(ids), CustomOptions.getAuthOptionsWithBody())
.pipe(catchError(this.handleError));
}
deletePages(ids : string[], helpContentUrl:string) {
return this.http.post(helpContentUrl + '/page/delete',JSON.stringify(ids), CustomOptions.getAuthOptionsWithBody())
.pipe(catchError(this.handleError));
}
getPageHelpContents(helpContentUrl:string) {
return this.http.get<Array<PageHelpContent>>(helpContentUrl + 'pagehelpcontent')
//.map(res => <Array<PageHelpContent>> res.json())
.pipe(catchError(this.handleError));
}
getCommunityPageHelpContents(community_pid: string, helpContentUrl:string) {
return this.http.get<Array<PageHelpContent>>(helpContentUrl + '/pagehelpcontent?community='+community_pid)
//.map(res => <Array<PageHelpContent>> res.json())
.pipe(catchError(this.handleError));
}
getPageHelpContent(id : string, helpContentUrl:string) {
return this.http.get<PageHelpContent>(helpContentUrl + '/pagehelpcontent/' + id)
//.map(res => <PageHelpContent> res.json())
.pipe(catchError(this.handleError));
}
savePageHelpContent(pageHelpContent: PageHelpContent, helpContentUrl:string) {
HelpContentService.removeNulls(pageHelpContent);
return this.http.post<PageHelpContent>(helpContentUrl + '/pagehelpcontent/save', JSON.stringify(pageHelpContent), CustomOptions.getAuthOptionsWithBody())
//.map(res => <PageHelpContent> res.json())
.pipe(catchError(this.handleError));
}
updatePageHelpContent(pageHelpContent: PageHelpContent, helpContentUrl:string) {
HelpContentService.removeNulls(pageHelpContent);
return this.http.post<PageHelpContent>(helpContentUrl + '/pagehelpcontent/update', JSON.stringify(pageHelpContent), CustomOptions.getAuthOptionsWithBody())
//.map(res => <PageHelpContent> res.json())
.pipe(catchError(this.handleError));
}
deletePageHelpContents(ids : string[], helpContentUrl:string) {
return this.http.post(helpContentUrl + 'pagehelpcontent/delete',JSON.stringify(ids), CustomOptions.getAuthOptionsWithBody())
.pipe(catchError(this.handleError));
}
togglePageHelpContents(ids : string[],status : boolean, helpContentUrl:string) {
return this.http.post(helpContentUrl + '/pagehelpcontent/toggle?status='+ status.toString(), JSON.stringify(ids), CustomOptions.getAuthOptionsWithBody())
//.map( res => <string[]> res.json())
.pipe(catchError(this.handleError));
}
private handleError(error: HttpErrorResponse) {
// in a real world app, we may send the error to some remote logging infrastructure
// instead of just logging it to the console
console.error(error);
return Observable.throw(error.error || 'Server error');
}
// getDataProviders() {
// return this.http.get('https://beta.services.openaire.eu/search/v2/api/datasources?format=json').map(res => <any> res.json()).map(res => res.results).do(res => {console.log(res)}).catch(this.handleError);
// }
getCommunityStatistics(apiUrl: string, communityId: string): Observable<StatisticsSummary> {
const url = `${apiUrl}communities/${communityId}`;
//console.log(`getting statistics summary from: ${url}`);
return this.http.get(url)
//.map(res => <any>res.json())
.pipe(map(res => res['statistics']));
}
getCommunityAdminStatisticsChoices(apiUrl: string, communityId: string): Observable<StatisticsDisplay> {
const url = `${apiUrl}/statistics/${communityId}`;
//console.log(`getting admin choices for statistics from: ${url}`);
return this.http.get<StatisticsDisplay>(url)
//.map(stats => <StatisticsDisplay>stats.json())
.pipe(catchError(this.handleError));
}
postCommunityAdminStatisticsChoices(apiUrl: string,
communityId: string,
entity: string,
chartsOrNumbers: string,
title: string,
status: boolean,
monitor: boolean): Observable<any> {
const url = `${apiUrl}/statistics/${communityId}/${entity}/${chartsOrNumbers}?status=${status.toString()}&monitor=${monitor.toString()}`;
//console.log(`getting admin choices for statistics from: ${url}`);
return this.http.post(url, title, CustomOptions.getAuthOptionsWithBody())
//.map(stats => <any>stats.json())
.pipe(catchError(this.handleError));
}
}

@ -0,0 +1,15 @@
import {Page} from './page';
import {Entity} from './entity';
export interface Community {
_id: string;
pid: string;
name: string;
entities: string[] | Entity[];
pages: string[] | Page[];
}
export interface CheckCommunity {
community: Community;
checked: boolean;
}

@ -0,0 +1,21 @@
import { DivId } from './divId';
import {Community} from './community';
export interface DivHelpContent {
_id: string;
divId: DivId | string;
community: string | Community;
content: string;
isActive: boolean;
}
export interface CheckDivHelpContent {
divHelpContent : DivHelpContent;
checked : boolean;
}
export interface DivHelpContentFilterOptions {
id : string;
active : Boolean;
text : RegExp;
}

@ -0,0 +1,15 @@
import {Page} from './page';
export interface DivId {
_id: string;
name: string;
pages: Page[] | String[];
connect: boolean;
communities: boolean;
openaire: boolean;
}
export interface CheckDivId {
divId: DivId;
checked: boolean;
}

@ -0,0 +1,11 @@
export class Entity {
_id: string;
pid: string;
name: string;
isEnabled: boolean;
}
export interface CheckEntity {
entity: Entity;
checked: boolean;
}

@ -0,0 +1,14 @@
import { Page } from "./page";
import { Community } from "./community";
export interface HtmlPageContent {
_id: string;
page: Page | string;
community: Community | string;
content: string;
}
export interface CheckHtmlPageContent {
pageHelpContent: HtmlPageContent;
checked: boolean;
}

@ -0,0 +1,27 @@
/**
* Created by stefania on 7/13/17.
*/
import { Page } from './page';
import { Community } from './community';
export interface PageHelpContent {
_id: string;
page: Page | string;
community: Community | string;
placement: string;
order: number;
content: string;
isActive: boolean;
isPriorTo: boolean;
}
export interface CheckPageHelpContent {
pageHelpContent: PageHelpContent;
checked: boolean;
}
export interface PageHelpContentFilterOptions {
id: string;
active: Boolean;
text: RegExp;
}

@ -0,0 +1,22 @@
import { Entity } from './entity';
export interface Page {
_id: string;
route: string;
name: string;
type: string;
isEnabled: boolean;
connect: boolean;
communities: boolean;
openaire: boolean;
entities: Entity[] | string[];
top: boolean;
bottom: boolean;
left: boolean;
right: boolean;
}
export interface CheckPage {
page: Page;
checked: boolean;
}

@ -27,7 +27,10 @@ declare var UIkit: any;
<div [ngClass]="(choice)?'uk-width-1-2':'uk-width-1-1'">
<div *ngIf="okButtonLeft" class="uk-text-right" [hidden]=!alertFooter>
<span [hidden]=!okButton>
<button class="uk-button md-btn uk-button-default" (click)="ok()">{{okButtonText}}</button>
<button *ngIf="okDisabled" class="uk-button md-btn disabled uk-button-default ignoreCommunityPanelBackground" disabled>{{okButtonText}}</button>
<button *ngIf="!okDisabled"
class="uk-button md-btn md-btn-primary portal-button ignoreCommunityPanelBackground"
(click)="ok()">{{okButtonText}}</button>
</span>
<span [hidden]=!cancelButton>
<button class="uk-button md-btn uk-button-default uk-margin-small-left"
@ -149,7 +152,7 @@ export class AlertModal {
* ok method closes the modal and emits modalOutput.
*/
ok() {
if (!this.stayOpen){
if (!this.stayOpen) {
this.cancel();
}
if (!this.choice) {

Loading…
Cancel
Save