Skip to content

Commit f58bf8f

Browse files
committed
use ng2-flatpickr date time bug
1 parent f8ef8ff commit f58bf8f

9 files changed

+71
-51
lines changed

README.md

+38-20
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,75 @@
11
# hasap
22

3-
A web based general purpose math calculator. https://canbax.github.io/hasap/
4-
## features
5-
### Use it as an app
6-
Since **Hasap** is a progressive web app, you can download it and use it as an app.
3+
A web-based general-purpose math calculator.https://canbax.github.io/hasap/
74

5+
## features
86

97
### wide variaety of functions
10-
This application uses [math.js](https://github.com/josdejong/mathjs) for calculations.[math.js](https://github.com/josdejong/mathjs) has many [functions](https://mathjs.org/docs/reference/functions.html). You can see list of functions on the below image.
8+
This application uses [math.js](https://github.com/josdejong/mathjs) for calculations.[math.js](https://github.com/josdejong/mathjs) has many [functions](https://mathjs.org/docs/reference/functions.html). You can see list of functions from user-interface.
119
<p align="center">
1210
<img src="docs/showFunctions.gif" title="List of functions might be used in calculations"/>
1311
</p>
1412

1513
### automatic calculations
16-
As you type mathmatical expressions, the results are calculated automatically after you stopped typing. You don't need to press any button to calculate.
14+
15+
As you type mathematical expressions, the results are calculated automatically after you stopped typing. You don't need to press any button to calculate.
1716

1817
### 4 different modes
19-
There are 4 different modes. All the modes have its own screen keyboard.
2018

21-
In **programmer** mode you can make calculations in 4 different bases and can see the results in 4 different bases. (hexadecimal, decimal, octal, binary) You can copy the results of calculations in 4 different bases.
19+
There are 4 different modes. All the modes have their own screen keyboard.
20+
21+
In **programmer** mode you can make calculations in 4 different bases and can see the results in 4 different bases.(hexadecimal, decimal, octal, binary) You can copy the results of calculations in 4 different bases.
2222
<p align="center">
2323
<img src="docs/programmer.gif" title="List of time units"/>
2424
</p>
2525

26-
In **date & time** mode you can make date time calculations. For example, let's say you want to know how much time it is 13800 seconds minus 10000 milliseconds. You can use autocomplete for selecting time units like in the image below.
26+
In **date & time** mode you can make date-time calculations. For example, let's say you want to know how much time it is 13800 seconds minus 10000 milliseconds. You can use autocomplete for selecting time units like in the image below.
2727
<p align="center">
2828
<img src="docs/timeCalc.gif" title="List of time units"/>
2929
</p>
3030

31-
Here you can also make date time calculations. Let's say today is 4 of April 2020. What is the date after 90 days. It is 3 of July 2020.
31+
Here you can also make date-time calculations. Let's say today is 4 of April 2020. What is the date after 90 days. It is 3 of July 2020.
3232
<p align="center">
3333
<img src="docs/dateCalc.gif" title="List of time units"/>
3434
</p>
3535

36-
3736
### You can change your theme
37+
3838
<p align="center">
3939
<img src="docs/themes.gif" title="List of time units"/>
4040
</p>
4141

4242
### Copy-paste and others
43-
You can copy-paste input. You can copy the results of calculations. You can ignore commas in calculations.
44-
You can set the number of digits in result. You can set the precision in results.
43+
44+
You can copy-paste input. You can copy the results of the calculations. You can ignore commas in calculations.
45+
You can set the number of digits in the result. You can set the precision in results.
4546
<p align="center">
4647
<img src="docs/copyPasteIgnoreComma.gif" title="List of time units"/>
4748
</p>
4849

50+
## Use it as an app
51+
52+
Since **Hasap** is a progressive web app, you can download it and use it as an app. If you download it as an app, you can use it without the Internet.
53+
<p align="center">
54+
<img src="docs/win10-pwa.png" title="List of functions might be used in calculations"/>
55+
</p>
56+
I didn't consider mobile experience. So it is not good in mobile but it can be used anyway.
57+
<p align="center">
58+
<img src="docs/android-pwa1.jfif" title="UI in mobile"/>
59+
</p>
60+
<p align="center">
61+
<img src="docs/android-pwa0.jfif" title="Add as an app"/>
62+
</p>
63+
4964
## Yet another calculator. Why?
50-
I find the tools that I use frustrating and not functional enough.
51-
For example Windows 10 has a great calculator. It has more functionality than this one. I definetely inspired by it.
52-
- But you can not copy paste whole strings to it.
53-
- Let's say I did a long calculation like `2^4-145+4*23`. Why I can't change 145 to 146?
54-
- I really like button pressed effect on screen keyboard. But there is a small glitch which I found bit annoying. When I press a button conitiounly It is not shown pressed contiously, there is a small glitch.
65+
66+
I find the tools that I use frustrating and not functional enough.
67+
For example Windows 10 has a great calculator. It has more functionality than this one. I definitely inspired by it.
68+
69+
* But you can not copy paste whole strings to it.
70+
* Let's say I did a long calculation like `2^4-145+4*23` . Why I can't change 145 to 146?
71+
* I really like button pressed effect on screen keyboard. But there is a small glitch which I found bit annoying. When I press a button continiously It is not shown pressed contiously, there is a small glitch.
72+
5573
<p align="center">
5674
<img src="docs/win10-glitch.gif" title="I press the button continously but it is not shown pressed continously"/>
5775
</p>
@@ -61,10 +79,10 @@ I used google as calculator a lot. You can copy-paste text and change the string
6179
<img src="docs/googleAsCalculator.gif" title="Chaning unit type to degree does not work"/>
6280
</p>
6381

64-
I also used duckduckgo a lot. It wasn't good with trigonometic functions either.
82+
I also used duckduckgo a lot. It wasn't good with trigonometric functions either.
6583
<p align="center">
6684
<img src="docs/ddgCalculator.gif" title="Chaning unit type to degree does not work"/>
6785
</p>
6886

69-
I hope this tool would be handy and useful for people.
87+
I hope this tool would be handy and useful for people.
7088

docs/android-pwa0.jfif

45.3 KB
Binary file not shown.

docs/android-pwa1.jfif

161 KB
Binary file not shown.

docs/win10-pwa.png

20.1 KB
Loading

package-lock.json

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
"flatpickr": "^4.6.3",
3030
"hammerjs": "^2.0.8",
3131
"mathjs": "^6.6.2",
32+
"ng2-flatpickr": "^9.0.0",
3233
"ngx-clipboard": "^13.0.0",
3334
"rxjs": "^6.5.5",
3435
"tslib": "^1.11.1",

src/app/app.component.html

+3-1
Original file line numberDiff line numberDiff line change
@@ -167,9 +167,11 @@ <h5>{{'About'|translate}}</h5>
167167
</mat-radio-group>
168168
</div>
169169
<div *ngIf="settings.mode != 'programmer'">
170-
<button *ngIf="settings.mode == 'date & time'" mat-button mat-icon-button id="date-inp">
170+
<button *ngIf="settings.mode == 'date & time'" mat-button mat-icon-button (click)="toggleFlatPickr()">
171171
<mat-icon>date_range</mat-icon>
172172
</button>
173+
<ng2-flatpickr #fpElem [config]="dateTimePickerOpt" *ngIf="settings.mode == 'date & time'">
174+
</ng2-flatpickr>
173175
<span matRipple [matRippleTrigger]="resultRipple2" #resultRipple2 class="result-txt">{{results[1]}}</span>
174176
<button *ngIf="results[1].length > 0" mat-icon-button matSuffix (click)="copy(results[1])">
175177
<mat-icon>file_copy</mat-icon>

src/app/app.component.ts

+19-30
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ import { MathFnGroup, _filter, fnGroups, fnGroupExpo } from './math-fn';
1414
import { MatAutocompleteSelectedEvent } from '@angular/material/autocomplete';
1515
import { UserSettingService, UserSetting } from './user-setting.service';
1616
import { TranslateService } from '@ngx-translate/core';
17-
import flatpickr from 'flatpickr';
1817
import { ENTER } from '@angular/cdk/keycodes';
1918
import { MatChipInputEvent } from '@angular/material/chips';
2019
import { trigger, style, animate, transition } from '@angular/animations';
2120
import { MatRipple } from '@angular/material/core';
21+
import { FlatpickrOptions } from 'ng2-flatpickr';
2222

2323
@Component({
2424
selector: 'app-root',
@@ -101,6 +101,9 @@ export class AppComponent implements OnInit {
101101
@ViewChild(MatRipple) ripple: MatRipple;
102102
usrHint = '';
103103
isAnimateTitle = true;
104+
@ViewChild('fpElem', { static: false })
105+
private _fpElem;
106+
dateTimePickerOpt: FlatpickrOptions;
104107

105108
constructor(private _clipboardService: ClipboardService, private _snackBar: MatSnackBar, private _formBuilder: FormBuilder,
106109
private _usrSetting: UserSettingService, public translate: TranslateService) {
@@ -152,10 +155,21 @@ export class AppComponent implements OnInit {
152155
);
153156
setInterval(this.keepHistory.bind(this), this.PUSH_HISTORY_MS);
154157

155-
this.handleFlatPickr();
156-
157158
this.setHtmlTitle();
158159
setTimeout(() => { this.isAnimateTitle = false }, 3000);
160+
161+
this.dateTimePickerOpt = {
162+
defaultDate: new Date(), enableTime: true, enableSeconds: true, time_24hr: true,
163+
onClose: (e: Date[]) => {
164+
if (this.isDateSelected) {
165+
this.processInp4chips();
166+
this.dateChips.push({ isHumanDate: true, str: e[0].toLocaleString(), val: e[0].getTime() });
167+
this.isDateSelected = false;
168+
this.compute();
169+
}
170+
}, static: true, altFormat:'F j, Y', altInput: true,
171+
onChange: () => { this.isDateSelected = true; }
172+
};
159173
}
160174

161175
syncInp() {
@@ -205,7 +219,6 @@ export class AppComponent implements OnInit {
205219
this.bases = [];
206220
}
207221
this._usrSetting.setSetting('mode', this.settings.mode);
208-
this.handleFlatPickr();
209222
this.refreshSideNav();
210223
}
211224

@@ -369,32 +382,8 @@ export class AppComponent implements OnInit {
369382
this.compute();
370383
}
371384

372-
private handleFlatPickr() {
373-
let dateElem = document.querySelector('#date-inp');
374-
375-
if (this.settings.mode != 'date & time') {
376-
if (dateElem && dateElem['_flatpickr']) {
377-
dateElem.parentNode.removeChild(dateElem);
378-
}
379-
} else {
380-
setTimeout(() => {
381-
if (dateElem && dateElem['_flatpickr']) {
382-
return;
383-
}
384-
flatpickr('#date-inp', {
385-
defaultDate: new Date(), enableTime: true, enableSeconds: true, time_24hr: true,
386-
onClose: () => {
387-
if (this.isDateSelected) {
388-
let d1 = document.querySelector('#date-inp')['_flatpickr'].selectedDates[0] as Date;
389-
this.processInp4chips();
390-
this.dateChips.push({ isHumanDate: true, str: d1.toLocaleString(), val: d1.getTime() });
391-
this.isDateSelected = false;
392-
this.compute();
393-
}
394-
}, onChange: () => { this.isDateSelected = true; }
395-
});
396-
}, 1000);
397-
}
385+
toggleFlatPickr() {
386+
this._fpElem.flatpickr.toggle();
398387
}
399388

400389
private setHtmlTitle() {

src/app/app.module.ts

+2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import { TranslateHttpLoader } from '@ngx-translate/http-loader';
2121
import { HttpClient, HttpClientModule } from '@angular/common/http';
2222
import { MatChipsModule } from '@angular/material/chips';
2323
import { MatRippleModule } from '@angular/material/core';
24+
import { Ng2FlatpickrModule } from 'ng2-flatpickr';
2425

2526
import { AppComponent } from './app.component';
2627
import { ScreenKeyboardComponent } from './screen-keyboard/screen-keyboard.component';
@@ -52,6 +53,7 @@ import { environment } from '../environments/environment';
5253
MatListModule,
5354
MatExpansionModule,
5455
HttpClientModule,
56+
Ng2FlatpickrModule,
5557
MatChipsModule,
5658
MatRippleModule,
5759
TranslateModule.forRoot({

0 commit comments

Comments
 (0)