Skip to content
This repository was archived by the owner on Oct 2, 2019. It is now read-only.

fix(#271) if option is set the refresh function is getting the request. #1845

Merged
merged 11 commits into from
Jan 25, 2017

Conversation

Jefiozie
Copy link
Contributor

@Jefiozie Jefiozie commented Nov 3, 2016

I think this is something that is requested multiple times: #271, #625,#619.

Used the initial changes from 625 with some minor adjustments to let everything work and only watch variables if needed.

If this is a viable solution i think all the other can be closed down.

@user378230
Copy link
Contributor

Could we instead pass ctrl.open as an argument to the refresh function?

@Jefiozie
Copy link
Contributor Author

Jefiozie commented Nov 3, 2016

Instead of the refreshIsActive ? Will run some tests with it.

DId some test changing the isActive to open will have the same behaviour.

@user378230
Copy link
Contributor

user378230 commented Nov 3, 2016

Ah we actually have two "issues" here:

  1. refresh is being called when ui-select is initialized (but not opened)
  2. refresh is not called when select is activated
  1. Can be solved by passing ctrl.open as an argument to the refresh function (inside the refresh function users can say if select is not open then don't call server)
    Maybe actually user's can already do this themselves, by defining refresh="fetchFromServer($select.search, $select.open)"?
  2. Can be solved by calling refresh in $select.open $watch like you did.

For 2 we don't need a new attribute, just call refresh every time, as we call refresh whenever $select.search changes anyway.

@Jefiozie
Copy link
Contributor Author

Jefiozie commented Nov 4, 2016

But if we look if ctrl.open is true we could fix also point 1 right? If you search but it is not active (open will be set to true in the function active). This will prevent the refresh function to go off on initializing and only execute the function when it is active. Right?

@Jefiozie
Copy link
Contributor Author

Jefiozie commented Nov 4, 2016

Did some test to verify if this solution is working.....and it will break a lot of tests. Need to dig a little bit deeper because in the test the function openDropDown will set the ctrl.open manually to true. I thought it should be $select.activate() but still problems. Ideas are welcome 😉

@Jefiozie Jefiozie closed this Nov 4, 2016
@Jefiozie Jefiozie reopened this Nov 4, 2016
@user378230
Copy link
Contributor

user378230 commented Nov 5, 2016

@Jefiozie I think you misunderstand, we do not need to do anything with ctrl.open because user can already do refresh="fetchFromServer($select.search, $select.open)" right?

Then the user can check manually in fetchFromServer(...) if select is open.

I cannot test this right now but I think it should be correct?


The only thing extra we need to do it, is call ctrl.refresh in activate (so that refresh is called whenever select is opened).

Does that make sense?

@user378230
Copy link
Contributor

Tagging #1174 for reference.

@Jefiozie
Copy link
Contributor Author

Jefiozie commented Nov 6, 2016

@user378230 , understand you now and agree on both points. Will remove the extra parameters/ variables and add the ctrl.refresh in activate function

@Jefiozie
Copy link
Contributor Author

Jefiozie commented Nov 6, 2016

@user378230 ,
So making these changes have a lot of impact. This peace of code is executed on initializing uiSelectChoicesDirective.js#L68. Adding a check on this if the $select.open equals true (as this is set by the activate function) it will break all tests but has the behavior as it should ( I believe).

Next problem:
In a use case where the ui-select doesn't use the refresh functionality it will not set the items until it has a search value. Trying to find out why this is happening, if you don't use the refresh it should just set the items. But it looks like the have a relation somewhere.

Example of this problem

Keep you posted

@@ -55,10 +55,9 @@ uis.directive('uiSelectChoices',


$select.parseRepeatAttr(attrs.repeat, groupByExp, groupFilterExp); //Result ready at $select.parserResult

$select.refreshOnActive = scope.$eval(attrs.refreshOnActive);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets remove the attribute, this can be default functionality. We just call refresh more often now. (ie. When search.length == 0)

@@ -68,7 +67,7 @@ uis.directive('uiSelectChoices',
scope.$watch('$select.search', function(newValue) {
if(newValue && !$select.open && $select.multiple) $select.activate(false, true);
$select.activeIndex = $select.tagging.isActivated ? -1 : 0;
if (!attrs.minimumInputLength || $select.search.length >= attrs.minimumInputLength) {
if ((!attrs.minimumInputLength || $select.search.length >= attrs.minimumInputLength) && (!$select.refreshOnActive || ($select.refreshOnActive && $select.open))) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can undo changes here also. It will be up to user to check in their own function.

scope.$watch('$select.open', function(open) {
if (open) {
tElement.attr('role', 'listbox');
if(!angular.isUndefined($select.refreshOnActive)){
Copy link
Contributor

@user378230 user378230 Nov 7, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder instead if we do this in a uis:activate listener? (So it's clearer)

@Jefiozie
Copy link
Contributor Author

Jefiozie commented Nov 7, 2016

@user378230 I removed this already only I didn't commit it. Can commit the latest changes if you want?
All test will fail though.

@user378230
Copy link
Contributor

Commit what you have I can always pull down and test myself 😁

@Jefiozie
Copy link
Contributor Author

Jefiozie commented Nov 7, 2016

Here it is 😈

@@ -68,7 +66,7 @@ uis.directive('uiSelectChoices',
scope.$watch('$select.search', function(newValue) {
if(newValue && !$select.open && $select.multiple) $select.activate(false, true);
$select.activeIndex = $select.tagging.isActivated ? -1 : 0;
if (!attrs.minimumInputLength || $select.search.length >= attrs.minimumInputLength) {
if ((!attrs.minimumInputLength || $select.search.length >= attrs.minimumInputLength) && $select.open) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How come you changed this? I didn't think it would be needed? Does reverting this fix tests?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed this as this will prevent the initial request of the refresh function on initializing.
Yes reverting will fix the tests.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So we can revert this then. 😁

From my comment a few days ago:

the user can check manually in fetchFromServer(...) if select is open

Copy link
Contributor Author

@Jefiozie Jefiozie Nov 7, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Based on your comment yes we can revert. But still on initializing the refresh will be exectued. And this is not the behavior as it should be i think and also the problem of #271 ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I said before I want the user to check if it's open not us, users should already be able to do this. (I'm writing on mobile so my replies are short sorry!).

I also don't want to add breaking change as some users might like to load on initialise.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, if that is the case then we can revert almost everything. Only thing we need to add is when activating/focus the control we need to execute the refreshfunction.

The users can already check if it is open by adding (as you already mentioned) a second param $select.open

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup 😁 if I could add functionality while reducing lines of code I would! 😛 Hopefully we both learned something more about ui-select though 😂

@@ -257,8 +254,6 @@ uis.controller('uiSelectCtrl',
if (ctrl.dropdownPosition === 'auto' || ctrl.dropdownPosition === 'up'){
$scope.calculateDropdownPos();
}

$scope.$broadcast('uis:refresh');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was the removed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because nothing is listing on it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't users listen on it? 🤔 I don't use events much in angular so not completely sure!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes you could both I cannot think of any use case where you need this? And if we want to support this it should be in the refreshfunction instead of activate.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No harm is keeping it there now, someone might use it already and we should avoid breaking their use case 😬

Copy link
Contributor Author

@Jefiozie Jefiozie Nov 7, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agree, but still it doesn't feel good to leave code that does nothing.

@Jefiozie
Copy link
Contributor Author

Jefiozie commented Nov 7, 2016

@user378230, so reverted the broadcast event. But also found a other use case where we could fix the original problem.By checking if the newValue !== '' and check ifnewValue !== oldValue we will prevent the initial call on load. As the watch is fired every time a user types in a char it will execute the refresh function.

Second we will fire a refresh on activating the ui-select where the value of $select.search is already empty (as it should because nothing is present at that time).

Do you believe this is a good way to solve the problem?

p.s. all test are passing. 😄

@user378230
Copy link
Contributor

user378230 commented Nov 8, 2016

But also found a other use case where we could fix the original problem.By checking if the newValue !== '' and check ifnewValue !== oldValue we will prevent the initial call on load. As the watch is fired every time a user types in a char it will execute the refresh function.

Isn't this the use case I said we wanted to keep? (Calling the refresh function when the directive is first loaded?) Or am I misunderstanding what you said...

After this PR we should have 3 different routes to calling refresh:

  1. When directive is first loaded ($select.search = "", $select.open = false) - existing
  2. When ui-select is opened ($select.search = "", $select.open = true) - new
  3. When $select.search changes ($select.search = "xyz", $select.open = true) - existing

You are making me work hard for this PR haha! 😆

@Jefiozie
Copy link
Contributor Author

Jefiozie commented Nov 8, 2016

@user378230 , thanks for all the feedback great PR 😆!
Then this is it (I believe) reverted all changed and added the new use case.

When ui-select is opened ($select.search = "", $select.open = true) - new

With some tests of course.

@user378230
Copy link
Contributor

@Jefiozie Think you just need to review your commit once more (can you revert empty line changes too and an extra whitespace)

And tests are like gold dust in library, so the more the better! 👍

@Jefiozie
Copy link
Contributor Author

Jefiozie commented Nov 8, 2016

@user378230, so after this intensive PR 😈 i think we have learned and made it a little beter. Right 😉 , again thanks for the feedback/ help and good discussion.

@user378230
Copy link
Contributor

@Jefiozie check the files tab on here please... 🙂

@Jefiozie
Copy link
Contributor Author

Jefiozie commented Nov 9, 2016

@user378230 ,Think it looks better now.

@user378230
Copy link
Contributor

Queued for next released. Just want to undo the unnecessary empty line changes before I merge.

@Jefiozie
Copy link
Contributor Author

Jefiozie commented Dec 4, 2016

@user378230 , Any ideas when this will be merged?

@aaronroberson
Copy link
Contributor

@Jefiozie Can you resolve the conflicts so that I can merge? Thanks for all your work!

@Jefiozie
Copy link
Contributor Author

Jefiozie commented Jan 5, 2017

Sure will have a look.

Does @user378230 not maintain this repository any more or is he gone (as far as you know)?

@Jefiozie
Copy link
Contributor Author

@aaronroberson , see my previous comment.

Does @user378230 not maintain this repository any more or is he gone (as far as you know)?
Many issue and PR's are still open and I think we need to do something about it 😄

@Jefiozie
Copy link
Contributor Author

@aaronroberson , made the changes. I can be merged also can you reply on previous comments?

@Jefiozie
Copy link
Contributor Author

@aaronroberson sorry to bother you but I'm seeing the issue list grow and want to help getting this a little bit smaller. Can you merge this? Thanks.

@Jefiozie
Copy link
Contributor Author

@aaronroberson @user378230 sorry to bother you guys. But this libary needs some attention.
Can I maybe help you guys in a way?

CC @wesleycho , maybe you can contact people above? (thanks and sorry to bother you just wanne keep te libary "up to date")

@aaronroberson
Copy link
Contributor

Can you send me an email to discuss having you help maintain the project? My email is aaronaroberson at gmail.

@Jefiozie Jefiozie merged commit 3642a1d into angular-ui:master Jan 25, 2017
cloudrick pushed a commit to hardcoretech/ui-select that referenced this pull request Feb 17, 2017
fix(angular-ui#271) if option is set the refresh function is getting the request.
@Jefiozie Jefiozie deleted the 625_refreshOnActive branch March 21, 2017 07:12
@houwei544
Copy link

when ui-select is multiple , function refresh can't get $select .

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants