import { Component , ViewChild } from '@angular/core' ; import { MatSnackBar } from '@angular/material/snack-bar' ; import { OnInit } from '@angular/core' ; import { CliCreateComponent } from './cli/create/create.component' ; import { TerminalData } from './_shared/terminal/terminal.service' ; @ Component ( { selector : 'app-snack-bar-error' , styles : [ `
      :host {
        display: flex;
        flex-direction: row;
        align-items: center;
        justify-content: center;
      }
      span {
        color: #f44336;
        font-family: Roboto, 'Helvetica Neue', sans-serif;
      }
      mat-icon {
        color: #f44336;
      }
    ` ] , template : '<mat-icon>error</mat-icon><span>An error has occured. Check the logs tab.</span>' } ) export class SnackBarErrorComponent { } @ Component ( { selector : 'app-snack-bar-success' , styles : [ `
      :host {
        display: flex;
        flex-direction: row;
        align-items: center;
        justify-content: center;
      }
      span {
        color: #81c784;
        font-family: Roboto, 'Helvetica Neue', sans-serif;
      }
      mat-icon {
        color: #4caf50;
      }
    ` ] , template : '<mat-icon>verified_user</mat-icon><span>Command executed successfully.</span>' } ) export class SnackBarSuccessComponent { } @ Component ( { selector : 'app-root' , templateUrl : './app.component.html' , styleUrls : [ './app.component.css' ] } ) export class AppComponent implements OnInit { selectedIndex = 0 ; @ ViewChild ( 'appCli' , { static : true } ) appCli : CliCreateComponent ; constructor ( public snackBarError , public snackBarSuccess ) { } ngOnInit ( ) { this . selectedIndex = parseInt ( localStorage . getItem ( 'ui.selectedIndex' ) || '0' , 10 ) ; localStorage . setItem ( 'ui.selectedIndex' , `${ this . selectedIndex }` ) ; } storeIndex ( index ) { localStorage . setItem ( 'ui.selectedIndex' , `${ index }` ) ; } onError ( message ) { console . log ( 'onError::' , message ) ; this . snackBarError . openFromComponent ( SnackBarErrorComponent , { duration : 3000 , panelClass : [ 'error-container' ] } ) ; } onSuccess ( message ) { console . log ( 'onSuccess::' , message ) ; if ( message ) { this . snackBarSuccess . openFromComponent ( SnackBarSuccessComponent , { duration : 2000 } ) ; } } onDrag ( event ) { event . preventDefault ( ) ; event . stopPropagation ( ) ; } onDragLeave ( event ) { event . preventDefault ( ) ; event . stopPropagation ( ) ; } onDrop ( event ) { event . preventDefault ( ) ; this . appCli . import ( event ) ; } onTerminalOpen ( data ) { /**
         * Set current directory from server if root directory field is empty
         */ if ( data . cwd && ! this . appCli . form . value [ 'root-dir' ] ) { this . appCli . form . patchValue ( { 'root-dir' : data . cwd } ) ; } } }