]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-4712 Ensure most pages work without snapshot
authorJean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com>
Fri, 27 Sep 2013 14:01:54 +0000 (16:01 +0200)
committerJean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com>
Mon, 30 Sep 2013 13:44:52 +0000 (15:44 +0200)
Add message for pages available to empty (provisioned) projects
Modify layouts that don't depend explicitly on last snapshot
Hide 'Tools' section from the navigation sidebar on empty projects
Ensure 'Tools' section is available when last snapshot exists

plugins/sonar-core-plugin/src/main/resources/org/sonar/l10n/core.properties
sonar-server/src/main/webapp/WEB-INF/app/controllers/action_plans_controller.rb
sonar-server/src/main/webapp/WEB-INF/app/controllers/application_controller.rb
sonar-server/src/main/webapp/WEB-INF/app/controllers/dashboard_controller.rb
sonar-server/src/main/webapp/WEB-INF/app/controllers/project_controller.rb
sonar-server/src/main/webapp/WEB-INF/app/controllers/project_roles_controller.rb
sonar-server/src/main/webapp/WEB-INF/app/views/layouts/_layout.html.erb
sonar-server/src/main/webapp/WEB-INF/app/views/project/deletion.html.erb
sonar-server/src/main/webapp/WEB-INF/app/views/project/history.html.erb
sonar-server/src/main/webapp/WEB-INF/app/views/settings/_settings.html.erb

index e1f4a99751d7902b6d625e3b019741c9c49dadfd..5dc68304c8bc28d8d2b71fae77ad61e80faa12d3 100644 (file)
@@ -1716,6 +1716,7 @@ bulk_deletion.delete_all_ghosts=Delete all ghosts
 #------------------------------------------------------------------------------
 provisioning.missing.key=Key is missing
 provisioning.missing.name=Name is missing
+provisioning.no_analysis=No analysis has been performed since creation. The only available section is configuration.
 
 
 #------------------------------------------------------------------------------
index 579e250b930b123750a806eecac0503fba051674..bb4392c3db085100045ebea2ba385416491cd998 100644 (file)
@@ -77,8 +77,9 @@ class ActionPlansController < ApplicationController
 
   def load_resource
     @resource=Project.by_key(params[:id])
-    return redirect_to home_path unless @resource
+    return redirect_to(home_path) unless @resource
     access_denied unless has_role?(:admin, @resource)
+    @snapshot=@resource.last_snapshot
   end
 
   def load_action_plans
index 0c13f71d1e2c850e503d70a215426ff09e76070a..f24b4314c3773e58bd538b3c9d28bfc96127d341 100644 (file)
@@ -234,7 +234,6 @@ class ApplicationController < ActionController::Base
     @resource=@resource.permanent_resource
 
     @snapshot=@resource.last_snapshot
-    not_found("Snapshot not found") unless @snapshot
 
     access_denied unless has_role?(role, @resource)
   end
index 6ec1fe7f223daf3b97643215fe622ee8e0129a18..92819c4ce0ba4384f71b542975937474c6d060b8 100644 (file)
@@ -187,7 +187,7 @@ class DashboardController < ApplicationController
       @resource=@resource.permanent_resource
 
       @snapshot=@resource.last_snapshot
-      return project_not_found unless @snapshot
+      return project_not_analyzed unless @snapshot
 
       access_denied unless has_role?(:user, @resource)
 
@@ -200,6 +200,10 @@ class DashboardController < ApplicationController
     redirect_to :action => :index
   end
 
+  def project_not_analyzed
+    redirect_to :controller => :project, :action => :settings, :id => @resource
+  end
+
   def load_authorized_widget_definitions
     @authorized_widget_definitions=java_facade.getWidgets().select do |widget|
       roles = widget.getUserRoles()
@@ -209,13 +213,13 @@ class DashboardController < ApplicationController
 
   def load_widget_definitions(filter_on_category)
     @widget_definitions=java_facade.getWidgets().sort {|w1,w2| widgetL10nName(w1) <=> widgetL10nName(w2)}
-    
+
     @widget_categories=@widget_definitions.map(&:getWidgetCategories).flatten.uniq.sort
     unless filter_on_category.blank?
       @widget_definitions=@widget_definitions.select { |definition| definition.getWidgetCategories().to_a.include?(filter_on_category) }
     end
   end
-  
+
   def widgetL10nName(widget)
     Api::Utils.message('widget.' + widget.id + '.name')
   end
index cc4d9901857bc6e24829e0bc8966d6baa4577472..5fc629a33e4f11d7df610cb7a9673e5d6fce866c 100644 (file)
@@ -79,6 +79,7 @@ class ProjectController < ApplicationController
   def profile
     require_parameters :id
     @project=get_current_project_for_profile(params[:id])
+    @snapshot=@project.last_snapshot
   end
 
   # POST /project/set_profile?id=<project id>&language=<language>[&profile_id=<profile id>]
@@ -109,6 +110,7 @@ class ProjectController < ApplicationController
 
   def key
     @project = get_current_project(params[:id])
+    @snapshot = @project.last_snapshot
   end
 
   def update_key
index 3ada58fecef3b571a0a366533bb5af2c081db442..d0787d925e31620babb6e1dabbbfc35ab186bc29 100644 (file)
@@ -26,6 +26,7 @@ class ProjectRolesController < ApplicationController
   def index
     @project=Project.by_key(params[:id])
     access_denied unless is_admin?(@project)
+    @snapshot=@project.last_snapshot
   end
 
 end
index 4846e47b609af6c0d92742f87c55133796674ecf..2ef018270a40d7792d07fc252cd3cf0a037face8 100644 (file)
@@ -77,6 +77,8 @@
                 <a href="<%= ApplicationController.root_context -%>/dashboard/index/<%= @project.id -%>?did=<%= active_dashboard.dashboard_id -%><%= "&"+period_param if period_param -%>"><%= h active_dashboard.dashboard.name(true) -%></a>
               </li>
             <% end %>
+
+            <% if @snapshot %>
             <li class="spacer"></li>
             <li class="sidebar-title"><%= message('sidebar.tools') -%></li>
             <li class="<%= 'active' if request.request_uri.include?('/components/index') -%>">
             <li class="<%= 'active' if request.request_uri.include?('/drilldown/issues') -%>">
               <a href="<%= ApplicationController.root_context -%>/drilldown/issues/<%= @project.id -%><%= "?"+period_param if period_param -%>"><%= message('issues_drilldown.page') -%></a>
             </li>
-            <% project_metrics = @project.last_snapshot.metric_keys.to_java(:string) if @project.last_snapshot
-              controller.java_facade.getPages(Navigation::SECTION_RESOURCE, @project.scope, @project.qualifier, @project.language, project_metrics).each do |page|
-              page_url = (page.isController() ? "#{page.getId()}?id=#{@project.id}" : "/plugins/resource/#{@project.id}?page=#{page.getId()}")
-            %>
+              <% project_metrics = @project.last_snapshot.metric_keys.to_java(:string) if @project.last_snapshot
+                controller.java_facade.getPages(Navigation::SECTION_RESOURCE, @project.scope, @project.qualifier, @project.language, project_metrics).each do |page|
+                page_url = (page.isController() ? "#{page.getId()}?id=#{@project.id}" : "/plugins/resource/#{@project.id}?page=#{page.getId()}")
+              %>
               <li class="<%= 'active' if request.request_uri.include?(page_url) -%>">
                 <a href="<%= ApplicationController.root_context -%><%= page_url -%>"><%= h message(page.getId() + '.page', :default => page.getTitle()) -%></a>
               </li>
-            <% end %>
+              <% end %>
             <li class="<%= 'active' if controller.controller_path=='cloud' -%>">
               <a href="<%= ApplicationController.root_context -%>/cloud/index/<%= @project.id -%>"><%= message('clouds.page') -%></a>
             </li>
-            <% if controller.java_facade.getResourceTypeBooleanProperty(@project.qualifier, 'comparable') %>
+              <% if controller.java_facade.getResourceTypeBooleanProperty(@project.qualifier, 'comparable') %>
               <li class="<%= 'active' if request.request_uri.include?('/comparison/index') -%>">
                 <a href="<%= ApplicationController.root_context -%>/comparison/index?resource=<%= @project.key -%>"><%= message('comparison.page') -%></a>
               </li>
+              <% end %>
             <% end %>
 
-
           <% elsif selected_section==Navigation::SECTION_CONFIGURATION %>
 
             <% if is_admin? %>
index c0023528bf9b18148920e490e1485d04f43d39e8..8644fb5769ed3287d445d6dbf4efc843715c353b 100644 (file)
@@ -1,5 +1,5 @@
-<% 
-  if @snapshot.root?
+<%
+  if !@snapshot || @snapshot.root?
     resource_name = message('qualifier.' + @project.qualifier)
     delete_resource_message = message('project_deletion.delete_resource', :params => resource_name)
 %>
@@ -22,9 +22,9 @@
 
     <%= message('project_deletion.operation_cannot_be_undone') -%>
     <br/>
-    <%= submit_tag delete_resource_message, :id => 'delete_resource', :class => 'action red-button', 
+    <%= submit_tag delete_resource_message, :id => 'delete_resource', :class => 'action red-button',
                    :confirm => message('project_deletion.delete_resource_confirmation', :params => resource_name) %>
     </form>
   </div>
 </div>
