feat: add the app

This commit is contained in:
Jovan Krunić
2018-12-11 22:11:50 +01:00
parent b4268b236f
commit 8b23159e67
129 changed files with 16359 additions and 1 deletions

View File

@@ -0,0 +1,34 @@
/*
* Copyright (C) 2018 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.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* 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 {NgModule} from '@angular/core';
import {RouterModule, Routes} from '@angular/router';
import {DataDetailComponent} from './detail/data-detail.component';
import {DataListComponent} from './list/data-list.component';
const dataRoutes: Routes = [
{path: 'search', component: DataListComponent},
{path: 'data-detail/:uid', component: DataDetailComponent}
];
@NgModule({
imports: [
RouterModule.forChild(dataRoutes)
],
// tslint:disable-next-line:object-literal-sort-keys
exports: [
RouterModule
]
})
export class DataRoutingModule {}

View File

@@ -0,0 +1,18 @@
<!--
Generated template for the DataPage page.
See http://ionicframework.com/docs/components/#navigation for more info on
Ionic pages and navigation.
-->
<ion-header>
<ion-toolbar>
<ion-title>data</ion-title>
</ion-toolbar>
</ion-header>
<ion-content padding>
</ion-content>

View File

@@ -0,0 +1,56 @@
/*
* Copyright (C) 2018 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.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* 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 {CommonModule} from '@angular/common';
import {HttpClientModule} from '@angular/common/http';
import {NgModule} from '@angular/core';
import {FormsModule} from '@angular/forms';
import {IonicModule} from '@ionic/angular';
import {DataRoutingModule} from './data-routing.module';
import {DataProvider, StAppsWebHttpClient} from './data.provider';
import {DataDetailComponent} from './detail/data-detail.component';
import {DataListItem} from './list/data-list-item.component';
import {DataListComponent} from './list/data-list.component';
import {DishDetailContentComponent} from './types/dish/dish-detail-content.component';
import {DishListItem} from './types/dish/dish-list-item.component';
import {EventListItemComponent} from './types/event/event-list-item.component';
@NgModule({
declarations: [
DataDetailComponent,
DishDetailContentComponent,
DishListItem,
EventListItemComponent,
DataListItem,
DataListComponent,
],
entryComponents: [
DataListComponent,
],
imports: [
IonicModule.forRoot(),
CommonModule,
FormsModule,
DataRoutingModule,
HttpClientModule,
],
providers: [
DataProvider,
StAppsWebHttpClient,
],
})
export class DataModule {}

View File

@@ -0,0 +1,81 @@
/*
* Copyright (C) 2018 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.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* 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 {HttpClient, HttpResponse} from '@angular/common/http';
import {Injectable} from '@angular/core';
import {HttpClientInterface, HttpClientRequest} from '@openstapps/api/lib/httpClientInterface';
/**
* Response with generic for the type of body that is returned from the request
*/
export interface Response<TYPE_OF_BODY> extends HttpResponse<TYPE_OF_BODY> {
body: TYPE_OF_BODY;
statusCode: number;
}
/**
* HttpClient that is based on angular's HttpClient (@TODO: move it to provider or independent package)
*/
@Injectable()
export class StAppsWebHttpClient implements HttpClientInterface {
constructor(private http: HttpClient) {
}
/**
* Make a request
* @param requestConfig Configuration of the request
*/
async request<TYPE_OF_BODY>(
requestConfig: HttpClientRequest,
): Promise<Response<TYPE_OF_BODY>> {
const options: {
[key: string]: any;
observe: 'response';
} = {
body: {},
observe: 'response',
responseType: 'json',
};
if (typeof requestConfig.body !== 'undefined') {
options.body = requestConfig.body;
}
if (typeof requestConfig.headers !== 'undefined') {
options.headers = requestConfig.headers;
}
try {
const response: HttpResponse<TYPE_OF_BODY> = await this.http.request<TYPE_OF_BODY>(
requestConfig.method || 'GET', requestConfig.url.toString(), options)
.toPromise();
return Object.assign(response, {statusCode: response.status, body: response.body || {}});
} catch (err) {
throw Error(err);
}
}
}
/*
Generated class for the DataProvider provider.
See https://angular.io/guide/dependency-injection for more info on providers
and Angular DI.
*/
@Injectable()
export class DataProvider {
constructor() {
// @TODO
}
}

