-
Notifications
You must be signed in to change notification settings - Fork 6.7k
feat(timepicker): add timepicker directive #358
Conversation
I need a little help with the |
Do you have a plnkr for the timepicker directive anywhere? |
It is not the final implementation as may things have changed since I started writing this PR, but the overall behavior can be found on the initial discussion. #332 |
@bekos looks very nice as well. For this implementation I would only suggest a restriction of times, like suggested for the datepicker. Perhaps comparable to the filter solution I suggested. |
@jhiemer Thank you. In this case I don't think it's good to pass the validation / restriction implementation into the directive. Someone can |
@bekos sounds like a plan. Great! |
Hi @bekos, this looks great! 🎯 For the Try something like this: function wheelThatMouse(delta) {
var e = $.Event("mousewheel");
e.wheelDelta = delta;
return e;
}
it('should mousewheel', function() {
myElm.trigger( wheelThatMouse(10) );
}); |
Hi again @ajoslin and thank you! :-D Another thanks for your help on the mousewheel tests. I owe you! 👍 |
Alright, I have a few suggestions for improvement, mainly on the UI side.. I'm basing a lot of these thoughts on timepicker UIs like this that are standard already, like the android timepicker. Improvements:
Questions:
Lastly, perhaps we should close this PR and re-open it with a branch on bootstrap main, so we can pull/push our little ideas to it. If that's ok with you? |
@ajoslin I agree with the UI changes/improvements you propose, and these are changes that can be made just in the template. The initial template is the one that @ProLoser suggested and is used in some popular implementations of the timepicker for bootstrap. Example: http://jdewit.github.io/bootstrap-timepicker/ Probably we can provide two different templates, since
Feel free to close this one and create a new branch in main if you think this will also help others to participate to make things better :-) |
My 2 cents here: I don't think we should use any of the AngularJS 1.1.x features till it becomes stable. Many people are still on 1.0.x and we would exclude all of them. @bekos @ajoslin where do we stand with this one? Are there any outstanding items to discuss / decide upon? |
@pkozlowski-opensource Totally agree that we should not use "unstable" features at this moment. The matter here is that @ajoslin proposed a different template. In my opinion both templates deserve to be in the source files and offered to the users. So, the question (if you agree with me) is how do we offer these two alternatives to the users, at this moment? The other thing is user's input validation. For the initial version I didn't want to focus on user's input validation, but to user's interaction with the provided controls. Actually, I was thinking for start to use |
OMG! I was doing this very wrong :-) Refactored and dropped 40 LOC even if I added 30 LOC for user's input validation. I finally changed template to a mix of what @ajoslin proposed & what was already there (changed meridian to button, but kept the Has anyone time for a code review? |
} | ||
}, true); | ||
|
||
var convert24to12Hours = function(hours) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Couldn't this just be 'return hours % 12'?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No. The problem is with 0 and 12. Both must return 12 instead of 0 that mod returns.
Probably I can do this in one line :-)
I was interrupted by a phone call while reviewing this yesterday. I'll try to take a peak in a little bit. |
@ajoslin Thank you. I don't like the way that user's input is validated. Probably you can come up with a better solution :-) |
mousewheel: true | ||
}) | ||
|
||
.directive('timepicker', ['$filter', '$parse', 'timepickerConfig', function ($filter, $parse, timepickerConfig) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could just inject padFilter
here instead of $filter
. Then you wouldn't have to call the filter('pad')
getter here. Tiny unnoticeable performance boost 🎉
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right. Thx.
Your validation looks fine to me :-) I like that you do it on blur. Messing with the ngModelCtrl $parsers pipeline of each hours/minute input would get funky IMO. It looks a lot better now for sure :-) |
After @ajoslin 's review & comments (thank you 👍 ) I think there is no other outstanding item at this moment. |
It LGTM! Just pulled down the newest and tried it out. I also love the little eyes you put on the docs for the observed attributes! 👀 😄 Anyone else have objections to merging this bad boy? |
So I used it again .. and I dunno if I still agree with my earlier sentiment about validation :-) I just used it and it really doesn't feel "angular-y" that the time only actually changes on blur. It would be better to create sub-directives (hours-input, minutes-input) which hook into a timepicker controller and use ngModel $parsers to validate. Also, I noticed that if you for example input "12:33" and the timestep is 15 minutes, it will force you to go back to "12:30". I think if the user inputs it should override the timestep, that makes the most since. What do you think @bekos? |
@ajoslin I am not so keen about the normalization of minutes. This is something I saw in a timepicker (I don't remember which one) and I tried to reproduce. Probably it will be better off. If user wants to normalize the initial minutes can do it in the controller probably. About the validation what you describe is absolutely better, but it sounds like trouble :-) |
Probably instead of extra directives, we can hook with more events, like |
Yeah, that works. |
@ajoslin Took even easier approach with I hope you like it now :-) |
I like it! Good work. I did find a bug though. To reproduce:
It really does look good after that tiny bugfix though. It's really sleek now with the instant date change on input 👍 |
@ajoslin This was not a bug, it was more like a missing feature :-P Since the model was invalidated, the toggle of meridian, wasn't triggering a reset of values! Anyway, I fixed it and added a test for Andy''s use case. I hope everything is(:question:) OK now! |
Everything's OK now! (http://youtu.be/ocy_kp8HT_k) LGTM, let's merge :-) |
@bekos could you merge it? Looks like it is fine now :-) |
@pkozlowski-opensource Sure! I'll do it later today :-) |
Was playing with it so finally landed as 9bc5207. Yay! |
Based on #332