diff --git a/app/app.component.html b/app/app.component.html index 7c51f30..ceac8e6 100644 --- a/app/app.component.html +++ b/app/app.component.html @@ -47,7 +47,18 @@ +
  • + Manage Predefined Classes for Contents + +
  • Manage Pages @@ -89,6 +100,12 @@ Page Contents
  • +
  • + + + Class Contents + +
  • diff --git a/app/app.module.ts b/app/app.module.ts index a12e92b..1b5627a 100644 --- a/app/app.module.ts +++ b/app/app.module.ts @@ -32,7 +32,14 @@ import { CommunityFormComponent } from './pages/community/community-form.compone import { CommunityEditFormComponent } from './pages/community/community-edit-form.component'; import { EntitiesComponent } from "./pages/helpcontent/entities.component"; import { EntityFormComponent } from "./pages/helpcontent/entity-form.component"; +import { DivIdsComponent } from "./pages/divId/divIds.component"; +import { DivIdFormComponent } from "./pages/divId/divId-form.component"; +import { DivHelpContentsComponent } from "./pages/divhelpcontent/div-help-contents.component"; +import { NewDivHelpContentComponent } from "./pages/divhelpcontent/new-div-help-content.component"; +import { DivContentFormComponent } from "./pages/divhelpcontent/div-help-content-form.component"; +import { EditDivHelpContentComponent } from "./pages/divhelpcontent/edit-div-help-content.component"; import {BottomModule, FeedbackModule, NavigationBarModule, CookieLawModule} from 'ng-openaire-library'; + //, , ErrorModule CookieLawModule @NgModule({ imports: [ @@ -69,7 +76,13 @@ import {BottomModule, FeedbackModule, NavigationBarModule, CookieLawModule} from CommunityFormComponent, CommunityEditFormComponent, EntitiesComponent, - EntityFormComponent + EntityFormComponent, + DivIdsComponent, + DivIdFormComponent, + DivHelpContentsComponent, + NewDivHelpContentComponent, + EditDivHelpContentComponent, + DivContentFormComponent ], providers: [ FAQService, diff --git a/app/app.routing.ts b/app/app.routing.ts index 155e0c0..ff2e8a2 100644 --- a/app/app.routing.ts +++ b/app/app.routing.ts @@ -14,7 +14,10 @@ import { PagesComponent } from "./pages/helpcontent/pages.component"; import { PageHelpContentsComponent } from "./pages/helpcontent/page-help-contents.component"; import { NewPageHelpContentComponent } from "./pages/helpcontent/new-page-help-content.component"; import { EditPageHelpContentComponent } from "./pages/helpcontent/edit-page-help-content.component"; - +import { DivIdsComponent } from "./pages/divId/divIds.component"; +import { DivHelpContentsComponent } from "./pages/divhelpcontent/div-help-contents.component"; +import { NewDivHelpContentComponent } from "./pages/divhelpcontent/new-div-help-content.component"; +import { EditDivHelpContentComponent } from "./pages/divhelpcontent/edit-div-help-content.component"; const appRoutes: Routes = [ { @@ -46,6 +49,10 @@ const appRoutes: Routes = [ path: 'entities', component: EntitiesComponent, }, + { + path: 'classes', + component: DivIdsComponent, + }, { path: 'pages', component: PagesComponent, @@ -62,6 +69,18 @@ const appRoutes: Routes = [ //path: 'pageContents/edit/:id', path: 'pageContents/edit', component: EditPageHelpContentComponent, + }, + { + path: 'classContents', + component: DivHelpContentsComponent, + }, + { + path: 'classContents/new', + component: NewDivHelpContentComponent, + }, + { + path: 'classContents/edit', + component: EditDivHelpContentComponent, } ]; diff --git a/app/domain/div-help-content.ts b/app/domain/div-help-content.ts new file mode 100644 index 0000000..a013212 --- /dev/null +++ b/app/domain/div-help-content.ts @@ -0,0 +1,19 @@ +import { DivId } from "./divId"; + +export interface DivHelpContent { + _id: string; + divId: DivId | string; + content: string; + isActive: boolean; +} + +export interface CheckDivHelpContent { + divHelpContent : DivHelpContent; + checked : boolean; +} + +export interface DivHelpContentFilterOptions { + id : string; + active : Boolean; + text : RegExp; +} diff --git a/app/domain/divId.ts b/app/domain/divId.ts new file mode 100644 index 0000000..823dce4 --- /dev/null +++ b/app/domain/divId.ts @@ -0,0 +1,14 @@ +import {Page} from './page'; +import {Community} from './community'; + +export interface DivId { + _id: string; + name: string; + page: string | Page; + community: string | Community; +} + +export interface CheckDivId { + divId : DivId; + checked : boolean; +} diff --git a/app/domain/page-help-content.ts b/app/domain/page-help-content.ts index 086c800..d9c580f 100644 --- a/app/domain/page-help-content.ts +++ b/app/domain/page-help-content.ts @@ -12,6 +12,7 @@ export interface PageHelpContent { order: number; content: string; isActive: boolean; + isPriorTo: boolean; } export interface CheckPageHelpContent { diff --git a/app/pages/community/communities.component.html b/app/pages/community/communities.component.html index 4922ca3..999b188 100644 --- a/app/pages/community/communities.component.html +++ b/app/pages/community/communities.component.html @@ -5,7 +5,7 @@
    Communities
    New Community @@ -22,7 +22,7 @@
    - +
    • Delete
    • diff --git a/app/pages/divId/divId-form.component.html b/app/pages/divId/divId-form.component.html new file mode 100644 index 0000000..f137f13 --- /dev/null +++ b/app/pages/divId/divId-form.component.html @@ -0,0 +1,13 @@ +
      +
      + + +
      +
      + + +
      + +
      diff --git a/app/pages/divId/divId-form.component.ts b/app/pages/divId/divId-form.component.ts new file mode 100644 index 0000000..a73588a --- /dev/null +++ b/app/pages/divId/divId-form.component.ts @@ -0,0 +1,53 @@ +import {Component, OnInit, Input} from '@angular/core'; +import {FormGroup, FormArray, FormBuilder, Validators} from "@angular/forms"; +import { HelpContentService } from "../../services/help-content.service"; +import { Page } from "../../domain/page"; + +@Component({ + selector: 'divId-form', + templateUrl: './divId-form.component.html', +}) + +export class DivIdFormComponent implements OnInit{ + @Input('group') + myForm: FormGroup; + @Input('communityPid') + communityPid: string; + @Input('pageId') + pageId: string; + @Input('availablePages') + availablePages : Page[] = []; + + public errorMessage: string; + + constructor(public _fb: FormBuilder, private _helpContentService: HelpContentService){} + + ngOnInit(): void { + + } + + public get form() { + return this._fb.group({ + _id : '', + name : ['', Validators.required], + page : [this.pageId,Validators.required], + community : this.communityPid, + }); + } + + public reset() { + this.myForm.patchValue({ + _id : '', + name : '', + page: '', + community: this.communityPid + }); + } + + handleError(message: string, error) { + if(error == null) { + this.reset(); + } + this.errorMessage = message + ' (Server responded: ' + error + ')'; + } +} diff --git a/app/pages/divId/divIds.component.html b/app/pages/divId/divIds.component.html new file mode 100644 index 0000000..b740edf --- /dev/null +++ b/app/pages/divId/divIds.component.html @@ -0,0 +1,104 @@ +
      + + + +
      +
      +
      + + + + +
      +
      +
      + +
      + +
      +
      +
      +
      + +
      +
      +
      +
      +
      + +
      + + + + + + + + + + + + + + + + + + +
      NameCommunityPage
      + +
      {{check.divId.name}}
      +
      +
      {{check.divId.community.name}}
      +
      +
      {{check.divId.page.name}}
      +
      +
      + + +
      +
      + +
      +
      No classes found
      +
      +
      +
      +
      +
      +
      +
      +
      +
      + + + + + + + + + + Are you sure you want to delete the selected class(-es)? + diff --git a/app/pages/divId/divIds.component.ts b/app/pages/divId/divIds.component.ts new file mode 100644 index 0000000..adcd43c --- /dev/null +++ b/app/pages/divId/divIds.component.ts @@ -0,0 +1,198 @@ +import { Component, ViewChild, OnInit } from '@angular/core'; +import { ActivatedRoute } from "@angular/router"; +import { HelpContentService } from "../../services/help-content.service"; +import { FormGroup } from "@angular/forms"; +import { ModalFormComponent } from "../modal-form.component"; +import { DeleteConfirmationDialogComponent } from "../delete-confirmation-dialog.component"; +import { DivIdFormComponent } from "./divId-form.component"; +import { CheckDivId, DivId } from "../../domain/divId"; +import { Community } from "../../domain/community"; +import { Page } from "../../domain/page"; + +@Component({ + selector: 'divIds', + templateUrl: './divIds.component.html', +}) + +export class DivIdsComponent implements OnInit { + + @ViewChild(ModalFormComponent) + @ViewChild('saveModal') + public modal:ModalFormComponent; + + @ViewChild('updateModal') + public updateModal:ModalFormComponent; + + @ViewChild('deleteConfirmationModal') + public deleteConfirmationModal : DeleteConfirmationDialogComponent; + + @ViewChild(DivIdFormComponent) + public formComponent : DivIdFormComponent; + + public checkboxes : CheckDivId[] = []; + + public divIds : DivId[] = []; + + public errorMessage: string; + + public formGroup : FormGroup; + + private searchText : RegExp = new RegExp(''); + + public selectedCommunityPid: string; + public communities: Community[] = []; + public pages: Page[] = []; + + ngOnInit() { + this.formGroup = this.formComponent.form; + this.route.queryParams.subscribe(params => { + // if(params['community']) { + // this.getCommunity(params['community']); + // } else { + this.getCommunities(); + //} + }); + } + + constructor(private route: ActivatedRoute, private _helpContentService: HelpContentService) {} +/* + getCommunity(community_pid: string) { + let self = this; + this._helpContentService.getCommunityFull(community_pid).subscribe( + community => { + self.communities = [community]; + this.checkboxes.push({community : community, checked : false}); + }, + error => this.handleError('System error retrieving communities', error)); + } +*/ + getCommunities() { + let self = this; + this._helpContentService.getCommunities().subscribe( + communities => { + self.communities = communities; + self.selectedCommunityPid = self.communities[0].pid; + self.getPages(self.selectedCommunityPid); + self.getDivIds(self.selectedCommunityPid); + self.formGroup.patchValue({ + community: self.selectedCommunityPid + }); + }, + error => this.handleError('System error retrieving communities', error)); + } + + getPages(community_pid: string) { + this._helpContentService.getCommunityPages(community_pid).subscribe( + pages => this.pages = pages, + error => this.handleError('System error retrieving pages', error)); + } + + getDivIds(community_pid: string) { + let self = this; + this._helpContentService.getDivIdsFull(community_pid, null).subscribe( + divIds => { + self.divIds = divIds; + + self.checkboxes = []; + divIds.forEach(_ => { + self.checkboxes.push({divId : _, checked : 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) { + console.info("applyCheck "+flag); + 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.deleteConfirmationModal.ids = [id]; + this.deleteConfirmationModal.showModal(); + } + + public confirmDeleteSelectedDivIds() { + this.deleteConfirmationModal.ids = this.getSelectedDivIds(); + this.deleteConfirmationModal.showModal(); + } + + public confirmedDeleteDivIds(ids : string[]) { + this._helpContentService.deleteDivIds(ids).subscribe( + _ => this.deleteDivIdsFromArray(ids), + error => this.handleError('System error deleting the selected classes', error) + ); + } + + public editDivId(i : number) { + let divId : DivId = this.checkboxes[i].divId; + this.formGroup.patchValue(divId); + this.updateModal.showModal(); + } + + public divIdSavedSuccessfully(divId: DivId) { + this.checkboxes.push({divId : divId, checked : false}); + console.info("checkboxes length: "+this.checkboxes.length); + 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() == '' || (/*community.route + ' ' +*/divId.name).match(this.searchText) != null; + return textFlag; + } + + public filterByCommunity(event: any) { + this.selectedCommunityPid = event.target.value; + this.formGroup.patchValue({ + community: this.selectedCommunityPid + }); + this.applyCommunityFilter(this.selectedCommunityPid); + } + + public applyCommunityFilter(community_pid: string) { + this.getDivIds(community_pid); + this.getPages(community_pid); + } + + handleError(message: string, error) { + if(error == null) { + this.formComponent.reset(); + } + this.errorMessage = message + ' (Server responded: ' + error + ')'; + } +} diff --git a/app/pages/divhelpcontent/div-help-content-form.component.html b/app/pages/divhelpcontent/div-help-content-form.component.html new file mode 100644 index 0000000..e34e435 --- /dev/null +++ b/app/pages/divhelpcontent/div-help-content-form.component.html @@ -0,0 +1,49 @@ +
      {{errorMessage}}
      +
      +
      + + + + + + + +
      +
      + +
      + + + + + + + + +
      + + +
      +
      + + +
      + +
      + + + + diff --git a/app/pages/divhelpcontent/div-help-content-form.component.ts b/app/pages/divhelpcontent/div-help-content-form.component.ts new file mode 100644 index 0000000..0c834bb --- /dev/null +++ b/app/pages/divhelpcontent/div-help-content-form.component.ts @@ -0,0 +1,86 @@ +import { Component, OnInit, Input } from '@angular/core'; +import { FormGroup, FormBuilder, Validators } from "@angular/forms"; +import { Page } from "../../domain/page"; +import { DivId } from "../../domain/divId"; +import { HelpContentService } from "../../services/help-content.service"; + + +@Component({ + selector: 'div-content-form', + templateUrl: './div-help-content-form.component.html', +}) + +export class DivContentFormComponent implements OnInit{ + + @Input('group') + myForm: FormGroup; + @Input('communityPid') + communityPid: string; + @Input('pageId') + pageId: string; + + showPageSelect: boolean = true; + + private availablePages : Page[] = []; + private availableDivs : DivId[] = []; + + private errorMessage: string; + + private ckeditorContent : string; + + constructor(private _fb: FormBuilder, private _helpContentService: HelpContentService){} + + ngOnInit() { + this.myForm = this.form; + + if(this.pageId) { + this.showPageSelect = false; + this.getDivs(this.pageId); + } else { + this._helpContentService.getCommunityPagesWithDivId(this.communityPid).subscribe( + pages => this.availablePages = pages, + error => this.handleError('System error retrieving pages', error)); + } + } + + public pageSelected(event) { + this.getDivs(event.target.value); + } + + public getDivs(pageId: string) { + console.info(pageId); + this._helpContentService.getDivIdsFull(this.communityPid, pageId).subscribe( + divs => { + this.availableDivs = divs; + this.pageId = pageId; + }, + error => this.handleError('System error retrieving pages', error)); + } + + public selectedDiv(event) { + console.info(event.target.value); + } + + public get form() { + return this._fb.group({ + divId: ['', Validators.required], + content: ['', Validators.required], + isActive: true, + _id : '', + }); + } + + public reset() { + this.myForm.patchValue({ + divId: '', + content: '', + isActive: true, + _id : '' + }); + this.myForm.markAsPristine(); + } + + handleError(message: string, error) { + this.errorMessage = message + ' (Server responded: ' + error + ')'; + } +} diff --git a/app/pages/divhelpcontent/div-help-contents.component.html b/app/pages/divhelpcontent/div-help-contents.component.html new file mode 100644 index 0000000..97154a9 --- /dev/null +++ b/app/pages/divhelpcontent/div-help-contents.component.html @@ -0,0 +1,138 @@ +
      + + + +
      +
      +
      + + + + +
      +
      +
      + + +
      +
      +
      + +
      +
      +
      +
      + +
      + +
      +
      + +
      + + Filter page contents: + + + + + + + + + + + + + + + + + + + + + + + + + +
      PageCommunityClassContentActiveActions
      + +
      {{check.divHelpContent.divId.page.name}}
      +
      +
      {{check.divHelpContent.divId.community.name}}
      +
      +
      {{check.divHelpContent.divId.name}}
      +
      +
      {{check.divHelpContent.content}}
      +
      +
      + +
      +
      + +
      +
      +
      + + +
      +
      + +
      +
      No page contents found
      +
      +
      +
      +
      + Go back to {{page.type}} pages +
      +
      +
      +
      +
      + + + Are you sure you want to delete the selected page content(s)? + diff --git a/app/pages/divhelpcontent/div-help-contents.component.ts b/app/pages/divhelpcontent/div-help-contents.component.ts new file mode 100644 index 0000000..7ba9741 --- /dev/null +++ b/app/pages/divhelpcontent/div-help-contents.component.ts @@ -0,0 +1,308 @@ +import { Component, ViewChild, OnInit } from '@angular/core'; +import { Router } from "@angular/router"; +import { FormGroup } from "@angular/forms"; +import { ActivatedRoute } from "@angular/router"; +import { DeleteConfirmationDialogComponent } from "../delete-confirmation-dialog.component"; +import { HelpContentService } from "../../services/help-content.service"; +import { DivHelpContent, CheckDivHelpContent, DivHelpContentFilterOptions } from "../../domain/div-help-content"; +import { Page } from "../../domain/page"; +import { Community } from "../../domain/community"; +import { DivId } from "../../domain/divId"; + +@Component({ + selector: 'div-help-contents', + templateUrl: './div-help-contents.component.html', +}) + +export class DivHelpContentsComponent implements OnInit { + + // @ViewChild(ModalFormComponent) + // @ViewChild('saveModal') + // public modal:ModalFormComponent; + // + // @ViewChild('updateModal') + // public updateModal:ModalFormComponent; + // + // @ViewChild(PageHelpContentsFormComponent) + // public formComponent : PageHelpContentsFormComponent; + + @ViewChild('deleteConfirmationModal') + public deleteConfirmationModal : DeleteConfirmationDialogComponent; + + public checkboxes : CheckDivHelpContent[] = []; + + public divHelpContents : DivHelpContent[] = []; + + public errorMessage: string; + + public formGroup : FormGroup; + + public pages: Page[]; + + public checkboxAll : boolean = false; + + public filters : DivHelpContentFilterOptions = {id : '', active : null, text : new RegExp('')}; + + public counter = {all : 0, active : 0, inactive : 0}; + + public communities: Community[] = []; + + public selectedCommunityPid: string; + + public selectedPageId: string; + + public community: Community; + + public page: Page; + + ngOnInit() { + this.route.queryParams.subscribe(params => { + + this.selectedCommunityPid = params['community']; + this.selectedPageId = params['page']; + + if(this.selectedCommunityPid && this.selectedPageId) { + this.getDivHelpContents(this.selectedCommunityPid); + this.getPage(this.selectedPageId); + this.getCommunity(this.selectedCommunityPid); + } else { + this.selectedPageId = ""; + this.getCommunities(); + } + }); + // this.formGroup = this.formComponent.form; + } + + constructor(private route: ActivatedRoute, private _helpService: HelpContentService, private router : Router) {} + + getPage(pageId: string) { + let self = this; + this._helpService.getPage(pageId).subscribe( + page => { + self.page = page; + } + ); + } + + getCommunity(communityPid: string) { + let self = this; + this._helpService.getCommunity(communityPid).subscribe( + community => { + self.community = community; + } + ); + } + + getCommunities() { + let self = this; + this._helpService.getCommunitiesWithDivId().subscribe( + communities => { + self.communities = communities; + self.selectedCommunityPid = self.communities[0].pid; + this.getPages(self.selectedCommunityPid); + this.getDivHelpContents(self.selectedCommunityPid); + }, + error => this.handleError('System error retrieving communities', error)); + } + + getPages(community_pid: string) { + this._helpService.getCommunityPagesWithDivId(community_pid).subscribe( + pages => this.pages = pages, + error => this.handleError('System error retrieving pages', error)); + } + + public countDivHelpContents() { + this.counter = {all : 0, active : 0, inactive : 0}; + let filter = Object.assign({},this.filters); + filter.active = null; + this.divHelpContents.forEach(_ => { + if(this.filterDivHelpContent(_,filter)){ + if (_.isActive==true) this.counter.active++; + else this.counter.inactive++ + } + }); + this.counter.all = this.counter.active + this.counter.inactive; + } + + getDivHelpContents(community_pid: string) { + let self = this; + this._helpService.getCommunityDivHelpContents(community_pid).subscribe( + divHelpContents => { + self.divHelpContents = divHelpContents as Array; + self.counter.all = self.divHelpContents.length; + self.checkboxes = []; + /*self.pageHelpContents.forEach(_ => { + let page: Page = _.page as Page; + if(!self.selectedPageId || (page._id == self.selectedPageId)) { + self.checkboxes.push({pageHelpContent : _, checked : false}); + } + });*/ + for (let i = self.divHelpContents.length - 1; i >= 0; i -= 1) { + let divId: DivId = self.divHelpContents[i].divId as DivId; + let page: Page = divId.page as Page; + if(!self.selectedPageId || (page._id == self.selectedPageId)) { + self.checkboxes.push({divHelpContent : self.divHelpContents[i], checked : false}); + } else { + self.divHelpContents.splice(i, 1); + } + } + + self.countDivHelpContents(); + }, + error => this.handleError('System error retrieving page contents', error)); + } + + // public showModal():void { + // this.modal.showModal(); + // } + + public toggleCheckBoxes(event) { + this.checkboxes.forEach(_ => _.checked = event.target.checked); + this.checkboxAll = event.target.checked; + } + + public applyCheck(flag : boolean) { + this.checkboxes.forEach(_ => _.checked = flag); + this.checkboxAll = false; + } + + public getSelectedDivHelpContents() : string[] { + return this.checkboxes.filter(divHelpContent => divHelpContent.checked == true) + .map(checkedDivHelpContent => checkedDivHelpContent.divHelpContent).map(res => res._id); + } + + public confirmDeleteDivHelpContent(id : string) { + this.deleteConfirmationModal.ids = [id]; + this.deleteConfirmationModal.showModal(); + } + + public confirmDeleteSelectedDivHelpContents() { + this.deleteConfirmationModal.ids = this.getSelectedDivHelpContents(); + this.deleteConfirmationModal.showModal(); + } + + public confirmedDeleteDivHelpContents(ids : string[]) { + this._helpService.deleteDivHelpContents(ids).subscribe( + _ => this.deleteDivHelpContentsFromArray(ids), + error => this.handleError('System error deleting the selected class content(s)', error) + ); + } + + private deleteDivHelpContentsFromArray(ids : string[]) : void { + for(let id of ids) { + let iqc = this.checkboxes.findIndex(_ => _.divHelpContent._id == id); + let iq = this.divHelpContents.findIndex(_ => _._id == id); + this.checkboxes.splice(iqc, 1); + this.divHelpContents.splice(iqc, 1); + } + this.countDivHelpContents(); + } + + public editDivHelpContent(id : string) { + //this.router.navigate(['/pageContents/edit/', _id]); + if(this.selectedPageId) { + this.router.navigate( ['/classContents/edit/'], { queryParams: { "classContentId": id, "community": this.selectedCommunityPid, "pageId": this.selectedPageId } } ); + } else { + this.router.navigate( ['/classContents/edit/'], { queryParams: { "classContentId": id, "community": this.selectedCommunityPid } } ); + } + } + + public toggleDivHelpContents(status : boolean, ids : string[]) { + this._helpService.toggleDivHelpContents(ids,status).subscribe( + () => { + for(let id of ids) { + let i = this.checkboxes.findIndex(_ => _.divHelpContent._id == id); + console.info(i); + this.checkboxes[i].divHelpContent.isActive=status; + } + this.countDivHelpContents(); + this.applyCheck(false); + }, + error => this.handleError('System error changing the status of the selected page content(s)', error) + ); + } + + public saveDivHelpContent(data : any):void { + console.log(data); + + this._helpService.insertOrUpdateDivHelpContent(data).subscribe( + divHelpContent => this.divHelpContentSavedSuccessfully(divHelpContent), + error => this.handleError('System error saving the specified help content', error) + ); + + } + + public divHelpContentSavedSuccessfully(divHelpContent: DivHelpContent) { + this.checkboxes.push({divHelpContent : divHelpContent, checked : false}); + this.divHelpContents.push(divHelpContent); + this.applyCheck(false); + this.countDivHelpContents(); + } + + public divHelpContentUpdatedSuccessfully(divHelpContent : DivHelpContent) { + this.checkboxes.find(checkItem => checkItem.divHelpContent._id==divHelpContent._id).divHelpContent = divHelpContent; + let index = this.divHelpContents.findIndex(checkItem => checkItem._id==divHelpContent._id); + this.divHelpContents[index] = divHelpContent; + this.applyCheck(false); + this.countDivHelpContents(); + } + + + public filterDivHelpContent(divHelpContent : DivHelpContent, filters : DivHelpContentFilterOptions) : boolean { + let divId: DivId = divHelpContent.divId as DivId; + let idFlag = filters.id == '' || (divId.page)._id == filters.id; + let activeFlag = filters.active == null || divHelpContent.isActive == filters.active; + let textFlag = filters.text.toString() == '' || (divHelpContent.content).match(filters.text) != null; + return idFlag && activeFlag && textFlag; + } + + public applyFilter() { + this.checkboxes = []; + this.divHelpContents.filter(item => this.filterDivHelpContent(item,this.filters)).forEach( + _ => this.checkboxes.push({divHelpContent: _, checked: false}) + ); + this.countDivHelpContents(); + } + + public filterByPage(event: any) { + this.filters.id = event.target.value; + this.applyFilter(); + } + + public displayAllDivHelpContents() { + this.filters.active = null; + this.applyFilter(); + } + + public displayActiveDivHelpContents() { + this.filters.active = true; + this.applyFilter(); + } + + public filterBySearch(text : string) { + this.filters.text = new RegExp(text, "i"); + this.applyFilter(); + } + + public displayInactiveDivHelpContents() { + this.filters.active = false; + this.applyFilter(); + } + + handleError(message: string, error) { + if(error == null) { + // this.formComponent.reset(); + } + this.errorMessage = message + ' (Server responded: ' + error + ')'; + } + + public filterByCommunity(event: any) { + this.selectedCommunityPid = event.target.value; + this.applyCommunityFilter(this.selectedCommunityPid); + } + + public applyCommunityFilter(community_pid: string) { + this.getPages(community_pid); + this.getDivHelpContents(community_pid); + } +} diff --git a/app/pages/divhelpcontent/edit-div-help-content.component.html b/app/pages/divhelpcontent/edit-div-help-content.component.html new file mode 100644 index 0000000..04fb1b3 --- /dev/null +++ b/app/pages/divhelpcontent/edit-div-help-content.component.html @@ -0,0 +1,21 @@ +
      +
      + + +
      + +
      +
      {{errorMessage}}
      + + + +
      +
      +
      +
      diff --git a/app/pages/divhelpcontent/edit-div-help-content.component.ts b/app/pages/divhelpcontent/edit-div-help-content.component.ts new file mode 100644 index 0000000..fabe092 --- /dev/null +++ b/app/pages/divhelpcontent/edit-div-help-content.component.ts @@ -0,0 +1,99 @@ +import { Component, ViewChild, OnInit, OnDestroy } from '@angular/core'; +import { DivContentFormComponent } from "./div-help-content-form.component"; +import { Subscription } from "rxjs/Subscription"; +import { HelpContentService } from "../../services/help-content.service"; +import { DivHelpContent } from "../../domain/div-help-content"; +import { ActivatedRoute, Router } from "@angular/router"; + +@Component({ + selector: 'edit-div-help-content', + templateUrl: 'edit-div-help-content.component.html', +}) + +export class EditDivHelpContentComponent implements OnInit, OnDestroy{ + + @ViewChild(DivContentFormComponent) + public formComponent : DivContentFormComponent; + + private communityPid: string; + + private pageId: string; + + private sub: Subscription; + + private divHelpContent: DivHelpContent; + + private errorMessage : string = null; + + constructor( + private route: ActivatedRoute, + private router: Router, + private _helpContentService: HelpContentService) {} + + ngOnInit() { + + this.sub = this.route.queryParams.subscribe(params => { + //let id = params['id']; + let divContentId = params['classContentId']; + this.communityPid = params['community']; + this.pageId = params['pageId']; + this._helpContentService.getDivHelpContent(divContentId as string).subscribe( + divHelpContent => this.updateForm(divHelpContent), + error => this.handleError('System error retrieving class help content', error)); + }); + } + ngOnDestroy() { + this.sub.unsubscribe(); + } + + handleError(message: string, error) { + this.errorMessage = message + ' (Server responded: ' + error + ')'; + } + + getDivId(divId: string) { + this._helpContentService.getDivId(divId).subscribe( + divId => { + this.formComponent.pageId = divId.page; + this.formComponent.getDivs(this.formComponent.pageId); + }, + error => this.handleError('System error retrieving class', error) + ); + } + + private updateForm(divHelpContent : DivHelpContent) { + this.divHelpContent = divHelpContent; + console.info(divHelpContent); + + if(!this.pageId) { + this.getDivId(divHelpContent.divId as string); + } + this.formComponent.myForm.patchValue((divHelpContent)); + // console.log("patching",pageHelpContent); + } + + private saveCustom() { + if(this.formComponent.myForm.valid) { + let divHelpContent : DivHelpContent = this.formComponent.myForm.value; + this._helpContentService.insertOrUpdateDivHelpContent(divHelpContent).subscribe( + _ => { + if(this.pageId) { + this.router.navigate( ['/classContents/'], { queryParams: { "community": this.communityPid, "page": this.pageId } } ); + } else { + this.router.navigate(['/classContents']); + } + }, + err => this.handleError('System error updating class content', err) + ); + } else { + this.errorMessage = "Please fill all required fields"; + } + } + + private cancelCustom() { + if(this.pageId) { + this.router.navigate( ['/classContents/'], { queryParams: { "community": this.communityPid, "page": this.pageId } } ); + } else { + this.router.navigate(['/classContents']); + } + } +} diff --git a/app/pages/divhelpcontent/new-div-help-content.component.html b/app/pages/divhelpcontent/new-div-help-content.component.html new file mode 100644 index 0000000..83a5a9b --- /dev/null +++ b/app/pages/divhelpcontent/new-div-help-content.component.html @@ -0,0 +1,21 @@ +
      +
      + + +
      + +
      +
      {{errorMessage}}
      + + + +
      +
      +
      +
      diff --git a/app/pages/divhelpcontent/new-div-help-content.component.ts b/app/pages/divhelpcontent/new-div-help-content.component.ts new file mode 100644 index 0000000..c24dd76 --- /dev/null +++ b/app/pages/divhelpcontent/new-div-help-content.component.ts @@ -0,0 +1,69 @@ +import { Component, ViewChild } from '@angular/core'; +import { ActivatedRoute, Router } from "@angular/router"; +import { DivContentFormComponent } from "./div-help-content-form.component"; +import { DivHelpContent } from "../../domain/div-help-content"; +import { HelpContentService } from "../../services/help-content.service"; + +@Component({ + selector: 'new-div-help-content', + templateUrl: 'new-div-help-content.component.html', +}) + +export class NewDivHelpContentComponent { + + @ViewChild(DivContentFormComponent) + public formComponent : DivContentFormComponent; + + private errorMessage : string = null; + + private communityPid: string; + + private pageId: string; + + constructor( + private route: ActivatedRoute, + private router: Router, + private _helpContentService: HelpContentService) {} + + ngOnInit() { + this.route.queryParams.subscribe(params => { + this.communityPid = params['community']; + this.pageId = params['pageId']; + }); + } + + private saveCustom() { + + this.errorMessage = null; + + if(this.formComponent.myForm.valid) { + let divHelpContent : DivHelpContent = this.formComponent.myForm.value; + + this._helpContentService.insertOrUpdateDivHelpContent(divHelpContent).subscribe( + _ => { + if(this.pageId) { + this.router.navigate( ['/classContents/'], { queryParams: { "community": this.communityPid, "page": this.pageId } } ); + } else { + this.router.navigate(['/classContents']); + } + }, + err => this.handleError('System error saving page content', err) + ); + } else { + this.errorMessage = "Please fill all required fields"; + } + } + + private cancelCustom() { + if(this.pageId) { + this.router.navigate( ['/classContents/'], { queryParams: { "community": this.communityPid, "page": this.pageId } } ); + } else { + this.router.navigate(['/classContents']); + } + } + + handleError(message: string, error) { + this.errorMessage = message + ' (Server responded: ' + error + ')'; + + } +} diff --git a/app/pages/faq/questions.component.html b/app/pages/faq/questions.component.html index 5096752..12e67c9 100644 --- a/app/pages/faq/questions.component.html +++ b/app/pages/faq/questions.component.html @@ -77,7 +77,7 @@
    - +
    No questions found
    diff --git a/app/pages/faq/topics.component.html b/app/pages/faq/topics.component.html index 633e0c8..6df4c0d 100644 --- a/app/pages/faq/topics.component.html +++ b/app/pages/faq/topics.component.html @@ -55,7 +55,7 @@
    - +
    No topics found
    diff --git a/app/pages/helpcontent/edit-page-help-content.component.html b/app/pages/helpcontent/edit-page-help-content.component.html index 96e953d..3b329de 100644 --- a/app/pages/helpcontent/edit-page-help-content.component.html +++ b/app/pages/helpcontent/edit-page-help-content.component.html @@ -13,7 +13,7 @@
    {{errorMessage}}
    - +
    diff --git a/app/pages/helpcontent/edit-page-help-content.component.ts b/app/pages/helpcontent/edit-page-help-content.component.ts index a486cb0..de7a43d 100644 --- a/app/pages/helpcontent/edit-page-help-content.component.ts +++ b/app/pages/helpcontent/edit-page-help-content.component.ts @@ -55,6 +55,7 @@ export class EditPageHelpContentComponent implements OnInit, OnDestroy{ private updateForm(pageHelpContent : PageHelpContent) { this.pageHelpContent = pageHelpContent; + console.info(pageHelpContent); this.formComponent.myForm.patchValue((pageHelpContent)); // console.log("patching",pageHelpContent); } diff --git a/app/pages/helpcontent/entities.component.html b/app/pages/helpcontent/entities.component.html index d17014c..2a20327 100644 --- a/app/pages/helpcontent/entities.component.html +++ b/app/pages/helpcontent/entities.component.html @@ -5,7 +5,7 @@
    Entities
    New Entity
    @@ -22,7 +22,7 @@
    - +
    • Activate
    • @@ -110,7 +110,12 @@ [isModalShown]="isModalShown" (emmitObject)="entityUpdatedSuccessfully($event)" (emmitError)="handleError($event)"> - + + This action will affect all search pages related to this entity! + Pages' status will change to entity's status! + Do you want to continue? + Are you sure you want to delete the selected entity(-ies)? diff --git a/app/pages/helpcontent/entities.component.ts b/app/pages/helpcontent/entities.component.ts index 8e6dd9e..bea54a3 100644 --- a/app/pages/helpcontent/entities.component.ts +++ b/app/pages/helpcontent/entities.component.ts @@ -40,6 +40,10 @@ export class EntitiesComponent implements OnInit { public communities: Community[] = []; public selectedCommunityPid: string; + @ViewChild('okModal') + public okModal:ModalFormComponent; +public toggleIds: string[]; +public toggleStatus: boolean; ngOnInit() { this.getCommunities(); @@ -167,16 +171,22 @@ export class EntitiesComponent implements OnInit { } public toggleEntities(status : boolean, ids : string[]) { - this._helpContentService.toggleEntities(this.selectedCommunityPid,ids,status).subscribe( - () => { - for(let id of ids) { - let i = this.checkboxes.findIndex(_ => _.entity._id == id); - this.checkboxes[i].entity.isEnabled=status; - } - this.applyCheck(false); - }, - error => this.handleError('System error changing the status of the selected entity(-ies)', error) - ); + this.okModal.showModal(); + this.toggleIds = ids; + this.toggleStatus = status; + } + + public continueToggling(event: any) { + this._helpContentService.toggleEntities(this.selectedCommunityPid,this.toggleIds,this.toggleStatus).subscribe( + () => { + for(let id of this.toggleIds) { + let i = this.checkboxes.findIndex(_ => _.entity._id == id); + this.checkboxes[i].entity.isEnabled=this.toggleStatus; + } + this.applyCheck(false); + }, + error => this.handleError('System error changing the status of the selected entity(-ies)', error) + ); } } diff --git a/app/pages/helpcontent/new-page-help-content.component.html b/app/pages/helpcontent/new-page-help-content.component.html index 010c3b4..7e8e639 100644 --- a/app/pages/helpcontent/new-page-help-content.component.html +++ b/app/pages/helpcontent/new-page-help-content.component.html @@ -13,7 +13,7 @@
      {{errorMessage}}
      - +
    diff --git a/app/pages/helpcontent/page-help-content-form.component.html b/app/pages/helpcontent/page-help-content-form.component.html index 665ff5b..88ee02d 100644 --- a/app/pages/helpcontent/page-help-content-form.component.html +++ b/app/pages/helpcontent/page-help-content-form.component.html @@ -38,6 +38,14 @@
    +
    + + +