mirror of
https://gitlab.com/openstapps/openstapps.git
synced 2026-01-20 16:42:56 +00:00
refactor: remove lodash
This commit is contained in:
@@ -1,16 +1,16 @@
|
||||
/*
|
||||
* 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.
|
||||
* Copyright (C) 2022 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.
|
||||
* 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/>.
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||
@@ -23,18 +23,6 @@ import {
|
||||
} from '@angular/core';
|
||||
import {ModalController, PopoverController} from '@ionic/angular';
|
||||
import {SCDateSeries} from '@openstapps/core';
|
||||
import {
|
||||
difference,
|
||||
every,
|
||||
flatMap,
|
||||
groupBy,
|
||||
mapValues,
|
||||
some,
|
||||
sortBy,
|
||||
union,
|
||||
values,
|
||||
} from 'lodash-es';
|
||||
import {capitalize, last} from 'lodash-es';
|
||||
import {Subscription} from 'rxjs';
|
||||
import {
|
||||
DateSeriesRelevantData,
|
||||
@@ -44,6 +32,9 @@ import {
|
||||
import {CalendarService} from '../../calendar/calendar.service';
|
||||
import {AddEventReviewModalComponent} from '../../calendar/add-event-review-modal.component';
|
||||
import {ThingTranslatePipe} from '../../../translation/thing-translate.pipe';
|
||||
import {groupBy, groupByProperty} from '../../../_helpers/collections/group-by';
|
||||
import {mapValues} from '../../../_helpers/collections/map-values';
|
||||
import {stringSortBy} from '../../../_helpers/collections/string-sort';
|
||||
|
||||
enum Selection {
|
||||
ON = 2,
|
||||
@@ -93,10 +84,10 @@ class TreeNode<T extends TreeNode<any> | SelectionValue> {
|
||||
: Selection.OFF,
|
||||
);
|
||||
|
||||
this.checked = every(selections, it => it === Selection.ON);
|
||||
this.checked = selections.every(it => it === Selection.ON);
|
||||
this.indeterminate = this.checked
|
||||
? false
|
||||
: some(selections, it => it > Selection.OFF);
|
||||
: selections.some(it => it > Selection.OFF);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -174,21 +165,11 @@ interface SelectionValue {
|
||||
styleUrls: ['add-event-popover.scss'],
|
||||
})
|
||||
export class AddEventPopoverComponent implements OnInit, OnDestroy {
|
||||
/**
|
||||
* Lodash alias
|
||||
*/
|
||||
capitalize: (item: string) => string = capitalize;
|
||||
|
||||
/**
|
||||
* The item the action belongs to
|
||||
*/
|
||||
@Input() items: SCDateSeries[];
|
||||
|
||||
/**
|
||||
* Lodash alias
|
||||
*/
|
||||
last: <T>(item: T[] | null | undefined) => T | undefined = last;
|
||||
|
||||
/**
|
||||
* Selection of the item
|
||||
*/
|
||||
@@ -229,17 +210,16 @@ export class AddEventPopoverComponent implements OnInit, OnDestroy {
|
||||
this.partialDateSeries = result;
|
||||
|
||||
this.selection = new TreeNode(
|
||||
values(
|
||||
Object.values(
|
||||
groupBy(
|
||||
sortBy(
|
||||
this.items.map(item => ({
|
||||
this.items
|
||||
.map(item => ({
|
||||
selected: this.partialDateSeries.some(
|
||||
it => it.uid === item.uid,
|
||||
),
|
||||
item: item,
|
||||
})),
|
||||
it => it.item.repeatFrequency,
|
||||
),
|
||||
}))
|
||||
.sort(stringSortBy(it => it.item.repeatFrequency)),
|
||||
it => it.item.repeatFrequency,
|
||||
),
|
||||
).map(item => new TreeNode(item, this.ref)),
|
||||
@@ -254,7 +234,10 @@ export class AddEventPopoverComponent implements OnInit, OnDestroy {
|
||||
unselected: DateSeriesRelevantData[];
|
||||
} {
|
||||
const selection = mapValues(
|
||||
groupBy(flatMap(this.selection.children, 'children'), 'selected'),
|
||||
groupByProperty(
|
||||
this.selection.children.flatMap(it => it.children),
|
||||
'selected',
|
||||
),
|
||||
value => value.map(it => toDateSeriesRelevantData(it.item)),
|
||||
);
|
||||
|
||||
@@ -285,9 +268,12 @@ export class AddEventPopoverComponent implements OnInit, OnDestroy {
|
||||
if (save) {
|
||||
const {selected, unselected} = this.getSelection();
|
||||
console.log(selected, unselected);
|
||||
this.scheduleProvider.partialEvents$.next(
|
||||
union(difference(this.partialDateSeries, unselected), selected),
|
||||
);
|
||||
this.scheduleProvider.partialEvents$.next([
|
||||
...new Set([
|
||||
...this.partialDateSeries.filter(it => !unselected.includes(it)),
|
||||
...selected,
|
||||
]),
|
||||
]);
|
||||
}
|
||||
|
||||
await this.popoverController.dismiss();
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
<!--
|
||||
~ 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.
|
||||
~ Copyright (C) 2022 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.
|
||||
~ 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/>.
|
||||
~ You should have received a copy of the GNU General Public License along with
|
||||
~ this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
-->
|
||||
|
||||
<ion-card-content>
|
||||
@@ -54,13 +54,16 @@
|
||||
{{ 'data.chips.add_events.popover.AT' | translate }}
|
||||
{{ date.item.dates[0] | amDateFormat: 'HH:mm ddd' }}
|
||||
{{ 'data.chips.add_events.popover.UNTIL' | translate }}
|
||||
{{ last(date.item.dates) | amDateFormat: 'll' }}
|
||||
{{ date.item.dates[date.item.dates.length - 1] | amDateFormat: 'll' }}
|
||||
</ion-label>
|
||||
<ng-template #single_event>
|
||||
<ion-label class="ion-text-wrap">
|
||||
{{ date.item.duration | amDuration: 'hours' }}
|
||||
{{ 'data.chips.add_events.popover.AT' | translate }}
|
||||
{{ last(date.item.dates) | amDateFormat: 'll, HH:mm' }}
|
||||
{{
|
||||
date.item.dates[date.item.dates.length - 1]
|
||||
| amDateFormat: 'll, HH:mm'
|
||||
}}
|
||||
</ion-label>
|
||||
</ng-template>
|
||||
<ion-checkbox slot="start" [checked]="date.selected"> </ion-checkbox>
|
||||
|
||||
@@ -1,22 +1,22 @@
|
||||
/* tslint:disable:prefer-function-over-method */
|
||||
/*
|
||||
* 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.
|
||||
* Copyright (C) 2022 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.
|
||||
* 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/>.
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/* tslint:disable:prefer-function-over-method */
|
||||
import {Component, Input, OnDestroy} from '@angular/core';
|
||||
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 '../../../calendar/schedule.provider';
|
||||
import {AddEventPopoverComponent} from '../add-event-popover.component';
|
||||
@@ -180,7 +180,9 @@ export class AddEventActionChipComponent implements OnDestroy {
|
||||
return;
|
||||
}
|
||||
switch (
|
||||
difference(map(associatedDateSeries, 'uid'), this.uuids).length
|
||||
associatedDateSeries
|
||||
.map(it => it.uid)
|
||||
.filter(it => !this.uuids.includes(it)).length
|
||||
) {
|
||||
case 0:
|
||||
this.applyState(AddEventStates.ADDED_ALL);
|
||||
|
||||
Reference in New Issue
Block a user