From b8b595c842bd8aae1eb994464d9172e163a67e57 Mon Sep 17 00:00:00 2001 From: Fabrice Bellingard Date: Tue, 30 Aug 2011 18:08:55 +0200 Subject: [PATCH] SONAR-893 Provide a new "History" service for projects --- .../resources/org/sonar/l10n/core.properties | 23 +++++ .../app/controllers/project_controller.rb | 28 ++++++ .../app/views/layouts/_layout.html.erb | 3 + .../app/views/project/history.html.erb | 90 +++++++++++++++++++ 4 files changed, 144 insertions(+) create mode 100644 sonar-server/src/main/webapp/WEB-INF/app/views/project/history.html.erb 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 @@ -591,6 +592,28 @@ manual_measures.save_and_add_button=Save & Add new manual_measures.pending_message=Pending measures are marked with orange box. Their values will be integrated to project during next analysis. +#------------------------------------------------------------------------------ +# +# 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 @@ -63,6 +63,9 @@ <% if (@project.project? || @project.view? || @project.subview?) %>
  • <%= message('project_roles.page') -%>
  • <% end %> + <% if (@project.project?) %> +
  • <%= message('project_history.page') -%>
  • + <% end %> <% if (@project.project?) %>
  • <%= message('project_deletion.page') -%>
  • <% 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? %> +

    <%= message('project_history.page_title') -%>

    +
    + + + +
    + + + + + + + + + + + + + + + <% + current_year = nil + current_month = nil + @snapshots.each do |snapshot| + number_of_events = snapshot.events.size + time = snapshot.created_at + %> + + + + + + + + + + <% + current_year = time.year + current_month = time.month + end + %> + +
    <%= message('project_history.col.year') -%><%= message('project_history.col.month') -%><%= message('project_history.col.time') -%><%= message('project_history.col.events') -%><%= message('project_history.col.action') -%> + +
    <%= time.year unless time.year == current_year -%><%= l(time, :format => '%B').capitalize unless time.month == current_month -%> + <% if snapshot.status == 'U' %> + + <% end %> + <%= l time, :format => :long -%> + <%= snapshot.events.map{|e| e.name}.join(', ') -%> + + <% + 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 + %> + ) { 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 %> + + <% unless snapshot.islast %> + + <% end %> +
    +
    + +<% end %> \ No newline at end of file -- 2.39.5