From 8876b0b60eee2f9c1283023a6b6492840610a6b5 Mon Sep 17 00:00:00 2001 From: Fabrice Bellingard Date: Wed, 21 Nov 2012 10:31:50 +0100 Subject: [PATCH] SONAR-2342 Add "recent history" feature => Provide a way to quickly come back to a resource which has been recently browsed --- .../resources/org/sonar/l10n/core.properties | 3 + sonar-server/pom.xml | 1 + .../WEB-INF/app/views/layouts/_head.html.erb | 1 + .../app/views/layouts/_layout.html.erb | 1 + .../views/layouts/_resource_history.html.erb | 17 +++++ .../WEB-INF/app/views/resource/index.html.erb | 6 ++ .../main/webapp/javascripts/recent-history.js | 75 +++++++++++++++++++ .../src/main/webapp/stylesheets/layout.css | 22 ++++++ 8 files changed, 126 insertions(+) create mode 100644 sonar-server/src/main/webapp/WEB-INF/app/views/layouts/_resource_history.html.erb create mode 100644 sonar-server/src/main/webapp/javascripts/recent-history.js diff --git a/plugins/sonar-core-plugin/src/main/resources/org/sonar/l10n/core.properties b/plugins/sonar-core-plugin/src/main/resources/org/sonar/l10n/core.properties index ff533f8caf4..18cdbac7b8f 100644 --- a/plugins/sonar-core-plugin/src/main/resources/org/sonar/l10n/core.properties +++ b/plugins/sonar-core-plugin/src/main/resources/org/sonar/l10n/core.properties @@ -294,6 +294,9 @@ layout.plugins=Plugins layout.evaluation=Embedded database should be used for evaluation purpose only layout.ie6_warn=Your web browser is outdated. This website may not display correctly. layout.dashboards=Dashboards +layout.recent_history.link=Recent history +layout.recent_history.clear=Clear +layout.recent_history.no_history_yet=No history yet sidebar.project_settings=Configuration sidebar.security=Security diff --git a/sonar-server/pom.xml b/sonar-server/pom.xml index 8b5c20e7aa5..2fc2a0123bf 100644 --- a/sonar-server/pom.xml +++ b/sonar-server/pom.xml @@ -247,6 +247,7 @@ **/dashboard-min.js **/duplication-min.js **/resource-min.js + **/recent-history.js ${project.build.directory}/${project.build.finalName}/javascripts/sonar.js diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/layouts/_head.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/layouts/_head.html.erb index b19a1f05f9c..9e37fa96731 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/layouts/_head.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/layouts/_head.html.erb @@ -53,6 +53,7 @@ <%= javascript_include_tag 'dashboard' %> <%= javascript_include_tag 'duplication' %> <%= javascript_include_tag 'resource' %> + <%= javascript_include_tag 'recent-history' %> <% end %> + + \ No newline at end of file diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/resource/index.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/resource/index.html.erb index 1f452a265e9..a5c092c063d 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/resource/index.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/resource/index.html.erb @@ -1,3 +1,9 @@ + + <%= render :partial => 'tabs' -%> <%= render :partial => "resource/header_#{@extension.getId()}" -%> diff --git a/sonar-server/src/main/webapp/javascripts/recent-history.js b/sonar-server/src/main/webapp/javascripts/recent-history.js new file mode 100644 index 00000000000..986bc362d43 --- /dev/null +++ b/sonar-server/src/main/webapp/javascripts/recent-history.js @@ -0,0 +1,75 @@ +window.Sonar = {}; + +Sonar.RecentHistory = function (applicationContext) { + this.appContext = applicationContext; + this.translations = {}; + this.addTranslation = function (key, value) { + this.translations[key] = value; + return this; + } +}; + +Sonar.RecentHistory.prototype.getRecentHistory = function() { + var sonarHistory = localStorage.getItem("sonar_recent_history"); + if (sonarHistory == null) { + sonarHistory = new Array(); + } else { + sonarHistory = JSON.parse(sonarHistory); + } + return sonarHistory; +}; + +Sonar.RecentHistory.prototype.clear = function () { + localStorage.clear(); + $("sonar_recent_history_dropdown").hide(); + this.populateRecentHistoryDropDown(); +}; + +Sonar.RecentHistory.prototype.add = function (resourceKey, resourceName, resourceQualifier) { + var sonarHistory = this.getRecentHistory(); + + if (resourceKey != '') { + var newEntry = {'key': resourceKey, 'name': resourceName, 'qualifier': resourceQualifier}; + // removes the element of the array if it exists + for (i = 0; i < sonarHistory.length; i++) { + var item = sonarHistory[i]; + if (item['key'] == resourceKey) { + sonarHistory.splice(i, 1); + break; + } + } + // then add it to the beginning of the array + sonarHistory.unshift(newEntry); + // and finally slice the array to keep only 10 elements + sonarHistory = sonarHistory.slice(0,10); + + localStorage.setItem("sonar_recent_history", JSON.stringify(sonarHistory)); + } +}; + +Sonar.RecentHistory.prototype.populateRecentHistoryDropDown = function () { + var dropdown = $j('#sonar_recent_history_dropdown'); + dropdown.empty(); + + var recentHistory = this.getRecentHistory(); + + recentHistory.forEach(function (resource) { + dropdown.append('
  • ' + + resource['name'] + + '
  • '); + }); + + if (recentHistory.length == 0) { + dropdown.append('
  • ' + this.translations['no_history_yet'] + '
  • '); + } else { + dropdown.append('
  • ' + this.translations['clear'] + '
  • '); + } +}; diff --git a/sonar-server/src/main/webapp/stylesheets/layout.css b/sonar-server/src/main/webapp/stylesheets/layout.css index 4ba2bcf8bde..a3ce8614e73 100644 --- a/sonar-server/src/main/webapp/stylesheets/layout.css +++ b/sonar-server/src/main/webapp/stylesheets/layout.css @@ -138,14 +138,36 @@ body, a { #bc li a { text-decoration: none; } + #bc li a:hover, #bc li a:focus { text-decoration: underline; } + #crumbs-ops { float: right; padding: 0 5px 0 0; } +#sonar_recent_history_dropdown a { + color: #000 !important; + display: inline !important; + padding-left: 5px !important; +} + +#sonar_recent_history_dropdown li:hover a { + color: #fff !important; +} + +#sonar_recent_history_dropdown li.clear_list { + background-color: #EFEFEF !important; + border-top: 1px solid #CCCCCC !important; + color: #EFEFEF !important; +} + +#sonar_recent_history_dropdown li.clear_list:hover a { + color: #000 !important; +} + #nonav { text-align: left; margin: 50px 180px 0; -- 2.39.5