2021-09-13 12:37:58 +01:00
|
|
|
import { Injectable } from '@angular/core';
|
|
|
|
|
import { FileLoaderService } from '../file/file-loader.service';
|
|
|
|
|
import { FileToBase64Service } from '../file/file-to-base64.service';
|
2021-09-14 15:57:24 +01:00
|
|
|
import { InAppBrowser } from '@ionic-native/in-app-browser/ngx';
|
2021-09-14 10:30:13 +01:00
|
|
|
//Cordova
|
|
|
|
|
import { Camera, CameraOptions } from '@ionic-native/camera/ngx';
|
2021-09-21 14:05:59 +01:00
|
|
|
import { ChatService } from '../chat.service';
|
|
|
|
|
import { ModalController } from '@ionic/angular';
|
|
|
|
|
import { SearchPage } from 'src/app/pages/search/search.page';
|
|
|
|
|
import { SearchList } from 'src/app/models/search-document';
|
|
|
|
|
import { ProcessesService } from '../processes.service';
|
|
|
|
|
import { ToastService } from '../toast.service';
|
2021-09-13 12:37:58 +01:00
|
|
|
|
|
|
|
|
@Injectable({
|
|
|
|
|
providedIn: 'root'
|
|
|
|
|
})
|
|
|
|
|
export class FileService {
|
|
|
|
|
|
|
|
|
|
capturedImage:any;
|
|
|
|
|
capturedImageTitle:any;
|
2021-09-21 14:05:59 +01:00
|
|
|
documents:SearchList[] = [];
|
|
|
|
|
showLoader: boolean;
|
2021-09-13 12:37:58 +01:00
|
|
|
|
2021-10-06 17:27:49 +01:00
|
|
|
files: Set<File>;
|
|
|
|
|
|
2021-09-13 12:37:58 +01:00
|
|
|
constructor(
|
2021-09-14 10:30:13 +01:00
|
|
|
private camera: Camera,
|
2021-09-13 12:37:58 +01:00
|
|
|
private fileLoaderService: FileLoaderService,
|
|
|
|
|
private fileToBase64Service: FileToBase64Service,
|
2021-09-14 15:57:24 +01:00
|
|
|
private iab: InAppBrowser,
|
2021-09-21 14:05:59 +01:00
|
|
|
private chatService: ChatService,
|
|
|
|
|
private modalController: ModalController,
|
|
|
|
|
private processesService: ProcessesService,
|
|
|
|
|
private toastService: ToastService,
|
2021-09-13 12:37:58 +01:00
|
|
|
) { }
|
|
|
|
|
|
2021-09-14 10:30:13 +01:00
|
|
|
takePicture() {
|
|
|
|
|
const options: CameraOptions = {
|
|
|
|
|
quality: 50,
|
|
|
|
|
destinationType: this.camera.DestinationType.DATA_URL,
|
|
|
|
|
encodingType: this.camera.EncodingType.JPEG,
|
|
|
|
|
mediaType: this.camera.MediaType.PICTURE,
|
|
|
|
|
targetWidth: 720,
|
|
|
|
|
targetHeight: 720,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.camera.getPicture(options).then((imageData) => {
|
|
|
|
|
// imageData is either a base64 encoded string or a file URI
|
|
|
|
|
// If it's base64 (DATA_URL): m
|
|
|
|
|
//let base64Image = 'data:image/jpeg;base64,' + imageData;
|
|
|
|
|
|
|
|
|
|
this.capturedImage = 'data:image/png;base64,'+imageData;
|
|
|
|
|
this.capturedImageTitle = new Date().getTime() + '.jpeg';
|
|
|
|
|
}, (err) => {
|
|
|
|
|
/* console.log(err); */
|
|
|
|
|
});
|
|
|
|
|
let data = {
|
|
|
|
|
image:this.capturedImage,
|
|
|
|
|
name: this.capturedImageTitle
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return data;
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-13 12:37:58 +01:00
|
|
|
loadPicture() {
|
|
|
|
|
const input = this.fileLoaderService.createInput({
|
|
|
|
|
accept: ['image/apng', 'image/jpeg', 'image/png']
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
input.onchange = async () => {
|
|
|
|
|
const file = this.fileLoaderService.getFirstFile(input)
|
|
|
|
|
|
|
|
|
|
console.log(file);
|
|
|
|
|
|
|
|
|
|
const imageData = await this.fileToBase64Service.convert(file)
|
|
|
|
|
this.capturedImage = imageData;
|
|
|
|
|
this.capturedImageTitle = file.name;
|
|
|
|
|
|
|
|
|
|
let data = {
|
|
|
|
|
image:this.capturedImage,
|
|
|
|
|
name: this.capturedImageTitle
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return data;
|
|
|
|
|
};
|
|
|
|
|
}
|
2021-09-14 15:57:24 +01:00
|
|
|
|
2021-09-21 14:05:59 +01:00
|
|
|
addCameraPictureToChat(roomId){
|
2021-10-08 15:37:24 +01:00
|
|
|
|
|
|
|
|
const options: CameraOptions = {
|
|
|
|
|
quality: 50,
|
|
|
|
|
destinationType: this.camera.DestinationType.DATA_URL,
|
|
|
|
|
encodingType: this.camera.EncodingType.JPEG,
|
|
|
|
|
mediaType: this.camera.MediaType.PICTURE,
|
|
|
|
|
targetWidth: 720,
|
|
|
|
|
targetHeight: 720,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.camera.getPicture(options).then((imageData) => {
|
|
|
|
|
this.capturedImage = 'data:image/png;base64,'+imageData;
|
|
|
|
|
this.capturedImageTitle = new Date().getTime() + '.jpeg';
|
|
|
|
|
|
2021-09-21 14:05:59 +01:00
|
|
|
let body = {
|
|
|
|
|
"message":
|
|
|
|
|
{
|
|
|
|
|
"rid": roomId,
|
|
|
|
|
"msg": "",
|
|
|
|
|
"attachments": [{
|
2021-10-08 15:37:24 +01:00
|
|
|
"title": this.capturedImageTitle,
|
2021-09-21 14:05:59 +01:00
|
|
|
"title_link_download": false,
|
2021-10-08 15:37:24 +01:00
|
|
|
"image_url": this.capturedImage,
|
2021-09-21 14:05:59 +01:00
|
|
|
}]
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-10-08 15:37:24 +01:00
|
|
|
const loader = this.toastService.loading();
|
2021-09-21 14:05:59 +01:00
|
|
|
this.chatService.sendMessage(body).subscribe(res=> {
|
|
|
|
|
console.log(res);
|
2021-10-08 15:37:24 +01:00
|
|
|
loader.remove();
|
2021-09-21 14:05:59 +01:00
|
|
|
},(error) => {
|
2021-10-08 15:37:24 +01:00
|
|
|
loader.remove();
|
|
|
|
|
this.toastService.badRequest("Não foi possível adicionar a fotografia!");
|
2021-09-21 14:05:59 +01:00
|
|
|
});
|
2021-10-08 15:37:24 +01:00
|
|
|
|
|
|
|
|
}, (err) => {
|
2021-09-21 14:05:59 +01:00
|
|
|
this.toastService.badRequest("Não foi possível adicionar a fotografia!");
|
2021-10-08 15:37:24 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
addPictureToChatMobile(roomId) {
|
|
|
|
|
alert('Here')
|
|
|
|
|
|
|
|
|
|
const options: CameraOptions = {
|
|
|
|
|
quality: 90,
|
|
|
|
|
sourceType: this.camera.PictureSourceType.PHOTOLIBRARY,
|
|
|
|
|
destinationType: this.camera.DestinationType.DATA_URL,
|
|
|
|
|
encodingType: this.camera.EncodingType.JPEG,
|
|
|
|
|
mediaType: this.camera.MediaType.PICTURE,
|
|
|
|
|
targetWidth: 720,
|
|
|
|
|
targetHeight: 720,
|
|
|
|
|
correctOrientation: true
|
2021-09-21 14:05:59 +01:00
|
|
|
}
|
2021-10-08 15:37:24 +01:00
|
|
|
|
|
|
|
|
this.camera.getPicture(options).then((imageData) => {
|
|
|
|
|
let base64Image = 'data:image/jpeg;base64,' + imageData;
|
|
|
|
|
this.capturedImage = imageData;
|
|
|
|
|
this.capturedImageTitle = new Date().getTime() + '.jpeg';
|
|
|
|
|
|
|
|
|
|
//const loader = this.toastService.loading();
|
|
|
|
|
|
|
|
|
|
let body = {
|
|
|
|
|
"message":
|
|
|
|
|
{
|
|
|
|
|
"rid": roomId,
|
|
|
|
|
"msg": "",
|
|
|
|
|
"attachments": [{
|
|
|
|
|
//"title": this.capturedImageTitle ,
|
|
|
|
|
//"text": "description",
|
|
|
|
|
"title_link_download": false,
|
|
|
|
|
"image_url": this.capturedImage,
|
|
|
|
|
}]
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
console.log(this.capturedImage)
|
|
|
|
|
|
|
|
|
|
this.chatService.sendMessage(body).subscribe(res=> {
|
|
|
|
|
//loader.remove();
|
|
|
|
|
//console.log(res);
|
|
|
|
|
},(error) => {
|
|
|
|
|
//loader.remove();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}, (err) => {
|
|
|
|
|
//console.log(err);
|
|
|
|
|
});
|
|
|
|
|
|
2021-09-21 14:05:59 +01:00
|
|
|
}
|
|
|
|
|
|
2021-10-07 15:30:36 +01:00
|
|
|
addPictureToChat(roomId) {
|
2021-10-08 15:37:24 +01:00
|
|
|
|
2021-09-21 14:05:59 +01:00
|
|
|
const input = this.fileLoaderService.createInput({
|
|
|
|
|
accept: ['image/apng', 'image/jpeg', 'image/png']
|
|
|
|
|
})
|
|
|
|
|
|
2021-10-08 15:37:24 +01:00
|
|
|
|
|
|
|
|
setInterval(()=>{
|
|
|
|
|
console.log(input.value)
|
|
|
|
|
}, 550)
|
|
|
|
|
|
|
|
|
|
|
2021-09-21 14:05:59 +01:00
|
|
|
input.onchange = async () => {
|
|
|
|
|
|
2021-10-08 15:37:24 +01:00
|
|
|
alert('Onchange AQUI')
|
|
|
|
|
|
2021-09-21 14:05:59 +01:00
|
|
|
const file = this.fileLoaderService.getFirstFile(input)
|
|
|
|
|
|
|
|
|
|
console.log(file);
|
|
|
|
|
const loader = this.toastService.loading();
|
|
|
|
|
|
|
|
|
|
const imageData = await this.fileToBase64Service.convert(file)
|
|
|
|
|
this.capturedImage = imageData;
|
|
|
|
|
this.capturedImageTitle = file.name;
|
|
|
|
|
|
|
|
|
|
let body = {
|
|
|
|
|
"message":
|
|
|
|
|
{
|
|
|
|
|
"rid": roomId,
|
|
|
|
|
"msg": "",
|
|
|
|
|
"attachments": [{
|
|
|
|
|
//"title": this.capturedImageTitle ,
|
|
|
|
|
//"text": "description",
|
|
|
|
|
"title_link_download": false,
|
|
|
|
|
"image_url": this.capturedImage,
|
|
|
|
|
}]
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-07 15:30:36 +01:00
|
|
|
console.log(this.capturedImage)
|
|
|
|
|
|
2021-09-21 14:05:59 +01:00
|
|
|
this.chatService.sendMessage(body).subscribe(res=> {
|
|
|
|
|
loader.remove();
|
|
|
|
|
//console.log(res);
|
|
|
|
|
},(error) => {
|
|
|
|
|
loader.remove();
|
|
|
|
|
});
|
|
|
|
|
//console.log(this.capturedImage)
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
addDocumentToChat(roomId:string) {
|
|
|
|
|
const input = this.fileLoaderService.createInput({
|
|
|
|
|
accept: ['.doc', '.docx', '.pdf']
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
input.onchange = async () => {
|
|
|
|
|
const loader = this.toastService.loading();
|
|
|
|
|
const file = this.fileLoaderService.getFirstFile(input)
|
|
|
|
|
|
|
|
|
|
console.log(file);
|
|
|
|
|
|
2021-10-06 17:27:49 +01:00
|
|
|
const formData = new FormData();
|
|
|
|
|
formData.append('file', file, file.name);
|
2021-09-21 14:05:59 +01:00
|
|
|
|
2021-10-06 17:27:49 +01:00
|
|
|
this.chatService.uploadFile(formData, roomId).subscribe(res=> {
|
|
|
|
|
console.log(res);
|
2021-09-21 14:05:59 +01:00
|
|
|
loader.remove();
|
|
|
|
|
},(error) => {
|
|
|
|
|
loader.remove();
|
|
|
|
|
});
|
|
|
|
|
//console.log(this.capturedImage)
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async addDocGestaoDocumentalToChat(roomId:string){
|
|
|
|
|
const modal = await this.modalController.create({
|
|
|
|
|
component: SearchPage,
|
|
|
|
|
cssClass: 'group-messages modal-desktop search-modal search-modal-to-desktop',
|
|
|
|
|
componentProps: {
|
|
|
|
|
type: 'AccoesPresidenciais & ArquivoDespachoElect',
|
|
|
|
|
select: true,
|
|
|
|
|
showSearchInput: true,
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
await modal.present();
|
|
|
|
|
modal.onDidDismiss().then(async res=>{
|
2021-09-23 12:13:20 +01:00
|
|
|
const data = res.data;
|
|
|
|
|
|
|
|
|
|
if(data.selected){
|
2021-09-21 14:05:59 +01:00
|
|
|
const loader = this.toastService.loading();
|
2021-09-23 12:13:20 +01:00
|
|
|
|
2021-09-21 14:05:59 +01:00
|
|
|
this.documents.push(data.selected);
|
|
|
|
|
console.log(res.data.selected);
|
|
|
|
|
console.log(res.data.selected.Id);
|
|
|
|
|
console.log(res.data.selected.ApplicationType);
|
|
|
|
|
|
|
|
|
|
let url = await this.processesService.GetDocumentUrl(res.data.selected.Id, res.data.selected.ApplicationType).toPromise();
|
|
|
|
|
let url_no_options: string = url.replace("webTRIX.Viewer","webTRIX.Viewer.Branch1");
|
|
|
|
|
console.log(url_no_options);
|
|
|
|
|
console.log('Oie');
|
|
|
|
|
|
|
|
|
|
let body = {
|
|
|
|
|
"message":
|
|
|
|
|
{
|
|
|
|
|
"rid": roomId,
|
|
|
|
|
"msg": "",
|
|
|
|
|
"attachments": [{
|
|
|
|
|
"title": res.data.selected.Assunto,
|
2021-09-23 12:13:20 +01:00
|
|
|
"description": res.data.selected.DocTypeDesc,
|
2021-09-21 14:05:59 +01:00
|
|
|
"title_link": url_no_options,
|
|
|
|
|
"title_link_download": true,
|
2021-09-23 12:13:20 +01:00
|
|
|
//"thumb_url": "assets/images/webtrix-logo.png",
|
2021-09-21 14:05:59 +01:00
|
|
|
"message_link": url_no_options,
|
2021-10-05 16:29:33 +01:00
|
|
|
"type": "webtrix"
|
2021-09-23 12:13:20 +01:00
|
|
|
}],
|
|
|
|
|
"file":{
|
|
|
|
|
"name": res.data.selected.Assunto,
|
|
|
|
|
"type": "application/webtrix"
|
|
|
|
|
}
|
2021-09-21 14:05:59 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
this.chatService.sendMessage(body).subscribe(res=> {
|
|
|
|
|
loader.remove();
|
|
|
|
|
console.log(res);
|
|
|
|
|
},(error) => {
|
|
|
|
|
loader.remove();
|
|
|
|
|
});
|
2021-09-23 12:13:20 +01:00
|
|
|
loader.remove();
|
2021-09-21 14:05:59 +01:00
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-14 15:57:24 +01:00
|
|
|
viewDocumentByUrl(url) {
|
2021-10-05 16:29:33 +01:00
|
|
|
const browser = this.iab.create(url,"_blank");
|
2021-09-14 15:57:24 +01:00
|
|
|
browser.show();
|
|
|
|
|
}
|
2021-09-13 12:37:58 +01:00
|
|
|
}
|