mirror of
https://gitlab.com/openstapps/openstapps.git
synced 2026-01-19 16:13:06 +00:00
feat(data): use data provider for list and detail view
This commit is contained in:
@@ -14,4 +14,4 @@
|
||||
</span>
|
||||
</div>
|
||||
</ion-label>
|
||||
</ion-item>
|
||||
</ion-item>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2018 StApps
|
||||
* Copyright (C) 2018, 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.
|
||||
@@ -14,21 +14,19 @@
|
||||
*/
|
||||
import {Component} from '@angular/core';
|
||||
import {AlertController, LoadingController} from '@ionic/angular';
|
||||
import {Client} from '@openstapps/api/lib/client';
|
||||
import {SCThing} from '@openstapps/core';
|
||||
import {Subject} from 'rxjs';
|
||||
import {debounceTime, distinctUntilChanged} from 'rxjs/operators';
|
||||
import {StAppsWebHttpClient} from '../stapps-web-http-client.provider';
|
||||
import {DataProvider} from '../data.provider';
|
||||
|
||||
@Component({
|
||||
selector: 'stapps-data-list',
|
||||
templateUrl: 'data-list.html',
|
||||
})
|
||||
export class DataListComponent {
|
||||
selectedItem: any;
|
||||
dataProvider: DataProvider;
|
||||
items: SCThing[] = [];
|
||||
|
||||
client: Client;
|
||||
selectedItem: any;
|
||||
|
||||
size: number = 30;
|
||||
from: number = 0;
|
||||
@@ -38,11 +36,9 @@ export class DataListComponent {
|
||||
|
||||
loading: HTMLIonLoadingElement;
|
||||
|
||||
constructor(private loadingController: LoadingController,
|
||||
private alertController: AlertController,
|
||||
swHttpClient: StAppsWebHttpClient) {
|
||||
this.client = new Client(swHttpClient, 'https://stappsbe01.innocampus.tu-berlin.de', '1.0.6');
|
||||
|
||||
// tslint:disable-next-line:max-line-length
|
||||
constructor(private loadingController: LoadingController, private alertController: AlertController, dataProvider: DataProvider) {
|
||||
this.dataProvider = dataProvider;
|
||||
this.queryChanged
|
||||
.pipe(
|
||||
debounceTime(1000),
|
||||
@@ -57,27 +53,16 @@ export class DataListComponent {
|
||||
this.fetchItems();
|
||||
}
|
||||
|
||||
search(query: string) {
|
||||
this.queryChanged.next(query);
|
||||
}
|
||||
|
||||
async loadMore(event: any): Promise<any> {
|
||||
this.from += this.size;
|
||||
await this.fetchItems();
|
||||
event.target.complete();
|
||||
return;
|
||||
}
|
||||
|
||||
private async fetchItems(): Promise<any> {
|
||||
if (this.from === 0) {
|
||||
this.loading = await this.loadingController.create();
|
||||
await this.loading.present();
|
||||
}
|
||||
|
||||
return this.client.search({
|
||||
return this.dataProvider.search({
|
||||
from: this.from,
|
||||
query: this.query,
|
||||
size: this.size
|
||||
size: this.size,
|
||||
} as any).then((result) => {
|
||||
result.data.forEach((item) => {
|
||||
this.items.push(item);
|
||||
@@ -98,4 +83,16 @@ export class DataListComponent {
|
||||
await this.loading.dismiss();
|
||||
});
|
||||
}
|
||||
|
||||
async loadMore(event: any): Promise<any> {
|
||||
this.from += this.size;
|
||||
await this.fetchItems();
|
||||
event.target.complete();
|
||||
return;
|
||||
}
|
||||
|
||||
search(query: string) {
|
||||
this.queryChanged.next(query);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user