import { Component , ViewChild , Renderer2 , ElementRef , ViewChildren , QueryList } from '@angular/core' ; import { ModalController } from '@ionic/angular' ; import { UserService } from 'src/app/core/services/user.service' ; import { DataService } from 'src/app/core/services/data.service' ; import { ViewService } from 'src/app/core/services/view.service' ; @ Component ( { selector : 'page-dashboard' , templateUrl : 'dashboard.html' , } ) export class DashboardPage { showBlockList = false ; editMode = false ; oldBlockListData ; delSelected = 99 ; @ ViewChildren ( "sortbox" ) sortbox : QueryList < ElementRef > ; get blockList ( ) { return this . dataService . block ; } set blockList ( newblockList ) { this . dataService . block = newblockList ; } @ ViewChild ( 'dashboardbox' , { read : ElementRef , static : true } ) dashboardbox : ElementRef ; constructor ( public modalCtrl , public render , public userService , private dataService , private viewService ) { this . oldBlockListData = JSON . stringify ( this . blockList ) ; } ngAfterViewInit ( ) { this . initSortable ( ) ; } gotoSettings ( ) { } unlock ( ) { this . editMode = true ; } lock ( ) { this . editMode = false ; if ( this . oldBlockListData == JSON . stringify ( this . blockList ) ) return ; this . saveConfig ( ) ; } saveConfig ( ) { let userConfig = { "blockList" : this . blockList } ; this . userService . saveUserConfig ( userConfig ) ; } restorePosition ( ) { this . render . setStyle ( this . dashboardbox . nativeElement , 'top' , '0px' ) ; } showAddBlockModal ( e ) { this . showBlockList = true ; this . render . setStyle ( this . dashboardbox . nativeElement , 'position' , 'absolute' ) ; this . render . setStyle ( this . dashboardbox . nativeElement , 'top' , `${ - e . srcElement . offsetTop + 10 }px` ) ; } delBlock ( blockId , index ) { if ( index > - 1 ) this . blockList . list . splice ( index , 1 ) ; delete this . blockList . dict [ blockId ] ; } sortable ; initSortable ( ) { } saveList ( ) { console . log ( this . sortable . toArray ( ) ) ; this . blockList . list = this . sortable . toArray ( ) ; } changeView ( ) { this . viewService . changeView ( ) ; } }