This commit is contained in:
2022-04-02 14:13:37 +01:00
parent c0a500f5e0
commit fa25462897
9 changed files with 409 additions and 104 deletions
+1
View File
@@ -7,6 +7,7 @@ export interface EventListStore {
calendarName: "Oficial" |"Pessoal"
profile: "md" | "pr",
id: string
CalendarId: any
}
export interface EventList {
+20 -1
View File
@@ -296,6 +296,7 @@ export class AgendaPage implements OnInit {
/* console.log('Event clicked', event); */
//clear
console.log(event)
this.setIntervenient([]);
this.setIntervenientCC([]);
@@ -817,7 +818,6 @@ export class AgendaPage implements OnInit {
this.TimelineMDList = this.listBoxService.list(this.listToPresent, 'md', this.rangeStartDate, this.rangeEndDate, { segment: this.segment, selectedDate: this.eventSelectedDate })
console.log('check list to present data', this.listToPresent);
this.myCal.update();
this.myCal.loadEvents();
@@ -1019,6 +1019,25 @@ export class AgendaPage implements OnInit {
}
getEventsFromDB () {
new Promise((resolve, reject)=>{
if (this.platform.is('desktop') || this.platform.is('mobileweb')) {
this.storage.get('agendaResponse').then((events) => {
resolve(events)
})
} else {
this.sqliteservice.getAllEvents().then((events: any[]) => {
resolve(events)
})
}
})
}
updateEventListBox() {
if (window.innerWidth < 800) {
@@ -128,7 +128,6 @@ export class NewEventPage implements OnInit {
console.log(this.postEvent);
console.log(this.selectedSegment);
this.getRecurrenceTypes();
if(this.selectedSegment != "Combinada"){
@@ -22,6 +22,8 @@ import { StorageService } from 'src/app/services/storage.service';
import { ThemeService } from 'src/app/services/theme.service'
import { RouteService } from 'src/app/services/route.service';
import { Storage } from '@ionic/storage';
import { SessionStore } from 'src/app/store/session.service';
import { CalendarService } from 'src/app/store/calendar.service';
@Component({
@@ -55,7 +57,7 @@ export class ViewEventPage implements OnInit {
header = true
task: ExpedientTaskModalPageNavParamsTask;
LoadedDocument: any = null;
sesseionStora = SessionStore
constructor(
private modalController: ModalController,
/* private navParams: NavParams, */
@@ -75,7 +77,8 @@ export class ViewEventPage implements OnInit {
private storage: StorageService,
public ThemeService: ThemeService,
private RouteService: RouteService,
private ionicStorage: Storage
private ionicStorage: Storage,
private CalendarService: CalendarService
) {
this.isEventEdited = false;
this.loadedEvent = new Event();
@@ -137,6 +140,23 @@ export class ViewEventPage implements OnInit {
}
getEventsFromDB () {
return new Promise((resolve, reject) => {
if (this.platform.is('desktop') || this.platform.is('mobileweb')) {
this.storage.get('agendaResponse').then((events) => {
resolve(events)
})
} else {
this.sqliteservice.getAllEvents().then((events: any[]) => {
resolve(events)
})
}
})
}
close() {
this.modalController.dismiss(this.isEventEdited);
@@ -166,27 +186,62 @@ export class ViewEventPage implements OnInit {
loadEvent() {
const loader = this.toastService.loading();
this.eventsService.getEvent(this.eventId).subscribe(res => {
this.loadedEvent = res;
this.addEventToDb(res);
console.log('Loaded one event', res)
/* 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) => {
console.log('errorstatus ss',error.status)
if (error.status === 0) {
this.getFromDb();
} else {
this.toastService.badRequest('Este evento já não existe na sua agenda')
if(this.sesseionStora.user.Profile == 'MDGPR' || this.sesseionStora.user.Profile == 'PR') {
this.eventsService.getEvent(this.eventId).subscribe(res => {
this.loadedEvent = res;
this.addEventToDb(res);
console.log('Loaded one event', res)
/* this.today = new Date(res.StartDate);
this.customDate = this.days[this.today.getDay()]+ ", " + this.today.getDate() +" de " + ( this.months[this.today.getMonth()]); */
loader.remove()
this.modalController.dismiss('Eevent not Foud');
this.RouteService.goBack();
}, (error) => {
console.log('errorstatus ss',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.RouteService.goBack();
}
loader.remove()
});
} else {
const event = this.CalendarService.eventSource.find((ele) => ele.id == this.eventId)
if(event?.CalendarId) {
this.eventsService.genericGetEvent(this.eventId, event.CalendarId).subscribe(res => {
this.loadedEvent = res;
this.addEventToDb(res);
console.log('Loaded one event', res)
/* 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) => {
console.log('errorstatus ss',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.RouteService.goBack();
}
loader.remove()
});
}
loader.remove()
});
}
}
deleteEvent() {
+2 -1
View File
@@ -199,7 +199,8 @@ export class ListBoxService {
EndDate: event.event.EndDate,
Location: event.event.Location,
EventId: event.event.EventId,
CalendarName: event.event.CalendarName
CalendarName: event.event.CalendarName,
CalendarId: event.event.CalendarId
},
Subject: event.event.Subject,
startMany: false,
+170 -26
View File
@@ -29,7 +29,7 @@ export class EventsService {
headersMdPessoal: HttpHeaders;
headerOwnOficial: HttpHeaders;
headersOwnPessoal: HttpHeaders;
headerOwnPessoal: HttpHeaders;
headerSharedOficial: HttpHeaders;
headerSharedPessoal: HttpHeaders;
@@ -64,7 +64,7 @@ export class EventsService {
this.headerOwnOficial= new HttpHeaders();
this.headersOwnPessoal= new HttpHeaders();
this.headerOwnPessoal= new HttpHeaders();
this.headerSharedOficial= new HttpHeaders();
this.headerSharedPessoal= new HttpHeaders();
@@ -83,7 +83,6 @@ export class EventsService {
this.hasSharedCalendar = false
this.hasOwnCalendar = false
this.calendarOwnerIds = []
if (this.loggeduser) {
@@ -166,11 +165,13 @@ export class EventsService {
this.headerOwnOficial = this.headerOwnOficial.set('Authorization', this.loggeduser.BasicAuthKey);
this.headerOwnOficial = this.headerOwnOficial.set('CalendarId', calendar.CalendarId);
this.headerOwnOficial = this.headerOwnOficial.set('CalendarRoleId', calendar.CalendarRoleId);
this.headerOwnOficial = this.headerOwnOficial.set('CalendarName', calendar.CalendarName);
}
else if (calendar.CalendarName == 'Pessoal') {
this.headersOwnPessoal.set('Authorization', this.loggeduser.BasicAuthKey);
this.headersOwnPessoal.set('CalendarId', calendar.CalendarId);
this.headersOwnPessoal.set('CalendarRoleId', calendar.CalendarRoleId);
this.headerOwnPessoal = this.headerOwnPessoal.set('Authorization', this.loggeduser.BasicAuthKey);
this.headerOwnPessoal =this.headerOwnPessoal.set('CalendarId', calendar.CalendarId);
this.headerOwnPessoal =this.headerOwnPessoal.set('CalendarRoleId', calendar.CalendarRoleId);
this.headerOwnPessoal = this.headerOwnPessoal.set('CalendarName', calendar.CalendarName);
}
});
@@ -185,18 +186,19 @@ export class EventsService {
this.hasSharedCalendar = true
if (sharedCalendar.CalendarName == 'Oficial') {
sharedCalendar.CalendarName
this.headerSharedOficial = this.headerSharedOficial.set('Authorization', 'Basic '+sharedCalendar.CalendarToken);
this.headerSharedOficial = this.headerSharedOficial.set('CalendarId', sharedCalendar.CalendarId);
this.headerSharedOficial = this.headerSharedOficial.set('CalendarRoleId', sharedCalendar.CalendarRoleId);
this.headerSharedOficial = this.headerSharedOficial.set('CalendarName', sharedCalendar.CalendarName);
}
else if (sharedCalendar.CalendarName == 'Pessoal') {
this.headerSharedPessoal = this.headerSharedPessoal.set('Authorization', 'Basic '+sharedCalendar.CalendarToken);
this.headerSharedPessoal = this.headerSharedPessoal.set('CalendarId', sharedCalendar.CalendarId);
this.headerSharedPessoal = this.headerSharedPessoal.set('CalendarRoleId', sharedCalendar.CalendarRoleId);
this.headerSharedPessoal = this.headerSharedPessoal.set('CalendarName', sharedCalendar.CalendarName);
}
}
console.log(this.loggeduser.SharedCalendars)
}
@@ -321,7 +323,7 @@ export class EventsService {
params = params.set("EndDate", enddate);
let options = {
headers: this.headersOwnPessoal,
headers: this.headerOwnPessoal,
params: params
};
return this.http.get<any>(`${geturl}`, options)
@@ -458,6 +460,39 @@ export class EventsService {
return this.http.get<Event>(`${geturl}`, options);
}
genericGetEvent(eventid: string, calendarId: string) {
let geturl = environment.apiURL + 'calendar/GetEvent';
let params = new HttpParams();
params = params.set("EventId", eventid);
const headers = [
this.headerSharedOficial,
this.headerSharedPessoal,
this.headerOwnPessoal,
this.headerOwnOficial
]
const header = headers.find((header)=> {
return header?.get('CalendarId')?.includes(calendarId)
})
if(header) {
let options = {
headers: header,
params: params
}
return this.http.get<Event>(`${geturl}`, options);
} else {
alert('headr not found'+ calendarId)
}
throw('error')
}
putEvent(event: Event, conflictResolutionMode: number, sendInvitationsOrCancellationsMode: number, sharedagenda: string): Observable<Event> {
const puturl = environment.apiURL + 'calendar/' + ((sharedagenda != '') ? sharedagenda : 'PutEvent');
@@ -494,7 +529,12 @@ export class EventsService {
else if (this.loggeduser.Profile == 'PR') {
this.headers = this.headersPrOficial;
} else {
this.headers = this.headerOwnOficial
if(this.hasOwnCalendar) {
this.headers = this.headerOwnOficial
} else {
this.headers = this.headerSharedOficial
}
}
}
else {
@@ -505,7 +545,11 @@ export class EventsService {
this.headers = this.headersPrPessoal;
}
else {
this.headers = this.headersOwnPessoal
if(this.hasSharedCalendar) {
this.headers = this.headerSharedPessoal
} else {
this.headers = this.headerOwnPessoal
}
}
}
@@ -522,6 +566,7 @@ export class EventsService {
})
)
}
changeAgenda(body: any) {
const puturl = environment.apiURL + 'Calendar/MoveEvent';
@@ -597,23 +642,45 @@ export class EventsService {
let options: any;
switch (calendarName) {
case 'Oficial':
options = {
headers: this.headerSharedOficial,
params: params
};
break;
case 'Pessoal':
options = {
headers: this.headerSharedPessoal,
params: params
};
break;
if(this.hasOwnCalendar) {
switch (calendarName) {
case 'Oficial':
options = {
headers: this.headerOwnOficial,
params: params
};
break;
case 'Pessoal':
options = {
headers: this.headerOwnPessoal,
params: params
};
break;
}
} else {
switch (calendarName) {
case 'Oficial':
options = {
headers: this.headerSharedOficial,
params: params
};
break;
case 'Pessoal':
options = {
headers: this.headerSharedPessoal,
params: params
};
break;
}
}
return this.http.post<string>(`${puturl}`, event, options)
}
@@ -673,6 +740,83 @@ export class EventsService {
})
)
}
genericDeleteEvent(eventid: string, eventDeleteType: number, calendarName: string, calendarId: string) {
let arrayReq = [];
let Object = {
eventid: eventid,
eventDeleteType: eventDeleteType,
calendarName: calendarName
}
arrayReq.push(Object)
const puturl = environment.apiURL + 'calendar/DeleteEvent';
let params = new HttpParams();
params = params.set("EventId", eventid);
// 0 for occurence and 1 for serie (delete all events)
params = params.set("eventDeleteType", eventDeleteType.toString());
let options;
if(this.loggeduser.Profile == 'MDGPR') {
if (calendarName == 'Pessoal') {
options = {
headers: this.headersMdPessoal,
params: params
};
}
else if (calendarName == 'Oficial') {
options = {
headers: this.headersMdOficial,
params: params
};
}
}
else if (this.loggeduser.Profile == 'PR') {
if (calendarName == 'Pessoal') {
options = {
headers: this.headersPrPessoal,
params: params
};
}
else if (calendarName == 'Oficial') {
options = {
headers: this.headersPrOficial,
params: params
};
}
}
else {
const headers = [
this.headerSharedOficial,
this.headerSharedPessoal,
this.headerOwnPessoal,
this.headerOwnOficial
]
const header = headers.find((header)=> {
return header?.get('CalendarId')?.includes(calendarId)
})
if (header) {
return this.http.delete(`${puturl}`, options).pipe(
catchError(err => {
console.log('Event edit saved offline')
this.offlinemanager.storeRequestData('eventDelete', arrayReq);
throw new Error(err);
})
)
}
throw('header not found')
}
}
postExpedientEvent(docId: any, body: any, sharedagenda: string, serialNumber: any, applicationID: any) {
const geturl = environment.apiURL + 'calendar/' + ((sharedagenda != '') ? sharedagenda : 'CreateEventExpediente') + '/event';
let params = new HttpParams();
@@ -13,6 +13,7 @@ import { ToastService } from 'src/app/services/toast.service';
import { FormControl, FormGroup, Validators } from '@angular/forms';
import { ParticipantsPipe } from 'src/app/pipes/participants.pipe';
import { ThemeService } from 'src/app/services/theme.service'
import { SessionStore } from 'src/app/store/session.service';
@Component({
selector: 'app-edit-event',
@@ -83,6 +84,7 @@ export class EditEventPage implements OnInit {
public stepSeconds = [1, 5, 10, 15, 20, 25];
private participantsPipe = new ParticipantsPipe()
sesseionStora = SessionStore
constructor(
private modalController: ModalController,
@@ -258,19 +260,37 @@ export class EditEventPage implements OnInit {
this.showLoader = true;
try {
await this.eventsService.editEvent(this.postEvent, 2, 3).toPromise()
if(this.initCalendarName != this.postEvent.CalendarName) {
let body = {
"EventId": this.postEvent.EventId,
"CalendarDestinationName": this.postEvent.CalendarName,
if(this.sesseionStora.user.Profile == 'MDGPR' || this.sesseionStora.user.Profile == 'PR') {
await this.eventsService.editEvent(this.postEvent, 2, 3).toPromise()
if(this.initCalendarName != this.postEvent.CalendarName) {
let body = {
"EventId": this.postEvent.EventId,
"CalendarDestinationName": this.postEvent.CalendarName,
}
try {
await this.eventsService.changeAgenda(body).toPromise();
} catch (e) {}
}
try {
await this.eventsService.changeAgenda(body).toPromise();
} catch (e) {}
this.showLoader = false;
this.toastService.successMessage()
} else {
await this.eventsService.editEvent(this.postEvent, 2, 3).toPromise()
if(this.initCalendarName != this.postEvent.CalendarName) {
let body = {
"EventId": this.postEvent.EventId,
"CalendarDestinationName": this.postEvent.CalendarName,
}
try {
await this.eventsService.changeAgenda(body).toPromise();
} catch (e) {}
}
this.showLoader = false;
this.toastService.successMessage()
}
this.showLoader = false;
this.toastService.successMessage()
} catch(error) {
this.showLoader = false
this.toastService.badRequest()
@@ -14,6 +14,8 @@ import { ExpedientTaskModalPage } from 'src/app/pages/gabinete-digital/expedient
import { ViewDocumentPage } from 'src/app/modals/view-document/view-document.page';
import { ThemeService } from 'src/app/services/theme.service'
import { RouteService } from 'src/app/services/route.service';
import { CalendarService } from 'src/app/store/calendar.service';
import { SessionStore } from 'src/app/store/session.service';
@Component({
@@ -46,6 +48,7 @@ export class ViewEventPage implements OnInit {
@Input() eventId: string;
@Output() viewEventDetailDismiss = new EventEmitter<any>();
sesseionStora = SessionStore
constructor(
private eventsService: EventsService,
@@ -55,7 +58,8 @@ export class ViewEventPage implements OnInit {
private modalController: ModalController,
public popoverController: PopoverController,
private toastService: ToastService,
public ThemeService: ThemeService
public ThemeService: ThemeService,
private CalendarService: CalendarService
) {
this.isEventEdited = false;
this.loadedEvent = new Event();
@@ -97,24 +101,54 @@ export class ViewEventPage implements OnInit {
loadEvent() {
this.eventsService.getEvent(this.eventId).subscribe(res => {
console.log(res);
this.loadedEvent = res;
this.today = new Date(res.StartDate);
this.customDate = this.days[this.today.getDay()]+ ", " + this.today.getDate() +" de " + ( this.months[this.today.getMonth()]);
}, (error)=> {
if(this.sesseionStora.user.Profile == 'MDGPR' || this.sesseionStora.user.Profile == 'PR') {
this.eventsService.getEvent(this.eventId).subscribe(res => {
console.log(res);
this.loadedEvent = res;
this.today = new Date(res.StartDate);
this.customDate = this.days[this.today.getDay()]+ ", " + this.today.getDate() +" de " + ( this.months[this.today.getMonth()]);
}, (error)=> {
this.viewEventDetailDismiss.emit({
type: 'close'
})
if(error.status == 0) {
this.toastService.badRequest('Não é possível visualizar este evento no modo offline')
} else {
this.toastService.badRequest('Este evento já não existe na sua agenda')
}
});
} else {
this.viewEventDetailDismiss.emit({
type: 'close'
})
if(error.status == 0) {
this.toastService.badRequest('Não é possível visualizar este evento no modo offline')
} else {
this.toastService.badRequest('Este evento já não existe na sua agenda')
const event = this.CalendarService.eventSource.find((ele) => ele.id == this.eventId)
if(event?.CalendarId) {
this.eventsService.genericGetEvent(this.eventId, event.CalendarId).subscribe(res => {
console.log(res);
this.loadedEvent = res;
this.today = new Date(res.StartDate);
this.customDate = this.days[this.today.getDay()]+ ", " + this.today.getDate() +" de " + ( this.months[this.today.getMonth()]);
}, (error)=> {
this.viewEventDetailDismiss.emit({
type: 'close'
})
if(error.status == 0) {
this.toastService.badRequest('Não é possível visualizar este evento no modo offline')
} else {
this.toastService.badRequest('Este evento já não existe na sua agenda')
}
});
}
});
}
}
async deleteEvent() {
@@ -122,24 +156,56 @@ export class ViewEventPage implements OnInit {
if (this.loadedEvent.IsRecurring) {
const loader = this.toastService.loading()
this.eventsService.deleteEvent(this.loadedEvent.EventId, 0, this.loadedEvent.CalendarName).subscribe(async () => {
this.toastService.successMessage('Evento apagado');
this.close();
},()=>{},
()=>{
loader.remove();
});
if(this.sesseionStora.user.Profile == 'MDGPR' || this.sesseionStora.user.Profile == 'PR') {
this.eventsService.deleteEvent(this.loadedEvent.EventId, 0, this.loadedEvent.CalendarName).subscribe(async () => {
this.toastService.successMessage('Evento apagado');
this.close();
},()=>{},
()=>{
loader.remove();
});
} else {
const event = this.CalendarService.eventSource.find((ele) => ele.id == this.eventId)
if(event?.CalendarId) {
this.eventsService.genericDeleteEvent(this.loadedEvent.EventId, 0, this.loadedEvent.CalendarName, event?.CalendarId).subscribe(async () => {
this.toastService.successMessage('Evento apagado');
this.close();
},()=>{},
()=>{
loader.remove();
});
}
}
} else {
const loader = this.toastService.loading()
if(this.sesseionStora.user.Profile == 'MDGPR' || this.sesseionStora.user.Profile == 'PR') {
this.eventsService.deleteEvent(this.loadedEvent.EventId, 0, this.loadedEvent.CalendarName).subscribe(async () => {
this.toastService.successMessage('Evento apagado');
this.close();
},()=>{},
()=>{
loader.remove();
});
} else {
const event = this.CalendarService.eventSource.find((ele) => ele.id == this.eventId)
if(event?.CalendarId) {
this.eventsService.genericDeleteEvent(this.loadedEvent.EventId, 0, this.loadedEvent.CalendarName, event?.CalendarId).subscribe(async () => {
this.toastService.successMessage('Evento apagado');
this.close();
},()=>{},
()=>{
loader.remove();
});
}
}
this.eventsService.deleteEvent(this.loadedEvent.EventId, 0, this.loadedEvent.CalendarName).subscribe(async () => {
this.toastService.successMessage('Evento apagado');
this.close();
},()=>{},
()=>{
loader.remove();
});
}
}
+13 -13
View File
@@ -21,20 +21,19 @@ export class CalendarService {
let restore = this.localstoreService.get(this.keyName, [])
setTimeout(()=>{
restore.forEach((element:EventListStore, eventIndex) => {
this._eventSource.push({
startTime: new Date(element.startTime),
endTime: new Date(element.endTime),
allDay: element.allDay,
event: element.event,
calendarName: element.calendarName,
profile: element.profile,
id: element.id,
});
restore.forEach((element:EventListStore, eventIndex) => {
this._eventSource.push({
startTime: new Date(element.startTime),
endTime: new Date(element.endTime),
allDay: element.allDay,
event: element.event,
calendarName: element.calendarName,
CalendarId: element.CalendarId,
profile: element.profile,
id: element.id,
});
},10)
});
}
@@ -75,6 +74,7 @@ export class CalendarService {
calendarName: element.CalendarName,
profile: profile,
id: element.EventId,
CalendarId: element.CalendarId
});
});