-<% end %>
\ No newline at end of file
+<% end %>
index 09317d0a1e1878a80fb332b58154d8f77656181e..005c2ba322d7001fd198f711ae08919741f2d039 100644 (file)
@@ -1,4 +1,10 @@
-<% if @snapshot.root? %>
+<h1><%= message('project_history.page') -%></h1>
+
+<% if !@snapshot %>
+
+<p class="info"><%= message('provisioning.no_analysis') -%></p>
+
+<% elsif @snapshot.root? %>
 <style>
 .snapshot .edit_actions a {
   visibility: hidden;
@@ -16,8 +22,6 @@
 }
 </style>
 
-<h1><%= message('project_history.page') -%></h1>
-
 <p style="margin: 15px 0px">
   <%= message('project_history.description') -%>
 </p>
@@ -37,7 +41,7 @@
     </tr>
   </thead>
   <tbody>
-    <% 
+    <%
       current_year = nil
       current_month = nil
       @snapshots.each_with_index do |snapshot, index|
         other_events = snapshot.events.select{|e| e.category!=EventCategory::KEY_VERSION && e.category!=EventCategory::KEY_ALERT && e.category!=EventCategory::KEY_PROFILE}
     %>
     <tr class="<%= cycle 'even','odd' -%> hoverable snapshot">
-    
+
       <td class="thin nowrap"><b><%= time.year unless time.year == current_year -%></b></td>
-    
+
       <td class="thin nowrap"><b><%= l(time, :format => '%B').capitalize unless time.month == current_month -%></b></td>
 
       <td class="thin nowrap"><%= l(time, :format => '%d') -%></td>
-      
+
       <td class="thin nowrap"><%= l(time, :format => '%H:%M') -%></td>
-      
+
       <td class="thin nowrap" style="padding-left: 20px;">
           <table class="width100">
             <tr id="version_<%= index -%>">
@@ -65,9 +69,9 @@
               <td class="small edit_actions" style="padding-left:20px">
                 <a id="version_<%= index -%>_change" href="#" onclick="$j('#version_<%= index -%>').hide();$j('#version_<%= index -%>_form').show();$j('#version_name_<%= index -%>').focus();return false;"><%= message('project_history.rename_version') -%></a>
                 <% if version_event && !snapshot.islast? %>
-                  <%= link_to( message('project_history.remove_version'),  
-                                       { :action => 'delete_version', :sid => snapshot.id},
-                                       :confirm => message('project_history.do_you_want_to_remove_version', :params => version_event.name) ) -%>
+                  <%= link_to( message('project_history.remove_version'),
+                            { :action => 'delete_version', :sid => snapshot.id},
+                            :confirm => message('project_history.do_you_want_to_remove_version', :params => version_event.name) ) -%>
                 <% end %>
               </td>
               <% else %>
@@ -79,7 +83,7 @@
             <tr id="version_<%= index -%>_form" style="display:none;">
               <td coslpan="2" class="admin">
                 <% form_tag( {:action => 'update_version', :sid => snapshot.id }) do -%>
-                  <input id="version_name_<%= index -%>" name="version_name" type="text" value="<%= version_event ? version_event.name : '' -%>" 
+                  <input id="version_name_<%= index -%>" name="version_name" type="text" value="<%= version_event ? version_event.name : '' -%>"
                          onKeyUp="if (this.value=='') $j('#save_version_<%= index -%>').disabled='true'; else $j('#save_version_<%= index -%>').disabled='';"/>
                   <%= submit_tag message('save'), :id => 'save_version_' + index.to_s %>
                   <a href="#" onclick="$j('#version_<%= index -%>').show();$j('#version_<%= index -%>_form').hide();"><%= message('cancel') -%></a>
             </tr>
           </table>
       </td>
-      
+
       <td class="thin nowrap" style="padding-left: 20px;">
         <table class="width100">
-          <% 
+          <%
              other_events.each_with_index do |event, index2|
-               event_index = index.to_s + '-' + index2.to_s 
+               event_index = index.to_s + '-' + index2.to_s
           %>
-               <tr id="event_<%= event_index -%>">
-                 <td class="width100"><%= event.name -%></td>
-                 <td class="small edit_actions" style="padding-left:20px">
+          <tr id="event_<%= event_index -%>">
+            <td class="width100"><%= event.name -%></td>
+            <td class="small edit_actions" style="padding-left:20px">
                 <a id="event_<%= event_index -%>_change" href="#" onclick="$j('#event_<%= event_index -%>').hide();$j('#event_<%= event_index -%>_form').show();$j('#event_name_<%= event_index -%>').focus();return false;"><%= message('project_history.rename_event') -%></a>
