import { Component , OnInit } from '@angular/core' ; import { ActivatedRoute } from '@angular/router' ; import { GroupService } from '../../services/groups/group.service' ; import { UtilsService } from "../../services/utils.service" ; import { RequestsActionsComponent } from "../../secondary-components/requests-actions/requests-actions.component" ; import * as _ from "lodash" ; import { RequestsService } from "../../services/requests/requests.service" ; import { TableHeader } from "../../models/table-header.model" ; import { GroupsUtilsService } from "../../services/groups/groups-utils.service" ; import { UsersUtilsService } from "../../services/users/users-utils.service" ; import { RequestsUtilsService } from "../../services/requests/requests-utils.service" ; @ Component ( { selector : 'app-requests' , templateUrl : './requests.component.html' , styleUrls : [ './requests.component.scss' ] } ) export class RequestsComponent { public requestsReceived ; public tableConfig ; public showConfirmModal = false ; public confirmModalConfig : any = { } ; constructor ( private activatedRoute , private groupService , private groupUtils , private usersUtils , private requestUtils , private requestsService , private utils ) { this . requestsReceived = this . activatedRoute . snapshot . data [ 'requestsReceived' ] ; this . tableConfig = { selectable : true , selection : [ ] , headers : [ new TableHeader ( 'Name' , '' , 'function' , ( element ) => { return this . usersUtils . getUser ( element . target ) . name ; } ) , new TableHeader ( 'Group Requested' , '' , 'function' , ( element ) => { return this . groupUtils . getGroup ( element . object ) . name ; } ) , new TableHeader ( 'Reason' , 'openReason' , 'string' ) ] , actionsComponent : RequestsActionsComponent } ; } approveSelection ( ) { this . showConfirmModal = true ; this . confirmModalConfig = { confirmMessage : 'Approve ' + this . tableConfig . selection . length + ' request(s)?' , onConfirm : ( ) => { this . requestUtils . approveAllRequests ( this . tableConfig . selection ) . then ( ( response ) => { _ . remove ( this . requestsReceived , ( request ) => { return _ . find ( this . tableConfig . selection , ( selectionElement ) => { return request . id === selectionElement . id ; } ) ; } ) ; this . tableConfig . selection = [ ] ; } ) ; } } ; } denySelection ( ) { this . showConfirmModal = true ; this . confirmModalConfig = { confirmMessage : 'Deny ' + this . tableConfig . selection . length + ' request(s)?' , onConfirm : ( ) => { this . requestUtils . denyAllRequests ( this . tableConfig . selection ) . then ( ( response ) => { _ . remove ( this . requestsReceived , ( request ) => { return _ . find ( this . tableConfig . selection , ( selectionElement ) => { return request . id === selectionElement . id ; } ) ; } ) ; this . tableConfig . selection = [ ] ; } ) ; } } ; } }