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

@@ -35,7 +35,7 @@ export class DataProvider {
private _storagePrefix: string = 'stapps.data';
// @TODO: get backendUrl and appVersion and storagePrefix from config (module)
appVersion: string = '1.0.6';
backendUrl: string = 'https://stappsbe01.innocampus.tu-berlin.de';
backendUrl: string = 'http://localhost:3000';
client: Client;
storageProvider: StorageProvider;

View File

@@ -14,29 +14,21 @@
*/
import {Component} from '@angular/core';
import {ActivatedRoute} from '@angular/router';
import {SCThingOriginType, SCThings, SCThingType} from '@openstapps/core';
import {SCThing} from '@openstapps/core';
import {DataProvider, DataScope} from '../data.provider';
@Component({
selector: 'stapps-data-detail',
templateUrl: 'data-detail.html',
})
export class DataDetailComponent {
item: SCThings;
constructor(private route: ActivatedRoute) {
this.item = {
categories: ['main dish'],
name: 'Demo-Name',
origin: {
indexed: '2018-09-11T12:30:00Z',
name: 'Dummy',
type: SCThingOriginType.Remote,
},
type: SCThingType.Dish,
uid: '',
};
dataProvider: DataProvider;
item: SCThing;
constructor(private route: ActivatedRoute, dataProvider: DataProvider) {
this.dataProvider = dataProvider;
}
ngOnInit() {
this.item.uid = this.route.snapshot.paramMap.get('uid') || '';
this.item.description = 'Demo Beschreibung für das Item mit der UID ' + this.item.uid;
async ngOnInit() {
const uid = this.route.snapshot.paramMap.get('uid') || '';
this.item = (await this.dataProvider.get(uid, DataScope.Remote));
}
}

View File

@@ -8,7 +8,7 @@
</ion-toolbar>
</ion-header>
<ion-content padding>
<ion-content padding *ngIf="item">
<stapps-data-list-item [item]="item"></stapps-data-list-item>
<div [ngSwitch]="item.type">
@@ -18,4 +18,4 @@
<p *ngIf="item.description">{{item.description}}</p>
</span>
</div>
</ion-content>
</ion-content>

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

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.
@@ -18,7 +18,7 @@ import {SCDish, SCDishMeta, SCLanguageName, SCThingMeta} from '@openstapps/core'
@Component({
selector: 'stapps-dish-detail-content',
templateUrl: 'dish-detail-content.html'
templateUrl: 'dish-detail-content.html',
})
export class DishDetailContentComponent {
@Input() item: SCDish;

View File

@@ -7,3 +7,43 @@
<ion-card-header>{{meta.getFieldTranslation(language, 'categories')}}</ion-card-header>
<ion-card-content>{{item.categories.join(', ')}}</ion-card-content>
</ion-card>
<ion-card *ngIf="item.characteristics">
<ion-card-header>{{meta.getFieldTranslation(language, 'characteristics')}}</ion-card-header>
<ion-card-content>{{item.characteristics.join(', ')}}</ion-card-content>
</ion-card>
<ion-card *ngIf="item.additives">
<ion-card-header>{{meta.getFieldTranslation(language, 'additives')}}</ion-card-header>
<ion-card-content>{{item.additives.join(', ')}}</ion-card-content>
</ion-card>
<ion-card *ngIf="item.place">
<ion-card-header>{{meta.getFieldTranslation(language, 'place')}}</ion-card-header>
<ion-card-content><a>{{item.place.name}}</a></ion-card-content>
</ion-card>
<ion-card>
<ion-card-header>{{meta.getFieldTranslation(language, 'price')}}</ion-card-header>
<ion-card-content>
<ion-grid *ngFor="let offer of item.offers">
<ion-row>
<ion-col>Student</ion-col>
<ion-col>{{offer.prices.student}}</ion-col>
</ion-row>
<ion-row>
<ion-col>Mitarbeiter</ion-col>
<ion-col>{{offer.prices.employee}}</ion-col>
</ion-row>
<ion-row>
<ion-col>Standard / Gäste</ion-col>
<ion-col>{{offer.prices.guest}}</ion-col>
</ion-row>
</ion-grid>
</ion-card-content>
</ion-card>
<ion-card *ngIf="item.availabilityStarts">
<ion-card-header>Verfügbarkeit</ion-card-header>
<ion-card-content>{{item.availabilityStarts | date}}</ion-card-content>
</ion-card>

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.
@@ -18,7 +18,7 @@ import {DataListItem} from '../../list/data-list-item.component';
@Component({
selector: 'stapps-event-list-item',
templateUrl: 'event-list-item.html'
templateUrl: 'event-list-item.html',
})
export class EventListItemComponent extends DataListItem {
@Input() item: SCDateSeries;