diff --git a/src/app/pages/publications/publications.page.ts b/src/app/pages/publications/publications.page.ts index 4ff0d213c..70912831c 100644 --- a/src/app/pages/publications/publications.page.ts +++ b/src/app/pages/publications/publications.page.ts @@ -16,6 +16,7 @@ import { PublicationTravelFolderStore } from 'src/app/store/publication-travel-f import { SqliteService } from 'src/app/services/sqlite.service'; import { BackgroundService } from 'src/app/services/background.service'; import { ThemeService } from 'src/app/services/theme.service' +import { Storage } from '@ionic/storage'; @Component({ @@ -59,7 +60,7 @@ export class PublicationsPage implements OnInit { hideRefreshBtn = true; showSlidingOptions = true; idSelected: string; - skeletonLoader:boolean; + skeletonLoader: boolean; constructor( private router: Router, @@ -71,6 +72,7 @@ export class PublicationsPage implements OnInit { private backgroundservice: BackgroundService, private platform: Platform, public ThemeService: ThemeService, + private storage: Storage ) { this.months = ["Janeiro", "Fevereiro", "Março", "Abril", "Maio", "Junho", "Julho", "Agosto", "Setembro", "Outubro", "Novembro", "Dezembro"]; @@ -85,13 +87,15 @@ export class PublicationsPage implements OnInit { this.router.events.forEach((event) => { if (event instanceof NavigationEnd && event.url == pathname) { this.getActions(); + + } }); this.hideRefreshButton(); - this.backgroundservice.registerBackService('Online', () => { + /* this.backgroundservice.registerBackService('Online', () => { this.getActions(); - }) + }) */ } @@ -143,12 +147,13 @@ export class PublicationsPage implements OnInit { getActions() { this.showLoader = true; this.skeletonLoader = true; - this.publications.GetPublicationFolderList().subscribe(res => { + this.getFromDB() + this.publications.GetPublicationFolderList().subscribe(async res => { console.log('accoes', res) - this.publicationsEventFolderList = new Array(); - this.publicationsTravelFolderList = new Array(); + let publicationsEventFolderList = new Array(); + let publicationsTravelFolderList = new Array(); res.forEach(data => { let folder: PublicationFolder = { @@ -164,22 +169,41 @@ export class PublicationsPage implements OnInit { if (data.ActionType == "Evento") { console.log('Evento', folder) - this.publicationsEventFolderList.push(folder); + publicationsEventFolderList.push(folder); } else { console.log('Viagem', folder) - this.publicationsTravelFolderList.push(folder); + publicationsTravelFolderList.push(folder); } - this.showLoader = false; + + }); + 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() + } - }, (error) => { + this.showLoader = false; + + }/* , (error) => { this.getFromDB(); - }); + } */); this.skeletonLoader = false; } + addActionToStorage(events, viagens) { + console.log('actionsWEBDB', events, viagens) + 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 { @@ -190,6 +214,40 @@ export class PublicationsPage implements OnInit { getFromDB() { if (this.platform.is('desktop') || this.platform.is('mobileweb')) { + this.publicationsEventFolderList = new Array(); + this.publicationsTravelFolderList = new Array(); + this.storage.get('actionsEvents').then((events) => { + console.log('actionsEvents', 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; + }); + }); + this.storage.get('actionsViagens').then((viagens) => { + console.log('actionsViagens', 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; + }); + }); } else { this.sqliteservice.getAllActions().then((actions: any[]) => { @@ -379,7 +437,7 @@ export class PublicationsPage implements OnInit { this.desktopComponent.showAddNewPublication = true; } - async editPublication(foolderId:string){ + async editPublication(foolderId: string) { this.closeDesktopComponent(); this.desktopComponent.showEditActions = true; }