From f5c17aba00cd5e775c9144f6f0e6eefc2a8f3d9d Mon Sep 17 00:00:00 2001 From: Stas Vilchik Date: Thu, 3 Apr 2014 17:14:29 +0600 Subject: [PATCH] SONAR-5165 It should be possible to use up and down arrows to navigate through results in Issues page Enable for coding rules --- .../views/coding-rules-list-view.coffee | 43 ++++++++++++++++++- sonar-server/src/main/js/issues/extra.js | 4 +- 2 files changed, 44 insertions(+), 3 deletions(-) diff --git a/sonar-server/src/main/coffee/coding-rules/views/coding-rules-list-view.coffee b/sonar-server/src/main/coffee/coding-rules/views/coding-rules-list-view.coffee index 93db305b2b5..c91beba027e 100644 --- a/sonar-server/src/main/coffee/coding-rules/views/coding-rules-list-view.coffee +++ b/sonar-server/src/main/coffee/coding-rules/views/coding-rules-list-view.coffee @@ -19,5 +19,46 @@ define [ listView: @, app: @options.app + initialize: -> + openRule = (el) -> el.click() + @openRule = _.debounce openRule, 300 + key.setScope 'list' + + + onRender: -> + key 'up', 'list', => @selectPrev() + key 'down', 'list', => @selectNext() + + + selectIssue: (el, open) -> + @$('.active').removeClass 'active' + el.addClass 'active' + @openRule el if open + + selectFirst: -> - @$el.find('*:first').click() + @selected = -1 + @selectNext() + + + selectNext: -> + if @selected < @collection.length - 1 + @selected++ + child = @$el.children().eq @selected + container = jQuery('.navigator-results') + containerHeight = container.height() + bottom = child.position().top + child.outerHeight() + if bottom > containerHeight + container.scrollTop(container.scrollTop() - containerHeight + bottom) + @selectIssue child, true + + + selectPrev: -> + if @selected > 0 + @selected-- + child = @$el.children().eq @selected + container = jQuery('.navigator-results') + top = child.position().top + if top < 0 + container.scrollTop(container.scrollTop() + top) + @selectIssue child, true \ No newline at end of file diff --git a/sonar-server/src/main/js/issues/extra.js b/sonar-server/src/main/js/issues/extra.js index a291721ed9c..0cf04865b0e 100644 --- a/sonar-server/src/main/js/issues/extra.js +++ b/sonar-server/src/main/js/issues/extra.js @@ -246,7 +246,7 @@ define( initialize: function() { var openIssue = function(el) { el.click(); }; - this.openIssue = _.debounce(openIssue, 300); + this.openRule = _.debounce(openIssue, 300); }, @@ -262,7 +262,7 @@ define( this.$('.active').removeClass('active'); el.addClass('active'); if (open) { - this.openIssue(el); + this.openRule(el); } }, -- 2.39.5