fix
This commit is contained in:
@@ -95,7 +95,7 @@ export const ROUTES: RouteInfo[] = [
|
||||
},
|
||||
{
|
||||
path: '/settings/item-categories',
|
||||
title: '',
|
||||
title: 'MENUITEMS.SETTINGS.LIST.ITEMCATEGORIES',
|
||||
iconType: '',
|
||||
icon: '',
|
||||
class: 'ml-menu',
|
||||
|
||||
@@ -3,6 +3,9 @@ export interface MotionModel {
|
||||
date?: Date;
|
||||
item?: string;
|
||||
description?: string;
|
||||
itemId?: string;
|
||||
accountId?: string;
|
||||
plus?: number;
|
||||
minus?: number;
|
||||
amountBalancing?: number;
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ import { EventEmitter } from '@angular/core';
|
||||
|
||||
// libs
|
||||
import * as moment from 'moment';
|
||||
import { Observable } from 'rxjs';
|
||||
|
||||
// app
|
||||
import { ApiRoutes } from '../../api-routes';
|
||||
@@ -28,8 +29,9 @@ export class AccountComponent {
|
||||
public form!: UntypedFormGroup;
|
||||
@Input('account') account!: AccountDetailedModel;
|
||||
@Input('active') active: boolean = false;
|
||||
@Input() reloadEvent!: Observable<string[]>;
|
||||
|
||||
@Output() onUpdate: EventEmitter<MotionModel> = new EventEmitter<MotionModel>();
|
||||
@Output() onUpdate: EventEmitter<MotionModel[]> = new EventEmitter<MotionModel[]>();
|
||||
|
||||
constructor(
|
||||
private fb: UntypedFormBuilder,
|
||||
@@ -55,13 +57,21 @@ export class AccountComponent {
|
||||
],
|
||||
});
|
||||
this.loadMotions();
|
||||
|
||||
this.reloadEvent.subscribe(x => {
|
||||
if (x.find(x => x === this.account.account.id)) {
|
||||
this.loadMotions();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
onSubmitClick() {
|
||||
}
|
||||
|
||||
handlerOnAdd(motion: MotionModel) {
|
||||
handlerOnAdd(motions: MotionModel[]) {
|
||||
this.onUpdate?.emit(motions.filter(x => x.accountId !== this.account.account!.id));
|
||||
this.loadMotions();
|
||||
|
||||
this.httpClient
|
||||
.get<AccountDetailedModel>(ApiRoutes.Account.replace(':id', this.account.account!.id!))
|
||||
.subscribe(data => {
|
||||
@@ -93,6 +103,10 @@ export class AccountComponent {
|
||||
refresh += window.location.host;
|
||||
refresh += window.location.pathname;
|
||||
refresh += window.location.hash;
|
||||
var idx = refresh.indexOf('/account/');
|
||||
if (idx > -1) {
|
||||
refresh = refresh.substr(0, idx);
|
||||
}
|
||||
refresh += '/account/' + this.account.account.id;
|
||||
window.history.pushState({ path: refresh }, '', refresh);
|
||||
}
|
||||
|
||||
@@ -8,8 +8,11 @@
|
||||
<div class="row clearfix">
|
||||
<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
|
||||
<mat-accordion class="main-headers-align" multi>
|
||||
<div *ngFor="let account of accounts; let i = index" >
|
||||
<account [account]="account" [active]="account.account.id === activeAccount" />
|
||||
<div *ngFor="let account of accounts; let i = index">
|
||||
<account [account]="account"
|
||||
[active]="account.account.id === activeAccount"
|
||||
(onUpdate)="handlerOnUpdate($event)"
|
||||
[reloadEvent]="reloadSubject.asObservable()" />
|
||||
</div>
|
||||
</mat-accordion>
|
||||
</div>
|
||||
|
||||
@@ -4,11 +4,13 @@ import { HttpClient } from '@angular/common/http';
|
||||
import { ActivatedRoute } from '@angular/router';
|
||||
|
||||
// libs
|
||||
import { Subject } from 'rxjs';
|
||||
|
||||
// app
|
||||
import { AccountCategoryService } from '../../services/account.category.service';
|
||||
import { ApiRoutes } from '../../api-routes';
|
||||
import { AccountDetailedModel } from '../../model/account.detailed.model';
|
||||
import { MotionModel } from '../../model/motion.model';
|
||||
|
||||
@Component({
|
||||
templateUrl: './account.list.component.html',
|
||||
@@ -19,6 +21,8 @@ export class AccountListComponent {
|
||||
public category = '';
|
||||
public activeAccount = '';
|
||||
|
||||
reloadSubject: Subject<string[]> = new Subject<string[]>();
|
||||
|
||||
constructor(
|
||||
private httpClient: HttpClient,
|
||||
private activatedRoute: ActivatedRoute,
|
||||
@@ -43,4 +47,8 @@ export class AccountListComponent {
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
handlerOnUpdate(motions: MotionModel[]) {
|
||||
this.reloadSubject.next(motions.map(x => x.accountId!));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
Motion
|
||||
<span *ngIf="selectedItem">!!</span>
|
||||
</mat-label>
|
||||
<input #motionInput matInput formControlName="item" required [matAutocomplete]="auto">
|
||||
<input autocomplete="off" #motionInput matInput formControlName="item" required [matAutocomplete]="auto">
|
||||
<mat-error *ngIf="form.controls['item'].hasError('required') && !form.pristine">
|
||||
Please enter motion
|
||||
</mat-error>
|
||||
@@ -38,7 +38,7 @@
|
||||
</mat-autocomplete>
|
||||
</mat-form-field>
|
||||
<mat-form-field class="example-full-width" appearance="fill">
|
||||
<input matInput formControlName="description">
|
||||
<input autocomplete="off" matInput formControlName="description">
|
||||
</mat-form-field>
|
||||
</div>
|
||||
<div class="" style="width: 100px; min-width: 100px;">
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
.mat-mdc-option.mdc-list-item.mat-mdc-option-active {
|
||||
filter: brightness(50%)
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ export class MotionComponent {
|
||||
@Input('motion') motion!: MotionModel;
|
||||
@Input('account') account!: AccountModel;
|
||||
|
||||
@Output() onAdd: EventEmitter<MotionModel> = new EventEmitter<MotionModel>();
|
||||
@Output() onAdd: EventEmitter<MotionModel[]> = new EventEmitter<MotionModel[]>();
|
||||
@Output() onDelete: EventEmitter<MotionModel> = new EventEmitter<MotionModel>();
|
||||
|
||||
@ViewChild('motionInput') motionInput?: ElementRef;
|
||||
@@ -93,6 +93,15 @@ export class MotionComponent {
|
||||
this.filteredItems = x;
|
||||
});
|
||||
});
|
||||
|
||||
this.form.valueChanges.subscribe(val => {
|
||||
this.form.controls['plus'].markAsPristine();
|
||||
this.form.controls['plus'].markAsUntouched();
|
||||
this.form.controls['plus'].setErrors(null);
|
||||
this.form.controls['minus'].markAsPristine();
|
||||
this.form.controls['minus'].markAsUntouched();
|
||||
this.form.controls['minus'].setErrors(null);
|
||||
});
|
||||
}
|
||||
|
||||
displayFn(item: any): string {
|
||||
@@ -107,24 +116,36 @@ export class MotionComponent {
|
||||
add() {
|
||||
this.form.markAllAsTouched();
|
||||
|
||||
if (this.form.hasError('atLeastOne')) {
|
||||
this.form.get('plus')!.setErrors(this.form.errors);
|
||||
this.form.get('minus')!.setErrors(this.form.errors);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!this.form.valid) {
|
||||
if (this.form.hasError('atLeastOne')) {
|
||||
this.form.get('plus')!.setErrors(this.form.errors);
|
||||
this.form.get('minus')!.setErrors(this.form.errors);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
this.setInProgress();
|
||||
|
||||
var data = this.form.value;
|
||||
data.motion = data.item.name
|
||||
? data.item.name
|
||||
: data.item;
|
||||
data.itemId = this.selectedItem?.id;
|
||||
var data: MotionModel = {
|
||||
description: this.form.value.description,
|
||||
plus: this.form.value.plus || 0,
|
||||
minus: this.form.value.minus || 0,
|
||||
};
|
||||
|
||||
if (this.form.value.item.name) {
|
||||
data.date = this.form.value.date;
|
||||
data.item = this.form.value.item.name;
|
||||
data.itemId = this.form.value.item.id;
|
||||
data.accountId = this.form.value.item.accountId;
|
||||
data.amountBalancing = data.plus! > 0 ? data.plus : data.minus;
|
||||
} else {
|
||||
data.item = this.form.value.item;
|
||||
}
|
||||
|
||||
this.httpClient
|
||||
.post<MotionModel>(ApiRoutes.Motions.replace(':id', this.account.id!), data)
|
||||
.post<MotionModel[]>(ApiRoutes.Motions.replace(':id', this.account.id!), data)
|
||||
.subscribe(response => {
|
||||
this.onAdd?.emit(response);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user