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

185 lines
4.8 KiB
TypeScript
Raw Normal View History

import { Component, OnInit } from '@angular/core';
import { ModalController, NavParams } from '@ionic/angular';
import { GalleryPage } from '../gallery/gallery.page';
/* import { Camera } from '@ionic-native/camera/ngx'; */
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';
/* import { Camera } from '@ionic-native/camera/ngx'; */
/* const { Camera } = Plugins; */
@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;
constructor(
private modalController: ModalController,
private navParams: NavParams,
/* private camera: Camera, */
private sanitizer: DomSanitizer,
private publications: PublicationsService,
) {
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();
}
/* 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);
}
} */
save(){
2020-12-10 11:22:06 +01:00
if(this.publicationType == '3'){
this.image = {
title: this.image.title,
url: this.image.url,
format: 'png'
}
this.publication = {
publicationId:this.publication.publicationId,
processId:this.publication.processId,
title: this.publication.title,
description: this.publication.description,
date: this.publication.date,
2020-12-10 11:22:06 +01:00
/* image: this.image, */
imageTitle: '',
imageUrl: this.publication.imageUrl,
imageFormat: 'png',
}
2020-12-10 11:22:06 +01:00
console.log('Edit');
console.log(this.publication);
this.publications.UpdatePublication(this.publication.processId, this.publication);
}
else{
2020-12-10 11:22:06 +01:00
this.image = {
title: this.image.title,
url: this.image.url,
format: 'png'
}
this.publication = {
publicationId:null,
processId:this.folderId,
title: this.pub.title,
description: this.pub.description,
date: new Date(),
/* image: this.image, */
imageTitle: '',
imageUrl: '',
imageFormat: 'jpg',
}
2020-12-10 11:22:06 +01:00
console.log('Create');
console.log(this.publication);
this.publications.CreatePublication(this.folderId, this.publication);
}
}
close(){
this.modalController.dismiss();
}
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');
}
}
async openGallery() {
const modal = await this.modalController.create({
component: GalleryPage,
componentProps:{
},
cssClass: 'new-publication',
backdropDismiss: false
});
await modal.present();
modal.onDidDismiss();
}
async takePicture(){
const image = await Plugins.Camera.getPhoto({
quality: 100,
allowEditing: false,
resultType: CameraResultType.DataUrl,
source: CameraSource.Camera
});
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);
}); */
}
}