aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-server/src
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@sonarsource.com>2014-06-25 11:06:31 +0200
committerSimon Brandhof <simon.brandhof@sonarsource.com>2014-06-25 11:06:40 +0200
commit669fdadd3bcd34ae9691505c7baf3d4428e76b14 (patch)
tree866bd27a714a364c320fd5281fac92d132643417 /sonar-server/src
parent5108a3616b020a6c328637bb9ae78d47f2471f95 (diff)
downloadsonarqube-669fdadd3bcd34ae9691505c7baf3d4428e76b14.tar.gz
sonarqube-669fdadd3bcd34ae9691505c7baf3d4428e76b14.zip
Revert management of source viewer extensions
Diffstat (limited to 'sonar-server/src')
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/controllers/resource_controller.rb52
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/views/resource/_extension.html.erb3
2 files changed, 55 insertions, 0 deletions
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/resource_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/resource_controller.rb
index 4e7ccec4f81..c67ee3048ad 100644
--- a/sonar-server/src/main/webapp/WEB-INF/app/controllers/resource_controller.rb
+++ b/sonar-server/src/main/webapp/WEB-INF/app/controllers/resource_controller.rb
@@ -17,10 +17,14 @@
# along with this program; if not, write to the Free Software Foundation,
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
+
class ResourceController < ApplicationController
SECTION=Navigation::SECTION_RESOURCE
+ helper :dashboard
+ helper SourceHelper, UsersHelper, IssuesHelper
+
def index
require_parameters 'id'
@@ -37,4 +41,52 @@ class ResourceController < ApplicationController
redirect_to :controller => 'component', :action => 'index', :anchor => anchor
end
+ #
+ # Call by new component viewer to display plugin extension
+ #
+ # GET /resource/extension?id=<component_key>&tab=extension_key
+ def extension
+ @resource = Project.by_key(params[:id])
+ not_found('Resource not found') unless @resource
+ @resource = @resource.permanent_resource
+ access_denied unless has_role?(:user, @resource)
+
+ @snapshot = @resource.last_snapshot
+ load_extensions() if @snapshot
+ if @extension
+ render :partial => 'extension'
+ else
+ not_found('Extension not found')
+ end
+ end
+
+ private
+
+ def load_extensions
+ @extensions=[]
+ java_facade.getResourceTabs(@resource.scope, @resource.qualifier, @resource.language, @snapshot.metric_keys.to_java(:string)).each do |tab|
+ if tab.getUserRoles().empty?
+ @extensions<<tab
+ else
+ tab.getUserRoles().each do |role|
+ if has_role?(role, @resource)
+ @extensions<<tab
+ break
+ end
+ end
+ end
+ end
+
+ if params[:tab].present?
+ # Hack to manage violations as issues.
+ params[:tab] = 'issues' if params[:tab] == 'violations'
+ @extension=@extensions.find { |extension| extension.getId()==params[:tab] }
+
+ elsif !params[:metric].blank?
+ metric = Metric.by_key(params[:metric])
+ @extension=@extensions.find { |extension| extension.getDefaultTabForMetrics().include?(metric.key) }
+ end
+ @extension=@extensions.find { |extension| extension.isDefaultTab() } if @extension==nil
+ end
+
end
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/resource/_extension.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/resource/_extension.html.erb
new file mode 100644
index 00000000000..ccad5e6fd9c
--- /dev/null
+++ b/sonar-server/src/main/webapp/WEB-INF/app/views/resource/_extension.html.erb
@@ -0,0 +1,3 @@
+<div>
+ <%= render :inline => @extension.getTarget().getTemplate() -%>
+</div>