import { Injectable } from '@angular/core' ; import { HttpClient , HttpHeaders } from '@angular/common/http' ; import { Observable } from 'rxjs' ; import { SR , SrUserInput } from '../model/sr' ; import { DatasetData } from '../model/index' ; import * as _ from 'lodash' ; import { EnvironmentsService } from './environments.service' ; import { map } from 'rxjs/operators' ; @ Injectable ( ) export class AvaService { baseUrl : string ; constructor ( private http , private env ) { this . baseUrl = `${ this . env . config . annotationService }/api/v1.0` ; } public getAllUsers ( ) { return this . http . get < any > ( `${ this . baseUrl }/users` ) ; } public saveUser ( payload ) { return this . http . post < any > ( `${ this . baseUrl }/users` , payload ) ; } public deleteUser ( payload ) { const options = { headers : new HttpHeaders ( ) , body : payload , } ; return this . http . delete ( `${ this . baseUrl }/users` , options ) ; } public saveRoleEdit ( payload ) { return this . http . patch ( `${ this . baseUrl }/users` , payload ) ; } public getUserRole ( ) { return this . http . get < any > ( `${ this . baseUrl }/users/roles` ) ; } public getMyDatasets ( format ? ) { return this . http . get < any > ( `${ this . baseUrl }/users/datasets?format=${ format }` ) ; } public getProjectsList ( ) { return this . http . get < any > ( `${ this . baseUrl }/users/projects/names` ) ; } public postDataset ( formdata ) { return this . http . post < DatasetData > ( `${ this . baseUrl }/projects` , formdata ) ; } public saveProjectEdit ( payload ) { return this . http . patch ( `${ this . baseUrl }/projects` , payload ) ; } public deleteProject ( payload ) { const options = { headers : new HttpHeaders ( ) , } ; return this . http . delete ( `${ this . baseUrl }/projects?pid=${ payload . pid }` , options ) ; } public getProjects ( router ) { return this . http . get < any > ( `${ this . baseUrl }/projects?src=${ router }` ) ; } public getProjectInfo ( pid ) { return this . http . get ( `${ this . baseUrl }/projects/details?pid=${ pid }` ) ; } public findProjectName ( param ) { return this . http . get < any > ( `${ this . baseUrl }/projects/names?pname=${ param . pname }` ) ; } public getAccuracy ( projectId ? ) { return this . http . get < any > ( `${ this . baseUrl }/projects/al/accuracy?pid=${ projectId }` ) ; } public generate ( id ? , format ? , src ? , onlyLabelled ? ) { return this . http . get < any > ( `${ this . baseUrl }/projects/generate?pid=${ id }&format=${ format }&src=${ src }&onlyLabelled=${ onlyLabelled }` ) ; } public downloadProject ( id ? ) { return this . http . get < any > ( `${ this . baseUrl }/projects/download?pid=${ id }` ) ; } public communityDownload ( payload ? ) { return this . http . post ( `${ this . baseUrl }/projects/download/community-download-count` , payload ) ; } public shareStatus ( payload ) { return this . http . patch ( `${ this . baseUrl }/projects/share` , payload ) ; } public getProblemCategories ( id ? ) { return this . http . get < any > ( `${ this . baseUrl }/projects/labels?pid=${ id }` ) ; } public getChart ( projectId ? ) { return this . http . get < any > ( `${ this . baseUrl }/projects/annotations?pid=${ projectId }` ) ; } public getProgress ( payload ) { return this . http . get ( `${ this . baseUrl }/projects/users/progression?pid=${ payload . id }&review=${ payload . review }` ) ; } public putSrUserInput ( srUserInput ) { return this . http . patch < any > ( `${ this . baseUrl }/projects/tickets` , srUserInput ) ; } public appendSrs ( payload ? ) { return this . http . post ( `${ this . baseUrl }/projects/tickets` , payload ) ; } public deleteTicket ( payload ? ) { const options = { headers : new HttpHeaders ( ) , body : payload , } ; return this . http . delete ( `${ this . baseUrl }/projects/tickets` , options ) ; } public getSample ( dataSetId ? ) { return this . http . get < any > ( `${ this . baseUrl }/projects/tickets/examples?pid=${ dataSetId }` ) . pipe ( map ( ( res ) => { const flag = [ ] ; _ . forIn ( res . sampleSr , function ( value , key ) { flag . push ( { key , value } ) ; } ) ; res . sampleSr = flag ; return res ; } ) ) ; } public getRandomSr ( param ) { return this . http . get < SR > ( `${ this . baseUrl }/projects/tickets/annotations?pid=${ param . id }` ) ; } public skipToNext ( param ) { return this . http . post < SR > ( `${ this . baseUrl }/projects/tickets/skip` , param ) ; } public getALLSrs ( payload ) { return this . http . get ( `${ this . baseUrl }/projects/tickets?pid=${ payload . id }&fname=${ payload . fname }&page=${ payload . pageNumber }&limit=${ payload . limit }` ) ; } public getSrById ( payload ) { return this . http . get ( `${ this . baseUrl }/projects/tickets/details?tid=${ payload . id }&pid=${ payload . pid }` ) ; } public toFlagTicket ( payload ? ) { return this . http . post < SR > ( `${ this . baseUrl }/projects/tickets/flags` , payload ) ; } public unflag ( payload ? ) { return this . http . post ( `${ this . baseUrl }/projects/tickets/flags/un-flag` , payload ) ; } public getAllFlag ( projectName ? , pageNumber ? , limit ? ) { return this . http . get < any > ( `${ this . baseUrl }/projects/tickets/users/flags?pname=${ projectName }&page=${ pageNumber }&limit=${ limit }` ) ; } public getAllFlagTickets ( projectName ? , pageNumber ? , limit ? ) { return this . http . get < any > ( `${ this . baseUrl }/projects/tickets/flags?pname=${ projectName }&page=${ pageNumber }&limit=${ limit }` ) ; } public silenceTicket ( payload ? ) { return this . http . post ( `${ this . baseUrl }/projects/tickets/flags/silence` , payload ) ; } public getS3UploadConfig ( ) { return this . http . get < any > ( `${ this . baseUrl }/datasets/s3/credentials` ) ; } public getCloudUrl ( dataSetId ? ) { return this . http . get < any > ( `${ this . baseUrl }/datasets/s3/signed-url?dsid=${ dataSetId }` ) ; } public uploadDateset ( payload ) { return this . http . post ( `${ this . baseUrl }/datasets` , payload ) ; } public deleteMyDataset ( payload ) { const options = { headers : new HttpHeaders ( ) , } ; return this . http . delete ( `${ this . baseUrl }/datasets?dsid=${ payload . dsId }` , options ) ; } public findDatasetName ( dataSetName ? ) { return this . http . get < any > ( `${ this . baseUrl }/datasets/names?dsname=${ dataSetName }` ) ; } public sendSQL ( payload ? ) { return this . http . post ( `${ this . baseUrl }/datasets/query-from-superCollider` , payload ) ; } public sendEmailToOwner ( payload ) { return this . http . post ( `${ this . baseUrl }/emails/send-to-owners` , payload ) ; } public sendEmailToAnnotator ( payload ) { return this . http . post ( `${ this . baseUrl }/emails/send-to-annotators` , payload ) ; } public deleteLabel ( payload ) { const options = { headers : new HttpHeaders ( ) , body : payload , } ; return this . http . delete ( `${ this . baseUrl }/projects/labels` , options ) ; } public register ( payload ) { return this . http . put ( `${ this . baseUrl }/register` , payload ) ; } public login ( payload ) { return this . http . post ( `${ this . baseUrl }/login` , payload ) ; } public getToken ( ) { return this . http . get < any > ( `${ this . baseUrl }/token` ) ; } public getProjectsReviewList ( ) { return this . http . get < any > ( `${ this . baseUrl }/projects/review` ) ; } public getOneReview ( pid , user ? , order ? ) { return this . http . get < any > ( `${ this . baseUrl }/projects/tickets/review?pid=${ pid }&user=${ user }&order=${ order }` ) ; } public passTicket ( payload ) { return this . http . patch ( `${ this . baseUrl }/projects/tickets/review` , payload ) ; } public getAllLogFilename ( pid ) { return this . http . get < any > ( `${ this . baseUrl }/projects/log/files?pid=${ pid }` ) ; } public getSrByFilename ( data ) { return this . http . get < any > ( `${ this . baseUrl }/projects/log/filter?pid=${ data . pid }&fname=${ data . fname }` ) ; } public getSetData ( payload ) { return this . http . post ( `${ this . baseUrl }/datasets/set-data` , payload ) ; } public checkLocalFileExist ( filename ) { return this . http . get < any > ( `${ this . baseUrl }/datasets/file?file=${ filename }` ) . pipe ( map ( ( res ) => { if ( res . fileExist ) { return true ; } else { return false ; } } , ( err ) => { console . log ( err ) ; return false ; } ) ) ; } }