diff --git a/config.xml b/config.xml index 7cb062033..2e850bb20 100644 --- a/config.xml +++ b/config.xml @@ -3,7 +3,7 @@ gabinete digital An awesome Ionic/Cordova app. Ionic Framework Team - + diff --git a/src/app/pages/agenda/agenda.page.html b/src/app/pages/agenda/agenda.page.html index e67175919..a0360274e 100644 --- a/src/app/pages/agenda/agenda.page.html +++ b/src/app/pages/agenda/agenda.page.html @@ -138,7 +138,7 @@ , private toastService: ToastService, private listBoxService: ListBoxService, - private changeProfileService: ChangeProfileService - ) { + private changeProfileService: ChangeProfileService, + private sqliteservice: SqliteService, + private platform: Platform + ) { this.dateAdapter.setLocale('es'); this.locale = 'pt' this.loggeduser = authService.ValidatedUser; - - this.changeProfileService.registerCallback(()=>{ + + this.changeProfileService.registerCallback(() => { this.tigerUpdate() - if(this.loggeduser.Profile == 'MDGPR') { + if (this.loggeduser.Profile == 'MDGPR') { this.mobileComponent.showEventList = true; this.profile = "mdgpr"; } else { @@ -187,7 +193,7 @@ export class AgendaPage implements OnInit { } }) - if(this.loggeduser.Profile == 'MDGPR') { + if (this.loggeduser.Profile == 'MDGPR') { this.mobileComponent.showEventList = true; this.profile = "mdgpr"; } else { @@ -196,7 +202,7 @@ export class AgendaPage implements OnInit { this.calendarHeight = "320px"; this.showCalendar = true; - this.timelineDate = momentG(new Date(),'dd MMMM yyyy'); + this.timelineDate = momentG(new Date(), 'dd MMMM yyyy'); this.showLoader = false; this.showTimelineFilterState = false; @@ -210,11 +216,11 @@ export class AgendaPage implements OnInit { } tigerUpdate() { - setTimeout(()=>{ + setTimeout(() => { try { this.myCal.update(); this.myCal.loadEvents(); - } catch(e) {} + } catch (e) { } this.updateEventListBox() @@ -223,31 +229,11 @@ export class AgendaPage implements OnInit { ngOnInit() { - - 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.getFromDB() window.onresize = (event) => { // if not table remove all component - if( window.innerWidth <= 1024){ + if (window.innerWidth <= 1024) { this.cloneAllmobileComponent(); } }; @@ -273,15 +259,15 @@ export class AgendaPage implements OnInit { } // show information about the clicked event in timeline - eventClicked(event : CalendarEvent): void { - /* console.log('Event clicked', event); */ + eventClicked(event: CalendarEvent): void { + /* console.log('Event clicked', event); */ //clear this.setIntervenient([]); this.setIntervenientCC([]); this.clearPostEvent(); - this.IsEvent= "view"; + this.IsEvent = "view"; this.viewingEventObject = event; @@ -292,7 +278,7 @@ export class AgendaPage implements OnInit { this.showEventEditOrOpen = 'edit'; - if( window.innerWidth <= 1024) { + if (window.innerWidth <= 1024) { this.viewEventDetail(event.id) //this.router.navigate(["/home/agenda", event.id, 'agenda']); } else { @@ -305,17 +291,17 @@ export class AgendaPage implements OnInit { //Show information of the event - async onEventSelected(ev: { event: Event}){ + async onEventSelected(ev: { event: Event }) { this.router.navigate(["/home/agenda", ev.event.EventId, 'agenda']); } onCurrentChanged = (ev: Date) => { // timeline change date - this.timelineDate = momentG(new Date(ev),'dd MMMM yyyy'); - + this.timelineDate = momentG(new Date(ev), 'dd MMMM yyyy'); + this.monthNum = new Date(ev).getMonth() - this.yearNum = new Date(ev).getFullYear() + this.yearNum = new Date(ev).getFullYear() this.viewDate = new Date(ev); // calendar change date @@ -327,9 +313,9 @@ export class AgendaPage implements OnInit { onDropDownScrollWeal() { - setTimeout(()=>{ + setTimeout(() => { document.querySelector('.dropdown-scroll-weel').querySelectorAll('.active')[0].scrollIntoView({ behavior: 'smooth', block: 'center' }); - setTimeout(()=>{ + setTimeout(() => { document.querySelector('.dropdown-scroll-weel').querySelectorAll('.active')[1].scrollIntoView({ behavior: 'smooth', block: 'center' }); }, 300) }, 10) @@ -337,7 +323,7 @@ export class AgendaPage implements OnInit { } // changedate - dropDownChangeDate(id: string){ + dropDownChangeDate(id: string) { /* const currentCandarDayYear = formatDate(this.eventSelectedDate,'dd -- yyyy', 'pt'); const newDate = new Date(currentCandarDayYear.replace('--',id)); this.onCurrentChanged(newDate); */ @@ -348,7 +334,7 @@ export class AgendaPage implements OnInit { this.eventSelectedDate2 = ev.selectedTime; } - onRangeChanged (ev: { startTime: Date, endTime: Date }) { + onRangeChanged(ev: { startTime: Date, endTime: Date }) { this.rangeStartDate = ev.startTime; this.rangeEndDate = ev.endTime; @@ -358,7 +344,7 @@ export class AgendaPage implements OnInit { try { this.myCal.update(); this.myCal.loadEvents(); - } catch(e) {} + } catch (e) { } this.updateEventListBox() @@ -379,7 +365,7 @@ export class AgendaPage implements OnInit { events.forEach(element => { - const profile_ = element.profile == 'md'? 'mdgpr': 'pr'; + const profile_ = element.profile == 'md' ? 'mdgpr' : 'pr'; const eventtype = element.event.CalendarName; @@ -400,23 +386,23 @@ export class AgendaPage implements OnInit { // for timeline - get CalendarCurrentDay ():any { + get CalendarCurrentDay(): any { return this.viewDate.getDate() } // for timeline timelineIsCurrentDate(): Boolean { - return momentG(new Date(),'dd MMMM yyyy', 'pt') == momentG(this.eventSelectedDate,'dd MMMM yyyy', 'pt'); + return momentG(new Date(), 'dd MMMM yyyy', 'pt') == momentG(this.eventSelectedDate, 'dd MMMM yyyy', 'pt'); } - momentG(date, formate , wgs) { - return momentG(date, formate , wgs) + momentG(date, formate, wgs) { + return momentG(date, formate, wgs) } // for timeline - timelineFilter(calendarName, eventsList, profile){ + timelineFilter(calendarName, eventsList, profile) { this.timelineFilterState = calendarName; @@ -428,7 +414,7 @@ export class AgendaPage implements OnInit { eventsList.forEach((element, eventIndex) => { // timeline start - const startHours = new Date(element.StartDate).getHours().toLocaleString(); + const startHours = new Date(element.StartDate).getHours().toLocaleString(); const EndHours = new Date(element.EndDate).getHours().toLocaleString(); events.push({ @@ -451,18 +437,18 @@ export class AgendaPage implements OnInit { return events; } - eventFilter() {} + eventFilter() { } TimelineDayEvent(day): string { - return (day).padStart(2, '0') +' '+this.viewTitle + return (day).padStart(2, '0') + ' ' + this.viewTitle } get calendarDay(): string { - return ((new Date(this.timelineDate)).getDate()).toString().padStart(2,'0') + return ((new Date(this.timelineDate)).getDate()).toString().padStart(2, '0') } - EventTretment ({startTime, endTime}) { + EventTretment({ startTime, endTime }) { const startTimeSamp = new Date(startTime).toLocaleDateString() const endTimeSamp = new Date(endTime).toLocaleDateString() @@ -471,7 +457,7 @@ export class AgendaPage implements OnInit { const endHours = new Date(endTime).getHours() - if (startTimeSamp < endTimeSamp && (endMinutes + endHours) == 0) { + if (startTimeSamp < endTimeSamp && (endMinutes + endHours) == 0) { endTime = new Date(endTime); endTime.setSeconds(endTime.getSeconds() - 1); return new Date(endTime) @@ -485,15 +471,18 @@ export class AgendaPage implements OnInit { this.rangeStartDate = startTime this.rangeEndDate = endTime - + this.showLoader = true; - if(window.innerWidth < 800) { + if (window.innerWidth < 800) { - if(this.profile == "mdgpr" && 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( + if (this.profile == "mdgpr" && 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) => { + (response: any) => { + console.log('ALL MD EVENTS', response); + + this.addEventToDB(response, "md"); // calendar this.CalendarStore.removeRange(startTime, endTime, 'md') @@ -501,7 +490,26 @@ export class AgendaPage implements OnInit { // loop this.CalendarStore.pushEvent(response, 'md'); - this.TimelineMDList = this.listBoxService.list(this.CalendarStore.eventSource, 'md', this.rangeStartDate, this.rangeEndDate, {segment:this.segment, selectedDate: this.eventSelectedDate}) + console.log('CALENDAR STORE',this.CalendarStore.eventSource) + + let array = [] + response.forEach(element => { + let event = { + startTime: new Date(element.StartDate), + endTime: new Date(element.EndDate), + allDay: false, + event: element, + calendarName: element.CalendarName, + profile: "md", + id: element.EventId, + } + array.push(event) + }); + + this.listToPresent = array; + 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 }) this.myCal.update(); this.myCal.loadEvents(); @@ -509,20 +517,21 @@ export class AgendaPage implements OnInit { this.showLoader = false; this.showTimeline = true; - }).finally(()=>{ - this.showLoader = false; - }) + }).finally(() => { + this.showLoader = false; + }) } - 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) => { + 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) => { this.CalendarStore.removeRange(startTime, endTime, 'pr') // calendar this.CalendarStore.pushEvent(response, 'pr'); + this.listToPresent = response; - this.TimelineMDList = this.listBoxService.list(this.CalendarStore.eventSource, 'pr', this.rangeStartDate, this.rangeEndDate, {segment:this.segment, selectedDate: this.eventSelectedDate}) + this.TimelineMDList = this.listBoxService.list(this.listToPresent, 'pr', this.rangeStartDate, this.rangeEndDate, { segment: this.segment, selectedDate: this.eventSelectedDate }) this.myCal.update(); this.myCal.loadEvents(); @@ -530,22 +539,39 @@ export class AgendaPage implements OnInit { this.showLoader = false; this.showTimeline = true; - }).finally(()=>{ - this.showLoader = false; - }) + }).finally(() => { + this.showLoader = false; + }) } - else if(this.loggeduser.Profile == 'PR') { - 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) => { + else if (this.loggeduser.Profile == 'PR') { + 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) => { + console.log('ALL EVENT PR', response) + this.addEventToDB(response, "pr"); // clear the current month only this.CalendarStore.removeRange(startTime, endTime, 'pr') this.CalendarStore.pushEvent(response, 'pr'); + let array = [] + response.array.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, + } + array.push(event) + }); + + this.listToPresent = array; - this.TimelineMDList = this.listBoxService.list(this.CalendarStore.eventSource, 'pr', this.rangeStartDate, this.rangeEndDate, {segment:this.segment, selectedDate: this.eventSelectedDate}) + this.TimelineMDList = this.listBoxService.list(this.listToPresent, 'pr', this.rangeStartDate, this.rangeEndDate, { segment: this.segment, selectedDate: this.eventSelectedDate }) this.myCal.update(); @@ -555,7 +581,7 @@ export class AgendaPage implements OnInit { this.showTimeline = true; - }).finally(()=>{ + }).finally(() => { this.showLoader = false; }) } @@ -565,18 +591,19 @@ export class AgendaPage implements OnInit { let counter = 0; - 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) => { + 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) => { - let eventsList = response; + let eventsList = response; this.CalendarStore.removeRange(startTime, endTime, 'md') // loop this.CalendarStore.pushEvent(eventsList, 'md'); + this.listToPresent = eventsList; - this.TimelineMDList = this.listBoxService.list(this.CalendarStore.eventSource, 'md', this.rangeStartDate, this.rangeEndDate, {segment:this.segment, selectedDate: this.eventSelectedDate}) + this.TimelineMDList = this.listBoxService.list(this.listToPresent, 'md', this.rangeStartDate, this.rangeEndDate, { segment: this.segment, selectedDate: this.eventSelectedDate }) this.myCal.update(); this.myCal.loadEvents(); @@ -584,19 +611,19 @@ export class AgendaPage implements OnInit { this.showTimelineMD = true; counter++; - if(counter==2) { + if (counter == 2) { this.showLoader = false; } - }).finally(()=> { + }).finally(() => { counter++; - if(counter==2) { + if (counter == 2) { this.showLoader = false; } }) - 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) => { + 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) => { let eventsList = response; @@ -604,8 +631,9 @@ export class AgendaPage implements OnInit { this.CalendarStore.removeRange(startTime, endTime, 'pr') this.CalendarStore.pushEvent(eventsList, 'pr'); + this.listToPresent = eventsList; - this.TimelinePRList = this.listBoxService.list(this.CalendarStore.eventSource, 'pr', this.rangeStartDate, this.rangeEndDate, {segment:this.segment, selectedDate: this.eventSelectedDate}) + this.TimelinePRList = this.listBoxService.list(this.listToPresent, 'pr', this.rangeStartDate, this.rangeEndDate, { segment: this.segment, selectedDate: this.eventSelectedDate }) this.myCal.update(); this.myCal.loadEvents(); @@ -614,110 +642,177 @@ export class AgendaPage implements OnInit { counter++; - if(counter==2 || this.loggeduser.Profile == 'PR') { + if (counter == 2 || this.loggeduser.Profile == 'PR') { this.showLoader = false; } - }).finally(()=>{ + }).finally(() => { counter++; - if(counter==2) { + if (counter == 2) { this.showLoader = false; } }) } else { - 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) => { + 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') { - eventsList = response.filter(data => data.CalendarName == "Oficial"); - } else if (this.segment == 'Pessoal') { - eventsList = response.filter(data => data.CalendarName == "Pessoal"); - } else { - eventsList = response; - } + let eventsList; + if (this.segment == 'Oficial') { + eventsList = response.filter(data => data.CalendarName == "Oficial"); + } else if (this.segment == 'Pessoal') { + eventsList = response.filter(data => data.CalendarName == "Pessoal"); + } else { + eventsList = response; + } - // clear the current month only - this.CalendarStore.removeRange(startTime, endTime, 'pr') + // clear the current month only + 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.CalendarStore.eventSource, 'pr', this.rangeStartDate, this.rangeEndDate, {segment:this.segment, selectedDate: this.eventSelectedDate}) + this.TimelinePRList = this.listBoxService.list(this.listToPresent, 'pr', this.rangeStartDate, this.rangeEndDate, { segment: this.segment, selectedDate: this.eventSelectedDate }) - this.myCal.update(); - this.myCal.loadEvents(); + this.myCal.update(); + this.myCal.loadEvents(); - this.showTimelinePR = true; + this.showTimelinePR = true; - counter++; + counter++; - if(counter==1 || this.loggeduser.Profile == 'PR') { - this.showLoader = false; - } + if (counter == 1 || this.loggeduser.Profile == 'PR') { + this.showLoader = false; + } - }).finally(()=>{ - if(counter==1 || this.loggeduser.Profile == 'PR') { - this.showLoader = false; - } - }) + }).finally(() => { + if (counter == 1 || this.loggeduser.Profile == 'PR') { + this.showLoader = false; + } + }) + + } } + } + addEventToDB(response, profile) { + if (this.platform.is('desktop') || this.platform.is('mobileweb')) { + } else { + if (response.length > 0) { + + response.forEach(element => { + let event = { + CalendarId: element.CalendarId, + CalendarName: element.CalendarName, + EndDate: element.EndDate, + EventId: element.EventId, + HasAttachments: element.HasAttachments, + HumanDate: element.HumanDate, + IsAllDayEvent: element.IsAllDayEvent, + Location: element.Location, + StartDate: element.StartDate, + Subject: element.Subject, + Profile: profile + } + this.sqliteservice.addEvent(event) + }); + } + } + } + + 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('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 + + }) } } updateEventListBox() { - if(window.innerWidth < 800){ + if (window.innerWidth < 800) { switch (this.segment) { case "Combinado": - if(this.profile == "mdgpr" && this.loggeduser.Profile == 'MDGPR' ) { - this.TimelineMDList = this.listBoxService.list(this.CalendarStore.eventSource, 'md', this.rangeStartDate, this.rangeEndDate, {segment:this.segment, selectedDate: this.eventSelectedDate}) + if (this.profile == "mdgpr" && this.loggeduser.Profile == 'MDGPR') { + this.TimelineMDList = this.listBoxService.list(this.listToPresent, 'md', this.rangeStartDate, this.rangeEndDate, { segment: this.segment, selectedDate: this.eventSelectedDate }) } - else if(this.profile == "pr" && this.loggeduser.Profile == 'MDGPR') { + else if (this.profile == "pr" && this.loggeduser.Profile == 'MDGPR') { - this.TimelineMDList = this.listBoxService.list(this.CalendarStore.eventSource, 'pr', this.rangeStartDate, this.rangeEndDate, {segment:this.segment, selectedDate: this.eventSelectedDate}) + this.TimelineMDList = this.listBoxService.list(this.listToPresent, 'pr', this.rangeStartDate, this.rangeEndDate, { segment: this.segment, selectedDate: this.eventSelectedDate }) } - else if(this.loggeduser.Profile == 'PR') { - this.TimelineMDList = this.listBoxService.list(this.CalendarStore.eventSource, 'pr', this.rangeStartDate, this.rangeEndDate, {segment:this.segment, selectedDate: this.eventSelectedDate}) + else if (this.loggeduser.Profile == 'PR') { + this.TimelineMDList = this.listBoxService.list(this.listToPresent, 'pr', this.rangeStartDate, this.rangeEndDate, { segment: this.segment, selectedDate: this.eventSelectedDate }) } - break; + break; case "Pessoal": //Inicializa o array eventSource - if(this.profile == "mdgpr" && this.loggeduser.Profile == 'MDGPR') { - this.TimelineMDList = this.listBoxService.list(this.CalendarStore.eventSource, 'md', this.rangeStartDate, this.rangeEndDate, {segment:this.segment, selectedDate: this.eventSelectedDate}) + if (this.profile == "mdgpr" && this.loggeduser.Profile == 'MDGPR') { + this.TimelineMDList = this.listBoxService.list(this.listToPresent, 'md', this.rangeStartDate, this.rangeEndDate, { segment: this.segment, selectedDate: this.eventSelectedDate }) } - else{ - this.TimelineMDList = this.listBoxService.list(this.CalendarStore.eventSource, 'pr', this.rangeStartDate, this.rangeEndDate, {segment:this.segment, selectedDate: this.eventSelectedDate}) - this.TimelinePRList = this.listBoxService.list(this.CalendarStore.eventSource, 'pr', this.rangeStartDate, this.rangeEndDate, {segment:this.segment, selectedDate: this.eventSelectedDate}) + else { + this.TimelineMDList = this.listBoxService.list(this.listToPresent, 'pr', this.rangeStartDate, this.rangeEndDate, { segment: this.segment, selectedDate: this.eventSelectedDate }) + this.TimelinePRList = this.listBoxService.list(this.listToPresent, 'pr', this.rangeStartDate, this.rangeEndDate, { segment: this.segment, selectedDate: this.eventSelectedDate }) } break; case "Oficial": - if(this.profile == "mdgpr" && this.loggeduser.Profile == 'MDGPR') { - this.TimelineMDList = this.listBoxService.list(this.CalendarStore.eventSource, 'md', this.rangeStartDate, this.rangeEndDate, {}) + if (this.profile == "mdgpr" && this.loggeduser.Profile == 'MDGPR') { + this.TimelineMDList = this.listBoxService.list(this.listToPresent, 'md', this.rangeStartDate, this.rangeEndDate, {}) } else { - this.TimelineMDList = this.listBoxService.list(this.CalendarStore.eventSource, 'pr', this.rangeStartDate, this.rangeEndDate, {segment:this.segment, selectedDate: this.eventSelectedDate}) - this.TimelinePRList = this.listBoxService.list(this.CalendarStore.eventSource, 'pr', this.rangeStartDate, this.rangeEndDate, {segment:this.segment, selectedDate: this.eventSelectedDate}) + this.TimelineMDList = this.listBoxService.list(this.listToPresent, 'pr', this.rangeStartDate, this.rangeEndDate, { segment: this.segment, selectedDate: this.eventSelectedDate }) + this.TimelinePRList = this.listBoxService.list(this.listToPresent, 'pr', this.rangeStartDate, this.rangeEndDate, { segment: this.segment, selectedDate: this.eventSelectedDate }) } break; } } else { - this.TimelinePRList = this.listBoxService.list(this.CalendarStore.eventSource, 'pr', this.rangeStartDate, this.rangeEndDate, {segment:this.segment, selectedDate: this.eventSelectedDate}) - this.TimelineMDList = this.listBoxService.list(this.CalendarStore.eventSource, 'md', this.rangeStartDate, this.rangeEndDate, {segment:this.segment, selectedDate: this.eventSelectedDate}) - + this.TimelinePRList = this.listBoxService.list(this.listToPresent, 'pr', this.rangeStartDate, this.rangeEndDate, { segment: this.segment, selectedDate: this.eventSelectedDate }) + this.TimelineMDList = this.listBoxService.list(this.listToPresent, 'md', this.rangeStartDate, this.rangeEndDate, { segment: this.segment, selectedDate: this.eventSelectedDate }) + } } @@ -727,23 +822,23 @@ export class AgendaPage implements OnInit { const isInvalidDate = (dateString) => JSON.stringify(new Date(dateString)) === 'null'; - const newDate = new Date(year, a.getMonth(), a.getDay()); - - if(!(isInvalidDate(newDate))) { + const newDate = new Date(year, a.getMonth(), a.getDay()); + + if (!(isInvalidDate(newDate))) { this.calendar.currentDate = newDate - + try { this.myCal.update(); this.myCal.loadEvents(); this.onDropDownScrollWeal() - } catch(e) {} - + } catch (e) { } + this.updateEventListBox() } else { - console.log('not valid '+ a) + console.log('not valid ' + a) } - + } changeMonth = (month) => { @@ -752,40 +847,40 @@ export class AgendaPage implements OnInit { const isInvalidDate = (dateString) => JSON.stringify(new Date(dateString)) === 'null'; - const newDate = new Date(a.getFullYear(), month, a.getDay()); + const newDate = new Date(a.getFullYear(), month, a.getDay()); - if(!(isInvalidDate(newDate))) { + if (!(isInvalidDate(newDate))) { this.calendar.currentDate = newDate - + try { this.myCal.update(); this.myCal.loadEvents(); this.onDropDownScrollWeal() - } catch(e) {} - + } catch (e) { } + this.updateEventListBox() } else { - console.log('not valid '+ a) + console.log('not valid ' + a) } } - get viewEventMonth () { - return this.viewDate.getMonth() + get viewEventMonth() { + return this.viewDate.getMonth() } dateMonth(event: any) { - return new Date(event.start).getMonth() + return new Date(event.start).getMonth() } eventListVisible(event) { - return momentG(event,'MMMM yyyy') == momentG(this.calendar.currentDate, 'MMMM yyyy') + return momentG(event, 'MMMM yyyy') == momentG(this.calendar.currentDate, 'MMMM yyyy') } - actions(){} + actions() { } - doRefresh(ev: any){ + doRefresh(ev: any) { this.loadRangeEvents(this.rangeStartDate, this.rangeEndDate); setTimeout(() => { ev.target.complete(); @@ -798,16 +893,16 @@ export class AgendaPage implements OnInit { changeProfile() { - if(this.profile == "mdgpr") { - this.profile ="pr"; + if (this.profile == "mdgpr") { + this.profile = "pr"; this.loadRangeEvents(this.rangeStartDate, this.rangeEndDate); - this.TimelineMDList = this.listBoxService.list(this.CalendarStore.eventSource, 'pr', this.rangeStartDate, this.rangeEndDate, {segment:this.segment, selectedDate: this.eventSelectedDate}) + this.TimelineMDList = this.listBoxService.list(this.listToPresent, 'pr', this.rangeStartDate, this.rangeEndDate, { segment: this.segment, selectedDate: this.eventSelectedDate }) } else { - this.profile ="mdgpr"; + this.profile = "mdgpr"; this.loadRangeEvents(this.rangeStartDate, this.rangeEndDate); - this.TimelineMDList = this.listBoxService.list(this.CalendarStore.eventSource, 'md', this.rangeStartDate, this.rangeEndDate, {segment:this.segment, selectedDate: this.eventSelectedDate}) + this.TimelineMDList = this.listBoxService.list(this.listToPresent, 'md', this.rangeStartDate, this.rangeEndDate, { segment: this.segment, selectedDate: this.eventSelectedDate }) } } @@ -819,10 +914,10 @@ export class AgendaPage implements OnInit { this.showEventEditOrOpen = 'add'; this.IsEvent = 'add'; - if( window.innerWidth <= 1024){ + if (window.innerWidth <= 1024) { const modal = await this.modalCtrl.create({ component: NewEventPage, - componentProps:{ + componentProps: { segment: this.segment, profile: this.profile, eventSelectedDate: this.eventSelectedDate @@ -832,7 +927,7 @@ export class AgendaPage implements OnInit { }); await modal.present(); modal.onDidDismiss().then((data) => { - if(data){ + if (data) { } this.openAddEventDismiss(data['data']) @@ -843,16 +938,15 @@ export class AgendaPage implements OnInit { } - openEditEvent(){ + openEditEvent() { this.showEventEditOrOpen = 'edit'; } - openAddEventDismiss(data){ + openAddEventDismiss(data) { let postEvent: Event = data; - if (postEvent.Subject != null) - { + if (postEvent.Subject != null) { // this.eventSource.push({ // title: postEvent.Subject, // startTime: new Date(postEvent.StartDate), @@ -869,7 +963,7 @@ export class AgendaPage implements OnInit { } // open component - async viewEventDetail(eventId:any) { + async viewEventDetail(eventId: any) { this.router.navigate(['/home/agenda', eventId, 'agenda']); /* console.log(this.profile); @@ -913,7 +1007,7 @@ export class AgendaPage implements OnInit { async viewEventsToApprove() { await this.cloneAllmobileComponent(); - if( window.innerWidth <= 801) { + if (window.innerWidth <= 801) { this.router.navigate(['/home/agenda/event-list']); } else { // hide all components @@ -934,15 +1028,15 @@ export class AgendaPage implements OnInit { } - approveEventDismiss({saveData, serialNumber, action}) { + approveEventDismiss({ saveData, serialNumber, action }) { window['temp.path:/shared/agenda/edit-event-to-approve.ts'] = {} - if(action == 'Aprovar') { + if (action == 'Aprovar') { this.eventToaprove = { back: true, saveData: saveData, - serialNumber:serialNumber, + serialNumber: serialNumber, action: action, InstanceId: saveData.workflowInstanceDataFields.InstanceId || "" } @@ -956,7 +1050,7 @@ export class AgendaPage implements OnInit { } closeEventToApprove() { - if (this.eventToaprove.back ==true && this.mobileComponent.showEventList ==true) { + if (this.eventToaprove.back == true && this.mobileComponent.showEventList == true) { this.mobileComponent.transparentEventList = false; this.mobileComponent.showEventToApprove = false; this.eventToaprove.back = false; @@ -971,7 +1065,7 @@ export class AgendaPage implements OnInit { } closeEventToApproveGoBack() { - if( window.innerWidth <= 801){ + if (window.innerWidth <= 801) { this.router.navigate(['/home/agenda/event-list']); } else { // hide all components @@ -1006,8 +1100,8 @@ export class AgendaPage implements OnInit { } async AproveEventEditEvent(data) { - this.postEvent =data; - this.mobileComponent.transparentEventToApprove= true; + this.postEvent = data; + this.mobileComponent.transparentEventToApprove = true; this.mobileComponent.showAddNewEvent = true; } @@ -1024,11 +1118,11 @@ export class AgendaPage implements OnInit { this.contacts = []; } - async setContact(data:EventPerson[]) { + async setContact(data: EventPerson[]) { this.contacts = data; } - async openAttendeeModal(){ + async openAttendeeModal() { this.cloneAllmobileComponent(); this.mobileComponent.showAttendeeModal = true; } @@ -1036,15 +1130,15 @@ export class AgendaPage implements OnInit { async GoBackEditOrAdd() { - if(this.showEventEditOrOpen == "edit") { + if (this.showEventEditOrOpen == "edit") { this.cloneAllmobileComponent(); this.mobileComponent.showEditEvent = true; - } else if(this.showEventEditOrOpen == "add") { + } else if (this.showEventEditOrOpen == "add") { this.cloneAllmobileComponent(); this.mobileComponent.showAddNewEvent = true; - } else if(this.showEventEditOrOpen == "eventoToApprove") { + } else if (this.showEventEditOrOpen == "eventoToApprove") { this.cloneAllmobileComponent(); this.mobileComponent.showEditEventToApprove = true } @@ -1056,7 +1150,7 @@ export class AgendaPage implements OnInit { async closeComponentEditEventOrAdd() { - if(this.IsEvent ='edit') { + if (this.IsEvent = 'edit') { this.eventClicked(this.viewingEventObject); } else if (this.IsEvent = 'add') { this.cloneAllmobileComponent(); @@ -1069,14 +1163,14 @@ export class AgendaPage implements OnInit { async setIntervenient(data) { - setTimeout(()=>{ + setTimeout(() => { this.taskParticipants = removeDuplicate(data) }, 10) } async setIntervenientCC(data) { - setTimeout(()=>{ + setTimeout(() => { this.taskParticipantsCc = removeDuplicate(data) }, 10) @@ -1084,18 +1178,18 @@ export class AgendaPage implements OnInit { // Emitters // adding - async setAdding(adding: "intervenient" | "CC" = "intervenient") { - this.adding = adding; + async setAdding(adding: "intervenient" | "CC" = "intervenient") { + this.adding = adding; } - async clearPostEvent(){ + async clearPostEvent() { this.postEvent = false; } - async changeSegment(segments: "Combinado" | "Pessoal" | "Oficial") { - this.segment = segments; + async changeSegment(segments: "Combinado" | "Pessoal" | "Oficial") { + this.segment = segments; - if(segments=='Combinado'){ + if (segments == 'Combinado') { this.timelineFilterState = 'Todos' } else { this.timelineFilterState = segments @@ -1112,11 +1206,11 @@ export class AgendaPage implements OnInit { shoeEventDay(events: any[]) { - if ( this.segment == 'Combinado') { + if (this.segment == 'Combinado') { return true; } - const reuslt = events.filter((e)=> e.CalendarName == this.segment) + const reuslt = events.filter((e) => e.CalendarName == this.segment) return reuslt.length != 0 } diff --git a/src/app/pages/events/events.page.ts b/src/app/pages/events/events.page.ts index 0ccefc6c2..ffcc423df 100644 --- a/src/app/pages/events/events.page.ts +++ b/src/app/pages/events/events.page.ts @@ -108,14 +108,14 @@ export class EventsPage implements OnInit { }); - if (this.platform.is('desktop') || this.platform.is('mobileweb')) { + /* if (this.platform.is('desktop') || this.platform.is('mobileweb')) { } else { try { this.sqliteservice.databaseConn(); } catch (error) { console.log("Error creating local database: ", error) } - } + } */ } @@ -324,52 +324,6 @@ export class EventsPage implements OnInit { getEventsFromLocalDb() { - window.addEventListener('online',() => { - this.showGreeting(); - - this.router.events.forEach((event) => { - if (event instanceof NavigationEnd && event.url == '/home/events') { - this.RefreshEvents(); - setTimeout(() => { - this.LoadList(); - }, 1500) - } - }); - this.hideSearch(); - }) - - window.addEventListener('offline', () => { - this.sqliteservice.getAllEvents().then((event:any[]) => { - this.listToPresent = event - this.totalEvent = this.listToPresent.length - this.currentEvent = this.listToPresent[0].Subject - this.currentHoursMinutes = this.listToPresent[0].StartDate - console.log("All events from local,", event) - }) - - this.sqliteservice.getprocessByworkflow("Expediente").then((process: any[]) => { - var expedientlist = []; - process.forEach((element) => { - let task = { - CreateDate: element.taskStartDate, - DocumentsQty: element.totalDocuments, - Senders: JSON.parse(element.workflowInstanceDataFields).Sender, - SerialNumber: element.serialNumber, - Status: JSON.parse(element.workflowInstanceDataFields).Status, - Subject: JSON.parse(element.workflowInstanceDataFields).Subject, - WorkflowName: element.workflowDisplayName, - activityInstanceName: element.activityInstanceName, - taskStartDate: element.taskStartDate, - } - expedientlist.push(task); - }) - const ExpedienteTask = expedientlist.map(e => this.expedienteTaskPipe.transform(e)) - this.listToPresentexpediente = ExpedienteTask; - - - }) - }) - if (synchro.connected === true) { this.showGreeting(); @@ -382,7 +336,8 @@ export class EventsPage implements OnInit { } }); this.hideSearch(); - } else { + } else { + this.platform.ready().then(async () => { this.sqliteservice.getAllEvents().then((event:any[]) => { this.listToPresent = event this.totalEvent = this.listToPresent.length @@ -412,6 +367,7 @@ export class EventsPage implements OnInit { }) + }); } } diff --git a/src/app/pages/publications/publications.page.html b/src/app/pages/publications/publications.page.html index 2d76756ae..d1ae5d28b 100644 --- a/src/app/pages/publications/publications.page.html +++ b/src/app/pages/publications/publications.page.html @@ -40,7 +40,7 @@
+ *ngFor="let viagem of publicationsTravelFolderList"> + *ngFor="let evento of publicationsEventFolderList"> { - if(event instanceof NavigationEnd && event.url == pathname) { - this.getActions(); - } - }); - - this.hideRefreshButton(); + private toastService: ToastService, + private sqliteservice: SqliteService + ) { + 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"]; } - hideRefreshButton(){ + ngOnInit() { + this.getFromDB(); + } + + hideRefreshButton() { window.onresize = (event) => { - if( window.innerWidth < 801) { + if (window.innerWidth < 801) { this.hideRefreshBtn = false; this.showSlidingOptions = false; } - else{ + else { this.hideRefreshBtn = true; this.showSlidingOptions = true; } } - if(window.innerWidth < 801){ + if (window.innerWidth < 801) { this.hideRefreshBtn = false; this.showSlidingOptions = false; } - else{ + else { this.hideRefreshBtn = true; this.showSlidingOptions = true; } @@ -120,12 +114,15 @@ export class PublicationsPage implements OnInit { getDate(date) { this.theDate = new Date(date); - return this.theDate.getDate() +" de " + ( this.months[this.theDate.getMonth()])+" de " +this.theDate.getFullYear() + return this.theDate.getDate() + " de " + (this.months[this.theDate.getMonth()]) + " de " + this.theDate.getFullYear() } getActions() { this.showLoader = true; - this.publications.GetPublicationFolderList().subscribe(res=>{ + this.publications.GetPublicationFolderList().subscribe(res => { + + console.log('accoes', res) + this.sqliteservice.addactions(res); this.publicationsEventFolderList = new Array(); this.publicationsTravelFolderList = new Array(); @@ -140,46 +137,87 @@ export class PublicationsPage implements OnInit { ActionType: data.ActionType, } - if(data.ActionType == "Evento") { + if (data.ActionType == "Evento") { this.publicationsEventFolderList.push(folder); } - else{ + else { this.publicationsTravelFolderList.push(folder); } this.showLoader = false; - this.publicationEventFolderStorage.reset(this.publicationsEventFolderList) - this.publicationTravelFolderService.reset(this.publicationsTravelFolderList) + /* this.publicationEventFolderStorage.reset(this.publicationsEventFolderList) + this.publicationTravelFolderService.reset(this.publicationsTravelFolderList) */ }); }); } - async editAction(folderId?: string){ + getFromDB() { + + if (synchro.connected === true) { + const pathname = window.location.pathname + + this.router.events.forEach((event) => { + if (event instanceof NavigationEnd && event.url == pathname) { + this.getActions(); + } + }); + + this.hideRefreshButton(); + } else { + this.sqliteservice.getAllActions().then((actions: any[]) => { + + 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; + }); + + }) + } + } + + async editAction(folderId?: string) { const modal = await this.modalController.create({ component: EditActionPage, - componentProps:{ + componentProps: { folderId: folderId, }, cssClass: 'new-action modal modal-desktop', backdropDismiss: true }); await modal.present(); - modal.onDidDismiss().then(()=>{ + modal.onDidDismiss().then(() => { this.getActions(); }); //this.refreshing() } - async deleteAction(id?: string){ + async deleteAction(id?: string) { const loader = this.toastService.loading(); try { await this.publications.DeletePresidentialAction(id).toPromise(); this.toastService.successMessage() - } catch(e) { + } catch (e) { this.toastService.badRequest() } finally { @@ -189,21 +227,21 @@ export class PublicationsPage implements OnInit { this.refreshing() } - async AddPublicationFolder(item?:any) { + async AddPublicationFolder(item?: any) { this.closeDesktopComponent(); - if(window.innerWidth <= 1024) { + if (window.innerWidth <= 1024) { const modal = await this.modalController.create({ component: NewActionPage, - componentProps:{ + componentProps: { item: item, }, cssClass: 'new-action modal modal-desktop', backdropDismiss: false }); await modal.present(); - modal.onDidDismiss().then(()=>{ + modal.onDidDismiss().then(() => { this.getActions(); }); } else { @@ -212,12 +250,12 @@ export class PublicationsPage implements OnInit { } - goToPublicationsList(folderId: string){ + goToPublicationsList(folderId: string) { this.folderId = folderId this.idSelected = folderId; - if( window.innerWidth <= 800){ - this.router.navigate(['/home/publications',folderId]); + if (window.innerWidth <= 800) { + this.router.navigate(['/home/publications', folderId]); } else { this.closeDesktopComponent(); this.folderId = folderId @@ -256,14 +294,14 @@ export class PublicationsPage implements OnInit { this.closeDesktopComponent(); // OpenModal - if( window.innerWidth <= 800){ + if (window.innerWidth <= 800) { /* let item = this.publicationFolderList; */ const modal = await this.modalController.create({ component: ViewPublicationsPage, //enterAnimation, //leaveAnimation, - componentProps:{ - folderId:folderId, + componentProps: { + folderId: folderId, }, cssClass: 'new-action modal modal-desktop', backdropDismiss: false @@ -281,7 +319,7 @@ export class PublicationsPage implements OnInit { // called from publications details // Emittter - goBackToViewPublications(){ + goBackToViewPublications() { this.closeDesktopComponent(); this.desktopComponent.showViewPublication = true; @@ -289,21 +327,21 @@ export class PublicationsPage implements OnInit { // called from publications details // Emitters - goBackToPubications(){ + goBackToPubications() { this.closeDesktopComponent(); this.desktopComponent.showViewPublication = true; } // called from edit publication (Emitters only) // Emitters - async goBacktoPublicationDetails(){ + async goBacktoPublicationDetails() { this.closeDesktopComponent(); this.desktopComponent.showPublicationDetail = true; } // add new publication or edit publicaton - async addNewPublication({publicationType, folderId, publication}){ + async addNewPublication({ publicationType, folderId, publication }) { this.closeDesktopComponent(); @@ -319,7 +357,7 @@ export class PublicationsPage implements OnInit { this.desktopComponent.showAddNewPublication = true; } - async openPublicationDetails(publicationId: string){ + async openPublicationDetails(publicationId: string) { this.publicationId = publicationId; @@ -328,11 +366,11 @@ export class PublicationsPage implements OnInit { } - async updateDesktopComponent(e?:any){ + async updateDesktopComponent(e?: any) { this.getActions(); } - async closeDesktopComponent (xx?: any){ + async closeDesktopComponent(xx?: any) { this.desktopComponent = { showViewPublication: false, @@ -380,10 +418,10 @@ export class PublicationsPage implements OnInit { }); await modal.present(); modal.onDidDismiss().then(res => { - if(res['data']=='edit') { + if (res['data'] == 'edit') { this.closeDesktopComponent(); this.desktopComponent.showEditActions = true; - } else if (res['data']=='delete') { + } else if (res['data'] == 'delete') { setTimeout(() => { this.getActions(); }, 1000) diff --git a/src/app/pages/publications/view-publications/view-publications.page.ts b/src/app/pages/publications/view-publications/view-publications.page.ts index 776316e26..d6ec9cfed 100644 --- a/src/app/pages/publications/view-publications/view-publications.page.ts +++ b/src/app/pages/publications/view-publications/view-publications.page.ts @@ -10,6 +10,8 @@ import { PublicationListStorage } from 'src/app/store/publication-list.service'; import { PublicationTravelFolderStore } from 'src/app/store/publication-travel-folder.service'; import { NewPublicationPage } from '../new-publication/new-publication.page'; import { PublicationDetailPage } from './publication-detail/publication-detail.page'; +import { SqliteService } from 'src/app/services/sqlite.service'; +import { synchro } from 'src/app/services/socket/synchro.service'; @Component({ selector: 'app-view-publications', @@ -36,7 +38,8 @@ export class ViewPublicationsPage implements OnInit { private modalController: ModalController, private publications: PublicationsService, private activatedRoute: ActivatedRoute, - private router: Router) { + private router: Router, + private sqliteservice: SqliteService) { this.item = new PublicationFolder(); this.activatedRoute.paramMap.subscribe(params => { @@ -97,6 +100,7 @@ export class ViewPublicationsPage implements OnInit { setTimeout(() => { let allActions = this.publicationEventFolderStorage.list.concat(this.publicationTravelFolderService.list) this.item = allActions.find((e)=> e.ProcessId == this.folderId); + console.log('item', this.item) }, 100); } @@ -105,7 +109,9 @@ export class ViewPublicationsPage implements OnInit { this.showLoader = true; const folderId = this.folderId this.publications.GetPublications(this.folderId).subscribe(res=>{ - + console.log(this.folderId) + console.log('getPublications',res) + this.sqliteservice.updateactions(this.folderId, res); this.publicationList = new Array(); @@ -131,6 +137,14 @@ export class ViewPublicationsPage implements OnInit { } + getFromDB() { + if(synchro.connected === true) { + + } else { + + } + } + async AddPublication(publicationType:any, folderId:any) { const modal = await this.modalController.create({ component: NewPublicationPage, diff --git a/src/app/services/sqlite.service.ts b/src/app/services/sqlite.service.ts index d9d2bf61a..bc7e60598 100644 --- a/src/app/services/sqlite.service.ts +++ b/src/app/services/sqlite.service.ts @@ -12,10 +12,13 @@ export class SqliteService { readonly events: string = "Events"; readonly expedientes: string = "Expedientes"; readonly allprocess: string = "ALLPROCESS"; + readonly actions: string = "ACTIONS"; + readonly publications: string = "PUBLICATIONS"; EVENTS: Array; EXPEDIENTES: Array; ALLPROCESS: Array; PROCESS: Array; + ALLACTIONS: Array; constructor(private platform: Platform, private sqlite: SQLite) { @@ -51,7 +54,8 @@ export class SqliteService { EventRecurrence Text, Attachments Text, Body Text, - Profile varchar(255) + Profile varchar(255), + HumanDate varchar(255) )`, []) .then((res) => { console.log("Sucess Events Table created: ", res) @@ -102,22 +106,59 @@ export class SqliteService { console.log("Sucess AllProcess Table created: ", res) }) .catch((error) => console.log(JSON.stringify(error))); + + await sqLite.executeSql(` + CREATE TABLE IF NOT EXISTS ${this.actions} ( + ProcessId INTERGER PRIMARY KEY, + ActionType varchar(255), + DateBegin varchar(255), + DateEnd varchar(255), + Detail varchar(255), + Description varchar(255), + DateIndex varchar(255), + DatePublication varchar(255), + DocumentId INTERGER, + FileBase64 Text, + FileExtension varchar(255), + Message varchar(255), + OrganicEntityId INTERGER, + OriginalFileName varchar(255), + Title varchar(255) + )`, []) + .then((res) => { + console.log("Sucess action Table created: ", res) + }) + .catch((error) => console.log(JSON.stringify(error))); }) .catch((error) => console.log(JSON.stringify(error))); }); } + //addactions + public addactions(data) { + this.dbInstance.executeSql(` + INSERT OR IGNORE INTO ${this.actions} (ActionType,DateBegin,DateEnd,Description,Detail,ProcessId,DateIndex,DatePublication,DocumentId,FileBase64,FileExtension,Message,OrganicEntityId,OriginalFileName,Title) + VALUES ('${data.ActionType}','${data.DateBegin}', '${data.DateEnd}','${data.Description}','${data.Detail}','${data.ProcessId}','${data.DateIndex}','${data.DatePublication},'${data.DocumentId}', + '${data.FileBase64}','${data.FileExtension}','${data.Message}','${data.OrganicEntityId}','${data.OriginalFileName}','${data.Title}')`, []) + .then(() => { + console.log("action add with Success"); + + }, (e) => { + console.log(JSON.stringify(e.err)); + }); + } + //addEvent public addEvent(data) { this.dbInstance.executeSql(` - INSERT OR IGNORE INTO ${this.events} (EventId,Subject,HasAttachments,Location,CalendarId,CalendarName,StartDate,EndDate,EventType,Attendees,IsMeeting,IsRecurring,IsAllDayEvent,AppointmentState,TimeZone,Organizer,Category,EventRecurrence,Attachments,Body,Profile ) - VALUES ('${data.EventId}','${data.Subject}', '${data.HasAttachments}','${data.Location}','${data.CalendarId}','${data.CalendarName}','${data.StartDate}','${data.EndDate}','${data.EventType}','${data.Attendees}','${data.IsMeeting}','${data.IsRecurring}', - '${data.IsAllDayEvent}','${data.AppointmentState}','${data.TimeZone}','${data.Organizer}','${data.Category}','${data.EventRecurrence}','${data.Attachments}','${data.Body}','${data.Profile}')`, []) + INSERT OR IGNORE INTO ${this.events} (EventId,Subject,HasAttachments,Location,CalendarId,CalendarName,StartDate,EndDate,EventType,Attendees,IsMeeting,IsRecurring,IsAllDayEvent,AppointmentState,TimeZone,Organizer,Category,EventRecurrence,Attachments,Body,Profile,HumanDate ) + VALUES ('${data.EventId}','${data.Subject}','${data.HasAttachments}','${data.Location}','${data.CalendarId}','${data.CalendarName}','${data.StartDate}','${data.EndDate}','${data.EventType}','${data.Attendees}','${data.IsMeeting}','${data.IsRecurring}', + '${data.IsAllDayEvent}','${data.AppointmentState}','${data.TimeZone}','${data.Organizer}','${data.Category}','${data.EventRecurrence}','${data.Attachments}','${data.Body}','${data.Profile}','${data.HumanDate}')`, []) .then(() => { console.log("event add with Success"); }, (e) => { - console.log(JSON.stringify(e.err)); + console.log(JSON.stringify(e)); }); } @@ -149,34 +190,47 @@ export class SqliteService { }); } - //updateprocess - public updateProcess(data) { - this.dbInstance.executeSql(` + //updateActions + public updateactions(id,data) { + this.dbInstance.executeSql(` + UPDATE ${this.actions} SET DateIndex = ?, DatePublication = ?,DocumentId = ?,FileBase64 = ?,FileExtension = ?,Message = ?,OrganicEntityId = ?,OriginalFileName = ?,Title = ? WHERE ProcessId = ${id}`,data) + .then(() => { + console.log("action update with Success"); + + }, (e) => { + console.log(JSON.stringify(e.err)); + }); + } + + + //updateprocess + public updateProcess(data) { + this.dbInstance.executeSql(` INSERT OR REPLACE INTO ${this.allprocess} (serialNumber,workflowInstanceFolio,Documents,actions,activityInstanceName,formURL,originator,taskStartDate,totalDocuments,workflowDisplayName,workflowID,workflowInstanceDataFields,workflowInstanceID,workflowName) VALUES ('${data.serialNumber}','${data.workflowInstanceFolio}', '${JSON.stringify(data.Documents)}','${JSON.stringify(data.actions)}','${data.activityInstanceName}','${data.formURL}','${JSON.stringify(data.originator)}','${data.taskStartDate}','${data.totalDocuments}','${data.workflowDisplayName}','${data.workflowID}', '${JSON.stringify(data.workflowInstanceDataFields)}','${data.workflowInstanceID}','${data.workflowName}')`, []) - .then(() => { - console.log("process add with Success"); - - }, (e) => { - console.log(JSON.stringify(e.err)); - }); - } + .then(() => { + console.log("process add with Success"); - //updateAttachment - updateUser(id, document,) { - let data = [document]; - return this.dbInstance.executeSql(`UPDATE ${this.allprocess} SET Documents = ? WHERE serialNumber = ${id}`, [document]).then(() => { - console.log("process attachment updated") - }) - } - //updateAttachment - updateProcessInterveners(id, interveners,) { - let data = [document]; - return this.dbInstance.executeSql(`UPDATE ${this.allprocess} SET interveners = ? WHERE serialNumber = ${id}`, [interveners]).then(() => { - console.log("process interveners updated") - }) - } + }, (e) => { + console.log(JSON.stringify(e.err)); + }); + } + + //updateAttachment + updateUser(id, document,) { + let data = [document]; + return this.dbInstance.executeSql(`UPDATE ${this.allprocess} SET Documents = ? WHERE serialNumber = ${id}`, [document]).then(() => { + console.log("process attachment updated") + }) + } + //updateAttachment + updateProcessInterveners(id, interveners,) { + let data = [document]; + return this.dbInstance.executeSql(`UPDATE ${this.allprocess} SET interveners = ? WHERE serialNumber = ${id}`, [interveners]).then(() => { + console.log("process interveners updated") + }) + } //getAllEvents getAllEvents() { var hashattachment = false; @@ -218,7 +272,10 @@ export class SqliteService { Organizer: res.rows.item(i).Organizer, Category: res.rows.item(i).Category, EventRecurrence: res.rows.item(i).EventRecurrence, - Attachments: res.rows.item(i).Attachments + Attachments: res.rows.item(i).Attachments, + Profile: res.rows.item(i).Profile, + HumanDate: res.rows.item(i).HumanDate + } this.EVENTS.push(event); } @@ -258,9 +315,23 @@ export class SqliteService { }); } + //getAllAtions + getAllActions() { + return this.dbInstance.executeSql(`SELECT * FROM ${this.actions}`, []).then((res) => { + this.ALLACTIONS = []; + if (res.rows.length > 0) { + for (var i = 0; i < res.rows.length; i++) { + this.ALLACTIONS.push(res.rows.item(i)); + } + return this.ALLACTIONS; + } + }, (e) => { + console.log(" Get all actions error", JSON.stringify(e)); + }); + } //getlistOfEventAprove getListOfEventAprove(process, type) { - return this.dbInstance.executeSql(`SELECT * FROM ${this.allprocess} WHERE workflowDisplayName = ? OR workflowDisplayName = ? `, [process,type]).then((res) => { + return this.dbInstance.executeSql(`SELECT * FROM ${this.allprocess} WHERE workflowDisplayName = ? OR workflowDisplayName = ? `, [process, type]).then((res) => { this.ALLPROCESS = []; if (res.rows.length > 0) { for (var i = 0; i < res.rows.length; i++) { @@ -288,35 +359,35 @@ export class SqliteService { }); } - //getprocessByworkflow - getprocessByworkflow(process) { - return this.dbInstance.executeSql(`SELECT * FROM ${this.allprocess} WHERE workflowDisplayName = ? `, [process]).then((res) => { - this.ALLPROCESS = []; - if (res.rows.length > 0) { - for (var i = 0; i < res.rows.length; i++) { - this.ALLPROCESS.push(res.rows.item(i)); - } - return this.ALLPROCESS; + //getprocessByworkflow + getprocessByworkflow(process) { + return this.dbInstance.executeSql(`SELECT * FROM ${this.allprocess} WHERE workflowDisplayName = ? `, [process]).then((res) => { + this.ALLPROCESS = []; + if (res.rows.length > 0) { + for (var i = 0; i < res.rows.length; i++) { + this.ALLPROCESS.push(res.rows.item(i)); } - }, (e) => { - console.log(" Get all process error", JSON.stringify(e)); - }); - } + return this.ALLPROCESS; + } + }, (e) => { + console.log(" Get all process error", JSON.stringify(e)); + }); + } - //getprocessByworkflowpedido - getprocessByworkflowpedido(process, process2) { - return this.dbInstance.executeSql(`SELECT * FROM ${this.allprocess} WHERE workflowDisplayName = ? OR workflowDisplayName = ? `, [process, process2]).then((res) => { - this.ALLPROCESS = []; - if (res.rows.length > 0) { - for (var i = 0; i < res.rows.length; i++) { - this.ALLPROCESS.push(res.rows.item(i)); - } - return this.ALLPROCESS; + //getprocessByworkflowpedido + getprocessByworkflowpedido(process, process2) { + return this.dbInstance.executeSql(`SELECT * FROM ${this.allprocess} WHERE workflowDisplayName = ? OR workflowDisplayName = ? `, [process, process2]).then((res) => { + this.ALLPROCESS = []; + if (res.rows.length > 0) { + for (var i = 0; i < res.rows.length; i++) { + this.ALLPROCESS.push(res.rows.item(i)); } - }, (e) => { - console.log(" Get all process error", JSON.stringify(e)); - }); - } + return this.ALLPROCESS; + } + }, (e) => { + console.log(" Get all process error", JSON.stringify(e)); + }); + } getProcessById(serial) { return this.dbInstance.executeSql(`SELECT * FROM ${this.allprocess} WHERE serialNumber = ? `, [serial]).then((res) => {