aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFabrice Bellingard <bellingard@gmail.com>2011-08-30 18:08:55 +0200
committerFabrice Bellingard <bellingard@gmail.com>2011-08-30 18:08:55 +0200
commitb8b595c842bd8aae1eb994464d9172e163a67e57 (patch)
tree29ae9a99eab7fffeb92547cf32a787028742f304
parenta5985a04a701a9bdae0718fa8b4945ce54c9ba27 (diff)
downloadsonarqube-b8b595c842bd8aae1eb994464d9172e163a67e57.tar.gz
sonarqube-b8b595c842bd8aae1eb994464d9172e163a67e57.zip
SONAR-893 Provide a new "History" service for projects
-rw-r--r--plugins/sonar-l10n-en-plugin/src/main/resources/org/sonar/l10n/core.properties23
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/controllers/project_controller.rb28
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/views/layouts/_layout.html.erb3
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/views/project/history.html.erb90
4 files changed, 144 insertions, 0 deletions
diff --git a/plugins/sonar-l10n-en-plugin/src/main/resources/org/sonar/l10n/core.properties b/plugins/sonar-l10n-en-plugin/src/main/resources/org/sonar/l10n/core.properties
index 4fa26ccaed7..d8227b41094 100644
--- a/plugins/sonar-l10n-en-plugin/src/main/resources/org/sonar/l10n/core.properties
+++ b/plugins/sonar-l10n-en-plugin/src/main/resources/org/sonar/l10n/core.properties
@@ -280,6 +280,7 @@ project_roles.page=Project Roles
project_settings.page=Settings
project_links.page=Links
project_exclusions.page=Exclusions
+project_history.page=History
project_deletion.page=Deletion
quality_profiles.page=Quality Profiles
reviews.page=Reviews
@@ -593,6 +594,28 @@ manual_measures.pending_message=Pending measures are marked with orange box. The
#------------------------------------------------------------------------------
#
+# PROJECT HISTORY SERVICE
+#
+#------------------------------------------------------------------------------
+
+project_history.page_title=Delete quality snapshots from project history
+project_history.col.year=Year
+project_history.col.month=Month
+project_history.col.time=Time
+project_history.col.events=Events
+project_history.col.action=Action
+project_history.delete=Delete
+project_history.recover=Recover
+project_history.delete_snapshot=Delete snapshot
+project_history.recover_snapshot=Recover snapshot
+project_history.sure_to_delete_snapshot=Are you sure you want to delete this snapshot?
+project_history.x_snapshots_deleted={0} snapshot(s) will be deleted during next analysis.
+project_history.x_snapshots_recovered={0} snapshot(s) will not be deleted during next analysis.
+project_history.snapshot_will_be_deleted_next_analysis=This snapshot will be deleted during next analysis.
+
+
+#------------------------------------------------------------------------------
+#
# TIME MACHINE
#
#------------------------------------------------------------------------------
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/project_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/project_controller.rb
index 127e6816f68..ce250b2011a 100644
--- a/sonar-server/src/main/webapp/WEB-INF/app/controllers/project_controller.rb
+++ b/sonar-server/src/main/webapp/WEB-INF/app/controllers/project_controller.rb
@@ -47,6 +47,34 @@ class ProjectController < ApplicationController
redirect_to_default
end
+ def history
+ @project=Project.by_key(params[:id])
+ return access_denied unless is_admin?(@project)
+
+ if !@project.project?
+ redirect_to :action => 'index', :id => params[:id]
+ end
+
+ @snapshot=@project.last_snapshot
+ @snapshots = Snapshot.find(:all, :conditions => ["project_id=?", @project.id],
+ :include => 'events', :order => 'snapshots.created_at DESC')
+ end
+
+ def snapshot_history
+ project=Project.by_key(params[:id])
+ return access_denied unless is_admin?(@project)
+
+ sids = params[:snapshot_ids]
+ delete_operation = params[:operation] == "delete"
+ unless sids.empty?
+ status = delete_operation ? 'U' : 'P'
+ Snapshot.update_all("status='"+status+"'", ["id IN (?) or root_snapshot_id IN (?)", sids, sids])
+ flash[:notice] = message(delete_operation ? 'project_history.x_snapshots_deleted' : 'project_history.x_snapshots_recovered', :params => sids.size)
+ end
+
+ redirect_to :action => 'history', :id => project.id
+ end
+
def links
@project=Project.by_key(params[:id])
return access_denied unless is_admin?(@project)
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/layouts/_layout.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/layouts/_layout.html.erb
index d90df8671ef..477661b16fd 100644
--- a/sonar-server/src/main/webapp/WEB-INF/app/views/layouts/_layout.html.erb
+++ b/sonar-server/src/main/webapp/WEB-INF/app/views/layouts/_layout.html.erb
@@ -64,6 +64,9 @@
<li class="<%= 'selected' if request.request_uri.include?('/project_roles') -%>"><a href="<%= ApplicationController.root_context -%>/project_roles/index?resource=<%= @project.id -%>"><%= message('project_roles.page') -%></a></li>
<% end %>
<% if (@project.project?) %>
+ <li class="<%= 'selected' if request.request_uri.include?('/project/history') -%>"><a href="<%= ApplicationController.root_context -%>/project/history/<%= @project.id -%>"><%= message('project_history.page') -%></a></li>
+ <% end %>
+ <% if (@project.project?) %>
<li class="<%= 'selected' if request.request_uri.include?('/project/deletion') -%>"><a href="<%= ApplicationController.root_context -%>/project/deletion/<%= @project.id -%>"><%= message('project_deletion.page') -%></a></li>
<% end %>
<% end %>
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/project/history.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/project/history.html.erb
new file mode 100644
index 00000000000..a7adeb68616
--- /dev/null
+++ b/sonar-server/src/main/webapp/WEB-INF/app/views/project/history.html.erb
@@ -0,0 +1,90 @@
+<% if @snapshot.root? %>
+<h1><%= message('project_history.page_title') -%></h1>
+<br/>
+
+<script>
+ function updateSelectBox() {
+ var inputs = document.getElementsByName("snapshot_ids[]");
+ var selected = false;
+ for (i=0; i<inputs.length; i++) {
+ if (inputs[i].checked) { selected = true; break;}
+ }
+ $('operation-select-box').disabled = !selected;
+ }
+</script>
+
+<form action="<%= ApplicationController.root_context -%>/project/snapshot_history" method="POST" id="snapshots-form">
+<input type="hidden" name="id" value="<%= @project.id -%>"/>
+<table class="width100 data">
+ <thead>
+ <tr>
+ <th class="thin nowrap"><%= message('project_history.col.year') -%></th>
+ <th class="thin nowrap"><%= message('project_history.col.month') -%></th>
+ <th style="width: 18px"></th>
+ <th class="nowrap"><%= message('project_history.col.time') -%></th>
+ <th class="nowrap"><%= message('project_history.col.events') -%></th>
+ <th class="thin nowrap center"><%= message('project_history.col.action') -%></th>
+ <th class="thin nowrap">
+ <select id="operation-select-box" name="operation" onChange="$('snapshots-form').submit()" disabled>
+ <option value="" selected></option>
+ <option value="delete"><%= message('project_history.delete') -%></option>
+ <option value="recover"><%= message('project_history.recover') -%></option>
+ </select>
+ </th>
+ </tr>
+ </thead>
+ <tbody>
+ <%
+ current_year = nil
+ current_month = nil
+ @snapshots.each do |snapshot|
+ number_of_events = snapshot.events.size
+ time = snapshot.created_at
+ %>
+ <tr class="<%= cycle 'even','odd' -%>">
+ <td class="thin nowrap"><%= time.year unless time.year == current_year -%></td>
+ <td class="thin nowrap"><%= l(time, :format => '%B').capitalize unless time.month == current_month -%></td>
+ <td style="width: 18px">
+ <% if snapshot.status == 'U' %>
+ <img src="<%= image_path '/images/exclamation.png' -%>" title="<%= message('project_history.snapshot_will_be_deleted_next_analysis') -%>">
+ <% end %>
+ </td>
+ <td class="nowrap"><%= l time, :format => :long -%></td>
+ <td>
+ <%= snapshot.events.map{|e| e.name}.join(', ') -%>
+ </td>
+ <td class="thin nowrap center">
+ <%
+ unless snapshot.islast
+ button_value, operation, class_style, confirm_message = nil
+ if snapshot.status == 'P'
+ button_value = message('project_history.delete_snapshot')
+ operation = 'delete'
+ class_style = 'action red-button'
+ confirm_message = message('project_history.sure_to_delete_snapshot')
+ else
+ button_value = message('project_history.recover_snapshot')
+ operation = 'recover'
+ class_style = 'action'
+ end
+ %>
+ <input type="submit" value="<%= button_value-%>" id="delete_exclusions" class="<%= class_style -%>"
+ onclick="if (<%= confirm_message ? "confirm('"+confirm_message+"')" : 'true'-%>) { var f = document.createElement('form'); f.style.display = 'none'; this.parentNode.appendChild(f); f.method = 'POST'; f.action = '<%= url_for :action => "snapshot_history", :id => @project.id, :snapshot_ids => [snapshot.id], :operation => operation -%>';f.submit(); };return false;">
+ <% end %>
+ </td>
+ <td class="center">
+ <% unless snapshot.islast %>
+ <input id="snapshot_ids" name="snapshot_ids[]" type="checkbox" value="<%= snapshot.id -%>" onClick="updateSelectBox()" />
+ <% end %>
+ </td>
+ </tr>
+ <%
+ current_year = time.year
+ current_month = time.month
+ end
+ %>
+ </tbody>
+</table>
+</form>
+
+<% end %> \ No newline at end of file