import { Component , OnInit } from '@angular/core' ; import { Client } from '../../../services/api/client' ; import { REASONS , REPORT_ACTIONS } from '../../../services/list-options' ; import { JurySessionService } from '../juryduty/session/session.service' ; import { FormToastService } from '../../../common/services/form-toast.service' ; @ Component ( { selector : 'm-report-console' , templateUrl : 'console.component.html' , } ) export class ReportConsoleComponent implements OnInit { filter : string = 'review' ; appeals : any [ ] = [ ] ; inProgress : boolean = false ; offset : string = '' ; moreData : boolean = true ; constructor ( private client , public service , protected toasterService ) { } ngOnInit ( ) { this . load ( true ) ; } setFilter ( filter ) { this . filter = filter ; this . load ( true ) ; } async load ( refresh = false ) { if ( refresh ) { this . inProgress = false ; this . offset = '' ; this . moreData = true ; } this . inProgress = true ; try { let response = await this . client . get ( `api/v2/moderation/appeals/${ this . filter }` , { limit : 12 , offset : this . offset , } ) ; if ( refresh ) { this . appeals = [ ] ; } if ( response . appeals ) { this . appeals . push ( ... response . appeals ) ; } if ( response [ 'load-next' ] ) { this . offset = response [ 'load-next' ] ; } else { this . moreData = false ; } } catch ( e ) { } finally { this . inProgress = false ; } } async sendAppeal ( appeal , content , i ) { appeal . inProgress = true ; try { let response = await this . client . post ( `api/v2/moderation/appeals/${ appeal . report . urn }` , { note : content , } ) ; this . appeals . splice ( i , 1 ) ; } catch ( e ) { this . toasterService . error ( ( e && e . message ) || 'Error sending appeal' ) ; } } parseAction ( action ) { return typeof REPORT_ACTIONS [ action ] !== 'undefined' ? REPORT_ACTIONS [ action ] : action ; } }