Skip to content

Commit

Permalink
[fix] Bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Dafnik committed Oct 22, 2021
1 parent 0546493 commit 7c13ae3
Show file tree
Hide file tree
Showing 20 changed files with 70 additions and 66 deletions.
12 changes: 4 additions & 8 deletions src/app/_helper/abstract-models-list-by-id.component.ts
Expand Up @@ -23,23 +23,19 @@ export abstract class AbstractModelsListByIdComponent<
modal: NgbModal,
protected route: ActivatedRoute,
protected router: Router,
protected entityService: AbstractEntityService<number, EntityType>
protected byIdEntityService: AbstractEntityService<number, EntityType>
) {
super(modelService, modal);

this.route.paramMap.subscribe((params) => {
const id = params.get('id');
if (id != null) {
this.entitiesLoaded = false;
if (TypeHelper.isNumeric(id)) {
const nId = Converter.stringToNumber(id);
this.lumber.info('const', 'Model to open: ' + nId);
this.entity = this.entityService.getSingle(nId);
if (this.entity?.id == nId) {
this.initializeVariables();
}
this.entity = this.byIdEntityService.getSingle(nId);
this.autoUnsubscribe(
this.entityService.singleChange.subscribe((entity) => {
this.byIdEntityService.singleChange.subscribe((entity) => {
this.entity = entity;
this.initializeVariables();
})
Expand All @@ -59,7 +55,7 @@ export abstract class AbstractModelsListByIdComponent<
if (!this.entity) {
return;
}
this.modelService.setGetAllUrl(this.getAllUrl + this.entity.id);
this.entitiesService.setGetAllUrl(this.getAllUrl + this.entity.id);
super.initializeVariables();
}
}
24 changes: 14 additions & 10 deletions src/app/_helper/abstract-models-list.component.ts
@@ -1,4 +1,4 @@
import {Component, QueryList, ViewChildren} from '@angular/core';
import {Component, OnInit, QueryList, ViewChildren} from '@angular/core';
import {FormControl} from '@angular/forms';

import {NgbModal} from '@ng-bootstrap/ng-bootstrap';
Expand All @@ -12,7 +12,7 @@ import {QuestionDialogComponent} from '../_shared/question-dialog/question-dialo
@Component({
template: '',
})
export abstract class AbstractModelsListComponent<EntityType extends AbstractEntity<number>> extends AbstractComponent {
export abstract class AbstractModelsListComponent<EntityType extends AbstractEntity<number>> extends AbstractComponent implements OnInit {
protected lumber = LoggerFactory.getLogger('AModelsListComponent');

@ViewChildren(SortableHeaderDirective) public headers: QueryList<SortableHeaderDirective> | undefined;
Expand All @@ -22,9 +22,8 @@ export abstract class AbstractModelsListComponent<EntityType extends AbstractEnt
public entitiesCopy!: IList<EntityType>;
public entitiesLoaded = false;

protected constructor(protected modelService: AbstractModelService<EntityType>, protected modal: NgbModal) {
protected constructor(protected entitiesService: AbstractModelService<EntityType>, protected modal: NgbModal) {
super();
this.initializeVariables();

this.filter.valueChanges.subscribe((value) => {
if (value == null) {
Expand All @@ -41,14 +40,19 @@ export abstract class AbstractModelsListComponent<EntityType extends AbstractEnt
});
}

ngOnInit() {
this.initializeVariables();
}

protected initializeVariables(): void {
this.entities = this.modelService.getAll();
this.entities = this.entitiesService.getAll();
this.entitiesCopy = this.entities.clone();
if (this.entities.length > 0) {
this.entitiesLoaded = true;
}
// Don't check because events waiters and org waiters use same list
// if (this.entities.length > 0) {
// this.entitiesLoaded = true;
// }
this.autoUnsubscribe(
this.modelService.allChange.subscribe((value) => {
this.entitiesService.allChange.subscribe((value) => {
this.entities = value;
this.entitiesCopy = this.entities.clone();
this.entitiesLoaded = true;
Expand All @@ -67,7 +71,7 @@ export abstract class AbstractModelsListComponent<EntityType extends AbstractEnt
modalRef.componentInstance.title = 'DELETE_CONFIRMATION';
void modalRef.result.then((result) => {
if (result?.toString().includes(QuestionDialogComponent.YES_VALUE)) {
this.modelService.delete(modelId);
this.entitiesService.delete(modelId);
}
});
}
Expand Down
6 changes: 3 additions & 3 deletions src/app/_models/event.model.ts
@@ -1,14 +1,14 @@
import {AbstractEntityWithName} from 'dfx-helper';
import {AbstractEntityWithNumberIDAndName} from 'dfx-helper';

export class EventModel extends AbstractEntityWithName<number> {
export class EventModel extends AbstractEntityWithNumberIDAndName {
public readonly date: Date | null;
public readonly street: string;
public readonly street_number: string;
public readonly postal_code: string;
public readonly city: string;

constructor(data: any) {
super(data.id, data.name);
super(data.id, data.name, data);
this.street = data.street;
this.street_number = data.street_number;
this.postal_code = data.postal_code;
Expand Down
6 changes: 3 additions & 3 deletions src/app/_models/organisation.model.ts
@@ -1,14 +1,14 @@
import {AbstractEntityWithName} from 'dfx-helper';
import {AbstractEntityWithNumberIDAndName} from 'dfx-helper';

export class OrganisationModel extends AbstractEntityWithName<number> {
export class OrganisationModel extends AbstractEntityWithNumberIDAndName {
public readonly street: string;
public readonly street_number: string;
public readonly postal_code: string;
public readonly city: string;
public readonly country_code: string;

constructor(data: any) {
super(data.id, data.name);
super(data.id, data.name, data);
this.street = data.street;
this.street_number = data.street_number;
this.postal_code = data.postal_code;
Expand Down
10 changes: 5 additions & 5 deletions src/app/_models/products.ts
@@ -1,14 +1,14 @@
import {AbstractEntityWithName} from 'dfx-helper';
import {AbstractEntityWithNumberIDAndName} from 'dfx-helper';

export class ProductsModel extends AbstractEntityWithName<number> {
export class ProductsModel extends AbstractEntityWithNumberIDAndName {
public readonly price: number;
public readonly allergens: Array<AllergensModel>;
public readonly group_id: number;
public readonly printer_id: number;
public readonly organisation_id: number;

constructor(data: any) {
super(data.id, data.name);
super(data.id, data.name, data);
this.price = data.price;
this.allergens = data.allergens;
this.group_id = data.group_id;
Expand All @@ -17,11 +17,11 @@ export class ProductsModel extends AbstractEntityWithName<number> {
}
}

export class AllergensModel extends AbstractEntityWithName<number> {
export class AllergensModel extends AbstractEntityWithNumberIDAndName {
public readonly short_name: string;

constructor(data: any) {
super(data.id, data.name);
super(data.id, data.name, data);
this.short_name = data.short_name;
}
}
6 changes: 3 additions & 3 deletions src/app/_models/session.model.ts
@@ -1,10 +1,10 @@
import {AbstractEntityWithName} from 'dfx-helper';
import {AbstractEntityWithNumberIDAndName} from 'dfx-helper';

export class SessionsModel extends AbstractEntityWithName<number> {
export class SessionsModel extends AbstractEntityWithNumberIDAndName {
public readonly registered_at: string;

constructor(data: any) {
super(data.id, data.name);
super(data.id, data.name, data);
this.registered_at = data.registered_at;
}
}
6 changes: 3 additions & 3 deletions src/app/_models/table-group.model.ts
@@ -1,11 +1,11 @@
import {AbstractEntityWithName} from 'dfx-helper';
import {AbstractEntityWithNumberIDAndName} from 'dfx-helper';

export class TableGroupModel extends AbstractEntityWithName<number> {
export class TableGroupModel extends AbstractEntityWithNumberIDAndName {
public seats: number;
public event_id: number;

constructor(data: any) {
super(data.id, data.name);
super(data.id, data.name, data);
this.seats = data.seats;
this.event_id = data.event_id;
}
Expand Down
6 changes: 3 additions & 3 deletions src/app/_models/table.model.ts
@@ -1,14 +1,14 @@
import {AbstractEntityWithName, Converter} from 'dfx-helper';
import {AbstractEntityWithNumberIDAndName, Converter} from 'dfx-helper';

export class TableModel extends AbstractEntityWithName<number> {
export class TableModel extends AbstractEntityWithNumberIDAndName {
public tableNumber: number;
public seats: number;
public group_id: number;
public group_name: string | undefined;
public event_id: number;

constructor(data: any) {
super(data.id, Converter.numberToString(data.number));
super(data.id, Converter.numberToString(data.number), data);
this.tableNumber = data.number;
this.seats = data.seats;
this.group_id = data.group_id;
Expand Down
6 changes: 3 additions & 3 deletions src/app/_models/user.model.ts
@@ -1,14 +1,14 @@
import {AbstractEntityWithName} from 'dfx-helper';
import {AbstractEntityWithNumberIDAndName} from 'dfx-helper';

export class UserModel extends AbstractEntityWithName<number> {
export class UserModel extends AbstractEntityWithNumberIDAndName {
public readonly email_address: string;
public readonly firstname: string;
public readonly surname: string;
public readonly birthday: Date;
public is_admin: boolean;

constructor(data: any) {
super(data.id, data.firstname + ' ' + data.surname);
super(data.id, data.firstname + ' ' + data.surname, data);
this.email_address = data.email_address;
this.firstname = data.firstname;
this.surname = data.surname;
Expand Down
6 changes: 3 additions & 3 deletions src/app/_models/waiter.model.ts
@@ -1,12 +1,12 @@
import {AbstractEntityWithName} from 'dfx-helper';
import {AbstractEntityWithNumberIDAndName} from 'dfx-helper';

export class WaiterModel extends AbstractEntityWithName<number> {
export class WaiterModel extends AbstractEntityWithNumberIDAndName {
public readonly token: string;
public readonly organisation_id: number;
public readonly event_ids: number[];

constructor(data: any) {
super(data.id, data.name);
super(data.id, data.name, data);
this.token = data.token;
this.organisation_id = data.organisation_id;
this.event_ids = data.event_ids;
Expand Down
2 changes: 1 addition & 1 deletion src/app/_services/tables.service.ts
Expand Up @@ -19,7 +19,7 @@ export class TablesService extends AbstractModelService<TableModel> {
});
}

public setEventGetAllUrl(): void {
public setSelectedEventGetAllUrl(): void {
this.setGetAllUrl('/config/table?event_id=' + this.eventsService.getSelected()?.id);
}

Expand Down
12 changes: 11 additions & 1 deletion src/app/_services/waiters.service.ts
Expand Up @@ -4,13 +4,23 @@ import {HttpService} from './http.service';
import {AbstractModelService} from './abstract-model.service';

import {WaiterModel} from '../_models/waiter.model';
import {OrganisationsService} from './organisations.service';

@Injectable({
providedIn: 'root',
})
export class WaitersService extends AbstractModelService<WaiterModel> {
constructor(httpService: HttpService) {
constructor(httpService: HttpService, private organisationService: OrganisationsService) {
super(httpService, '/config/waiter');

this.setGetAllUrl('/config/table?event_id=' + this.organisationService.getSelected()?.id);
this.organisationService.selectedChange.subscribe((org) => {
this.setGetAllUrl('/config/waiter?organisation_id=' + org?.id);
});
}

public setSelectedOrganisationGetAllUrl(): void {
this.setGetAllUrl('/config/waiter?organisation_id=' + this.organisationService.getSelected()?.id);
}

protected convert(jsonData: any): WaiterModel {
Expand Down
Expand Up @@ -23,8 +23,8 @@ export class AppDownloadBtnListComponent {
{
text: 'F-Droid',
link: 'https://f-droid.org',
img: 'assets/fdroidLogo.svg',
img2: 'assets/fdroidLogo_black.svg',
img: 'assets/store_logos/fdroidLogo.svg',
img2: 'assets/store_logos/fdroidLogo_black.svg',
},
{
text: 'App Store',
Expand All @@ -34,8 +34,8 @@ export class AppDownloadBtnListComponent {
{
text: 'AppGallery',
link: 'https://appgallery.huawei.com',
img: 'assets/appGallery.svg',
img2: 'assets/appGallery_black.svg',
img: 'assets/store_logos/appGallery.svg',
img2: 'assets/store_logos/appGallery_black.svg',
},
{
text: 'Play Store',
Expand Down
8 changes: 4 additions & 4 deletions src/app/home/tables/all-tables/all-tables.component.ts
Expand Up @@ -18,14 +18,14 @@ import {EventModel} from '../../../_models/event.model';
export class AllTablesComponent extends AbstractModelsListComponent<TableModel> {
selectedEvent: EventModel | undefined;

constructor(protected modelService: TablesService, modal: NgbModal) {
super(modelService, modal);
constructor(protected entitiesService: TablesService, modal: NgbModal) {
super(entitiesService, modal);

this.modelService.setEventGetAllUrl();
this.entitiesService.setSelectedEventGetAllUrl();
}

protected override initializeVariables(): void {
this.modelService.setEventGetAllUrl();
this.entitiesService.setSelectedEventGetAllUrl();
super.initializeVariables();
}

Expand Down
Expand Up @@ -31,14 +31,12 @@ <h1>"{{ selectedOrganisation?.name }}" {{ 'HOME_WAITERS_NAV_ORGANISATION' | tr }
<table class="table table-dark table-hover">
<thead>
<tr class="table-dark">
<th sortable="id" (sort)="onSort($event)">#</th>
<th sortable="name" (sort)="onSort($event)" style="min-width: 20vh">{{ 'NAME' | tr }}</th>
<th style="min-width: 20vh">{{ 'ACTIONS' | tr }}</th>
</tr>
</thead>
<tbody>
<tr *ngFor="let waiter of entitiesCopy" class="table-dark clickable" (click)="openQRCode(waiter)">
<th>{{ waiter.id }}</th>
<td>{{ waiter.name }}</td>
<td (click)="$event.stopPropagation()">
<a class="btn btn-sm m-1 btn-outline-success text-white" routerLink="../{{ waiter.id }}" ngbTooltip="{{ 'EDIT' | tr }}">
Expand Down
Expand Up @@ -20,24 +20,20 @@ import {WaiterQRCodeModalComponent} from '../waiter-qr-code-modal.component';
export class OrganisationWaitersComponent extends AbstractModelsListComponent<WaiterModel> {
selectedOrganisation: OrganisationModel | undefined;

constructor(waitersService: WaitersService, organisationsService: OrganisationsService, modal: NgbModal) {
super(waitersService, modal);
constructor(protected entitiesService: WaitersService, organisationsService: OrganisationsService, modal: NgbModal) {
super(entitiesService, modal);

this.selectedOrganisation = organisationsService.getSelected();
this.initializeVariables();
this.autoUnsubscribe(
organisationsService.selectedChange.subscribe((organisation) => {
this.selectedOrganisation = organisation;
this.initializeVariables();
organisationsService.selectedChange.subscribe((org) => {
this.selectedOrganisation = org;
})
);
this.entitiesService.setSelectedOrganisationGetAllUrl();
}

protected override initializeVariables(): void {
if (!this.selectedOrganisation) {
return;
}
this.modelService.setGetAllUrl('/config/waiter?organisation_id=' + Converter.numberToString(this.selectedOrganisation.id));
this.entitiesService.setSelectedOrganisationGetAllUrl();
super.initializeVariables();
}

Expand Down
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes

0 comments on commit 7c13ae3

Please sign in to comment.