Refactoring made on offline

This commit is contained in:
Eudes Inácio
2021-10-18 17:42:25 +01:00
parent a9eee0f9a0
commit a21a196248
20 changed files with 1377 additions and 1322 deletions
+61 -48
View File
@@ -30,7 +30,7 @@ import { ListBoxService } from 'src/app/services/agenda/list-box.service';
import { ChangeProfileService } from 'src/app/services/change-profile.service';
import { SqliteService } from 'src/app/services/sqlite.service';
import { synchro } from 'src/app/services/socket/synchro.service';
import { BackgroundService } from 'src/app/services/background.service';
@Component({
@@ -175,7 +175,8 @@ export class AgendaPage implements OnInit {
private listBoxService: ListBoxService,
private changeProfileService: ChangeProfileService,
private sqliteservice: SqliteService,
private platform: Platform
private platform: Platform,
private backgroundservice: BackgroundService
) {
this.dateAdapter.setLocale('es');
@@ -229,7 +230,23 @@ export class AgendaPage implements OnInit {
ngOnInit() {
this.getFromDB()
const pathname = window.location.pathname
let realoadCounter = 0
this.router.events.forEach((event) => {
if (event instanceof NavigationEnd && event.url == pathname) {
if (this.segment == null) {
this.segment = "Combinado";
}
if (realoadCounter != 0) {
this.loadRangeEvents(this.rangeStartDate, this.rangeEndDate);
}
realoadCounter++;
}
});
this.backgroundservice.registerBackService('Online', () => {
this.loadRangeEvents(this.rangeStartDate, this.rangeEndDate);
});
window.onresize = (event) => {
// if not table remove all component
@@ -490,7 +507,7 @@ export class AgendaPage implements OnInit {
// loop
this.CalendarStore.pushEvent(response, 'md');
console.log('CALENDAR STORE',this.CalendarStore.eventSource)
console.log('CALENDAR STORE', this.CalendarStore.eventSource)
let array = []
response.forEach(element => {
@@ -507,7 +524,7 @@ export class AgendaPage implements OnInit {
});
this.listToPresent = array;
console.log('LIST TO PRESET',this.listToPresent)
console.log('LIST TO PRESET', this.listToPresent)
this.TimelineMDList = this.listBoxService.list(this.listToPresent, 'md', this.rangeStartDate, this.rangeEndDate, { segment: this.segment, selectedDate: this.eventSelectedDate })
@@ -517,13 +534,16 @@ export class AgendaPage implements OnInit {
this.showLoader = false;
this.showTimeline = true;
}).finally(() => {
}).catch((error) => {
this.getFromDB();
})
.finally(() => {
this.showLoader = false;
})
}
// view PR calendar with MDGPR profile
else if(this.profile == "pr" && this.loggeduser.Profile == 'MDGPR') {
else if (this.profile == "pr" && this.loggeduser.Profile == 'MDGPR') {
this.eventService.getAllSharedEvents(momentG(new Date(startTime), 'yyyy-MM-dd HH:mm:ss'), momentG(new Date(endTime), 'yyyy-MM-dd 23:59:59')).then((response: any) => {
@@ -556,7 +576,7 @@ export class AgendaPage implements OnInit {
// startTime = 1, endTime = 31
this.CalendarStore.removeRange(startTime, endTime, 'pr')
this.CalendarStore.pushEvent(response, 'pr');
let array = []
let array = []
response.array.forEach(element => {
let event = {
startTime: new Date(element.StartDate),
@@ -585,7 +605,10 @@ export class AgendaPage implements OnInit {
this.showTimeline = true;
}).finally(() => {
}).catch((error) => {
this.getFromDB()
})
.finally(() => {
this.showLoader = false;
})
}
@@ -596,7 +619,7 @@ export class AgendaPage implements OnInit {
let counter = 0;
// view MDGPR calendar with MDGPR profile
if(this.loggeduser.Profile == 'MDGPR') {
if (this.loggeduser.Profile == 'MDGPR') {
this.eventService.getAllMdEvents(momentG(new Date(startTime), 'yyyy-MM-dd HH:mm:ss'), momentG(new Date(endTime), 'yyyy-MM-dd 23:59:59')).then((response: any) => {
@@ -633,9 +656,9 @@ export class AgendaPage implements OnInit {
let eventsList = response;
// clear the current month only
this.CalendarStore.removeRange(startTime, endTime, 'pr')
/* this.CalendarStore.removeRange(startTime, endTime, 'pr')
this.CalendarStore.pushEvent(eventsList, 'pr');
this.CalendarStore.pushEvent(eventsList, 'pr'); */
this.listToPresent = eventsList;
this.TimelinePRList = this.listBoxService.list(this.listToPresent, 'pr', this.rangeStartDate, this.rangeEndDate, { segment: this.segment, selectedDate: this.eventSelectedDate })
@@ -660,8 +683,8 @@ export class AgendaPage implements OnInit {
} else {
// view PR calendar with PR profile
this.eventService.getAllPrEvents(momentG(new Date(startTime),'yyyy-MM-dd HH:mm:ss'), momentG(new Date(endTime),'yyyy-MM-dd 23:59:59')).then((response:any) => {
// view PR calendar with PR profile
this.eventService.getAllPrEvents(momentG(new Date(startTime), 'yyyy-MM-dd HH:mm:ss'), momentG(new Date(endTime), 'yyyy-MM-dd 23:59:59')).then((response: any) => {
let eventsList;
if (this.segment == 'Oficial') {
@@ -729,44 +752,34 @@ export class AgendaPage implements OnInit {
}
getFromDB() {
if (synchro.connected === true) {
const pathname = window.location.pathname
let realoadCounter = 0
this.router.events.forEach((event) => {
if (event instanceof NavigationEnd && event.url == pathname) {
if (this.segment == null) {
this.segment = "Combinado";
}
if (realoadCounter != 0) {
this.loadRangeEvents(this.rangeStartDate, this.rangeEndDate);
}
realoadCounter++;
console.log('ALL EVENTS FROM DB AGENDA OFFLINE')
this.sqliteservice.getAllEvents().then((events: any[]) => {
console.log('ALL EVENTS FROM DB', events)
let eventArray = [];
events.forEach(element => {
let event = {
startTime: new Date(element.StartDate),
endTime: new Date(element.EndDate),
allDay: false,
event: element,
calendarName: element.CalendarName,
profile: element.Profile,
id: element.EventId,
}
eventArray.push(event);
});
console.log('LISTTOPRESENT', this.listToPresent)
} else {
console.log('ALL EVENTS FROM DB AGENDA OFFLINE')
this.sqliteservice.getAllEvents().then((events: any[]) => {
let eventArray = [];
events.forEach(element => {
let event = {
startTime: new Date(element.StartDate),
endTime: new Date(element.EndDate),
allDay: false,
event: element,
calendarName: element.CalendarName,
profile: element.profile,
id: element.EventId,
}
eventArray.push(event);
});
console.log('ALL EVENTS FROM DB', events)
this.listToPresent = eventArray
this.listToPresent = eventArray
this.updateEventListBox()
})
}
this.myCal.update();
this.myCal.loadEvents();
this.showLoader = false;
this.showTimeline = true;
})
}
updateEventListBox() {
+133 -132
View File
@@ -13,11 +13,11 @@ import { ToastService } from 'src/app/services/toast.service';
import { EliminateEventPage } from 'src/app/modals/eliminate-event/eliminate-event.page';
import { Location } from '@angular/common'
import { SqliteService } from 'src/app/services/sqlite.service';
import { synchro } from '../../../services/socket/synchro.service';
import { ExpedientTaskModalPageNavParamsTask } from 'src/app/models/ExpedientTaskModalPage';
import { DocumentSetUpMeetingPage } from 'src/app/modals/document-set-up-meeting/document-set-up-meeting.page';
import { ExpedientTaskModalPage } from '../../gabinete-digital/expediente/expedient-task-modal/expedient-task-modal.page';
import { ViewDocumentPage } from 'src/app/modals/view-document/view-document.page';
import { BackgroundService } from 'src/app/services/background.service';
@Component({
selector: 'app-view-event',
@@ -30,17 +30,17 @@ export class ViewEventPage implements OnInit {
loadedEvent: Event;
isEventEdited: boolean;
eventBody: EventBody;
loadedAttachments:any;
loadedAttachments: any;
pageId: string;
showLoader: boolean;
minDate: Date;
profile:string;
eventId:string;
caller:string;
customDate:any;
today:any;
profile: string;
eventId: string;
caller: string;
customDate: any;
today: any;
months = ["Janeiro", "Fevereiro", "Março", "Abril", "Maio", "Junho", "Julho", "Agosto", "Setembro", "Outubro", "Novembro", "Dezembro"];
days = ["Domingo", "Segunda-feira", "Terça-feira", "Quarta-feira", "Quinta-feira", "Sexta-feira", "Sábado"];
@@ -48,13 +48,12 @@ export class ViewEventPage implements OnInit {
dicIndex = 0;
isModal = false
header = true
synch = synchro;
task: ExpedientTaskModalPageNavParamsTask;
LoadedDocument:any = null;
LoadedDocument: any = null;
constructor(
private modalController: ModalController,
/* private navParams: NavParams, */
/* private navParams: NavParams, */
private eventsService: EventsService,
private attachmentsService: AttachmentsService,
public alertController: AlertController,
@@ -66,26 +65,24 @@ export class ViewEventPage implements OnInit {
private toastService: ToastService,
private location: Location,
public platform: Platform,
private sqliteservice: SqliteService
)
{
private sqliteservice: SqliteService,
private backgroundservice: BackgroundService
) {
this.isEventEdited = false;
this.loadedEvent = new Event();
this.eventBody = { BodyType : "1", Text : ""};
this.eventBody = { BodyType: "1", Text: "" };
this.loadedEvent.Body = this.eventBody;
this.activatedRoute.paramMap.subscribe(params =>{
this.activatedRoute.paramMap.subscribe(params => {
this.eventId = params['params'].eventId;
if(params["params"].caller){
if (params["params"].caller) {
this.caller = (params["params"].caller);
}
if(params["params"].isModal) {
if (params["params"].isModal) {
this.isModal = params["params"].isModal
}
if(params["params"].header) {
if (params["params"].header) {
this.header = params["params"].header
}
});
@@ -100,41 +97,44 @@ export class ViewEventPage implements OnInit {
}
ngOnInit() {
this.getFromDb();
this.loadEvent();
this.backgroundservice.registerBackService('Online', () => {
this.loadEvent();
});
window.onresize = (event) => {
// if not mobile remove all component
if( window.innerWidth >= 1024) {
if (window.innerWidth >= 1024) {
this.modalController.dismiss(this.isEventEdited);
}
};
}
close(){
close() {
this.modalController.dismiss(this.isEventEdited);
}
goBack() {
if(this.isModal) {
if (this.isModal) {
this.close()
} else {
this.activatedRoute.paramMap.subscribe(params => {
if(params["params"].caller == 'expediente'){
window.history.back();
}
else{
this.router.navigate(['/home',params["params"].caller]);
}
this.activatedRoute.paramMap.subscribe(params => {
if (params["params"].caller == 'expediente') {
window.history.back();
}
else {
this.router.navigate(['/home', params["params"].caller]);
}
});
}
}
doRefresh(ev){
doRefresh(ev) {
this.loadEvent();
ev.target.complete();
}
@@ -148,39 +148,40 @@ export class ViewEventPage implements OnInit {
/* this.today = new Date(res.StartDate);
this.customDate = this.days[this.today.getDay()]+ ", " + this.today.getDate() +" de " + ( this.months[this.today.getMonth()]); */
loader.remove()
}, (error)=>{
}, (error) => {
if(error.status == 0) {
this.toastService.badRequest('Não é possível vizualizar este evento no modo offline')
console.log('errorstatus',error.status)
if (error.status == 0) {
this.getFromDb();
} else {
this.toastService.badRequest('Este evento já não existe na sua agenda')
loader.remove()
this.modalController.dismiss('Eevent not Foud');
this.location.back();
}
loader.remove()
this.modalController.dismiss('Eevent not Foud');
this.location.back();
});
}
deleteEvent(){
deleteEvent() {
const loader = this.toastService.loading()
this.eventsService.deleteEvent(this.loadedEvent.EventId, 0, this.loadedEvent.CalendarName).subscribe(async () =>
{
const alert = await this.alertController.create({
cssClass: 'my-custom-class',
header: 'Evento removido',
buttons: ['OK']
});
this.eventsService.deleteEvent(this.loadedEvent.EventId, 0, this.loadedEvent.CalendarName).subscribe(async () => {
const alert = await this.alertController.create({
cssClass: 'my-custom-class',
header: 'Evento removido',
buttons: ['OK']
});
setTimeout(()=>{
alert.dismiss();
}, 1500);
this.goBack();
this.toastService.successMessage('Evento apagado');
}, ()=>{},
()=>{
setTimeout(() => {
alert.dismiss();
}, 1500);
this.goBack();
this.toastService.successMessage('Evento apagado');
}, () => { },
() => {
loader.remove();
});
}
@@ -201,7 +202,7 @@ export class ViewEventPage implements OnInit {
modal.onDidDismiss().then((res) => {
console.log(res);
if(res){
if (res) {
setTimeout(() => {
/* this.loadEvent(); */
this.loadEvent()
@@ -228,7 +229,7 @@ export class ViewEventPage implements OnInit {
modal.onDidDismiss().then((res) => {
console.log(res);
if(res){
if (res) {
setTimeout(() => {
/* this.loadEvent(); */
this.loadEvent()
@@ -243,15 +244,15 @@ export class ViewEventPage implements OnInit {
console.log(this.loadedEvent);
let classs;
if( window.innerWidth <= 800){
if (window.innerWidth <= 800) {
classs = 'modal modal-desktop'
} else {
} else {
classs = 'modal modal-desktop showAsideOptions'
}
const modal = await this.modalController.create({
component: EditEventPage,
componentProps:{
componentProps: {
event: this.loadedEvent,
caller: this.caller,
},
@@ -261,7 +262,7 @@ export class ViewEventPage implements OnInit {
modal.onDidDismiss().then((res) => {
console.log(res);
if(res){
if (res) {
setTimeout(() => {
/* this.loadEvent(); */
this.loadEvent()
@@ -271,15 +272,15 @@ export class ViewEventPage implements OnInit {
});
}
docIndex(index: number){
docIndex(index: number) {
this.dicIndex = index
}
async LoadDocumentDetails() {
const docId = this.loadedEvent.Attachments[ this.dicIndex].SourceId
const applicationId: any = this.loadedEvent.Attachments[ this.dicIndex].ApplicationId
const selectedDoc = this.loadedEvent.Attachments[ this.dicIndex]
const docId = this.loadedEvent.Attachments[this.dicIndex].SourceId
const applicationId: any = this.loadedEvent.Attachments[this.dicIndex].ApplicationId
const selectedDoc = this.loadedEvent.Attachments[this.dicIndex]
console.log('selectedDoc', selectedDoc)
@@ -307,7 +308,7 @@ export class ViewEventPage implements OnInit {
url: '',
title_link: '',
},
Document: this.loadedEvent.Attachments[ this.dicIndex],
Document: this.loadedEvent.Attachments[this.dicIndex],
applicationId: this.task.workflowInstanceDataFields.SourceSecFsID,
docId: selectedDoc.SourceId,
folderId: '',
@@ -321,33 +322,33 @@ export class ViewEventPage implements OnInit {
async openBookMeetingModal() {
let classs;
if( window.innerWidth < 701) {
if (window.innerWidth < 701) {
classs = 'book-meeting-modal modal modal-desktop'
} else {
} else {
classs = 'modal modal-desktop showAsideOptions'
}
const modal = await this.modalController.create({
component: DocumentSetUpMeetingPage,
componentProps: {
subject: this.task.workflowInstanceDataFields.Subject,
document: this.loadedEvent.Attachments[ this.dicIndex],
document: this.loadedEvent.Attachments[this.dicIndex],
},
cssClass: classs,
backdropDismiss: false
});
await modal.present();
modal.onDidDismiss().then(res=>{
modal.onDidDismiss().then(res => {
//this.location.back();
});
}
// efetuar despacho
async openExpedientActionsModal( taskAction: any) {
async openExpedientActionsModal(taskAction: any) {
let classs;
if( window.innerWidth < 701) {
if (window.innerWidth < 701) {
classs = 'modal modal-desktop'
} else {
} else {
classs = 'modal modal-desktop showAsideOptions'
}
const modal = await this.modalController.create({
@@ -355,74 +356,74 @@ export class ViewEventPage implements OnInit {
componentProps: {
taskAction: taskAction,
task: this.task,
seachDocuments: this.loadedEvent.Attachments[ this.dicIndex],
aplicationId: this.loadedEvent.Attachments[ this.dicIndex].ApplicationId || this.loadedEvent.Attachments[ this.dicIndex]['ApplicationID']
seachDocuments: this.loadedEvent.Attachments[this.dicIndex],
aplicationId: this.loadedEvent.Attachments[this.dicIndex].ApplicationId || this.loadedEvent.Attachments[this.dicIndex]['ApplicationID']
},
cssClass: classs,
});
await modal.present();
modal.onDidDismiss().then( async(res)=>{});
modal.onDidDismiss().then(async (res) => { });
}
addEventToDb(data) {
let event = {
Attendees: JSON.stringify(data.Attendees) || JSON.stringify(''),
Body: JSON.stringify(data.Body) || JSON.stringify(''),
CalendarId: data.CalendarId,
CalendarName: data.CalendarName,
Category: data.Category,
EndDate: data.EndDate,
EventId: data.EventId,
EventRecurrence: JSON.stringify(data.EventRecurrence) || JSON.stringify(''),
EventType: data.EventType,
HasAttachments: data.HasAttachments,
IsAllDayEvent: data.IsAllDayEvent,
IsMeeting: data.IsMeeting,
IsRecurring: data.IsRecurring,
Location: data.Location,
Organizer: JSON.stringify(data.Organizer) || JSON.stringify(''),
StartDate: data.StartDate,
Subject: data.Subject,
TimeZone: data.TimeZone
}
this.sqliteservice.updateEvent(event);
addEventToDb(data) {
if (this.platform.is('desktop') || this.platform.is('mobileweb')) {
} else {
let event = {
Attendees: JSON.stringify(data.Attendees) || JSON.stringify(''),
Body: JSON.stringify(data.Body) || JSON.stringify(''),
CalendarId: data.CalendarId,
CalendarName: data.CalendarName,
Category: data.Category,
EndDate: data.EndDate,
EventId: data.EventId,
EventRecurrence: JSON.stringify(data.EventRecurrence) || JSON.stringify(''),
EventType: data.EventType,
HasAttachments: data.HasAttachments,
IsAllDayEvent: data.IsAllDayEvent,
IsMeeting: data.IsMeeting,
IsRecurring: data.IsRecurring,
Location: data.Location,
Organizer: JSON.stringify(data.Organizer) || JSON.stringify(''),
StartDate: data.StartDate,
Subject: data.Subject,
TimeZone: data.TimeZone
}
this.sqliteservice.updateEvent(event);
}
}
getFromDb() {
if (synchro.connected === true) {
this.loadEvent();
console.log('Onlineee view-event')
} else {
this.sqliteservice.getEventById(this.eventId).then((event) => {
let arrayevent = [];
let elemet = {
Attendees: JSON.parse(event[0].Attendees) || "",
Body: JSON.parse(event[0].Body) || "",
CalendarId: event[0].CalendarId,
CalendarName: event[0].CalendarName,
Category: event[0].Category,
EndDate: event[0].EndDate,
EventId: event[0].EventId,
EventRecurrence: JSON.parse(event[0].EventRecurrence) || "",
EventType: event[0].EventType,
HasAttachments: event[0].HasAttachments,
IsAllDayEvent: event[0].IsAllDayEvent,
IsMeeting: event[0].IsMeeting,
IsRecurring: event[0].IsRecurring,
Location: event[0].Location,
Organizer: JSON.parse(event[0].Organizer) || "",
StartDate: event[0].StartDate,
Subject: event[0].Subject,
TimeZone: event[0].TimeZone
}
arrayevent.push(elemet);
this.loadedEvent = arrayevent[0];
console.log("Event ditails local,", elemet)
})
console.log('Offlineee')
}
}}
const loader = this.toastService.loading();
this.sqliteservice.getEventById(this.eventId).then((event) => {
let arrayevent = [];
let elemet = {
Attendees: JSON.parse(event[0].Attendees) || "",
Body: JSON.parse(event[0].Body) || "",
CalendarId: event[0].CalendarId,
CalendarName: event[0].CalendarName,
Category: event[0].Category,
EndDate: event[0].EndDate,
EventId: event[0].EventId,
EventRecurrence: JSON.parse(event[0].EventRecurrence) || "",
EventType: event[0].EventType,
HasAttachments: event[0].HasAttachments,
IsAllDayEvent: event[0].IsAllDayEvent,
IsMeeting: event[0].IsMeeting,
IsRecurring: event[0].IsRecurring,
Location: event[0].Location,
Organizer: JSON.parse(event[0].Organizer) || "",
StartDate: event[0].StartDate,
Subject: event[0].Subject,
TimeZone: event[0].TimeZone
}
arrayevent.push(elemet);
this.loadedEvent = arrayevent[0];
console.log("Event ditails local,", elemet)
})
loader.remove()
}
}