refactor: remove lodash

This commit is contained in:
Thea Schöbl
2022-04-12 09:59:55 +00:00
parent fd7f664792
commit 72e5fcca77
58 changed files with 1294 additions and 356 deletions

View File

@@ -1,19 +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.
* 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 {Component, OnInit} from '@angular/core';
import {map} from 'lodash-es';
import {ModalController} from '@ionic/angular';
import {AboutLicenseModalComponent} from './about-license-modal.component';
import licensesFile from 'src/assets/about/licenses.json';
@@ -59,9 +58,7 @@ export class AboutLicensesComponent implements OnInit {
}
loadLicenses(): License[] {
return map(
// eslint-disable-next-line @typescript-eslint/ban-types
licensesFile as Record<string, object>,
return Object.values(licensesFile as Record<string, object>).map(
(value, key) =>
({
name: key,

View File

@@ -6,7 +6,7 @@
*
* 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 Licens for
* 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
@@ -14,7 +14,6 @@
*/
import {Component, ViewChild} from '@angular/core';
import {flatMap} from 'lodash-es';
import {ActivatedRoute} from '@angular/router';
import {AssessmentsProvider} from '../assessments.provider';
import {
@@ -48,14 +47,16 @@ export class AssessmentsDetailComponent implements ViewWillEnter {
event.resolve(
assessment
? assessment
: flatMap(assessments, it =>
Array.isArray(it.superAssessments)
? it.superAssessments.map(superAssessment => ({
...superAssessment,
origin: it.origin,
}))
: [],
).find(it => it?.uid === event.uid),
: assessments
.flatMap(it =>
Array.isArray(it.superAssessments)
? it.superAssessments.map(superAssessment => ({
...superAssessment,
origin: it.origin,
}))
: [],
)
.find(it => it?.uid === event.uid),
);
});
}

View File

@@ -6,7 +6,7 @@
*
* 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 Licens for
* 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
@@ -22,7 +22,6 @@ import {
} from '@angular/core';
import {AssessmentsProvider} from '../assessments.provider';
import {SCAssessment, SCCourseOfStudy} from '@openstapps/core';
import {groupBy, mapValues} from 'lodash-es';
import {ActivatedRoute, Router} from '@angular/router';
import {Subscription} from 'rxjs';
import {NGXLogger} from 'ngx-logger';
@@ -30,6 +29,8 @@ import {materialSharedAxisX} from '../../../animation/material-motion';
import {SharedAxisChoreographer} from '../../../animation/animation-choreographer';
import {DataProvider, DataScope} from '../../data/data.provider';
import {DataRoutingService} from '../../data/data-routing.service';
import {groupBy} from '../../../_helpers/collections/group-by';
import {mapValues} from '../../../_helpers/collections/map-values';
@Component({
selector: 'app-assessments-page',

View File

@@ -6,7 +6,7 @@
*
* 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 Licens for
* 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
@@ -15,7 +15,7 @@
import {Component, Input} from '@angular/core';
import {SCAssessment, SCCourseOfStudyWithoutReferences} from '@openstapps/core';
import {sum, sumBy} from 'lodash-es';
import {sum, sumBy} from '../../../../_helpers/collections/sum';
@Component({
selector: 'course-of-study-assessment',
@@ -40,6 +40,6 @@ export class CourseOfStudyAssessmentComponent {
.map(assessment => Number(assessment.grade))
.filter(grade => !Number.isNaN(grade));
this.grade = grades.length > 0 ? sum(grades) / grades.length : 0;
this.ects = sumBy(this._assessments, 'ects');
this.ects = sumBy(this._assessments, it => it.ects);
}
}

View File

@@ -1,12 +1,12 @@
/*
* Copyright (C) 2021 StApps
* 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 Licens for
* 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
@@ -27,7 +27,6 @@ import {DateFormatPipe, DurationPipe} from 'ngx-moment';
import {BackgroundFetch} from '@transistorsoft/capacitor-background-fetch';
import {StorageProvider} from '../../storage/storage.provider';
import {CalendarService} from '../../calendar/calendar.service';
import {flatMap} from 'lodash-es';
import {toICal} from '../../calendar/ical/ical';
import {Subscription} from 'rxjs';
import {ChangesOf} from './changes';
@@ -173,7 +172,7 @@ export class ScheduleSyncService implements OnDestroy {
const dateSeries = (await this.scheduleProvider.getDateSeries(this.uuids))
.dates;
const events = flatMap(dateSeries, event =>
const events = dateSeries.flatMap(event =>
toICal(event, this.translator.translator, {
allowRRuleExceptions: false,
excludeCancelledEvents: true,

View File

@@ -1,12 +1,12 @@
/*
* Copyright (C) 2021 StApps
* 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 Licens for
* 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
@@ -15,8 +15,8 @@
import {findRRules, RRule} from './ical';
import moment, {unitOfTime} from 'moment';
import {shuffle} from 'lodash-es';
import {SCISO8601Date} from '@openstapps/core';
import {shuffle} from '../../../_helpers/collections/shuffle';
/**
*

View File

@@ -1,12 +1,12 @@
/*
* Copyright (C) 2021 StApps
* 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 Licens for
* 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
@@ -20,16 +20,9 @@ import {
SCThingWithCategories,
SCUuid,
} from '@openstapps/core';
import {
difference,
flatMap,
isObject,
last,
mapValues,
minBy,
size,
} from 'lodash-es';
import moment, {unitOfTime} from 'moment';
import {minBy} from '../../../_helpers/collections/min';
import {mapValues} from '../../../_helpers/collections/map-values';
export interface ICalEvent {
name?: string;
@@ -126,7 +119,7 @@ export function findRRules(
for (let i = 0; i < sorted.length; i++) {
const current = sorted[i];
const next = sorted[i + 1] as SCISO8601Date | undefined;
const element = last(output);
const element = output[output.length - 1];
const units: unitOfTime.Diff[] = element?.freq
? [element.freq]
@@ -208,8 +201,9 @@ export function toICal(
options: ToICalOptions = {},
): ICalEvent[] {
const rrules = findRRules(
options.excludeCancelledEvents
? difference(dateSeries.dates, dateSeries.exceptions ?? [])
options.excludeCancelledEvents && dateSeries.exceptions
? // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
dateSeries.dates.filter(it => !dateSeries.exceptions!.includes(it))
: dateSeries.dates,
);
@@ -276,8 +270,9 @@ function stringifyLinebreaks<T extends string | unknown[] | unknown>(
if (Array.isArray(value)) {
return value.map(stringifyLinebreaks) as T;
}
if (isObject(value)) {
return mapValues(value, stringifyLinebreaks) as T;
// noinspection SuspiciousTypeOfGuard
if (value instanceof Object) {
return mapValues<object, unknown>(value, stringifyLinebreaks) as T;
}
return value;
}
@@ -348,7 +343,7 @@ export function serializeICalEvent(iCal: ICalEvent): ICalLike {
`STATUS:${normalized.cancelled === true ? 'CANCELLED' : 'CONFIRMED'}`,
`URL:${normalized.url}`,
// `RDATE;VALUE=DATE:${normalized.dates.join(',')}`,
size(normalized.exceptionDates) > 0
(normalized.exceptionDates?.length ?? 0) > 0
? `EXDATE;VALUE=DATE:${normalized.exceptionDates?.join(',')}`
: undefined,
`RRULE:${serializeRRule(normalized.rrule)}`,
@@ -372,7 +367,7 @@ export function serializeICal(iCal: ICalEvent[]): string {
'CALSCALE:GREGORIAN',
'COLOR:#FF0000',
'METHOD:PUBLISH',
...flatMap(iCal, serializeICalEvent),
...iCal.flatMap(serializeICalEvent),
'END:VCALENDAR',
]);
}
@@ -384,7 +379,7 @@ export function getNativeCalendarExport(
dateSeries: SCDateSeries[],
translator: SCThingTranslator,
): ICalEvent[] {
return flatMap(dateSeries, event =>
return dateSeries.flatMap(event =>
toICal(event, translator, {
allowRRuleExceptions: false,
excludeCancelledEvents: true,
@@ -401,14 +396,14 @@ export function getICalExport(
includeCancelled: boolean,
): ICalEvent[] {
return [
...flatMap(dateSeries, event =>
...dateSeries.flatMap(event =>
toICal(event, translator, {
allowRRuleExceptions: false,
excludeCancelledEvents: !includeCancelled,
}),
),
...(includeCancelled
? flatMap(dateSeries, event => toICalUpdates(event, translator))
? dateSeries.flatMap(event => toICalUpdates(event, translator))
: []),
];
}

View File

@@ -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 unicorn/no-null */
@@ -27,8 +27,8 @@ import {
import {BehaviorSubject, Observable, Subscription} from 'rxjs';
import {DataProvider} from '../data/data.provider';
import {map} from 'rxjs/operators';
import {pick} from 'lodash-es';
import {DateFormatPipe, DurationPipe} from 'ngx-moment';
import {pick} from '../../_helpers/collections/pick';
/**
*
@@ -36,7 +36,7 @@ import {DateFormatPipe, DurationPipe} from 'ngx-moment';
export function toDateSeriesRelevantData(
dateSeries: SCDateSeries,
): DateSeriesRelevantData {
return pick(dateSeries, ...dateSeriesRelevantKeys);
return pick(dateSeries, dateSeriesRelevantKeys);
}
export type DateSeriesRelevantKeys =

View File

@@ -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();

View File

@@ -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>

View File

@@ -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);

View File

@@ -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;

View File

@@ -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)),
),
)),
);

View File

@@ -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 => {

View File

@@ -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[]>;
}
}

View File

@@ -1,3 +1,18 @@
/*
* 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.
*
* 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 {JQueryRequestor, Requestor} from '@openid/appauth';
import {
@@ -31,6 +46,7 @@ export class LibraryAccountService {
private readonly authHelper: AuthHelperService,
readonly configProvider: ConfigProvider,
) {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const config: SCFeatureConfigurationExtern = (
configProvider.getValue('features') as SCFeatureConfiguration
).extern!.paia;

View File

@@ -1,16 +1,16 @@
/*
* Copyright (C) 2020 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-non-null-assertion, @typescript-eslint/ban-ts-comment */
import {

View File

@@ -1,22 +1,21 @@
/*
* 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 {Component, Input, OnDestroy, OnInit, ViewChild} from '@angular/core';
import {ActivatedRoute} from '@angular/router';
import {Platform} from '@ionic/angular';
import {SCISO8601Date, SCUuid} from '@openstapps/core';
import {last} from 'lodash-es';
import moment, {Moment} from 'moment';
import {DateFormatPipe} from 'ngx-moment';
import {Subscription} from 'rxjs';
@@ -178,7 +177,8 @@ export class CalendarViewComponent implements OnDestroy, OnInit {
let dayString: string | number | null =
this.activatedRoute.snapshot.paramMap.get('date');
if (dayString == undefined || dayString === 'now') {
const urlFragment: string = last(window.location.href.split('/')) ?? '';
const fragments = window.location.href.split('/');
const urlFragment: string = fragments[fragments.length - 1] ?? '';
dayString = /^\d{4}-\d{2}-\d{2}$/.test(urlFragment)
? urlFragment

View File

@@ -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-non-null-assertion */
@@ -33,8 +33,8 @@ import {
ViewContainerRef,
} from '@angular/core';
import Swiper from 'swiper';
import {drop, dropRight, forEach, range, take, takeRight, zip} from 'lodash-es';
import {materialManualFade} from '../../../../animation/material-motion';
import {zip} from '../../../../_helpers/collections/zip';
export interface SlideContext {
$implicit: number;
@@ -221,17 +221,23 @@ export class InfiniteSwiperComponent
);
// delete slides that are going to be dropped
for (const slide of (direction ? takeRight : take)(slides, deltaAmount)) {
for (const slide of [...slides].splice(
direction ? -deltaAmount : 0,
deltaAmount,
)) {
slide?.destroy();
}
// reuse existing slides
const newElements: undefined[] = Array.from({length: deltaAmount});
const shiftedSlides = direction
? [...newElements, ...dropRight(slides, deltaAmount)]
: [...drop(slides, deltaAmount), ...newElements];
? [...newElements, ...slides.slice(0, -deltaAmount)]
: [...slides.slice(deltaAmount), ...newElements];
forEach(zip(containers, shiftedSlides), ([container, element], i) => {
for (const [i, [container, element]] of zip(
containers,
shiftedSlides,
).entries()) {
// TODO: we should be able to skip this... In theory.
while (container!.length > 0) {
console.warn('Slide container is not empty after detach!');
@@ -245,12 +251,14 @@ export class InfiniteSwiperComponent
$implicit: this.virtualIndex + (i - this.slidesPerView),
});
}
});
}
this.swiper.slideTo(this.slidesPerView, 0, false);
}
resetSlides() {
this.slidesArray = range(0, this.slidesPerView * 3);
this.slidesArray = Array.from({length: this.slidesPerView * 3}).map(
(_, i) => i,
);
}
}

View File

@@ -1,4 +1,3 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
/*
* Copyright (C) 2022 StApps
* This program is free software: you can redistribute it and/or modify it
@@ -7,14 +6,16 @@
*
* 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 Licens for
* 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/>.
*/
/* eslint-disable @typescript-eslint/no-explicit-any */
import {groupRangeOverlaps} from './range-overlap';
import {shuffle} from 'lodash-es';
import {shuffle} from '../../../../_helpers/collections/shuffle';
interface SimpleRange {
starty: number;

View File

@@ -6,13 +6,13 @@
*
* 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 Licens for
* 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/>.
*/
import {flatMap, max, min, partition} from 'lodash-es';
import {partition} from '../../../../_helpers/collections/partition';
export interface RangeInfo<T> {
elements: T[];
@@ -75,11 +75,9 @@ function internalGroupRangeOverlaps<T>(input: RangeInfo<T>[]): RangeInfo<T>[] {
ranges = rest;
const elements = [range, ...overlaps];
result.push({
elements: flatMap(elements, 'elements'),
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
start: min(elements.map(it => it.start))!,
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
end: max(elements.map(it => it.end))!,
elements: elements.flatMap(it => it.elements),
start: Math.min(...elements.map(it => it.start)),
end: Math.max(...elements.map(it => it.end)),
});
}
return cumulativeReorders === 0 ? result : internalGroupRangeOverlaps(result);

View File

@@ -1,25 +1,27 @@
/*
* 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 {Component, Input, OnDestroy, OnInit} from '@angular/core';
import {SCDateSeries, SCUuid} from '@openstapps/core';
import {flatMap, groupBy, isNil, omit, sortBy} from 'lodash-es';
import moment from 'moment';
import {Subscription} from 'rxjs';
import {materialFade} from '../../../animation/material-motion';
import {ScheduleProvider} from '../../calendar/schedule.provider';
import {ScheduleEvent} from './schema/schema';
import {groupBy} from '../../../_helpers/collections/group-by';
import {omit} from '../../../_helpers/collections/omit';
import {stringSortBy} from '../../../_helpers/collections/string-sort';
/**
* A single event
@@ -72,32 +74,34 @@ export class ScheduleSingleEventsComponent implements OnInit, OnDestroy {
static groupDateSeriesToDays(
dateSeries: SCDateSeries[],
): ScheduleSingleEvent[][] {
return sortBy(
return Object.entries(
groupBy(
flatMap(dateSeries, event =>
event.dates.map(date => ({
dateUnix: moment(date).unix(),
day: moment(date).startOf('day').toISOString(),
event: {
dateSeries: event,
time: {
start:
moment(date).hour() +
moment(date)
// tslint:disable-next-line:no-magic-numbers
.minute() /
60,
duration: event.duration,
dateSeries
.flatMap(event =>
event.dates.map(date => ({
dateUnix: moment(date).unix(),
day: moment(date).startOf('day').toISOString(),
event: {
dateSeries: event,
time: {
start:
moment(date).hour() +
moment(date)
// tslint:disable-next-line:no-magic-numbers
.minute() /
60,
duration: event.duration,
},
},
},
})),
)
})),
)
.sort((a, b) => a.dateUnix - b.dateUnix)
.map(event => omit(event, 'dateUnix')),
'day',
it => it.day,
),
'day',
);
)
.sort(stringSortBy(([key]) => key))
.map(([_, value]) => value);
}
constructor(protected readonly scheduleProvider: ScheduleProvider) {}
@@ -115,7 +119,7 @@ export class ScheduleSingleEventsComponent implements OnInit, OnDestroy {
// TODO: replace with filter
return ScheduleSingleEventsComponent.groupDateSeriesToDays(
dateSeries.dates.filter(it => isNil(it.repeatFrequency)),
dateSeries.dates.filter(it => !it.repeatFrequency),
);
}

View File

@@ -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 {Component} from '@angular/core';
import {ActivatedRoute} from '@angular/router';
@@ -92,7 +92,6 @@ export class ScheduleViewComponent extends CalendarViewComponent {
for (const series of dateSeries.dates) {
const weekDays = Object.keys(
// eslint-disable-next-line unicorn/no-array-reduce
series.dates.reduce((accumulator, date) => {
accumulator[moment(date).isoWeekday()] = true;
return accumulator;

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2021 StApps
* 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.
@@ -17,7 +17,6 @@ import {Component, OnInit} from '@angular/core';
import {AddEventReviewModalComponent} from '../../calendar/add-event-review-modal.component';
import {ModalController} from '@ionic/angular';
import {ScheduleProvider} from '../../calendar/schedule.provider';
import {map} from 'lodash-es';
import {Directory, Encoding, Filesystem} from '@capacitor/filesystem';
import {Share} from '@capacitor/share';
import {Device} from '@capacitor/device';
@@ -99,7 +98,7 @@ export class CalendarSyncSettingsComponent implements OnInit {
async setSetting(settings: Partial<Record<CALENDAR_SYNC_KEYS, boolean>>) {
await Promise.all(
map(settings, (setting, key) =>
Object.entries(settings).map(([key, setting]) =>
this.storageProvider.put(calendarSettingStorageKey(key), setting),
),
);

View File

@@ -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 {Injectable} from '@angular/core';
import {Storage} from '@ionic/storage-angular';