feat(data): use data provider for list and detail view

This commit is contained in:
Jovan Krunić
2019-02-07 16:13:11 +01:00
parent ffe05e4548
commit 7caaa18b7e
9 changed files with 87 additions and 81 deletions

View File

@@ -14,4 +14,4 @@
</span>
</div>
</ion-label>
</ion-item>
</ion-item>

View File

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