import { Component , Injector , OnInit , ElementRef } from '@angular/core' ; import * as _ from "lodash" ; import { RequestsService } from "../../services/requests/requests.service" ; import { PopupItem } from "../../models/popup-item.model" ; import { MatSnackBar } from "@angular/material" ; import { UtilsService } from "../../services/utils.service" ; import { UsersUtilsService } from "../../services/users/users-utils.service" ; @ Component ( { selector : 'app-requests-actions' , templateUrl : './requests-actions.component.html' , styleUrls : [ './requests-actions.component.scss' ] } ) export class RequestsActionsComponent { public row ; public list ; public showConfirmModal = false ; public confirmModalConfig : any = { } ; public showDialog = false ; public optionsList = [ new PopupItem ( 'Approve' , 'fa fa-check' , ( ) => { this . approve ( ) ; } ) , new PopupItem ( 'Deny' , 'fa fa-close' , ( ) => { this . deny ( ) ; } ) ] ; constructor ( private injector , private utils , private usersUtils , private requestsService ) { this . row = injector . get ( 'row' ) ; this . list = injector . get ( 'list' ) ; } approve ( ) { this . showConfirmModal = true ; this . confirmModalConfig = { confirmMessage : 'Approve request from ' + this . usersUtils . getUser ( this . row . opener ) . name , onConfirm : ( ) => { this . requestsService . approveRequest ( this . row . id ) . then ( ( response ) => { _ . remove ( this . list , { id : this . row . id } ) ; this . utils . defaultSnackBar ( 'Request Accepted' ) ; } ) ; } } ; } deny ( ) { this . showConfirmModal = true ; this . confirmModalConfig = { confirmMessage : 'Deny request from ' + this . usersUtils . getUser ( this . row . opener ) . name , onConfirm : ( ) => { this . requestsService . denyRequest ( this . row . id ) . then ( ( response ) => { _ . remove ( this . list , { id : this . row . id } ) ; this . utils . defaultSnackBar ( 'Request Denied' ) ; } ) ; } } ; } toggleDialog ( $event ) { this . showDialog = ! this . showDialog ; $event . stopPropagation ( ) ; } }