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);
|
||||
|
||||
@@ -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/>.
|
||||
*/
|
||||
import {SCSearchRequest, SCSearchResponse} from '@openstapps/core';
|
||||
import {Injectable} from '@angular/core';
|
||||
@@ -29,7 +29,6 @@ async function delay(ms: number): Promise<void> {
|
||||
* ['a', 'b', 'c'] => {0: 'a', 1: 'b', 2: 'c'}
|
||||
*/
|
||||
export function arrayToIndexMap<T>(array: T[]): Record<number, T> {
|
||||
// eslint-disable-next-line unicorn/no-array-reduce
|
||||
return array.reduce((previous, current, index) => {
|
||||
previous[index] = current;
|
||||
return previous;
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
/*
|
||||
* Copyright (C) 2018-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/>.
|
||||
*/
|
||||
import {Injectable} from '@angular/core';
|
||||
import {Client} from '@openstapps/api/lib/client';
|
||||
@@ -31,10 +31,10 @@ import {
|
||||
SCFeedbackRequest,
|
||||
SCFeedbackResponse,
|
||||
} from '@openstapps/core';
|
||||
import {chunk, fromPairs, toPairs} from 'lodash-es';
|
||||
import {environment} from '../../../environments/environment';
|
||||
import {StorageProvider} from '../storage/storage.provider';
|
||||
import {StAppsWebHttpClient} from './stapps-web-http-client.provider';
|
||||
import {chunk} from '../../_helpers/collections/chunk';
|
||||
|
||||
export enum DataScope {
|
||||
Local = 'local',
|
||||
@@ -275,8 +275,8 @@ export class DataProvider {
|
||||
return Object.assign(
|
||||
{},
|
||||
...(await Promise.all(
|
||||
chunk(toPairs(query), this.backendQueriesLimit).map(request =>
|
||||
this.client.multiSearch(fromPairs(request)),
|
||||
chunk(Object.entries(query), this.backendQueriesLimit).map(request =>
|
||||
this.client.multiSearch(Object.fromEntries(request)),
|
||||
),
|
||||
)),
|
||||
);
|
||||
|
||||
@@ -1,23 +1,22 @@
|
||||
/*
|
||||
* Copyright (C) 2019 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/>.
|
||||
*/
|
||||
|
||||
import moment, {Moment} from 'moment';
|
||||
|
||||
import {AfterViewInit, Component, Input, OnDestroy} from '@angular/core';
|
||||
import {SCDish, SCISO8601Date, SCPlace} from '@openstapps/core';
|
||||
import {keys} from 'lodash-es';
|
||||
import {PlaceMensaService} from './place-mensa-service';
|
||||
import {DataRoutingService} from '../../../../data-routing.service';
|
||||
import {Router} from '@angular/router';
|
||||
@@ -83,7 +82,7 @@ export class PlaceMensaDetailComponent implements AfterViewInit, OnDestroy {
|
||||
delete result[key];
|
||||
}
|
||||
}
|
||||
this.selectedDay = keys(result)[0];
|
||||
this.selectedDay = Object.keys(result)[0];
|
||||
});
|
||||
this.subscriptions.push(
|
||||
this.dataRoutingService.itemSelectListener().subscribe(item => {
|
||||
|
||||
@@ -1,29 +1,29 @@
|
||||
/*
|
||||
* Copyright (C) 2019 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/>.
|
||||
*/
|
||||
|
||||
import {Injectable} from '@angular/core';
|
||||
import {
|
||||
SCDish,
|
||||
SCISO8601Date,
|
||||
SCMultiSearchRequest,
|
||||
SCPlace,
|
||||
SCSearchQuery,
|
||||
SCThingType,
|
||||
} from '@openstapps/core';
|
||||
import {keyBy, mapValues, range} from 'lodash-es';
|
||||
import moment from 'moment';
|
||||
import {DataProvider} from '../../../../data.provider';
|
||||
import {mapValues} from '../../../../../../_helpers/collections/map-values';
|
||||
|
||||
/**
|
||||
* TODO
|
||||
@@ -43,9 +43,18 @@ export class PlaceMensaService {
|
||||
place: SCPlace,
|
||||
days: number,
|
||||
): Promise<Record<SCISO8601Date, SCDish[]>> {
|
||||
const request: SCMultiSearchRequest = mapValues(
|
||||
keyBy(range(days).map(i => moment().add(i, 'days').toISOString())),
|
||||
(date: SCISO8601Date) => ({
|
||||
const request = mapValues<
|
||||
Record<SCISO8601Date, SCISO8601Date>,
|
||||
SCSearchQuery
|
||||
>(
|
||||
Array.from({length: days})
|
||||
.map((_, i) => i)
|
||||
.map(i => moment().add(i, 'days').toISOString())
|
||||
.reduce((accumulator, item) => {
|
||||
accumulator[item] = item;
|
||||
return accumulator;
|
||||
}, {} as Record<SCISO8601Date, SCISO8601Date>),
|
||||
date => ({
|
||||
filter: {
|
||||
arguments: {
|
||||
filters: [
|
||||
@@ -82,7 +91,7 @@ export class PlaceMensaService {
|
||||
|
||||
return mapValues(
|
||||
await this.dataProvider.multiSearch(request),
|
||||
'data',
|
||||
it => it.data,
|
||||
) as Record<SCISO8601Date, SCDish[]>;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user