GitHub PullRequestReviewCommentEvent at 2014-02-17 17:39:19
Repository: encore-ui
Actor: klamping
Payload: {"comment":{"url":"https://api.github.com/repos/rackerlabs/encore-ui/pulls/comments/9798976","id":9798976,"diff_hunk":"@@ -1,11 +1,154 @@\n /*jshint node:true*/\n var Page = require('astrolabe').Page;\n+var exceptions = require('exceptions');\n+var _ = require('lodash');\n \n-exports.rxPaginate = Page.create({\n-    // Elements\n-    rxPaginateElement: {\n-        get: function () {\n-            return this.findElement(this.by.id('rxPaginateElement'));\n+var page = {\n+\n+    lnkCurrentPage: {\n+        get: function () { return this.rxPaginate.findElement(this.by.css('ul.pagination li.active a')); }\n+    },\n+\n+    tblPagination: {\n+        get: function () { return this.rxPaginate.findElements(this.by.css('ul.pagination li a')); }\n+    },\n+\n+    jumpToPage: {\n+        value: function (pageNumber) {\n+            var page = this;\n+            return this.getPageNumbers().then(function (pageNumbers) {\n+                var pageIndex = _.indexOf(pageNumbers, pageNumber);\n+                if (pageIndex === -1) {\n+                    if (_.min(pageNumbers) > pageNumber) {\n+                        page.jumpToLowestAvailablePage_(pageNumber);\n+                        page.jumpToPage(pageNumber);\n+                    } else {\n+                        page.jumpToHighestAvailablePage_(pageNumber, pageNumbers);\n+                        page.jumpToPage(pageNumber);\n+                    }\n+                } else {\n+                    return page.tblPagination.then(function (pagination) {\n+                        // pageIndex + 2 will offset the [\"First\", \"Prev\"] links.\n+                        return pagination[pageIndex + 2].then(function (page) {\n+                            return page.then(function (p) {\n+                                p.click();\n+                            });\n+                        });\n+                    });\n+                }\n+            });\n+        }\n+    },\n+\n+    firstPage: {\n+        value: function () {\n+            return this.tblPagination.then(function (pages) {\n+                return pages[0].then(function (firstPage) {\n+                    firstPage.click();\n+                });\n+            });\n+        }\n+    },\n+\n+    previousPage: {\n+        value: function () {\n+            return this.tblPagination.then(function (pages) {\n+                return pages[1].then(function (previousPage) {\n+                    previousPage.click();\n+                });\n+            });\n+        }\n+    },\n+\n+    nextPage: {\n+        value: function () {\n+            return this.tblPagination.then(function (pages) {\n+                return pages[pages.length - 2].then(function (nextPage) {\n+                    nextPage.click();\n+                });\n+            });\n+        }\n+    },\n+\n+    lastPage: {\n+        value: function () {\n+            return this.tblPagination.then(function (pages) {\n+                return _.last(pages).then(function (lastPage) {\n+                    lastPage.click();\n+                });\n+            });\n         }\n+    },\n+\n+    getCurrentPageNumber: {\n+        value: function () {\n+            return this.lnkCurrentPage.then(function (currentPage) {\n+                return currentPage.getText().then(function (text) {\n+                    return parseInt(text, 10);\n+                });\n+            });\n+        }\n+    },\n+\n+    getPageNumbers: {\n+        value: function () {\n+            // Return a list of page numbers available to paginate to.\n+            var pages = [];\n+            var css = 'a[ng-click$=\"pageNumber = n\"]';\n+            return this.driver.findElements(this.by.css(css)).then(function (pageNumbers) {\n+                    _.forEach(pageNumbers, function (pageNumber) {\n+                        return pageNumber.then(function (number) {\n+                            return number.getText().then(function (n) {\n+                                pages.push(parseInt(n, 10));\n+                            });\n+                        });\n+                    });\n+                    return pages;\n+                });\n+        }\n+    },\n+\n+    jumpToLowestAvailablePage_: {\n+        value: function (pageNumber) {\n+            var page = this;\n+            return this.tblPagination.then(function (pagination) {\n+                return pagination[2].then(function (lowestLink) {\n+                    if (pageNumber < 1) {\n+                        page.NoSuchPageException.thro('Page number must be >= 1');\n+                    }","path":"src/rxPaginate/rxPaginate.page.js","position":123,"original_position":123,"commit_id":"c5a5206bdca31fb10be97317b75c483f93699215","original_commit_id":"c5a5206bdca31fb10be97317b75c483f93699215","user":{"login":"klamping","id":706039,"avatar_url":"https://gravatar.com/avatar/6823d6d1ee14bd068007bd60ddb6a41a?d=https%3A%2F%2Fidenticons.github.com%2F449300d7903a2004fb26a2d86e232cfa.png&r=x","gravatar_id":"6823d6d1ee14bd068007bd60ddb6a41a","url":"https://api.github.com/users/klamping","html_url":"https://github.com/klamping","followers_url":"https://api.github.com/users/klamping/followers","following_url":"https://api.github.com/users/klamping/following{/other_user}","gists_url":"https://api.github.com/users/klamping/gists{/gist_id}","starred_url":"https://api.github.com/users/klamping/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/klamping/subscriptions","organizations_url":"https://api.github.com/users/klamping/orgs","repos_url":"https://api.github.com/users/klamping/repos","events_url":"https://api.github.com/users/klamping/events{/privacy}","received_events_url":"https://api.github.com/users/klamping/received_events","type":"User","site_admin":false},"body":"Thinking this through more, I don't think this function should take a number. Wouldn't it be better if it did the work of figuring out the lowest page for you? As it stands, this function is more 'go to page passed in and throw error if outside limit'. ","created_at":"2014-02-17T17:39:19Z","updated_at":"2014-02-17T17:39:19Z","html_url":"https://github.com/rackerlabs/encore-ui/pull/50#discussion_r9798976","pull_request_url":"https://api.github.com/repos/rackerlabs/encore-ui/pulls/50","_links":{"self":{"href":"https://api.github.com/repos/rackerlabs/encore-ui/pulls/comments/9798976"},"html":{"href":"https://github.com/rackerlabs/encore-ui/pull/50#discussion_r9798976"},"pull_request":{"href":"https://api.github.com/repos/rackerlabs/encore-ui/pulls/50"}}}}