2021-03-15 12:06:06 +01:00
|
|
|
import { Component, OnInit, Input, Output, EventEmitter } from '@angular/core';
|
2021-07-12 11:13:29 +01:00
|
|
|
import { SafeResourceUrl } from '@angular/platform-browser';
|
2021-03-15 12:06:06 +01:00
|
|
|
import { PublicationsService } from 'src/app/services/publications.service';
|
|
|
|
|
import { Publication } from 'src/app/models/publication';
|
|
|
|
|
import { Image } from 'src/app/models/image';
|
|
|
|
|
import { PhotoService } from 'src/app/services/photo.service';
|
2021-06-15 15:09:20 +01:00
|
|
|
import { ToastService } from 'src/app/services/toast.service';
|
2021-07-06 12:26:45 +01:00
|
|
|
import { FormControl, FormGroup, Validators } from '@angular/forms';
|
2021-11-09 18:06:10 +01:00
|
|
|
import { ThemeService } from 'src/app/services/theme.service';
|
2022-04-26 16:14:55 +01:00
|
|
|
import { Camera, CameraResultType, CameraSource} from '@capacitor/camera';
|
2023-02-27 09:34:36 +01:00
|
|
|
import { HttpErrorHandle } from 'src/app/services/http-error-handle.service';
|
2021-03-15 12:06:06 +01:00
|
|
|
@Component({
|
|
|
|
|
selector: 'app-new-publication',
|
|
|
|
|
templateUrl: './new-publication.page.html',
|
|
|
|
|
styleUrls: ['./new-publication.page.scss'],
|
|
|
|
|
})
|
|
|
|
|
export class NewPublicationPage implements OnInit {
|
|
|
|
|
showLoader: boolean;
|
2021-04-06 17:39:27 +01:00
|
|
|
pub: Publication = new Publication();
|
2021-03-15 12:06:06 +01:00
|
|
|
image: Image = new Image();
|
|
|
|
|
|
|
|
|
|
publicationTitle:string;
|
|
|
|
|
imgUrl:any;
|
|
|
|
|
|
|
|
|
|
Defaultimage:any = '';
|
|
|
|
|
|
2021-07-06 12:26:45 +01:00
|
|
|
Form: FormGroup;
|
|
|
|
|
validateFrom = false
|
2021-03-15 12:06:06 +01:00
|
|
|
|
|
|
|
|
photo: SafeResourceUrl;
|
2021-04-06 17:39:27 +01:00
|
|
|
|
|
|
|
|
publication: Publication = new Publication();
|
2021-03-15 12:06:06 +01:00
|
|
|
|
|
|
|
|
@Input() publicationType: string;
|
|
|
|
|
@Input() folderId: string;
|
2021-04-08 11:55:44 +01:00
|
|
|
@Input() publicationId:string;
|
2021-03-15 12:06:06 +01:00
|
|
|
@Output() closeDesktopComponent = new EventEmitter<any>();
|
2021-03-17 10:03:39 +01:00
|
|
|
@Output() openPublicationDetails = new EventEmitter<any>();
|
|
|
|
|
@Output() goBackToViewPublications = new EventEmitter<any>();
|
|
|
|
|
@Output() goBacktoPublicationDetails = new EventEmitter<any>();
|
2021-11-09 10:39:14 +01:00
|
|
|
|
2021-03-15 12:06:06 +01:00
|
|
|
guestPicture:any;
|
|
|
|
|
|
2021-11-09 10:39:14 +01:00
|
|
|
capturedImage:any = '';
|
2021-03-15 12:06:06 +01:00
|
|
|
capturedImageTitle:any;
|
2021-11-09 10:39:14 +01:00
|
|
|
photos: any[] = [];
|
2021-03-15 12:06:06 +01:00
|
|
|
|
|
|
|
|
constructor(
|
|
|
|
|
public photoService: PhotoService,
|
|
|
|
|
private publications: PublicationsService,
|
2021-06-15 15:09:20 +01:00
|
|
|
private toastService: ToastService,
|
2023-02-27 09:34:36 +01:00
|
|
|
public ThemeService: ThemeService,
|
|
|
|
|
private httpErroHandle: HttpErrorHandle
|
2021-08-23 16:06:05 +01:00
|
|
|
) {
|
|
|
|
|
this.publicationTitle = 'Nova Publicação';
|
|
|
|
|
}
|
2021-03-15 12:06:06 +01:00
|
|
|
|
|
|
|
|
ngOnInit() {
|
2021-04-08 11:55:44 +01:00
|
|
|
if(this.publicationType == '3'){
|
|
|
|
|
this.getPublicationDetail();
|
|
|
|
|
}
|
2021-03-15 12:06:06 +01:00
|
|
|
this.setTitle();
|
2021-11-09 10:39:14 +01:00
|
|
|
//this.clear();
|
|
|
|
|
//this.takePicture();
|
2021-03-15 12:06:06 +01:00
|
|
|
}
|
2021-04-08 11:55:44 +01:00
|
|
|
|
2021-11-09 10:39:14 +01:00
|
|
|
getPublicationDetail() {
|
2021-04-08 11:55:44 +01:00
|
|
|
this.showLoader = true;
|
2021-08-23 17:17:07 +01:00
|
|
|
this.publications.GetPublicationById(this.publicationId).subscribe( res =>{
|
2021-04-08 11:55:44 +01:00
|
|
|
this.publication = {
|
|
|
|
|
DateIndex: res.DateIndex,
|
|
|
|
|
DocumentId: res.DocumentId,
|
|
|
|
|
ProcessId:res.ProcessId,
|
|
|
|
|
Title:res.Title,
|
|
|
|
|
Message: res.Message,
|
|
|
|
|
DatePublication: res.DatePublication,
|
|
|
|
|
FileBase64: "data:image/jpg;base64," + res.FileBase64,
|
|
|
|
|
OriginalFileName: res.OriginalFileName,
|
|
|
|
|
FileExtension: 'jpeg',
|
|
|
|
|
}
|
|
|
|
|
this.pub = this.publication;
|
|
|
|
|
this.showLoader = false;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2021-11-09 10:39:14 +01:00
|
|
|
async takePicture() {
|
|
|
|
|
const capturedImage = await Camera.getPhoto({
|
2023-07-26 13:06:42 +01:00
|
|
|
quality: 50,
|
2021-11-09 10:39:14 +01:00
|
|
|
// allowEditing: true,
|
2022-02-11 15:08:27 +01:00
|
|
|
resultType: CameraResultType.Base64,
|
2021-11-09 10:39:14 +01:00
|
|
|
source: CameraSource.Camera
|
|
|
|
|
});
|
|
|
|
|
|
2022-02-11 15:08:27 +01:00
|
|
|
this.capturedImage = 'data:image/jpeg;base64,' +capturedImage.base64String;
|
|
|
|
|
this.capturedImageTitle = capturedImage.path;
|
2022-04-28 09:32:27 +01:00
|
|
|
//
|
2021-11-09 10:39:14 +01:00
|
|
|
}
|
|
|
|
|
|
2021-11-09 16:38:26 +01:00
|
|
|
async laodPicture() {
|
|
|
|
|
const capturedImage = await Camera.getPhoto({
|
|
|
|
|
quality: 90,
|
2022-02-11 15:08:27 +01:00
|
|
|
resultType: CameraResultType.Base64,
|
|
|
|
|
source: CameraSource.Photos
|
2021-11-09 16:38:26 +01:00
|
|
|
});
|
|
|
|
|
|
2022-02-11 15:08:27 +01:00
|
|
|
this.capturedImage = 'data:image/jpeg;base64,' +capturedImage.base64String;
|
|
|
|
|
this.capturedImageTitle = capturedImage.path;
|
2021-11-09 16:38:26 +01:00
|
|
|
}
|
|
|
|
|
|
2021-07-06 12:26:45 +01:00
|
|
|
|
|
|
|
|
runValidation() {
|
|
|
|
|
this.validateFrom = true
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
injectValidation() {
|
|
|
|
|
|
|
|
|
|
this.Form = new FormGroup({
|
|
|
|
|
Subject: new FormControl(this.pub.Title, [
|
2023-02-27 09:34:36 +01:00
|
|
|
Validators.required,
|
2021-07-06 12:26:45 +01:00
|
|
|
// Validators.minLength(4)
|
2021-07-15 15:39:10 +01:00
|
|
|
]),
|
|
|
|
|
Message: new FormControl(this.pub.Message, [
|
2023-02-27 09:34:36 +01:00
|
|
|
Validators.required,
|
2021-07-15 15:39:10 +01:00
|
|
|
Validators.maxLength(1000)
|
2021-07-06 12:26:45 +01:00
|
|
|
])
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2021-07-14 19:04:33 +01:00
|
|
|
async save() {
|
2021-07-06 12:26:45 +01:00
|
|
|
|
|
|
|
|
this.injectValidation()
|
|
|
|
|
this.runValidation()
|
|
|
|
|
|
2023-02-27 09:34:36 +01:00
|
|
|
if(this.Form.invalid) {
|
|
|
|
|
return false
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
|
|
}
|
2021-07-06 12:26:45 +01:00
|
|
|
|
2021-07-14 15:38:58 +01:00
|
|
|
if(this.publicationType == '3') {
|
2021-07-26 16:40:51 +01:00
|
|
|
|
2021-05-25 16:12:40 +01:00
|
|
|
if(this.capturedImage != '') {
|
2021-07-26 16:40:51 +01:00
|
|
|
|
2021-03-15 12:06:06 +01:00
|
|
|
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.capturedImageTitle,
|
|
|
|
|
FileBase64: this.capturedImage,
|
|
|
|
|
FileExtension: 'jpeg',
|
|
|
|
|
}
|
2021-07-14 15:38:58 +01:00
|
|
|
|
2022-04-28 09:32:27 +01:00
|
|
|
|
|
|
|
|
|
2021-07-12 11:13:29 +01:00
|
|
|
const loader = this.toastService.loading()
|
2021-05-25 16:12:40 +01:00
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
await this.publications.UpdatePublication(this.publication.ProcessId, this.publication).toPromise()
|
2023-02-27 09:34:36 +01:00
|
|
|
this.httpErroHandle.httpsSucessMessagge('Criar publicação')
|
2021-05-25 16:12:40 +01:00
|
|
|
|
|
|
|
|
this.goBack();
|
|
|
|
|
} catch (error) {
|
2023-02-27 09:34:36 +01:00
|
|
|
this.httpErroHandle.httpStatusHandle(error)
|
2021-07-12 11:13:29 +01:00
|
|
|
} finally {
|
|
|
|
|
loader.remove()
|
2021-05-25 16:12:40 +01:00
|
|
|
}
|
|
|
|
|
|
2021-03-15 12:06:06 +01:00
|
|
|
}
|
2021-08-23 16:00:58 +01:00
|
|
|
else if (!this.publication.OriginalFileName) { //
|
2021-03-15 12:06:06 +01:00
|
|
|
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,
|
2021-08-23 16:00:58 +01:00
|
|
|
OriginalFileName: this.capturedImageTitle,
|
2021-07-14 16:57:06 +01:00
|
|
|
// OriginalFileName: this.publication.OriginalFileName,
|
|
|
|
|
// FileBase64: this.publication.FileBase64,
|
|
|
|
|
// FileExtension: 'jpeg',
|
2021-03-15 12:06:06 +01:00
|
|
|
}
|
2021-07-12 11:13:29 +01:00
|
|
|
const loader = this.toastService.loading()
|
2021-05-25 16:12:40 +01:00
|
|
|
|
|
|
|
|
try {
|
2022-04-28 09:32:27 +01:00
|
|
|
|
2021-05-25 16:12:40 +01:00
|
|
|
await this.publications.UpdatePublication(this.publication.ProcessId, this.publication).toPromise()
|
2021-11-10 15:51:27 +01:00
|
|
|
|
2023-02-27 09:34:36 +01:00
|
|
|
this.httpErroHandle.httpsSucessMessagge('Criar publicação')
|
2021-11-09 10:39:14 +01:00
|
|
|
|
2021-05-25 16:12:40 +01:00
|
|
|
this.goBack();
|
|
|
|
|
} catch (error) {
|
2023-02-27 09:34:36 +01:00
|
|
|
this.httpErroHandle.httpStatusHandle(error)
|
2021-07-12 11:13:29 +01:00
|
|
|
} finally {
|
|
|
|
|
loader.remove()
|
2021-05-25 16:12:40 +01:00
|
|
|
}
|
2021-11-09 10:39:14 +01:00
|
|
|
|
2021-07-26 15:19:03 +01:00
|
|
|
} else {
|
|
|
|
|
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.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 09:34:36 +01:00
|
|
|
this.httpErroHandle.httpsSucessMessagge('Criar publicação')
|
2021-07-26 15:19:03 +01:00
|
|
|
|
|
|
|
|
this.goBack();
|
|
|
|
|
} catch (error) {
|
2023-02-27 09:34:36 +01:00
|
|
|
this.httpErroHandle.httpStatusHandle(error)
|
2021-07-26 15:19:03 +01:00
|
|
|
} finally {
|
|
|
|
|
loader.remove()
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-15 12:06:06 +01:00
|
|
|
}
|
|
|
|
|
}
|
2021-07-12 11:13:29 +01:00
|
|
|
else {
|
2021-07-14 16:57:06 +01:00
|
|
|
|
|
|
|
|
let time = new Date()
|
2021-03-15 12:06:06 +01:00
|
|
|
this.publication = {
|
2021-07-14 16:57:06 +01:00
|
|
|
DateIndex: time,
|
2021-07-26 15:19:03 +01:00
|
|
|
DocumentId: null,
|
2021-03-15 12:06:06 +01:00
|
|
|
ProcessId:this.folderId,
|
2021-04-06 17:39:27 +01:00
|
|
|
Title: this.pub.Title,
|
2021-03-15 12:06:06 +01:00
|
|
|
Message: this.pub.Message,
|
2021-07-14 16:57:06 +01:00
|
|
|
DatePublication: time,
|
2021-03-15 12:06:06 +01:00
|
|
|
OriginalFileName: this.capturedImageTitle,
|
|
|
|
|
FileBase64: this.capturedImage,
|
|
|
|
|
FileExtension: 'jpeg',
|
|
|
|
|
}
|
2021-11-09 10:39:14 +01:00
|
|
|
|
2021-07-12 11:13:29 +01:00
|
|
|
const loader = this.toastService.loading()
|
|
|
|
|
|
2021-05-25 16:12:40 +01:00
|
|
|
try {
|
2022-04-28 09:32:27 +01:00
|
|
|
|
2021-05-25 16:12:40 +01:00
|
|
|
await this.publications.CreatePublication(this.folderId, this.publication).toPromise()
|
2023-02-27 09:31:10 +01:00
|
|
|
if(this.publicationTitle == '1') {
|
|
|
|
|
|
|
|
|
|
} else if (this.publicationTitle == '2') {
|
2023-02-27 09:45:31 +01:00
|
|
|
this.httpErroHandle.httpsSucessMessagge('Criar publicação')
|
2023-02-27 09:31:10 +01:00
|
|
|
} else if (this.publicationTitle == '3') {
|
2023-02-27 09:45:31 +01:00
|
|
|
this.httpErroHandle.httpsSucessMessagge('Editar publicação')
|
2023-02-27 09:31:10 +01:00
|
|
|
}
|
|
|
|
|
|
2021-05-25 16:12:40 +01:00
|
|
|
|
|
|
|
|
this.goBackToViewPublications.emit();
|
|
|
|
|
} catch (error) {
|
2023-02-27 09:34:36 +01:00
|
|
|
this.httpErroHandle.httpStatusHandle(error)
|
2021-07-12 11:13:29 +01:00
|
|
|
} finally {
|
|
|
|
|
loader.remove()
|
2021-05-25 16:12:40 +01:00
|
|
|
}
|
2021-03-15 12:06:06 +01:00
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
close(){
|
2021-03-17 10:03:39 +01:00
|
|
|
this.goBack();
|
2021-03-15 12:06:06 +01:00
|
|
|
}
|
2021-11-10 15:51:27 +01:00
|
|
|
|
2021-03-15 12:06:06 +01:00
|
|
|
clear(){
|
|
|
|
|
this.capturedImage = '';
|
|
|
|
|
}
|
2021-12-13 09:51:57 +01:00
|
|
|
|
2021-03-15 12:06:06 +01:00
|
|
|
setTitle(){
|
2021-08-23 16:00:58 +01:00
|
|
|
if(this.publicationType == '1') {
|
2021-03-15 12:06:06 +01:00
|
|
|
this.publicationTitle = 'Nova Publicação Rápida';
|
|
|
|
|
}
|
2021-08-23 16:00:58 +01:00
|
|
|
else if(this.publicationType == '2') {
|
2021-03-15 12:06:06 +01:00
|
|
|
this.publicationTitle = 'Nova Publicação';
|
|
|
|
|
}
|
2021-07-14 15:38:58 +01:00
|
|
|
else if(this.publicationType == '3') {
|
2021-03-15 12:06:06 +01:00
|
|
|
this.publicationTitle = 'Editar Publicação';
|
2021-03-16 14:35:52 +01:00
|
|
|
this.pub = this.publication;
|
2021-03-15 12:06:06 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-17 09:01:24 +01:00
|
|
|
async goBack(){
|
2021-11-09 10:39:14 +01:00
|
|
|
|
2021-03-17 10:03:39 +01:00
|
|
|
if(this.publicationType == '2'){
|
|
|
|
|
this.goBackToViewPublications.emit();
|
|
|
|
|
} else {
|
2021-04-08 11:55:44 +01:00
|
|
|
this.goBackToViewPublications.emit();
|
|
|
|
|
//this.goBacktoPublicationDetails.emit();
|
2021-03-17 10:03:39 +01:00
|
|
|
}
|
2021-11-09 10:39:14 +01:00
|
|
|
|
2021-03-17 09:01:24 +01:00
|
|
|
}
|
|
|
|
|
|
2021-03-15 12:06:06 +01:00
|
|
|
}
|