mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-18 20:47:54 +00:00
188 lines
5.0 KiB
TypeScript
188 lines
5.0 KiB
TypeScript
import { Component, OnInit, Input, Output, EventEmitter } from '@angular/core';
|
|
import { ModalController } from '@ionic/angular';
|
|
import { Publication } from 'src/app/models/publication';
|
|
import { NewPublicationPage } from 'src/app/pages/publications/new-publication/new-publication.page';
|
|
import { PublicationsService } from 'src/app/services/publications.service';
|
|
import { ToastService } from 'src/app/services/toast.service';
|
|
import { ThemeService } from 'src/app/services/theme.service'
|
|
import { ViewMediaPage } from 'src/app/modals/view-media/view-media.page';
|
|
import { PermissionService } from 'src/app/services/permission.service';
|
|
import { HttpErrorHandle } from 'src/app/services/http-error-handle.service';
|
|
import { PublicationFolderService } from 'src/app/store/publication-folder.service';
|
|
import { PublicationPipe } from 'src/app/pipes/publication.pipe';
|
|
@Component({
|
|
selector: 'app-publication-detail-shared',
|
|
templateUrl: './publication-detail.page.html',
|
|
styleUrls: ['./publication-detail.page.scss'],
|
|
})
|
|
export class PublicationDetailPage implements OnInit {
|
|
showLoader: boolean;
|
|
/* folderId: string; */
|
|
publication: Publication;
|
|
@Input() publicationId: string;
|
|
@Input() folderId: string;
|
|
@Output() addNewPublication = new EventEmitter<any>();
|
|
@Output() closeDesktopComponent = new EventEmitter<any>();
|
|
@Output() goBackToViewPublications = new EventEmitter();
|
|
publicationPipe = new PublicationPipe()
|
|
|
|
constructor(
|
|
private modalController: ModalController,
|
|
private publications:PublicationsService,
|
|
private toastService: ToastService,
|
|
public ThemeService: ThemeService,
|
|
public p:PermissionService,
|
|
private httpErrorHandle: HttpErrorHandle,
|
|
public publicationFolderService: PublicationFolderService,
|
|
) {
|
|
|
|
/* this.folderId = this.navParams.get('folderIdId'); */
|
|
this.publication = {
|
|
DateIndex: null,
|
|
DocumentId: null,
|
|
ProcessId:'',
|
|
Title:'',
|
|
Message: '',
|
|
/* image: null, */
|
|
DatePublication: null,
|
|
FileBase64: '',
|
|
OriginalFileName: '',
|
|
FileExtension: '',
|
|
};
|
|
}
|
|
|
|
ngOnInit() {
|
|
this.getPublicationDetail();
|
|
}
|
|
doRefresh(event) {
|
|
this.getPublicationDetail();
|
|
|
|
setTimeout(() => {
|
|
try {
|
|
event?.target?.complete();
|
|
} catch(error) {}
|
|
}, 2000);
|
|
}
|
|
|
|
getPublicationDetail() {
|
|
|
|
const folderId = this.folderId
|
|
const localPublication = this.publicationFolderService.getLocalPublication(folderId, this.publicationId);
|
|
|
|
if(localPublication?.ProcessId) {
|
|
|
|
this.publication = localPublication
|
|
|
|
} else {
|
|
|
|
this.showLoader = true;
|
|
this.publications.GetPublicationById(this.publicationId).subscribe(res => {
|
|
|
|
this.publication = this.publicationPipe.itemList(res)
|
|
|
|
|
|
this.showLoader = false;
|
|
}, (error) => {
|
|
this.showLoader = false;
|
|
|
|
if(error.status == 404) {
|
|
this.publicationFolderService.deletePost(this.folderId, this.publicationId)
|
|
}
|
|
|
|
this.goBack();
|
|
this.httpErrorHandle.httpStatusHandle(error)
|
|
});
|
|
}
|
|
|
|
}
|
|
|
|
close() {
|
|
this.modalController.dismiss();
|
|
}
|
|
|
|
async deletePost(){
|
|
|
|
const laoder = this.toastService.loading()
|
|
|
|
try {
|
|
await this.publications.DeletePublication(this.folderId, this.publicationId).toPromise();
|
|
this.httpErrorHandle.httpsSucessMessagge('Eliminar publicação')
|
|
|
|
this.publicationFolderService.deletePost(this.folderId, this.publicationId)
|
|
|
|
if(window['app-view-publications-page-doRefresh']) {
|
|
window['app-view-publications-page-doRefresh']()
|
|
}
|
|
|
|
this.goBackToViewPublications.emit();
|
|
} catch (error) {
|
|
|
|
if(error.status == 404) {
|
|
this.publicationFolderService.deletePost(this.folderId, this.publicationId)
|
|
this.goBackToViewPublications.emit();
|
|
}
|
|
|
|
this.httpErrorHandle.httpStatusHandle(error)
|
|
} finally {
|
|
laoder.remove()
|
|
}
|
|
|
|
}
|
|
|
|
async editPost(publicationType:any) {
|
|
|
|
|
|
if(window.innerWidth < 701){
|
|
const modal = await this.modalController.create({
|
|
component: NewPublicationPage,
|
|
componentProps:{
|
|
publicationType: publicationType,
|
|
publication: this.publication,
|
|
},
|
|
cssClass: 'new-publication',
|
|
backdropDismiss: false
|
|
});
|
|
|
|
modal.onDidDismiss().then(()=>{
|
|
setTimeout(() => {
|
|
this.getPublicationDetail();
|
|
}, 5000);
|
|
});
|
|
await modal.present();
|
|
} else {
|
|
|
|
this.addNewPublication.emit({
|
|
publicationType: publicationType,
|
|
folderId: this.folderId,
|
|
publication: this.publication,
|
|
})
|
|
}
|
|
|
|
}
|
|
|
|
async goBack(){
|
|
|
|
this.goBackToViewPublications.emit();
|
|
}
|
|
|
|
async openPreview(item) {
|
|
const modal = await this.modalController.create({
|
|
component: ViewMediaPage,
|
|
cssClass: 'modal modal-desktop',
|
|
componentProps: {
|
|
image: item.FileBase64,
|
|
username: item.Title,
|
|
_updatedAt: item.DatePublication
|
|
}
|
|
});
|
|
modal.present();
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|