Files
doneit-web/src/app/pages/publications/publications.page.ts
T

543 lines
15 KiB
TypeScript
Raw Normal View History

import { Component, OnInit } from '@angular/core';
2020-12-10 11:22:06 +01:00
import { Router, NavigationEnd } from '@angular/router';
import { ModalController, Platform } from '@ionic/angular';
import { PublicationFolder } from 'src/app/models/publicationfolder';
import { PublicationsService } from 'src/app/services/publications.service';
import { NewActionPage } from './new-action/new-action.page';
import { ViewPublicationsPage } from './view-publications/view-publications.page';
2021-07-21 19:08:31 +01:00
import { AnimationController } from '@ionic/angular';
2021-04-08 11:55:44 +01:00
import { Publication } from 'src/app/models/publication';
2021-06-30 15:01:07 +01:00
import { ActionsOptionsPage } from 'src/app/shared/popover/actions-options/actions-options.page';
2021-07-07 16:34:01 +01:00
import { EditActionPage } from './edit-action/edit-action.page';
2021-07-13 17:10:54 +01:00
import { ToastService } from 'src/app/services/toast.service';
2021-10-09 09:15:22 +01:00
import { SqliteService } from 'src/app/services/sqlite.service';
2021-10-19 09:41:06 +01:00
import { BackgroundService } from 'src/app/services/background.service';
2021-10-21 15:47:00 +01:00
import { ThemeService } from 'src/app/services/theme.service'
2022-01-28 16:19:54 +01:00
import { Storage } from '@ionic/storage';
2022-03-30 16:32:56 +01:00
import { PermissionService } from 'src/app/services/permission.service';
2021-11-22 16:37:11 +01:00
2020-12-15 19:37:42 +01:00
@Component({
selector: 'app-publications',
templateUrl: './publications.page.html',
styleUrls: ['./publications.page.scss'],
})
export class PublicationsPage implements OnInit {
2020-12-10 11:22:06 +01:00
showLoader: boolean;
2020-12-11 15:09:53 +01:00
publicationFolder: PublicationFolder;
2021-04-08 11:55:44 +01:00
publication: Publication;
publicationsEventFolderList: PublicationFolder[];
2021-07-22 14:36:29 +01:00
actionsListStorage: PublicationFolder[] = new Array();
publicationsTravelFolderList: PublicationFolder[];
2021-10-09 09:15:22 +01:00
theDate: any;
theEndDate: any;
customDate: any;
2020-12-10 11:22:06 +01:00
months: string[];
2021-10-09 09:15:22 +01:00
days: string[];
2020-12-10 11:22:06 +01:00
2021-07-22 14:36:29 +01:00
2021-03-12 14:38:55 +01:00
desktopComponent: any = {
showViewPublication: false,
2021-03-15 16:47:16 +01:00
showAddNewPublication: false,
2021-03-16 12:14:46 +01:00
showPublicationDetail: false,
2021-06-30 16:15:54 +01:00
showAddActions: false,
showEditActions: false
2021-03-12 14:38:55 +01:00
}
folderId: string;
2021-03-16 14:35:52 +01:00
// data set from child component
2021-03-15 12:06:06 +01:00
publicationType: any;
2021-03-15 16:47:16 +01:00
publicationId: string;
2021-03-12 14:38:55 +01:00
2021-03-16 14:35:52 +01:00
// from publication details
2021-04-08 11:55:44 +01:00
//publication: object;
2021-06-17 16:43:18 +01:00
hideRefreshBtn = true;
2021-07-08 09:49:18 +01:00
showSlidingOptions = true;
2021-09-02 13:19:50 +01:00
idSelected: string;
2022-01-28 16:19:54 +01:00
skeletonLoader: boolean;
2021-03-16 14:35:52 +01:00
constructor(
2021-07-22 14:36:29 +01:00
private router: Router,
private modalController: ModalController,
2020-12-15 19:37:42 +01:00
private animationController: AnimationController,
private publications: PublicationsService,
2021-10-09 09:15:22 +01:00
private toastService: ToastService,
2021-10-19 09:41:06 +01:00
private sqliteservice: SqliteService,
private backgroundservice: BackgroundService,
2021-10-21 15:47:00 +01:00
private platform: Platform,
public ThemeService: ThemeService,
2022-03-30 16:32:56 +01:00
private storage: Storage,
public p: PermissionService,
2021-12-14 16:22:53 +01:00
2021-10-09 09:15:22 +01:00
) {
this.months = ["Janeiro", "Fevereiro", "Março", "Abril", "Maio", "Junho", "Julho", "Agosto", "Setembro", "Outubro", "Novembro", "Dezembro"];
this.days = ["Domingo", "Segunda-feira", "Terça-feira", "Quarta-feira", "Quinta-feira", "Sexta-feira", "Sábado"];
2021-12-16 19:11:30 +01:00
this.skeletonLoader = true;
2021-10-09 09:15:22 +01:00
}
ngOnInit() {
2021-10-19 09:41:06 +01:00
const pathname = window.location.pathname
this.router.events.forEach((event) => {
if (event instanceof NavigationEnd && event.url == pathname) {
this.getActions();
2022-01-28 16:19:54 +01:00
2021-10-19 09:41:06 +01:00
}
});
this.hideRefreshButton();
2022-01-28 16:19:54 +01:00
/* this.backgroundservice.registerBackService('Online', () => {
2021-10-19 09:41:06 +01:00
this.getActions();
2022-01-28 16:19:54 +01:00
}) */
2021-10-19 09:41:06 +01:00
2021-06-17 16:43:18 +01:00
}
2021-10-09 09:15:22 +01:00
hideRefreshButton() {
2021-06-17 16:43:18 +01:00
window.onresize = (event) => {
2022-02-09 14:51:00 +01:00
if (window.innerWidth < 701) {
2021-06-17 16:43:18 +01:00
this.hideRefreshBtn = false;
2021-07-08 09:49:18 +01:00
this.showSlidingOptions = false;
2021-06-17 16:43:18 +01:00
}
2021-10-09 09:15:22 +01:00
else {
2021-06-17 16:43:18 +01:00
this.hideRefreshBtn = true;
2021-07-08 09:49:18 +01:00
this.showSlidingOptions = true;
2021-06-17 16:43:18 +01:00
}
}
2022-02-09 14:51:00 +01:00
if (window.innerWidth < 701) {
2021-06-17 16:43:18 +01:00
this.hideRefreshBtn = false;
2021-07-08 09:49:18 +01:00
this.showSlidingOptions = false;
}
2021-10-09 09:15:22 +01:00
else {
2021-07-08 09:49:18 +01:00
this.hideRefreshBtn = true;
this.showSlidingOptions = true;
2021-06-17 16:43:18 +01:00
}
2020-12-10 11:22:06 +01:00
}
2021-07-07 16:34:01 +01:00
refreshing() {
setTimeout(() => {
this.getActions();
}, 1500);
}
2021-07-22 14:36:29 +01:00
2021-06-17 16:12:56 +01:00
doRefresh(event) {
this.getActions();
2020-12-10 11:22:06 +01:00
setTimeout(() => {
2021-06-17 16:12:56 +01:00
event.target.complete();
}, 250);
}
2021-05-05 16:08:38 +01:00
get windowInnerWidth(): number {
return window.innerWidth
}
2021-07-22 14:36:29 +01:00
getDate(date) {
this.theDate = new Date(date);
2021-10-09 09:15:22 +01:00
return this.theDate.getDate() + " de " + (this.months[this.theDate.getMonth()]) + " de " + this.theDate.getFullYear()
2021-07-22 14:36:29 +01:00
}
2021-07-13 17:01:59 +01:00
getActions() {
2020-12-15 19:37:42 +01:00
this.showLoader = true;
2021-12-16 19:11:30 +01:00
this.skeletonLoader = true;
2022-01-28 16:19:54 +01:00
this.getFromDB()
this.publications.GetPublicationFolderList().subscribe(async res => {
2021-10-09 09:15:22 +01:00
2022-04-28 09:32:27 +01:00
2021-07-21 19:08:31 +01:00
2022-01-28 16:19:54 +01:00
let publicationsEventFolderList = new Array();
let publicationsTravelFolderList = new Array();
2021-07-21 19:08:31 +01:00
2020-12-11 15:09:53 +01:00
res.forEach(data => {
let folder: PublicationFolder = {
ProcessId: data.ProcessId,
Description: data.Description,
Detail: data.Detail,
2021-07-22 14:36:29 +01:00
DateBegin: data.DateBegin,
DateEnd: data.DateEnd,
2020-12-11 15:09:53 +01:00
ActionType: data.ActionType,
}
2021-07-21 20:26:41 +01:00
this.addActionToDB(folder)
2021-10-11 17:22:01 +01:00
2021-10-09 09:15:22 +01:00
if (data.ActionType == "Evento") {
2022-04-26 14:34:52 +01:00
2022-01-28 16:19:54 +01:00
publicationsEventFolderList.push(folder);
2020-12-11 15:09:53 +01:00
}
2021-10-09 09:15:22 +01:00
else {
2022-04-28 09:32:27 +01:00
2022-01-28 16:19:54 +01:00
publicationsTravelFolderList.push(folder);
2020-12-11 15:09:53 +01:00
}
2022-01-28 16:19:54 +01:00
2020-12-11 15:09:53 +01:00
});
2021-07-21 19:08:31 +01:00
2022-01-28 16:19:54 +01:00
if (this.platform.is('desktop') || this.platform.is('mobileweb')) {
await this.storage.set('actionsEvents', publicationsEventFolderList);
await this.storage.set('actionsViagens', publicationsTravelFolderList);
this.getFromDB()
} else {
this.getFromDB()
}
2021-07-21 19:08:31 +01:00
2022-01-28 16:19:54 +01:00
this.showLoader = false;
}/* , (error) => {
2021-10-19 09:41:06 +01:00
this.getFromDB();
2022-01-28 16:19:54 +01:00
} */);
2021-12-16 19:11:30 +01:00
this.skeletonLoader = false;
}
2022-01-28 16:19:54 +01:00
addActionToStorage(events, viagens) {
2022-04-28 09:32:27 +01:00
2022-01-28 16:19:54 +01:00
if (this.platform.is('desktop') || this.platform.is('mobileweb')) {
this.storage.set('actionsEvents', events);
this.storage.set('actionsViagens', viagens);
}
}
addActionToDB(folder) {
if (this.platform.is('desktop') || this.platform.is('mobileweb')) {
} else {
this.sqliteservice.addactions(folder);
}
}
2021-10-09 09:15:22 +01:00
getFromDB() {
2021-12-14 16:22:53 +01:00
if (this.platform.is('desktop') || this.platform.is('mobileweb')) {
2022-01-28 16:19:54 +01:00
this.publicationsEventFolderList = new Array();
this.publicationsTravelFolderList = new Array();
2022-06-06 16:09:20 +01:00
this.storage.get('actionsEvents').then((events = []) => {
2022-04-28 09:32:27 +01:00
2022-06-06 16:09:20 +01:00
if(Array.isArray(events)) {
events.forEach(data => {
let folder: PublicationFolder = {
ProcessId: data.ProcessId,
Description: data.Description,
Detail: data.Detail,
DateBegin: data.DateBegin,
DateEnd: data.DateEnd,
ActionType: data.ActionType,
}
this.publicationsEventFolderList.push(folder);
this.showLoader = false;
});
}
2022-01-28 16:19:54 +01:00
});
2022-05-27 13:36:37 +01:00
this.storage.get('actionsViagens').then((viagens = []) => {
2022-04-28 09:32:27 +01:00
2022-06-06 16:09:20 +01:00
if(Array.isArray(viagens)) {
viagens.forEach(data => {
let folder: PublicationFolder = {
ProcessId: data.ProcessId,
Description: data.Description,
Detail: data.Detail,
DateBegin: data.DateBegin,
DateEnd: data.DateEnd,
ActionType: data.ActionType,
}
this.publicationsTravelFolderList.push(folder);
this.showLoader = false;
});
}
2022-01-28 16:19:54 +01:00
});
} else {
this.sqliteservice.getAllActions().then((actions: any[]) => {
2022-04-28 09:32:27 +01:00
this.publicationsEventFolderList = new Array();
this.publicationsTravelFolderList = new Array();
actions.forEach(data => {
let folder: PublicationFolder = {
ProcessId: data.ProcessId,
Description: data.Description,
Detail: data.Detail,
DateBegin: data.DateBegin,
DateEnd: data.DateEnd,
ActionType: data.ActionType,
}
if (data.ActionType == "Evento") {
this.publicationsEventFolderList.push(folder);
}
else {
this.publicationsTravelFolderList.push(folder);
}
this.showLoader = false;
});
})
}
2021-10-09 09:15:22 +01:00
}
async editAction(folderId?: string) {
2021-07-07 16:34:01 +01:00
const modal = await this.modalController.create({
component: EditActionPage,
2021-10-09 09:15:22 +01:00
componentProps: {
2021-07-07 17:02:19 +01:00
folderId: folderId,
2021-07-07 16:34:01 +01:00
},
cssClass: 'new-action modal modal-desktop',
2021-07-07 17:02:19 +01:00
backdropDismiss: true
2021-07-07 16:34:01 +01:00
});
await modal.present();
2021-10-09 09:15:22 +01:00
modal.onDidDismiss().then(() => {
2021-07-07 16:34:01 +01:00
this.getActions();
});
//this.refreshing()
}
2021-10-09 09:15:22 +01:00
async deleteAction(id?: string) {
2021-07-13 17:10:54 +01:00
const loader = this.toastService.loading();
try {
2021-07-13 17:15:25 +01:00
await this.publications.DeletePresidentialAction(id).toPromise();
2021-11-09 15:37:59 +01:00
this.toastService._successMessage()
2021-10-09 09:15:22 +01:00
} catch (e) {
2021-11-09 15:37:59 +01:00
this.toastService._badRequest()
2021-07-13 17:10:54 +01:00
}
finally {
loader.remove()
}
2021-07-07 16:34:01 +01:00
this.refreshing()
}
2021-10-09 09:15:22 +01:00
async AddPublicationFolder(item?: any) {
2021-07-22 14:36:29 +01:00
2021-03-15 12:06:06 +01:00
this.closeDesktopComponent();
2022-06-06 15:28:27 +01:00
this.idSelected = '';
2022-06-06 16:09:20 +01:00
2022-02-09 14:42:36 +01:00
if (window.innerWidth < 701) {
2021-03-17 11:12:20 +01:00
2021-03-16 12:14:46 +01:00
const modal = await this.modalController.create({
component: NewActionPage,
2021-10-09 09:15:22 +01:00
componentProps: {
2021-03-16 12:14:46 +01:00
item: item,
},
2021-04-14 15:27:50 +01:00
cssClass: 'new-action modal modal-desktop',
2021-03-16 12:14:46 +01:00
backdropDismiss: false
});
await modal.present();
2021-10-09 09:15:22 +01:00
modal.onDidDismiss().then(() => {
2021-06-17 16:12:56 +01:00
this.getActions();
2021-03-16 12:14:46 +01:00
});
} else {
this.desktopComponent.showAddActions = true;
}
}
2021-10-09 09:15:22 +01:00
goToPublicationsList(folderId: string) {
2022-02-09 14:42:36 +01:00
if (window.innerWidth < 701) {
2021-10-09 09:15:22 +01:00
this.router.navigate(['/home/publications', folderId]);
2021-12-14 16:22:53 +01:00
this.idSelected = "";
2021-06-18 11:01:02 +01:00
} else {
this.closeDesktopComponent();
2021-12-14 16:22:53 +01:00
this.idSelected = folderId;
2021-06-18 11:01:02 +01:00
this.folderId = folderId
2021-07-22 14:36:29 +01:00
this.desktopComponent.showViewPublication = true;
2021-06-18 11:01:02 +01:00
}
}
async viewPublications(folderId: string) {
2021-07-21 20:26:41 +01:00
this.folderId = folderId
2020-12-15 19:37:42 +01:00
2021-02-18 12:44:35 +01:00
const enterAnimation = (baseEl: any) => {
2020-12-15 19:37:42 +01:00
const backdropAnimation = this.animationController.create()
.addElement(baseEl.querySelector('ion-backdrop')!)
.fromTo('opacity', '0.01', 'var(--backdrop-opacity)');
const wrapperAnimation = this.animationController.create()
.addElement(baseEl.querySelector('.modal-wrapper')!)
.keyframes([
{ offset: 0, opacity: '0', transform: 'scale(0)' },
{ offset: 1, opacity: '0.99', transform: 'scale(1)' }
]);
return this.animationController.create()
.addElement(baseEl)
.easing('ease-out')
.duration(500)
.addAnimation([backdropAnimation, wrapperAnimation]);
}
const leaveAnimation = (baseEl: any) => {
return enterAnimation(baseEl).direction('reverse');
}
2021-07-22 14:36:29 +01:00
2020-12-15 19:37:42 +01:00
2021-03-15 12:06:06 +01:00
this.closeDesktopComponent();
2021-03-12 14:38:55 +01:00
// OpenModal
2022-02-09 14:51:00 +01:00
if (window.innerWidth < 701) {
2021-03-12 14:38:55 +01:00
/* let item = this.publicationFolderList; */
const modal = await this.modalController.create({
component: ViewPublicationsPage,
2021-04-29 19:46:40 +01:00
//enterAnimation,
//leaveAnimation,
2021-10-09 09:15:22 +01:00
componentProps: {
folderId: folderId,
2021-03-12 14:38:55 +01:00
},
2021-04-14 15:27:50 +01:00
cssClass: 'new-action modal modal-desktop',
2021-03-12 14:38:55 +01:00
backdropDismiss: false
});
await modal.present();
modal.onDidDismiss();
} else {
// open angular component
this.folderId = folderId
2021-07-22 14:36:29 +01:00
this.desktopComponent.showViewPublication = true;
2021-03-12 14:38:55 +01:00
}
}
2021-03-17 10:03:39 +01:00
2021-07-22 14:36:29 +01:00
// called from publications details
2021-03-17 10:03:39 +01:00
// Emittter
2021-10-09 09:15:22 +01:00
goBackToViewPublications() {
this.closeDesktopComponent();
this.idSelected = this.folderId;
this.desktopComponent.showViewPublication = true;
}
2021-03-17 10:03:39 +01:00
// called from publications details
// Emitters
2021-10-09 09:15:22 +01:00
goBackToPubications() {
this.closeDesktopComponent();
this.idSelected = this.folderId;
this.desktopComponent.showViewPublication = true;
}
2021-03-17 10:03:39 +01:00
// called from edit publication (Emitters only)
// Emitters
2021-10-09 09:15:22 +01:00
async goBacktoPublicationDetails() {
this.closeDesktopComponent();
this.desktopComponent.showPublicationDetail = true;
2021-03-12 14:38:55 +01:00
}
2021-03-17 10:57:16 +01:00
// add new publication or edit publicaton
2021-10-09 09:15:22 +01:00
async addNewPublication({ publicationType, folderId, publication }) {
2021-03-15 12:06:06 +01:00
this.closeDesktopComponent();
// propr to add new publication
this.publicationType = publicationType;
2021-03-17 10:57:16 +01:00
// edit publication will send null
if (folderId != undefined) {
this.folderId = folderId;
this.idSelected = this.folderId;
2021-03-17 10:57:16 +01:00
}
2021-07-22 14:36:29 +01:00
2021-03-16 14:35:52 +01:00
this.publication = publication;
2021-03-15 12:06:06 +01:00
this.desktopComponent.showAddNewPublication = true;
}
2022-01-28 16:19:54 +01:00
async editPublication(foolderId: string) {
this.closeDesktopComponent();
2022-06-09 10:24:50 +01:00
this.idSelected = this.folderId;
this.desktopComponent.showEditActions = true;
}
2021-10-09 09:15:22 +01:00
async openPublicationDetails(publicationId: string) {
2021-07-22 14:36:29 +01:00
2021-03-15 16:47:16 +01:00
this.publicationId = publicationId;
2021-07-22 14:36:29 +01:00
2021-03-15 16:47:16 +01:00
this.closeDesktopComponent();
this.idSelected = this.folderId;
2021-03-15 16:47:16 +01:00
this.desktopComponent.showPublicationDetail = true;
}
2021-07-01 14:30:44 +01:00
2021-10-09 09:15:22 +01:00
async updateDesktopComponent(e?: any) {
2021-07-01 14:30:44 +01:00
this.getActions();
}
2021-07-22 14:36:29 +01:00
2021-10-09 09:15:22 +01:00
async closeDesktopComponent(xx?: any) {
2021-03-15 12:06:06 +01:00
this.desktopComponent = {
showViewPublication: false,
2021-03-15 16:47:16 +01:00
showAddNewPublication: false,
2021-03-16 12:14:46 +01:00
showPublicationDetail: false,
showAddActions: false,
2021-06-30 16:26:35 +01:00
showEditActions: false,
2021-03-15 12:06:06 +01:00
}
2022-06-06 15:28:27 +01:00
setTimeout(()=>{
if(this.desktopComponent.showViewPublication == false &&
this.desktopComponent.showAddNewPublication == false &&
this.desktopComponent.showPublicationDetail == false &&
this.desktopComponent.showAddActions == false &&
this.desktopComponent.showEditActions == false) {
this.idSelected = "";
}
}, 10)
2021-03-15 12:06:06 +01:00
}
2021-06-30 15:48:37 +01:00
async openOptions(id?: string) {
2021-07-01 09:36:17 +01:00
this.folderId = id;
2021-06-30 15:48:37 +01:00
const enterAnimation = (baseEl: any) => {
const backdropAnimation = this.animationController.create()
.addElement(baseEl.querySelector('ion-backdrop')!)
.fromTo('opacity', '0.01', 'var(--backdrop-opacity)');
const wrapperAnimation = this.animationController.create()
.addElement(baseEl.querySelector('.modal-wrapper')!)
.keyframes([
{ offset: 0, opacity: '1', right: '-100%' },
{ offset: 1, opacity: '1', right: '0px' }
]);
return this.animationController.create()
.addElement(baseEl)
.easing('ease-out')
.duration(500)
.addAnimation([backdropAnimation, wrapperAnimation]);
}
const leaveAnimation = (baseEl: any) => {
return enterAnimation(baseEl).direction('reverse');
}
const modal = await this.modalController.create({
enterAnimation,
leaveAnimation,
2021-06-30 15:01:07 +01:00
component: ActionsOptionsPage,
2021-06-30 15:48:37 +01:00
cssClass: 'model profile-modal search-submodal',
2021-06-30 15:01:07 +01:00
componentProps: {
2021-06-30 15:48:37 +01:00
id: id,
2021-06-30 15:01:07 +01:00
},
//translucent: true
});
2021-06-30 16:12:47 +01:00
await modal.present();
2021-07-14 09:46:03 +01:00
modal.onDidDismiss().then(res => {
2021-10-09 09:15:22 +01:00
if (res['data'] == 'edit') {
2021-07-01 14:30:44 +01:00
this.closeDesktopComponent();
2021-06-30 16:15:54 +01:00
this.desktopComponent.showEditActions = true;
2021-10-09 09:15:22 +01:00
} else if (res['data'] == 'delete') {
2021-07-14 09:46:03 +01:00
setTimeout(() => {
2021-07-13 17:10:54 +01:00
this.getActions();
2021-07-14 09:46:03 +01:00
}, 1000)
2021-07-14 09:00:04 +01:00
this.closeDesktopComponent()
2021-06-30 16:12:47 +01:00
}
});
2021-06-30 15:01:07 +01:00
}
2021-07-22 14:36:29 +01:00
}