]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-2342 Add "recent history" feature
authorFabrice Bellingard <fabrice.bellingard@sonarsource.com>
Wed, 21 Nov 2012 09:31:50 +0000 (10:31 +0100)
committerFabrice Bellingard <fabrice.bellingard@sonarsource.com>
Wed, 21 Nov 2012 16:11:35 +0000 (17:11 +0100)
=> Provide a way to quickly come back to a resource which has been
   recently browsed

plugins/sonar-core-plugin/src/main/resources/org/sonar/l10n/core.properties
sonar-server/pom.xml
sonar-server/src/main/webapp/WEB-INF/app/views/layouts/_head.html.erb
sonar-server/src/main/webapp/WEB-INF/app/views/layouts/_layout.html.erb
sonar-server/src/main/webapp/WEB-INF/app/views/layouts/_resource_history.html.erb [new file with mode: 0644]
sonar-server/src/main/webapp/WEB-INF/app/views/resource/index.html.erb
sonar-server/src/main/webapp/javascripts/recent-history.js [new file with mode: 0644]
sonar-server/src/main/webapp/stylesheets/layout.css

index ff533f8caf420d62c6d8b5c4513d77e921508e0c..18cdbac7b8f4ef600014ba001fc1724944b6852b 100644 (file)
@@ -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
index 8b5c20e7aa50f3a20369fc6f892bbbf04718a9e7..2fc2a0123bf1c87c494a1fc426a2e7d605fc7276 100644 (file)
                 <include>**/dashboard-min.js</include>
                 <include>**/duplication-min.js</include>
                 <include>**/resource-min.js</include>
+                <include>**/recent-history.js</include>
               </includes>
               <output>${project.build.directory}/${project.build.finalName}/javascripts/sonar.js</output>
             </aggregation>
index b19a1f05f9c93d2d67d576c61f8ab86f70c81980..9e37fa96731f8d74c8bb980a213200be34cdc244 100644 (file)
@@ -53,6 +53,7 @@
     <%= javascript_include_tag 'dashboard' %>
     <%= javascript_include_tag 'duplication' %>
     <%= javascript_include_tag 'resource' %>
+    <%= javascript_include_tag 'recent-history' %>
   <% end %>
   <!--[if lte IE 8]><%= javascript_include_tag 'protovis-msie' -%><![endif]-->
   <script>var baseUrl = '<%= ApplicationController.root_context -%>';
index 84e35fd4a3b62715ff820f4fad8313e9b38f181b..5aaed32bc8b3c5b436d80e01e816be5993f1f03e 100644 (file)
@@ -34,6 +34,7 @@
         <li><a href="<%= ApplicationController.root_context -%>/sessions/new?return_to=<%= u (request.request_uri) -%>"><%= message('layout.login') -%></a></li>
       <% end %>
       <li><a href="<%= ApplicationController.root_context -%>/profiles"><%= message('layout.configuration') -%></a></li>
+      <%= render 'layouts/resource_history' -%>
     </ul>
   </div>
   <div id="searchResourcesResults" class="autocomplete" style="display:none"></div>
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/layouts/_resource_history.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/layouts/_resource_history.html.erb
new file mode 100644 (file)
index 0000000..46937d5
--- /dev/null
@@ -0,0 +1,17 @@
+<script>
+  var sonarRecentHistory = new Sonar.RecentHistory('<%= ApplicationController.root_context -%>')
+                                       .addTranslation('clear', '<%= message('layout.recent_history.clear') -%>')
+                                       .addTranslation('no_history_yet', '<%= message('layout.recent_history.no_history_yet') -%>');
+  
+  sonarRecentHistory.add('<%= @resource ? @resource.key : "" -%>', 
+                         '<%= @resource ? @resource.name : "" -%>', 
+                         '<%= @resource ? @resource.qualifier : "" -%>');  
+</script>
+
+<div class="dropdown">
+  <a href="#" class="link-more" onclick="sonarRecentHistory.populateRecentHistoryDropDown(); $('sonar_recent_history_dropdown').toggle();return false;"><%= message('layout.recent_history.link') -%></a>
+  
+  <ul style="display: none" class="dropdown-menu" id="sonar_recent_history_dropdown" onmouseout="this.hide();" onmouseover="this.show();">
+  </ul>
+  
+</div>
\ No newline at end of file
index 1f452a265e91bb9f210d1a1a5e74bb27a0860a83..a5c092c063d89d0f2d216ec0650036140915849c 100644 (file)
@@ -1,3 +1,9 @@
+<script>
+  sonarRecentHistory.add('<%= @resource.key -%>', 
+                         '<%= @resource.name -%>', 
+                         '<%= @resource.qualifier -%>');  
+</script>
+
 <%= 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 (file)
index 0000000..986bc36
--- /dev/null
@@ -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('<li><img width="16" height="16" src="'
+                          + sonarRecentHistory.appContext
+                          + '/images/q/'
+                          + resource['qualifier']
+                          + '.png"><a href="'
+                          + sonarRecentHistory.appContext
+                          + '/dashboard/index/'
+                          + resource['key']
+                          + '">' 
+                          + resource['name'] 
+                          + '</a></li>');
+  });
+  
+  if (recentHistory.length == 0) {
+    dropdown.append('<li style="color: #000 !important">' + this.translations['no_history_yet'] + '</li>');
+  } else {
+    dropdown.append('<li class="clear_list"><a href="#" onclick="sonarRecentHistory.clear(); return false;">' + this.translations['clear'] + '</a></li>');
+  }
+};
index 4ba2bcf8bde7da10dbf40d3bd9b69cd7f6850706..a3ce8614e73ee980d5df658e190c09e38d573514 100644 (file)
@@ -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;