mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-19 04:57:52 +00:00
save
This commit is contained in:
@@ -2,14 +2,14 @@ import { Injectable } from '@angular/core';
|
||||
import { FileLoaderService } from '../file/file-loader.service';
|
||||
import { FileToBase64Service } from '../file/file-to-base64.service';
|
||||
import { InAppBrowser } from '@ionic-native/in-app-browser/ngx';
|
||||
//Cordova
|
||||
import { Camera, CameraOptions } from '@ionic-native/camera/ngx';
|
||||
|
||||
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';
|
||||
import { Camera, CameraResultType, CameraSource, Photo} from '@capacitor/camera';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
@@ -22,9 +22,9 @@ export class FileService {
|
||||
showLoader: boolean;
|
||||
|
||||
files: Set<File>;
|
||||
photos: any[] = [];
|
||||
|
||||
constructor(
|
||||
private camera: Camera,
|
||||
private fileLoaderService: FileLoaderService,
|
||||
private fileToBase64Service: FileToBase64Service,
|
||||
private iab: InAppBrowser,
|
||||
@@ -34,26 +34,25 @@ export class FileService {
|
||||
private toastService: ToastService,
|
||||
) { }
|
||||
|
||||
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,
|
||||
}
|
||||
async takePicture() {
|
||||
const capturedImage = await Camera.getPhoto({
|
||||
quality: 90,
|
||||
// allowEditing: true,
|
||||
resultType: CameraResultType.Uri,
|
||||
source: CameraSource.Camera
|
||||
|
||||
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); */
|
||||
});
|
||||
const response = await fetch(capturedImage.webPath!);
|
||||
const blob = await response.blob();
|
||||
|
||||
this.photos.unshift({
|
||||
filepath: "soon...",
|
||||
webviewPath: capturedImage.webPath
|
||||
});
|
||||
|
||||
this.capturedImage = await this.convertBlobToBase64(blob);
|
||||
this.capturedImageTitle = new Date().getTime() + '.jpeg';
|
||||
|
||||
let data = {
|
||||
image:this.capturedImage,
|
||||
name: this.capturedImageTitle
|
||||
@@ -62,6 +61,15 @@ export class FileService {
|
||||
return data;
|
||||
}
|
||||
|
||||
convertBlobToBase64 = (blob: Blob) => new Promise((resolve, reject) => {
|
||||
const reader = new FileReader;
|
||||
reader.onerror = reject;
|
||||
reader.onload = () => {
|
||||
resolve(reader.result);
|
||||
};
|
||||
reader.readAsDataURL(blob);
|
||||
});
|
||||
|
||||
loadPicture() {
|
||||
const input = this.fileLoaderService.createInput({
|
||||
accept: ['image/apng', 'image/jpeg', 'image/png']
|
||||
@@ -85,19 +93,24 @@ export class FileService {
|
||||
};
|
||||
}
|
||||
|
||||
addCameraPictureToChat(roomId){
|
||||
async addCameraPictureToChat(roomId){
|
||||
|
||||
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,
|
||||
}
|
||||
const capturedImage = await Camera.getPhoto({
|
||||
quality: 90,
|
||||
// allowEditing: true,
|
||||
resultType: CameraResultType.Uri,
|
||||
source: CameraSource.Camera
|
||||
|
||||
this.camera.getPicture(options).then((imageData) => {
|
||||
this.capturedImage = 'data:image/png;base64,'+imageData;
|
||||
});
|
||||
const response = await fetch(capturedImage.webPath!);
|
||||
const blob = await response.blob();
|
||||
|
||||
this.photos.unshift({
|
||||
filepath: "soon...",
|
||||
webviewPath: capturedImage.webPath
|
||||
});
|
||||
|
||||
this.capturedImage = await this.convertBlobToBase64(blob);
|
||||
this.capturedImageTitle = new Date().getTime() + '.jpeg';
|
||||
|
||||
let body = {
|
||||
@@ -121,29 +134,26 @@ export class FileService {
|
||||
this.toastService.badRequest("Não foi possível adicionar a fotografia!");
|
||||
});
|
||||
|
||||
}, (err) => {
|
||||
this.toastService.badRequest("Não foi possível adicionar a fotografia!");
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
addPictureToChatMobile(roomId) {
|
||||
alert('Here')
|
||||
async addPictureToChatMobile(roomId) {
|
||||
|
||||
const options: CameraOptions = {
|
||||
const capturedImage = await Camera.getPhoto({
|
||||
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
|
||||
}
|
||||
// allowEditing: true,
|
||||
resultType: CameraResultType.Uri,
|
||||
source: CameraSource.Camera
|
||||
|
||||
this.camera.getPicture(options).then((imageData) => {
|
||||
let base64Image = 'data:image/jpeg;base64,' + imageData;
|
||||
this.capturedImage = imageData;
|
||||
});
|
||||
const response = await fetch(capturedImage.webPath!);
|
||||
const blob = await response.blob();
|
||||
|
||||
this.photos.unshift({
|
||||
filepath: "soon...",
|
||||
webviewPath: capturedImage.webPath
|
||||
});
|
||||
|
||||
this.capturedImage = await this.convertBlobToBase64(blob);
|
||||
this.capturedImageTitle = new Date().getTime() + '.jpeg';
|
||||
|
||||
//const loader = this.toastService.loading();
|
||||
@@ -161,21 +171,12 @@ export class FileService {
|
||||
}]
|
||||
}
|
||||
}
|
||||
|
||||
console.log(this.capturedImage)
|
||||
|
||||
this.chatService.sendMessage(body).subscribe(res=> {
|
||||
//loader.remove();
|
||||
//console.log(res);
|
||||
},(error) => {
|
||||
//loader.remove();
|
||||
});
|
||||
|
||||
|
||||
}, (err) => {
|
||||
//console.log(err);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
addPictureToChat(roomId) {
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<div class="main-header">
|
||||
<div class="header-top">
|
||||
<div class="middle" *ngFor="let users of dmUsers">
|
||||
<ion-label class="title">{{users.name}}11</ion-label>
|
||||
<ion-label class="title">{{users.name}}</ion-label>
|
||||
<span><ion-icon class="{{users.status}}" name="ellipse"></ion-icon></span>
|
||||
</div>
|
||||
<div hidden class="right">
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
</button>
|
||||
</div>
|
||||
<div class="buttons">
|
||||
<button hidden (click)="takePicture()" full class="btn-ok" shape="round" >Tirar Fotografia</button>
|
||||
<button (click)="takePicture()" full class="btn-ok" shape="round" >Tirar Fotografia</button>
|
||||
<button hidden (click)="addFile()" class="btn-ok" shape="round" >Anexar Documento</button>
|
||||
<button hidden (click)="anexarFoto()" full class="btn-ok" shape="round" >Anexar Fotografia</button>
|
||||
<button (click)="addDocGestaoDocumental()" class="btn-ok" shape="round" >Gestão Documental</button>
|
||||
|
||||
@@ -27,7 +27,6 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="picture d-flex pb-5 hide-desktop" *ngIf="publication.FileBase64 && capturedImage ==''">
|
||||
<div class="post-img">
|
||||
<img src="{{publication.FileBase64}}" alt="image" >
|
||||
@@ -84,7 +83,6 @@
|
||||
|
||||
</ion-content>
|
||||
|
||||
|
||||
<ion-footer class="ion-no-border">
|
||||
<ion-toolbar class="footer-toolbar width-100 px-20">
|
||||
<ion-buttons slot="start">
|
||||
|
||||
Reference in New Issue
Block a user