mirror of
https://gitlab.com/openstapps/openstapps.git
synced 2026-01-03 12:02:53 +00:00
fix: calculating SCDateSeries for next unit view
This commit is contained in:
@@ -62,12 +62,12 @@ export class DashboardComponent implements OnInit, OnDestroy {
|
||||
/**
|
||||
* UUID subscription
|
||||
*/
|
||||
private _uuidSubscription: Subscription;
|
||||
private _eventUuidSubscription: Subscription;
|
||||
|
||||
/**
|
||||
* The events to display
|
||||
*/
|
||||
private uuids: SCUuid[];
|
||||
private eventUuids: SCUuid[];
|
||||
|
||||
/**
|
||||
* Next event in calendar
|
||||
@@ -103,9 +103,9 @@ export class DashboardComponent implements OnInit, OnDestroy {
|
||||
}
|
||||
|
||||
async ngOnInit() {
|
||||
this._uuidSubscription = this.scheduleProvider.uuids$.subscribe(
|
||||
this._eventUuidSubscription = this.scheduleProvider.uuids$.subscribe(
|
||||
async result => {
|
||||
this.uuids = result;
|
||||
this.eventUuids = result;
|
||||
await this.loadNextEvent();
|
||||
},
|
||||
);
|
||||
@@ -131,13 +131,23 @@ export class DashboardComponent implements OnInit, OnDestroy {
|
||||
|
||||
async loadNextEvent() {
|
||||
const dataSeries = await this.scheduleProvider.getDateSeries(
|
||||
this.uuids,
|
||||
['P1W', 'P2W', 'P3W', 'P4W'],
|
||||
this.eventUuids,
|
||||
undefined,
|
||||
moment(moment.now()).startOf('week').toISOString(),
|
||||
);
|
||||
|
||||
this.nextEvent =
|
||||
(dataSeries && dataSeries.dates && dataSeries.dates[0]) || undefined;
|
||||
this.nextEvent = dataSeries.dates
|
||||
.map(series => ({
|
||||
time: new Date(
|
||||
series.dates
|
||||
.sort((a, b) => new Date(a).getTime() - new Date(b).getTime())
|
||||
.find(date => new Date(date) > new Date()) ||
|
||||
Number.POSITIVE_INFINITY,
|
||||
).getTime(),
|
||||
series,
|
||||
}))
|
||||
.sort(({time: a}, {time: b}) => a - b)
|
||||
.find(({time}) => !!time)?.series;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -147,7 +157,7 @@ export class DashboardComponent implements OnInit, OnDestroy {
|
||||
for (const sub of this.subscriptions) {
|
||||
sub.unsubscribe();
|
||||
}
|
||||
this._uuidSubscription.unsubscribe();
|
||||
this._eventUuidSubscription.unsubscribe();
|
||||
this.collapseAnimation.destroy();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user