Feature: Added hotkeys in vouchers for selecting date (f2), save (ctrl+s) and post (ctrl+p)

This commit is contained in:
Amritanshu 2019-05-07 14:59:51 +05:30
parent 017c828474
commit 120b9544f8
21 changed files with 172 additions and 25 deletions

@ -26,6 +26,7 @@
"@angular/router": "^7.1.0", "@angular/router": "^7.1.0",
"@ngx-loading-bar/http-client": "^3.0.0", "@ngx-loading-bar/http-client": "^3.0.0",
"@ngx-loading-bar/router": "^3.0.0", "@ngx-loading-bar/router": "^3.0.0",
"angular2-hotkeys": "^2.1.4",
"core-js": "^2.5.7", "core-js": "^2.5.7",
"hammerjs": "^2.0.8", "hammerjs": "^2.0.8",
"mathjs": "^5.0.4", "mathjs": "^5.0.4",

@ -66,6 +66,7 @@ import {AttendanceModule} from './attendance/attendance.module';
import {EmployeeAttendanceModule} from './employee-attendance/employee-attendance.module'; import {EmployeeAttendanceModule} from './employee-attendance/employee-attendance.module';
import {RawMaterialCostModule} from './raw-material-cost/raw-material-cost.module'; import {RawMaterialCostModule} from './raw-material-cost/raw-material-cost.module';
import {FlexLayoutModule} from "@angular/flex-layout"; import {FlexLayoutModule} from "@angular/flex-layout";
import {HotkeyModule} from "angular2-hotkeys";
registerLocaleData(enIN); registerLocaleData(enIN);
@ -81,6 +82,7 @@ registerLocaleData(enIN);
BrowserModule, BrowserModule,
BrowserAnimationsModule, BrowserAnimationsModule,
FlexLayoutModule.withConfig({useColumnBasisZero: true}), FlexLayoutModule.withConfig({useColumnBasisZero: true}),
HotkeyModule.forRoot(),
HttpClientModule, HttpClientModule,
LayoutModule, LayoutModule,
MatButtonModule, MatButtonModule,

@ -7,8 +7,8 @@
<div fxLayout="row" fxLayoutAlign="space-around start" fxLayout.lt-md="column" fxLayoutGap="20px" <div fxLayout="row" fxLayoutAlign="space-around start" fxLayout.lt-md="column" fxLayoutGap="20px"
fxLayoutGap.lt-md="0px"> fxLayoutGap.lt-md="0px">
<mat-form-field fxFlex="40"> <mat-form-field fxFlex="40">
<input matInput [matDatepicker]="date" (focus)="date.open()" placeholder="Date" formControlName="date" <input matInput [matDatepicker]="date" placeholder="Date" formControlName="date" autocomplete="off"
autocomplete="off"> #dateElement (focus)="dateElement.select()">
<mat-datepicker-toggle matSuffix [for]="date"></mat-datepicker-toggle> <mat-datepicker-toggle matSuffix [for]="date"></mat-datepicker-toggle>
<mat-datepicker #date></mat-datepicker> <mat-datepicker #date></mat-datepicker>
</mat-form-field> </mat-form-field>

