Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Miq widget columns #13753

Merged
merged 4 commits into from
Feb 7, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can drop this.

widget = FactoryGirl.build(:miq_widget, :miq_task => FactoryGirl.build(:miq_task, :message => "message"))
expect(widget.status_message).to eq("message")
end
end
end