refactor: replace TSLint with ESLint

This commit is contained in:
Wieland Schöbl
2021-06-30 13:53:44 +02:00
committed by Jovan Krunić
parent 67fb4a43c9
commit d696215d08
147 changed files with 5471 additions and 2704 deletions

View File

@@ -12,7 +12,7 @@
* 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 {Component, Input, OnDestroy, OnInit} from '@angular/core';
import {Router} from '@angular/router';
import {AlertController} from '@ionic/angular';
import {
@@ -38,51 +38,62 @@ import {DataProvider} from '../data.provider';
templateUrl: 'search-page.html',
providers: [ContextMenuService],
})
export class SearchPageComponent implements OnInit {
export class SearchPageComponent implements OnInit, OnDestroy {
/**
* Api query filter
*/
filterQuery: SCSearchFilter | undefined;
/**
* Filters the search should be initialized with
*/
@Input() forcedFilter?: SCSearchFilter;
/**
* Thing counter to start query the next page from
*/
from = 0;
/**
* Container for queried things
*/
items: Promise<SCThings[]>;
/**
* Page size of queries
*/
pageSize = 30;
/**
* Search value from search bar
*/
queryText: string;
/**
* Emits when there is a change in the query (search, sort or filter changed)
*/
queryChanged = new Subject<void>();
/**
* Subject to handle search text changes
*/
queryTextChanged = new Subject<string>();
/**
* Time to wait for search query if search text is changing
*/
searchQueryDueTime = 1000;
/**
* Search response only ever contains a single SCThingType
*/
singleTypeResponse = false;
/**
* Api query sorting
*/
sortQuery: SCSearchSort | undefined;
/**
* Array of all subscriptions to Observables
*/
@@ -110,21 +121,23 @@ export class SearchPageComponent implements OnInit {
) {
this.initialize();
combineLatest(
[this.queryTextChanged.pipe(debounceTime(this.searchQueryDueTime),
combineLatest([
this.queryTextChanged.pipe(
debounceTime(this.searchQueryDueTime),
distinctUntilChanged(),
startWith(this.queryText),
),
this.contextMenuService.filterQueryChanged$.pipe(startWith(this.filterQuery)),
this.contextMenuService.filterQueryChanged$.pipe(
startWith(this.filterQuery),
),
this.contextMenuService.sortQueryChanged$.pipe(startWith(this.sortQuery)),
])
.subscribe(async (query) => {
this.queryText = query[0];
this.filterQuery = query[1];
this.sortQuery = query[2];
this.from = 0;
await this.fetchAndUpdateItems();
this.queryChanged.next();
]).subscribe(async query => {
this.queryText = query[0];
this.filterQuery = query[1];
this.sortQuery = query[2];
this.from = 0;
await this.fetchAndUpdateItems();
this.queryChanged.next();
});
this.fetchAndUpdateItems();
@@ -132,19 +145,21 @@ export class SearchPageComponent implements OnInit {
/**
* Subscribe to 'settings.changed' events
*/
this.subscriptions.push(this.settingsProvider.settingsActionChanged$.subscribe(({type, payload}) => {
if (type === 'stapps.settings.changed') {
const {category, name, value} = payload!;
this.logger.log(`received event "settings.changed" with category:
this.subscriptions.push(
this.settingsProvider.settingsActionChanged$.subscribe(
({type, payload}) => {
if (type === 'stapps.settings.changed') {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const {category, name, value} = payload!;
this.logger.log(`received event "settings.changed" with category:
${category}, name: ${name}, value: ${JSON.stringify(value)}`);
}
},
));
this.subscriptions.push(this.dataRoutingService.itemSelectListener()
.subscribe((item) => {
}
},
),
this.dataRoutingService.itemSelectListener().subscribe(item => {
void this.router.navigate(['data-detail', item.uid]);
}));
}),
);
}
/**
@@ -185,13 +200,15 @@ export class SearchPageComponent implements OnInit {
};
}
return this.dataProvider.search(searchOptions)
.then(async (result) => {
this.singleTypeResponse = result.facets.find(facet => facet.field === 'type')?.buckets.length === 1;
return this.dataProvider.search(searchOptions).then(
async result => {
this.singleTypeResponse =
result.facets.find(facet => facet.field === 'type')?.buckets
.length === 1;
if (append) {
let items = await this.items;
// append results
items = items.concat(result.data);
items = [...items, ...result.data];
this.items = (async () => items)();
} else {
// override items with results
@@ -201,21 +218,23 @@ export class SearchPageComponent implements OnInit {
return result.data;
})();
}
}, async (err) => {
},
async error => {
const alert: HTMLIonAlertElement = await this.alertController.create({
buttons: ['Dismiss'],
header: 'Error',
subHeader: err.message,
subHeader: error.message,
});
await alert.present();
});
},
);
}
/**
* Set starting values (e.g. forced filter, which can be set in components inheriting this one)
*/
// tslint:disable-next-line:prefer-function-over-method
// eslint-disable-next-line class-methods-use-this
initialize() {
// nothing to do here
}
@@ -223,7 +242,7 @@ export class SearchPageComponent implements OnInit {
/**
* Loads next page of things
*/
// tslint:disable-next-line:no-any
// eslint-disable-next-line @typescript-eslint/no-explicit-any
async loadMore(): Promise<void> {
this.from += this.pageSize;
await this.fetchAndUpdateItems(true);