2020-12-01 14:03:15 +01:00
|
|
|
import { Component, OnInit } from '@angular/core';
|
2020-12-11 18:00:38 +01:00
|
|
|
import { AlertController, 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
|
|
|
|
2020-12-11 18:00:38 +01:00
|
|
|
/* import {Plugins, CameraResultType, CameraSource} from '@capacitor/core'; */
|
2020-12-09 12:10:19 +01:00
|
|
|
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';
|
2020-12-11 18:00:38 +01:00
|
|
|
import { AlertService } from 'src/app/services/alert.service';
|
2021-01-15 11:07:20 +01:00
|
|
|
//Capacitor
|
2020-12-11 18:00:38 +01:00
|
|
|
/* const { Camera } = Plugins; */
|
|
|
|
|
|
2021-01-15 11:07:20 +01:00
|
|
|
//Cordova
|
2021-02-09 13:16:41 +01:00
|
|
|
import { Camera, CameraOptions } from '@ionic-native/camera/ngx';
|
2020-12-15 19:37:42 +01:00
|
|
|
import { PublicationFolder } from 'src/app/models/publicationfolder';
|
|
|
|
|
import { ViewPublicationsPage } from '../view-publications/view-publications.page';
|
|
|
|
|
import { LoadingService } from 'src/app/services/loading.service';
|
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-15 19:37:42 +01:00
|
|
|
showLoader: boolean;
|
2020-12-09 12:10:19 +01:00
|
|
|
publication: Publication;
|
|
|
|
|
pub: Publication = new Publication();
|
2020-12-10 11:22:06 +01:00
|
|
|
folderId: string;
|
|
|
|
|
image: Image = new Image();
|
2020-12-09 12:10:19 +01:00
|
|
|
|
2020-12-01 17:22:45 +01:00
|
|
|
publicationType:string;
|
|
|
|
|
publicationTitle:string;
|
2020-12-09 12:10:19 +01:00
|
|
|
imgUrl:any;
|
|
|
|
|
|
2020-12-10 11:22:06 +01:00
|
|
|
Defaultimage:any = '';
|
|
|
|
|
|
|
|
|
|
|
2020-12-09 12:10:19 +01:00
|
|
|
photo: SafeResourceUrl;
|
|
|
|
|
|
|
|
|
|
guestPicture:any;
|
|
|
|
|
|
2020-12-11 15:09:53 +01:00
|
|
|
capturedImage:any;
|
2020-12-11 18:00:38 +01:00
|
|
|
capturedImageTitle:any;
|
|
|
|
|
|
2020-12-11 15:09:53 +01:00
|
|
|
|
2020-12-01 17:22:45 +01:00
|
|
|
constructor(
|
|
|
|
|
private modalController: ModalController,
|
2020-12-11 15:09:53 +01:00
|
|
|
public photoService: PhotoService,
|
2020-12-01 17:22:45 +01:00
|
|
|
private navParams: NavParams,
|
2020-12-09 12:10:19 +01:00
|
|
|
private publications: PublicationsService,
|
2021-02-09 13:16:41 +01:00
|
|
|
private camera: Camera,
|
2020-12-01 17:22:45 +01:00
|
|
|
) {
|
2020-12-17 10:59:11 +01:00
|
|
|
|
2020-12-01 17:22:45 +01:00
|
|
|
this.publicationType = this.navParams.get('publicationType');
|
2020-12-10 11:22:06 +01:00
|
|
|
this.folderId = this.navParams.get('folderId');
|
2020-12-01 17:22:45 +01:00
|
|
|
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-11 15:09:53 +01:00
|
|
|
this.clear();
|
2020-12-15 19:37:42 +01:00
|
|
|
this.takePicture();
|
2020-12-01 17:22:45 +01:00
|
|
|
}
|
2020-12-15 19:37:42 +01:00
|
|
|
takePicture(){
|
2021-02-09 13:16:41 +01:00
|
|
|
const options: CameraOptions = {
|
2020-12-11 18:00:38 +01:00
|
|
|
quality: 100,
|
|
|
|
|
destinationType: this.camera.DestinationType.DATA_URL,
|
|
|
|
|
encodingType: this.camera.EncodingType.JPEG,
|
2020-12-15 19:37:42 +01:00
|
|
|
mediaType: this.camera.MediaType.PICTURE,
|
|
|
|
|
targetWidth: 720,
|
|
|
|
|
targetHeight: 720,
|
2020-12-11 18:00:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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;
|
2020-12-15 19:37:42 +01:00
|
|
|
this.capturedImageTitle = new Date().getTime() + '.jpeg';
|
2020-12-11 18:00:38 +01:00
|
|
|
}, (err) => {
|
2020-12-15 19:37:42 +01:00
|
|
|
console.log(err);
|
2021-02-09 13:16:41 +01:00
|
|
|
});
|
2020-12-11 15:09:53 +01:00
|
|
|
}
|
|
|
|
|
|
2020-12-15 19:37:42 +01:00
|
|
|
getPicture(){
|
2021-02-04 09:01:58 +01:00
|
|
|
/* const options: CameraOptions = {
|
2020-12-15 19:37:42 +01:00
|
|
|
quality: 100,
|
|
|
|
|
sourceType: this.camera.PictureSourceType.PHOTOLIBRARY,
|
|
|
|
|
destinationType: this.camera.DestinationType.DATA_URL,
|
|
|
|
|
encodingType: this.camera.EncodingType.JPEG,
|
|
|
|
|
mediaType: this.camera.MediaType.PICTURE,
|
|
|
|
|
targetWidth: 720,
|
|
|
|
|
targetHeight: 720,
|
2020-12-09 12:10:19 +01:00
|
|
|
}
|
2020-12-15 19:37:42 +01:00
|
|
|
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() + '.jpeg';
|
|
|
|
|
}, (err) => {
|
|
|
|
|
console.log(err);
|
2021-02-04 09:01:58 +01:00
|
|
|
}); */
|
2020-12-15 19:37:42 +01:00
|
|
|
}
|
2020-12-09 12:10:19 +01:00
|
|
|
|
2020-12-11 15:09:53 +01:00
|
|
|
async save(){
|
2020-12-10 11:22:06 +01:00
|
|
|
if(this.publicationType == '3'){
|
2020-12-17 10:59:11 +01:00
|
|
|
console.log(this.navParams.get('publication'));
|
|
|
|
|
|
2020-12-11 18:00:38 +01:00
|
|
|
if(this.capturedImage != ''){
|
|
|
|
|
this.publication = {
|
2020-12-17 10:59:11 +01:00
|
|
|
DateIndex: this.publication.DateIndex,
|
2020-12-11 18:00:38 +01:00
|
|
|
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,
|
2020-12-17 10:59:11 +01:00
|
|
|
FileExtension: 'jpeg',
|
2020-12-11 18:00:38 +01:00
|
|
|
}
|
2020-12-15 19:37:42 +01:00
|
|
|
console.log('Edit change image');
|
|
|
|
|
console.log(this.publication);
|
|
|
|
|
this.publications.UpdatePublication(this.publication.ProcessId, this.publication);
|
|
|
|
|
this.close();
|
2020-12-10 11:22:06 +01:00
|
|
|
}
|
2020-12-11 18:00:38 +01:00
|
|
|
else{
|
|
|
|
|
this.publication = {
|
2020-12-17 10:59:11 +01:00
|
|
|
DateIndex: this.publication.DateIndex,
|
2020-12-11 18:00:38 +01:00
|
|
|
DocumentId:this.publication.DocumentId,
|
|
|
|
|
ProcessId:this.publication.ProcessId,
|
|
|
|
|
Title: this.pub.Title,
|
|
|
|
|
Message: this.pub.Message,
|
|
|
|
|
DatePublication: this.publication.DatePublication,
|
2020-12-17 10:59:11 +01:00
|
|
|
OriginalFileName: this.publication.OriginalFileName,
|
2020-12-11 18:00:38 +01:00
|
|
|
FileBase64: this.publication.FileBase64,
|
2020-12-17 10:59:11 +01:00
|
|
|
FileExtension: 'jpeg',
|
2020-12-11 18:00:38 +01:00
|
|
|
}
|
2020-12-15 19:37:42 +01:00
|
|
|
console.log('Edit - keep image');
|
|
|
|
|
console.log(this.publication);
|
|
|
|
|
this.publications.UpdatePublication(this.publication.ProcessId, this.publication);
|
|
|
|
|
this.close();
|
2020-12-09 12:10:19 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else{
|
2020-12-11 15:09:53 +01:00
|
|
|
|
2020-12-10 11:22:06 +01:00
|
|
|
this.publication = {
|
2020-12-17 10:59:11 +01:00
|
|
|
DateIndex: new Date(),
|
2020-12-11 15:09:53 +01:00
|
|
|
DocumentId:null,
|
|
|
|
|
ProcessId:this.folderId,
|
|
|
|
|
Title: this.pub.Title,
|
|
|
|
|
Message: this.pub.Message,
|
|
|
|
|
DatePublication: new Date(),
|
2020-12-11 18:00:38 +01:00
|
|
|
OriginalFileName: this.capturedImageTitle,
|
|
|
|
|
FileBase64: this.capturedImage,
|
2020-12-17 10:59:11 +01:00
|
|
|
FileExtension: 'jpeg',
|
2020-12-10 11:22:06 +01:00
|
|
|
}
|
2020-12-09 12:10:19 +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();
|
2020-12-09 12:10:19 +01:00
|
|
|
}
|
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(){
|
2020-12-15 19:37:42 +01:00
|
|
|
this.modalController.dismiss().then(()=>{
|
|
|
|
|
this.showLoader=true;
|
|
|
|
|
});
|
2020-12-01 17:22:45 +01:00
|
|
|
}
|
2020-12-11 15:09:53 +01:00
|
|
|
clear(){
|
2020-12-11 18:00:38 +01:00
|
|
|
this.capturedImage = '';
|
2020-12-11 15:09:53 +01:00
|
|
|
}
|
2020-12-01 17:22:45 +01:00
|
|
|
setTitle(){
|
|
|
|
|
if(this.publicationType == '1'){
|
2020-12-10 11:22:06 +01:00
|
|
|
this.publicationTitle = 'Nova Publicação Rápida';
|
2020-12-01 17:22:45 +01:00
|
|
|
}
|
2020-12-02 15:08:45 +01:00
|
|
|
else if(this.publicationType == '2'){
|
2020-12-10 11:22:06 +01:00
|
|
|
this.publicationTitle = 'Nova Publicação';
|
2020-12-01 17:22:45 +01:00
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-11 15:09:53 +01:00
|
|
|
/* async openGallery() {
|
2020-12-02 15:08:45 +01:00
|
|
|
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
|
|
|
} */
|
2020-12-01 14:03:15 +01:00
|
|
|
|
2020-12-11 18:00:38 +01:00
|
|
|
/* async takePicture(){
|
2020-12-09 12:10:19 +01:00
|
|
|
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);
|
|
|
|
|
|
2020-12-09 12:10:19 +01:00
|
|
|
this.photo = this.sanitizer.bypassSecurityTrustResourceUrl(image && (image.dataUrl));
|
2020-12-11 18:00:38 +01:00
|
|
|
} */
|
2020-12-09 12:10:19 +01:00
|
|
|
|
2020-12-01 14:03:15 +01:00
|
|
|
}
|