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

208 lines
5.3 KiB
TypeScript
Raw Normal View History

import { Injectable } from '@angular/core';
2022-12-19 18:38:53 +01:00
import { Attachment } from '../models/attachment.model';
import { Observable } from 'rxjs';
import { HttpClient, HttpHeaders, HttpParams } from '@angular/common/http';
import { environment } from 'src/environments/environment';
2021-08-27 15:21:15 +01:00
import { LoginUserRespose } from '../models/user.model';
2022-02-07 17:55:00 +01:00
import { SessionStore } from '../store/session.service';
2022-03-09 09:23:27 +01:00
import { File } from '@ionic-native/file/ngx';
import { Platform } from '@ionic/angular';
2022-12-19 18:38:53 +01:00
import { ChangeProfileService } from './change-profile.service';
@Injectable({
providedIn: 'root'
})
export class AttachmentsService {
2021-08-27 15:21:15 +01:00
loggeduser: LoginUserRespose;
headers: HttpHeaders;
2022-12-19 18:38:53 +01:00
constructor(
2023-09-14 11:58:24 +01:00
private http: HttpClient,
private platform: Platform,
private file: File,
2022-12-19 18:38:53 +01:00
private changeProfileService: ChangeProfileService) {
this.changeProfileService.registerCallback(() => {
2023-01-24 15:56:47 +01:00
this.setHeader()
});
this.setHeader()
2022-12-19 18:38:53 +01:00
2023-01-24 15:56:47 +01:00
}
setHeader() {
2022-02-07 17:55:00 +01:00
this.loggeduser = SessionStore.user
2023-10-25 09:08:49 +01:00
this.headers = new HttpHeaders();;
2023-11-29 12:17:52 +01:00
this.headers = this.headers.set('Authorization', 'Bearer ' + SessionStore.user.Authorization);
}
2023-09-14 11:58:24 +01:00
uploadFile(formData: any) {
2022-02-03 21:01:53 +01:00
//const geturl = environment.apiURL + 'Tasks/DelegateTask';
const geturl = environment.apiURL + 'ObjectServer/UploadFiles';
let options = {
headers: this.headers
};
return this.http.post(`${geturl}`, formData, options);
}
2023-09-14 11:58:24 +01:00
getFile(guid: any) {
2022-02-03 21:01:53 +01:00
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);
}
2023-09-14 11:58:24 +01:00
downloadFile(guid: any) {
2022-02-03 21:01:53 +01:00
2023-09-14 11:58:24 +01:00
let downloadUrl = environment.apiURL + 'objectserver/streamfiles?path=' + guid;
2022-02-03 21:01:53 +01:00
var name = new Date().getTime();
return this.http.get(downloadUrl, {
responseType: "arraybuffer",
reportProgress: true, observe: 'events'
})
}
2022-03-09 09:23:27 +01:00
2023-09-14 11:58:24 +01:00
downloadFileAndStore(guid: any) {
2022-03-09 09:23:27 +01:00
var name = new Date().getTime();
const downloadPath = (
this.platform.is('android')
2023-09-14 11:58:24 +01:00
) ? this.file.externalDataDirectory : this.file.documentsDirectory;
let vm = this;
/** HttpClient - @angular/common/http */
this.http.get(
environment.apiURL + 'objectserver/streamfiles?path=' + guid,
2022-03-09 09:23:27 +01:00
{
2023-09-14 11:58:24 +01:00
responseType: 'arraybuffer',
2022-03-09 09:23:27 +01:00
}
2023-09-14 11:58:24 +01:00
).subscribe((fileBlob: Uint8Array) => {
2022-03-09 09:23:27 +01:00
/** File - @ionic-native/file/ngx */
2023-09-14 11:58:24 +01:00
vm.file.writeFile(downloadPath, "YourFileName.pdf", fileBlob, { replace: true });
});
}
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);
2021-08-03 12:24:34 +01:00
let options = {
headers: this.headers,
params: params
};
2023-09-14 11:58:24 +01:00
return this.http.get<Attachment[]>(`${geturl}`, options);
}
2021-04-19 15:21:35 +01:00
getAttachments(source: number, sourceid: string): Observable<Attachment[]> {
let geturl = environment.apiURL + 'attachments/GetSourceName';
let params = new HttpParams();
params = params.set("Source", source.toString());
/* 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
}
2023-09-14 11:58:24 +01:00
return this.http.post(`${geturl}`, body, options);
2021-04-19 15:21:35 +01:00
}
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
}
2023-09-14 11:58:24 +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,
}
2023-09-14 11:58:24 +01:00
return this.http.post(`${geturl}`, body, options);
}
addUserProfilePhoto(formData: any) {
const geturl = environment.apiURL + 'UserAuthentication/AddPhoto';
this.headers = this.headers.set('content-type', "application/json");
this.headers = this.headers.set('accept', "application/json");
let options = {
headers: this.headers
};
return this.http.post(`${geturl}`, formData, options);
}
getUserProfilePhoto(guid) {
2023-09-14 11:58:24 +01:00
const geturl = environment.apiURL + 'UserAuthentication/GetPhoto';
let params = new HttpParams();
params = params.set("UserPhoto", guid);
2023-09-14 11:58:24 +01:00
let options = {
headers: this.headers,
params: params
2023-09-14 11:58:24 +01:00
};
return this.http.get(`${geturl}`, options);
2021-08-06 17:19:48 +01:00
}
}