unless @dashboard
redirect_to home_path
end
-
end
def edit_layout
redirect_to :action => 'configure', :did => dashboard.id, :id => params[:id], :highlight => widget_id, :category => params[:category]
end
-
def save_widget
widget=Widget.find(params[:wid].to_i)
#TODO check owner of dashboard
def load_widget_definitions(filter_on_category=nil)
@widget_definitions=java_facade.getWidgets()
- @widget_categories=[]
- @widget_definitions.each { |definition| @widget_categories<<definition.getWidgetCategories() }
- @widget_categories=@widget_categories.flatten.uniq.sort
+ @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
-
-end
\ No newline at end of file
+end
SECTION=Navigation::SECTION_HOME
- verify :method => :post, :only => [:create, :update, :delete, :up, :down, :follow, :unfollow], :redirect_to => {:action => :index}
+ verify :method => :post, :only => [:set_layout, :add_widget, :set_dashboard, :save_widget], :redirect_to => {:action => :index}
before_filter :login_required, :except => [:index]
def index
+ # TODO display error page if no dashboard or no resource
+ load_resource()
load_dashboard()
load_authorized_widget_definitions()
unless @dashboard
end
def configure
+ # TODO display error page if no dashboard or no resource
+ load_resource()
load_dashboard()
@category=params[:category]
load_widget_definitions(@category)
end
def edit_layout
+ load_resource()
load_dashboard()
end
def set_layout
- dashboard=Dashboard.find(params[:id])
+ dashboard=Dashboard.find(params[:id].to_i)
if dashboard.editable_by?(current_user)
dashboard.column_layout=params[:layout]
dashboard.save!
end
def add_widget
- dashboard=Dashboard.find(params[:id])
+ dashboard=Dashboard.find(params[:id].to_i)
widget_id=nil
if dashboard.editable_by?(current_user)
definition=java_facade.getWidget(params[:widget])
@dashboard_configuration=Api::DashboardConfiguration.new(@dashboard, :period_index => params[:period], :snapshot => @snapshot) if @dashboard && @snapshot
end
+ def load_resource
+ end
+
def load_authorized_widget_definitions
+ if @resource
+ @authorized_widget_definitions = java_facade.getWidgets(@resource.scope, @resource.qualifier, @resource.language, @snapshot.metric_keys.to_java(:string))
+ @authorized_widget_definitions=@authorized_widget_definitions.select do |widget|
+ authorized=widget.getUserRoles().size==0
+ unless authorized
+ widget.getUserRoles().each do |role|
+ authorized=(role=='user') || (role=='viewer') || has_role?(role, @resource)
+ break if authorized
+ end
+ end
+ authorized
+ end
+ end
end
def load_widget_definitions(filter_on_category=nil)