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

refresh on active #625

Closed
wants to merge 1 commit into from
Closed

refresh on active #625

wants to merge 1 commit into from

Conversation

abudel
Copy link

@abudel abudel commented Feb 2, 2015

From #271,
By setting to true the attribute "refresh-on-active" in the "ui-select-choiche", refresh method is called when the component is activated the first time.

@dimirc
Copy link
Contributor

dimirc commented Feb 17, 2015

Can you add some tests?

@diogodomanski
Copy link

I've followed the instructions posted by abudel, but it didn't work.

@abudel
Copy link
Author

abudel commented Feb 23, 2015

Hi diogodomanski
you need to build the repository. Btw i made a plunker to see it in action.
Hope with this example you can figure it out.

@diogodomanski
Copy link

Thanks abudel. When will this feature be available in master branch?

@dimirc
Copy link
Contributor

dimirc commented Feb 26, 2015

@abudel LGTM. As you might saw already, the source was split onto multiple files, can you rebase this PR so I can merge it?

PD:Will be better if you just create a new branch from current master and apply all the changes, then just do a git push origin --force to overwrite the old commits

@dimirc dimirc added this to the 0.10.x milestone Feb 26, 2015
@abudel
Copy link
Author

abudel commented Feb 26, 2015

@dimirc thanks! i updated the repo as you asked.

@Envek
Copy link

Envek commented Mar 2, 2015

@abudel it's hard to test your changes as dist/select.js doesn't contain changes from src/*.js files (so it doesn't work), I had to patch dist/select.js manually in my app. After that everything worked 🎆!
Please clean up your pull request: dist/select.js should contain only your changes and not 1000+ unrelated ones (it's not even possible to see diff on GitHub). Changes to bower.json and other files probably also shouldn't go into PR. You probably should do as @dimirc have said above (new branch, apply changes, forced push of new branch to this branch).

But thank you very much for your work! 👍 This PR will definitely fix my #619 issue after merging and publishing in bower.

@dimirc
Copy link
Contributor

dimirc commented Mar 3, 2015

@abudel I still see changes to /dist files. Pls keep in mind that we should only change /src files. Also could you try to squash it all into one commit?

Let me know if you have any trouble on this changes.

@abudel
Copy link
Author

abudel commented Mar 5, 2015

@dimirc i don't get it. i tried to follow your instructions: 33f4d9f. Confused 😕

@Envek
Copy link

Envek commented Mar 5, 2015

@abudel In your fork's master branch (and it's specified as this PR branch) there is currently not only commit 33f4d9f but also another commits after it with various merges and so on. See your fork's Network page for a visual representation.

If you do not need these extra commits in your fork's master, you can do the following:

git checkout master             # Ensure we are on source branch
git reset --hard 33f4d9f        # Cut it to this commit
git push origin master --force  # Overwrite remote branch to be the same as local branch (to end with 33f4d9f)

After that contents of this PR will be updated. Please note that other commits from your master branch will disappear. If you do need these commits, please create a new branch from commit 33f4d9f and create a new PR from it (I see that there is a refresh-on-active branch).

This article from GitHub Help may help you: Using pull requests

@abudel
Copy link
Author

abudel commented Mar 6, 2015

@Envek thanks for your help. I followed your instructions.
@dimirc Now it should be ok.

@Envek
Copy link

Envek commented Mar 20, 2015

@dimirc can you please take a look?
@abudel seems like it needs to be rebased.

@diogodomanski
Copy link

Can anyone fix these merge conflits and make this feature available in master branch? Thanks

@milkolori
Copy link

Hey guys will this feature be available in the master brach, it is very useful?

@venkatesh13
Copy link

+1 Really Usefull. add this one to master. Thank you

@dmitry-dedukhin
Copy link

It's a must-have feature, could you please integrate it?

@sdvcrx
Copy link

sdvcrx commented Aug 4, 2015

+1

@dmitry-dedukhin
Copy link

Hi.

Seems that this can be achieved by custom directive like the following:

myModule.directive('uiSelectLazyLoad', function ($parse) {
    return {
        restrict: 'A',
        scope: true, // create new but not isolated scope
        compile: function (element, attrs) {
            var $choices = element.find('ui-select-choices'),
                refreshAttr = $choices.attr('refresh'),
                refreshFunc = null;

            if(!refreshAttr) {
                return;
            }

            refreshFunc = $parse(refreshAttr, /* interceptorFn */ null, /* expensiveChecks */ true);

            // replace all 'refresh' contents by own function
            $choices.attr('refresh', 'ptUiSelectLazyLoadHandler($event)');

            return function linkFn(scope, element, attrs) {
                var activated = false;

                element.one('click', function () {
                    activated = true;
                    scope.ptUiSelectLazyLoadHandler();
                });

                scope.ptUiSelectLazyLoadHandler = function ($event) {
                    if(!activated) {
                        return;
                    }
                    refreshFunc(scope);
                };
            };
        }
    };
});

The directive can be used like this:

        <ui-select ng-model="dummy" ui-select-lazy-load>
            <ui-select-match>{{$select.selected.name}}</ui-select-match>
            <ui-select-choices
                    repeat="soft.id as soft in softs"
                    refresh="loadSoft($select.search)"
                    refresh-delay="200">
                <div ng-bind-html="soft.name | highlight: $select.search"></div>
            </ui-select-choices>
        </ui-select>

Function specified in "refresh" attribute on <ui-select-choices> will be called first time only after control "activation" i.e. after first click on ui-select.

@Gillardo
Copy link

+1, must have feature!

@ghost
Copy link

ghost commented Sep 9, 2015

+1

4 similar comments
@Falldog
Copy link

Falldog commented Sep 12, 2015

+1

@maxzubr
Copy link

maxzubr commented Sep 24, 2015

+1

@fabio-paiva-sp
Copy link

+1

@ronaldotijucas
Copy link

+1

@ronaldotijucas ronaldotijucas mentioned this pull request Oct 8, 2015
@krotkiewicz
Copy link

+1

1 similar comment
@maiiku
Copy link

maiiku commented Nov 6, 2015

+1

@wald-tq wald-tq mentioned this pull request Nov 10, 2015
@shogondo
Copy link

+1

@maxbundchen
Copy link

Will this feature be in the dist? It's a must-have!

@adrien-k
Copy link

+1

3 similar comments
@dilerarc
Copy link

+1

@ftferes
Copy link

ftferes commented Feb 15, 2016

+1

@jeremypeters
Copy link

+1

@wesleycho wesleycho removed this from the 0.10.x milestone Mar 27, 2016
@Gillardo
Copy link

when is this going to be pulled into master?

@PRISMAY
Copy link

PRISMAY commented May 17, 2016

+1

1 similar comment
@oromand
Copy link

oromand commented May 26, 2016

+1

@gustavogsimas
Copy link

Why is this not pulled yet? Its an awesome feature... +1

@user378230
Copy link
Contributor

@twizzzlers:

This branch has conflicts that must be resolved

Note you could probably achieve this with custom directive such as:

app.directive('refreshOnActivate', function() {
  return {
    require: 'uiSelect',
    link: function(scope, element, attrs, $select) {
      var _activate = $select.activate;     
      $select.activate = function (initSearchValue, avoidReset) {        
        _activate(initSearchValue, avoidReset);
        $select.refresh();
      }
    }
  };
});

@shyamal890
Copy link

Any update on this feature?

@user378230
Copy link
Contributor

user378230 commented Aug 9, 2016

@shyamal890 My reply is literally just before yours! 😅

@shyamal890
Copy link

@user378230 Thats right, but I was wondering when the solution would be added to master?

@user378230
Copy link
Contributor

user378230 commented Aug 9, 2016

It can't be, as I said in my reply: This branch has conflicts that must be resolved

@shyamal890 also did you try using separate directive as I mentioned?

@kotmatpockuh
Copy link

+1

@fabiopaiva-praxis
Copy link

fabiopaiva-praxis commented Oct 24, 2016

This works for me:

<ui-select-choices refresh="myCustomRefresh($select.search)" refresh-on-active="true"></ui-select-choices>
app.directive('refreshOnActive', refreshOnActive);

function refreshOnActive() {
    return {
        restrict: 'A',
        link: refreshOnActiveLink,
        scope: {
            refreshOnActive: '=',
            refresh: '@'
        }
    }

    function refreshOnActiveLink(scope, element) {
        if (! scope.refreshOnActive === true) {
            return;
        }
        var storedFunction = scope.$parent.$select.refresh;
        scope.$parent.$select.refresh = function() {};

        var element = angular.element(element).closest('.ui-select-container');
        var fn = function() {
            scope.$parent.$select.refresh = function() {
                storedFunction(scope.refresh);
            };
            scope.$parent.$select.refresh.call();
            element.unbind('click', fn);
        };
        element.bind('click', fn);
    }
}

@Jefiozie
Copy link
Contributor

As the PR #1845 is merged please verify if it fix your problem.

@Jefiozie
Copy link
Contributor

Jefiozie commented Feb 6, 2017

Closing it down due to comment above (believe this should fix it), if needed you can reopen it.
Thanks.

@Jefiozie Jefiozie closed this Feb 6, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.