2020-12-01 14:03:15 +01:00
|
|
|
import { Component, OnInit } from '@angular/core';
|
2020-12-01 17:22:45 +01:00
|
|
|
import { ModalController, NavParams } from '@ionic/angular';
|
2020-12-02 15:08:45 +01:00
|
|
|
import { GalleryPage } from '../gallery/gallery.page';
|
2020-12-09 12:10:19 +01:00
|
|
|
/* 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';
|
|
|
|
|
/* import { Camera } from '@ionic-native/camera/ngx'; */
|
|
|
|
|
|
|
|
|
|
/* const { Camera } = Plugins; */
|
2020-12-01 14:03:15 +01:00
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
|
selector: 'app-new-publication',
|
|
|
|
|
templateUrl: './new-publication.page.html',
|
|
|
|
|
styleUrls: ['./new-publication.page.scss'],
|
|
|
|
|
})
|
|
|
|
|
export class NewPublicationPage implements OnInit {
|
2020-12-09 12:10:19 +01:00
|
|
|
publication: Publication;
|
|
|
|
|
pub: Publication = new Publication();
|
|
|
|
|
|
2020-12-01 17:22:45 +01:00
|
|
|
publicationType:string;
|
|
|
|
|
publicationTitle:string;
|
2020-12-09 12:10:19 +01:00
|
|
|
imgUrl:any;
|
|
|
|
|
|
|
|
|
|
photo: SafeResourceUrl;
|
|
|
|
|
|
|
|
|
|
guestPicture:any;
|
|
|
|
|
|
2020-12-01 17:22:45 +01:00
|
|
|
constructor(
|
|
|
|
|
private modalController: ModalController,
|
|
|
|
|
private navParams: NavParams,
|
2020-12-09 12:10:19 +01:00
|
|
|
/* private camera: Camera, */
|
|
|
|
|
private sanitizer: DomSanitizer,
|
|
|
|
|
private publications: PublicationsService,
|
2020-12-01 17:22:45 +01:00
|
|
|
) {
|
|
|
|
|
this.publicationType = this.navParams.get('publicationType');
|
|
|
|
|
this.publicationTitle = 'Nova Publicação';
|
|
|
|
|
}
|
2020-12-01 14:03:15 +01:00
|
|
|
|
|
|
|
|
ngOnInit() {
|
2020-12-01 17:22:45 +01:00
|
|
|
this.setTitle();
|
2020-12-09 12:10:19 +01:00
|
|
|
|
2020-12-01 17:22:45 +01:00
|
|
|
}
|
2020-12-09 12:10:19 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
/* 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-01 17:22:45 +01:00
|
|
|
save(){
|
2020-12-09 12:10:19 +01:00
|
|
|
if(this.publication.processId){
|
|
|
|
|
this.publication = {
|
|
|
|
|
publicationId:this.publication.publicationId,
|
|
|
|
|
processId:this.publication.processId,
|
|
|
|
|
title: this.publication.title,
|
|
|
|
|
description: this.publication.description,
|
|
|
|
|
imageUrl:this.publication.imageUrl,
|
|
|
|
|
date: this.publication.date,
|
|
|
|
|
}
|
|
|
|
|
console.log('Edit');
|
|
|
|
|
}
|
|
|
|
|
else{
|
|
|
|
|
console.log('Create');
|
|
|
|
|
|
|
|
|
|
}
|
2020-12-01 17:22:45 +01:00
|
|
|
}
|
2020-12-09 12:10:19 +01:00
|
|
|
|
|
|
|
|
|
2020-12-01 17:22:45 +01:00
|
|
|
close(){
|
|
|
|
|
this.modalController.dismiss();
|
|
|
|
|
}
|
|
|
|
|
setTitle(){
|
|
|
|
|
if(this.publicationType == '1'){
|
|
|
|
|
this.publicationTitle = 'Nova Publicação Rápida'
|
|
|
|
|
}
|
2020-12-02 15:08:45 +01:00
|
|
|
else if(this.publicationType == '2'){
|
2020-12-01 17:22:45 +01:00
|
|
|
this.publicationTitle = 'Nova Publicação'
|
|
|
|
|
}
|
2020-12-02 15:08:45 +01:00
|
|
|
else if(this.publicationType == '3'){
|
2020-12-09 12:10:19 +01:00
|
|
|
this.publicationTitle = 'Editar Publicação';
|
|
|
|
|
this.pub = this.navParams.get('publication');
|
|
|
|
|
|
|
|
|
|
|
2020-12-02 15:08:45 +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-01 14:03:15 +01:00
|
|
|
}
|
|
|
|
|
|
2020-12-09 12:10:19 +01:00
|
|
|
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);
|
|
|
|
|
}); */
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-01 14:03:15 +01:00
|
|
|
}
|