fix
This commit is contained in:
@@ -1,91 +1,99 @@
|
||||
// angular
|
||||
import { Component } from '@angular/core';
|
||||
import { Input } from '@angular/core';
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import { ActivatedRoute } from '@angular/router';
|
||||
import { UntypedFormGroup } from '@angular/forms';
|
||||
import { Validators } from '@angular/forms';
|
||||
import { UntypedFormBuilder } from '@angular/forms';
|
||||
import { Output } from '@angular/core';
|
||||
import { EventEmitter } from '@angular/core';
|
||||
|
||||
// libs
|
||||
import Swal from 'sweetalert2';
|
||||
import { MatDialog } from '@angular/material/dialog';
|
||||
import * as moment from 'moment';
|
||||
|
||||
// app
|
||||
import { AccountCategoryService } from '../../services/account.category.service';
|
||||
import { ApiRoutes } from '../../api-routes';
|
||||
import { AccountCategoryModel } from '../../model/account.category.model';
|
||||
import { SettingsAccountAddComponent } from '../settings/account/add.account.component';
|
||||
import { SettingsAccountEditComponent } from '../settings/account/edit.account.component';
|
||||
import { AccountModel } from '../../model/account.model';
|
||||
import { AccountDetailedModel } from '../../model/account.detailed.model';
|
||||
import { AccountMotionModel } from '../../model/account.motion';
|
||||
|
||||
@Component({
|
||||
templateUrl: './account.component.html',
|
||||
styleUrls: ['./account.component.scss'],
|
||||
selector: 'account'
|
||||
})
|
||||
export class AccountComponent {
|
||||
public accounts?: AccountDetailedModel[];
|
||||
public motions?: AccountMotionModel[];
|
||||
public newMotion: AccountMotionModel;
|
||||
public form!: UntypedFormGroup;
|
||||
@Input('account') account!: AccountDetailedModel;
|
||||
@Input('expanded') expanded!: boolean;
|
||||
|
||||
@Output() onUpdate: EventEmitter<AccountMotionModel> = new EventEmitter<AccountMotionModel>();
|
||||
|
||||
constructor(
|
||||
private fb: UntypedFormBuilder,
|
||||
private httpClient: HttpClient,
|
||||
private dialogModel: MatDialog,
|
||||
private activatedRoute: ActivatedRoute
|
||||
) {
|
||||
this.newMotion = {
|
||||
date: new Date(),
|
||||
plus: 0,
|
||||
minus: 0,
|
||||
};
|
||||
}
|
||||
|
||||
ngOnInit(): void {
|
||||
this.form = this.fb.group({
|
||||
dateFrom: [
|
||||
moment(new Date).add(-7, 'days').toDate(),
|
||||
[Validators.required],
|
||||
],
|
||||
dateTo: [
|
||||
new Date,
|
||||
[Validators.required],
|
||||
],
|
||||
});
|
||||
this.loadMotions();
|
||||
}
|
||||
|
||||
onSubmitClick() {
|
||||
}
|
||||
|
||||
handlerOnAdd(accountMotion: AccountMotionModel) {
|
||||
this.loadMotions();
|
||||
this.httpClient
|
||||
.get<AccountDetailedModel>(ApiRoutes.Account.replace(':id', this.account.account!.id!))
|
||||
.subscribe(data => {
|
||||
this.account = data;
|
||||
});
|
||||
|
||||
/*var md = moment(accountMotion.date);
|
||||
var mdf = moment(this.form.value.dateFrom);
|
||||
var mdt = moment(this.form.value.dateTo);
|
||||
if (md.isBetween(mdf, mdt, 'days', '[]')) {
|
||||
this.motions?.push(accountMotion);
|
||||
//this.motions?.sort((a, b) => (b.date!.getMilliseconds() - a.date!.getMilliseconds()));
|
||||
this.motions?.sort((a, b) => {
|
||||
var aa = moment(a.date).toDate();
|
||||
var bb = moment(b.date).toDate();
|
||||
|
||||
return (bb.getMilliseconds() - aa.getMilliseconds());
|
||||
});
|
||||
}*/
|
||||
}
|
||||
|
||||
private loadMotions() {
|
||||
var url = ApiRoutes.Motions.replace(':id', this.account.account.id!);
|
||||
url += '?from=' + moment(this.form.value.dateFrom).format('yyyy-MM-DD');
|
||||
url += '&to=' + moment(this.form.value.dateTo).format('yyyy-MM-DD');
|
||||
|
||||
this.activatedRoute.params.subscribe(params => {
|
||||
this.httpClient
|
||||
.get<AccountDetailedModel[]>(ApiRoutes.Accounts + "?category=" + params['id'])
|
||||
.get<AccountMotionModel[]>(url)
|
||||
.subscribe(data => {
|
||||
this.accounts = data;
|
||||
this.motions = data;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/*private loadAccounts() {
|
||||
}*/
|
||||
|
||||
/*private loadCategories() {
|
||||
this.accountCategoryService
|
||||
.getCategories()
|
||||
.subscribe(x => {
|
||||
this.accountCategories = x;
|
||||
this.loadAccounts();
|
||||
});
|
||||
}*/
|
||||
|
||||
/*public accountInCategory(category?: AccountCategoryModel) {
|
||||
if (this.accounts) {
|
||||
return this.accounts.filter(acc => (!category && (!acc.categories || acc.categories.length === 0)) || (category && acc.categories && acc.categories.filter(cat => cat.id === category.id).length > 0));
|
||||
}
|
||||
return null;
|
||||
}*/
|
||||
|
||||
/*public add() {
|
||||
this.dialogModel.open(SettingsAccountAddComponent, {
|
||||
width: '640px',
|
||||
disableClose: true,
|
||||
data: this.accounts,
|
||||
}).afterClosed().subscribe(x => {
|
||||
if (x && x.refresh) {
|
||||
this.loadAccounts();
|
||||
}
|
||||
});
|
||||
}*/
|
||||
|
||||
/*public edit(account: AccountModel) {
|
||||
this.dialogModel.open(SettingsAccountEditComponent, {
|
||||
width: '640px',
|
||||
disableClose: true,
|
||||
data: account,
|
||||
}).afterClosed().subscribe(x => {
|
||||
if (x && x.refresh) {
|
||||
this.loadAccounts();
|
||||
}
|
||||
});
|
||||
}*/
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user