mirror of
https://gitlab.com/openstapps/openstapps.git
synced 2026-01-20 16:42:56 +00:00
feat: calendar plugin
This commit is contained in:
committed by
Rainer Killinger
parent
080e6fa3e8
commit
a57c3029df
@@ -21,8 +21,8 @@ import {
|
||||
OnDestroy,
|
||||
OnInit,
|
||||
} from '@angular/core';
|
||||
import {PopoverController} from '@ionic/angular';
|
||||
import {SCDateSeries, SCUuid} from '@openstapps/core';
|
||||
import {ModalController, PopoverController} from '@ionic/angular';
|
||||
import {SCDateSeries} from '@openstapps/core';
|
||||
import {
|
||||
difference,
|
||||
every,
|
||||
@@ -36,7 +36,14 @@ import {
|
||||
} from 'lodash-es';
|
||||
import {capitalize, last} from 'lodash-es';
|
||||
import {Subscription} from 'rxjs';
|
||||
import {ScheduleProvider} from '../../schedule/schedule.provider';
|
||||
import {
|
||||
DateSeriesRelevantData,
|
||||
ScheduleProvider,
|
||||
toDateSeriesRelevantData,
|
||||
} from '../../calendar/schedule.provider';
|
||||
import {CalendarService} from '../../calendar/calendar.service';
|
||||
import {AddEventReviewModalComponent} from '../../calendar/add-event-review-modal.component';
|
||||
import {ThingTranslatePipe} from '../../../translation/thing-translate.pipe';
|
||||
|
||||
enum Selection {
|
||||
ON = 2,
|
||||
@@ -190,7 +197,7 @@ export class AddEventPopoverComponent implements OnInit, OnDestroy {
|
||||
/**
|
||||
* Uuids
|
||||
*/
|
||||
uuids: SCUuid[];
|
||||
partialDateSeries: DateSeriesRelevantData[];
|
||||
|
||||
/**
|
||||
* Uuid Subscription
|
||||
@@ -201,6 +208,9 @@ export class AddEventPopoverComponent implements OnInit, OnDestroy {
|
||||
readonly ref: ChangeDetectorRef,
|
||||
readonly scheduleProvider: ScheduleProvider,
|
||||
readonly popoverController: PopoverController,
|
||||
readonly calendar: CalendarService,
|
||||
readonly modalController: ModalController,
|
||||
readonly thingTranslatePipe: ThingTranslatePipe,
|
||||
) {}
|
||||
|
||||
/**
|
||||
@@ -214,16 +224,18 @@ export class AddEventPopoverComponent implements OnInit, OnDestroy {
|
||||
* Init
|
||||
*/
|
||||
ngOnInit() {
|
||||
this.uuidSubscription = this.scheduleProvider.uuids$.subscribe(
|
||||
this.uuidSubscription = this.scheduleProvider.partialEvents$.subscribe(
|
||||
async result => {
|
||||
this.uuids = result;
|
||||
this.partialDateSeries = result;
|
||||
|
||||
this.selection = new TreeNode(
|
||||
values(
|
||||
groupBy(
|
||||
sortBy(
|
||||
this.items.map(item => ({
|
||||
selected: this.uuids.includes(item.uid),
|
||||
selected: this.partialDateSeries.some(
|
||||
it => it.uid === item.uid,
|
||||
),
|
||||
item: item,
|
||||
})),
|
||||
it => it.item.repeatFrequency,
|
||||
@@ -237,17 +249,44 @@ export class AddEventPopoverComponent implements OnInit, OnDestroy {
|
||||
);
|
||||
}
|
||||
|
||||
getSelection(): {
|
||||
selected: DateSeriesRelevantData[];
|
||||
unselected: DateSeriesRelevantData[];
|
||||
} {
|
||||
const selection = mapValues(
|
||||
groupBy(flatMap(this.selection.children, 'children'), 'selected'),
|
||||
value => value.map(it => toDateSeriesRelevantData(it.item)),
|
||||
);
|
||||
|
||||
return {selected: selection.true ?? [], unselected: selection.false ?? []};
|
||||
}
|
||||
|
||||
async export() {
|
||||
const modal = await this.modalController.create({
|
||||
component: AddEventReviewModalComponent,
|
||||
swipeToClose: true,
|
||||
cssClass: 'add-modal',
|
||||
componentProps: {
|
||||
dismissAction: () => {
|
||||
modal.dismiss();
|
||||
},
|
||||
dateSeries: this.items,
|
||||
},
|
||||
});
|
||||
|
||||
await modal.present();
|
||||
await modal.onWillDismiss();
|
||||
}
|
||||
|
||||
/**
|
||||
* On selection change
|
||||
*/
|
||||
async onCommit(save: boolean) {
|
||||
if (save) {
|
||||
const {false: unselected, true: selected} = mapValues(
|
||||
groupBy(flatMap(this.selection.children, 'children'), 'selected'),
|
||||
value => value.map(it => it.item.uid),
|
||||
);
|
||||
this.scheduleProvider.uuids$.next(
|
||||
union(difference(this.uuids, unselected), selected),
|
||||
const {selected, unselected} = this.getSelection();
|
||||
console.log(selected, unselected);
|
||||
this.scheduleProvider.partialEvents$.next(
|
||||
union(difference(this.partialDateSeries, unselected), selected),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -75,4 +75,14 @@
|
||||
'ok' | translate
|
||||
}}</ion-button>
|
||||
</div>
|
||||
<div class="download-button">
|
||||
<ion-button
|
||||
fill="clear"
|
||||
(click)="export()"
|
||||
[disabled]="!(selection.indeterminate || selection.checked)"
|
||||
>
|
||||
<ion-icon slot="icon-only" name="download"></ion-icon>
|
||||
<!-- {{ 'export' | translate }} -->
|
||||
</ion-button>
|
||||
</div>
|
||||
</ion-card-content>
|
||||
|
||||
@@ -1,3 +1,18 @@
|
||||
/*!
|
||||
* Copyright (C) 2021 StApps
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the Free
|
||||
* Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
::ng-deep ion-item-divider {
|
||||
cursor: pointer;
|
||||
}
|
||||
@@ -5,3 +20,7 @@
|
||||
.action-buttons {
|
||||
float: right;
|
||||
}
|
||||
|
||||
.download-button {
|
||||
float: left;
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ import {PopoverController} from '@ionic/angular';
|
||||
import {SCDateSeries, SCThing, SCThingType, SCUuid} from '@openstapps/core';
|
||||
import {difference, map} from 'lodash-es';
|
||||
import {Subscription} from 'rxjs';
|
||||
import {ScheduleProvider} from '../../../schedule/schedule.provider';
|
||||
import {ScheduleProvider} from '../../../calendar/schedule.provider';
|
||||
import {AddEventPopoverComponent} from '../add-event-popover.component';
|
||||
import {CoordinatedSearchProvider} from '../../coordinated-search.provider';
|
||||
import {
|
||||
|
||||
Reference in New Issue
Block a user