diff --git a/dashboard/divId/divIds-routing.module.ts b/dashboard/divId/divIds-routing.module.ts new file mode 100644 index 00000000..5b588ebc --- /dev/null +++ b/dashboard/divId/divIds-routing.module.ts @@ -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 { } diff --git a/dashboard/divId/divIds.component.html b/dashboard/divId/divIds.component.html new file mode 100644 index 00000000..c976200c --- /dev/null +++ b/dashboard/divId/divIds.component.html @@ -0,0 +1,163 @@ +
+
+ +
+
+ search +
+
+ +
+
+ + +
+ + +
+
+
+ + + +
+
+
+ +
+ +
+
+
+
+ +
+
+
+ + + + + + + + + + + + + + + + + + + +
NamePageActions
+ +
{{check.divId.name}}
+
+
+ {{page.name}}, +
+
+ +
+ + delete +
+
+
+
+ add +
+
+
+
No classes found
+
+
+
+
+
+
+
+
+
+ + + + +
+ +
+
+ + + + {{page.name}} + cancel + + + + + + {{page.name}} + + + + +
+
Select if this class exists in:
+ + + + + + + + + + + +
+ + + +
+ +
+ + + diff --git a/dashboard/divId/divIds.component.ts b/dashboard/divId/divIds.component.ts new file mode 100644 index 00000000..37bfea64 --- /dev/null +++ b/dashboard/divId/divIds.component.ts @@ -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; + @ViewChild('PageInput') pageInput: ElementRef; + 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({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 = 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(this.myForm.value, this.properties.adminToolsAPIURL).subscribe( + divId => { + this.divIdSavedSuccessfully(divId); + }, + error => this.handleUpdateError("System error creating class", error) + ); + } else { + this._helpContentService.updateDivId(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({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({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); + } +} diff --git a/dashboard/divId/divIds.module.ts b/dashboard/divId/divIds.module.ts new file mode 100644 index 00000000..9a60cd30 --- /dev/null +++ b/dashboard/divId/divIds.module.ts @@ -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 { } diff --git a/dashboard/entity/entities-routing.module.ts b/dashboard/entity/entities-routing.module.ts new file mode 100644 index 00000000..5d1c3d2d --- /dev/null +++ b/dashboard/entity/entities-routing.module.ts @@ -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 { } diff --git a/dashboard/entity/entities.component.html b/dashboard/entity/entities.component.html new file mode 100644 index 00000000..68af069e --- /dev/null +++ b/dashboard/entity/entities.component.html @@ -0,0 +1,139 @@ +
+ + +
+ +
+
+ search +
+
+ +
+
+
+ + +
+
+
+
+
+ + Disable an entity to hide it from community dashboard portal. +
+
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. +
+ +
+ + + + +
+
+
+ + + + + + + + + + + + + + + + + + +
NameChange statusActions
+ +
{{check.entity.name}}
+
+ + +
+ + delete +
+
+
+
+ add +
+
+
+
No entities found
+
+
+
+ +
+
+
+
+
+
+ + + + +
+ +
+
+ +
+
+ +
+
+ + + + diff --git a/dashboard/entity/entities.component.ts b/dashboard/entity/entities.component.ts new file mode 100644 index 00000000..12682a64 --- /dev/null +++ b/dashboard/entity/entities.component.ts @@ -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({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({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( + this.myForm.value, this.properties.adminToolsAPIURL).subscribe( + entity => { + this.entityUpdatedSuccessfully(entity); + }, + error => this.handleUpdateError('System error updating entity', error) + ); + } else { + this._helpContentService.saveEntity(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({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({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) + ); + } + } +} diff --git a/dashboard/entity/entities.module.ts b/dashboard/entity/entities.module.ts new file mode 100644 index 00000000..e19f1f01 --- /dev/null +++ b/dashboard/entity/entities.module.ts @@ -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 { } diff --git a/dashboard/portal/communities-routing.module.ts b/dashboard/portal/communities-routing.module.ts new file mode 100644 index 00000000..716cb942 --- /dev/null +++ b/dashboard/portal/communities-routing.module.ts @@ -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 { } diff --git a/dashboard/portal/communities.component.html b/dashboard/portal/communities.component.html new file mode 100644 index 00000000..ee3b42b4 --- /dev/null +++ b/dashboard/portal/communities.component.html @@ -0,0 +1,121 @@ +
+ + +
+ +
+
+ search +
+
+ +
+
+
+ + + +
+ +
+ + + +
+
+
+ +
+ +
+
+
+
+ +
+
+
+ + + + + + + + + + + + + + + + + + +
NameActions
+ +
{{check.community.name}}
+
+
+ + delete +
+
+
+
+ add +
+
+ + +
+
No communities found
+
+
+
+
+ + +
+
+ + +
+ + + +
+
+
+
+
+ +
+ +
+ + + +
diff --git a/dashboard/portal/communities.component.ts b/dashboard/portal/communities.component.ts new file mode 100644 index 00000000..fcf354c0 --- /dev/null +++ b/dashboard/portal/communities.component.ts @@ -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({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(this.portalFG.value, + this.properties.adminToolsAPIURL).subscribe( + community => { + this.communityUpdatedSuccessfully(community); + }, + error => this.handleUpdateError('System error updating portal', error) + ); + }else{ + this._helpContentService.saveCommunity(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(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({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({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; + } +} diff --git a/dashboard/portal/communities.module.ts b/dashboard/portal/communities.module.ts new file mode 100644 index 00000000..e58ea75c --- /dev/null +++ b/dashboard/portal/communities.module.ts @@ -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 { } diff --git a/services/adminToolService.module.ts b/services/adminToolService.module.ts new file mode 100644 index 00000000..1aafe365 --- /dev/null +++ b/services/adminToolService.module.ts @@ -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 { } diff --git a/services/help-content.service.ts b/services/help-content.service.ts new file mode 100644 index 00000000..f3dd7b13 --- /dev/null +++ b/services/help-content.service.ts @@ -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>(helpContentUrl + '/divFull'+parameters) + //.map(res => > res.json()) + .pipe(catchError(this.handleError)); + } + + updateDivId(divId: DivId, helpContentUrl:string) { + HelpContentService.removeNulls(divId); + + return this.http.post(helpContentUrl + '/div/update', JSON.stringify(divId), CustomOptions.getAuthOptionsWithBody()) + //.map(res => res.json()) + .pipe(catchError(this.handleError)); + } + + getDivId(divId: string, helpContentUrl:string) { + return this.http.get(helpContentUrl + '/div/'+divId) + //.map(res => res.json()) + .pipe(catchError(this.handleError)); + } + + getDivIdFull(divId: string, helpContentUrl:string) { + return this.http.get(helpContentUrl + '/divFull/'+divId) + //.map(res => res.json()) + .pipe(catchError(this.handleError)); + } + + saveDivId(divId: DivId, helpContentUrl:string) { + HelpContentService.removeNulls(divId); + + return this.http.post(helpContentUrl + '/div/save', JSON.stringify(divId), CustomOptions.getAuthOptionsWithBody()) + //.map(res => res.json()) + .pipe(catchError(this.handleError)); + } +/* + getCommunitiesWithDivId(helpContentUrl:string) { + return this.http.get(helpContentUrl + 'community?div=true') + .map(res => > res.json()) + .catch(this.handleError); + } +*/ + getCommunityPagesWithDivId(community_pid: string, helpContentUrl:string) { + return this.http.get>(helpContentUrl + '/community/'+community_pid+'/pages?div=true') + //.map(res => > res.json()) + .pipe(catchError(this.handleError)); + } + + getCommunityDivHelpContents(community_pid: string, helpContentUrl:string) { + return this.http.get>(helpContentUrl + '/divhelpcontent?community='+community_pid) + //.map(res => > res.json()) + .pipe(catchError(this.handleError)); + } + + getDivHelpContent(id : string, helpContentUrl:string) { + return this.http.get(helpContentUrl + '/divhelpcontent/' + id) + //.map(res => res.json()) + .pipe(catchError(this.handleError)); + } + + insertOrUpdateDivHelpContent(divHelpContent: DivHelpContent, helpContentUrl:string) { + HelpContentService.removeNulls(divHelpContent); + + return this.http.post(helpContentUrl + '/divhelpcontent', JSON.stringify(divHelpContent), CustomOptions.getAuthOptionsWithBody()) + //.map(res => res.json()) + .pipe(catchError(this.handleError)); + } + + deleteDivIds(ids : string[], helpContentUrl:string) { + return this.http.post(helpContentUrl + '/div/delete',JSON.stringify(ids), CustomOptions.getAuthOptionsWithBody()) + .pipe(catchError(this.handleError)); + } + + deleteDivHelpContents(ids : string[], helpContentUrl:string) { + return this.http.post(helpContentUrl + '/divhelpcontent/delete',JSON.stringify(ids), CustomOptions.getAuthOptionsWithBody()) + .pipe(catchError(this.handleError)); + } + + toggleDivHelpContents(ids : string[],status : boolean, helpContentUrl:string) { + + return this.http.post(helpContentUrl + '/divhelpcontent/toggle?status='+ status.toString(), JSON.stringify(ids), CustomOptions.getAuthOptionsWithBody()) + //.map( res => res.json()) + .pipe(catchError(this.handleError)); + } + + getPagesWithDivIds(community_pid: string, helpContentUrl:string) { + let parameters = (community_pid ? "?communityId="+community_pid : ""); + return this.http.get>(helpContentUrl + '/div/pages'+parameters) + //.map(res => >> res.json()) + .pipe(catchError(this.handleError)); + } + + getPages(helpContentUrl:string,pid:string,with_positions:boolean=null) { + let parameters: string = ""; + if(pid || with_positions == true || with_positions == false) { + parameters = "?"; + if(pid) { + parameters += "&pid="+pid; + } + if(with_positions == true || with_positions == false) { + parameters += "&with_positions="+with_positions; + } + } + return this.http.get>(helpContentUrl + '/page'+parameters) + //.map(res => > res.json()) + .pipe(catchError(this.handleError)); + } + + getPagesFull(helpContentUrl:string,pid:string) { + return this.http.get>(helpContentUrl + '/pageFull'+(pid?("?pid="+pid):"")) + //.map(res => > res.json()) + .pipe(catchError(this.handleError)); + } + + getPage(pageId:string, helpContentUrl:string) { + return this.http.get(helpContentUrl + '/page/'+pageId) + //.map(res => res.json()) + .pipe(catchError(this.handleError)); + } + + getPageByRoute(route:string, helpContentUrl:string) { + return this.http.get(helpContentUrl + '/page/?page_route='+route) + .pipe(catchError(this.handleError)); + } + + getCommunities( helpContentUrl:string) { + return this.http.get>(helpContentUrl + '/community') + //.map(res => > res.json()) + .pipe(catchError(this.handleError)); + } + + getCommunity(community_pid: string, helpContentUrl:string) { + return this.http.get(helpContentUrl + '/community/'+community_pid) + //.map(res => res.json()) + .pipe(catchError(this.handleError)); + } + + getCommunitiesFull( helpContentUrl:string) { + return this.http.get>(helpContentUrl + '/communityFull') + //.map(res => > res.json()) + .pipe(catchError(this.handleError)); + } + + getCommunityFull(community_pid: string, helpContentUrl:string) { + return this.http.get(helpContentUrl + '/communityFull/'+community_pid) + //.map(res => res.json()) + .pipe(catchError(this.handleError)); + } + + saveCommunity(community: Community, helpContentUrl:string) { + // let headers = new Headers({'Content-Type': 'application/json'}); + // let options = new RequestOptions({headers: headers}); + + HelpContentService.removeNulls(community); + + return this.http.post(helpContentUrl + '/community/save', JSON.stringify(community), CustomOptions.getAuthOptionsWithBody()) + //.map(res => res.json()) + .pipe(catchError(this.handleError)); + } + + updateCommunity(community: Community, helpContentUrl:string) { + // let headers = new Headers({'Content-Type': 'application/json'}); + // let options = new RequestOptions({headers: headers}); + + HelpContentService.removeNulls(community); + + return this.http.post(helpContentUrl + '/community/update', JSON.stringify(community), CustomOptions.getAuthOptionsWithBody()) + //.map(res => res.json()) + .pipe(catchError(this.handleError)); + } + + deleteCommunities(ids : string[], helpContentUrl:string) { + // let headers = new Headers({'Content-Type': 'application/json'}); + // let options = new RequestOptions({headers: headers}); + + return this.http.post(helpContentUrl + '/community/delete',JSON.stringify(ids), CustomOptions.getAuthOptionsWithBody()) + .pipe(catchError(this.handleError)); + } + + getCommunityPages(community_pid: string, params: string, helpContentUrl:string) { + return this.http.get>(helpContentUrl + '/community/'+community_pid+'/pages'+params) + //.map(res => > res.json()) + .pipe(catchError(this.handleError)); + } + + getEntities(helpContentUrl:string) { + return this.http.get>(helpContentUrl + '/entity') + //.map(res => > res.json()) + .pipe(catchError(this.handleError)); + } + + getCommunityEntities(community_pid: string, helpContentUrl:string) { + return this.http.get>(helpContentUrl + '/community/'+community_pid+'/entities') + //.map(res => > res.json()) + .pipe(catchError(this.handleError)); + } + + + saveEntity(entity: Entity, helpContentUrl:string) { + HelpContentService.removeNulls(entity); + + return this.http.post(helpContentUrl + '/entity/save', JSON.stringify(entity), CustomOptions.getAuthOptionsWithBody()) + //.map(res => res.json()) + .pipe(catchError(this.handleError)); + } + + updateEntity(entity: Entity, helpContentUrl:string) { + HelpContentService.removeNulls(entity); + + return this.http.post(helpContentUrl + '/entity/update', JSON.stringify(entity), CustomOptions.getAuthOptionsWithBody()) + //.map(res => res.json()) + .pipe(catchError(this.handleError)); + } + + // toggleEntity(selectedCommunityId: string, id : string,status : boolean) { + // let headers = new Headers({'Content-Type': 'application/json'}); + // let options = new RequestOptions({headers: headers}); + // + // return this.http.post(helpContentUrl + 'community/'+selectedCommunityId+'/entity/toggle?status='+ status.toString()+'&entityId='+id.toString(), options) + // .catch(this.handleError); + // } + + toggleEntities(selectedCommunityPid: string, ids : string[],status : boolean, helpContentUrl:string) { + + return this.http.post(helpContentUrl +'/community/'+selectedCommunityPid+ '/entity/toggle?status='+ status.toString(), JSON.stringify(ids), CustomOptions.getAuthOptionsWithBody()) + //.map( res => res.json()) + .pipe(catchError(this.handleError)); + } + + deleteEntities(ids : string[], helpContentUrl:string) { + return this.http.post(helpContentUrl + '/entity/delete',JSON.stringify(ids), CustomOptions.getAuthOptionsWithBody()) + .pipe(catchError(this.handleError)); + } + + + toggleEntityOfPage(pageId: string, entityId : string,status : boolean, helpContentUrl:string) { + return this.http.post(helpContentUrl + '/page/'+pageId+'/entity/toggle?status='+ status.toString()+'&entityId='+entityId.toString(), CustomOptions.getAuthOptionsWithBody()) + .pipe(catchError(this.handleError)); + } + + savePage(page: Page, helpContentUrl:string) { + HelpContentService.removeNulls(page); + + return this.http.post(helpContentUrl + '/page/save', JSON.stringify(page), CustomOptions.getAuthOptionsWithBody()) + //.map(res => res.json()) + .pipe(catchError(this.handleError)); + } + + updatePage(page: Page, helpContentUrl:string) { + + HelpContentService.removeNulls(page); + + return this.http.post(helpContentUrl + '/page/update', JSON.stringify(page), CustomOptions.getAuthOptionsWithBody()) + //.map(res => res.json()) + .pipe(catchError(this.handleError)); + } + + togglePages(selectedCommunityPid: string, ids : string[],status : boolean, helpContentUrl:string) { + + return this.http.post(helpContentUrl + '/community/'+selectedCommunityPid+'/page/toggle?status='+ status.toString(),JSON.stringify(ids), CustomOptions.getAuthOptionsWithBody()) + .pipe(catchError(this.handleError)); + } + + deletePages(ids : string[], helpContentUrl:string) { + + return this.http.post(helpContentUrl + '/page/delete',JSON.stringify(ids), CustomOptions.getAuthOptionsWithBody()) + .pipe(catchError(this.handleError)); + } + + getPageHelpContents(helpContentUrl:string) { + return this.http.get>(helpContentUrl + 'pagehelpcontent') + //.map(res => > res.json()) + .pipe(catchError(this.handleError)); + } + + getCommunityPageHelpContents(community_pid: string, helpContentUrl:string) { + return this.http.get>(helpContentUrl + '/pagehelpcontent?community='+community_pid) + //.map(res => > res.json()) + .pipe(catchError(this.handleError)); + } + + getPageHelpContent(id : string, helpContentUrl:string) { + return this.http.get(helpContentUrl + '/pagehelpcontent/' + id) + //.map(res => res.json()) + .pipe(catchError(this.handleError)); + } + + savePageHelpContent(pageHelpContent: PageHelpContent, helpContentUrl:string) { + HelpContentService.removeNulls(pageHelpContent); + + return this.http.post(helpContentUrl + '/pagehelpcontent/save', JSON.stringify(pageHelpContent), CustomOptions.getAuthOptionsWithBody()) + //.map(res => res.json()) + .pipe(catchError(this.handleError)); + } + + updatePageHelpContent(pageHelpContent: PageHelpContent, helpContentUrl:string) { + HelpContentService.removeNulls(pageHelpContent); + + return this.http.post(helpContentUrl + '/pagehelpcontent/update', JSON.stringify(pageHelpContent), CustomOptions.getAuthOptionsWithBody()) + //.map(res => res.json()) + .pipe(catchError(this.handleError)); + } + + deletePageHelpContents(ids : string[], helpContentUrl:string) { + return this.http.post(helpContentUrl + 'pagehelpcontent/delete',JSON.stringify(ids), CustomOptions.getAuthOptionsWithBody()) + .pipe(catchError(this.handleError)); + } + + togglePageHelpContents(ids : string[],status : boolean, helpContentUrl:string) { + return this.http.post(helpContentUrl + '/pagehelpcontent/toggle?status='+ status.toString(), JSON.stringify(ids), CustomOptions.getAuthOptionsWithBody()) + //.map( res => res.json()) + .pipe(catchError(this.handleError)); + } + + private handleError(error: HttpErrorResponse) { + // in a real world app, we may send the error to some remote logging infrastructure + // instead of just logging it to the console + console.error(error); + return Observable.throw(error.error || 'Server error'); + } + + // getDataProviders() { + // return this.http.get('https://beta.services.openaire.eu/search/v2/api/datasources?format=json').map(res => res.json()).map(res => res.results).do(res => {console.log(res)}).catch(this.handleError); + // } + + getCommunityStatistics(apiUrl: string, communityId: string): Observable { + const url = `${apiUrl}communities/${communityId}`; + //console.log(`getting statistics summary from: ${url}`); + return this.http.get(url) + //.map(res => res.json()) + .pipe(map(res => res['statistics'])); + } + + getCommunityAdminStatisticsChoices(apiUrl: string, communityId: string): Observable { + const url = `${apiUrl}/statistics/${communityId}`; + //console.log(`getting admin choices for statistics from: ${url}`); + return this.http.get(url) + //.map(stats => stats.json()) + .pipe(catchError(this.handleError)); + } + + postCommunityAdminStatisticsChoices(apiUrl: string, + communityId: string, + entity: string, + chartsOrNumbers: string, + title: string, + status: boolean, + monitor: boolean): Observable { + const url = `${apiUrl}/statistics/${communityId}/${entity}/${chartsOrNumbers}?status=${status.toString()}&monitor=${monitor.toString()}`; + //console.log(`getting admin choices for statistics from: ${url}`); + + return this.http.post(url, title, CustomOptions.getAuthOptionsWithBody()) + //.map(stats => stats.json()) + .pipe(catchError(this.handleError)); + } +} diff --git a/utils/entities/adminTool/community.ts b/utils/entities/adminTool/community.ts new file mode 100644 index 00000000..9dd3177c --- /dev/null +++ b/utils/entities/adminTool/community.ts @@ -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; +} diff --git a/utils/entities/adminTool/div-help-content.ts b/utils/entities/adminTool/div-help-content.ts new file mode 100644 index 00000000..ed948a1e --- /dev/null +++ b/utils/entities/adminTool/div-help-content.ts @@ -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; +} diff --git a/utils/entities/adminTool/divId.ts b/utils/entities/adminTool/divId.ts new file mode 100644 index 00000000..3cca9078 --- /dev/null +++ b/utils/entities/adminTool/divId.ts @@ -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; +} diff --git a/utils/entities/adminTool/entity.ts b/utils/entities/adminTool/entity.ts new file mode 100644 index 00000000..a3e34e7f --- /dev/null +++ b/utils/entities/adminTool/entity.ts @@ -0,0 +1,11 @@ +export class Entity { + _id: string; + pid: string; + name: string; + isEnabled: boolean; +} + +export interface CheckEntity { + entity: Entity; + checked: boolean; +} diff --git a/utils/entities/adminTool/html-page-content.ts b/utils/entities/adminTool/html-page-content.ts new file mode 100644 index 00000000..40643561 --- /dev/null +++ b/utils/entities/adminTool/html-page-content.ts @@ -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; +} diff --git a/utils/entities/adminTool/page-help-content.ts b/utils/entities/adminTool/page-help-content.ts new file mode 100644 index 00000000..8fe047be --- /dev/null +++ b/utils/entities/adminTool/page-help-content.ts @@ -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; +} diff --git a/utils/entities/adminTool/page.ts b/utils/entities/adminTool/page.ts new file mode 100644 index 00000000..6768486e --- /dev/null +++ b/utils/entities/adminTool/page.ts @@ -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; +} diff --git a/utils/modal/alert.ts b/utils/modal/alert.ts index 9e3a3804..a751b536 100644 --- a/utils/modal/alert.ts +++ b/utils/modal/alert.ts @@ -27,7 +27,10 @@ declare var UIkit: any;
- + +