From af4524a2013cbeff078bf8c8fb2aacc38ee04873 Mon Sep 17 00:00:00 2001 From: "tiago.kayaya" Date: Tue, 9 Nov 2021 10:13:48 +0100 Subject: [PATCH] save --- package-lock.json | 5 ++ package.json | 1 + .../new-publication/new-publication.page.html | 4 +- .../new-publication/new-publication.page.ts | 85 ++++++++++--------- 4 files changed, 55 insertions(+), 40 deletions(-) diff --git a/package-lock.json b/package-lock.json index 5d2bbde89..40dacf83c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2040,6 +2040,11 @@ "resolved": "https://registry.npmjs.org/@capacitor/app/-/app-1.0.5.tgz", "integrity": "sha512-U0dAw1CAjKyguSRxKDabszsQ4dj679RnxaUZrSHDR5Jnt5x308oQuKXFP++wnMBbw72D02iqjG0a+/Ujye7C9g==" }, + "@capacitor/camera": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/@capacitor/camera/-/camera-1.2.0.tgz", + "integrity": "sha512-NAIGWnyHBGQ/dgla/D4KDkAeQ2f3fzw+D+DIkGNH3f1ciX4bXC7lNbDVU67SMOuNt+CmcTJF64q3nVXcpv5JvQ==" + }, "@capacitor/cli": { "version": "3.3.0", "resolved": "https://registry.npmjs.org/@capacitor/cli/-/cli-3.3.0.tgz", diff --git a/package.json b/package.json index d7e90f259..ee8d66bc4 100644 --- a/package.json +++ b/package.json @@ -33,6 +33,7 @@ "@angular/router": "~12.1.2", "@capacitor/android": "^3.3.0", "@capacitor/app": "^1.0.5", + "@capacitor/camera": "^1.2.0", "@capacitor/core": "^3.3.0", "@capacitor/filesystem": "^1.0.6", "@capacitor/haptics": "^1.1.3", diff --git a/src/app/pages/publications/new-publication/new-publication.page.html b/src/app/pages/publications/new-publication/new-publication.page.html index c010cc1ad..73ea9fe25 100644 --- a/src/app/pages/publications/new-publication/new-publication.page.html +++ b/src/app/pages/publications/new-publication/new-publication.page.html @@ -34,7 +34,9 @@

{{capturedImageTitle}}

- +
+ +
diff --git a/src/app/pages/publications/new-publication/new-publication.page.ts b/src/app/pages/publications/new-publication/new-publication.page.ts index a314b4e99..4130ecae9 100644 --- a/src/app/pages/publications/new-publication/new-publication.page.ts +++ b/src/app/pages/publications/new-publication/new-publication.page.ts @@ -9,15 +9,14 @@ import { Image } from 'src/app/models/image'; import { PhotoService } from 'src/app/services/photo.service'; //Capacitor -//Cordova -import { Camera, CameraOptions } from '@ionic-native/camera/ngx'; import { ToastService } from 'src/app/services/toast.service'; import { FormControl, FormGroup, Validators } from '@angular/forms'; import { ThemePalette } from '@angular/material/core'; import { formatDate } from 'src/plugin/momentG.js' import { FileLoaderService } from 'src/app/services/file/file-loader.service'; import { FileToBase64Service } from 'src/app/services/file/file-to-base64.service'; -import { ThemeService } from 'src/app/services/theme.service' +import { ThemeService } from 'src/app/services/theme.service'; +import { Camera, CameraResultType, CameraSource, Photo} from '@capacitor/camera'; @Component({ selector: 'app-new-publication', @@ -59,21 +58,21 @@ export class NewPublicationPage implements OnInit { guestPicture:any; - capturedImage:any; + capturedImage:any = ''; capturedImageTitle:any; + public photos: any[] = []; constructor( private modalController: ModalController, public photoService: PhotoService, private navParams: NavParams, private publications: PublicationsService, - private camera: Camera, private toastService: ToastService, private fileLoaderService: FileLoaderService, private fileToBase64Service: FileToBase64Service, public ThemeService: ThemeService ) { - + this.publicationType = this.navParams.get('publicationType'); this.folderId = this.navParams.get('folderId'); this.publicationTitle = 'Nova Publicação'; @@ -81,38 +80,46 @@ export class NewPublicationPage implements OnInit { ngOnInit() { this.setTitle(); - this.clear(); // this.takePicture(); } - 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); + + //console.log(this.capturedImage); + } + convertBlobToBase64 = (blob: Blob) => new Promise((resolve, reject) => { + const reader = new FileReader; + reader.onerror = reject; + reader.onload = () => { + resolve(reader.result); + }; + reader.readAsDataURL(blob); + }); + laodPicture() { const input = this.fileLoaderService.createInput({ accept: ['image/apng', 'image/jpeg', 'image/png'] }) - + input.onchange = async () => { const file = this.fileLoaderService.getFirstFile(input) @@ -125,7 +132,7 @@ export class NewPublicationPage implements OnInit { } - getPicture() { + /* getPicture() { const options: CameraOptions = { quality: 90, sourceType: this.camera.PictureSourceType.PHOTOLIBRARY, @@ -143,9 +150,9 @@ export class NewPublicationPage implements OnInit { this.capturedImage = imageData; this.capturedImageTitle = new Date().getTime() + '.jpeg'; }, (err) => { - /* console.log(err); */ + console.log(err); }); - } + } */ runValidation() { this.validateFrom = true @@ -168,19 +175,19 @@ export class NewPublicationPage implements OnInit { ]) }) } - + async save() { - + this.injectValidation() this.runValidation() if(this.Form.invalid) return false - + if(this.publicationType == '3') { console.log(this.navParams.get('publication')); - + if(this.capturedImage != '') { this.publication = { DateIndex: this.publication.DateIndex, @@ -198,7 +205,7 @@ export class NewPublicationPage implements OnInit { try { console.log(this.publication); - + await this.publications.UpdatePublication(this.publication.ProcessId, this.publication).toPromise() this.toastService.successMessage("Publicação criado") @@ -232,7 +239,7 @@ export class NewPublicationPage implements OnInit { console.log(this.publication); await this.publications.UpdatePublication(this.publication.ProcessId, this.publication).toPromise() this.toastService.successMessage("Publicação criado") - + this.close(); } catch (error) { this.toastService.badRequest("Publicação não criado") @@ -294,7 +301,7 @@ export class NewPublicationPage implements OnInit { await this.publications.CreatePublication(this.folderId, this.publication).toPromise(); this.close(); this.toastService.successMessage("Publicação criado") - + this.close(); } catch (error) { @@ -312,7 +319,7 @@ export class NewPublicationPage implements OnInit { this.showLoader=true; }); } - + clear() { this.capturedImage = ''; } @@ -352,8 +359,8 @@ export class NewPublicationPage implements OnInit { source: CameraSource.Camera }); console.log(image); - + this.photo = this.sanitizer.bypassSecurityTrustResourceUrl(image && (image.dataUrl)); } */ -} \ No newline at end of file +}