@ -1,20 +1,20 @@
import { Component , ViewChild, OnInit , ElementRef } from '@angular/core' ;
import { FormBuilder , FormControl , FormGroup } from "@angular/forms" ;
import { ActivatedRoute , Router } from "@angular/router" ;
import { HelpContentService } from "../../services/help-content.service" ;
import { Component , ElementRef, OnInit , ViewChild } from '@angular/core' ;
import { FormBuilder , FormControl , FormGroup } from '@angular/forms' ;
import { ActivatedRoute , Router } from '@angular/router' ;
import { HelpContentService } from '../../services/help-content.service' ;
import { PageHelpContentFilterOptions } from '../../utils/entities/adminTool/page-help-content' ;
import { Page } from "../../utils/entities/adminTool/page" ;
import { Portal } from "../../utils/entities/adminTool/portal" ;
import { Page } from '../../utils/entities/adminTool/page' ;
import { Portal } from '../../utils/entities/adminTool/portal' ;
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" ;
import { properties } from "../../../../environments/environment" ;
import { HelperFunctions } from '../../utils/HelperFunctions.class' ;
import { Subscriber } from 'rxjs' ;
import { properties } from '../../../../environments/environment' ;
import { DomSanitizer } from '@angular/platform-browser' ;
import { SearchInputComponent } from '../../sharedComponents/search-input/search-input.component' ;
import { ConnectHelper } from '../../connect/connectHelper' ;
import { CheckDivHelpContent , DivHelpContent } from '../../utils/entities/adminTool/div-help-content' ;
declare var UIkit ;
@ -23,74 +23,51 @@ declare var UIkit;
templateUrl : './class-help-contents.component.html' ,
} )
export class ClassHelpContentsComponent implements OnInit {
@ViewChild ( 'AlertModalDeletePageHelpContents' ) alertModalDeletePageHelpContents ;
private selectedPageContents : string [ ] = [ ] ;
public checkboxes : CheckDivHelpContent [ ] = [ ] ;
public pageHelpContents : DivHelpContent [ ] = [ ] ;
public divHelpContents : DivHelpContent [ ] = [ ] ;
public formGroup : FormGroup ;
public pages : Page [ ] ;
public checkboxAll : boolean = false ;
public filters : PageHelpContentFilterOptions = { id : '' , active : null , text : new RegExp ( '' ) } ;
public keyword : string = "" ;
public keyword : string = '' ;
public counter = { all : 0 , active : 0 , inactive : 0 } ;
public communities : Portal [ ] = [ ] ;
public portal : string ;
public selectedPageId : string ;
public community : Portal ;
public page : Page ;
public properties : EnvProperties = null ;
public properties : EnvProperties = properties ;
public showLoading : boolean = true ;
public errorMessage : string = '' ;
public updateErrorMessage : string = '' ;
public filterForm : FormControl ;
public selectForm : FormControl ;
private subscriptions : any [ ] = [ ] ;
public selectedKeyword : string ;
@ViewChild ( 'searchInputComponent' ) searchInputComponent : SearchInputComponent ;
constructor ( private element : ElementRef , private route : ActivatedRoute , private router : Router , private _helpService : HelpContentService , private _fb : FormBuilder , private sanitizer : DomSanitizer ) {
}
ngOnInit() {
this . filterForm = this . _fb . control ( '' ) ;
this . selectForm = this . _fb . control ( '' ) ;
this . subscriptions . push ( this . filterForm . valueChanges . subscribe ( value = > {
this . filterBySearch ( value ) ;
} ) ) ;
this . subscriptions . push ( this . selectForm . valueChanges . subscribe ( value = > {
this . filterByPage ( value ) ;
} ) ) ;
this . properties = properties ;
this . subscriptions . push ( this . route . params . subscribe ( params = > {
this . portal = ( this . route . snapshot . data . portal ) ? this . route.snapshot.data.portal : this.route.snapshot.params [ this . route . snapshot . data . param ] ;
ConnectHelper . setPortalTypeFromPid ( this . portal ) ;
this . subscriptions . push ( this . route . queryParams . subscribe ( params = > {
HelperFunctions . scroll ( ) ;
this . selectedPageId = params [ 'pageId' ] ;
if ( this . portal && this . selectedPageId ) {
this . getPage ( this . selectedPageId ) ;
}
if ( ! this . selectedPageId ) {
this . router . navigate ( [ '../pages' ] , { relativeTo : this.route } ) ;
if ( ! this . selectedPageId ) {
this . router . navigate ( [ '../pages' ] , { relativeTo : this.route } ) ;
}
} ) ) ;
} ) ) ;
}
constructor ( private element : ElementRef , private route : ActivatedRoute , private router : Router , private _helpService : HelpContentService , private _fb : FormBuilder , private sanitizer : DomSanitizer ) {
}
ngOnDestroy ( ) : void {
this . subscriptions . forEach ( value = > {
if ( value instanceof Subscriber ) {
@ -100,191 +77,145 @@ export class ClassHelpContentsComponent implements OnInit {
}
} ) ;
}
init ( ) {
}
getPage ( pageId : string ) {
if ( ! Session . isLoggedIn ( ) ) {
this . router . navigate ( [ '/user-info' ] , {
queryParams : {
"errorCode" : LoginErrorCodes . NOT_VALID ,
"redirectUrl" : this . router . url
this . showLoading = true ;
this . subscriptions . push ( this . _helpService . getPageByPortal ( pageId , this . properties . adminToolsAPIURL , this . portal ) . subscribe (
page = > {
if ( this . properties . adminToolsPortalType != page . portalType ) {
this . router . navigate ( [ './pageContents' ] , { queryParams : { 'communityId' : this . portal } } ) ;
} else {
this . page = page ;
this . getPageHelpContents ( this . portal ) ;
}
} ) ;
} else {
this . showLoading = true ;
this . updateErrorMessage = "" ;
this . errorMessage = "" ;
this . subscriptions . push ( this . _helpService . getPageByPortal ( pageId , this . properties . adminToolsAPIURL , this . portal ) . subscribe (
page = > {
if ( this . properties . adminToolsPortalType != page . portalType ) {
this . router . navigate ( [ './pageContents' ] , { queryParams : { "communityId" : this . portal } } ) ;
} else {
this . page = page ;
this . getPageHelpContents ( this . portal ) ;
}
} ,
error = > this . handleError ( 'System error retrieving page' , error ) ) ) ;
}
} ,
error = > this . handleError ( 'System error retrieving page' , error ) ) ) ;
}
public count Page HelpContents() {
public countClassHelpContents() {
this . counter = { all : 0 , active : 0 , inactive : 0 } ;
let filter = Object . assign ( { } , this . filters ) ;
filter . active = null ;
this . page HelpContents. forEach ( _ = > {
this . divHelpContents . forEach ( _ = > {
if ( this . filterPageHelpContent ( _ , filter ) ) {
if ( _ . isActive == true ) this . counter . active ++ ;
else this . counter . inactive ++
if ( _ . isActive == true ) {
this . counter . active ++ ;
} else {
this . counter . inactive ++ ;
}
}
} ) ;
this . counter . all = this . counter . active + this . counter . inactive ;
}
getPageHelpContents ( community_pid : string ) {
if ( ! Session . isLoggedIn ( ) ) {
this . router . navigate ( [ '/user-info' ] , {
queryParams : {
"errorCode" : LoginErrorCodes . NOT_VALID ,
"redirectUrl" : this . router . url
this . subscriptions . push ( this . _helpService . getCommunityDivHelpContents ( community_pid , this . properties . adminToolsAPIURL , this . selectedPageId ) . subscribe (
pageHelpContents = > {
this . divHelpContents = pageHelpContents as Array < DivHelpContent > ;
this . counter . all = this . divHelpContents . length ;
this . checkboxes = [ ] ;
for ( let i = this . divHelpContents . length - 1 ; i >= 0 ; i -= 1 ) {
this . checkboxes . unshift ( < CheckDivHelpContent > { divHelpContent : this.divHelpContents [ i ] , checked : false } ) ;
}
} ) ;
} else {
this . subscriptions . push ( this . _helpService . getCommunityDivHelpContents ( community_pid , this . properties . adminToolsAPIURL , this . selectedPageId ) . subscribe (
pageHelpContents = > {
this . pageHelpContents = pageHelpContents as Array < DivHelpContent > ;
this . counter . all = this . pageHelpContents . length ;
this . checkboxes = [ ] ;
for ( let i = this . pageHelpContents . length - 1 ; i >= 0 ; i -= 1 ) {
this . checkboxes . unshift ( < CheckDivHelpContent > { divHelpContent : this.pageHelpContents [ i ] , checked : false } ) ;
}
this . countPageHelpContents ( ) ;
this . showLoading = false ;
} ,
error = > this . handleError ( 'System error retrieving page contents' , error ) ) ) ;
}
}
public toggleCheckBoxes ( event ) {
this . checkboxes . forEach ( _ = > _ . checked = event . target . checked ) ;
this . checkboxAll = event . target . checked ;
this . countClassHelpContents ( ) ;
this . showLoading = false ;
} ,
error = > this . handleError ( 'System error retrieving page contents' , error ) ) ) ;
}
public applyCheck ( flag : boolean ) {
this . checkboxes . forEach ( _ = > _ . checked = flag ) ;
this . checkboxAll = false ;
}
public getSelectedPageHelpContents ( ) : string [ ] {
return this . checkboxes . filter ( pageHelpContent = > pageHelpContent . checked == true )
. map ( checkedPageHelpContent = > checkedPageHelpContent . divHelpContent ) . map ( res = > res . _id ) ;
}
public confirmDeletePageHelpContent ( id : string ) {
this . selectedPageContents = [ id ] ;
this . confirmModalOpen ( ) ;
}
public confirmDeleteSelectedPageHelpContents() {
this . selectedPageContents = this . getSelectedPageHelpContents ( ) ;
this . confirmModalOpen ( ) ;
}
private confirmModalOpen() {
if ( ! Session . isLoggedIn ( ) ) {
this . router . navigate ( [ '/user-info' ] , {
queryParams : {
"errorCode" : LoginErrorCodes . NOT_VALID ,
"redirectUrl" : this . router . url
}
} ) ;
} else {
this . alertModalDeletePageHelpContents . cancelButton = true ;
this . alertModalDeletePageHelpContents . okButton = true ;
this . alertModalDeletePageHelpContents . alertTitle = "Delete Confirmation" ;
this . alertModalDeletePageHelpContents . message = "Are you sure you want to delete the selected page content(s)?" ;
this . alertModalDeletePageHelpContents . okButtonText = "Yes" ;
this . alertModalDeletePageHelpContents . open ( ) ;
}
this . alertModalDeletePageHelpContents . cancelButton = true ;
this . alertModalDeletePageHelpContents . okButton = true ;
this . alertModalDeletePageHelpContents . alertTitle = 'Delete Confirmation' ;
this . alertModalDeletePageHelpContents . message = 'Are you sure you want to delete the selected page content(s)?' ;
this . alertModalDeletePageHelpContents . okButtonText = 'Yes' ;
this . alertModalDeletePageHelpContents . open ( ) ;
}
public confirmedDeletePageHelpContents ( 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 . subscriptions . push ( this . _helpService . deleteDivHelpContents ( this . selectedPageContents , this . properties . adminToolsAPIURL , this . portal ) . subscribe (
_ = > {
this . deletePageHelpContentsFromArray ( this . selectedPageContents ) ;
UIkit . notification ( 'Page content(s) has been <b>successfully deleted</b>' , {
status : 'success' ,
timeout : 6000 ,
pos : 'bottom-right'
} ) ;
this . showLoading = false ;
} ,
error = > this . handleUpdateError ( 'System error deleting the selected page content(s)' , error )
) ) ;
}
this . showLoading = true ;
this . subscriptions . push ( this . _helpService . deleteDivHelpContents ( this . selectedPageContents , this . properties . adminToolsAPIURL , this . portal ) . subscribe (
_ = > {
this . deletePageHelpContentsFromArray ( this . selectedPageContents ) ;
UIkit . notification ( 'Page content(s) has been <b>successfully deleted</b>' , {
status : 'success' ,
timeout : 6000 ,
pos : 'bottom-right'
} ) ;
this . showLoading = false ;
} ,
error = > this . handleUpdateError ( 'System error deleting the selected page content(s)' , error )
) ) ;
}
private deletePageHelpContentsFromArray ( ids : string [ ] ) : void {
for ( let id of ids ) {
let i qc = this . checkboxes . findIndex ( _ = > _ . divHelpContent . _id == id ) ;
let iq = this . page HelpContents. findIndex ( _ = > _ . _id == id ) ;
this . checkboxes . splice ( i qc , 1 ) ;
this . pageHelpContents. splice ( iqc , 1 ) ;
let i = this . checkboxes . findIndex ( _ = > _ . divHelpContent . _id == id ) ;
let j = this . divHelpContents . findIndex ( _ = > _ . _id == id ) ;
this . checkboxes . splice ( i , 1 ) ;
this . divHelpContents . splice ( j , 1 ) ;
}
this . count Page HelpContents( ) ;
this . countClassHelpContents ( ) ;
}
public editPageHelpContent ( id : string ) {
if ( this . selectedPageId ) {
this . router . navigate ( [ 'edit/' ] , {
queryParams : {
"pageContentId" : id ,
"pageId" : this . selectedPageId
'pageContentId' : id ,
'pageId' : this . selectedPageId
} , relativeTo : this.route
} ) ;
} else {
this . router . navigate ( [ 'edit/' ] , {
queryParams : {
"pageContentId" : id ,
'pageContentId' : id ,
} , relativeTo : this.route
} ) ;
}
}
public togglePageHelpContents ( status : boolean , ids : string [ ] ) {
if ( ! Session . isLoggedIn ( ) ) {
this . router . navigate ( [ '/user-info' ] , {
queryParams : {
"errorCode" : LoginErrorCodes . NOT_VALID ,
"redirectUrl" : this . router . url
'errorCode' : LoginErrorCodes . NOT_VALID ,
'redirectUrl' : this . router . url
}
} ) ;
} else {
this . updateErrorMessage = "" ;
this . subscriptions . push ( this . _helpService . toggleDivHelpContents ( ids , status , this . properties . adminToolsAPIURL , this . portal ) . subscribe (
( ) = > {
for ( let id of ids ) {
let i = this . checkboxes . findIndex ( _ = > _ . divHelpContent . _id == id ) ;
this . checkboxes [ i ] . divHelpContent . isActive = status ;
}
this . count Page HelpContents( ) ;
this . count Class HelpContents( ) ;
this . applyCheck ( false ) ;
UIkit . notification ( 'Page content(s) has been <b>successfully updated</b>' , {
status : 'success' ,
@ -296,69 +227,70 @@ export class ClassHelpContentsComponent implements OnInit {
) ) ;
}
}
public filterPageHelpContent ( page HelpContent: DivHelpContent , filters : PageHelpContentFilterOptions ) : boolean {
let activeFlag = filters . active == null || page HelpContent. isActive == filters . active ;
let textFlag = filters . text . toString ( ) == '' || ( pageHelpContent. content ) . match ( filters . text ) != null ;
return activeFlag && textFlag ;
public filterPageHelpContent ( div HelpContent: DivHelpContent , filters : PageHelpContentFilterOptions ) : boolean {
let activeFlag = filters . active == null || div HelpContent. isActive == filters . active ;
let textFlag = filters . text . toString ( ) == '' || ( divHelpContent. content && divHelpContent . content . match ( filters . text ) != null ) ;
return activeFlag && textFlag ;
}
public applyFilter() {
this . checkboxes = [ ] ;
this . page HelpContents. filter ( item = > this . filterPageHelpContent ( item , this . filters ) ) . forEach (
this . div HelpContents. filter ( item = > this . filterPageHelpContent ( item , this . filters ) ) . forEach (
_ = > {
this . checkboxes . push ( < CheckDivHelpContent > { divHelpContent : _ , checked : false } )
this . checkboxes . push ( < CheckDivHelpContent > { divHelpContent : _ , checked : false } ) ;
}
) ;
}
public filterByPage ( event : any ) {
if ( event . target && event . target . value ) {
this . filters . id = event . target . value ;
this . applyFilter ( ) ;
}
}
public filterBySearch ( text : string ) {
this . filters . text = new RegExp ( text , "i" ) ;
this . filters . text = new RegExp ( text , 'i' ) ;
this . applyFilter ( ) ;
}
handleError ( message : string , error ) {
this . errorMessage = message ;
UIkit . notification ( message , {
status : 'danger' ,
timeout : 6000 ,
pos : 'bottom-right'
} ) ;
console . log ( 'Server responded: ' + error ) ;
this . showLoading = false ;
}
handleUpdateError ( message : string , error ) {
this . updateErrorMessage = message ;
UIkit . notification ( message , {
status : 'danger' ,
timeout : 6000 ,
pos : 'bottom-right'
} ) ;
console . log ( 'Server responded: ' + error ) ;
this . showLoading = false ;
}
public newPageContent() {
this . router . navigate ( [ 'edit' ] , {
queryParams : {
pageId : this.selectedPageId
} , relativeTo : this.route
} ) ;
this . router . navigate ( [ 'edit' ] , {
queryParams : {
pageId : this.selectedPageId
} , relativeTo : this.route
} ) ;
}
public onSearchClose() {
this . selectedKeyword = this . filterForm . value ;
}
public reset() {
this . selectedKeyword = null ;
this . searchInputComponent . reset ( )
this . searchInputComponent . reset ( ) ;
}
selectAll ( ) {
let checked = ! ! ( this . getSelectedPageHelpContents ( ) . length != this . checkboxes . length ) ;
for ( let check of this . checkboxes ) {
check . checked = checked ;
}
selectAll() {
let checked = ( this . getSelectedPageHelpContents ( ) . length != this . checkboxes . length ) ;
for ( let check of this . checkboxes ) {
check . checked = checked ;
}
}
}