app/controllers/report_controller/widgets.rb
# Set record variables to new values
Set record variables to new values
Set record variables to new values
def widget_set_record_vars(widget)
    widget.title       = @edit[:new][:title]
    widget.description = @edit[:new][:description]
    widget.enabled     = @edit[:new][:enabled]
    widget.options ||= {}
    widget.options[:row_count] = widget.row_count(@edit[:new][:row_count]) if %w(r rf).include?(@sb[:wtype])
    if @sb[:wtype] == "rf"
      widget.set_rss_properties(@edit[:new][:feed_type], @edit[:new][:rss_feed_id], @edit[:new][:url])
    else
      widget.resource = @edit[:rpt]
    end
    widget.options[:col_order] = [] if @edit[:new][:pivotby1]
    widget.options[:col_order].push(@edit[:new][:pivotby1]) if !@edit[:new][:pivotby1].blank? && @edit[:new][:pivotby1] != "<<< Nothing >>>"
    widget.options[:col_order].push(@edit[:new][:pivotby2]) if !@edit[:new][:pivotby2].blank? && @edit[:new][:pivotby2] != "<<< Nothing >>>"
    widget.options[:col_order].push(@edit[:new][:pivotby3]) if !@edit[:new][:pivotby3].blank? && @edit[:new][:pivotby3] != "<<< Nothing >>>"
    widget.options[:col_order].push(@edit[:new][:pivotby4]) if !@edit[:new][:pivotby4].blank? && @edit[:new][:pivotby4] != "<<< Nothing >>>"
    widget.content_type = WIDGET_CONTENT_TYPE[@sb[:wtype]]
    widget.visibility ||= {}
    if @edit[:new][:visibility_typ] == "group"
      groups = []
      @edit[:new][:groups].each do |g|
        group = MiqGroup.find_by_id(from_cid(g))
        groups.push(group.description) if from_cid(g) == group.id
      end
      widget.visibility[:groups] =  groups
      widget.visibility.delete(:roles) if widget.visibility[:roles]
    else
      if @edit[:new][:visibility_typ] == "role"
        roles = []
        @edit[:new][:roles].each do |r|
          role = MiqUserRole.find_by_id(from_cid(r))
          roles.push(role.name) if from_cid(r) == role.id
        end
        widget.visibility[:roles] =  roles
      else
        widget.visibility[:roles] = ["_ALL_"]
      end
      widget.visibility.delete(:groups) if widget.visibility[:groups]
    end
    @edit[:schedule].name         = widget.title
    @edit[:schedule].description  = widget.description
    @edit[:schedule].towhat       = "MiqWidget"
    @edit[:schedule].sched_action = {:method => "generate_widget"}
    @edit[:schedule].run_at ||= {}
    run_at = create_time_in_utc("#{@edit[:new][:start_date]} #{@edit[:new][:start_hour]}:#{@edit[:new][:start_min]}:00", @edit[:tz])
    @edit[:schedule].run_at[:start_time] = "#{run_at} Z"
    @edit[:schedule].run_at[:tz]         = @edit[:tz]
    @edit[:schedule].run_at[:interval] ||= {}
    @edit[:schedule].run_at[:interval][:unit] = @edit[:new][:timer_typ].downcase
    case @edit[:new][:timer_typ].downcase
    when "monthly"
      @edit[:schedule].run_at[:interval][:value] = @edit[:new][:timer_months]
    when "weekly"
      @edit[:schedule].run_at[:interval][:value] = @edit[:new][:timer_weeks]
    when "daily"
      @edit[:schedule].run_at[:interval][:value] = @edit[:new][:timer_days]
    when "hourly"
      @edit[:schedule].run_at[:interval][:value] = @edit[:new][:timer_hours]
    else
      @edit[:schedule].run_at[:interval].delete(:value)
    end
    widget.miq_schedule = @edit[:schedule]
  end
