mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-18 20:47:54 +00:00
merge
This commit is contained in:
@@ -4,7 +4,6 @@ import { HttpClient, HttpHeaders, HttpParams } from '@angular/common/http';
|
||||
import { Observable, from } from 'rxjs';
|
||||
import { environment } from 'src/environments/environment';
|
||||
import { AuthService } from '../services/auth.service';
|
||||
import { UserSession } from '../models/user.model';
|
||||
import { EventList } from '../models/agenda/AgendaEventList';
|
||||
import { ChangeProfileService } from './change-profile.service';
|
||||
import { OfflineManagerService } from 'src/app/services/offline-manager.service';
|
||||
@@ -20,7 +19,6 @@ import { SessionStore } from '../store/session.service';
|
||||
export class EventsService {
|
||||
|
||||
authheader = {};
|
||||
loggeduser: UserSession;
|
||||
headers: HttpHeaders;
|
||||
|
||||
headersPrOficial: HttpHeaders;
|
||||
@@ -37,25 +35,17 @@ export class EventsService {
|
||||
|
||||
headersSharedOficial: HttpHeaders;
|
||||
headersSharedPessoal: HttpHeaders;
|
||||
|
||||
hasSharedCalendar = false
|
||||
hasOwnCalendar = false
|
||||
|
||||
|
||||
|
||||
calendarIds = []
|
||||
usersCalendarIds = []
|
||||
|
||||
hasSharedCalendar = false;
|
||||
hasSharedOficial: boolean = false;
|
||||
hasSharedPessoal: boolean = false;
|
||||
|
||||
hasOwnOficial: boolean = false;
|
||||
hasOwnPessoal: boolean = false;
|
||||
|
||||
|
||||
|
||||
userCalendarNameSharedOficial = '';
|
||||
userCalendarNameSharedPessoal = '';
|
||||
userCalendarNameOwnOficial = '';
|
||||
userCalendarNameOwnPessoal = '';
|
||||
hasOwnCalendar = false
|
||||
|
||||
calendarNames = {}
|
||||
|
||||
@@ -73,7 +63,14 @@ export class EventsService {
|
||||
private storage: Storage,
|
||||
private backgroundservice: BackgroundService) {
|
||||
|
||||
this.loggeduser = SessionStore.user;
|
||||
this.setHeader()
|
||||
this.changeProfileService.registerCallback(() => {
|
||||
this.setHeader()
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
async setHeader () {
|
||||
|
||||
this.headers = new HttpHeaders();
|
||||
this.headersMdOficial = new HttpHeaders();
|
||||
@@ -92,16 +89,14 @@ export class EventsService {
|
||||
this.headerSharedOficial= new HttpHeaders();
|
||||
this.headerSharedPessoal= new HttpHeaders();
|
||||
|
||||
this.headers = this.headers.set('Authorization', SessionStore.user.BasicAuthKey);
|
||||
|
||||
this.setHeader()
|
||||
this.changeProfileService.registerCallback(() => {
|
||||
this.loggeduser = SessionStore.user;
|
||||
this.setHeader()
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
async setHeader () {
|
||||
this.usersCalendarIds = [];
|
||||
this.calendarNames = {}
|
||||
this.calendarIds = []
|
||||
|
||||
this.calendarNamesAry = []
|
||||
this.calendarNamesType = {}
|
||||
|
||||
this.hasSharedCalendar = false
|
||||
this.hasSharedOficial = false
|
||||
@@ -110,32 +105,11 @@ export class EventsService {
|
||||
this.hasOwnCalendar = false
|
||||
this.hasOwnOficial = false
|
||||
this.hasOwnPessoal = false
|
||||
|
||||
this.headers = new HttpHeaders();
|
||||
|
||||
this.headerOwnOficial= new HttpHeaders();
|
||||
this.headerOwnPessoal= new HttpHeaders();
|
||||
|
||||
this.headerSharedOficial= new HttpHeaders();
|
||||
this.headerSharedPessoal= new HttpHeaders();
|
||||
if (SessionStore.user) {
|
||||
if (SessionStore.user.Profile == 'MDGPR') {
|
||||
|
||||
this.headers = this.headers.set('Authorization', this.loggeduser.BasicAuthKey);
|
||||
|
||||
this.userCalendarNameSharedOficial = '';
|
||||
this.userCalendarNameSharedPessoal = '';
|
||||
this.userCalendarNameOwnOficial = '';
|
||||
this.userCalendarNameOwnPessoal = '';
|
||||
|
||||
this.usersCalendarIds = [];
|
||||
this.calendarNames = {}
|
||||
|
||||
this.calendarNamesAry = []
|
||||
this.calendarNamesType = {}
|
||||
|
||||
if (this.loggeduser) {
|
||||
if (this.loggeduser.Profile == 'MDGPR') {
|
||||
|
||||
for (let calendar of this.loggeduser.OwnerCalendars) {
|
||||
for (let calendar of SessionStore.user.OwnerCalendars) {
|
||||
this.hasAnyCalendar = false
|
||||
|
||||
if (calendar.CalendarName == 'Oficial') {
|
||||
@@ -143,7 +117,7 @@ export class EventsService {
|
||||
this.hasOwnOficial = true
|
||||
|
||||
|
||||
this.headersMdOficial = this.headersMdOficial.set('Authorization', this.loggeduser.BasicAuthKey);
|
||||
this.headersMdOficial = this.headersMdOficial.set('Authorization', SessionStore.user.BasicAuthKey);
|
||||
this.headersMdOficial = this.headersMdOficial.set('CalendarId', calendar.CalendarId);
|
||||
this.headersMdOficial = this.headersMdOficial.set('CalendarRoleId', calendar.CalendarRoleId);
|
||||
}
|
||||
@@ -151,21 +125,21 @@ export class EventsService {
|
||||
|
||||
this.hasOwnPessoal = true
|
||||
|
||||
this.headersMdPessoal = this.headersMdPessoal.set('Authorization', this.loggeduser.BasicAuthKey);
|
||||
this.headersMdPessoal = this.headersMdPessoal.set('Authorization', SessionStore.user.BasicAuthKey);
|
||||
this.headersMdPessoal = this.headersMdPessoal.set('CalendarId', calendar.CalendarId);
|
||||
this.headersMdPessoal = this.headersMdPessoal.set('CalendarRoleId', calendar.CalendarRoleId);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
for (let sharedCalendar of this.loggeduser.SharedCalendars) {
|
||||
for (let sharedCalendar of SessionStore.user.SharedCalendars) {
|
||||
this.hasAnyCalendar = false
|
||||
|
||||
if (sharedCalendar.CalendarName == 'Oficial') {
|
||||
|
||||
this.hasSharedOficial = true
|
||||
|
||||
this.headersSharedOficial = this.headersSharedOficial.set('Authorization', this.loggeduser.BasicAuthKey);
|
||||
this.headersSharedOficial = this.headersSharedOficial.set('Authorization', SessionStore.user.BasicAuthKey);
|
||||
this.headersSharedOficial = this.headersSharedOficial.set('CalendarId', sharedCalendar.CalendarId);
|
||||
this.headersSharedOficial = this.headersSharedOficial.set('CalendarRoleId', sharedCalendar.CalendarRoleId);
|
||||
}
|
||||
@@ -173,7 +147,7 @@ export class EventsService {
|
||||
|
||||
this.hasSharedPessoal = true
|
||||
|
||||
this.headersSharedPessoal = this.headersSharedPessoal.set('Authorization', this.loggeduser.BasicAuthKey);
|
||||
this.headersSharedPessoal = this.headersSharedPessoal.set('Authorization', SessionStore.user.BasicAuthKey);
|
||||
this.headersSharedPessoal = this.headersSharedPessoal.set('CalendarId', sharedCalendar.CalendarId);
|
||||
this.headersSharedPessoal = this.headersSharedPessoal.set('CalendarRoleId', sharedCalendar.CalendarRoleId);
|
||||
}
|
||||
@@ -181,15 +155,15 @@ export class EventsService {
|
||||
|
||||
}
|
||||
|
||||
else if (this.loggeduser.Profile == 'PR') {
|
||||
else if (SessionStore.user.Profile == 'PR') {
|
||||
|
||||
for (let calendar of this.loggeduser.OwnerCalendars) {
|
||||
for (let calendar of SessionStore.user.OwnerCalendars) {
|
||||
this.hasAnyCalendar = false
|
||||
if (calendar.CalendarName == 'Oficial') {
|
||||
|
||||
this.hasOwnOficial = true
|
||||
|
||||
this.headersPrOficial = this.headersPrOficial.set('Authorization', this.loggeduser.BasicAuthKey);
|
||||
this.headersPrOficial = this.headersPrOficial.set('Authorization', SessionStore.user.BasicAuthKey);
|
||||
this.headersPrOficial = this.headersPrOficial.set('CalendarId', calendar.CalendarId);
|
||||
this.headersPrOficial = this.headersPrOficial.set('CalendarRoleId', calendar.CalendarRoleId);
|
||||
}
|
||||
@@ -197,7 +171,7 @@ export class EventsService {
|
||||
|
||||
this.hasOwnPessoal = true
|
||||
|
||||
this.headersPrPessoal = this.headersPrPessoal.set('Authorization', this.loggeduser.BasicAuthKey);
|
||||
this.headersPrPessoal = this.headersPrPessoal.set('Authorization', SessionStore.user.BasicAuthKey);
|
||||
this.headersPrPessoal = this.headersPrPessoal.set('CalendarId', calendar.CalendarId);
|
||||
this.headersPrPessoal = this.headersPrPessoal.set('CalendarRoleId', calendar.CalendarRoleId);
|
||||
|
||||
@@ -206,7 +180,7 @@ export class EventsService {
|
||||
|
||||
}
|
||||
|
||||
for (let calendar of this.loggeduser.OwnerCalendars) {
|
||||
for (let calendar of SessionStore.user.OwnerCalendars) {
|
||||
this.hasAnyCalendar = false
|
||||
if(!this.usersCalendarIds.includes(calendar.OwnerUserId)) {
|
||||
this.usersCalendarIds.push(calendar.OwnerUserId)
|
||||
@@ -222,7 +196,7 @@ export class EventsService {
|
||||
|
||||
this.hasOwnOficial = true
|
||||
|
||||
this.headerOwnOficial = this.headerOwnOficial.set('Authorization', this.loggeduser.BasicAuthKey);
|
||||
this.headerOwnOficial = this.headerOwnOficial.set('Authorization', SessionStore.user.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);
|
||||
@@ -231,14 +205,14 @@ export class EventsService {
|
||||
|
||||
this.hasOwnPessoal = true
|
||||
|
||||
this.headerOwnPessoal = this.headerOwnPessoal.set('Authorization', this.loggeduser.BasicAuthKey);
|
||||
this.headerOwnPessoal = this.headerOwnPessoal.set('Authorization', SessionStore.user.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);
|
||||
}
|
||||
}
|
||||
|
||||
for (let sharedCalendar of this.loggeduser.SharedCalendars) {
|
||||
for (let sharedCalendar of SessionStore.user.SharedCalendars) {
|
||||
this.hasAnyCalendar = false
|
||||
|
||||
if(!this.usersCalendarIds.includes(sharedCalendar.OwnerUserId)) {
|
||||
@@ -254,7 +228,7 @@ export class EventsService {
|
||||
if (sharedCalendar.CalendarName == 'Oficial') {
|
||||
this.hasSharedOficial = true
|
||||
|
||||
this.headerSharedOficial = this.headerSharedOficial.set('Authorization',this.loggeduser.BasicAuthKey);
|
||||
this.headerSharedOficial = this.headerSharedOficial.set('Authorization',SessionStore.user.BasicAuthKey);
|
||||
this.headerSharedOficial = this.headerSharedOficial.set('CalendarId', sharedCalendar.CalendarId);
|
||||
this.headerSharedOficial = this.headerSharedOficial.set('CalendarRoleId', sharedCalendar.CalendarRoleId);
|
||||
this.headerSharedOficial = this.headerSharedOficial.set('CalendarName', sharedCalendar.CalendarName);
|
||||
@@ -263,7 +237,7 @@ export class EventsService {
|
||||
|
||||
this.hasSharedPessoal = true
|
||||
|
||||
this.headerSharedPessoal = this.headerSharedPessoal.set('Authorization',this.loggeduser.BasicAuthKey);
|
||||
this.headerSharedPessoal = this.headerSharedPessoal.set('Authorization',SessionStore.user.BasicAuthKey);
|
||||
this.headerSharedPessoal = this.headerSharedPessoal.set('CalendarId', sharedCalendar.CalendarId);
|
||||
this.headerSharedPessoal = this.headerSharedPessoal.set('CalendarRoleId', sharedCalendar.CalendarRoleId);
|
||||
this.headerSharedPessoal = this.headerSharedPessoal.set('CalendarName', sharedCalendar.CalendarName);
|
||||
@@ -271,7 +245,7 @@ export class EventsService {
|
||||
}
|
||||
|
||||
|
||||
for (let sharedCalendar of this.loggeduser.SharedCalendars) {
|
||||
for (let sharedCalendar of SessionStore.user.SharedCalendars) {
|
||||
this.hasAnyCalendar = false
|
||||
if(sharedCalendar?.OwnerUserId) {
|
||||
this.GetCalendarName(sharedCalendar.OwnerUserId).subscribe((e)=> {
|
||||
@@ -291,7 +265,7 @@ export class EventsService {
|
||||
|
||||
}
|
||||
|
||||
for (let sharedCalendar of this.loggeduser.OwnerCalendars) {
|
||||
for (let sharedCalendar of SessionStore.user.OwnerCalendars) {
|
||||
this.hasAnyCalendar = false
|
||||
|
||||
this.calendarNames[sharedCalendar.CalendarId] = 'Meu calendario'
|
||||
@@ -326,13 +300,13 @@ export class EventsService {
|
||||
|
||||
isMyEvent(event: any) {
|
||||
|
||||
for (let calendar of this.loggeduser.OwnerCalendars) {
|
||||
for (let calendar of SessionStore.user.OwnerCalendars) {
|
||||
if(event.CalendarId == calendar.CalendarId) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
for (let sharedCalendar of this.loggeduser.SharedCalendars) {
|
||||
for (let sharedCalendar of SessionStore.user.SharedCalendars) {
|
||||
if(event.CalendarId == sharedCalendar.CalendarId) {
|
||||
return false
|
||||
}
|
||||
@@ -438,12 +412,18 @@ export class EventsService {
|
||||
|
||||
let prO = [], prP = [];
|
||||
|
||||
for (let calendar of this.loggeduser.OwnerCalendars) {
|
||||
for (let calendar of SessionStore.user.OwnerCalendars) {
|
||||
if (calendar.CalendarName == 'Oficial') {
|
||||
prO = await this.getAllMdOficialEvents(startdate, enddate).toPromise();
|
||||
if(!Array.isArray(prO)) {
|
||||
prO = []
|
||||
}
|
||||
}
|
||||
if(calendar.CalendarName == 'Pessoal') {
|
||||
prP = await this.getAllMdPessoalEvents(startdate, enddate).toPromise();
|
||||
if(!Array.isArray(prP)) {
|
||||
prP = []
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -462,10 +442,16 @@ export class EventsService {
|
||||
|
||||
if(this.hasOwnOficial) {
|
||||
ownO = await this.getAllOwnOficialEvents(startdate, enddate).toPromise();
|
||||
if(!Array.isArray(ownO)) {
|
||||
ownO = []
|
||||
}
|
||||
}
|
||||
|
||||
if(this.hasOwnPessoal) {
|
||||
ownP = await this.getAllOwnPessoalEvents(startdate, enddate).toPromise();
|
||||
if(!Array.isArray(ownP)) {
|
||||
ownP = []
|
||||
}
|
||||
}
|
||||
|
||||
const resFinal = ownO.concat(ownP);
|
||||
@@ -509,10 +495,10 @@ export class EventsService {
|
||||
|
||||
let result = []
|
||||
|
||||
for (let sharedCalendar of this.loggeduser.SharedCalendars) {
|
||||
for (let sharedCalendar of SessionStore.user.SharedCalendars) {
|
||||
|
||||
var header = new HttpHeaders();
|
||||
header = header.set('Authorization', this.loggeduser.BasicAuthKey);
|
||||
header = header.set('Authorization', SessionStore.user.BasicAuthKey);
|
||||
header = header.set('CalendarId', sharedCalendar.CalendarId);
|
||||
header = header.set('CalendarRoleId', sharedCalendar.CalendarRoleId);
|
||||
header = header.set('CalendarName', sharedCalendar.CalendarName);
|
||||
@@ -579,7 +565,7 @@ export class EventsService {
|
||||
|
||||
let prO = [], prP = [];
|
||||
|
||||
for(let calendar of this.loggeduser.SharedCalendars) {
|
||||
for(let calendar of SessionStore.user.SharedCalendars) {
|
||||
if (calendar.CalendarName == 'Oficial') {
|
||||
prO = await this.getAllSharedOficialEvents(startdate, enddate).toPromise();
|
||||
}
|
||||
@@ -596,8 +582,6 @@ export class EventsService {
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
getAllSharedOficialEvents(startdate: string, enddate: string): Observable<Event[]> {
|
||||
let geturl = environment.apiURL + 'calendar/pr';
|
||||
geturl = geturl.replace('/V4/', '/V5/')
|
||||
@@ -733,10 +717,10 @@ export class EventsService {
|
||||
this.headers['CalendarName'] = event.CalendarName
|
||||
|
||||
if (event.CalendarName == 'Oficial') {
|
||||
if (this.loggeduser.Profile == 'MDGPR') {
|
||||
if (SessionStore.user.Profile == 'MDGPR') {
|
||||
this.headers = this.headersMdOficial;
|
||||
}
|
||||
else if (this.loggeduser.Profile == 'PR') {
|
||||
else if (SessionStore.user.Profile == 'PR') {
|
||||
this.headers = this.headersPrOficial;
|
||||
} else {
|
||||
|
||||
@@ -755,10 +739,10 @@ export class EventsService {
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (this.loggeduser.Profile == 'MDGPR') {
|
||||
if (SessionStore.user.Profile == 'MDGPR') {
|
||||
this.headers = this.headersMdPessoal;
|
||||
}
|
||||
else if (this.loggeduser.Profile == 'PR') {
|
||||
else if (SessionStore.user.Profile == 'PR') {
|
||||
this.headers = this.headersPrPessoal;
|
||||
}
|
||||
else {
|
||||
@@ -904,7 +888,7 @@ export class EventsService {
|
||||
|
||||
let options;
|
||||
|
||||
switch (this.loggeduser.Profile) {
|
||||
switch (SessionStore.user.Profile) {
|
||||
case 'MDGPR':
|
||||
if (calendarName == 'Pessoal') {
|
||||
options = {
|
||||
@@ -962,7 +946,7 @@ export class EventsService {
|
||||
|
||||
let options;
|
||||
|
||||
if(this.loggeduser.Profile == 'MDGPR') {
|
||||
if(SessionStore.user.Profile == 'MDGPR') {
|
||||
if (calendarName == 'Pessoal') {
|
||||
options = {
|
||||
headers: this.headersMdPessoal,
|
||||
@@ -976,7 +960,7 @@ export class EventsService {
|
||||
};
|
||||
}
|
||||
}
|
||||
else if (this.loggeduser.Profile == 'PR') {
|
||||
else if (SessionStore.user.Profile == 'PR') {
|
||||
if (calendarName == 'Pessoal') {
|
||||
options = {
|
||||
headers: this.headersPrPessoal,
|
||||
@@ -1038,7 +1022,7 @@ export class EventsService {
|
||||
params = params.set("SerialNumber", serialNumber);
|
||||
params = params.set("applicationID", applicationID);
|
||||
|
||||
switch (this.loggeduser.Profile) {
|
||||
switch (SessionStore.user.Profile) {
|
||||
case 'MDGPR':
|
||||
if (body.CalendarName == 'Pessoal') {
|
||||
options = {
|
||||
@@ -1109,7 +1093,7 @@ export class EventsService {
|
||||
params = params.set("SerialNumber", serialNumber);
|
||||
params = params.set("applicationID", applicationID);
|
||||
|
||||
switch (this.loggeduser.Profile) {
|
||||
switch (SessionStore.user.Profile) {
|
||||
case 'MDGPR':
|
||||
if (body.CalendarName == 'Pessoal') {
|
||||
options = {
|
||||
|
||||
Reference in New Issue
Block a user