import { Component , OnInit } from '@angular/core' ; import { AngularFireDatabase , AngularFireList , AngularFireObject } from '@angular/fire/database' ; import { Router } from '@angular/router' ; import { GlobalService } from '../../../services/global.service' ; import { MatSnackBar } from '@angular/material/snack-bar' ; import { MatDialog , MatDialogRef } from '@angular/material/dialog' ; import { DeleteDialogComponent } from '../delete-dialog/delete-dialog.component' ; import { Observable } from 'rxjs' ; @ Component ( { selector : 'admin-pages' , templateUrl : './admin-pages.component.html' , styleUrls : [ './admin-pages.component.scss' ] } ) export class AdminPagesComponent implements OnInit { pages : Observable < any > ; page : AngularFireObject < any > ; selectedOption : any ; dialogRef : MatDialogRef < any > ; currentAdmin : any ; constructor ( public db , public router , public dialog , public snackBar , public globalService ) { this . pages = db . list ( '/pages' , ref => ref . orderByChild ( 'rdateUpdated' ) . limitToFirst ( 9999 ) ) . snapshotChanges ( ) ; this . globalService . admin . subscribe ( ( a ) => { this . currentAdmin = a ; } ) ; } onChange ( e , key ) { this . page = this . db . object ( '/pages/' + key ) ; if ( e . checked ) { this . page . update ( { published : true } ) ; } else { this . page . update ( { published : false } ) ; } } deletePage ( key ) { let dialogRef = this . dialog . open ( DeleteDialogComponent ) ; dialogRef . afterClosed ( ) . subscribe ( result => { this . selectedOption = result ; if ( this . selectedOption === 'delete' ) { this . db . object ( '/pages/' + key ) . remove ( ) ; let snackBarRef = this . snackBar . open ( 'Page deleted' , 'OK!' , { duration : 3000 } ) ; } } ) ; } ngOnInit ( ) { } }