update
This commit is contained in:
@@ -1,5 +1,9 @@
|
||||
// angular
|
||||
import { NgModule, Optional, SkipSelf, CUSTOM_ELEMENTS_SCHEMA, APP_INITIALIZER } from '@angular/core';
|
||||
import { NgModule } from '@angular/core';
|
||||
import { Optional } from '@angular/core';
|
||||
import { SkipSelf } from '@angular/core';
|
||||
import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
|
||||
import { APP_INITIALIZER } from '@angular/core';
|
||||
import { CommonModule } from '@angular/common';
|
||||
|
||||
// libs
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
export interface AccountMotionModel {
|
||||
export interface MotionModel {
|
||||
id?: string;
|
||||
date?: Date;
|
||||
motion?: string;
|
||||
@@ -1,4 +1,4 @@
|
||||
<mat-expansion-panel [expanded]="expanded">
|
||||
<mat-expansion-panel [expanded]="active" (afterExpand)="afterExpand()">
|
||||
<mat-expansion-panel-header>
|
||||
<mat-panel-description>
|
||||
<h4>{{account.account.name}}</h4>
|
||||
@@ -36,9 +36,12 @@
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
<hr/>
|
||||
<hr />
|
||||
<account-motion [motion]="newMotion" [account]="account.account" (onAdd)="handlerOnAdd($event)">
|
||||
</account-motion>
|
||||
<account-motion *ngFor="let motion of motions" [motion]="motion" [account]="account.account">
|
||||
<account-motion *ngFor="let motion of motions"
|
||||
[motion]="motion"
|
||||
[account]="account.account"
|
||||
(onDelete)="handlerOnDelete($event)">
|
||||
</account-motion>
|
||||
</mat-expansion-panel>
|
||||
|
||||
@@ -15,7 +15,7 @@ import * as moment from 'moment';
|
||||
// app
|
||||
import { ApiRoutes } from '../../api-routes';
|
||||
import { AccountDetailedModel } from '../../model/account.detailed.model';
|
||||
import { AccountMotionModel } from '../../model/account.motion';
|
||||
import { MotionModel } from '../../model/motion.model';
|
||||
|
||||
@Component({
|
||||
templateUrl: './account.component.html',
|
||||
@@ -23,13 +23,13 @@ import { AccountMotionModel } from '../../model/account.motion';
|
||||
selector: 'account'
|
||||
})
|
||||
export class AccountComponent {
|
||||
public motions?: AccountMotionModel[];
|
||||
public newMotion: AccountMotionModel;
|
||||
public motions?: MotionModel[];
|
||||
public newMotion: MotionModel;
|
||||
public form!: UntypedFormGroup;
|
||||
@Input('account') account!: AccountDetailedModel;
|
||||
@Input('expanded') expanded!: boolean;
|
||||
@Input('active') active: boolean = false;
|
||||
|
||||
@Output() onUpdate: EventEmitter<AccountMotionModel> = new EventEmitter<AccountMotionModel>();
|
||||
@Output() onUpdate: EventEmitter<MotionModel> = new EventEmitter<MotionModel>();
|
||||
|
||||
constructor(
|
||||
private fb: UntypedFormBuilder,
|
||||
@@ -60,27 +60,18 @@ export class AccountComponent {
|
||||
onSubmitClick() {
|
||||
}
|
||||
|
||||
handlerOnAdd(accountMotion: AccountMotionModel) {
|
||||
handlerOnAdd(motion: MotionModel) {
|
||||
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());
|
||||
});
|
||||
}*/
|
||||
handlerOnDelete(motion: MotionModel) {
|
||||
const index = this.motions!.findIndex(x => x.id === motion.id);
|
||||
this.motions!.splice(index, 1);
|
||||
}
|
||||
|
||||
private loadMotions() {
|
||||
@@ -90,10 +81,19 @@ export class AccountComponent {
|
||||
|
||||
this.activatedRoute.params.subscribe(params => {
|
||||
this.httpClient
|
||||
.get<AccountMotionModel[]>(url)
|
||||
.get<MotionModel[]>(url)
|
||||
.subscribe(data => {
|
||||
this.motions = data;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
afterExpand() {
|
||||
var refresh = window.location.protocol + "//";
|
||||
refresh += window.location.host;
|
||||
refresh += window.location.pathname;
|
||||
refresh += window.location.hash;
|
||||
refresh += '/account/' + this.account.account.id;
|
||||
window.history.pushState({ path: refresh }, '', refresh);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
<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" />
|
||||
<account [account]="account" [active]="account.account.id === activeAccount" />
|
||||
</div>
|
||||
</mat-accordion>
|
||||
</div>
|
||||
|
||||
@@ -4,18 +4,11 @@ import { HttpClient } from '@angular/common/http';
|
||||
import { ActivatedRoute } from '@angular/router';
|
||||
|
||||
// libs
|
||||
import Swal from 'sweetalert2';
|
||||
import { MatDialog } from '@angular/material/dialog';
|
||||
|
||||
// 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.list.component.html',
|
||||
@@ -24,12 +17,14 @@ import { AccountMotionModel } from '../../model/account.motion';
|
||||
export class AccountListComponent {
|
||||
public accounts?: AccountDetailedModel[];
|
||||
public category = '';
|
||||
public activeAccount = '';
|
||||
|
||||
constructor(
|
||||
private httpClient: HttpClient,
|
||||
private activatedRoute: ActivatedRoute,
|
||||
private accountCategoryService: AccountCategoryService,
|
||||
) {
|
||||
this.activatedRoute.params.subscribe(x => this.activeAccount = x['accountId']);
|
||||
}
|
||||
|
||||
ngOnInit(): void {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<form [formGroup]="form" (ngSubmit)="onSubmitClick()" novalidate autocomplete="off">
|
||||
<form [formGroup]="form" novalidate autocomplete="off">
|
||||
<div class="" style="display: flex;">
|
||||
<div class="" style="width: 310px; min-width: 310px;">
|
||||
<div style="display: flex; align-items: center;">
|
||||
@@ -42,19 +42,24 @@
|
||||
</mat-form-field>
|
||||
</div>
|
||||
<div class="" style="display: inline-block; width: 150px; min-width: 150px;">
|
||||
<button type="button" mat-stroked-button color="primary" *ngIf="!motion.id" (click)="onSubmitClick()">
|
||||
<!--
|
||||
<button type="button" mat-stroked-button color="primary" *ngIf="!motion.id" (click)="add()">
|
||||
<i class="material-icons font-40">add</i>
|
||||
</button>
|
||||
<button mat-stroked-button color="primary" *ngIf="!motion.id" (click)="onSubmitClick()">
|
||||
<i class="material-icons font-40">import_export</i>
|
||||
-->
|
||||
<button type="button" class="m-2" mat-mini-fab color="primary" *ngIf="!motion.id" (click)="add()">
|
||||
<i class="material-icons ">add</i>
|
||||
</button>
|
||||
<button mat-stroked-button color="primary" *ngIf="motion.id" (click)="onSubmitClick()">
|
||||
<i class="material-icons font-40">save</i>
|
||||
<button type="button" class="m-2" mat-mini-fab color="primary" *ngIf="!motion.id" (click)="import()">
|
||||
<i class="material-icons ">import_export</i>
|
||||
</button>
|
||||
<button mat-stroked-button color="primary" *ngIf="motion.id" (click)="onSubmitClick()">
|
||||
<i class="material-icons font-40">delete</i>
|
||||
<button type="button" class="m-2" mat-mini-fab color="primary" *ngIf="motion.id" (click)="update()">
|
||||
<i class="material-icons ">save</i>
|
||||
</button>
|
||||
<button type="button" class="m-2" mat-mini-fab color="primary" *ngIf="motion.id" (click)="delete()">
|
||||
<i class="material-icons ">delete</i>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<hr/>
|
||||
<hr />
|
||||
</form>
|
||||
|
||||
@@ -12,11 +12,12 @@ import { ElementRef } from '@angular/core';
|
||||
|
||||
// libs
|
||||
import * as moment from 'moment';
|
||||
import Swal from 'sweetalert2';
|
||||
|
||||
// app
|
||||
import { ApiRoutes } from '../../api-routes';
|
||||
import { AccountModel } from '../../model/account.model';
|
||||
import { AccountMotionModel } from '../../model/account.motion';
|
||||
import { MotionModel } from '../../model/motion.model';
|
||||
import { atLeastOneNumber } from '../../core/validators/atleastonenumber.validator';
|
||||
|
||||
@Component({
|
||||
@@ -28,10 +29,11 @@ export class MotionComponent {
|
||||
public form!: FormGroup;
|
||||
public errorMessage?: string;
|
||||
|
||||
@Input('motion') motion!: AccountMotionModel;
|
||||
@Input('motion') motion!: MotionModel;
|
||||
@Input('account') account!: AccountModel;
|
||||
|
||||
@Output() onAdd: EventEmitter<AccountMotionModel> = new EventEmitter<AccountMotionModel>();
|
||||
@Output() onAdd: EventEmitter<MotionModel> = new EventEmitter<MotionModel>();
|
||||
@Output() onDelete: EventEmitter<MotionModel> = new EventEmitter<MotionModel>();
|
||||
|
||||
@ViewChild('motionInput') motionInput?: ElementRef;
|
||||
|
||||
@@ -68,28 +70,75 @@ export class MotionComponent {
|
||||
});
|
||||
}
|
||||
|
||||
onSubmitClick() {
|
||||
add() {
|
||||
this.form.markAllAsTouched();
|
||||
|
||||
if (this.form.valid) {
|
||||
this.httpClient
|
||||
.post<AccountMotionModel>(ApiRoutes.Motions.replace(':id', this.account.id!), this.form.value)
|
||||
.subscribe(response => {
|
||||
if (!this.form.value.id) {
|
||||
this.onAdd?.emit(response);
|
||||
this.form.patchValue({
|
||||
motion: '',
|
||||
plus: 0,
|
||||
minus: 0,
|
||||
});
|
||||
this.form.markAsUntouched();
|
||||
this.httpClient
|
||||
.post<MotionModel>(ApiRoutes.Motions.replace(':id', this.account.id!), this.form.value)
|
||||
.subscribe(response => {
|
||||
this.onAdd?.emit(response);
|
||||
|
||||
this.motionInput?.nativeElement.focus();
|
||||
}
|
||||
}, error => {
|
||||
this.errorMessage = error.detail;
|
||||
this.form.patchValue({
|
||||
motion: '',
|
||||
plus: 0,
|
||||
minus: 0,
|
||||
});
|
||||
}
|
||||
this.form.markAsUntouched();
|
||||
|
||||
this.motionInput?.nativeElement.focus();
|
||||
}, error => {
|
||||
this.errorMessage = error.detail;
|
||||
});
|
||||
}
|
||||
|
||||
update() {
|
||||
var url = ApiRoutes.Motion
|
||||
.replace(':id', this.account.id!)
|
||||
.replace(':motionId', this.motion.id!);
|
||||
|
||||
this.httpClient
|
||||
.put<MotionModel>(url, this.form.value)
|
||||
.subscribe(response => {
|
||||
this.form.markAsUntouched();
|
||||
}, error => {
|
||||
this.errorMessage = error.detail;
|
||||
});
|
||||
}
|
||||
|
||||
delete() {
|
||||
Swal.fire({
|
||||
title: 'Delete motion ' + this.motion.motion,
|
||||
showCancelButton: true,
|
||||
confirmButtonText: 'Delete',
|
||||
showLoaderOnConfirm: true,
|
||||
preConfirm: (name) => {
|
||||
return new Promise<MotionModel>((resolve, reject) => {
|
||||
var url = ApiRoutes.Motion
|
||||
.replace(':id', this.account.id!)
|
||||
.replace(':motionId', this.motion.id!);
|
||||
|
||||
this.httpClient.delete<MotionModel>(url)
|
||||
.subscribe(data => {
|
||||
resolve(data);
|
||||
}, error => {
|
||||
Swal.showValidationMessage(error.detail);
|
||||
reject();
|
||||
});
|
||||
|
||||
}).catch(x => {
|
||||
return false;
|
||||
});
|
||||
},
|
||||
allowOutsideClick: () => !Swal.isLoading(),
|
||||
}).then((result) => {
|
||||
if (result.isConfirmed) {
|
||||
this.onDelete?.emit((result.value! as MotionModel));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
import() {
|
||||
|
||||
}
|
||||
|
||||
addDay(days: number) {
|
||||
|
||||
@@ -42,6 +42,10 @@ const routes: Routes = [
|
||||
path: 'account-category/:id',
|
||||
component: AccountListComponent,
|
||||
},
|
||||
{
|
||||
path: 'account-category/:id/account/:accountId',
|
||||
component: AccountListComponent,
|
||||
},
|
||||
];
|
||||
|
||||
@NgModule({
|
||||
|
||||
@@ -79,7 +79,7 @@ import { MotionComponent } from './accounts/motion.component';
|
||||
MatCardModule,
|
||||
MatExpansionModule,
|
||||
NgxMaskModule,
|
||||
NgxCurrencyModule,
|
||||
NgxCurrencyModule
|
||||
],
|
||||
providers: [
|
||||
{ provide: MAT_DATE_LOCALE, useValue: 'en-GB' },
|
||||
|
||||
@@ -96,7 +96,7 @@ export class SettingsAccountCategoryComponent {
|
||||
|
||||
public remove(category: AccountCategoryModel) {
|
||||
Swal.fire({
|
||||
title: 'Remove account category ' + category.name,
|
||||
title: 'Delete account category ' + category.name,
|
||||
showCancelButton: true,
|
||||
confirmButtonText: 'Delete',
|
||||
showLoaderOnConfirm: true,
|
||||
|
||||
@@ -96,7 +96,7 @@ export class SettingsItemCategoryComponent {
|
||||
|
||||
public remove(category: ItemCategoryModel) {
|
||||
Swal.fire({
|
||||
title: 'Remove item category ' + category.name,
|
||||
title: 'Delete item category ' + category.name,
|
||||
showCancelButton: true,
|
||||
confirmButtonText: 'Delete',
|
||||
showLoaderOnConfirm: true,
|
||||
|
||||
@@ -72,7 +72,7 @@ export class SettingsItemComponent {
|
||||
|
||||
public remove(category: ItemModel) {
|
||||
Swal.fire({
|
||||
title: 'Remove item from ' + category.name,
|
||||
title: 'Delete item from ' + category.name,
|
||||
showCancelButton: true,
|
||||
confirmButtonText: 'Delete',
|
||||
showLoaderOnConfirm: true,
|
||||
|
||||
Reference in New Issue
Block a user