This commit is contained in:
tiago.kayaya
2021-11-09 10:13:48 +01:00
parent 6d24784991
commit af4524a201
4 changed files with 55 additions and 40 deletions
@@ -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));
} */
}
}