Skip to content

Commit d99cd9d

Browse files
committed
dateTime bug fix, name change
1 parent e4f6ec5 commit d99cd9d

7 files changed

+81
-41
lines changed

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
# HandyCalc
1+
# hasap
22

3-
A web based general purpose math calculator. Use `ng deploy --base-href=/handyCalc/` to deploy to github-pages
3+
A web based general purpose math calculator. Use `ng deploy --base-href=/hasap/` to deploy to github-pages
44

55
Built with [Angular CLI](https://github.com/angular/angular-cli) version 9.0.7.

angular.json

+8-8
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"version": 1,
44
"newProjectRoot": "projects",
55
"projects": {
6-
"handyCalc": {
6+
"hasap": {
77
"projectType": "application",
88
"schematics": {},
99
"root": "",
@@ -13,7 +13,7 @@
1313
"build": {
1414
"builder": "@angular-devkit/build-angular:browser",
1515
"options": {
16-
"outputPath": "dist/handyCalc",
16+
"outputPath": "dist/hasap",
1717
"index": "src/index.html",
1818
"main": "src/main.ts",
1919
"polyfills": "src/polyfills.ts",
@@ -68,18 +68,18 @@
6868
"serve": {
6969
"builder": "@angular-devkit/build-angular:dev-server",
7070
"options": {
71-
"browserTarget": "handyCalc:build"
71+
"browserTarget": "hasap:build"
7272
},
7373
"configurations": {
7474
"production": {
75-
"browserTarget": "handyCalc:build:production"
75+
"browserTarget": "hasap:build:production"
7676
}
7777
}
7878
},
7979
"extract-i18n": {
8080
"builder": "@angular-devkit/build-angular:extract-i18n",
8181
"options": {
82-
"browserTarget": "handyCalc:build"
82+
"browserTarget": "hasap:build"
8383
}
8484
},
8585
"test": {
@@ -118,11 +118,11 @@
118118
"builder": "@angular-devkit/build-angular:protractor",
119119
"options": {
120120
"protractorConfig": "e2e/protractor.conf.js",
121-
"devServerTarget": "handyCalc:serve"
121+
"devServerTarget": "hasap:serve"
122122
},
123123
"configurations": {
124124
"production": {
125-
"devServerTarget": "handyCalc:serve:production"
125+
"devServerTarget": "hasap:serve:production"
126126
}
127127
}
128128
},
@@ -133,7 +133,7 @@
133133
}
134134
}
135135
},
136-
"defaultProject": "handyCalc",
136+
"defaultProject": "hasap",
137137
"cli": {
138138
"analytics": "be52f3a5-601b-4520-87da-b01b2b0f3ec9"
139139
}

e2e/src/app.e2e-spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ describe('workspace-project App', () => {
1010

1111
it('should display welcome message', () => {
1212
page.navigateTo();
13-
expect(page.getTitleText()).toEqual('handyCalc app is running!');
13+
expect(page.getTitleText()).toEqual('hasap app is running!');
1414
});
1515

1616
afterEach(async () => {

karma.conf.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ module.exports = function (config) {
1616
clearContext: false // leave Jasmine Spec Runner output visible in browser
1717
},
1818
coverageIstanbulReporter: {
19-
dir: require('path').join(__dirname, './coverage/handyCalc'),
19+
dir: require('path').join(__dirname, './coverage/hasap'),
2020
reports: ['html', 'lcovonly', 'text-summary'],
2121
fixWebpackSourcePaths: true
2222
},

src/app/app.component.html

+13-9
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
<mat-sidenav-container class="main-container mat-app-background">
22
<mat-sidenav mode="side" #sidenav [(opened)]="isOpen" (disableClose)="true">
33
<mat-accordion>
4-
54
<div>
65
<div class="form-part">
76
<form [formGroup]="fnListForm" class="container">
@@ -92,13 +91,12 @@
9291
<h5>{{'About'|translate}}</h5>
9392
<span style="display:table; max-width:20vw;">{{'AboutTxt'|translate}}</span>
9493
<small> <span>Hasap 1.0.0</span> </small>
95-
<a href="https://github.com/canbax/handyCalc" target="_blank" mat-button>
94+
<a href="https://github.com/canbax/hasap" target="_blank" mat-button>
9695
<small> <span>{{'MoreAbout'|translate}}</span> </small>
9796
</a>
9897
</div>
9998
</div>
10099
</mat-accordion>
101-
102100
</mat-sidenav>
103101
<mat-sidenav-content class="m-5">
104102
<div>
@@ -109,7 +107,6 @@ <h5>{{'About'|translate}}</h5>
109107
</div>
110108

111109
<div class="m-5">
112-
113110
<div [hidden]="settings.mode != 'date & time'">
114111
<mat-form-field class="editor" appearance="outline">
115112
<mat-chip-list #chipList>
@@ -120,6 +117,14 @@ <h5>{{'About'|translate}}</h5>
120117
<input #userDateInp2 #userDateInp="matAutocompleteTrigger" [matAutocomplete]="auto"
121118
[matChipInputFor]="chipList" [matChipInputSeparatorKeyCodes]="[13, 32]" [matChipInputAddOnBlur]="false"
122119
(matChipInputTokenEnd)="addChip($event)" (change)="syncInp()">
120+
<span matSuffix>
121+
<button style="display: inline;" mat-button mat-icon-button (click)="copy(inp)">
122+
<mat-icon>file_copy</mat-icon>
123+
</button>
124+
<button style="display: inline;" mat-button mat-icon-button (click)="isShowHistory=!isShowHistory;">
125+
<mat-icon>history</mat-icon>
126+
</button>
127+
</span>
123128
<mat-hint>{{usrHint}}</mat-hint>
124129
</mat-chip-list>
125130
<mat-autocomplete #auto="matAutocomplete" (optionSelected)="timeUnitSelected($event)">
@@ -128,6 +133,7 @@ <h5>{{'About'|translate}}</h5>
128133
</mat-option>
129134
</mat-autocomplete>
130135
</mat-form-field>
136+
131137
</div>
132138
<div>
133139
<mat-form-field *ngIf="settings.mode != 'date & time'" [style.fontSize]="16" class="editor"
@@ -139,11 +145,6 @@ <h5>{{'About'|translate}}</h5>
139145
<mat-hint>{{usrHint}}</mat-hint>
140146
<!-- buttons which are inline with input -->
141147
<span matSuffix>
142-
<span [hidden]="settings.mode != 'date & time'">
143-
<button style="display: inline;" mat-button mat-icon-button id="date-inp">
144-
<mat-icon>date_range</mat-icon>
145-
</button>
146-
</span>
147148
<button style="display: inline;" mat-button mat-icon-button (click)="copy(inp)">
148149
<mat-icon>file_copy</mat-icon>
149150
</button>
@@ -166,6 +167,9 @@ <h5>{{'About'|translate}}</h5>
166167
</mat-radio-group>
167168
</div>
168169
<div *ngIf="settings.mode != 'programmer'">
170+
<button *ngIf="settings.mode == 'date & time'" mat-button mat-icon-button id="date-inp">
171+
<mat-icon>date_range</mat-icon>
172+
</button>
169173
<span matRipple [matRippleTrigger]="resultRipple2" #resultRipple2 class="result-txt">{{results[1]}}</span>
170174
<button *ngIf="results[1].length > 0" mat-icon-button matSuffix (click)="copy(results[1])">
171175
<mat-icon>file_copy</mat-icon>

src/app/app.component.spec.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,16 @@ describe('AppComponent', () => {
1616
expect(app).toBeTruthy();
1717
});
1818

19-
it(`should have as title 'handyCalc'`, () => {
19+
it(`should have as title 'hasap'`, () => {
2020
const fixture = TestBed.createComponent(AppComponent);
2121
const app = fixture.debugElement.componentInstance;
22-
expect(app.title).toEqual('handyCalc');
22+
expect(app.title).toEqual('hasap');
2323
});
2424

2525
it('should render title', () => {
2626
const fixture = TestBed.createComponent(AppComponent);
2727
fixture.detectChanges();
2828
const compiled = fixture.debugElement.nativeElement;
29-
expect(compiled.querySelector('.content span').textContent).toContain('handyCalc app is running!');
29+
expect(compiled.querySelector('.content span').textContent).toContain('hasap app is running!');
3030
});
3131
});

src/app/app.component.ts

+53-17
Original file line numberDiff line numberDiff line change
@@ -152,18 +152,8 @@ export class AppComponent implements OnInit {
152152
);
153153
setInterval(this.keepHistory.bind(this), this.PUSH_HISTORY_MS);
154154

155-
flatpickr('#date-inp', {
156-
defaultDate: new Date(), enableTime: true, enableSeconds: true, time_24hr: true,
157-
onClose: () => {
158-
if (this.isDateSelected) {
159-
let d1 = document.querySelector('#date-inp')['_flatpickr'].selectedDates[0] as Date;
160-
this.processInp4chips();
161-
this.dateChips.push({ isHumanDate: true, str: d1.toLocaleString(), val: d1.getTime() });
162-
this.isDateSelected = false;
163-
this.compute();
164-
}
165-
}, onChange: () => { this.isDateSelected = true; }
166-
});
155+
this.initFlatPickr();
156+
167157
this.setHtmlTitle();
168158
setTimeout(() => { this.isAnimateTitle = false }, 3000);
169159
}
@@ -215,6 +205,9 @@ export class AppComponent implements OnInit {
215205
this.bases = [];
216206
}
217207
this._usrSetting.setSetting('mode', this.settings.mode);
208+
if (this.settings.mode == 'date & time') {
209+
this.initFlatPickr();
210+
}
218211
this.refreshSideNav();
219212
}
220213

@@ -354,9 +347,11 @@ export class AppComponent implements OnInit {
354347
}
355348

356349
addChip(event: MatChipInputEvent): void {
357-
const value = event.value;
350+
let value = event.value.trim();
358351
this.processInp4chips();
359-
this.dateChips.push({ val: Number(value), str: value, isHumanDate: false });
352+
if (value.length > 0) {
353+
this.dateChips.push({ val: Number(value), str: value, isHumanDate: false });
354+
}
360355
this.compute();
361356
}
362357

@@ -369,10 +364,37 @@ export class AppComponent implements OnInit {
369364
let s = this._usrDateInp.nativeElement.value.trim();
370365
let unit = e.option.viewValue;
371366
this.processInp4chips();
367+
if (s.length < 1) {
368+
s = '1';
369+
}
372370
this.dateChips.push({ isHumanDate: false, str: s + unit, val: Number(s) });
373371
this.compute();
374372
}
375373

374+
private initFlatPickr() {
375+
if (this.settings.mode != 'date & time') {
376+
return;
377+
}
378+
setTimeout(() => {
379+
let dateElem = document.querySelector('#date-inp');
380+
if (dateElem && dateElem['_flatpickr']) {
381+
return;
382+
}
383+
flatpickr('#date-inp', {
384+
defaultDate: new Date(), enableTime: true, enableSeconds: true, time_24hr: true,
385+
onClose: () => {
386+
if (this.isDateSelected) {
387+
let d1 = document.querySelector('#date-inp')['_flatpickr'].selectedDates[0] as Date;
388+
this.processInp4chips();
389+
this.dateChips.push({ isHumanDate: true, str: d1.toLocaleString(), val: d1.getTime() });
390+
this.isDateSelected = false;
391+
this.compute();
392+
}
393+
}, onChange: () => { this.isDateSelected = true; }
394+
});
395+
}, 1000);
396+
}
397+
376398
private setHtmlTitle() {
377399
let e = document.getElementsByTagName('title')[0];
378400
this.translate.get('appTitle').subscribe(x => {
@@ -408,7 +430,7 @@ export class AppComponent implements OnInit {
408430
}
409431

410432
private processInp4chips() {
411-
let s = this._usrDateInp.nativeElement.value;
433+
let s = this._usrDateInp.nativeElement.value.trim();
412434
if (this.opChips4DateTime.includes(s)) {
413435
this.dateChips.push({ isHumanDate: false, str: s, val: 0 });
414436
}
@@ -418,11 +440,16 @@ export class AppComponent implements OnInit {
418440

419441
private compute4dateTime(): string {
420442
let s = '';
421-
for (let c of this.dateChips) {
443+
for (let i = 0; i < this.dateChips.length; i++) {
444+
let c = this.dateChips[i];
422445
if (c.isHumanDate) {
423446
s += c.val;
424447
} else {
425-
s += c.str;
448+
if (i > 0 && !this.dateChips[i - 1].isHumanDate && !this.isContainDateOp(c.str) && !this.isContainDateOp(this.dateChips[i - 1].str)) {
449+
s += '+' + c.str;
450+
} else {
451+
s += c.str;
452+
}
426453
}
427454
}
428455
for (let u in TIME_UNIT_STR[this.settings.lang]) {
@@ -432,6 +459,15 @@ export class AppComponent implements OnInit {
432459
return s;
433460
}
434461

462+
private isContainDateOp(s: string) {
463+
for (let i = 0; i < this.opChips4DateTime.length; i++) {
464+
if (s.includes(this.opChips4DateTime[i])) {
465+
return true;
466+
}
467+
}
468+
return false;
469+
}
470+
435471
private getResult4DateTime(result: string): string {
436472
let hasHumanDate = false;
437473
for (let c of this.dateChips) {

0 commit comments

Comments
 (0)