mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-20 13:26:08 +00:00
Refactoring made on offline
This commit is contained in:
@@ -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()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user