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

41
package-lock.json generated
View File

@@ -3061,7 +3061,6 @@
"resolved": "https://registry.npmjs.org/are-we-there-yet/-/are-we-there-yet-1.1.5.tgz",
"integrity": "sha512-5hYdAkZlcG8tOLujVDTgCT+uPX0VnpAH28gWsLfzpXYm7wP6mp5Q/gYyR7YQ0cKVJcXJnl3j2kpBan13PtQf6w==",
"dev": true,
"optional": true,
"requires": {
"delegates": "^1.0.0",
"readable-stream": "^2.0.6"
@@ -4571,8 +4570,7 @@
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/console-control-strings/-/console-control-strings-1.1.0.tgz",
"integrity": "sha1-PXz0Rk22RG6mRL9LOVB/mFEAjo4=",
"dev": true,
"optional": true
"dev": true
},
"constants-browserify": {
"version": "1.0.0",
@@ -5198,8 +5196,7 @@
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/delegates/-/delegates-1.0.0.tgz",
"integrity": "sha1-hMbhWbgZBP3KWaDvRM2HDTElD5o=",
"dev": true,
"optional": true
"dev": true
},
"depd": {
"version": "1.1.2",
@@ -6979,7 +6976,6 @@
"resolved": "https://registry.npmjs.org/gauge/-/gauge-2.7.4.tgz",
"integrity": "sha1-LANAXHU4w51+s3sxcCLjJfsBi/c=",
"dev": true,
"optional": true,
"requires": {
"aproba": "^1.0.3",
"console-control-strings": "^1.0.0",
@@ -6995,15 +6991,13 @@
"version": "2.1.1",
"resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-2.1.1.tgz",
"integrity": "sha1-w7M6te42DYbg5ijwRorn7yfWVN8=",
"dev": true,
"optional": true
"dev": true
},
"is-fullwidth-code-point": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-1.0.0.tgz",
"integrity": "sha1-754xOG8DGn8NZDr4L95QxFfvAMs=",
"dev": true,
"optional": true,
"requires": {
"number-is-nan": "^1.0.0"
}
@@ -7013,7 +7007,6 @@
"resolved": "https://registry.npmjs.org/string-width/-/string-width-1.0.2.tgz",
"integrity": "sha1-EYvfW4zcUaKn5w0hHgfisLmxB9M=",
"dev": true,
"optional": true,
"requires": {
"code-point-at": "^1.0.0",
"is-fullwidth-code-point": "^1.0.0",
@@ -7025,7 +7018,6 @@
"resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-3.0.1.tgz",
"integrity": "sha1-ajhfuIU9lS1f8F0Oiq+UJ43GPc8=",
"dev": true,
"optional": true,
"requires": {
"ansi-regex": "^2.0.0"
}
@@ -7058,8 +7050,7 @@
"version": "4.0.1",
"resolved": "https://registry.npmjs.org/get-stdin/-/get-stdin-4.0.1.tgz",
"integrity": "sha1-uWjGsKBDhDJJAui/Gl3zJXmkUP4=",
"dev": true,
"optional": true
"dev": true
},
"get-stream": {
"version": "3.0.0",
@@ -7258,8 +7249,7 @@
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/has-unicode/-/has-unicode-2.0.1.tgz",
"integrity": "sha1-4Ob+aijPUROIVeCG0Wkedx3iqLk=",
"dev": true,
"optional": true
"dev": true
},
"has-value": {
"version": "1.0.0",
@@ -8105,8 +8095,7 @@
"version": "0.2.1",
"resolved": "https://registry.npmjs.org/is-utf8/-/is-utf8-0.2.1.tgz",
"integrity": "sha1-Sw2hRCEE0bM2NA6AeX6GXPOffXI=",
"dev": true,
"optional": true
"dev": true
},
"is-windows": {
"version": "1.0.2",
@@ -8847,7 +8836,6 @@
"resolved": "https://registry.npmjs.org/load-json-file/-/load-json-file-1.1.0.tgz",
"integrity": "sha1-lWkFcI1YtLq0wiYbBPWfMcmTdMA=",
"dev": true,
"optional": true,
"requires": {
"graceful-fs": "^4.1.2",
"parse-json": "^2.2.0",
@@ -8860,8 +8848,7 @@
"version": "2.3.0",
"resolved": "https://registry.npmjs.org/pify/-/pify-2.3.0.tgz",
"integrity": "sha1-7RQaasBDqEnqWISY59yosVMw6Qw=",
"dev": true,
"optional": true
"dev": true
}
}
},
@@ -9179,8 +9166,7 @@
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/map-obj/-/map-obj-1.0.1.tgz",
"integrity": "sha1-2TPOuSBdgr3PSIb2dCvcK03qFG0=",
"dev": true,
"optional": true
"dev": true
},
"map-stream": {
"version": "0.1.0",
@@ -9908,7 +9894,6 @@
"resolved": "https://registry.npmjs.org/npmlog/-/npmlog-4.1.2.tgz",
"integrity": "sha512-2uUqazuKlTaSI/dC8AzicUck7+IrEaOnN/e0jd3Xtt1KcGpwx30v50mL7oPyr/h9bL3E4aZccVwpwP+5W9Vjkg==",
"dev": true,
"optional": true,
"requires": {
"are-we-there-yet": "~1.1.2",
"console-control-strings": "~1.1.0",
@@ -11225,7 +11210,6 @@
"resolved": "https://registry.npmjs.org/read-pkg/-/read-pkg-1.1.0.tgz",
"integrity": "sha1-9f+qXs0pyzHAR0vKfXVra7KePyg=",
"dev": true,
"optional": true,
"requires": {
"load-json-file": "^1.0.0",
"normalize-package-data": "^2.3.2",
@@ -11237,7 +11221,6 @@
"resolved": "https://registry.npmjs.org/path-type/-/path-type-1.1.0.tgz",
"integrity": "sha1-WcRPfuSR2nBNpBXaWkBwuk+P5EE=",
"dev": true,
"optional": true,
"requires": {
"graceful-fs": "^4.1.2",
"pify": "^2.0.0",
@@ -11248,8 +11231,7 @@
"version": "2.3.0",
"resolved": "https://registry.npmjs.org/pify/-/pify-2.3.0.tgz",
"integrity": "sha1-7RQaasBDqEnqWISY59yosVMw6Qw=",
"dev": true,
"optional": true
"dev": true
}
}
},
@@ -11258,7 +11240,6 @@
"resolved": "https://registry.npmjs.org/read-pkg-up/-/read-pkg-up-1.0.1.tgz",
"integrity": "sha1-nWPBMnbAZZGNV/ACpX9AobZD+wI=",
"dev": true,
"optional": true,
"requires": {
"find-up": "^1.0.0",
"read-pkg": "^1.0.0"
@@ -11269,7 +11250,6 @@
"resolved": "https://registry.npmjs.org/find-up/-/find-up-1.1.2.tgz",
"integrity": "sha1-ay6YIrGizgpgq2TWEOzK1TyyTQ8=",
"dev": true,
"optional": true,
"requires": {
"path-exists": "^2.0.0",
"pinkie-promise": "^2.0.0"
@@ -11280,7 +11260,6 @@
"resolved": "https://registry.npmjs.org/path-exists/-/path-exists-2.1.0.tgz",
"integrity": "sha1-D+tsZPD8UY2adU3V77YscCJ2H0s=",
"dev": true,
"optional": true,
"requires": {
"pinkie-promise": "^2.0.0"
}
@@ -12718,7 +12697,6 @@
"resolved": "https://registry.npmjs.org/strip-bom/-/strip-bom-2.0.0.tgz",
"integrity": "sha1-YhmoVhZSBJHzV4i9vxRHqZx+aw4=",
"dev": true,
"optional": true,
"requires": {
"is-utf8": "^0.2.0"
}
@@ -14418,7 +14396,6 @@
"resolved": "https://registry.npmjs.org/wide-align/-/wide-align-1.1.3.tgz",
"integrity": "sha512-QGkOQc8XL6Bt5PwnsExKBPuMKBxnGxWWW3fU55Xt4feHozMUhdUMaBCk290qpm/wG5u/RSKzwdAC4i51YigihA==",
"dev": true,
"optional": true,
"requires": {
"string-width": "^1.0.2 || 2"
}

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;