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
|
|
|
|
2023-11-06 13:33:35 +01:00
|
|
|
import { Filesystem, Directory, Encoding, FilesystemDirectory } 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';
|
2023-08-18 17:37:11 +01:00
|
|
|
import { PublicationFolderService } from 'src/app/store/publication-folder.service';
|
2023-08-22 11:25:13 +01:00
|
|
|
import { RouteService } from 'src/app/services/route.service';
|
2023-08-23 17:19:22 +01:00
|
|
|
import { FileService } from 'src/app/services/functions/file.service';
|
|
|
|
|
import { readAndCompressImage } from 'browser-image-resizer';
|
2023-10-31 10:09:12 +01:00
|
|
|
import { FilePicker } from '@capawesome/capacitor-file-picker';
|
|
|
|
|
import { CapacitorVideoPlayer } from 'capacitor-video-player';
|
2023-11-06 13:33:35 +01:00
|
|
|
import { CaptureError, CaptureImageOptions, MediaCapture, MediaFile } from '@awesome-cordova-plugins/media-capture/ngx';
|
2023-11-06 09:07:04 +01:00
|
|
|
import { Capacitor } from '@capacitor/core';
|
2023-11-10 15:37:12 +01:00
|
|
|
import { File } from '@ionic-native/file/ngx';
|
|
|
|
|
import { Media } from '@ionic-native/media/ngx';
|
2023-11-20 14:12:32 +01:00
|
|
|
import { checkFileTypeService } from 'src/app/services/checkFileType.service';
|
2023-11-09 11:45:04 +01:00
|
|
|
import { FileValidatorService } from "src/app/services/file/file-validator.service"
|
2023-08-23 17:19:22 +01:00
|
|
|
const config = {
|
|
|
|
|
quality: 0.5,
|
|
|
|
|
maxWidth: 800,
|
|
|
|
|
maxHeight: 600,
|
|
|
|
|
debug: true
|
|
|
|
|
};
|
2021-11-16 13:07:55 +01:00
|
|
|
const IMAGE_DIR = 'stored-images';
|
2023-10-31 10:09:12 +01:00
|
|
|
/* const { VideoRecorder } = Plugin; */
|
2021-11-16 13:07:55 +01:00
|
|
|
|
|
|
|
|
interface LocalFile {
|
|
|
|
|
name: string;
|
|
|
|
|
path: string;
|
|
|
|
|
data: string;
|
|
|
|
|
}
|
2023-10-31 10:09:12 +01:00
|
|
|
|
2023-11-06 13:33:35 +01:00
|
|
|
/* const config_video: VideoRecorderPreviewFrame = {
|
2023-10-31 10:09:12 +01:00
|
|
|
id: 'video-record',
|
|
|
|
|
stackPosition: 'front', // 'front' overlays your app', 'back' places behind your app.
|
|
|
|
|
width: 'fill',
|
|
|
|
|
height: 'fill',
|
|
|
|
|
x: 0,
|
|
|
|
|
y: 0,
|
|
|
|
|
borderRadius: 0
|
2023-11-06 13:33:35 +01:00
|
|
|
}; */
|
2020-12-01 14:03:15 +01:00
|
|
|
@Component({
|
|
|
|
|
selector: 'app-new-publication',
|
|
|
|
|
templateUrl: './new-publication.page.html',
|
|
|
|
|
styleUrls: ['./new-publication.page.scss'],
|
|
|
|
|
})
|
2023-10-31 10:09:12 +01:00
|
|
|
|
|
|
|
|
|
2020-12-01 14:03:15 +01:00
|
|
|
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 = '';
|
2023-10-31 10:09:12 +01:00
|
|
|
capturedVideo: any = '';
|
2021-11-16 14:06:30 +01:00
|
|
|
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;
|
2023-10-25 09:08:49 +01:00
|
|
|
intent: any;
|
2023-10-31 10:09:12 +01:00
|
|
|
video: any;
|
|
|
|
|
photoOrVideo: boolean = false;
|
|
|
|
|
fileType = "";
|
2023-11-06 09:07:04 +01:00
|
|
|
filecontent: boolean;
|
2023-11-20 14:12:32 +01:00
|
|
|
seletedContent: any[] = []
|
|
|
|
|
// Set a limit for the number of images to display
|
|
|
|
|
displayLimit = 4;
|
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-08-18 17:37:11 +01:00
|
|
|
private httpErrorHandle: HttpErrorHandle,
|
2023-08-22 11:25:13 +01:00
|
|
|
public PublicationFolderService: PublicationFolderService,
|
|
|
|
|
private RouteService: RouteService,
|
2023-10-31 10:09:12 +01:00
|
|
|
public FileService: FileService,
|
2023-11-20 14:12:32 +01:00
|
|
|
private mediaCapture: MediaCapture,
|
2023-11-29 16:06:56 +01:00
|
|
|
public checkFileType: checkFileTypeService,
|
2023-11-09 11:45:04 +01:00
|
|
|
private FileValidatorService: FileValidatorService
|
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');
|
2023-08-18 17:37:11 +01:00
|
|
|
this.publication = this.navParams.get('publication');
|
2023-11-29 12:17:52 +01:00
|
|
|
if (this.publication) {
|
|
|
|
|
this.seletedContent = this.publication.Files;
|
|
|
|
|
this.filecontent = true;
|
|
|
|
|
}
|
|
|
|
|
console.log('Edit', this.publication)
|
2021-11-16 14:06:30 +01:00
|
|
|
this.publicationTitle = 'Nova Publicação';
|
2023-10-25 09:08:49 +01:00
|
|
|
this.intent = this.navParams.get('intent');
|
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() {
|
2023-11-29 12:17:52 +01:00
|
|
|
this.reciveSharedContent();
|
2023-10-25 09:08:49 +01:00
|
|
|
|
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
|
|
|
|
2023-11-13 10:59:36 +01:00
|
|
|
document.addEventListener("click", clickOutside, false);
|
|
|
|
|
function clickOutside(e) {
|
|
|
|
|
const inside = document.getElementById('container-multiselect').contains(e.target);
|
|
|
|
|
this.photoOrVideo = false;
|
|
|
|
|
console.log(this.photoOrVideo)
|
|
|
|
|
}
|
2020-12-01 17:22:45 +01:00
|
|
|
}
|
2021-07-06 16:18:00 +01:00
|
|
|
|
2023-08-23 17:19:22 +01:00
|
|
|
// in use
|
2021-11-16 14:06:30 +01:00
|
|
|
async takePicture() {
|
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,
|
2023-08-28 16:36:31 +01:00
|
|
|
resultType: CameraResultType.Base64,
|
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
|
|
|
|
2023-11-29 12:17:52 +01:00
|
|
|
console.log(capturedImage)
|
|
|
|
|
|
2023-10-31 10:09:12 +01:00
|
|
|
this.capturedImage = 'data:image/jpeg;base64,' + capturedImage.base64String;
|
|
|
|
|
this.capturedImageTitle = 'foto';
|
|
|
|
|
|
|
|
|
|
const compressedImage = await this.compressImageBase64(
|
|
|
|
|
this.capturedImage,
|
|
|
|
|
800, // maxWidth
|
|
|
|
|
800, // maxHeight
|
|
|
|
|
0.9 // quality
|
|
|
|
|
).then((picture) => {
|
2023-11-29 12:17:52 +01:00
|
|
|
console.log('take picture', this.removeTextBeforeSlash(picture, ','),)
|
2023-11-06 09:07:04 +01:00
|
|
|
this.filecontent = true;
|
2023-10-31 10:09:12 +01:00
|
|
|
this.photoOrVideo = false;
|
2023-11-29 12:17:52 +01:00
|
|
|
let fileObject = {
|
|
|
|
|
FileBase64: this.removeTextBeforeSlash(picture, ','),
|
|
|
|
|
FileExtension: capturedImage.format
|
|
|
|
|
}
|
|
|
|
|
this.seletedContent.push(fileObject)
|
|
|
|
|
|
2023-10-31 15:13:19 +01:00
|
|
|
|
2023-10-31 10:09:12 +01:00
|
|
|
});
|
|
|
|
|
}
|
2021-11-09 10:13:48 +01:00
|
|
|
|
2023-10-31 10:09:12 +01:00
|
|
|
async laodPicture() {
|
|
|
|
|
const capturedImage = await Camera.getPhoto({
|
|
|
|
|
quality: 90,
|
|
|
|
|
resultType: CameraResultType.Base64,
|
|
|
|
|
source: CameraSource.Photos
|
|
|
|
|
});
|
2023-08-28 16:36:31 +01:00
|
|
|
|
2023-10-31 10:09:12 +01:00
|
|
|
this.capturedImage = 'data:image/jpeg;base64,' + capturedImage.base64String;
|
|
|
|
|
this.capturedImageTitle = 'foto';
|
|
|
|
|
|
|
|
|
|
const compressedImage = await this.compressImageBase64(
|
|
|
|
|
this.capturedImage,
|
|
|
|
|
800, // maxWidth
|
|
|
|
|
800, // maxHeight
|
|
|
|
|
0.9 // quality
|
|
|
|
|
).then((picture) => {
|
|
|
|
|
console.log('Selected: ', picture)
|
|
|
|
|
this.capturedImage = picture
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
}
|
2022-01-05 12:54:46 +01:00
|
|
|
|
2023-10-31 10:09:12 +01:00
|
|
|
async startVideoRecording() {
|
|
|
|
|
try {
|
2023-11-20 14:12:32 +01:00
|
|
|
let options: CaptureImageOptions = { limit: 5 }
|
2023-11-29 12:17:52 +01:00
|
|
|
const data: any = await this.mediaCapture.captureVideo(options)
|
2023-11-06 16:28:10 +01:00
|
|
|
this.video = data[0];
|
2023-11-10 15:37:12 +01:00
|
|
|
console.log(data)
|
2023-11-29 12:17:52 +01:00
|
|
|
data.forEach(async element => {
|
|
|
|
|
|
|
|
|
|
const savedFile = await Filesystem.copy({
|
|
|
|
|
from: element.fullPath, // directory prop removed, Capacitor parses filename for us
|
|
|
|
|
to: "video.mp4",
|
|
|
|
|
toDirectory: FilesystemDirectory.Data
|
|
|
|
|
});
|
|
|
|
|
console.log(savedFile.uri)
|
|
|
|
|
Filesystem.readFile({ path: savedFile.uri })
|
|
|
|
|
|
|
|
|
|
.then(async (content) => {
|
|
|
|
|
this.filecontent = true;
|
|
|
|
|
let fileObject = {
|
|
|
|
|
FileBase64: content.data,
|
|
|
|
|
FileExtension: 'mp4'
|
|
|
|
|
}
|
|
|
|
|
this.seletedContent.push(fileObject)
|
|
|
|
|
})
|
|
|
|
|
.catch((err) => console.error(err));
|
2023-11-13 10:59:36 +01:00
|
|
|
});
|
2023-11-10 15:37:12 +01:00
|
|
|
} catch (error) {
|
|
|
|
|
console.log('record video error: ', error)
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-11-06 13:33:35 +01:00
|
|
|
|
2023-10-31 10:09:12 +01:00
|
|
|
async loadVideo() {
|
|
|
|
|
|
2023-10-31 15:13:19 +01:00
|
|
|
const result = await FilePicker.pickMedia
|
2023-11-06 09:07:04 +01:00
|
|
|
({
|
|
|
|
|
multiple: true,
|
|
|
|
|
});
|
2023-11-20 14:12:32 +01:00
|
|
|
result.files.forEach(element => {
|
|
|
|
|
|
2023-11-29 12:17:52 +01:00
|
|
|
if (this.checkFileType.checkFileType(element.mimeType) == 'image' || this.checkFileType.checkFileType(element.mimeType) == 'video') {
|
|
|
|
|
let resultUrl = decodeURIComponent(element.path);
|
|
|
|
|
Filesystem.readFile({ path: resultUrl })
|
|
|
|
|
|
|
|
|
|
.then(async (content) => {
|
|
|
|
|
console.log(result)
|
|
|
|
|
console.log(content)
|
|
|
|
|
this.filecontent = true;
|
|
|
|
|
let fileObject = {
|
|
|
|
|
FileBase64: content.data,
|
|
|
|
|
FileExtension: this.removeTextBeforeSlash(element.mimeType, '/')
|
|
|
|
|
}
|
|
|
|
|
this.seletedContent.push(fileObject)
|
|
|
|
|
})
|
|
|
|
|
.catch((err) => console.error(err));
|
|
|
|
|
}
|
2023-11-20 14:12:32 +01:00
|
|
|
|
|
|
|
|
});
|
2023-10-31 10:09:12 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
chossePhotoOrVideo() {
|
2023-10-31 15:13:19 +01:00
|
|
|
this.photoOrVideo = !this.photoOrVideo
|
2023-10-31 10:09:12 +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 = () => {
|
2023-10-31 10:09:12 +01:00
|
|
|
resolve(reader.result);
|
2021-11-09 10:13:48 +01:00
|
|
|
};
|
|
|
|
|
reader.readAsDataURL(blob);
|
2023-10-31 10:09:12 +01:00
|
|
|
}).catch((error) => {
|
2022-12-20 17:06:19 +01:00
|
|
|
console.error(error);
|
2021-11-09 10:13:48 +01:00
|
|
|
});
|
|
|
|
|
|
2021-08-23 16:06:05 +01:00
|
|
|
|
2023-10-31 10:09:12 +01:00
|
|
|
/* // in use
|
|
|
|
|
async laodPicture() {
|
|
|
|
|
|
|
|
|
|
const capturedImage = await Camera.getPhoto({
|
|
|
|
|
quality: 90,
|
|
|
|
|
// allowEditing: true,
|
|
|
|
|
resultType: CameraResultType.Uri,
|
|
|
|
|
source: CameraSource.Photos
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const response = await fetch(capturedImage.webPath!);
|
|
|
|
|
const blob = await response.blob();
|
|
|
|
|
|
|
|
|
|
this.convertBlobToBase64Worker.postMessage(blob);
|
|
|
|
|
this.convertBlobToBase64Worker.onmessage = async (oEvent)=> {
|
|
|
|
|
this.capturedImage = oEvent.data
|
|
|
|
|
this.capturedImageTitle = 'foto'
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} */
|
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') {
|
2023-08-23 09:55:14 +01:00
|
|
|
const loader = this.toastService.loading()
|
2021-11-09 10:13:48 +01:00
|
|
|
|
2023-11-29 12:17:52 +01:00
|
|
|
// has file
|
|
|
|
|
if (this.PublicationFolderService.PublicationHasImage(this.publication)) {
|
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,
|
2023-11-29 12:17:52 +01:00
|
|
|
OriginalFileName: this.publication.OriginalFileName,
|
|
|
|
|
Files: this.seletedContent,
|
2020-12-11 18:00:38 +01:00
|
|
|
}
|
2021-06-29 14:16:49 +01:00
|
|
|
|
2023-11-29 12:17:52 +01:00
|
|
|
/* } else if (this.capturedVideo != '' && this.capturedImage == '') {
|
|
|
|
|
this.publication = {
|
|
|
|
|
DateIndex: this.publication.DateIndex,
|
|
|
|
|
DocumentId: this.publication.DocumentId,
|
|
|
|
|
ProcessId: this.publication.ProcessId,
|
|
|
|
|
Title: this.pub.Title,
|
|
|
|
|
Message: this.pub.Message,
|
|
|
|
|
DatePublication: this.publication.DatePublication,
|
|
|
|
|
OriginalFileName: this.publication.OriginalFileName || 'video',
|
|
|
|
|
Files: this.seletedContent,
|
|
|
|
|
FileExtension: 'mp4',
|
|
|
|
|
}
|
|
|
|
|
} */
|
|
|
|
|
// no names
|
|
|
|
|
} else if (!this.PublicationFolderService.PublicationHasImage(this.publication)) {
|
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,
|
2023-08-24 22:15:56 +01:00
|
|
|
OriginalFileName: this.publication.OriginalFileName,
|
2023-11-29 12:17:52 +01:00
|
|
|
Files: this.seletedContent,
|
2020-12-11 18:00:38 +01:00
|
|
|
}
|
2021-07-12 11:13:29 +01:00
|
|
|
|
2021-06-29 14:16:49 +01:00
|
|
|
|
2023-10-31 10:09:12 +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,
|
2023-08-22 15:43:20 +01:00
|
|
|
OriginalFileName: this.publication.OriginalFileName,
|
|
|
|
|
FileBase64: this.publication.FileBase64,
|
2023-08-24 22:15:56 +01:00
|
|
|
FileExtension: this.publication.FileExtension || 'jpeg',
|
2021-07-26 15:19:03 +01:00
|
|
|
}
|
|
|
|
|
|
2023-10-31 10:09:12 +01:00
|
|
|
} */
|
2023-08-23 09:55:14 +01:00
|
|
|
|
2023-08-24 22:15:56 +01:00
|
|
|
|
2023-08-23 09:55:14 +01:00
|
|
|
try {
|
|
|
|
|
|
2023-10-31 10:09:12 +01:00
|
|
|
const response = await this.publications.UpdatePublication(this.publication.ProcessId, this.publication).toPromise()
|
2023-08-23 09:55:14 +01:00
|
|
|
|
|
|
|
|
this.httpErrorHandle.httpsSucessMessagge('Editar publicação')
|
2023-10-31 10:09:12 +01:00
|
|
|
console.log({ response })
|
2023-08-23 09:55:14 +01:00
|
|
|
|
2021-07-26 15:19:03 +01:00
|
|
|
|
2023-08-23 09:55:14 +01:00
|
|
|
this.close();
|
|
|
|
|
} catch (error) {
|
2023-10-31 10:09:12 +01:00
|
|
|
if (error.status == 404) {
|
|
|
|
|
this.PublicationFolderService.deletePost(this.publication.ProcessId, this.publication.DocumentId)
|
2023-08-24 22:15:56 +01:00
|
|
|
this.close();
|
|
|
|
|
}
|
2023-08-23 09:55:14 +01:00
|
|
|
this.httpErrorHandle.httpStatusHandle(error)
|
2023-10-31 10:09:12 +01:00
|
|
|
} finally {
|
2023-08-23 09:55:14 +01:00
|
|
|
loader.remove()
|
2020-12-09 12:10:19 +01:00
|
|
|
}
|
2023-08-18 17:37:11 +01:00
|
|
|
|
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')
|
2023-10-31 10:09:12 +01:00
|
|
|
|
2023-11-29 12:17:52 +01:00
|
|
|
/* if (this.capturedImage != '') { */
|
|
|
|
|
this.publication = {
|
|
|
|
|
DateIndex: date,
|
|
|
|
|
DocumentId: null,
|
|
|
|
|
ProcessId: this.folderId,
|
|
|
|
|
Title: this.pub.Title,
|
|
|
|
|
Message: this.pub.Message,
|
|
|
|
|
DatePublication: date,
|
|
|
|
|
OriginalFileName: this.capturedImageTitle,
|
|
|
|
|
Files: this.seletedContent,
|
|
|
|
|
/* FileExtension: 'jpeg', */
|
2020-12-10 11:22:06 +01:00
|
|
|
}
|
2021-06-29 14:16:49 +01:00
|
|
|
|
2023-11-29 12:17:52 +01:00
|
|
|
/* } else if (this.capturedVideo != '') {
|
|
|
|
|
this.publication = {
|
|
|
|
|
DateIndex: date,
|
|
|
|
|
DocumentId: null,
|
|
|
|
|
ProcessId: this.folderId,
|
|
|
|
|
Title: this.pub.Title,
|
|
|
|
|
Message: this.pub.Message,
|
|
|
|
|
DatePublication: date,
|
|
|
|
|
OriginalFileName: this.capturedImageTitle || 'video',
|
|
|
|
|
Files: this.seletedContent,
|
|
|
|
|
FileExtension: 'mp4',
|
|
|
|
|
}
|
|
|
|
|
} */
|
|
|
|
|
|
2023-10-31 10:09:12 +01:00
|
|
|
|
2021-07-12 11:13:29 +01:00
|
|
|
const loader = this.toastService.loading()
|
|
|
|
|
|
2021-06-29 14:16:49 +01:00
|
|
|
try {
|
2023-10-31 10:09:12 +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')
|
2023-11-29 12:17:52 +01:00
|
|
|
window["sharedContent"] = null;
|
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
|
|
|
}
|
2023-08-23 09:55:14 +01:00
|
|
|
|
|
|
|
|
this.PublicationFolderService.getPublicationsIds(this.folderId)
|
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() {
|
2023-08-23 09:55:14 +01:00
|
|
|
this.modalController.dismiss(this.publication).then(() => {
|
2021-11-16 14:06:30 +01:00
|
|
|
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() {
|
2023-08-22 15:43:20 +01:00
|
|
|
this.capturedImageTitle = null;
|
2023-11-29 12:17:52 +01:00
|
|
|
this.seletedContent = [];
|
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
|
|
|
|
2023-10-31 10:09:12 +01:00
|
|
|
|
2020-12-02 15:08:45 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-16 13:07:55 +01:00
|
|
|
|
2021-11-22 13:53:37 +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) => {
|
2023-10-31 10:09:12 +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;
|
2023-10-31 10:09:12 +01:00
|
|
|
|
2021-11-26 14:46:08 +01:00
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2023-08-15 10:15:08 +01:00
|
|
|
deletePublicationImage() {
|
2023-11-29 12:17:52 +01:00
|
|
|
this.seletedContent = []
|
2023-08-15 10:15:08 +01:00
|
|
|
}
|
2023-08-28 16:36:31 +01:00
|
|
|
|
|
|
|
|
async compressImageBase64(base64String: string, maxWidth: number, maxHeight: number, quality: number): Promise<string> {
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
|
const image = new (window as any).Image();
|
|
|
|
|
image.src = base64String;
|
2023-10-31 10:09:12 +01:00
|
|
|
|
2023-08-28 16:36:31 +01:00
|
|
|
image.onload = async () => {
|
|
|
|
|
const canvas = document.createElement('canvas');
|
|
|
|
|
let newWidth = image.width;
|
|
|
|
|
let newHeight = image.height;
|
2023-10-31 10:09:12 +01:00
|
|
|
|
2023-08-28 16:36:31 +01:00
|
|
|
if (newWidth > maxWidth) {
|
|
|
|
|
newHeight *= maxWidth / newWidth;
|
|
|
|
|
newWidth = maxWidth;
|
|
|
|
|
}
|
2023-10-31 10:09:12 +01:00
|
|
|
|
2023-08-28 16:36:31 +01:00
|
|
|
if (newHeight > maxHeight) {
|
|
|
|
|
newWidth *= maxHeight / newHeight;
|
|
|
|
|
newHeight = maxHeight;
|
|
|
|
|
}
|
2023-10-31 10:09:12 +01:00
|
|
|
|
2023-08-28 16:36:31 +01:00
|
|
|
canvas.width = newWidth;
|
|
|
|
|
canvas.height = newHeight;
|
2023-10-31 10:09:12 +01:00
|
|
|
|
2023-08-28 16:36:31 +01:00
|
|
|
const context = canvas.getContext('2d');
|
|
|
|
|
context?.drawImage(image, 0, 0, newWidth, newHeight);
|
2023-10-31 10:09:12 +01:00
|
|
|
|
2023-08-28 16:36:31 +01:00
|
|
|
const compressedBase64 = canvas.toDataURL('image/jpeg', quality);
|
|
|
|
|
resolve(compressedBase64);
|
|
|
|
|
};
|
2023-10-31 10:09:12 +01:00
|
|
|
|
2023-08-28 16:36:31 +01:00
|
|
|
image.onerror = (error) => {
|
|
|
|
|
reject(error);
|
|
|
|
|
};
|
|
|
|
|
});
|
|
|
|
|
}
|
2023-10-31 10:09:12 +01:00
|
|
|
|
2023-11-06 13:33:35 +01:00
|
|
|
_getBase64(file) {
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
|
var reader = new FileReader();
|
|
|
|
|
reader.readAsDataURL(file);
|
|
|
|
|
reader.onload = function () {
|
|
|
|
|
resolve(reader.result)
|
|
|
|
|
};
|
|
|
|
|
reader.onerror = function (error) {
|
|
|
|
|
console.log('Error: ', error);
|
|
|
|
|
};
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
2023-11-10 15:37:12 +01:00
|
|
|
|
2023-11-06 13:33:35 +01:00
|
|
|
async copyVideoToDataDirectory(videoFile: any): Promise<string | null> {
|
|
|
|
|
try {
|
|
|
|
|
const { uri } = videoFile;
|
|
|
|
|
const fileName = uri.substring(uri.lastIndexOf('/') + 1);
|
|
|
|
|
const targetPath = Directory.Data + fileName; // Set your target directory path
|
2023-11-10 15:37:12 +01:00
|
|
|
|
2023-11-06 13:33:35 +01:00
|
|
|
await Filesystem.copy({
|
|
|
|
|
from: uri,
|
|
|
|
|
to: targetPath,
|
|
|
|
|
});
|
2023-11-10 15:37:12 +01:00
|
|
|
|
2023-11-06 13:33:35 +01:00
|
|
|
return targetPath;
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.error(error);
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-11-10 15:37:12 +01:00
|
|
|
|
2023-11-06 13:33:35 +01:00
|
|
|
async convertVideoToBase64(videoPath: string): Promise<string | null> {
|
|
|
|
|
try {
|
|
|
|
|
const file = await Filesystem.readFile({ path: videoPath, directory: FilesystemDirectory.Data });
|
|
|
|
|
if (file.data) {
|
|
|
|
|
return 'data:video/mp4;base64,' + file.data;
|
|
|
|
|
} else {
|
|
|
|
|
throw new Error('Failed to read the video file.');
|
|
|
|
|
}
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.error(error);
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-11-10 15:37:12 +01:00
|
|
|
|
|
|
|
|
async copyAndReadFile(filePath: string): Promise<string> {
|
|
|
|
|
try {
|
|
|
|
|
// Copy the file to the app's data directory
|
|
|
|
|
const copyResult = await Filesystem.copy({
|
|
|
|
|
from: filePath,
|
|
|
|
|
to: '20231110_125118.mp4', // or any desired name
|
|
|
|
|
directory: Directory.Data,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const copiedFilePath = copyResult.uri; // Use 'uri' instead of 'to'
|
|
|
|
|
|
|
|
|
|
// Read the copied file as base64
|
|
|
|
|
const readResult = await Filesystem.readFile({
|
|
|
|
|
path: copiedFilePath,
|
|
|
|
|
directory: Directory.Data,
|
|
|
|
|
encoding: Encoding.UTF8,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const base64Data = readResult.data;
|
|
|
|
|
console.log('Base64 data:', base64Data);
|
|
|
|
|
|
|
|
|
|
return base64Data;
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.error('Error copying/reading file:', error);
|
|
|
|
|
throw error;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-11-29 12:17:52 +01:00
|
|
|
removeTextBeforeSlash(inputString, controlString) {
|
|
|
|
|
if (inputString.includes(controlString)) {
|
|
|
|
|
const parts = inputString.split(controlString);
|
|
|
|
|
return parts.length > 1 ? parts[1] : inputString;
|
|
|
|
|
} else {
|
|
|
|
|
return inputString;
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-11-06 13:33:35 +01:00
|
|
|
|
2023-11-29 12:17:52 +01:00
|
|
|
reciveSharedContent() {
|
|
|
|
|
if (this.intent) {
|
|
|
|
|
this.filecontent = true
|
|
|
|
|
console.log(this.intent)
|
|
|
|
|
let filesArray = [];
|
|
|
|
|
let fistFile = {
|
|
|
|
|
title: this.intent.title,
|
|
|
|
|
type: this.intent.type,
|
|
|
|
|
url: this.intent.url
|
|
|
|
|
}
|
|
|
|
|
filesArray = this.intent?.additionalItems;
|
|
|
|
|
filesArray.push(fistFile)
|
|
|
|
|
filesArray.forEach(element => {
|
|
|
|
|
let FileExtension = this.removeTextBeforeSlash(element.title, '.')
|
|
|
|
|
if (this.checkFileType.checkFileType(FileExtension) == 'image' || this.checkFileType.checkFileType(FileExtension) == 'video') {
|
|
|
|
|
let resultUrl = decodeURIComponent(element.url);
|
|
|
|
|
Filesystem.readFile({ path: resultUrl }).then(async (content) => {
|
|
|
|
|
console.log('shared base',content.data)
|
|
|
|
|
let fileObject = {
|
|
|
|
|
FileBase64: this.removeTextBeforeSlash(content.data, ','),
|
|
|
|
|
FileExtension: FileExtension
|
|
|
|
|
}
|
|
|
|
|
this.seletedContent.push(fileObject)
|
|
|
|
|
})
|
|
|
|
|
} else {
|
|
|
|
|
this.httpErrorHandle.validationMessagge('filetype');
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-11-13 10:59:36 +01:00
|
|
|
|
|
|
|
|
|
2021-11-09 10:13:48 +01:00
|
|
|
}
|
2023-11-09 11:45:04 +01:00
|
|
|
|