mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-18 20:47:54 +00:00
list shared calendar from new api
This commit is contained in:
@@ -45,7 +45,7 @@
|
||||
</div>
|
||||
|
||||
|
||||
<div *ngIf="SessionStore.user.RoleID !== 100000014" style="
|
||||
<div *ngIf="SessionStore.user.RoleID !== 100000014 && (sharedCalendar | async) as calendarData" style="
|
||||
padding-bottom: 10px;
|
||||
padding-left: 10px;
|
||||
padding-right: 10px;
|
||||
@@ -53,35 +53,35 @@
|
||||
border-radius: 5px;
|
||||
margin-right: 10px;"
|
||||
class="select-calendar">
|
||||
<mat-form-field class="select-calendar" appearance="none" color="ion-color-secondary" placeholder="Selecione agenda">
|
||||
<mat-select [(value)]="CalendarName" (selectionChange)="reloadCalendar()">
|
||||
|
||||
<mat-option *ngFor="let calendars of eventService.calendarNamesAry" value="{{calendars.Fullname || calendars}}">
|
||||
{{ selectedUserCalendar }}
|
||||
<!-- Debug line to print data -->
|
||||
<mat-form-field class="select-calendar" appearance="none" color="ion-color-secondary" placeholder="Selecione agenda">
|
||||
<mat-select [(value)]="selectedUserCalendar" (selectionChange)="reloadCalendar()" *ngIf="calendarData?.length">
|
||||
|
||||
<mat-option *ngFor="let calendars of calendarData" value="{{calendars.wxUserId}}">
|
||||
|
||||
<div *ngIf="environment.presidential">
|
||||
<div *ngIf="calendars.Role == 'Presidente da República'"> PR </div>
|
||||
<div *ngIf="calendars.Role == 'Ministro e Director do Gabinete do PR'"> MDGPR </div>
|
||||
<div *ngIf="calendars.Role != 'Ministro e Director do Gabinete do PR' && calendars.Role != 'Presidente da República' && calendars.Fullname"> Agenda do {{calendars.Fullname}} </div>
|
||||
<div *ngIf="calendars.Role != 'Presidente da República' && calendars.Role != 'Ministro e Director do Gabinete do PR' && calendars == 'Meu calendario' ">
|
||||
<!-- <span *ngIf="SessionStore.user.Profile == 'PR' ">PR</span>
|
||||
<span *ngIf="SessionStore.user.Profile == 'MDGPR' ">MDGPR</span>
|
||||
<span *ngIf="SessionStore.user.Profile != 'MDGPR' && SessionStore.user.Profile != 'PR' ">Minha agenda</span> -->
|
||||
<div *ngIf="calendars.roleId == RoleIdService.PRES"> PR </div>
|
||||
<div *ngIf="calendars.roleId == RoleIdService.MD"> MDGPR </div>
|
||||
<div *ngIf="calendars.roleId != RoleIdService.MD && calendars.roleId != RoleIdService.PRES && calendars.wxFullName"> Agenda do {{calendars.wxFullName}} </div>
|
||||
<div *ngIf="calendars.roleId != RoleIdService.PRES && calendars.roleId != RoleIdService.MD && calendars.wxUserId == SessionStore.user.UserId ">
|
||||
Minha agenda
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div *ngIf="!environment.presidential">
|
||||
<div *ngIf="calendars != 'Meu calendario' && calendars.Role == 'Presidente da República'"> {{ environment.agendaPR}} </div>
|
||||
<div *ngIf="calendars != 'Meu calendario' && calendars.Role == 'Ministro e Director do Gabinete do PR'"> {{ environment.agendaVP}} </div>
|
||||
<div *ngIf="calendars != 'Meu calendario' && calendars.Role != 'Ministro e Director do Gabinete do PR' && calendars.Role != 'Presidente da República'"> Agenda do {{calendars.Fullname}} </div>
|
||||
<div *ngIf="calendars == 'Meu calendario'">Minha agenda</div>
|
||||
<div *ngIf="calendars.wxUserId != SessionStore.user.UserId && calendars.roleId == RoleIdService.PRES"> {{ environment.agendaPR}} </div>
|
||||
<div *ngIf="calendars.wxUserId != SessionStore.user.UserId && calendars.roleId == RoleIdService.MD"> {{ environment.agendaVP}} </div>
|
||||
<div *ngIf="calendars.wxUserId != SessionStore.user.UserId && calendars.roleId != RoleIdService.MD && calendars.roleId != RoleIdService.PRES"> Agenda do {{calendars.wxFullName}} </div>
|
||||
<div *ngIf="calendars.wxUserId == SessionStore.user.UserId">Minha agenda</div>
|
||||
</div>
|
||||
|
||||
</mat-option>
|
||||
|
||||
<mat-option value="PR+MDGPR" *ngIf="p.userPermission([p.permissionList.Gabinete.md_tasks]) && environment.presidential">
|
||||
<!-- <mat-option value="PR+MDGPR" *ngIf="p.userPermission([p.permissionList.Gabinete.md_tasks]) && environment.presidential">
|
||||
PR+MDGPR
|
||||
</mat-option>
|
||||
</mat-option> -->
|
||||
|
||||
</mat-select>
|
||||
</mat-form-field>
|
||||
@@ -140,6 +140,8 @@
|
||||
</thead>
|
||||
</table>
|
||||
|
||||
|
||||
|
||||
<div class="calendar-conteiner-height overflow-hidden" [style.height]="listBoxService.height">
|
||||
<calendar
|
||||
class="calendar-component"
|
||||
@@ -230,7 +232,7 @@
|
||||
|
||||
<div *ngFor="let day of month.days; let i = index " class="EventListBox-container" >
|
||||
|
||||
<div class="day" *ngIf="!(i == 0 && isSelectedDayHasEvent) || !hasEventToday" >
|
||||
<div class="day" *ngIf="!(i == 0 && isSelectedDayHasEvent)" >
|
||||
|
||||
{{ day.daysInfo.dayName }} <div style="text-transform: capitalize; display: inline;">{{month.monthInfo.monthName}}</div>
|
||||
</div>
|
||||
|
||||
@@ -35,6 +35,9 @@ import { environment } from 'src/environments/environment';
|
||||
import { RoleIdService } from 'src/app/services/role-id.service'
|
||||
import { EventListStore } from 'src/app/models/agenda/AgendaEventList';
|
||||
import { Cy } from 'cypress/enum'
|
||||
import { Observable } from 'rxjs';
|
||||
import { TableSharedCalendar } from 'src/app/services/Repositorys/Agenda/agenda-local-data-source.service';
|
||||
import { map } from 'rxjs/operators';
|
||||
@Component({
|
||||
selector: 'app-agenda',
|
||||
templateUrl: './agenda.page.html',
|
||||
@@ -169,10 +172,12 @@ export class AgendaPage implements OnInit {
|
||||
|
||||
SessionStore = SessionStore;
|
||||
environment = environment
|
||||
CalendarName = ''
|
||||
selectedUserCalendar: number | string = ''
|
||||
hasEventToday = false
|
||||
isSelectedDayHasEvent = true
|
||||
|
||||
sharedCalendar: Observable<TableSharedCalendar[]>
|
||||
|
||||
constructor(
|
||||
@Inject(LOCALE_ID) private locale: string,
|
||||
private modalCtrl: ModalController,
|
||||
@@ -188,15 +193,25 @@ export class AgendaPage implements OnInit {
|
||||
public AgendaDataRepositoryService: AgendaDataRepositoryService,
|
||||
) {
|
||||
|
||||
(async () => {
|
||||
const result = await this.AgendaDataRepositoryService.getSharedCalendar()
|
||||
this.AgendaDataRepositoryService.getSharedCalendar()
|
||||
|
||||
// Define the role priorities
|
||||
const rolePriorities: { [key: number]: number } = {
|
||||
100000014: 1, // Presidente da República
|
||||
100000011: 2, // Vice Presidente (example role ID)
|
||||
// Add other roles with their priorities here
|
||||
};
|
||||
|
||||
this.sharedCalendar = this.AgendaDataRepositoryService.getShareCalendarItemsLive().pipe(
|
||||
map(data => data.sort((a, b) => {
|
||||
console.log('Raw data:', data); // Debug line
|
||||
const priorityA = rolePriorities[a.roleId] || Infinity;
|
||||
const priorityB = rolePriorities[b.roleId] || Infinity;
|
||||
return priorityA - priorityB;
|
||||
}))
|
||||
)
|
||||
|
||||
|
||||
if(result.isOk()) {
|
||||
console.log('111', result)
|
||||
} else {
|
||||
console.log('error')
|
||||
}
|
||||
})()
|
||||
|
||||
this.dateAdapter.setLocale('es');
|
||||
this.locale = 'pt'
|
||||
@@ -254,10 +269,10 @@ export class AgendaPage implements OnInit {
|
||||
|
||||
this.weekToShow()
|
||||
|
||||
this.eventService.registerOnLoadCalendars(()=> {
|
||||
this.eventService.registerOnLoadCalendars(async ()=> {
|
||||
|
||||
this.setCalendarByDefault(true)
|
||||
const selectedCalendarIds = this.getSelectedAgendaCalendars();
|
||||
const selectedCalendarIds = await this.getSelectedAgendaCalendars();
|
||||
this.listToPresent = this.CalendarStore.getEventsByCalendarIds(selectedCalendarIds)
|
||||
|
||||
this.reloadCalendar()
|
||||
@@ -283,9 +298,12 @@ export class AgendaPage implements OnInit {
|
||||
ngOnInit() {
|
||||
|
||||
this.setCalendarByDefault(false)
|
||||
const selectedCalendarIds = this.getSelectedAgendaCalendars();
|
||||
this.getSelectedAgendaCalendars().then((selectedCalendarIds) => {
|
||||
|
||||
this.listToPresent = this.CalendarStore.getEventsByCalendarIds(selectedCalendarIds)
|
||||
|
||||
});
|
||||
|
||||
setTimeout(() => {
|
||||
const pathname = window.location.pathname
|
||||
let realoadCounter = 0
|
||||
@@ -360,20 +378,18 @@ export class AgendaPage implements OnInit {
|
||||
}, 250)
|
||||
}
|
||||
|
||||
setCalendarByDefault(force) {
|
||||
if (!this.CalendarName || force) {
|
||||
const prObject = this.eventService.calendarNamesAry.find(e => e?.RoleId == 100000014)
|
||||
async setCalendarByDefault(force) {
|
||||
if (!this.selectedUserCalendar || force) {
|
||||
const data = await this.AgendaDataRepositoryService.geCalendars()
|
||||
|
||||
const prObject = data.find(e => e?.roleId == 100000014)
|
||||
|
||||
if(prObject) {
|
||||
console.log({prObject})
|
||||
this.CalendarName = prObject.Fullname
|
||||
} else if (this.eventService.calendarNamesAry.includes('Meu calendario')) {
|
||||
this.CalendarName = 'Meu calendario';
|
||||
this.selectedUserCalendar = prObject.wxUserId
|
||||
} else {
|
||||
this.CalendarName = this.eventService.calendarNamesAry[0]
|
||||
this.selectedUserCalendar = SessionStore.user.UserId
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//Go to the next view of the calendar month/week/day
|
||||
@@ -628,10 +644,10 @@ export class AgendaPage implements OnInit {
|
||||
removeDuplicatesByOwnerUserId = (array) => {
|
||||
const seen = new Set();
|
||||
return array.filter(item => {
|
||||
if (seen.has(item.OwnerUserId)) {
|
||||
if (seen.has(item.wxUserId)) {
|
||||
return false;
|
||||
} else {
|
||||
seen.add(item.OwnerUserId);
|
||||
seen.add(item.wxUserId);
|
||||
return true;
|
||||
}
|
||||
});
|
||||
@@ -646,9 +662,16 @@ export class AgendaPage implements OnInit {
|
||||
this.rangeStartDate = startTime
|
||||
this.rangeEndDate = endTime
|
||||
|
||||
|
||||
|
||||
this.showLoader = true;
|
||||
const selectedCalendarIds = this.removeDuplicatesByOwnerUserId(this.getSelectedAgendaCalendars());
|
||||
const selectedCalendarIds = await this.getSelectedAgendaCalendars()
|
||||
|
||||
console.log({selectedCalendarIds})
|
||||
|
||||
this.listToPresent = this.CalendarStore.getEventsByCalendarIds(selectedCalendarIds)
|
||||
|
||||
console.log('listToPresent', this.listToPresent)
|
||||
// this.calendar.currentDate.setDate(1);
|
||||
|
||||
this.updateEventListBox()
|
||||
@@ -663,8 +686,8 @@ export class AgendaPage implements OnInit {
|
||||
for (const selectedCalendar of selectedCalendarIds) {
|
||||
|
||||
const response = await this.AgendaDataRepositoryService.EventList({
|
||||
userId: selectedCalendar.OwnerUserId,
|
||||
calendarOwnerName: selectedCalendar['FullName'],
|
||||
userId: selectedCalendar.wxUserId,
|
||||
calendarOwnerName: selectedCalendar.wxFullName,
|
||||
endDate: endTime.toISOString(),
|
||||
startDate: startTime.toISOString()
|
||||
})
|
||||
@@ -674,16 +697,16 @@ export class AgendaPage implements OnInit {
|
||||
|
||||
if (SessionStore.user.Profile == 'PR') {
|
||||
label = "pr"
|
||||
} else if (selectedCalendar.OwnerUserId == SessionStore.user.UserId as any) {
|
||||
} else if (selectedCalendar.wxUserId == SessionStore.user.UserId as any) {
|
||||
label = 'md'
|
||||
} else {
|
||||
label = "pr"
|
||||
}
|
||||
|
||||
this.CalendarStore.removeRangeForCalendar(startTime, endTime, null , selectedCalendar.OwnerUserId as any)
|
||||
this.CalendarStore.removeRangeForCalendar(startTime, endTime, null , selectedCalendar.wxUserId as any)
|
||||
|
||||
let eventsList = response.value;
|
||||
this.CalendarStore.pushEvent(eventsList, label, selectedCalendar.OwnerUserId);
|
||||
this.CalendarStore.pushEvent(eventsList, label, selectedCalendar.wxUserId);
|
||||
|
||||
this.listToPresent = this.CalendarStore.getEventsByCalendarIds(selectedCalendarIds)
|
||||
|
||||
@@ -716,77 +739,33 @@ export class AgendaPage implements OnInit {
|
||||
|
||||
selectedAgenda = {}
|
||||
|
||||
getSelectedAgendaCalendars(): any {
|
||||
async getSelectedAgendaCalendars() {
|
||||
|
||||
if (this.CalendarName == 'PR+MDGPR') {
|
||||
if (this.selectedUserCalendar == 'PR+MDGPR') {
|
||||
|
||||
const pr = this.SessionStore.user.SharedCalendars.filter(e => e.CalendarRoleId == this.RoleIdService.PRES.toString())
|
||||
const data = await this.AgendaDataRepositoryService.geCalendars()
|
||||
|
||||
const prObject = data.find(e => e?.roleId == 100000014)
|
||||
|
||||
return[{
|
||||
...this.eventService.calendarNamesType['Meu calendario'],
|
||||
OwnerUserId: this.SessionStore.user.UserId
|
||||
wxUserId: this.SessionStore.user.UserId
|
||||
}, {
|
||||
...pr[0]
|
||||
...prObject
|
||||
}]
|
||||
|
||||
} else {
|
||||
|
||||
const calendar = this.eventService.calendarNamesType[this.CalendarName];
|
||||
let Oficial = calendar?.['OficialId']
|
||||
let Pessoal = calendar?.['PessoalId']
|
||||
const data = await this.AgendaDataRepositoryService.geCalendars()
|
||||
|
||||
if (Oficial && Pessoal) {
|
||||
|
||||
return [
|
||||
{
|
||||
OwnerUserId: calendar.OwnerId,
|
||||
CalendarId: Oficial,
|
||||
OwnerId: calendar.OwnerId,
|
||||
CalendarName: calendar.CalendarName,
|
||||
FullName: calendar.FullName
|
||||
},
|
||||
{
|
||||
OwnerUserId: calendar.OwnerId,
|
||||
OwnerId: calendar.OwnerId,
|
||||
CalendarId: Pessoal,
|
||||
CalendarName: calendar.CalendarName,
|
||||
FullName: calendar.FullName
|
||||
}
|
||||
]
|
||||
|
||||
} else if (Oficial) {
|
||||
try {
|
||||
return [{
|
||||
OwnerUserId: calendar.OwnerId,
|
||||
OwnerId: calendar.OwnerId,
|
||||
CalendarId: Oficial,
|
||||
CalendarName: calendar.CalendarName,
|
||||
FullName: calendar.FullName
|
||||
}]
|
||||
} catch (error) {
|
||||
console.log(error)
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
return [{
|
||||
OwnerUserId: calendar.OwnerId,
|
||||
OwnerId: calendar.OwnerId,
|
||||
CalendarId: Pessoal,
|
||||
CalendarName: calendar.CalendarName,
|
||||
FullName: calendar.FullName
|
||||
}]
|
||||
} catch (error) {
|
||||
console.log(error)
|
||||
}
|
||||
return [data.find(e => e?.wxUserId == this.selectedUserCalendar)]
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
async updateEventListBox() {
|
||||
|
||||
updateEventListBox() {
|
||||
|
||||
const selectedCalendarIds = this.removeDuplicatesByOwnerUserId(this.getSelectedAgendaCalendars());
|
||||
const selectedCalendarIds = await this.getSelectedAgendaCalendars()
|
||||
this.listToPresent = this.CalendarStore.getEventsByCalendarIds(selectedCalendarIds)
|
||||
|
||||
const year = this.listBoxService.list(this.listToPresent, 'md', this.rangeStartDate, this.rangeEndDate, { segment: this.segment, selectedDate: this.eventSelectedDate })
|
||||
|
||||
@@ -177,7 +177,7 @@ export class AgendaDataRepositoryService {
|
||||
if(result.isOk()) {
|
||||
await this.agendaLocalDataSourceService.clearSharedCalendar()
|
||||
if(result.value?.data) {
|
||||
return await this.agendaLocalDataSourceService.create(result.value.data)
|
||||
return await this.agendaLocalDataSourceService.bulkCreate(result.value.data)
|
||||
} else {
|
||||
return result
|
||||
}
|
||||
@@ -186,4 +186,12 @@ export class AgendaDataRepositoryService {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
getShareCalendarItemsLive() {
|
||||
return this.agendaLocalDataSourceService.getShareCalendarItemsLive()
|
||||
}
|
||||
|
||||
async geCalendars() {
|
||||
return await this.agendaLocalDataSourceService.geCalendars()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import { Dexie, EntityTable, liveQuery } from 'Dexie';
|
||||
import { SharedCalendarListItemOutputDTO, SharedCalendarListOutputDTO } from './model/sharedCalendarOutputDTO';
|
||||
import { any, z } from 'zod';
|
||||
import { err, ok } from 'neverthrow';
|
||||
import { from } from 'rxjs';
|
||||
|
||||
|
||||
const tableScharedCalendar = z.object({
|
||||
@@ -34,17 +35,16 @@ export class AgendaLocalDataSourceService {
|
||||
|
||||
constructor() { }
|
||||
|
||||
async create(data: SharedCalendarListItemOutputDTO[]) {
|
||||
async bulkCreate(data: SharedCalendarListItemOutputDTO[]) {
|
||||
// db.eve
|
||||
try {
|
||||
const result = AgendaDataSource.shareCalendar.bulkAdd(data)
|
||||
const result = await AgendaDataSource.shareCalendar.bulkAdd(data)
|
||||
return ok(result)
|
||||
} catch (e) {
|
||||
return err(false)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
clearSharedCalendar() {
|
||||
// db.eve
|
||||
try {
|
||||
@@ -53,6 +53,15 @@ export class AgendaLocalDataSourceService {
|
||||
} catch (e) {
|
||||
return err(false)
|
||||
}
|
||||
}
|
||||
|
||||
async geCalendars() {
|
||||
return await AgendaDataSource.shareCalendar.toArray()
|
||||
}
|
||||
|
||||
getShareCalendarItemsLive() {
|
||||
return from(liveQuery( () => {
|
||||
return AgendaDataSource.shareCalendar.toArray()
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -75,6 +75,7 @@ export class ListBoxService {
|
||||
// daysObject[day] = object[day]
|
||||
// }
|
||||
|
||||
console.log('newStracture', newStracture)
|
||||
|
||||
return this.display(newStracture, selectedDate).year
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@ export class RoleIdService {
|
||||
* @description President role id
|
||||
*/
|
||||
PV: number = 100000011
|
||||
MD: number = 100000011
|
||||
/**
|
||||
* @description Vice president role id
|
||||
*/
|
||||
|
||||
@@ -109,11 +109,11 @@ export class CalendarService {
|
||||
}, 10)
|
||||
}
|
||||
|
||||
getEventsByCalendarIds(ids:Object[]): EventListStore[] {
|
||||
getEventsByCalendarIds(ids:any[]): EventListStore[] {
|
||||
|
||||
let result = [];
|
||||
for (const calendar of ids) {
|
||||
const events = this._eventSource.filter(e => e.CalendarId == calendar['OwnerUserId'])
|
||||
const events = this._eventSource.filter(e => e.CalendarId == calendar.wxUserId )
|
||||
result = result.concat(events)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user