View File

@@ -0,0 +1,68 @@
/*
* Copyright (C) 2018 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.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* 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 {CUSTOM_ELEMENTS_SCHEMA} from '@angular/core';
import {async, ComponentFixture, TestBed} from '@angular/core/testing';
import {ActivatedRoute, RouterModule} from '@angular/router';
import {DataRoutingModule} from '../data-routing.module';
import {DataListComponent} from '../list/data-list.component';
import {DataDetailComponent} from './data-detail.component';
describe('DataDetailComponent', () => {
let comp: DataDetailComponent;
let fixture: ComponentFixture<DataDetailComponent>;
let detailPage: HTMLElement;
// @Component({ selector: 'stapps-data-list-item', template: '' })
// class DataListItemComponent {
// @Input() item;
// }
const fakeActivatedRoute = {
snapshot: {
paramMap: {
get: (url) => {
return url;
}
}
}
} as ActivatedRoute;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [DataListComponent, DataDetailComponent],
imports: [RouterModule, DataRoutingModule],
providers: [{provide: ActivatedRoute, useValue: fakeActivatedRoute}],
schemas: [CUSTOM_ELEMENTS_SCHEMA],
})
.compileComponents();
}));
beforeEach(async() => {
fixture = await TestBed.createComponent(DataDetailComponent);
comp = fixture.componentInstance;
fixture.detectChanges();
});
it('should create component', () =>
expect(comp).toBeDefined(),
);
it('should have apropriate title', () => {
detailPage = fixture.nativeElement;
const title: HTMLIonTitleElement | null = detailPage.querySelector('ion-title');
expect(title).not.toBe(null);
expect(title!.innerText).toContain('Detailansicht');
});
});

View File

@@ -0,0 +1,41 @@
/*
* Copyright (C) 2018 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.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* 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} from '@angular/core';
import {ActivatedRoute} from '@angular/router';
import {SCThings} from '@openstapps/core';
@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: 'dish',
uid: '',
};
}
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;
}
}

View File

@@ -0,0 +1,21 @@
<ion-header>
<ion-toolbar>
<ion-buttons slot="start">
<ion-back-button></ion-back-button>
<ion-menu-button></ion-menu-button>
</ion-buttons>
<ion-title>Detailansicht</ion-title>
</ion-toolbar>
</ion-header>
<ion-content padding>
<stapps-data-list-item [item]="item"></stapps-data-list-item>
<div [ngSwitch]="item.type">
<stapps-dish-detail-content [item]="item" *ngSwitchCase="'dish'"></stapps-dish-detail-content>
<span *ngSwitchDefault>
<p *ngIf="item.description">{{item.description}}</p>
</span>
</div>
</ion-content>

View File

@@ -0,0 +1,3 @@
stapps-data-detail {
}

View File

@@ -0,0 +1,34 @@
/*
* Copyright (C) 2018 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.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* 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 {SCThings} from '@openstapps/core';
@Component({
selector: 'stapps-data-list-item',
templateUrl: 'data-list-item.html'
})
export class DataListItem implements OnInit {
@Input() item: SCThings;
constructor() {
// noop
// this.item is not available yet
}
ngOnInit() {
// noop
// this.item is available now - the template is loaded and compiled
}
}

View File

@@ -0,0 +1,17 @@
<ion-item text-wrap button="true" lines="inset" [routerLink]="['/data-detail', item.uid]">
<ion-thumbnail slot="start">
<img src="../../../assets/imgs/logo.png">
</ion-thumbnail>
<ion-label [ngSwitch]="item.type" lines="full">
<div>
<stapps-dish-list-item [item]="item" *ngSwitchCase="'Dish'"></stapps-dish-list-item>
<stapps-event-list-item [item]="item" *ngSwitchCase="'Event'"></stapps-event-list-item>
<span *ngSwitchDefault>
{{item.name}}<br/>
<ion-note>{{item.type}}</ion-note>
</span>
</div>
</ion-label>
</ion-item>

View File

@@ -0,0 +1,101 @@
/*
* Copyright (C) 2018 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.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* 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} 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 '../data.provider';
@Component({
selector: 'stapps-data-list',
templateUrl: 'data-list.html',
})
export class DataListComponent {
selectedItem: any;
items: SCThing[] = [];
client: Client;
size: number = 30;
from: number = 0;
query: string;
queryChanged: Subject<string> = new Subject<string>();
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');
this.queryChanged
.pipe(
debounceTime(1000),
distinctUntilChanged())
.subscribe((model) => {
this.from = 0;
this.query = model;
this.items = [];
this.fetchItems();
});
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({
from: this.from,
query: this.query,
size: this.size
} as any).then((result) => {
result.data.forEach((item) => {
this.items.push(item);
});
if (this.from === 0) {
this.loading.dismiss();
}
}, async (err) => {
const alert: HTMLIonAlertElement = await this.alertController.create({
buttons: ['Dismiss'],
header: 'Error',
subHeader: err.message,
});
await alert.present();
await this.loading.dismiss();
});
}
}

View File

@@ -0,0 +1,22 @@
<ion-header>
<ion-toolbar>
<ion-buttons slot="start">
<ion-back-button></ion-back-button>
<ion-menu-button></ion-menu-button>
</ion-buttons>
<ion-searchbar (ngModelChange)="search($event)" [(ngModel)]="query"></ion-searchbar>
<!--<ion-title>List</ion-title>-->
</ion-toolbar>
</ion-header>
<ion-content>
<ion-list *ngFor="let item of items">
<stapps-data-list-item [item]="item"></stapps-data-list-item>
</ion-list>
<ion-infinite-scroll (ionInfinite)="loadMore($event)">
<ion-infinite-scroll-content></ion-infinite-scroll-content>
</ion-infinite-scroll>
</ion-content>

View File

@@ -0,0 +1,3 @@
stapps-data-list {
}

View File

@@ -0,0 +1,37 @@
/*
* Copyright (C) 2018 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.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* 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} from '@angular/core';
import {LangChangeEvent, TranslateService} from '@ngx-translate/core';
import {SCDish, SCDishMeta, SCLanguageName, SCThingMeta} from '@openstapps/core';
@Component({
selector: 'stapps-dish-detail-content',
templateUrl: 'dish-detail-content.html'
})
export class DishDetailContentComponent {
@Input() item: SCDish;
language: SCLanguageName;
meta: SCThingMeta;
constructor(translateService: TranslateService) {
this.language = translateService.currentLang as SCLanguageName;
this.meta = SCDishMeta;
translateService.onLangChange.subscribe((event: LangChangeEvent) => {
this.language = event.lang as SCLanguageName;
});
}
}

View File

@@ -0,0 +1,47 @@
<ion-card *ngIf="item.description">
<ion-card-header>{{meta.getFieldTranslation(language, 'description')}}</ion-card-header>
<ion-card-content>{{item.description}}</ion-card-content>
</ion-card>
<ion-card *ngIf="item.categories">
<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>
<ion-row *ngFor="let offer of item.offers">
<ion-col>
{{offer.universityRole.name}}
</ion-col>
<ion-col>{{offer.price}}</ion-col>
</ion-row>
<ion-row>
<ion-col>Standard / Gäste</ion-col>
<ion-col>{{item.price}}</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

@@ -0,0 +1,25 @@
/*
* Copyright (C) 2018 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.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* 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} from '@angular/core';
import {SCDish} from '@openstapps/core';
import {DataListItem} from '../../list/data-list-item.component';
@Component({
selector: 'stapps-dish-list-item',
templateUrl: 'dish-list-item.html',
})
export class DishListItem extends DataListItem {
@Input() item: SCDish;
}

View File

@@ -0,0 +1,6 @@
{{item.name}}<br/>
<ion-note>
{{item.price}}
{{item.categories.join(',')}}
{{item.place.name}}
</ion-note>

View File

@@ -0,0 +1,25 @@
/*
* Copyright (C) 2018 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.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* 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} from '@angular/core';
import {SCDateSeries} from '@openstapps/core';
import {DataListItem} from '../../list/data-list-item.component';
@Component({
selector: 'stapps-event-list-item',
templateUrl: 'event-list-item.html'
})
export class EventListItemComponent extends DataListItem {
@Input() item: SCDateSeries;
}

View File

@@ -0,0 +1,7 @@
{{item.name}}<br/>
<ion-note>
{{item.subProperties.semester}}
{{item.categories.join(', ')}}
{{item.startDate}} - {{item.endDate}}
</ion-note>