Files
doneit-web/src/app/pages/publications/new-publication/new-publication.page.ts
T

233 lines
6.3 KiB
TypeScript
Raw Normal View History

import { Component, OnInit } from '@angular/core';
import { AlertController, ModalController, NavParams } from '@ionic/angular';
import { GalleryPage } from '../gallery/gallery.page';
/* import {Plugins, CameraResultType, CameraSource} from '@capacitor/core'; */
import { DomSanitizer, SafeResourceUrl } from '@angular/platform-browser';
import { PublicationsService } from 'src/app/services/publications.service';
import { Publication } from 'src/app/models/publication';
2020-12-10 11:22:06 +01:00
import { Image } from 'src/app/models/image';
2020-12-11 15:09:53 +01:00
import { ThrowStmt } from '@angular/compiler';
import { PhotoService } from 'src/app/services/photo.service';
import { AlertService } from 'src/app/services/alert.service';
/* const { Camera } = Plugins; */
import { Camera, CameraOptions } from '@ionic-native/camera/ngx';
@Component({
selector: 'app-new-publication',
templateUrl: './new-publication.page.html',
styleUrls: ['./new-publication.page.scss'],
})
export class NewPublicationPage implements OnInit {
publication: Publication;
pub: Publication = new Publication();
2020-12-10 11:22:06 +01:00
folderId: string;
image: Image = new Image();
publicationType:string;
publicationTitle:string;
imgUrl:any;
2020-12-10 11:22:06 +01:00
Defaultimage:any = '';
photo: SafeResourceUrl;
guestPicture:any;
2020-12-11 15:09:53 +01:00
capturedImage:any;
capturedImageTitle:any;
2020-12-11 15:09:53 +01:00
constructor(
private modalController: ModalController,
2020-12-11 15:09:53 +01:00
public photoService: PhotoService,
private navParams: NavParams,
private alertService: AlertService,
/* private camera: Camera, */
private sanitizer: DomSanitizer,
private publications: PublicationsService,
private camera: Camera,
) {
this.publicationType = this.navParams.get('publicationType');
2020-12-10 11:22:06 +01:00
this.folderId = this.navParams.get('folderId');
this.publicationTitle = 'Nova Publicação';
}
ngOnInit() {
this.setTitle();
2020-12-11 15:09:53 +01:00
this.clear();
}
2020-12-11 15:09:53 +01:00
takePictureCodova(){
const options: CameraOptions = {
quality: 100,
destinationType: this.camera.DestinationType.DATA_URL,
encodingType: this.camera.EncodingType.JPEG,
mediaType: this.camera.MediaType.PICTURE
}
this.camera.getPicture(options).then((imageData) => {
// imageData is either a base64 encoded string or a file URI
// If it's base64 (DATA_URL):
let base64Image = 'data:image/jpeg;base64,' + imageData;
this.capturedImage = imageData;
this.capturedImageTitle = new Date().getTime();
}, (err) => {
// Handle error
});
2020-12-11 15:09:53 +01:00
}
/* takePictureCapacitor() {
this.photoService.addNewToGallery();
this.pub.FileBase64 = this.photoService.photos[0].webviewPath;
console.log(this.pub.FileBase64);
} */
/* async takePictures() {
try {
const profilePicture = await Camera.getPhoto({
quality: 90,
allowEditing: false,
resultType: CameraResultType.Base64,
}).then(res =>{
console.log(res);
});
console.log(profilePicture);
this.guestPicture = "data:image/jpg;base64," + profilePicture.base64String;
} catch (error) {
console.error(error);
}
} */
2020-12-11 15:09:53 +01:00
async save(){
console.log(this.pub.FileBase64);
2020-12-10 11:22:06 +01:00
if(this.publicationType == '3'){
if(this.capturedImage != ''){
this.publication = {
DocumentId:this.publication.DocumentId,
ProcessId:this.publication.ProcessId,
Title: this.pub.Title,
Message: this.pub.Message,
DatePublication: this.publication.DatePublication,
OriginalFileName: this.capturedImageTitle,
FileBase64: this.capturedImage,
FileExtension: 'jpg',
}
2020-12-10 11:22:06 +01:00
}
else{
this.publication = {
DocumentId:this.publication.DocumentId,
ProcessId:this.publication.ProcessId,
Title: this.pub.Title,
Message: this.pub.Message,
DatePublication: this.publication.DatePublication,
OriginalFileName: '',
FileBase64: this.publication.FileBase64,
FileExtension: 'jpg',
}
}
2020-12-10 11:22:06 +01:00
console.log('Edit');
console.log(this.publication);
2020-12-11 15:09:53 +01:00
this.publications.UpdatePublication(this.publication.ProcessId, this.publication);
this.close();
}
else{
2020-12-11 15:09:53 +01:00
2020-12-10 11:22:06 +01:00
this.publication = {
2020-12-11 15:09:53 +01:00
DocumentId:null,
ProcessId:this.folderId,
Title: this.pub.Title,
Message: this.pub.Message,
DatePublication: new Date(),
OriginalFileName: this.capturedImageTitle,
FileBase64: this.capturedImage,
2020-12-11 15:09:53 +01:00
FileExtension: 'jpg',
2020-12-10 11:22:06 +01:00
}
2020-12-10 11:22:06 +01:00
console.log('Create');
console.log(this.publication);
this.publications.CreatePublication(this.folderId, this.publication);
2020-12-11 15:09:53 +01:00
this.close();
}
}
close(){
this.modalController.dismiss();
}
2020-12-11 15:09:53 +01:00
clear(){
this.capturedImage = '';
2020-12-11 15:09:53 +01:00
}
setTitle(){
if(this.publicationType == '1'){
2020-12-10 11:22:06 +01:00
this.publicationTitle = 'Nova Publicação Rápida';
}
else if(this.publicationType == '2'){
2020-12-10 11:22:06 +01:00
this.publicationTitle = 'Nova Publicação';
}
else if(this.publicationType == '3'){
this.publicationTitle = 'Editar Publicação';
this.pub = this.navParams.get('publication');
}
}
2020-12-11 15:09:53 +01:00
/* async openGallery() {
const modal = await this.modalController.create({
component: GalleryPage,
componentProps:{
},
cssClass: 'new-publication',
backdropDismiss: false
});
await modal.present();
modal.onDidDismiss();
2020-12-11 15:09:53 +01:00
} */
/* async takePicture(){
const image = await Plugins.Camera.getPhoto({
quality: 100,
allowEditing: false,
resultType: CameraResultType.DataUrl,
source: CameraSource.Camera
});
2020-12-11 15:09:53 +01:00
console.log(image);
this.photo = this.sanitizer.bypassSecurityTrustResourceUrl(image && (image.dataUrl));
} */
openCamera(){
/* this.camera.getPicture({
sourceType: this.camera.PictureSourceType.CAMERA,
destinationType: this.camera.DestinationType.FILE_URI,
}).then((res)=>{
this.imgUrl = res;
}).catch(e=>{
console.log(e);
});
console.log('camera'); */
}
getGallery(){
/* this.camera.getPicture({
sourceType: this.camera.PictureSourceType.PHOTOLIBRARY,
destinationType: this.camera.DestinationType.DATA_URL,
}).then((res)=>{
this.imgUrl = 'data:image/jpeg;base64,' + res;
}).catch(e=>{
console.log(e);
}); */
}
2020-12-11 15:09:53 +01:00
Add
}