Skip to content

Commit

Permalink
Merge pull request #13753 from kbrock/miq_widget_columns
Browse files Browse the repository at this point in the history
Miq widget columns
  • Loading branch information
gtanzillo authored Feb 7, 2017
2 parents 65d2b91 + 7aaf73c commit cdae89a
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 37 deletions.
40 changes: 3 additions & 37 deletions app/models/miq_widget.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ def destroy_schedule
end

virtual_column :status, :type => :string, :uses => :miq_task
virtual_column :status_message, :type => :string, :uses => :miq_task
virtual_column :queued_at, :type => :datetime, :uses => :miq_task
virtual_delegate :status_message, :to => "miq_task.message", :allow_nil => true, :default => "Unknown"
virtual_delegate :queued_at, :to => "miq_task.created_on", :allow_nil => true
virtual_column :last_run_on, :type => :datetime, :uses => :miq_schedule

def row_count(row_count_param = nil)
Expand All @@ -55,13 +55,7 @@ def last_run_on
last_generated_content_on || (miq_schedule && miq_schedule.last_run_on)
end

def next_run_on
miq_schedule && miq_schedule.next_run_on
end

def queued_at
miq_task && miq_task.created_on
end
delegate :next_run_on, :to => :miq_schedule, :allow_nil => true

def status
if miq_task.nil?
Expand All @@ -71,34 +65,6 @@ def status
miq_task.human_status
end

def status_message
miq_task.nil? ? "Unknown" : miq_task.message
end

# Returns status, last_run_on, message
# Status: None | Queued | Running | Complete
def generation_status
miq_task = self.miq_task

if miq_task.nil?
return "None" if last_run_on.nil?
return "Complete", last_run_on
end

status = case miq_task.state
when MiqTask::STATE_QUEUED
"Queued"
when MiqTask::STATE_FINISHED
"Complete"
when MiqTask::STATE_ACTIVE
"Running"
else
raise "Unknown state=#{miq_task.state.inspect}"
end

return status, last_run_on, miq_task.message
end

def create_task(num_targets, userid = User.current_userid)
userid ||= "system"
context_data = {:targets => num_targets, :complete => 0}
Expand Down
26 changes: 26 additions & 0 deletions spec/models/miq_widget_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -725,4 +725,30 @@ def add_dashboard_for_user(db_name, userid, group)
end
end
end

describe "#queued_at" do
it "is nil when no task" do
widget = FactoryGirl.build(:miq_widget)
expect(widget.queued_at).to be_nil
end

it "uses task value" do
dt = Time.now.utc
widget = FactoryGirl.build(:miq_widget, :miq_task => FactoryGirl.build(:miq_task, :created_on => dt))
expect(widget.queued_at).to eq(dt)
end
end

describe "#status_message" do
it "is nil when no task" do
widget = FactoryGirl.build(:miq_widget)
expect(widget.status_message).to eq("Unknown")
end

it "uses task value" do
dt = Time.now.utc
widget = FactoryGirl.build(:miq_widget, :miq_task => FactoryGirl.build(:miq_task, :message => "message"))
expect(widget.status_message).to eq("message")
end
end
end

0 comments on commit cdae89a

Please sign in to comment.