-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feature(datepicker): let users define his own date model implementation #1753
Comments
This is duplicate of the existing issue #754 |
@pkozlowski-opensource I know about But If I want to pass a I want to submit a PR that issues these problems, exposing two methods Do you understand the problem? If there is another way to solve this please let me know. |
@edriang I do understand the issue, yes. And if you read through, more specifically here: #754 (comment) you will see:
This is why this issue is open as we need to be able to handle the case you are describing.
Awesome! We are busy with shipping 1.0 but this part of the datepicker is high on our priority list so any help would be more than appreciated! Now, could you, before starting any work on a PR, prepare a short design and put it in #754? This would allow us to validate our understanding / thinking and avoid back-and-forth on the actual PR. cc @maxokorokov |
Let the user define what structure to use for his application model. Before user was forced to use NgbDateStruct for the model. This means that the user has to convert from is own date-model implementation to the one used by ng-bootstrap/datepicker. Now user can define his own date-model through fromInput and toOutput methods declared in NgbDateParserFormatter. Users can overwrite these methods to convert from and to JavaScript native Date object. Closes ng-bootstrap#1753 BREAKING CHANGE: NgbDateParserFormatter now has to implement fromInput and toOutput methods. Retro-compatibility methods implementation can be found in NgbDateISOParserFormatter class.
Thanks @pkozlowski-opensource, I needed this feature right now so I've already worked on a patch in a fork. Let me know if you can see this commit details: edriang@683116a I will try to explain the modifications below:
In this way, I think that internal implementation of the datepicker should behave as always. At least all test cases were passed successfully. Let me know if you need some extra detail or if you think on a better approach to solve this. |
@edriang 2 quick thoughts (more tomorrow):
|
Re-opening as we start to have some good discussion here! |
@pkozlowski-opensource Great!, I will break those methods into a separated class. Any suggestion for the class name? Maybe something like I open also to suggestions about the methods names. Currently Thanks |
Hmmm... Not sure. 'modelToStruct' / Also note that material is taking a slightly different approach here: https://github.com/angular/material2/blob/master/src/lib/core/datetime/date-adapter.ts @maxokorokov WDYT? |
Let the user define what structure to use for his application model. Before user was forced to use NgbDateStruct for the model. This means that the user has to convert from is own date-model implementation to the one used by ng-bootstrap/datepicker. Now user can define his own date-model through modelToNgbDate and ngbDateToModel methods declared in NgbDateModelAdapter. Users can overwrite these methods to convert from and to his own model implementation. A default adapter is configured by default in the module using NgbDateModelStructAdapter class implementation. Closes ng-bootstrap#1753
Ok @pkozlowski-opensource , I took some of your suggestions with little modifications on names:
More details can be seen on the following commit: edriang@29f3a78
I can see they have only one adapter to configure all. In NgBootstrap configuration is split in different classes / services (ie: formatter/parser and I18N) In NgBootstrap you have |
Is there a way for me to get my hands on this? I really need the modelToNgbDate and ngbDateToModel functionality. |
@pkozlowski-opensource any suggestion about how to proceed? Do you need something else before sending the PR? Thanks in advance |
@edriang the proposal sounds good to me but I would love to have input from @maxokorokov (original author and maintainer of the datepicker). You can go ahead with a PR if you are not shying away from back-and-forth on the review :-) |
Hi there, that looks good to me as start, that's definitely one of the top priority things to fix. Would like to have a couple of questions clarified before you go with the PR:
class NgbDateAdapter<T> {
toModel(NgbDate): T;
fromModel(T): NgbDate;
} So implementations would be named
|
Hi @maxokorokov, thank you for the suggestions. I've committed a new version, you can see the changes here: edriang@38b335a About your questions:
Done. Liked the renaming suggestions.
I don't know if this is necessary, as a user I only care about ngModel. I mean, I don't have any problem configuring maxDate, minDate, etc, using NgbDateStruct format. I wanted to make few changes as possible regarding internal model manipulation. Do you think this is necessary?
Done
I think this is necessary if we want to keep retro-compatibility with actual implementation. Changing default Date model will be a breaking change for anyone using this datepicker With this commit, I've also pushed a modification on the demo project. I've updated the API doc section regarding NgbDateAdapter and also provided a minimal example defining a custom NgbDateNativeAdapter and using it in the example component. I'll be waiting for any other change or suggestion. Thanks |
Can't wait to see this avaliable in a release. |
@edriang, thanks, great job! I like it so far, looked through your code, haven't found any major issues for me. Do you mind opening a pull request for this one? I think lots of people would we happy with this change
It would be nice to have it in the long run. If you're using, say, momentjs in your app, you would expect it everywhere, all datepicker APIs included. But agree that for now ngModel is enough, l'll open a separate issue for this.
Agreed. Will open another issue to add other default adapters to be bundled with ng-bootstrap. |
Hi @maxokorokov, sorry for bothering you. I've tried to pull the request, but I'm having trouble with some I'm getting an error when the
Do you have any clue what could it be the problem? Because when running the demo with Thanks in advance for any help. |
Hey, @edriang. You have a missing Also did a quick pass through the code |
Hi @edriang, what is the current state of your implementation? Do you plan the PR or is there any issue stopping you from it? Thank you! |
Anyone can merge this? Is there anything or any additional step I'm missing in order to progress? |
Hi @edriang, it seems like additional work was requested by @maxokorokov. Do you plan to follow up or shall I try to finish it? Thank you! |
Hi @saxicek, sorry, I forgot to answer. I no longer work for the company that used Angular and where I needed this functionality. Feel free to fork the repo and continue. Any help you need you can ask although. |
Please remember, the issues forum is NOT for support requests. It is for bugs and feature requests only.
Please read https://github.com/ng-bootstrap/ng-bootstrap/blob/master/CONTRIBUTING.md and search
existing issues (both open and closed) prior to opening any new issue and ensure you follow the instructions therein.
Bug description:
The user is forced to use
NgbDateStruct
as his application-model for dates.If as a user I want to manage the dates using native JavaScript
Date
class, then I first need to convertDate
toNgbDateStruct
before assigning it to the date-pickers' model.Then, before persisting the model I need to convert back from
NgbDateStruct
toDate
.It could be nice that
NgbDateParserFormatter
let the user to define methods to convert from user-model date implementation to ng-bootstrap/datepickerNgbDate
implementation, and then back fromNgbDate
to user-model date implementation.Link to minimally-working plunker that reproduces the issue:
You can fork a plunker from one of our demos and use it as a starting point.
Please note that we can not act on bug reports without a minimal reproduction scenario in plunker. Here is why:
https://github.com/ng-bootstrap/ng-bootstrap#you-think-youve-found-a-bug
Version of Angular, ng-bootstrap, and Bootstrap:
Angular: 4.0.3
ng-bootstrap: 1.0.0-beta.1
Bootstrap: 4.0.0-beta
The text was updated successfully, but these errors were encountered: