chieffancypants / angular-hotkeys

Configuration-centric keyboard shortcuts for your Angular apps.
http://chieffancypants.github.io/angular-hotkeys/
MIT License
1.68k stars 254 forks source link

Integration with Angular UI-Router #5

Open devmondo opened 10 years ago

devmondo commented 10 years ago

hi,

this is great project, but as most of us use Angular UI Router, is there a way to integrate with it instead of Angular Default Router?

thanks in advanced.

chieffancypants commented 10 years ago

I figured this question would come up, but I simply don't have any experience with the UI Router, nor am I using it in production, so it would be tough for me to support it. I'm happy to review/accept PRs from someone with more experience in it.

joshbowdoin commented 10 years ago

I believe this pull request (partially) satisfies the request: https://github.com/chieffancypants/angular-hotkeys/pull/9

willhoag commented 10 years ago

+1

julianpaulozzi commented 10 years ago

+1

jeffwhelpley commented 10 years ago

+2

cesarhdz commented 10 years ago

+1

madhat2r commented 10 years ago

+1

Excerpts from César Hernández's message of 2014-06-06 13:54:28 -0500:

+1


Reply to this email directly or view it on GitHub: https://github.com/chieffancypants/angular-hotkeys/issues/5#issuecomment-45372023

gschuager commented 9 years ago

+1

Birowsky commented 9 years ago

+me and couple of friends

reyx commented 9 years ago

+1

towu commented 9 years ago

+1

apitts commented 9 years ago

+1

bonatoc commented 9 years ago

Hello,

Most of you probably already figured this out, but just in case you need to go from a detail page to the next/previous one. This is based on ui-router's official sample (http://angular-ui.github.io/ui-router/sample/#/), and "contacts.detail" has been replaced with "pages.detail" (http://angular-ui.github.io/ui-router/sample/states.js). Anyway, this is what I have in my "pages.detail" controller :

                           // SEE contacts.detail IN UI-ROUTER EXAMPLE
      .state('pages.detail', {
        url: '/{pageID:[0-9]{1,4}}',
        views: {
          '': {
            templateUrl: 'pages.detail.html',
            controller: ['$scope', '$stateParams',
              function page_detail_function (  $scope,   $stateParams) {
                // $scope.contact = utils.findById($scope.contacts, $stateParams.contactId);
                $scope.pageID = $stateParams.pageID;
                $rootScope.pageID = $scope.pageID;
              }]
          },
           // ....

            // ID OF PAGE CALLED
            $scope.pageID = $stateParams.pageID; // ui-router
             pageID = $scope.pageID;
            pageIDasInt = intval(pageID);

                             // ...

            // CALCULATE PREV AND NEXT PAGES IDS
            function getPrevNextPages(pageID)
            {                   
                // mainarrayData.OrdersArray.Products : THE JSON OBJECT I USE FOR DETAIL PAGES (originally contacts.json), REPLACE WITH YOURS
                                    pagesArray = Object.keys(mainarrayData.OrdersArray.Products); 

                $.each(pagesArray, function(key, value) {
                            if(value === pageID)
                            {
                                currentKey = key;
                            }
                        });
                previousPageID = pagesArray[currentKey - 1];
                nextPageID = pagesArray[currentKey + 1];

                arrayOfResults['previousPageID'] = previousPageID;
                arrayOfResults['nextPageID'] = nextPageID;

                return(arrayOfResults);
            }
            // -------- EOF - CALCULATE PREV AND NEXT PAGES IDS

            arrayOfResults = [];
            arrayOfResults = getPrevNextPages(pageID);
            previousPageID = arrayOfResults['previousPageID'];
            nextPageID = arrayOfResults['nextPageID'];

            firstPage = pagesArray[0];
            console.log('---> firstPage : ');
            console.log(firstPage);

            lastPage = (pagesArray.length)-1;
            console.log('---> lastPage : ');
            console.log(lastPage);

            // INFINITE LOOP - IF LAST OR NEXT UNDEFINED, SET LAST TO FIRST, AND FIRST TO LAST
            if (typeof(previousPageID) == "undefined") {
                console.log('---> previousPageID IS UNDEFINED : ');
                previousPageID = lastPage;
                // DEBUGGING previousPageID
                console.log('---> previousPageID NOW IS : ');
                console.log(previousPageID);

            };
            if (typeof(nextPageID) == "undefined") {
                console.log('---> nextPageID IS UNDEFINED : ');
                nextPageID = firstPage;
                // DEBUGGING nextPageID
                console.log('---> nextPageID NOW IS : ');
                console.log(nextPageID);
            };
            // -------- EOF - INFINITE LOOP - IF LAST OR NEXT UNDEFINED, SET LAST TO FIRST, AND FIRST TO LAST

            $rootScope.previousPageID = previousPageID || '';
            $rootScope.nextPageID = nextPageID || '';   
            $rootScope.typeOfPreviousPageID = typeof(previousPageID) || '';
            $rootScope.typeOfNextPageID = typeof(nextPageID) || '';

            $rootScope.pagesArray = pagesArray;

            // ANGULAR HOTKEYS SETTINGS FOR GOING TO NEXT PAGE / PREV PAGE THROUGH KEYBOARD
            hotkeys.add({
                combo: 'right',
                description: 'Next page',
                callback: function() {
                  $state.go("pages.detail",{pageID:nextPageID});
                }
              });

            hotkeys.add({
                combo: 'left',
                description: 'Previous page',
                callback: function() {
                  $state.go("pages.detail",{pageID:previousPageID});
                }
              });
            // -------- EOF - ANGULAR HOTKEYS SETTINGS FOR GOING TO NEXT PAGE / PREV PAGE THROUGH KEYBOARD
rmariuzzo commented 9 years ago

@chieffancypants what needs to be done to merge the PR? May I help?

chieffancypants commented 9 years ago

@rmariuzzo Do you mean #9? It was incomplete. I merged the code into a branch so others could help and participate but it's still in a pretty broken state. Essentially, all the current tests should also pass when using ui-router, so any help you can provide would be amazing!

rmariuzzo commented 9 years ago

@chieffancypants, good! I will check it out to collaborate and add that feature. I will also make sure all test passes.

aneuhauser commented 9 years ago

+1

jmls commented 8 years ago

@rmariuzzo were you able to get angular-ui working ?

Evanion commented 8 years ago

Any update on this?

rmariuzzo commented 8 years ago

@jmls unfortunately I didn't have enough time… by that time. :/

jondthompson commented 8 years ago

+1

jmelosegui commented 8 years ago

+1

niemyjski commented 8 years ago

+1

AshMcConnell commented 8 years ago

+1

andrewmcconville commented 8 years ago

+1

tejasrivastav commented 7 years ago

+1

vaibhav-jain commented 7 years ago

Any update ??

lwthatcher commented 6 years ago

+1

fjakop commented 6 years ago

+1