Skip to content

Commit

Permalink
Merge branch 'feature/job-progress-tweaks'
Browse files Browse the repository at this point in the history
  • Loading branch information
alexwelch committed Feb 10, 2015
2 parents f2fc32e + 5ba3cc4 commit 0183097
Show file tree
Hide file tree
Showing 11 changed files with 89 additions and 2 deletions.
9 changes: 9 additions & 0 deletions app/assets/stylesheets/panamax/deployments.css.scss
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,16 @@
}
}

.deployment-job-documentation {
background-color: $white;
padding: 15px;
padding-bottom: 0;
margin-bottom: 20px;
}

.deployment-job-log .log-output {
height: 300px;

&.truncated {
overflow: hidden;
height: 0;
Expand Down
6 changes: 5 additions & 1 deletion app/controllers/deployment_targets_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ def destroy
def hydrate_index_view
@deployment_targets = DeploymentTarget.all
@job_templates = JobTemplate.all
@jobs = Job.all.map(&:with_log!).map(&:with_step_status!).reverse
@jobs = Job.all
.map(&:with_template!)
.map(&:with_log!)
.map(&:with_step_status!)
.reverse
end
end
4 changes: 4 additions & 0 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,8 @@ def formatted_title(*page_titles)
titles = ['Panamax'] + page_titles
titles.compact.join(' > ')
end

def markdown_to_html(markdown)
markdown.present? ? Kramdown::Document.new(markdown).to_html : ''
end
end
6 changes: 6 additions & 0 deletions app/models/job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ class Job < BaseResource
integer :template_id
string :status
string :log
string :template
end

def with_template!
self.template = JobTemplate.find(job_template_id)
self
end

def with_log!
Expand Down
4 changes: 4 additions & 0 deletions app/presenters/job_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ def title
@job.name
end

def documentation
@view_context.markdown_to_html(@job.template.try(:documentation))
end

def destroy_path
@view_context.job_path(@job.key)
end
Expand Down
6 changes: 5 additions & 1 deletion app/views/deployment_targets/index.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,12 @@
.deployment-job{ class: "initially-#{presenter.status}", id: "#{presenter.dom_id}" }
.deployment-job-progress{ data: { source: job_path(job.key) } }
= render 'job', presenter: presenter
- if presenter.documentation.present?
.deployment-job-documentation
%h5 Documentation
!= presenter.documentation
.deployment-job-log
%code.log-output.truncated{ data: { source: log_job_path(job.key) } }
%code.log-output{ data: { source: log_job_path(job.key) } }
- job.log.each do |output|
%p= output

Expand Down
1 change: 1 addition & 0 deletions app/views/jobs/new.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
- content_for(:title, "New #{@template.name} Remote Deployment Target")

%h1 create a new job
%p!= markdown_to_html(@template.description)
%p.microcopy All fields required.
= form_for @job do |f|
= f.hidden_field :template_id
Expand Down
20 changes: 20 additions & 0 deletions spec/helpers/application_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,24 @@
it { should eq 'Panamax > pretty pictures > more pretty' }
end
end

describe '#markdown_to_html' do
context 'when content is passed in' do
subject { helper.markdown_to_html('#bla') }

let(:fake_kramdoc) { double(:fake_kramdoc, to_html: '<h1>bla</h1>') }

before do
allow(Kramdown::Document).to receive(:new).with('#bla').and_return(fake_kramdoc)
end

it { should eq '<h1>bla</h1>' }
end

context 'when nothing is passed in' do
subject { helper.markdown_to_html('') }

it { should eq '' }
end
end
end
15 changes: 15 additions & 0 deletions spec/models/job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,21 @@
end
end

describe '#with_template!' do
let(:fake_template) { double(:fake_template) }

before do
subject.job_template_id = 9
allow(JobTemplate).to receive(:find).with(9).and_return(fake_template)
end

it 'fetches and assigns the template' do
expect(subject.template).to be_nil
subject.with_template!
expect(subject.template).to eq fake_template
end
end

describe '#with_log!' do
let(:fake_new_job) { double(:fake_new_job) }
before do
Expand Down
20 changes: 20 additions & 0 deletions spec/presenters/job_presenter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
status: 'complete',
success?: nil,
failure?: nil,
template: '',
steps: [
double(:step1, name: 'foo', status: 'complete'),
double(:step2, name: 'bar', status: 'in-progress')
Expand All @@ -27,6 +28,25 @@
it { should eq 'abc123' }
end

describe '#documentation' do
context 'when a template has been assigned to the job' do
before do
fake_job.stub(:template).and_return(double(:fake_template, documentation: '#bla'))
view_context.stub(:markdown_to_html).with('#bla').and_return('<h1>bla</h1>')
end

its(:documentation) { should eq '<h1>bla</h1>' }
end

context 'when no template has been assigned to the job' do
before do
view_context.stub(:markdown_to_html).with(nil).and_return('')
end

its(:documentation) { should eq '' }
end
end

describe '#destroy_path' do
before do
view_context.stub(:job_path).with('xyz').and_return('/destroy/path')
Expand Down

0 comments on commit 0183097

Please sign in to comment.