Files
doneit-web/src/app/services/attachments.service.ts
T

142 lines
3.7 KiB
TypeScript
Raw Normal View History

import { Injectable } from '@angular/core';
2021-04-19 15:21:35 +01:00
import { Attachment, EventAttachment } from '../models/attachment.model';
import { Observable } from 'rxjs';
import { HttpClient, HttpHeaders, HttpParams } from '@angular/common/http';
import { environment } from 'src/environments/environment';
import { AuthService } from '../services/auth.service';
2021-08-27 15:21:15 +01:00
import { LoginUserRespose } from '../models/user.model';
@Injectable({
providedIn: 'root'
})
export class AttachmentsService {
2021-08-27 15:21:15 +01:00
loggeduser: LoginUserRespose;
headers: HttpHeaders;
2021-08-03 12:24:34 +01:00
constructor(private http: HttpClient, user: AuthService) {
this.loggeduser = user.ValidatedUser;
this.headers = new HttpHeaders();
this.headers = this.headers.set('Authorization', this.loggeduser.BasicAuthKey);
}
2022-02-03 21:01:53 +01:00
uploadFile(formData:any) {
console.log('UPLOAD file', formData)
//const geturl = environment.apiURL + 'Tasks/DelegateTask';
const geturl = environment.apiURL + 'ObjectServer/UploadFiles';
let options = {
headers: this.headers
};
return this.http.post(`${geturl}`, formData, options);
}
getFile(guid:any) {
const geturl = environment.apiURL + 'lakefs/StreamFile';
let params = new HttpParams();
params = params.set("path", guid);
this.headers = this.headers.set('responseType', 'blob');
this.headers = this.headers.set('Content-Type', 'application/octet-stream');
let options = {
headers: this.headers,
params: params
};
return this.http.get<any>(`${geturl}`, options);
}
downloadFile(guid:any) {
let downloadUrl = environment.apiURL +'objectserver/streamfiles?path='+guid;
var name = new Date().getTime();
return this.http.get(downloadUrl, {
responseType: "arraybuffer",
reportProgress: true, observe: 'events'
})
}
2020-11-25 11:25:08 +01:00
getAttachmentsBySerial(serialNumber: string): Observable<Attachment[]>{
let geturl = environment.apiURL + 'attachments/GetAttachments';
let params = new HttpParams();
2020-11-25 11:25:08 +01:00
params = params.set("SerialNumber", serialNumber);
2020-11-16 00:41:11 +01:00
2021-08-03 12:24:34 +01:00
let options = {
headers: this.headers,
params: params
};
return this.http.get<Attachment[]>(`${geturl}`, options);
}
2021-04-19 15:21:35 +01:00
getAttachments(source: number, sourceid: string): Observable<Attachment[]> {
2020-11-05 16:43:01 +01:00
let geturl = environment.apiURL + 'attachments/GetSourceName';
let params = new HttpParams();
params = params.set("Source", source.toString());
2020-11-05 16:43:01 +01:00
/* params = params.set("SourceId", sourceid); */
2021-08-03 12:24:34 +01:00
let options = {
headers: this.headers,
params: params
};
2020-11-25 11:25:08 +01:00
return this.http.get<Attachment[]>(`${geturl}`, options);
}
2021-04-19 15:21:35 +01:00
getAttachmentsById(eventId: string): Observable<Attachment[]> {
2020-11-25 11:25:08 +01:00
let geturl = environment.apiURL + 'attachments/GetAttachmentsByEventId';
let params = new HttpParams();
params = params.set("ParentId", eventId);
/* params = params.set("SourceId", sourceid); */
2021-08-03 12:24:34 +01:00
2021-04-19 15:21:35 +01:00
let options = {
2021-08-03 12:24:34 +01:00
headers: this.headers,
params: params
2020-11-25 11:25:08 +01:00
};
return this.http.get<Attachment[]>(`${geturl}`, options);
}
2021-04-19 15:21:35 +01:00
2021-08-03 12:24:34 +01:00
setEventAttachmentById(body: any) {
2021-04-19 15:21:35 +01:00
let geturl = environment.apiURL + 'Attachments/Create';
2021-08-03 12:24:34 +01:00
let options = {
headers: this.headers,
2021-04-19 15:21:35 +01:00
}
return this.http.post(`${geturl}`, body, options);
}
2021-08-03 12:24:34 +01:00
deleteEventAttachmentById(attachmentId) {
2021-09-15 15:39:55 +01:00
let geturl = environment.apiURL + 'Attachments/Delete';
2021-04-20 15:05:40 +01:00
let params = new HttpParams();
params = params.set("attachmentId", attachmentId);
2021-08-03 12:24:34 +01:00
let options = {
headers: this.headers,
params: params
2021-04-20 15:05:40 +01:00
}
2021-04-20 16:06:31 +01:00
return this.http.delete(`${geturl}`, options);
2021-04-20 15:05:40 +01:00
}
2021-08-06 17:19:48 +01:00
AddAttachment(body: any) {
let geturl = environment.apiURL + 'Attachments/CreateAttachmentProcess';
let options = {
headers: this.headers,
}
return this.http.post(`${geturl}`, body, options);
}
}