feat: separate prettier from eslint

This commit is contained in:
Rainer Killinger
2023-01-11 13:25:18 +01:00
committed by Thea Schöbl
parent 939fb6ef0f
commit a88d000ccd
381 changed files with 17952 additions and 38411 deletions

View File

@@ -1,16 +1,16 @@
/*
* 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 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, OnInit} from '@angular/core';
import {
@@ -68,9 +68,7 @@ export class AddEventReviewModalComponent implements OnInit {
});
this.iCalEvents = this.dateSeries.map(event => ({
title:
this.translator.translator.translatedAccess(event).event.name() ??
'error',
title: this.translator.translator.translatedAccess(event).event.name() ?? 'error',
events: toICal(event, this.translator.translator, {
allowRRuleExceptions: true,
excludeCancelledEvents: false,
@@ -81,9 +79,7 @@ export class AddEventReviewModalComponent implements OnInit {
async toCalendar() {
await Dialog.confirm({
title: this.translateService.instant(
'schedule.toCalendar.reviewModal.dialogs.toCalendarConfirm.TITLE',
),
title: this.translateService.instant('schedule.toCalendar.reviewModal.dialogs.toCalendarConfirm.TITLE'),
message: this.translateService.instant(
'schedule.toCalendar.reviewModal.dialogs.toCalendarConfirm.DESCRIPTION',
),
@@ -98,15 +94,7 @@ export class AddEventReviewModalComponent implements OnInit {
async download() {
const blob = new Blob(
[
serializeICal(
getICalExport(
this.dateSeries,
this.translator.translator,
this.includeCancelled,
),
),
],
[serializeICal(getICalExport(this.dateSeries, this.translator.translator, this.includeCancelled))],
{
type: 'text/calendar',
},
@@ -115,11 +103,7 @@ export class AddEventReviewModalComponent implements OnInit {
const a = document.createElement('a');
a.href = url;
a.download = `${
this.dateSeries.length === 1
? this.dateSeries[0].event.name
: 'stapps_calendar'
}.ics`;
a.download = `${this.dateSeries.length === 1 ? this.dateSeries[0].event.name : 'stapps_calendar'}.ics`;
a.click();
}
@@ -128,15 +112,7 @@ export class AddEventReviewModalComponent implements OnInit {
if (info.platform === 'web') {
const blob = new Blob(
[
serializeICal(
getICalExport(
this.dateSeries,
this.translator.translator,
this.includeCancelled,
),
),
],
[serializeICal(getICalExport(this.dateSeries, this.translator.translator, this.includeCancelled))],
{
type: 'text/calendar',
},
@@ -144,27 +120,19 @@ export class AddEventReviewModalComponent implements OnInit {
const file = new File([blob], 'calendar.ics', {type: blob.type});
const shareData: NewShareData = {
files: [file],
title: this.translateService.instant(
'schedule.toCalendar.reviewModal.shareData.TITLE',
),
text: this.translateService.instant(
'schedule.toCalendar.reviewModal.shareData.TEXT',
),
title: this.translateService.instant('schedule.toCalendar.reviewModal.shareData.TITLE'),
text: this.translateService.instant('schedule.toCalendar.reviewModal.shareData.TEXT'),
};
if (!(navigator as unknown as NewShareNavigator).canShare) {
return Dialog.alert({
title: this.translateService.instant(
'schedule.toCalendar.reviewModal.dialogs.cannotShare.TITLE',
),
title: this.translateService.instant('schedule.toCalendar.reviewModal.dialogs.cannotShare.TITLE'),
message: this.translateService.instant(
'schedule.toCalendar.reviewModal.dialogs.cannotShare.DESCRIPTION',
),
});
}
console.log(
(navigator as unknown as NewShareNavigator).canShare(shareData),
);
console.log((navigator as unknown as NewShareNavigator).canShare(shareData));
if (!(navigator as unknown as NewShareNavigator).canShare(shareData)) {
return Dialog.alert({
@@ -181,9 +149,7 @@ export class AddEventReviewModalComponent implements OnInit {
} catch (error) {
console.log(error);
return Dialog.alert({
title: this.translateService.instant(
'schedule.toCalendar.reviewModal.dialogs.failedShare.TITLE',
),
title: this.translateService.instant('schedule.toCalendar.reviewModal.dialogs.failedShare.TITLE'),
message: this.translateService.instant(
'schedule.toCalendar.reviewModal.dialogs.failedShare.DESCRIPTION',
),
@@ -194,32 +160,20 @@ export class AddEventReviewModalComponent implements OnInit {
path: `${
this.dateSeries.length === 1
? this.dateSeries[0].event.name
: this.translateService.instant(
'schedule.toCalendar.reviewModal.shareData.FILE_TYPE',
)
: this.translateService.instant('schedule.toCalendar.reviewModal.shareData.FILE_TYPE')
}.ics`,
data: serializeICal(
getICalExport(
this.dateSeries,
this.translator.translator,
this.includeCancelled,
),
getICalExport(this.dateSeries, this.translator.translator, this.includeCancelled),
),
encoding: Encoding.UTF8,
directory: Directory.Cache,
});
await Share.share({
title: this.translateService.instant(
'schedule.toCalendar.reviewModal.shareData.TITLE',
),
text: this.translateService.instant(
'schedule.toCalendar.reviewModal.shareData.TEXT',
),
title: this.translateService.instant('schedule.toCalendar.reviewModal.shareData.TITLE'),
text: this.translateService.instant('schedule.toCalendar.reviewModal.shareData.TEXT'),
url: result.uri,
dialogTitle: this.translateService.instant(
'schedule.toCalendar.reviewModal.shareData.TITLE',
),
dialogTitle: this.translateService.instant('schedule.toCalendar.reviewModal.shareData.TITLE'),
});
}
}

View File

@@ -1,22 +1,20 @@
<!--
~ 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 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/>.
-->
<div>
<ion-card-header>
<ion-card-title>{{
'schedule.toCalendar.reviewModal.TITLE' | translate
}}</ion-card-title>
<ion-card-title>{{ 'schedule.toCalendar.reviewModal.TITLE' | translate }}</ion-card-title>
<ion-button fill="clear" (click)="dismissAction()">
<ion-label>{{ 'modal.DISMISS' | translate }}</ion-label>
</ion-button>
@@ -52,9 +50,7 @@
<div class="horizontal-flex">
<ion-item lines="none">
<ion-label>{{
'schedule.toCalendar.reviewModal.INCLUDE_CANCELLED' | translate
}}</ion-label>
<ion-label>{{ 'schedule.toCalendar.reviewModal.INCLUDE_CANCELLED' | translate }}</ion-label>
<ion-checkbox [(ngModel)]="includeCancelled" slot="end"></ion-checkbox>
</ion-item>
</div>
@@ -63,11 +59,7 @@
{{ 'share' | translate }}
<ion-icon slot="end" md="share" ios="ios_share"></ion-icon>
</ion-button>
<ion-button
fill="outline"
(click)="download()"
*ngIf="isWeb; else exportButton"
>
<ion-button fill="outline" (click)="download()" *ngIf="isWeb; else exportButton">
{{ 'schedule.toCalendar.reviewModal.DOWNLOAD' | translate }}
<ion-icon slot="end" name="download"></ion-icon>
</ion-button>

View File

@@ -1,16 +1,16 @@
/*
* 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 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 {Calendar} from '@awesome-cordova-plugins/calendar/ngx';
@@ -22,9 +22,7 @@ import {CalendarInfo} from './calendar-info';
import {Subject} from 'rxjs';
import {ConfigProvider} from '../config/config.provider';
const RECURRENCE_PATTERNS: Partial<
Record<unitOfTime.Diff, string | undefined>
> = {
const RECURRENCE_PATTERNS: Partial<Record<unitOfTime.Diff, string | undefined>> = {
year: 'yearly',
month: 'monthly',
week: 'weekly',
@@ -40,12 +38,8 @@ export class CalendarService {
calendarName = 'StApps';
// eslint-disable-next-line @typescript-eslint/no-empty-function
constructor(
readonly calendar: Calendar,
private readonly configProvider: ConfigProvider,
) {
this.calendarName =
(this.configProvider.getValue('name') as string) ?? 'StApps';
constructor(readonly calendar: Calendar, private readonly configProvider: ConfigProvider) {
this.calendarName = (this.configProvider.getValue('name') as string) ?? 'StApps';
}
async createCalendar(): Promise<CalendarInfo | undefined> {
@@ -61,9 +55,7 @@ export class CalendarService {
}
async findCalendar(name: string): Promise<CalendarInfo | undefined> {
return (await this.listCalendars())?.find(
(calendar: CalendarInfo) => calendar.name === name,
);
return (await this.listCalendars())?.find((calendar: CalendarInfo) => calendar.name === name);
}
async purge(): Promise<CalendarInfo | undefined> {

View File

@@ -1,16 +1,16 @@
/*
* 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 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 {findRRules, RRule} from './ical';
@@ -27,10 +27,7 @@ function expandRRule(rule: RRule): SCISO8601Date[] {
return shuffle(
Array.from({
length:
Math.floor(
moment(rule.until).diff(initial, rule.freq, true) / interval,
) + 1,
length: Math.floor(moment(rule.until).diff(initial, rule.freq, true) / interval) + 1,
}).map((_, i) =>
initial
.clone()
@@ -65,8 +62,7 @@ describe('iCal', () => {
});
it('should find mixed recurrence patterns', () => {
const singlePattern: SCISO8601Date =
moment('2021-09-01T09:00').toISOString();
const singlePattern: SCISO8601Date = moment('2021-09-01T09:00').toISOString();
const weeklyPattern: RRule = {
freq: 'week',
@@ -75,8 +71,9 @@ describe('iCal', () => {
until: moment('2021-09-03T10:00').add(4, 'weeks').toISOString(),
};
expect(
findRRules(shuffle([singlePattern, ...expandRRule(weeklyPattern)])),
).toEqual([singlePattern, weeklyPattern]);
expect(findRRules(shuffle([singlePattern, ...expandRRule(weeklyPattern)]))).toEqual([
singlePattern,
weeklyPattern,
]);
});
});

View File

@@ -1,16 +1,16 @@
/*
* 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 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 {
SCDateSeries,
@@ -85,27 +85,19 @@ export interface MergedRRule {
/**
* Merge compatible RRules to a single RRule with exceptions
*/
export function mergeRRules(
rules: Array<RRule | SCISO8601Date>,
allowExceptions = true,
): MergedRRule[] {
if (!allowExceptions)
return rules.map(it => (typeof it === 'string' ? {date: it} : {rrule: it}));
export function mergeRRules(rules: Array<RRule | SCISO8601Date>, allowExceptions = true): MergedRRule[] {
if (!allowExceptions) return rules.map(it => (typeof it === 'string' ? {date: it} : {rrule: it}));
/*map(groupBy(rules, it => `${it.freq}@${it.interval}`), it => {
});*/
return rules.map(it =>
typeof it === 'string' ? {date: it} : {rrule: it},
) /* TODO */;
return rules.map(it => (typeof it === 'string' ? {date: it} : {rrule: it})) /* TODO */;
}
/**
* Find RRules in a list of dates
*/
export function findRRules(
dates: SCISO8601Date[],
): Array<RRule | SCISO8601Date> {
export function findRRules(dates: SCISO8601Date[]): Array<RRule | SCISO8601Date> {
const sorted = dates.sort((a, b) => moment(a).unix() - moment(b).unix());
const output: Optional<RRule, 'freq'>[] = [
@@ -121,9 +113,7 @@ export function findRRules(
const next = sorted[i + 1] as SCISO8601Date | undefined;
const element = output[output.length - 1];
const units: unitOfTime.Diff[] = element?.freq
? [element.freq]
: ['day', 'week', 'month', 'year'];
const units: unitOfTime.Diff[] = element?.freq ? [element.freq] : ['day', 'week', 'month', 'year'];
const freq = minBy(
units.map(recurrence => ({
recurrence: recurrence,
@@ -179,8 +169,7 @@ function getICalData(
uuid: dateSeries.uid,
categories: [
'stapps',
...((translated.event() as SCThingWithCategories<string, never>)
?.categories ?? []),
...((translated.event() as SCThingWithCategories<string, never>)?.categories ?? []),
],
description: translated.event()?.description ?? translated.description(),
geo: translated.inPlace()?.name,
@@ -207,28 +196,23 @@ export function toICal(
: dateSeries.dates,
);
return mergeRRules(rrules, options.allowRRuleExceptions).map(
(it, i, array) => ({
...getICalData(dateSeries, translator),
dates: dateSeries.dates,
rrule: it.rrule,
recurrenceSequence: array.length > 1 ? i + 1 : undefined,
recurrenceSequenceAmount: array.length > 1 ? array.length : undefined,
exceptionDates: it.exceptions,
start: it.rrule?.from ?? it.date ?? dateSeries.dates[0],
sequence: 0,
duration: dateSeries.duration,
}),
);
return mergeRRules(rrules, options.allowRRuleExceptions).map((it, i, array) => ({
...getICalData(dateSeries, translator),
dates: dateSeries.dates,
rrule: it.rrule,
recurrenceSequence: array.length > 1 ? i + 1 : undefined,
recurrenceSequenceAmount: array.length > 1 ? array.length : undefined,
exceptionDates: it.exceptions,
start: it.rrule?.from ?? it.date ?? dateSeries.dates[0],
sequence: 0,
duration: dateSeries.duration,
}));
}
/**
*
*/
export function toICalUpdates(
dateSeries: SCDateSeries,
translator: SCThingTranslator,
): ICalEvent[] {
export function toICalUpdates(dateSeries: SCDateSeries, translator: SCThingTranslator): ICalEvent[] {
return (
dateSeries.exceptions?.map(exception => ({
...getICalData(dateSeries, translator),
@@ -246,9 +230,7 @@ export function toICalUpdates(
export function iso8601ToICalDateTime<T extends SCISO8601Date | undefined>(
date: T,
): T extends SCISO8601Date ? string : undefined {
return (
date ? `${moment(date).utc().format('YYYYMMDDTHHmmss')}Z` : undefined
) as never;
return (date ? `${moment(date).utc().format('YYYYMMDDTHHmmss')}Z` : undefined) as never;
}
/**
@@ -261,9 +243,7 @@ export function iso8601ToICalDate(date: SCISO8601Date): string {
/**
* Recursively stringify all linebreaks to \n strings
*/
function stringifyLinebreaks<T extends string | unknown[] | unknown>(
value: T,
): T {
function stringifyLinebreaks<T extends string | unknown[] | unknown>(value: T): T {
if (typeof value === 'string') {
return value.replace(/\r?\n|\r/g, '\\n') as T;
}
@@ -307,9 +287,7 @@ export function serializeICalLike(iCal: ICalLike): string {
/**
* Removes all strings that are either undefined or end with 'undefined'
*/
function withoutNullishStrings<T extends string>(
array: Array<T | `${string}${undefined}` | undefined>,
): T[] {
function withoutNullishStrings<T extends string>(array: Array<T | `${string}${undefined}` | undefined>): T[] {
return array.filter(it => it && !it.endsWith('undefined')) as T[];
}
@@ -318,9 +296,9 @@ function withoutNullishStrings<T extends string>(
*/
export function serializeRRule(rrule?: RRule): string | undefined {
return rrule
? `FREQ=${
REPEAT_FREQUENCIES[rrule.freq ?? 's']
};UNTIL=${iso8601ToICalDateTime(rrule.until)};INTERVAL=${rrule.interval}`
? `FREQ=${REPEAT_FREQUENCIES[rrule.freq ?? 's']};UNTIL=${iso8601ToICalDateTime(rrule.until)};INTERVAL=${
rrule.interval
}`
: undefined;
}
@@ -402,8 +380,6 @@ export function getICalExport(
excludeCancelledEvents: !includeCancelled,
}),
),
...(includeCancelled
? dateSeries.flatMap(event => toICalUpdates(event, translator))
: []),
...(includeCancelled ? dateSeries.flatMap(event => toICalUpdates(event, translator)) : []),
];
}

View File

@@ -1,16 +1,16 @@
/*
* 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 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 */
@@ -33,18 +33,11 @@ import {pick} from '../../_helpers/collections/pick';
/**
*
*/
export function toDateSeriesRelevantData(
dateSeries: SCDateSeries,
): DateSeriesRelevantData {
export function toDateSeriesRelevantData(dateSeries: SCDateSeries): DateSeriesRelevantData {
return pick(dateSeries, dateSeriesRelevantKeys);
}
export type DateSeriesRelevantKeys =
| 'uid'
| 'dates'
| 'exceptions'
| 'repeatFrequency'
| 'duration';
export type DateSeriesRelevantKeys = 'uid' | 'dates' | 'exceptions' | 'repeatFrequency' | 'duration';
export const dateSeriesRelevantKeys: Array<DateSeriesRelevantKeys> = [
'uid',
@@ -62,12 +55,9 @@ export const formatRelevantKeys: {
) => string;
} = {
uid: value => value,
dates: (value, dateFormatter) =>
`[${value.map(it => dateFormatter.transform(it)).join(', ')}]`,
exceptions: (value, dateFormatter) =>
`[${value?.map(it => dateFormatter.transform(it)).join(', ') ?? ''}]`,
repeatFrequency: (value, _, durationFormatter) =>
durationFormatter.transform(value),
dates: (value, dateFormatter) => `[${value.map(it => dateFormatter.transform(it)).join(', ')}]`,
exceptions: (value, dateFormatter) => `[${value?.map(it => dateFormatter.transform(it)).join(', ') ?? ''}]`,
repeatFrequency: (value, _, durationFormatter) => durationFormatter.transform(value),
duration: (value, _, durationFormatter) => durationFormatter.transform(value),
};
@@ -133,19 +123,12 @@ export class ScheduleProvider implements OnDestroy {
public get partialEvents$(): BehaviorSubject<DateSeriesRelevantData[]> {
if (!this._partialEvents$) {
const data = ScheduleProvider.get<DateSeriesRelevantData>(
ScheduleProvider.partialEventsStorageKey,
);
const data = ScheduleProvider.get<DateSeriesRelevantData>(ScheduleProvider.partialEventsStorageKey);
this._partialEvents$ = new BehaviorSubject(data ?? []);
this._partialEventsSubscription = this._partialEvents$.subscribe(
result => {
ScheduleProvider.set(
ScheduleProvider.partialEventsStorageKey,
result,
);
},
);
this._partialEventsSubscription = this._partialEvents$.subscribe(result => {
ScheduleProvider.set(ScheduleProvider.partialEventsStorageKey, result);
});
}
return this._partialEvents$;