def widget_set_record_vars ( widget ) widget . title = @edit [ :new ] [ :title ] widget . description = @edit [ :new ] [ :description ] widget . enabled = @edit [ :new ] [ :enabled ] widget . options ||= { } widget . options [ :row_count ] = widget . row_count ( @edit [ :new ] [ :row_count ] ) if %w( r rf ) . include? ( @sb [ :wtype ] ) if @sb [ :wtype ] == "rf" widget . set_rss_properties ( @edit [ :new ] [ :feed_type ] , @edit [ :new ] [ :rss_feed_id ] , @edit [ :new ] [ :url ] ) else widget . resource = @edit [ :rpt ] end widget . options [ :col_order ] = [ ] if @edit [ :new ] [ :pivotby1 ] widget . options [ :col_order ] . push ( @edit [ :new ] [ :pivotby1 ] ) if ! @edit [ :new ] [ :pivotby1 ] . blank? && @edit [ :new ] [ :pivotby1 ] != "<<< Nothing >>>" widget . options [ :col_order ] . push ( @edit [ :new ] [ :pivotby2 ] ) if ! @edit [ :new ] [ :pivotby2 ] . blank? && @edit [ :new ] [ :pivotby2 ] != "<<< Nothing >>>" widget . options [ :col_order ] . push ( @edit [ :new ] [ :pivotby3 ] ) if ! @edit [ :new ] [ :pivotby3 ] . blank? && @edit [ :new ] [ :pivotby3 ] != "<<< Nothing >>>" widget . options [ :col_order ] . push ( @edit [ :new ] [ :pivotby4 ] ) if ! @edit [ :new ] [ :pivotby4 ] . blank? && @edit [ :new ] [ :pivotby4 ] != "<<< Nothing >>>" widget . content_type = WIDGET_CONTENT_TYPE [ @sb [ :wtype ] ] widget . visibility ||= { } if @edit [ :new ] [ :visibility_typ ] == "group" groups = [ ] @edit [ :new ] [ :groups ] . each do | g | group = MiqGroup . find_by_id ( from_cid ( g ) ) groups . push ( group . description ) if from_cid ( g ) == group . id end widget . visibility [ :groups ] = groups widget . visibility . delete ( :roles ) if widget . visibility [ :roles ] else if @edit [ :new ] [ :visibility_typ ] == "role" roles = [ ] @edit [ :new ] [ :roles ] . each do | r | role = MiqUserRole . find_by_id ( from_cid ( r ) ) roles . push ( role . name ) if from_cid ( r ) == role . id end widget . visibility [ :roles ] = roles else widget . visibility [ :roles ] = [ "_ALL_" ] end widget . visibility . delete ( :groups ) if widget . visibility [ :groups ] end @edit [ :schedule ] . name = widget . title @edit [ :schedule ] . description = widget . description @edit [ :schedule ] . towhat = "MiqWidget" @edit [ :schedule ] . sched_action = { :method => "generate_widget" } @edit [ :schedule ] . run_at ||= { } run_at = create_time_in_utc ( "#{@edit[:new][:start_date]} #{@edit[:new][:start_hour]}:#{@edit[:new][:start_min]}:00" , @edit [ :tz ] ) @edit [ :schedule ] . run_at [ :start_time ] = "#{run_at} Z" @edit [ :schedule ] . run_at [ :tz ] = @edit [ :tz ] @edit [ :schedule ] . run_at [ :interval ] ||= { } @edit [ :schedule ] . run_at [ :interval ] [ :unit ] = @edit [ :new ] [ :timer_typ ] . downcase case @edit [ :new ] [ :timer_typ ] . downcase when "monthly" @edit [ :schedule ] . run_at [ :interval ] [ :value ] = @edit [ :new ] [ :timer_months ] when "weekly" @edit [ :schedule ] . run_at [ :interval ] [ :value ] = @edit [ :new ] [ :timer_weeks ] when "daily" @edit [ :schedule ] . run_at [ :interval ] [ :value ] = @edit [ :new ] [ :timer_days ] when "hourly" @edit [ :schedule ] . run_at [ :interval ] [ :value ] = @edit [ :new ] [ :timer_hours ] else @edit [ :schedule ] . run_at [ :interval ] . delete ( :value ) end widget . miq_schedule = @edit [ :schedule ] end
Set record variables to new values
Set record variables to new values
#    if @sb[:wtype] == "m" #      widget.miq_shortcuts = @edit[:new][:shortcuts].keys.collect{|s| MiqShortcut.find_by_id(s)} #      ws = Array.new  # Create an array of widget shortcuts #      @edit[:new][:shortcuts].keys.each_with_index do |s_id, s_idx| #        sc = MiqShortcut.find_by_id(s_id) #        ws.push(MiqWidgetShortcut.new(:sequence=>s_idx, :description=>@edit[:new][:shortcuts][s_id], :miq_shortcut=>sc)) #      end #      widget.miq_widget_shortcuts = ws #    end # schedule settings
widget
<not_specific>