Files
doneit-web/src/app/services/Repositorys/Agenda/utils.ts
T

203 lines
4.8 KiB
TypeScript
Raw Normal View History

2024-05-29 15:43:37 +01:00
import { Injectable } from '@angular/core';
import { AgendaDataService } from './agenda-data.service';
import { EventsService } from '../../events.service';
@Injectable({
2024-06-07 14:10:17 +01:00
providedIn: 'root'
2024-05-29 15:43:37 +01:00
})
export class Utils {
2024-06-07 14:10:17 +01:00
constructor(
private agendaDataService: AgendaDataService,
public eventService: EventsService,
) { }
2024-05-29 15:43:37 +01:00
2024-06-07 14:10:17 +01:00
selectedCalendarUserId(CalendarName, postEvent) {
2024-05-29 15:43:37 +01:00
if (this.eventService.calendarNamesType[CalendarName]?.['Oficial'] && postEvent.CalendarName == 'Oficial') {
return this.eventService.calendarNamesType[CalendarName]['OwnerId']
} else if (this.eventService.calendarNamesType[CalendarName]?.['Pessoal'] && postEvent.CalendarName == 'Pessoal') {
return this.eventService.calendarNamesType[CalendarName]['OwnerId']
} else {
return '11:11'
}
}
2024-06-21 23:33:29 +01:00
selectedCalendarOwner(roleDescription) {
console.log('roleDescription', roleDescription)
if (roleDescription) {
if (roleDescription == "Presidente da República") {
2024-05-29 15:43:37 +01:00
return 1;
2024-06-21 23:33:29 +01:00
} else if (roleDescription == "Ministro e Director do Gabinete do PR") {
2024-05-29 15:43:37 +01:00
return 2
} else {
return 3
}
}
}
2024-06-08 00:47:52 +01:00
findRoleIdByUserId(array, userId) {
for (let item of array) {
console.log('each item before',item)
if (typeof item === 'object' && item !== null && item.OwnerUserId === parseInt(userId)) {
console.log('each item after',item)
return item.Role;
} else {
return 'other';
}
}
2024-06-21 23:33:29 +01:00
2024-06-08 00:47:52 +01:00
}
2024-05-29 15:43:37 +01:00
calendarCategorySeleted(calendarName) {
var selectedCalendar = {
'Oficial': 1,
'Pessoal': 2
}
2024-06-21 23:33:29 +01:00
if(calendarName != 'Pessoal' && calendarName != 'Oficial') {
throw('bad logic')
}
2024-05-29 15:43:37 +01:00
return selectedCalendar[calendarName];
}
calendarTypeSeleted(calendarName) {
var selectedType = {
2024-06-04 11:56:56 +01:00
'Meeting': 1,
'Travel': 2,
'Conference': 3,
2024-05-29 15:43:37 +01:00
'Encontro': 1
}
return selectedType[calendarName];
}
2024-06-07 14:10:17 +01:00
documentAdded(documents: any[]) {
console.log('added doc create event', documents)
2024-06-04 13:18:00 +01:00
let listupdate = []
documents.forEach(element => {
let object = {
2024-06-18 11:39:17 +01:00
docId: element.docId || element.DocId,
sourceName: element.subject || element.sourceNames || element.Description,
2024-06-04 13:18:00 +01:00
description: "",
2024-06-18 11:39:17 +01:00
applicationId: element.applicationId || element.ApplicationId
2024-06-04 13:18:00 +01:00
}
2024-06-07 14:10:17 +01:00
2024-06-04 13:18:00 +01:00
listupdate.push(object)
});
return listupdate
2024-06-07 14:10:17 +01:00
/* return documents.map((e) => {
return {
docId: e.docId,
sourceName: e.subject || e.sourceNames,
description: "",
applicationId: e.applicationId
};
}); */
2024-05-29 15:43:37 +01:00
}
2024-06-02 13:53:46 +01:00
editDocumentAdded(documents: any[]) {
console.log('document added', documents)
return documents.map((element) => {
return {
docId: parseInt(element.SourceId),
sourceName: element.SourceName,
description: "",
applicationId: parseInt(element.ApplicationId)
};
});
}
2024-05-29 15:43:37 +01:00
atendeesSeletedType(type) {
var selectedType = {
2024-06-13 16:02:09 +01:00
'true': 1,
'false': 2,
'other': 3,
2024-05-29 15:43:37 +01:00
}
return selectedType[type];
}
attendeesAdded(taskParticipants: any[]) {
return taskParticipants.map((e) => {
return {
name: e.Name,
emailAddress: e.EmailAddress,
attendeeType: this.atendeesSeletedType(JSON.stringify(e.IsRequired)),
2024-06-07 14:10:17 +01:00
wxUserId: e.Id,
2024-05-29 15:43:37 +01:00
}
});
}
2024-05-31 12:50:25 +01:00
statusEventAproval(type) {
var selectedType = {
2024-06-13 16:02:09 +01:00
'Pending': 1,
'Revision': 2,
'Approved': 3,
"Declined": 4,
"Communicated": 5
2024-05-31 12:50:25 +01:00
}
return selectedType[type];
}
2024-06-02 13:53:46 +01:00
attendeesEdit(taskParticipants: any[]) {
return taskParticipants.map((e) => {
return {
name: e.Name,
emailAddress: e.EmailAddress,
attendeeType: this.atendeesSeletedType(JSON.stringify(e.IsRequired)),
wxUserId: e.wxUserId || e.Id,
}
});
}
2024-06-07 14:10:17 +01:00
eventRecurence(type) {
var selectedType = {
2024-06-14 09:18:56 +01:00
'never': 0,
'daily': 1,
'weekly': 2,
"monthly": 3,
"yearly": 4
2024-06-07 14:10:17 +01:00
}
return selectedType[type];
}
2024-06-10 09:55:23 +01:00
recurenceTypeSeleted(recurenceType) {
var selectedType = {
0: 'never',
1: 'daily',
2: 'weekly',
3: 'monthly',
4: 'yearly'
}
return selectedType[recurenceType];
}
2024-06-11 11:23:38 +01:00
addOneHourToIsoString(isoDateString) {
let date = new Date(isoDateString);
2024-06-21 23:33:29 +01:00
2024-06-11 16:23:09 +01:00
const tzOffset = -date.getTimezoneOffset(); // in minutes
const diff = tzOffset >= 0 ? '+' : '-';
const pad = (n: number) => (n < 10 ? '0' : '') + n;
2024-06-21 23:33:29 +01:00
2024-06-11 16:23:09 +01:00
return date.getFullYear() +
'-' + pad(date.getMonth() + 1) +
'-' + pad(date.getDate()) +
'T' + pad(date.getHours()) +
':' + pad(date.getMinutes()) +
':' + pad(date.getSeconds()) +
diff + pad(Math.floor(Math.abs(tzOffset) / 60)) +
':' + pad(Math.abs(tzOffset) % 60);
2024-06-11 11:23:38 +01:00
}
2024-05-29 15:43:37 +01:00
}