-                <%= link_to( message('project_history.remove_version'),  
-                                         { :action => 'delete_event', :id => event.id},
-                                     :confirm => message('project_history.do_you_want_to_remove_version', :params => event.name) ) -%>
-                 </td>
-               </tr>
-               <tr id="event_<%= event_index -%>_form" style="display:none;">
+                <%= link_to( message('project_history.remove_version'),
+                           { :action => 'delete_event', :id => event.id},
+                        :confirm => message('project_history.do_you_want_to_remove_version', :params => event.name) ) -%>
+            </td>
+          </tr>
+          <tr id="event_<%= event_index -%>_form" style="display:none;">
               <td colspan="2" class="admin">
                 <% form_tag( {:action => 'update_event', :id => event.id }) do -%>
-                  <input id="event_name_<%= event_index -%>" name="event_name" type="text" value="<%= event.name -%>" 
+                  <input id="event_name_<%= event_index -%>" name="event_name" type="text" value="<%= event.name -%>"
                          onKeyUp="if (this.value=='') $j('#save_event_<%= event_index -%>').disabled='true'; else $j('#save_event_<%= event_index -%>').disabled='';"/>
                   <%= submit_tag message('save'), :id => 'save_event_' + event_index %>
                   <a href="#" onclick="$j('#event_<%= event_index -%>').show();$j('#event_<%= event_index -%>_form').hide();"><%= message('cancel') -%></a>
                 <% end %>
               </td>
-               </tr>
-             <% end %>
-               <tr id="create_event_<%= index -%>">
-                 <td colspan="2" class="create_actions">
-                   <span class="small">
+          </tr>
+        <% end %>
+          <tr id="create_event_<%= index -%>">
+            <td colspan="2" class="create_actions">
+              <span class="small">
                   <a id="create_event_<%= index -%>_change" href="#" onclick="$j('#create_event_<%= index -%>').hide();$j('#create_event_<%= index -%>_form').show();$j('#create_event_name_<%= index -%>').focus();return false;"><%= message('project_history.create_event') -%></a>
                 </span>
-                 </td>
-               </tr>
-               <tr id="create_event_<%= index -%>_form" style="display:none;">
-                 <td colspan="2" class="admin">
+            </td>
+          </tr>
+          <tr id="create_event_<%= index -%>_form" style="display:none;">
+            <td colspan="2" class="admin">
                 <% form_tag( {:action => 'create_event', :sid => snapshot.id }) do -%>
-                  <input id="create_event_name_<%= index -%>" name="event_name" type="text" value="" 
+                  <input id="create_event_name_<%= index -%>" name="event_name" type="text" value=""
                          onKeyUp="if (this.value=='') $j('#create_save_event_<%= index -%>').disabled='true'; else $j('#create_save_event_<%= index -%>').disabled='';"/>
                   <%= submit_tag message('save'), :id => 'create_save_event_' + index.to_s %>
                   <a href="#" onclick="$j('#create_event_<%= index -%>').show();$j('#create_event_<%= index -%>_form').hide();"><%= message('cancel') -%></a>
                 <% end %>
-                 </td>
-               </tr>
+            </td>
+          </tr>
         </table>
       </td>
 
           if snapshot.islast?
             cell_content = "<b>" + message('project_history.last_snapshot') + "</b>"
           else
-            cell_content = button_to( message('project_history.delete_snapshot'), 
-                                        { :action => "delete_snapshot_history", :id => @project.id, :snapshot_id => snapshot.id }, 
-                                        :class => 'action red-button', 
-                                        :confirm => message('project_history.are_you_sure_delete_snapshot_x', :params => l(time, :format => :long)) )  
+            cell_content = button_to( message('project_history.delete_snapshot'),
+                                        { :action => "delete_snapshot_history", :id => @project.id, :snapshot_id => snapshot.id },
+                                        :class => 'action red-button',
+                                        :confirm => message('project_history.are_you_sure_delete_snapshot_x', :params => l(time, :format => :long)) )
           end
         %>
         <%= cell_content -%>
     </tr>
     <%
         current_year = time.year
-        current_month = time.month 
-      end 
+        current_month = time.month
+      end
     %>
   </tbody>
 </table>
 
-<% end %>
\ No newline at end of file
+<% end %>
index 323ea8e0e05ee96712aafeb4134b11ecb87a30c0..5809c89db5467707a414bf59c12fea92cb6cd97f 100644 (file)
@@ -1,5 +1,8 @@
 <div id="plugins">
   <h1 class="marginbottom10"><%= message(@resource ? 'project_settings.page' : 'settings.page') -%></h1>
+  <% if @resource and !@snapshot %>
+  <p class="info marginbottom10"><%= message('provisioning.no_analysis') -%></p>
+  <% end %>
 
   <table width="100%">
     <tr>