@ -1,4 +1,4 @@
import {AfterViewInit, Component, ElementRef, OnInit, ViewChild} from '@angular/core'; import {AfterViewInit, Component, ElementRef, OnInit, OnDestroy, ViewChild} from '@angular/core';
import {FormBuilder, FormGroup} from '@angular/forms'; import {FormBuilder, FormGroup} from '@angular/forms';
import {MatAutocompleteSelectedEvent, MatDialog} from '@angular/material'; import {MatAutocompleteSelectedEvent, MatDialog} from '@angular/material';
import {ActivatedRoute, Router} from '@angular/router'; import {ActivatedRoute, Router} from '@angular/router';
@ -16,14 +16,16 @@ import {BatchService} from '../purchase-return/batch.service';
import {IssueGridService} from './issue-grid.service'; import {IssueGridService} from './issue-grid.service';
import {CostCentre} from '../cost-centre/cost-centre'; import {CostCentre} from '../cost-centre/cost-centre';
import {IssueGridDataSource} from './issue-grid-datasource'; import {IssueGridDataSource} from './issue-grid-datasource';
import {Hotkey, HotkeysService} from "angular2-hotkeys";
@Component({ @Component({
selector: 'app-issue', selector: 'app-issue',
templateUrl: './issue.component.html', templateUrl: './issue.component.html',
styleUrls: ['./issue.component.css'] styleUrls: ['./issue.component.css']
}) })
export class IssueComponent implements OnInit, AfterViewInit { export class IssueComponent implements OnInit, AfterViewInit, OnDestroy {
@ViewChild('batchElement') batchElement: ElementRef; @ViewChild('batchElement') batchElement: ElementRef;
@ViewChild('dateElement') dateElement: ElementRef;
public inventoryObservable = new BehaviorSubject<Inventory[]>([]); public inventoryObservable = new BehaviorSubject<Inventory[]>([]);
public gridObservable = new BehaviorSubject<any[]>([]); public gridObservable = new BehaviorSubject<any[]>([]);
dataSource: IssueDataSource; dataSource: IssueDataSource;
@ -45,6 +47,7 @@ export class IssueComponent implements OnInit, AfterViewInit {
private router: Router, private router: Router,
private fb: FormBuilder, private fb: FormBuilder,
private dialog: MatDialog, private dialog: MatDialog,
private hotkeys: HotkeysService,
private toaster: ToasterService, private toaster: ToasterService,
private auth: AuthService, private auth: AuthService,
private ser: VoucherService, private ser: VoucherService,
@ -63,12 +66,27 @@ export class IssueComponent implements OnInit, AfterViewInit {
this.costCentres = data.costCentres; this.costCentres = data.costCentres;
this.loadVoucher(data.voucher); this.loadVoucher(data.voucher);
}); });
this.hotkeys.add(new Hotkey('f2', (event: KeyboardEvent): boolean => {
setTimeout(() => {
this.dateElement.nativeElement.focus();
}, 0);
return false; // Prevent bubbling
}, ['INPUT', 'SELECT', 'TEXTAREA']));
this.hotkeys.add(new Hotkey('ctrl+s', (event: KeyboardEvent): boolean => {
if (this.canSave())
this.save();
return false; // Prevent bubbling
}, ['INPUT', 'SELECT', 'TEXTAREA']));
} }
ngAfterViewInit() { ngAfterViewInit() {
this.focusBatch(); this.focusBatch();
} }
ngOnDestroy() {
this.hotkeys.reset();
}
loadVoucher(voucher: Voucher) { loadVoucher(voucher: Voucher) {
this.voucher = voucher; this.voucher = voucher;
this.sourceJournal = this.voucher.journals.filter(x => x.debit === -1)[0]; this.sourceJournal = this.voucher.journals.filter(x => x.debit === -1)[0];

@ -29,6 +29,7 @@ import {MomentDateAdapter} from '@angular/material-moment-adapter';
import {A11yModule} from '@angular/cdk/a11y'; import {A11yModule} from '@angular/cdk/a11y';
import {IssueDialogComponent} from './issue-dialog.component'; import {IssueDialogComponent} from './issue-dialog.component';
import {FlexLayoutModule} from '@angular/flex-layout'; import {FlexLayoutModule} from '@angular/flex-layout';
import {HotkeyModule} from "angular2-hotkeys";
export const MY_FORMATS = { export const MY_FORMATS = {
parse: { parse: {
@ -48,6 +49,7 @@ export const MY_FORMATS = {
CommonModule, CommonModule,
CdkTableModule, CdkTableModule,
FlexLayoutModule, FlexLayoutModule,
HotkeyModule,
MatAutocompleteModule, MatAutocompleteModule,
MatButtonModule, MatButtonModule,
MatCardModule, MatCardModule,

@ -10,8 +10,8 @@
<form [formGroup]="form" fxLayout="column"> <form [formGroup]="form" fxLayout="column">
<div fxLayout="row" fxLayout.lt-md="column" fxLayoutGap="20px" fxLayoutGap.lt-md="0px"> <div fxLayout="row" fxLayout.lt-md="column" fxLayoutGap="20px" fxLayoutGap.lt-md="0px">
<mat-form-field fxFlex> <mat-form-field fxFlex>
<input matInput [matDatepicker]="date" (focus)="date.open()" placeholder="Date" formControlName="date" <input matInput [matDatepicker]="date" placeholder="Date" formControlName="date" autocomplete="off"
autocomplete="off"> #dateElement (focus)="dateElement.select()">
<mat-datepicker-toggle matSuffix [for]="date"></mat-datepicker-toggle> <mat-datepicker-toggle matSuffix [for]="date"></mat-datepicker-toggle>
<mat-datepicker #date></mat-datepicker> <mat-datepicker #date></mat-datepicker>
</mat-form-field> </mat-form-field>

@ -1,4 +1,4 @@
import {AfterViewInit, Component, ElementRef, OnInit, ViewChild} from '@angular/core'; import {AfterViewInit, Component, ElementRef, OnInit, OnDestroy, ViewChild} from '@angular/core';
import {FormBuilder, FormGroup} from '@angular/forms'; import {FormBuilder, FormGroup} from '@angular/forms';
import {MatAutocompleteSelectedEvent, MatDialog} from '@angular/material'; import {MatAutocompleteSelectedEvent, MatDialog} from '@angular/material';
import {ActivatedRoute, Router} from '@angular/router'; import {ActivatedRoute, Router} from '@angular/router';
@ -16,14 +16,16 @@ import {ToasterService} from '../core/toaster.service';
import {debounceTime, distinctUntilChanged, map, startWith, switchMap} from 'rxjs/operators'; import {debounceTime, distinctUntilChanged, map, startWith, switchMap} from 'rxjs/operators';
import {JournalDialogComponent} from './journal-dialog.component'; import {JournalDialogComponent} from './journal-dialog.component';
import {ImageDialogComponent} from '../shared/image-dialog/image-dialog.component'; import {ImageDialogComponent} from '../shared/image-dialog/image-dialog.component';
import {Hotkey, HotkeysService} from "angular2-hotkeys";
@Component({ @Component({
selector: 'app-journal', selector: 'app-journal',
templateUrl: './journal.component.html', templateUrl: './journal.component.html',
styleUrls: ['./journal.component.css'] styleUrls: ['./journal.component.css']
}) })
export class JournalComponent implements OnInit, AfterViewInit { export class JournalComponent implements OnInit, AfterViewInit, OnDestroy {
@ViewChild('accountElement') accountElement: ElementRef; @ViewChild('accountElement') accountElement: ElementRef;
@ViewChild('dateElement') dateElement: ElementRef;
public journalObservable = new BehaviorSubject<Journal[]>([]); public journalObservable = new BehaviorSubject<Journal[]>([]);
dataSource: JournalDataSource; dataSource: JournalDataSource;
form: FormGroup; form: FormGroup;
@ -40,6 +42,7 @@ export class JournalComponent implements OnInit, AfterViewInit {
private router: Router, private router: Router,
private fb: FormBuilder, private fb: FormBuilder,
private dialog: MatDialog, private dialog: MatDialog,
private hotkeys: HotkeysService,
private toaster: ToasterService, private toaster: ToasterService,
private auth: AuthService, private auth: AuthService,
private ser: VoucherService, private ser: VoucherService,
@ -55,12 +58,32 @@ export class JournalComponent implements OnInit, AfterViewInit {
.subscribe((data: { voucher: Voucher }) => { .subscribe((data: { voucher: Voucher }) => {
this.loadVoucher(data.voucher); this.loadVoucher(data.voucher);
}); });
this.hotkeys.add(new Hotkey('f2', (event: KeyboardEvent): boolean => {
setTimeout(() => {
this.dateElement.nativeElement.focus();
}, 0);
return false; // Prevent bubbling
}, ['INPUT', 'SELECT', 'TEXTAREA']));
this.hotkeys.add(new Hotkey('ctrl+s', (event: KeyboardEvent): boolean => {
if (this.canSave())
this.save();
return false; // Prevent bubbling
}, ['INPUT', 'SELECT', 'TEXTAREA']));
this.hotkeys.add(new Hotkey('ctrl+p', (event: KeyboardEvent): boolean => {
if (this.voucher.id && !this.voucher.posted && this.auth.user.perms.indexOf('Post Vouchers') !== -1)
this.post();
return false; // Prevent bubbling
}, ['INPUT', 'SELECT', 'TEXTAREA']));
} }
ngAfterViewInit() { ngAfterViewInit() {
this.focusAccount(); this.focusAccount();
} }
ngOnDestroy() {
this.hotkeys.reset();
}
loadVoucher(voucher) { loadVoucher(voucher) {
this.voucher = voucher; this.voucher = voucher;
this.form.setValue({ this.form.setValue({

@ -29,6 +29,7 @@ import {MomentDateAdapter} from '@angular/material-moment-adapter';
import {A11yModule} from '@angular/cdk/a11y'; import {A11yModule} from '@angular/cdk/a11y';
import {JournalDialogComponent} from './journal-dialog.component'; import {JournalDialogComponent} from './journal-dialog.component';
import {FlexLayoutModule} from '@angular/flex-layout'; import {FlexLayoutModule} from '@angular/flex-layout';
import {HotkeyModule} from "angular2-hotkeys";
export const MY_FORMATS = { export const MY_FORMATS = {
parse: { parse: {
@ -48,6 +49,7 @@ export const MY_FORMATS = {
CommonModule, CommonModule,
CdkTableModule, CdkTableModule,
FlexLayoutModule, FlexLayoutModule,
HotkeyModule,
MatAutocompleteModule, MatAutocompleteModule,
MatButtonModule, MatButtonModule,
MatCardModule, MatCardModule,

@ -11,8 +11,8 @@
<div fxLayout="row" fxLayoutAlign="space-around start" fxLayout.lt-md="column" fxLayoutGap="20px" <div fxLayout="row" fxLayoutAlign="space-around start" fxLayout.lt-md="column" fxLayoutGap="20px"
fxLayoutGap.lt-md="0px"> fxLayoutGap.lt-md="0px">
<mat-form-field fxFlex="40"> <mat-form-field fxFlex="40">
<input matInput [matDatepicker]="date" (focus)="date.open()" placeholder="Date" formControlName="date" <input matInput [matDatepicker]="date" placeholder="Date" formControlName="date" autocomplete="off"
autocomplete="off"> #dateElement (focus)="dateElement.select()">
<mat-datepicker-toggle matSuffix [for]="date"></mat-datepicker-toggle> <mat-datepicker-toggle matSuffix [for]="date"></mat-datepicker-toggle>
<mat-datepicker #date></mat-datepicker> <mat-datepicker #date></mat-datepicker>
</mat-form-field> </mat-form-field>

@ -1,4 +1,4 @@
import {AfterViewInit, Component, ElementRef, OnInit, ViewChild} from '@angular/core'; import {AfterViewInit, Component, ElementRef, OnInit, OnDestroy, ViewChild} from '@angular/core';
import {FormBuilder, FormGroup} from '@angular/forms'; import {FormBuilder, FormGroup} from '@angular/forms';
import {MatAutocompleteSelectedEvent, MatDialog} from '@angular/material'; import {MatAutocompleteSelectedEvent, MatDialog} from '@angular/material';
import {ActivatedRoute, Router} from '@angular/router'; import {ActivatedRoute, Router} from '@angular/router';
@ -16,14 +16,16 @@ import {ToasterService} from '../core/toaster.service';
import {debounceTime, distinctUntilChanged, map, startWith, switchMap} from 'rxjs/operators'; import {debounceTime, distinctUntilChanged, map, startWith, switchMap} from 'rxjs/operators';
import {PaymentDialogComponent} from './payment-dialog.component'; import {PaymentDialogComponent} from './payment-dialog.component';
import {ImageDialogComponent} from '../shared/image-dialog/image-dialog.component'; import {ImageDialogComponent} from '../shared/image-dialog/image-dialog.component';
import {Hotkey, HotkeysService} from "angular2-hotkeys";
@Component({ @Component({
selector: 'app-payment', selector: 'app-payment',
templateUrl: './payment.component.html', templateUrl: './payment.component.html',
styleUrls: ['./payment.component.css'] styleUrls: ['./payment.component.css']
}) })
export class PaymentComponent implements OnInit, AfterViewInit { export class PaymentComponent implements OnInit, AfterViewInit, OnDestroy {
@ViewChild('accountElement') accountElement: ElementRef; @ViewChild('accountElement') accountElement: ElementRef;
@ViewChild('dateElement') dateElement: ElementRef;
public journalObservable = new BehaviorSubject<Journal[]>([]); public journalObservable = new BehaviorSubject<Journal[]>([]);
dataSource: PaymentDataSource; dataSource: PaymentDataSource;
form: FormGroup; form: FormGroup;
@ -42,6 +44,7 @@ export class PaymentComponent implements OnInit, AfterViewInit {
private router: Router, private router: Router,
private fb: FormBuilder, private fb: FormBuilder,
private dialog: MatDialog, private dialog: MatDialog,
private hotkeys: HotkeysService,
private toaster: ToasterService, private toaster: ToasterService,
private auth: AuthService, private auth: AuthService,
private ser: VoucherService, private ser: VoucherService,
@ -59,12 +62,32 @@ export class PaymentComponent implements OnInit, AfterViewInit {
this.paymentAccounts = data.paymentAccounts; this.paymentAccounts = data.paymentAccounts;
this.loadVoucher(data.voucher); this.loadVoucher(data.voucher);
}); });
this.hotkeys.add(new Hotkey('f2', (event: KeyboardEvent): boolean => {
setTimeout(() => {
this.dateElement.nativeElement.focus();
}, 0);
return false; // Prevent bubbling
}, ['INPUT', 'SELECT', 'TEXTAREA']));
this.hotkeys.add(new Hotkey('ctrl+s', (event: KeyboardEvent): boolean => {
if (this.canSave())
this.save();
return false; // Prevent bubbling
}, ['INPUT', 'SELECT', 'TEXTAREA']));
this.hotkeys.add(new Hotkey('ctrl+p', (event: KeyboardEvent): boolean => {
if (this.voucher.id && !this.voucher.posted && this.auth.user.perms.indexOf('Post Vouchers') !== -1)
this.post();
return false; // Prevent bubbling
}, ['INPUT', 'SELECT', 'TEXTAREA']));
} }
ngAfterViewInit() { ngAfterViewInit() {
this.focusAccount(); this.focusAccount();
} }
ngOnDestroy() {
this.hotkeys.reset();
}
loadVoucher(voucher: Voucher) { loadVoucher(voucher: Voucher) {
this.voucher = voucher; this.voucher = voucher;
this.paymentJournal = this.voucher.journals.filter(x => x.debit === -1)[0]; this.paymentJournal = this.voucher.journals.filter(x => x.debit === -1)[0];

@ -29,6 +29,7 @@ import {MomentDateAdapter} from '@angular/material-moment-adapter';
import {A11yModule} from '@angular/cdk/a11y'; import {A11yModule} from '@angular/cdk/a11y';
import {PaymentDialogComponent} from './payment-dialog.component'; import {PaymentDialogComponent} from './payment-dialog.component';
import {FlexLayoutModule} from '@angular/flex-layout'; import {FlexLayoutModule} from '@angular/flex-layout';
import {HotkeyModule} from "angular2-hotkeys";
export const MY_FORMATS = { export const MY_FORMATS = {
parse: { parse: {
@ -48,6 +49,7 @@ export const MY_FORMATS = {
CommonModule, CommonModule,
CdkTableModule, CdkTableModule,
FlexLayoutModule, FlexLayoutModule,
HotkeyModule,
MatAutocompleteModule, MatAutocompleteModule,
MatButtonModule, MatButtonModule,
MatCardModule, MatCardModule,

@ -57,7 +57,6 @@ export class ProductDetailComponent implements OnInit, AfterViewInit {
showItem(item: Product) { showItem(item: Product) {
this.item = item; this.item = item;
console.log(item);
this.form.setValue({ this.form.setValue({
code: this.item.code || '(Auto)', code: this.item.code || '(Auto)',
name: this.item.name || '', name: this.item.name || '',

@ -11,8 +11,8 @@
<div fxLayout="row" fxLayoutAlign="space-around start" fxLayout.lt-md="column" fxLayoutGap="20px" <div fxLayout="row" fxLayoutAlign="space-around start" fxLayout.lt-md="column" fxLayoutGap="20px"
fxLayoutGap.lt-md="0px"> fxLayoutGap.lt-md="0px">
<mat-form-field fxFlex="40"> <mat-form-field fxFlex="40">
<input matInput [matDatepicker]="date" (focus)="date.open()" placeholder="Date" formControlName="date" <input matInput [matDatepicker]="date" placeholder="Date" formControlName="date" autocomplete="off"
autocomplete="off"> #dateElement (focus)="dateElement.select()">
<mat-datepicker-toggle matSuffix [for]="date"></mat-datepicker-toggle> <mat-datepicker-toggle matSuffix [for]="date"></mat-datepicker-toggle>
<mat-datepicker #date></mat-datepicker> <mat-datepicker #date></mat-datepicker>
</mat-form-field> </mat-form-field>

@ -1,4 +1,4 @@
import {AfterViewInit, Component, ElementRef, OnInit, ViewChild} from '@angular/core'; import {AfterViewInit, Component, ElementRef, OnInit, OnDestroy, ViewChild} from '@angular/core';
import {FormBuilder, FormGroup} from '@angular/forms'; import {FormBuilder, FormGroup} from '@angular/forms';
import {MatAutocompleteSelectedEvent, MatDialog} from '@angular/material'; import {MatAutocompleteSelectedEvent, MatDialog} from '@angular/material';
import {ActivatedRoute, Router} from '@angular/router'; import {ActivatedRoute, Router} from '@angular/router';
@ -16,15 +16,17 @@ import {debounceTime, distinctUntilChanged, map, startWith, switchMap} from 'rxj
import {PurchaseReturnDialogComponent} from './purchase-return-dialog.component'; import {PurchaseReturnDialogComponent} from './purchase-return-dialog.component';
import {ImageDialogComponent} from '../shared/image-dialog/image-dialog.component'; import {ImageDialogComponent} from '../shared/image-dialog/image-dialog.component';
import {BatchService} from './batch.service'; import {BatchService} from './batch.service';
import {Hotkey, HotkeysService} from "angular2-hotkeys";
@Component({ @Component({
selector: 'app-purchase-return', selector: 'app-purchase-return',
templateUrl: './purchase-return.component.html', templateUrl: './purchase-return.component.html',
styleUrls: ['./purchase-return.component.css'] styleUrls: ['./purchase-return.component.css']
}) })
export class PurchaseReturnComponent implements OnInit, AfterViewInit { export class PurchaseReturnComponent implements OnInit, AfterViewInit, OnDestroy {
@ViewChild('accountElement') accountElement: ElementRef; @ViewChild('accountElement') accountElement: ElementRef;
@ViewChild('batchElement') batchElement: ElementRef; @ViewChild('batchElement') batchElement: ElementRef;
@ViewChild('dateElement') dateElement: ElementRef;
public inventoryObservable = new BehaviorSubject<Inventory[]>([]); public inventoryObservable = new BehaviorSubject<Inventory[]>([]);
dataSource: PurchaseReturnDataSource; dataSource: PurchaseReturnDataSource;
form: FormGroup; form: FormGroup;
@ -44,6 +46,7 @@ export class PurchaseReturnComponent implements OnInit, AfterViewInit {
private router: Router, private router: Router,
private fb: FormBuilder, private fb: FormBuilder,
private dialog: MatDialog, private dialog: MatDialog,
private hotkeys: HotkeysService,
private toaster: ToasterService, private toaster: ToasterService,
private auth: AuthService, private auth: AuthService,
private ser: VoucherService, private ser: VoucherService,
@ -60,12 +63,32 @@ export class PurchaseReturnComponent implements OnInit, AfterViewInit {
.subscribe((data: { voucher: Voucher }) => { .subscribe((data: { voucher: Voucher }) => {
this.loadVoucher(data.voucher); this.loadVoucher(data.voucher);
}); });
this.hotkeys.add(new Hotkey('f2', (event: KeyboardEvent): boolean => {
setTimeout(() => {
this.dateElement.nativeElement.focus();
}, 0);
return false; // Prevent bubbling
}, ['INPUT', 'SELECT', 'TEXTAREA']));
this.hotkeys.add(new Hotkey('ctrl+s', (event: KeyboardEvent): boolean => {
if (this.canSave())
this.save();
return false; // Prevent bubbling
}, ['INPUT', 'SELECT', 'TEXTAREA']));
this.hotkeys.add(new Hotkey('ctrl+p', (event: KeyboardEvent): boolean => {
if (this.voucher.id && !this.voucher.posted && this.auth.user.perms.indexOf('Post Vouchers') !== -1)
this.post();
return false; // Prevent bubbling
}, ['INPUT', 'SELECT', 'TEXTAREA']));
} }
ngAfterViewInit() { ngAfterViewInit() {
this.focusAccount(); this.focusAccount();
} }
ngOnDestroy() {
this.hotkeys.reset();
}
loadVoucher(voucher: Voucher) { loadVoucher(voucher: Voucher) {
this.voucher = voucher; this.voucher = voucher;
this.purchaseReturnJournal = this.voucher.journals.filter(x => x.debit === 1)[0]; this.purchaseReturnJournal = this.voucher.journals.filter(x => x.debit === 1)[0];

@ -29,6 +29,7 @@ import {MomentDateAdapter} from '@angular/material-moment-adapter';
import {A11yModule} from '@angular/cdk/a11y'; import {A11yModule} from '@angular/cdk/a11y';
import {PurchaseReturnDialogComponent} from './purchase-return-dialog.component'; import {PurchaseReturnDialogComponent} from './purchase-return-dialog.component';
import {FlexLayoutModule} from '@angular/flex-layout'; import {FlexLayoutModule} from '@angular/flex-layout';
import {HotkeyModule} from "angular2-hotkeys";
export const MY_FORMATS = { export const MY_FORMATS = {
parse: { parse: {
@ -48,6 +49,7 @@ export const MY_FORMATS = {
CommonModule, CommonModule,
CdkTableModule, CdkTableModule,
FlexLayoutModule, FlexLayoutModule,
HotkeyModule,
MatAutocompleteModule, MatAutocompleteModule,
MatButtonModule, MatButtonModule,
MatCardModule, MatCardModule,

@ -11,8 +11,8 @@
<div fxLayout="row" fxLayoutAlign="space-around start" fxLayout.lt-md="column" fxLayoutGap="20px" <div fxLayout="row" fxLayoutAlign="space-around start" fxLayout.lt-md="column" fxLayoutGap="20px"
fxLayoutGap.lt-md="0px"> fxLayoutGap.lt-md="0px">
<mat-form-field fxFlex="40"> <mat-form-field fxFlex="40">
<input matInput [matDatepicker]="date" (focus)="date.open()" placeholder="Date" formControlName="date" <input matInput [matDatepicker]="date" placeholder="Date" formControlName="date" autocomplete="off"
autocomplete="off"> #dateElement (focus)="dateElement.select()">
<mat-datepicker-toggle matSuffix [for]="date"></mat-datepicker-toggle> <mat-datepicker-toggle matSuffix [for]="date"></mat-datepicker-toggle>
<mat-datepicker #date></mat-datepicker> <mat-datepicker #date></mat-datepicker>
</mat-form-field> </mat-form-field>

@ -1,4 +1,4 @@
import {AfterViewInit, Component, ElementRef, OnInit, ViewChild} from '@angular/core'; import {AfterViewInit, Component, ElementRef, OnInit, OnDestroy, ViewChild} from '@angular/core';
import {FormBuilder, FormGroup} from '@angular/forms'; import {FormBuilder, FormGroup} from '@angular/forms';
import {MatAutocompleteSelectedEvent, MatDialog} from '@angular/material'; import {MatAutocompleteSelectedEvent, MatDialog} from '@angular/material';
import {ActivatedRoute, Router} from '@angular/router'; import {ActivatedRoute, Router} from '@angular/router';
@ -17,15 +17,17 @@ import {PurchaseDialogComponent} from './purchase-dialog.component';
import {ImageDialogComponent} from '../shared/image-dialog/image-dialog.component'; import {ImageDialogComponent} from '../shared/image-dialog/image-dialog.component';
import {ProductService} from '../product/product.service'; import {ProductService} from '../product/product.service';
import {Product} from '../product/product'; import {Product} from '../product/product';
import {Hotkey, HotkeysService} from "angular2-hotkeys";
@Component({ @Component({
selector: 'app-purchase', selector: 'app-purchase',
templateUrl: './purchase.component.html', templateUrl: './purchase.component.html',
styleUrls: ['./purchase.component.css'] styleUrls: ['./purchase.component.css']
}) })
export class PurchaseComponent implements OnInit, AfterViewInit { export class PurchaseComponent implements OnInit, AfterViewInit, OnDestroy {
@ViewChild('accountElement') accountElement: ElementRef; @ViewChild('accountElement') accountElement: ElementRef;
@ViewChild('productElement') productElement: ElementRef; @ViewChild('productElement') productElement: ElementRef;
@ViewChild('dateElement') dateElement: ElementRef;
public inventoryObservable = new BehaviorSubject<Inventory[]>([]); public inventoryObservable = new BehaviorSubject<Inventory[]>([]);
dataSource: PurchaseDataSource; dataSource: PurchaseDataSource;
form: FormGroup; form: FormGroup;
@ -45,6 +47,7 @@ export class PurchaseComponent implements OnInit, AfterViewInit {
private router: Router, private router: Router,
private fb: FormBuilder, private fb: FormBuilder,
private dialog: MatDialog, private dialog: MatDialog,
private hotkeys: HotkeysService,
private toaster: ToasterService, private toaster: ToasterService,
private auth: AuthService, private auth: AuthService,
private ser: VoucherService, private ser: VoucherService,
@ -61,12 +64,32 @@ export class PurchaseComponent implements OnInit, AfterViewInit {
.subscribe((data: { voucher: Voucher }) => { .subscribe((data: { voucher: Voucher }) => {
this.loadVoucher(data.voucher); this.loadVoucher(data.voucher);
}); });
this.hotkeys.add(new Hotkey('f2', (event: KeyboardEvent): boolean => {
setTimeout(() => {
this.dateElement.nativeElement.focus();
}, 0);
return false; // Prevent bubbling
}, ['INPUT', 'SELECT', 'TEXTAREA']));
this.hotkeys.add(new Hotkey('ctrl+s', (event: KeyboardEvent): boolean => {
if (this.canSave())
this.save();
return false; // Prevent bubbling
}, ['INPUT', 'SELECT', 'TEXTAREA']));
this.hotkeys.add(new Hotkey('ctrl+p', (event: KeyboardEvent): boolean => {
if (this.voucher.id && !this.voucher.posted && this.auth.user.perms.indexOf('Post Vouchers') !== -1)
this.post();
return false; // Prevent bubbling
}, ['INPUT', 'SELECT', 'TEXTAREA']));
} }
ngAfterViewInit() { ngAfterViewInit() {
this.focusAccount(); this.focusAccount();
} }
ngOnDestroy() {
this.hotkeys.reset();
}
loadVoucher(voucher) { loadVoucher(voucher) {
this.voucher = voucher; this.voucher = voucher;
this.purchaseJournal = this.voucher.journals.filter(x => x.debit === -1)[0]; this.purchaseJournal = this.voucher.journals.filter(x => x.debit === -1)[0];

@ -29,6 +29,7 @@ import {MomentDateAdapter} from '@angular/material-moment-adapter';
import {A11yModule} from '@angular/cdk/a11y'; import {A11yModule} from '@angular/cdk/a11y';
import {PurchaseDialogComponent} from './purchase-dialog.component'; import {PurchaseDialogComponent} from './purchase-dialog.component';
import {FlexLayoutModule} from '@angular/flex-layout'; import {FlexLayoutModule} from '@angular/flex-layout';
import {HotkeyModule} from "angular2-hotkeys";
export const MY_FORMATS = { export const MY_FORMATS = {
parse: { parse: {
@ -48,6 +49,7 @@ export const MY_FORMATS = {
CommonModule, CommonModule,
CdkTableModule, CdkTableModule,
FlexLayoutModule, FlexLayoutModule,
HotkeyModule,
MatAutocompleteModule, MatAutocompleteModule,
MatButtonModule, MatButtonModule,
MatCardModule, MatCardModule,

@ -11,8 +11,8 @@
<div fxLayout="row" fxLayoutAlign="space-around start" fxLayout.lt-md="column" fxLayoutGap="20px" <div fxLayout="row" fxLayoutAlign="space-around start" fxLayout.lt-md="column" fxLayoutGap="20px"
fxLayoutGap.lt-md="0px"> fxLayoutGap.lt-md="0px">
<mat-form-field fxFlex="40"> <mat-form-field fxFlex="40">
<input matInput [matDatepicker]="date" (focus)="date.open()" placeholder="Date" formControlName="date" <input matInput [matDatepicker]="date" placeholder="Date" formControlName="date" autocomplete="off"
autocomplete="off"> #dateElement (focus)="dateElement.select()">
<mat-datepicker-toggle matSuffix [for]="date"></mat-datepicker-toggle> <mat-datepicker-toggle matSuffix [for]="date"></mat-datepicker-toggle>
<mat-datepicker #date></mat-datepicker> <mat-datepicker #date></mat-datepicker>
</mat-form-field> </mat-form-field>

@ -1,4 +1,4 @@
import {AfterViewInit, Component, ElementRef, OnInit, ViewChild} from '@angular/core'; import {AfterViewInit, Component, ElementRef, OnInit, OnDestroy, ViewChild} from '@angular/core';
import {FormBuilder, FormGroup} from '@angular/forms'; import {FormBuilder, FormGroup} from '@angular/forms';
import {MatAutocompleteSelectedEvent, MatDialog} from '@angular/material'; import {MatAutocompleteSelectedEvent, MatDialog} from '@angular/material';
import {ActivatedRoute, Router} from '@angular/router'; import {ActivatedRoute, Router} from '@angular/router';
@ -16,14 +16,16 @@ import {ToasterService} from '../core/toaster.service';
import {debounceTime, distinctUntilChanged, map, startWith, switchMap} from 'rxjs/operators'; import {debounceTime, distinctUntilChanged, map, startWith, switchMap} from 'rxjs/operators';
import {ReceiptDialogComponent} from './receipt-dialog.component'; import {ReceiptDialogComponent} from './receipt-dialog.component';
import {ImageDialogComponent} from '../shared/image-dialog/image-dialog.component'; import {ImageDialogComponent} from '../shared/image-dialog/image-dialog.component';
import {Hotkey, HotkeysService} from "angular2-hotkeys";
@Component({ @Component({
selector: 'app-receipt', selector: 'app-receipt',
templateUrl: './receipt.component.html', templateUrl: './receipt.component.html',
styleUrls: ['./receipt.component.css'] styleUrls: ['./receipt.component.css']
}) })
export class ReceiptComponent implements OnInit, AfterViewInit { export class ReceiptComponent implements OnInit, AfterViewInit, OnDestroy {
@ViewChild('accountElement') accountElement: ElementRef; @ViewChild('accountElement') accountElement: ElementRef;
@ViewChild('dateElement') dateElement: ElementRef;
public journalObservable = new BehaviorSubject<Journal[]>([]); public journalObservable = new BehaviorSubject<Journal[]>([]);
dataSource: ReceiptDataSource; dataSource: ReceiptDataSource;
form: FormGroup; form: FormGroup;
@ -42,6 +44,7 @@ export class ReceiptComponent implements OnInit, AfterViewInit {
private router: Router, private router: Router,
private fb: FormBuilder, private fb: FormBuilder,
private dialog: MatDialog, private dialog: MatDialog,
private hotkeys: HotkeysService,
private toaster: ToasterService, private toaster: ToasterService,
private auth: AuthService, private auth: AuthService,
private ser: VoucherService, private ser: VoucherService,
@ -59,12 +62,32 @@ export class ReceiptComponent implements OnInit, AfterViewInit {
this.receiptAccounts = data.receiptAccounts; this.receiptAccounts = data.receiptAccounts;
this.loadVoucher(data.voucher); this.loadVoucher(data.voucher);
}); });
this.hotkeys.add(new Hotkey('f2', (event: KeyboardEvent): boolean => {
setTimeout(() => {
this.dateElement.nativeElement.focus();
}, 0);
return false; // Prevent bubbling
}, ['INPUT', 'SELECT', 'TEXTAREA']));
this.hotkeys.add(new Hotkey('ctrl+s', (event: KeyboardEvent): boolean => {
if (this.canSave())
this.save();
return false; // Prevent bubbling
}, ['INPUT', 'SELECT', 'TEXTAREA']));
this.hotkeys.add(new Hotkey('ctrl+p', (event: KeyboardEvent): boolean => {
if (this.voucher.id && !this.voucher.posted && this.auth.user.perms.indexOf('Post Vouchers') !== -1)
this.post();
return false; // Prevent bubbling
}, ['INPUT', 'SELECT', 'TEXTAREA']));
} }
ngAfterViewInit() { ngAfterViewInit() {
this.focusAccount(); this.focusAccount();
} }
ngOnDestroy() {
this.hotkeys.reset();
}
loadVoucher(voucher: Voucher) { loadVoucher(voucher: Voucher) {
this.voucher = voucher; this.voucher = voucher;
this.receiptJournal = this.voucher.journals.filter(x => x.debit === 1)[0]; this.receiptJournal = this.voucher.journals.filter(x => x.debit === 1)[0];

@ -29,6 +29,7 @@ import {MomentDateAdapter} from '@angular/material-moment-adapter';
import {A11yModule} from '@angular/cdk/a11y'; import {A11yModule} from '@angular/cdk/a11y';
import {ReceiptDialogComponent} from './receipt-dialog.component'; import {ReceiptDialogComponent} from './receipt-dialog.component';
import {FlexLayoutModule} from '@angular/flex-layout'; import {FlexLayoutModule} from '@angular/flex-layout';
import {HotkeyModule} from "angular2-hotkeys";
export const MY_FORMATS = { export const MY_FORMATS = {
parse: { parse: {
@ -48,6 +49,7 @@ export const MY_FORMATS = {
CommonModule, CommonModule,
CdkTableModule, CdkTableModule,
FlexLayoutModule, FlexLayoutModule,
HotkeyModule,
MatAutocompleteModule, MatAutocompleteModule,
MatButtonModule, MatButtonModule,
MatCardModule, MatCardModule,