Merge branch 'feature/viewer-attachment' of https://bitbucket.org/equilibriumito/gabinete-digital-fo into feature/viewer-attachment

This commit is contained in:
Eudes Inácio
2024-03-18 13:01:39 +01:00
3866 changed files with 1962980 additions and 289 deletions
@@ -9,9 +9,9 @@
{{filename}}
</div>
<div *ngIf=" task || Document" class="right cursor-pointer" (click)="openOptions()">
<!-- <div *ngIf=" task || Document" class="right cursor-pointer" (click)="openOptions()">
<fa-icon icon="ellipsis-v" class="menu-icon font-awesome-1"></fa-icon>
</div>
</div> -->
</div>
</ion-toolbar>
@@ -1161,7 +1161,7 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy {
}
async openFile(pdfString, filename, type) {
const modal = await this.modalController.create({
/* const modal = await this.modalController.create({
component: ViewDocumentSecondOptionsPage,
componentProps: {
fileUrl: pdfString,
@@ -1169,8 +1169,8 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy {
},
cssClass: 'modal modal-desktop'
});
await modal.present();
/* const blob = this.b64toBlob(pdfString, type)
await modal.present(); */
const blob = this.b64toBlob(pdfString, type)
let pathFile = ''
const fileName = filename
const contentFile = blob
@@ -1180,17 +1180,23 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy {
pathFile = this.file.externalRootDirectory
}
console.log('file data', pdfString)
console.log(pathFile)
let removePre = this.removeTextBeforeSlash(pdfString,',')
console.log('file data remove ', removePre)
await Filesystem.writeFile({
path: fileName,
data: pdfString,
directory: Directory.Data,
data: removePre,
directory: Directory.Cache,
}).then((dir) => {
console.log('DIR ', dir)
this.fileOpener
.open(dir.uri, type)
.then(() => console.log())
.catch(e => console.error(e))
}); */
});
}
downloadFileMsg(msg: MessageService) {
@@ -1327,6 +1333,16 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy {
reject(error);
};
});
}
removeTextBeforeSlash(inputString, controlString) {
if (inputString.includes(controlString)) {
const parts = inputString.split(controlString);
return parts.length > 1 ? parts[1] : inputString;
} else {
return inputString;
}
}
}
+7 -6
View File
@@ -857,7 +857,8 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy {
console.log('ios add file ')
const resultt = await FilePicker.pickFiles({
types: ['application/pdf'],
types: ['application/pdf', 'application/doc', 'application/docx','application/xls', 'application/xlsx', 'application/ppt',
'application/pptx', 'application/txt'],
multiple: false,
readData: true,
});
@@ -865,6 +866,7 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy {
console.log('RESULT', resultt.files[0].data)
const blobb = this.fileService.base64toBlob(resultt.files[0].data, resultt.files[0].mimeType)
const blob = new Blob([resultt.files[0].data], {type: resultt.files[0].mimeType});
const formDataa = new FormData();
formDataa.append('blobFile', blobb);
@@ -1118,7 +1120,7 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy {
console.log('url while open ',pdfString)
const modal = await this.modalController.create({
/* const modal = await this.modalController.create({
component: ViewDocumentSecondOptionsPage,
componentProps: {
fileUrl: pdfString,
@@ -1126,8 +1128,8 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy {
},
cssClass: 'modal modal-desktop'
});
await modal.present();
/*
await modal.present(); */
var blob = new Blob([pdfString], { type: 'application/pdf' });
console.log('blob blob', blob)
@@ -1156,7 +1158,6 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy {
path: fileName,
data: removePre,
directory: Directory.Cache,
encoding: Encoding.UTF8
}).then((dir) => {
console.log('DIR ', dir)
this.fileOpener
@@ -1165,7 +1166,7 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy {
.catch(e => console.error(e))
}).catch((error) => {
console.log('error writing the file', error)
}); */
});
}
removeTextBeforeSlash(inputString, controlString) {
+8 -5
View File
@@ -446,6 +446,8 @@ export class MessageService {
this.downloadLoader = true;
let downloadFile = "";
let downloadUrl = "";
this.AttachmentsService.downloadFile(this.file.guid).subscribe(async (event) => {
console.log('download file',event)
@@ -456,10 +458,10 @@ export class MessageService {
if (this.file.type == "application/img") {
downloadFile = 'data:image/jpeg;base64,' + btoa(new Uint8Array(event.body).reduce((data, byte) => data + String.fromCharCode(byte), ''));
} else if (this.file.type != "application/img") {
downloadFile = event.url
/*
let */
/* downloadFile = btoa(new Uint8Array(event.body).reduce((data, byte) => data + String.fromCharCode(byte), '')); */
downloadFile = btoa(new Uint8Array(event.body).reduce((data, byte) => data + String.fromCharCode(byte), ''));
downloadUrl = event.url
console.log('downloaded file', downloadFile)
console.log('event body downloaded file', event.url)
@@ -471,7 +473,8 @@ export class MessageService {
title: this.attachments[0].title,
title_link: downloadFile,
title_link_download: this.attachments[0].title_link_download,
ts: this.attachments[0].ts
ts: this.attachments[0].ts,
attachmentsUrl: downloadUrl
}
// save the changes to the storage
@@ -900,7 +900,7 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe
fileBase64 = await this._getBase64(file)
formData = new FormData();
formData.append('blobFile', blob);
formData.append('blobFile', file);
}
this.ChatSystemService.getGroupRoom(roomId).send({
@@ -1034,11 +1034,12 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe
}
downloadFileFromBrowser(fileName: string, data: any): void {
const linkSource = data;
const downloadLink = document.createElement("a");
downloadLink.href = linkSource;
downloadLink.download = fileName;
downloadLink.click();
const link = document.createElement("a")
link.href = `data:${data.type}';base64,${data.image_url}`;
link.download = fileName
link.click()
link.remove()
}
b64toBlob(b64Data, contentType) {
@@ -1120,10 +1121,10 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe
});
modal.present();
} else {
this.downloadFileFromBrowser("file", str)
this.downloadFileFromBrowser(msg.attachments[0].title, msg.attachments[0])
}
} else {
this.openFile(str, msg.attachments[0].title, msg.file.type);
this.openFile(msg.attachments.image_url, msg.attachments[0].title, msg.file.type);
}
}
+15 -11
View File
@@ -35,6 +35,7 @@ import { ChatMessageDebuggingPage } from 'src/app/shared/popover/chat-message-de
import { PermissionService } from 'src/app/services/permission.service';
import { FileValidatorService } from "src/app/services/file/file-validator.service"
import { ChangeDetectorRef } from '@angular/core';
import { saveAs } from 'file-saver';
const IMAGE_DIR = 'stored-images';
@@ -141,7 +142,7 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
this.ChatSystemService.openRoom(this.roomId)
this.ChatSystemService.getDmRoom(this.roomId)
this.ChatSystemService.getDmRoom(this.roomId).setChangeDetector(()=> {
this.ChatSystemService.getDmRoom(this.roomId).setChangeDetector(() => {
this.changeDetector()
})
@@ -712,7 +713,7 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
source: CameraSource.Camera
});
console.log('FILE CHAT',file)
console.log('FILE CHAT', file)
const imageBase64 = 'data:image/jpeg;base64,' + file.base64String
const blob = this.dataURItoBlob(imageBase64)
@@ -861,7 +862,7 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
file.type == 'application/xls' || file.type == 'application/xlsx' || file.type == 'application/ppt' ||
file.type == 'application/pptx' || file.type == 'application/txt') {
console.log('FILE', file)
console.log('FILE rigth?', file)
const fileName = file.name
@@ -886,12 +887,13 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
/* console.log('add file', fileBase64) */
} else {
console.log('encode data', encodedData)
blob = this.fileService.base64toBlob(encodedData, file.type)
fileBase64 = await this._getBase64(file)
formData = new FormData();
formData.append('blobFile', blob);
formData.append('blobFile', file);
}
@@ -1092,11 +1094,13 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
}
downloadFileFromBrowser(fileName: string, data: any): void {
const linkSource = data;
const downloadLink = document.createElement("a");
downloadLink.href = linkSource;
downloadLink.download = fileName;
downloadLink.click();
const link = document.createElement("a")
link.href = `data:${data.type}';base64,${data.image_url}`;
link.download = fileName
link.click()
link.remove()
}
viewDocument(file: any, url?: string) {
@@ -1164,12 +1168,12 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
});
modal.present();
} else {
this.downloadFileFromBrowser("file", str)
this.downloadFileFromBrowser(msg.attachments[0].title, msg.attachments[0],)
}
} else {
this.openFile(str, msg.attachments[0].title, msg.file.type);
this.openFile(msg.attachments[0].image_url, msg.attachments[0].title, msg.file.type);
// this.downloadFileFromBrowser("file", str)
}