mirror of
https://gitlab.com/openstapps/openstapps.git
synced 2026-01-21 00:52:55 +00:00
refactor: replace TSLint with ESLint
This commit is contained in:
committed by
Jovan Krunić
parent
67fb4a43c9
commit
d696215d08
@@ -28,9 +28,11 @@ export class ActionChipListComponent {
|
||||
* If chips are applicable
|
||||
*/
|
||||
applicable: Record<string, () => boolean> = {
|
||||
'locate': () => this.item.hasOwnProperty('inPlace'),
|
||||
'event': () => this.item.type === SCThingType.AcademicEvent ||
|
||||
(this.item.type === SCThingType.DateSeries && (this.item as SCDateSeries).dates.length !== 0),
|
||||
locate: () => this.item.hasOwnProperty('inPlace'),
|
||||
event: () =>
|
||||
this.item.type === SCThingType.AcademicEvent ||
|
||||
(this.item.type === SCThingType.DateSeries &&
|
||||
(this.item as SCDateSeries).dates.length > 0),
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,4 +1,10 @@
|
||||
<div>
|
||||
<stapps-locate-action-chip *ngIf='applicable["locate"]()' [item]='item'></stapps-locate-action-chip>
|
||||
<stapps-add-event-action-chip *ngIf='applicable["event"]()' [item]='item'></stapps-add-event-action-chip>
|
||||
<stapps-locate-action-chip
|
||||
*ngIf="applicable['locate']()"
|
||||
[item]="item"
|
||||
></stapps-locate-action-chip>
|
||||
<stapps-add-event-action-chip
|
||||
*ngIf="applicable['event']()"
|
||||
[item]="item"
|
||||
></stapps-add-event-action-chip>
|
||||
</div>
|
||||
|
||||
@@ -28,9 +28,8 @@ enum Selection {
|
||||
*
|
||||
* The generic is to preserve type safety of how deep the tree goes.
|
||||
*/
|
||||
// tslint:disable-next-line:no-any
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
class TreeNode<T extends TreeNode<any> | SelectionValue> {
|
||||
|
||||
/**
|
||||
* Value of this node
|
||||
*/
|
||||
@@ -55,13 +54,25 @@ class TreeNode<T extends TreeNode<any> | SelectionValue> {
|
||||
* Accumulate values of children to set current value
|
||||
*/
|
||||
private accumulateApplyValues() {
|
||||
const selections: number[] =
|
||||
this.children.map(it => it instanceof TreeNode ?
|
||||
(it.checked ? Selection.ON : (it.indeterminate ? Selection.PARTIAL : Selection.OFF)) :
|
||||
(it as SelectionValue).selected ? Selection.ON : Selection.OFF);
|
||||
const selections: number[] = this.children.map(
|
||||
it =>
|
||||
/* eslint-disable unicorn/no-nested-ternary */
|
||||
it instanceof TreeNode
|
||||
? it.checked
|
||||
? Selection.ON
|
||||
: it.indeterminate
|
||||
? Selection.PARTIAL
|
||||
: Selection.OFF
|
||||
: (it as SelectionValue).selected
|
||||
? Selection.ON
|
||||
: Selection.OFF,
|
||||
/* eslint-enable unicorn/no-nested-ternary */
|
||||
);
|
||||
|
||||
this.checked = every(selections, it => it === Selection.ON);
|
||||
this.indeterminate = this.checked ? false : some(selections, it => it > Selection.OFF);
|
||||
this.indeterminate = this.checked
|
||||
? false
|
||||
: some(selections, it => it > Selection.OFF);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -72,7 +83,7 @@ class TreeNode<T extends TreeNode<any> | SelectionValue> {
|
||||
if (child instanceof TreeNode) {
|
||||
child.checked = this.checked;
|
||||
child.indeterminate = false;
|
||||
// tslint:disable-next-line:no-any
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
(child as TreeNode<any>).applyValueDownwards();
|
||||
} else {
|
||||
(child as SelectionValue).selected = this.checked;
|
||||
@@ -159,18 +170,23 @@ export class AddEventPopoverComponent implements OnInit {
|
||||
*/
|
||||
selection: TreeNode<TreeNode<SelectionValue>>;
|
||||
|
||||
constructor(readonly ref: ChangeDetectorRef) {
|
||||
}
|
||||
constructor(readonly ref: ChangeDetectorRef) {}
|
||||
|
||||
/**
|
||||
* Init
|
||||
*/
|
||||
ngOnInit() {
|
||||
this.selection =
|
||||
new TreeNode(values(groupBy(sortBy(this.items.map(item => ({
|
||||
selected: false,
|
||||
item: item,
|
||||
})), it => it.item.frequency), it => it.item.frequency))
|
||||
.map(item => new TreeNode(item, this.ref)), this.ref);
|
||||
this.selection = new TreeNode(
|
||||
values(
|
||||
groupBy(
|
||||
sortBy(
|
||||
this.items.map(item => ({selected: false, item: item})),
|
||||
it => it.item.frequency,
|
||||
),
|
||||
it => it.item.frequency,
|
||||
),
|
||||
).map(item => new TreeNode(item, this.ref)),
|
||||
this.ref,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,39 +1,47 @@
|
||||
<ion-card-content>
|
||||
<ion-item-group>
|
||||
<ion-item-divider (click)='selection.click()'>
|
||||
<ion-label>{{'data.chips.add_events.popover.ALL' | translate}}</ion-label>
|
||||
<ion-checkbox slot='start'
|
||||
[checked]='selection.checked'
|
||||
[indeterminate]='selection.indeterminate'>
|
||||
<ion-item-divider (click)="selection.click()">
|
||||
<ion-label>{{
|
||||
'data.chips.add_events.popover.ALL' | translate
|
||||
}}</ion-label>
|
||||
<ion-checkbox
|
||||
slot="start"
|
||||
[checked]="selection.checked"
|
||||
[indeterminate]="selection.indeterminate"
|
||||
>
|
||||
</ion-checkbox>
|
||||
</ion-item-divider>
|
||||
<ion-item-group *ngFor='let frequency of selection.children'>
|
||||
<ion-item-divider (click)='frequency.click()'>
|
||||
<ion-label>{{('frequency' | thingTranslate: frequency.children[0].item) | titlecase}}</ion-label>
|
||||
<ion-checkbox slot='start'
|
||||
[checked]='frequency.checked'
|
||||
[indeterminate]='frequency.indeterminate'>
|
||||
<ion-item-group *ngFor="let frequency of selection.children">
|
||||
<ion-item-divider (click)="frequency.click()">
|
||||
<ion-label>{{
|
||||
'frequency' | thingTranslate: frequency.children[0].item | titlecase
|
||||
}}</ion-label>
|
||||
<ion-checkbox
|
||||
slot="start"
|
||||
[checked]="frequency.checked"
|
||||
[indeterminate]="frequency.indeterminate"
|
||||
>
|
||||
</ion-checkbox>
|
||||
</ion-item-divider>
|
||||
<ion-item *ngFor='let date of frequency.children'
|
||||
(click)='date.selected = !date.selected; frequency.notifyChildChanged()'>
|
||||
<ion-label *ngIf='date.item.dates.length > 1; else single_event'>
|
||||
{{date.item.duration | amDuration: 'hours'}}
|
||||
{{'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'}}
|
||||
<ion-item
|
||||
*ngFor="let date of frequency.children"
|
||||
(click)="date.selected = !date.selected; frequency.notifyChildChanged()"
|
||||
>
|
||||
<ion-label *ngIf="date.item.dates.length > 1; else single_event">
|
||||
{{ date.item.duration | amDuration: 'hours' }}
|
||||
{{ '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' }}
|
||||
</ion-label>
|
||||
<ng-template #single_event>
|
||||
<ion-label>
|
||||
{{date.item.duration | amDuration: 'hours'}}
|
||||
{{'data.chips.add_events.popover.AT' | translate}}
|
||||
{{last(date.item.dates) | amDateFormat: 'll, HH:mm'}}
|
||||
{{ date.item.duration | amDuration: 'hours' }}
|
||||
{{ 'data.chips.add_events.popover.AT' | translate }}
|
||||
{{ last(date.item.dates) | amDateFormat: 'll, HH:mm' }}
|
||||
</ion-label>
|
||||
</ng-template>
|
||||
<ion-checkbox slot='start'
|
||||
[checked]='date.selected'>
|
||||
</ion-checkbox>
|
||||
<ion-checkbox slot="start" [checked]="date.selected"> </ion-checkbox>
|
||||
</ion-item>
|
||||
</ion-item-group>
|
||||
</ion-item-group>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* tslint:disable:prefer-function-over-method */
|
||||
/* eslint-disable class-methods-use-this */
|
||||
/*
|
||||
* Copyright (C) 2021 StApps
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
@@ -91,9 +91,10 @@ export class AddEventActionChipComponent implements OnInit {
|
||||
},
|
||||
};
|
||||
|
||||
constructor(readonly popoverController: PopoverController,
|
||||
readonly dataProvider: DataProvider) {
|
||||
}
|
||||
constructor(
|
||||
readonly popoverController: PopoverController,
|
||||
readonly dataProvider: DataProvider,
|
||||
) {}
|
||||
|
||||
/**
|
||||
* Apply state
|
||||
@@ -110,35 +111,42 @@ export class AddEventActionChipComponent implements OnInit {
|
||||
* Init
|
||||
*/
|
||||
ngOnInit() {
|
||||
this.associatedDateSeries = this.item.type === SCThingType.DateSeries ?
|
||||
Promise.resolve([this.item as SCDateSeries]) :
|
||||
this.dataProvider.search({
|
||||
filter: {
|
||||
arguments: {
|
||||
filters: [
|
||||
{
|
||||
this.associatedDateSeries =
|
||||
this.item.type === SCThingType.DateSeries
|
||||
? Promise.resolve([this.item as SCDateSeries])
|
||||
: this.dataProvider
|
||||
.search({
|
||||
filter: {
|
||||
arguments: {
|
||||
field: 'type',
|
||||
value: SCThingType.DateSeries,
|
||||
filters: [
|
||||
{
|
||||
arguments: {
|
||||
field: 'type',
|
||||
value: SCThingType.DateSeries,
|
||||
},
|
||||
type: 'value',
|
||||
},
|
||||
{
|
||||
arguments: {
|
||||
field: 'event.uid',
|
||||
value: this.item.uid,
|
||||
},
|
||||
type: 'value',
|
||||
},
|
||||
],
|
||||
operation: 'and',
|
||||
},
|
||||
type: 'value',
|
||||
type: 'boolean',
|
||||
},
|
||||
{
|
||||
arguments: {
|
||||
field: 'event.uid',
|
||||
value: this.item.uid,
|
||||
},
|
||||
type: 'value',
|
||||
},
|
||||
],
|
||||
operation: 'and',
|
||||
},
|
||||
type: 'boolean',
|
||||
},
|
||||
})
|
||||
.then((it) => it.data as SCDateSeries[]);
|
||||
this.associatedDateSeries.then((it) => this.applyState(
|
||||
it.length < 1 ? AddEventStates.UNAVAILABLE : AddEventStates.REMOVED_ALL));
|
||||
})
|
||||
.then(it => it.data as SCDateSeries[]);
|
||||
this.associatedDateSeries.then(it =>
|
||||
this.applyState(
|
||||
it.length === 0
|
||||
? AddEventStates.UNAVAILABLE
|
||||
: AddEventStates.REMOVED_ALL,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -159,7 +167,10 @@ export class AddEventActionChipComponent implements OnInit {
|
||||
await popover.present();
|
||||
// TODO: replace dummy implementation
|
||||
await popover.onDidDismiss();
|
||||
this.applyState(this.state === AddEventStates.ADDED_ALL ?
|
||||
AddEventStates.REMOVED_ALL : AddEventStates.ADDED_ALL);
|
||||
this.applyState(
|
||||
this.state === AddEventStates.ADDED_ALL
|
||||
? AddEventStates.REMOVED_ALL
|
||||
: AddEventStates.ADDED_ALL,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,14 @@
|
||||
<div *ngIf='(associatedDateSeries | async) as associatedDateSeries; else loading'>
|
||||
<ion-chip [disabled]='disabled' (click)='$event.stopPropagation(); onClick($event)'>
|
||||
<ion-icon [name]='icon'></ion-icon>
|
||||
<ion-label>{{label | translate}}</ion-label>
|
||||
<div *ngIf="associatedDateSeries | async as associatedDateSeries; else loading">
|
||||
<ion-chip
|
||||
[disabled]="disabled"
|
||||
(click)="$event.stopPropagation(); onClick($event)"
|
||||
>
|
||||
<ion-icon [name]="icon"></ion-icon>
|
||||
<ion-label>{{ label | translate }}</ion-label>
|
||||
</ion-chip>
|
||||
</div>
|
||||
<ng-template #loading>
|
||||
<ion-chip>
|
||||
<ion-skeleton-text animated='true' ></ion-skeleton-text>
|
||||
<ion-skeleton-text animated="true"></ion-skeleton-text>
|
||||
</ion-chip>
|
||||
</ng-template>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* tslint:disable:prefer-function-over-method */
|
||||
/* eslint-disable class-methods-use-this */
|
||||
/*
|
||||
* Copyright (C) 2021 StApps
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
@@ -36,4 +36,3 @@ export class LocateActionChipComponent {
|
||||
// TODO
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<ion-chip class='chip-class' (click)='$event.stopPropagation(); onClick()'>
|
||||
<ion-icon name='location'></ion-icon>
|
||||
<ion-label>{{'Locate' | translate}}</ion-label>
|
||||
<ion-chip class="chip-class" (click)="$event.stopPropagation(); onClick()">
|
||||
<ion-icon name="location"></ion-icon>
|
||||
<ion-label>{{ 'Locate' | translate }}</ion-label>
|
||||
<ng-template #loading>
|
||||
<ion-skeleton-text animated='true'></ion-skeleton-text>
|
||||
<ion-skeleton-text animated="true"></ion-skeleton-text>
|
||||
</ng-template>
|
||||
</ion-chip>
|
||||
|
||||
Reference in New Issue
Block a user