2020-12-01 14:03:15 +01:00
|
|
|
import { Component, OnInit } from '@angular/core';
|
2022-04-26 16:53:10 +01:00
|
|
|
import { ModalController, NavParams, Platform, LoadingController } from '@ionic/angular';
|
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 { PhotoService } from 'src/app/services/photo.service';
|
2021-01-15 11:07:20 +01:00
|
|
|
//Capacitor
|
2020-12-11 18:00:38 +01:00
|
|
|
|
2021-06-29 14:16:49 +01:00
|
|
|
import { ToastService } from 'src/app/services/toast.service';
|
2021-07-06 16:18:00 +01:00
|
|
|
import { FormControl, FormGroup, Validators } from '@angular/forms';
|
|
|
|
|
import { ThemePalette } from '@angular/material/core';
|
2021-07-15 17:01:32 +01:00
|
|
|
import { formatDate } from 'src/plugin/momentG.js'
|
2021-11-09 10:13:48 +01:00
|
|
|
import { ThemeService } from 'src/app/services/theme.service';
|
2021-11-16 14:06:30 +01:00
|
|
|
import { Camera, CameraResultType, CameraSource, Photo } from '@capacitor/camera';
|
2020-12-01 14:03:15 +01:00
|
|
|
|
2021-11-16 13:07:55 +01:00
|
|
|
import { Filesystem, Directory } from '@capacitor/filesystem';
|
2021-11-26 14:46:08 +01:00
|
|
|
import { NgxImageCompressService } from "ngx-image-compress";
|
2023-02-27 09:34:36 +01:00
|
|
|
import { HttpErrorHandle } from 'src/app/services/http-error-handle.service';
|
2022-04-26 16:53:10 +01:00
|
|
|
|
2021-11-16 13:07:55 +01:00
|
|
|
const IMAGE_DIR = 'stored-images';
|
|
|
|
|
|
|
|
|
|
interface LocalFile {
|
|
|
|
|
name: string;
|
|
|
|
|
path: string;
|
|
|
|
|
data: string;
|
|
|
|
|
}
|
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 {
|
2021-11-16 13:07:55 +01:00
|
|
|
images: LocalFile[] = [];
|
2021-07-06 16:18:00 +01:00
|
|
|
|
|
|
|
|
// date picker
|
|
|
|
|
public date: any;
|
|
|
|
|
public disabled = false;
|
|
|
|
|
public showSpinners = true;
|
|
|
|
|
public showSeconds = false;
|
|
|
|
|
public touchUi = false;
|
|
|
|
|
public enableMeridian = false;
|
2021-11-16 14:06:30 +01:00
|
|
|
public minDate = new Date().toISOString().slice(0, 10)
|
2021-07-06 16:18:00 +01:00
|
|
|
public endMinDate = new Date(new Date().getTime() + 15 * 60000);
|
|
|
|
|
public stepHour = 1;
|
2023-01-24 15:56:47 +01:00
|
|
|
public stepMinute = 15;
|
2021-07-06 16:18:00 +01:00
|
|
|
public stepSecond = 5;
|
|
|
|
|
public color: ThemePalette = 'primary';
|
|
|
|
|
|
|
|
|
|
Form: FormGroup;
|
|
|
|
|
validateFrom = false
|
|
|
|
|
|
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
|
|
|
|
2021-11-16 14:06:30 +01:00
|
|
|
publicationType: string;
|
|
|
|
|
publicationTitle: string;
|
|
|
|
|
imgUrl: any;
|
2020-12-09 12:10:19 +01:00
|
|
|
|
2021-11-16 14:06:30 +01:00
|
|
|
Defaultimage: any = '';
|
2020-12-10 11:22:06 +01:00
|
|
|
|
2020-12-09 12:10:19 +01:00
|
|
|
photo: SafeResourceUrl;
|
|
|
|
|
|
2021-11-16 14:06:30 +01:00
|
|
|
guestPicture: any;
|
2020-12-09 12:10:19 +01:00
|
|
|
|
2021-11-16 14:06:30 +01:00
|
|
|
capturedImage: any = '';
|
|
|
|
|
capturedImageTitle: any;
|
2021-11-09 10:13:48 +01:00
|
|
|
public photos: any[] = [];
|
2023-08-11 16:14:25 +01:00
|
|
|
pictureExiste = false
|
2020-12-11 18:00:38 +01:00
|
|
|
|
2021-11-26 14:46:08 +01:00
|
|
|
imgResultBeforeCompress: string;
|
|
|
|
|
imgResultAfterCompress: string;
|
2022-01-05 12:54:46 +01:00
|
|
|
convertBlobToBase64Worker;
|
2021-11-26 14:46:08 +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-06-29 14:16:49 +01:00
|
|
|
private toastService: ToastService,
|
2021-11-16 13:07:55 +01:00
|
|
|
public ThemeService: ThemeService,
|
|
|
|
|
private platform: Platform,
|
|
|
|
|
private loadingCtrl: LoadingController,
|
2021-11-30 12:30:58 +01:00
|
|
|
public imageCompress: NgxImageCompressService,
|
2023-02-27 09:34:36 +01:00
|
|
|
private httpErrorHandle: HttpErrorHandle
|
2021-11-16 14:06:30 +01:00
|
|
|
) {
|
2021-11-09 10:13:48 +01:00
|
|
|
|
2021-11-16 14:06:30 +01:00
|
|
|
this.publicationType = this.navParams.get('publicationType');
|
|
|
|
|
this.folderId = this.navParams.get('folderId');
|
|
|
|
|
this.publicationTitle = 'Nova Publicação';
|
2022-01-05 12:54:46 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
this.convertBlobToBase64Worker = new Worker(new URL('./convertBlobToBase64.worker.js', import.meta.url));
|
|
|
|
|
|
2021-11-16 14:06:30 +01:00
|
|
|
}
|
2020-12-01 14:03:15 +01:00
|
|
|
|
|
|
|
|
ngOnInit() {
|
2020-12-01 17:22:45 +01:00
|
|
|
this.setTitle();
|
2021-11-16 13:07:55 +01:00
|
|
|
Filesystem.mkdir({
|
|
|
|
|
path: IMAGE_DIR,
|
|
|
|
|
directory: Directory.Data,
|
|
|
|
|
recursive: true
|
|
|
|
|
});
|
2021-11-09 12:21:23 +01:00
|
|
|
|
2021-05-07 13:19:50 +01:00
|
|
|
// this.takePicture();
|
2020-12-01 17:22:45 +01:00
|
|
|
}
|
2021-07-06 16:18:00 +01:00
|
|
|
|
2021-11-16 14:06:30 +01:00
|
|
|
async takePicture() {
|
2023-02-10 13:07:08 +01:00
|
|
|
|
2021-12-13 09:51:57 +01:00
|
|
|
const capturedImage = await Camera.getPhoto({
|
2023-03-09 16:55:31 +01:00
|
|
|
quality: 50,
|
2021-12-13 09:51:57 +01:00
|
|
|
// allowEditing: true,
|
2021-11-16 14:06:30 +01:00
|
|
|
resultType: CameraResultType.Uri,
|
2021-12-13 09:51:57 +01:00
|
|
|
source: CameraSource.Camera
|
2021-02-09 13:16:41 +01:00
|
|
|
});
|
2022-01-03 18:45:37 +01:00
|
|
|
|
2021-12-13 09:51:57 +01:00
|
|
|
const response = await fetch(capturedImage.webPath!);
|
|
|
|
|
const blob = await response.blob();
|
2021-11-09 10:13:48 +01:00
|
|
|
|
2023-02-10 13:07:08 +01:00
|
|
|
this.convertBlobToBase64Worker.postMessage(blob);
|
|
|
|
|
this.convertBlobToBase64Worker.onmessage = async (oEvent)=> {
|
|
|
|
|
this.capturedImage = oEvent.data
|
2022-01-05 12:54:46 +01:00
|
|
|
|
2023-02-10 13:07:08 +01:00
|
|
|
}
|
2022-01-05 12:54:46 +01:00
|
|
|
}
|
2021-11-23 16:05:32 +01:00
|
|
|
|
2021-11-26 14:46:08 +01:00
|
|
|
imageSize(image) {
|
|
|
|
|
var canvas = document.createElement('canvas');
|
|
|
|
|
var ctx = canvas.getContext('2d');
|
|
|
|
|
canvas.width = 100
|
|
|
|
|
canvas.height = 34
|
2023-03-09 16:55:31 +01:00
|
|
|
ctx.drawImage(image, 0, 0);
|
2021-11-26 14:46:08 +01:00
|
|
|
document.body.appendChild(canvas);
|
2021-11-22 13:53:37 +01:00
|
|
|
}
|
|
|
|
|
|
2021-11-09 10:13:48 +01:00
|
|
|
convertBlobToBase64 = (blob: Blob) => new Promise((resolve, reject) => {
|
|
|
|
|
const reader = new FileReader;
|
|
|
|
|
reader.onerror = reject;
|
|
|
|
|
reader.onload = () => {
|
2021-12-13 09:51:57 +01:00
|
|
|
resolve(reader.result);
|
2021-11-09 10:13:48 +01:00
|
|
|
};
|
|
|
|
|
reader.readAsDataURL(blob);
|
2022-12-20 17:06:19 +01:00
|
|
|
}).catch ((error) => {
|
|
|
|
|
console.error(error);
|
2021-11-09 10:13:48 +01:00
|
|
|
});
|
|
|
|
|
|
2021-08-23 16:06:05 +01:00
|
|
|
|
2022-01-19 16:32:06 +01:00
|
|
|
/* async laodPicture() {
|
2021-11-09 16:38:26 +01:00
|
|
|
const capturedImage = await Camera.getPhoto({
|
|
|
|
|
resultType: CameraResultType.Uri,
|
2021-12-13 09:51:57 +01:00
|
|
|
source: CameraSource.Photos,
|
2021-11-09 16:38:26 +01:00
|
|
|
quality: 90,
|
|
|
|
|
width: 1080,
|
|
|
|
|
height: 720,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
this.capturedImageTitle = new Date().getTime() + '.jpeg';
|
2022-01-19 16:32:06 +01:00
|
|
|
} */
|
2021-11-09 16:38:26 +01:00
|
|
|
|
2022-02-03 16:36:05 +01:00
|
|
|
async laodPicture() {
|
|
|
|
|
|
|
|
|
|
const capturedImage = await Camera.getPhoto({
|
|
|
|
|
quality: 90,
|
|
|
|
|
// allowEditing: true,
|
|
|
|
|
resultType: CameraResultType.Uri,
|
|
|
|
|
source: CameraSource.Photos
|
|
|
|
|
});
|
2021-11-09 10:13:48 +01:00
|
|
|
|
2022-02-03 16:36:05 +01:00
|
|
|
const response = await fetch(capturedImage.webPath!);
|
|
|
|
|
const blob = await response.blob();
|
2021-08-23 16:06:05 +01:00
|
|
|
|
2023-02-10 13:07:08 +01:00
|
|
|
this.convertBlobToBase64Worker.postMessage(blob);
|
|
|
|
|
this.convertBlobToBase64Worker.onmessage = async (oEvent)=> {
|
|
|
|
|
this.capturedImage = oEvent.data
|
2021-08-24 11:15:13 +01:00
|
|
|
|
2023-02-10 13:07:08 +01:00
|
|
|
}
|
2021-08-23 16:06:05 +01:00
|
|
|
|
2022-01-19 16:32:06 +01:00
|
|
|
}
|
2021-08-23 16:06:05 +01:00
|
|
|
|
2021-07-06 16:18:00 +01:00
|
|
|
|
2020-12-09 12:10:19 +01:00
|
|
|
|
2021-07-06 16:18:00 +01:00
|
|
|
runValidation() {
|
2021-11-16 14:06:30 +01:00
|
|
|
this.validateFrom = true
|
2021-07-06 16:18:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
injectValidation() {
|
|
|
|
|
|
|
|
|
|
this.Form = new FormGroup({
|
|
|
|
|
Subject: new FormControl(this.pub.Title, [
|
2023-02-27 09:34:36 +01:00
|
|
|
Validators.required,
|
2021-07-06 16:18:00 +01:00
|
|
|
// Validators.minLength(4)
|
|
|
|
|
]),
|
|
|
|
|
capturedImage: new FormControl(this.capturedImage, [
|
|
|
|
|
|
|
|
|
|
]),
|
|
|
|
|
Message: new FormControl(this.pub.Message, [
|
2023-02-27 09:34:36 +01:00
|
|
|
Validators.required,
|
2021-07-15 15:41:19 +01:00
|
|
|
Validators.maxLength(1000)
|
2021-07-15 15:39:10 +01:00
|
|
|
|
2021-07-06 16:18:00 +01:00
|
|
|
])
|
|
|
|
|
})
|
|
|
|
|
}
|
2021-11-09 10:13:48 +01:00
|
|
|
|
2021-07-06 16:18:00 +01:00
|
|
|
async save() {
|
2021-11-09 10:13:48 +01:00
|
|
|
|
2021-07-06 16:18:00 +01:00
|
|
|
this.injectValidation()
|
|
|
|
|
this.runValidation()
|
|
|
|
|
|
2021-11-16 14:06:30 +01:00
|
|
|
if (this.Form.invalid) return false
|
2021-07-06 16:18:00 +01:00
|
|
|
|
2021-11-09 10:13:48 +01:00
|
|
|
|
2021-07-14 15:38:58 +01:00
|
|
|
|
2021-11-16 14:06:30 +01:00
|
|
|
if (this.publicationType == '3') {
|
2021-11-09 10:13:48 +01:00
|
|
|
|
2021-11-16 14:06:30 +01:00
|
|
|
if (this.capturedImage != '') {
|
2020-12-11 18:00:38 +01:00
|
|
|
this.publication = {
|
2020-12-17 10:59:11 +01:00
|
|
|
DateIndex: this.publication.DateIndex,
|
2021-11-16 14:06:30 +01:00
|
|
|
DocumentId: this.publication.DocumentId,
|
|
|
|
|
ProcessId: this.publication.ProcessId,
|
2020-12-11 18:00:38 +01:00
|
|
|
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
|
|
|
}
|
2021-06-29 14:16:49 +01:00
|
|
|
|
2021-07-12 11:13:29 +01:00
|
|
|
const loader = this.toastService.loading()
|
|
|
|
|
|
2021-06-29 14:16:49 +01:00
|
|
|
try {
|
2021-11-09 10:13:48 +01:00
|
|
|
|
2021-06-29 14:16:49 +01:00
|
|
|
await this.publications.UpdatePublication(this.publication.ProcessId, this.publication).toPromise()
|
2023-02-27 09:34:36 +01:00
|
|
|
this.httpErrorHandle.httpsSucessMessagge('Publicação Editada')
|
2021-06-29 14:16:49 +01:00
|
|
|
|
|
|
|
|
this.close();
|
|
|
|
|
} catch (error) {
|
2023-02-27 09:34:36 +01:00
|
|
|
this.httpErrorHandle.httpStatusHandle(error)
|
2021-07-12 11:13:29 +01:00
|
|
|
} finally {
|
|
|
|
|
loader.remove()
|
2021-06-29 14:16:49 +01:00
|
|
|
}
|
|
|
|
|
|
2020-12-10 11:22:06 +01:00
|
|
|
}
|
2021-07-14 15:38:58 +01:00
|
|
|
else if (!this.publication.OriginalFileName) {
|
|
|
|
|
|
2020-12-11 18:00:38 +01:00
|
|
|
this.publication = {
|
2020-12-17 10:59:11 +01:00
|
|
|
DateIndex: this.publication.DateIndex,
|
2021-11-16 14:06:30 +01:00
|
|
|
DocumentId: this.publication.DocumentId,
|
|
|
|
|
ProcessId: this.publication.ProcessId,
|
2020-12-11 18:00:38 +01:00
|
|
|
Title: this.pub.Title,
|
|
|
|
|
Message: this.pub.Message,
|
|
|
|
|
DatePublication: this.publication.DatePublication,
|
2021-07-14 15:38:58 +01:00
|
|
|
// OriginalFileName: this.publication.OriginalFileName,
|
|
|
|
|
// FileBase64: this.publication.FileBase64,
|
|
|
|
|
// FileExtension: 'jpeg',
|
2020-12-11 18:00:38 +01:00
|
|
|
}
|
2021-07-12 11:13:29 +01:00
|
|
|
|
|
|
|
|
const loader = this.toastService.loading()
|
|
|
|
|
|
2021-06-29 14:16:49 +01:00
|
|
|
try {
|
|
|
|
|
await this.publications.UpdatePublication(this.publication.ProcessId, this.publication).toPromise()
|
2023-02-27 09:34:36 +01:00
|
|
|
this.httpErrorHandle.httpsSucessMessagge('Criar publicação')
|
2021-11-09 10:13:48 +01:00
|
|
|
|
2021-06-29 14:16:49 +01:00
|
|
|
this.close();
|
|
|
|
|
} catch (error) {
|
2023-02-27 09:34:36 +01:00
|
|
|
this.httpErrorHandle.httpStatusHandle(error)
|
2021-11-16 14:06:30 +01:00
|
|
|
} finally {
|
2021-07-12 11:13:29 +01:00
|
|
|
loader.remove()
|
2021-06-29 14:16:49 +01:00
|
|
|
}
|
|
|
|
|
|
2021-11-16 14:06:30 +01:00
|
|
|
} else {
|
2021-07-26 15:19:03 +01:00
|
|
|
this.publication = {
|
|
|
|
|
DateIndex: this.publication.DateIndex,
|
2021-11-16 14:06:30 +01:00
|
|
|
DocumentId: this.publication.DocumentId,
|
|
|
|
|
ProcessId: this.publication.ProcessId,
|
2021-07-26 15:19:03 +01:00
|
|
|
Title: this.pub.Title,
|
|
|
|
|
Message: this.pub.Message,
|
|
|
|
|
DatePublication: this.publication.DatePublication,
|
|
|
|
|
OriginalFileName: this.capturedImageTitle,
|
|
|
|
|
FileBase64: this.capturedImage,
|
|
|
|
|
FileExtension: 'jpeg',
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-28 09:32:27 +01:00
|
|
|
|
|
|
|
|
|
2021-07-26 15:19:03 +01:00
|
|
|
const loader = this.toastService.loading()
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
await this.publications.UpdatePublication(this.publication.ProcessId, this.publication).toPromise()
|
2023-02-27 17:39:10 +01:00
|
|
|
this.httpErrorHandle.httpsSucessMessagge('Publicação Editada')
|
2021-07-26 15:19:03 +01:00
|
|
|
|
|
|
|
|
this.close();
|
|
|
|
|
} catch (error) {
|
2023-02-27 09:34:36 +01:00
|
|
|
this.httpErrorHandle.httpStatusHandle(error)
|
2021-11-16 14:06:30 +01:00
|
|
|
} finally {
|
2021-07-26 15:19:03 +01:00
|
|
|
loader.remove()
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-09 12:10:19 +01:00
|
|
|
}
|
|
|
|
|
}
|
2021-07-06 16:18:00 +01:00
|
|
|
else {
|
2021-07-14 16:57:06 +01:00
|
|
|
|
2021-11-16 14:06:30 +01:00
|
|
|
const date = formatDate(new Date(), 'yyyy-MM-dd HH:mm:ss')
|
2022-04-28 09:32:27 +01:00
|
|
|
|
|
|
|
|
|
2021-11-09 12:21:23 +01:00
|
|
|
|
2021-07-15 17:01:32 +01:00
|
|
|
|
2020-12-10 11:22:06 +01:00
|
|
|
this.publication = {
|
2021-07-15 17:01:32 +01:00
|
|
|
DateIndex: date,
|
2021-11-16 14:06:30 +01:00
|
|
|
DocumentId: null,
|
|
|
|
|
ProcessId: this.folderId,
|
2020-12-11 15:09:53 +01:00
|
|
|
Title: this.pub.Title,
|
|
|
|
|
Message: this.pub.Message,
|
2021-07-15 17:01:32 +01:00
|
|
|
DatePublication: 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
|
|
|
}
|
2021-06-29 14:16:49 +01:00
|
|
|
|
2021-07-12 11:13:29 +01:00
|
|
|
const loader = this.toastService.loading()
|
|
|
|
|
|
2021-06-29 14:16:49 +01:00
|
|
|
try {
|
2022-04-28 09:32:27 +01:00
|
|
|
|
2021-06-30 16:11:07 +01:00
|
|
|
await this.publications.CreatePublication(this.folderId, this.publication).toPromise();
|
|
|
|
|
this.close();
|
2023-02-27 09:34:36 +01:00
|
|
|
this.httpErrorHandle.httpsSucessMessagge('Criar publicação')
|
2021-11-09 10:13:48 +01:00
|
|
|
|
2021-06-29 14:16:49 +01:00
|
|
|
|
|
|
|
|
this.close();
|
|
|
|
|
} catch (error) {
|
2023-02-27 09:34:36 +01:00
|
|
|
this.httpErrorHandle.httpStatusHandle(error)
|
2021-11-16 14:06:30 +01:00
|
|
|
} finally {
|
2021-07-12 11:13:29 +01:00
|
|
|
loader.remove()
|
2021-06-29 14:16:49 +01:00
|
|
|
}
|
|
|
|
|
|
2020-12-09 12:10:19 +01:00
|
|
|
}
|
2020-12-01 17:22:45 +01:00
|
|
|
}
|
2020-12-09 12:10:19 +01:00
|
|
|
|
|
|
|
|
|
2021-07-06 16:18:00 +01:00
|
|
|
close() {
|
2021-11-16 14:06:30 +01:00
|
|
|
this.modalController.dismiss().then(() => {
|
|
|
|
|
this.showLoader = true;
|
2020-12-15 19:37:42 +01:00
|
|
|
});
|
2020-12-01 17:22:45 +01:00
|
|
|
}
|
2021-11-09 10:13:48 +01:00
|
|
|
|
2021-07-06 16:18:00 +01:00
|
|
|
clear() {
|
2020-12-11 18:00:38 +01:00
|
|
|
this.capturedImage = '';
|
2020-12-11 15:09:53 +01:00
|
|
|
}
|
2021-07-06 16:18:00 +01:00
|
|
|
|
|
|
|
|
setTitle() {
|
2021-11-16 14:06:30 +01:00
|
|
|
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
|
|
|
}
|
2021-11-16 14:06:30 +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
|
|
|
}
|
2021-11-16 14:06:30 +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');
|
2021-07-14 15:38:58 +01:00
|
|
|
|
2022-04-28 09:32:27 +01:00
|
|
|
|
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
|
|
|
|
2021-11-16 14:06:30 +01:00
|
|
|
/* async takePicture(){
|
|
|
|
|
const image = await Plugins.Camera.getPhoto({
|
|
|
|
|
quality: 100,
|
|
|
|
|
allowEditing: false,
|
|
|
|
|
resultType: CameraResultType.DataUrl,
|
|
|
|
|
source: CameraSource.Camera
|
|
|
|
|
});
|
2022-04-28 09:32:27 +01:00
|
|
|
|
2021-11-16 14:06:30 +01:00
|
|
|
|
|
|
|
|
this.photo = this.sanitizer.bypassSecurityTrustResourceUrl(image && (image.dataUrl));
|
|
|
|
|
} */
|
2021-11-09 10:13:48 +01:00
|
|
|
|
2021-11-16 14:06:30 +01:00
|
|
|
async selectImage() {
|
2021-11-16 13:07:55 +01:00
|
|
|
const image = await Camera.getPhoto({
|
2021-12-08 19:39:30 +01:00
|
|
|
quality: 90,
|
2021-11-16 14:06:30 +01:00
|
|
|
allowEditing: false,
|
|
|
|
|
resultType: CameraResultType.Uri,
|
2021-11-22 16:37:11 +01:00
|
|
|
source: CameraSource.Camera // Camera, Photos or Prompt!
|
2021-11-16 13:07:55 +01:00
|
|
|
});
|
|
|
|
|
if (image) {
|
2021-11-16 14:06:30 +01:00
|
|
|
this.saveImage(image)
|
2021-11-16 13:07:55 +01:00
|
|
|
}
|
2021-11-16 14:06:30 +01:00
|
|
|
}
|
|
|
|
|
|
2021-11-26 14:46:08 +01:00
|
|
|
|
2021-11-22 13:53:37 +01:00
|
|
|
|
2021-11-16 14:06:30 +01:00
|
|
|
// Create a new file from a capture image
|
|
|
|
|
async saveImage(photo: Photo) {
|
2021-11-16 13:07:55 +01:00
|
|
|
const base64Data = await this.readAsBase64(photo);
|
2021-11-16 14:06:30 +01:00
|
|
|
|
2021-11-16 13:07:55 +01:00
|
|
|
const fileName = new Date().getTime() + '.jpeg';
|
|
|
|
|
const savedFile = await Filesystem.writeFile({
|
2021-11-16 14:06:30 +01:00
|
|
|
path: `${IMAGE_DIR}/${fileName}`,
|
|
|
|
|
data: base64Data,
|
|
|
|
|
directory: Directory.Data
|
2021-11-16 13:07:55 +01:00
|
|
|
});
|
2021-11-16 14:06:30 +01:00
|
|
|
|
2021-11-22 15:26:04 +01:00
|
|
|
//this.loadFiles(fileName);
|
|
|
|
|
this.loadFileData(fileName);
|
2021-11-16 14:06:30 +01:00
|
|
|
}
|
|
|
|
|
|
2021-11-16 13:07:55 +01:00
|
|
|
private async readAsBase64(photo: Photo) {
|
|
|
|
|
if (this.platform.is('hybrid')) {
|
2021-11-16 14:06:30 +01:00
|
|
|
const file = await Filesystem.readFile({
|
|
|
|
|
path: photo.path
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return file.data;
|
2021-11-16 13:07:55 +01:00
|
|
|
}
|
|
|
|
|
else {
|
2021-11-16 14:06:30 +01:00
|
|
|
// Fetch the photo, read as a blob, then convert to base64 format
|
|
|
|
|
const response = await fetch(photo.webPath);
|
|
|
|
|
const blob = await response.blob();
|
|
|
|
|
|
|
|
|
|
return await this.convertBlobToBase64(blob) as string;
|
2021-11-16 13:07:55 +01:00
|
|
|
}
|
2021-11-16 14:06:30 +01:00
|
|
|
}
|
2021-11-16 13:07:55 +01:00
|
|
|
|
2021-11-22 15:26:04 +01:00
|
|
|
async loadFiles(fileName) {
|
2021-11-16 14:06:30 +01:00
|
|
|
this.images = [];
|
2021-11-16 13:07:55 +01:00
|
|
|
|
2021-11-16 14:06:30 +01:00
|
|
|
const loading = await this.loadingCtrl.create({
|
|
|
|
|
message: 'Loading data...',
|
|
|
|
|
});
|
|
|
|
|
await loading.present();
|
|
|
|
|
|
2021-11-22 15:26:04 +01:00
|
|
|
/* Filesystem.readdir({
|
|
|
|
|
path: `${IMAGE_DIR}/${fileName}`,
|
2021-11-16 14:06:30 +01:00
|
|
|
directory: Directory.Data,
|
|
|
|
|
}).then(result => {
|
2022-04-28 09:32:27 +01:00
|
|
|
|
2021-11-16 14:06:30 +01:00
|
|
|
let lastphoto = result.files[result.files.length - 1]
|
|
|
|
|
this.loadFileData(lastphoto);
|
|
|
|
|
},
|
|
|
|
|
async (err) => {
|
2022-04-28 09:32:27 +01:00
|
|
|
|
2021-11-16 14:06:30 +01:00
|
|
|
// Folder does not yet exists!
|
|
|
|
|
await Filesystem.mkdir({
|
|
|
|
|
path: IMAGE_DIR,
|
|
|
|
|
directory: Directory.Data,
|
|
|
|
|
recursive: true
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
).then(_ => {
|
|
|
|
|
loading.dismiss();
|
2021-11-22 15:26:04 +01:00
|
|
|
}); */
|
2021-11-16 14:06:30 +01:00
|
|
|
}
|
2021-11-16 13:07:55 +01:00
|
|
|
|
2021-11-16 14:06:30 +01:00
|
|
|
async loadFileData(fileName: string) {
|
2022-04-28 09:32:27 +01:00
|
|
|
|
2021-11-22 15:26:04 +01:00
|
|
|
|
|
|
|
|
const loading = await this.loadingCtrl.create({
|
|
|
|
|
message: 'Loading data...',
|
|
|
|
|
});
|
|
|
|
|
await loading.present();
|
|
|
|
|
|
2021-11-16 13:07:55 +01:00
|
|
|
const filePath = `${IMAGE_DIR}/${fileName}`;
|
|
|
|
|
|
|
|
|
|
const readFile = await Filesystem.readFile({
|
|
|
|
|
path: filePath,
|
|
|
|
|
directory: Directory.Data,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
this.images.push({
|
|
|
|
|
name: fileName,
|
|
|
|
|
path: filePath,
|
|
|
|
|
data: `data:image/jpeg;base64,${readFile.data}`,
|
|
|
|
|
});
|
|
|
|
|
|
2022-04-28 09:32:27 +01:00
|
|
|
|
2021-11-16 13:07:55 +01:00
|
|
|
|
|
|
|
|
this.capturedImage = this.images[0].data
|
2021-11-22 15:26:04 +01:00
|
|
|
|
2021-11-26 14:46:08 +01:00
|
|
|
this.compressFile();
|
|
|
|
|
|
2021-11-22 15:26:04 +01:00
|
|
|
loading.dismiss();
|
|
|
|
|
|
2021-11-16 14:06:30 +01:00
|
|
|
}
|
2021-11-22 13:53:37 +01:00
|
|
|
|
2021-11-26 14:46:08 +01:00
|
|
|
/* compressImage() {
|
|
|
|
|
let image = this.capturedImage;
|
|
|
|
|
this.imageCompress.compressFile(image, orientation, 50, 50,).then(() => {
|
2021-12-13 09:51:57 +01:00
|
|
|
|
2021-11-26 14:46:08 +01:00
|
|
|
this.imgResultBeforeCompress = image;
|
2022-04-28 09:32:27 +01:00
|
|
|
|
2021-12-13 09:51:57 +01:00
|
|
|
|
2021-11-26 14:46:08 +01:00
|
|
|
this.imageCompress.compressFile(image, orientation, 50, 50).then(
|
|
|
|
|
result => {
|
|
|
|
|
this.imgResultAfterCompress = result;
|
2022-04-28 09:32:27 +01:00
|
|
|
|
2021-11-26 14:46:08 +01:00
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
})
|
|
|
|
|
} */
|
|
|
|
|
|
|
|
|
|
compressFile() {
|
|
|
|
|
|
2021-12-08 19:39:30 +01:00
|
|
|
//this.imgResultBeforeCompress = image;s
|
2021-11-26 14:46:08 +01:00
|
|
|
this.imageCompress.getOrientation(this.capturedImage).then((orientation) => {
|
2022-04-28 09:32:27 +01:00
|
|
|
|
2021-12-08 19:39:30 +01:00
|
|
|
this.imageCompress.compressFile(this.capturedImage, orientation, 90, 90).then(
|
2021-11-26 14:46:08 +01:00
|
|
|
result => {
|
|
|
|
|
this.capturedImage = result;
|
2022-04-28 09:32:27 +01:00
|
|
|
|
2021-11-26 14:46:08 +01:00
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2021-11-22 13:53:37 +01:00
|
|
|
|
2021-11-09 10:13:48 +01:00
|
|
|
}
|