Skip to content

Commit

Permalink
Merge 9970cc3 into c72be33
Browse files Browse the repository at this point in the history
  • Loading branch information
peetucket committed Sep 27, 2018
2 parents c72be33 + 9970cc3 commit 8a64989
Show file tree
Hide file tree
Showing 11 changed files with 197 additions and 80 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ gem 'ruby-prof'
gem 'sqlite3'
gem 'turbolinks' # improves speed of following links in web application
gem 'uglifier' # compressor for JavaScript assets
gem "simple_form" # rails form that handles errors internally and easily integrated w/ Bootstrap
gem 'simple_form' # rails form that handles errors internally and easily integrated w/ Bootstrap
gem 'kaminari' # pagination
gem 'capistrano-resque-pool'

Expand Down
95 changes: 95 additions & 0 deletions app/assets/javascripts/tmpl.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
/*
* JavaScript Templates
* https://github.com/blueimp/JavaScript-Templates
*
* Copyright 2011, Sebastian Tschan
* https://blueimp.net
*
* Licensed under the MIT license:
* https://opensource.org/licenses/MIT
*
* Inspired by John Resig's JavaScript Micro-Templating:
* http://ejohn.org/blog/javascript-micro-templating/
*/

/* global define */

;(function ($) {
'use strict'
var tmpl = function (str, data) {
var f = !/[^\w\-.:]/.test(str)
? (tmpl.cache[str] = tmpl.cache[str] || tmpl(tmpl.load(str)))
: new Function( // eslint-disable-line no-new-func
tmpl.arg + ',tmpl',
'var _e=tmpl.encode' +
tmpl.helper +
",_s='" +
str.replace(tmpl.regexp, tmpl.func) +
"';return _s;"
)
return data
? f(data, tmpl)
: function (data) {
return f(data, tmpl)
}
}
tmpl.cache = {}
tmpl.load = function (id) {
return document.getElementById(id).innerHTML
}
tmpl.regexp = /([\s'\\])(?!(?:[^{]|\{(?!%))*%\})|(?:\{%(=|#)([\s\S]+?)%\})|(\{%)|(%\})/g
tmpl.func = function (s, p1, p2, p3, p4, p5) {
if (p1) {
// whitespace, quote and backspace in HTML context
return (
{
'\n': '\\n',
'\r': '\\r',
'\t': '\\t',
' ': ' '
}[p1] || '\\' + p1
)
}
if (p2) {
// interpolation: {%=prop%}, or unescaped: {%#prop%}
if (p2 === '=') {
return "'+_e(" + p3 + ")+'"
}
return "'+(" + p3 + "==null?'':" + p3 + ")+'"
}
if (p4) {
// evaluation start tag: {%
return "';"
}
if (p5) {
// evaluation end tag: %}
return "_s+='"
}
}
tmpl.encReg = /[<>&"'\x00]/g // eslint-disable-line no-control-regex
tmpl.encMap = {
'<': '&lt;',
'>': '&gt;',
'&': '&amp;',
'"': '&quot;',
"'": '&#39;'
}
tmpl.encode = function (s) {
return (s == null ? '' : '' + s).replace(tmpl.encReg, function (c) {
return tmpl.encMap[c] || ''
})
}
tmpl.arg = 'o'
tmpl.helper =
",print=function(s,e){_s+=e?(s==null?'':s):_e(s);}" +
',include=function(s,d){_s+=tmpl(s,d);}'
if (typeof define === 'function' && define.amd) {
define(function () {
return tmpl
})
} else if (typeof module === 'object' && module.exports) {
module.exports = tmpl
} else {
$.tmpl = tmpl
}
})(this)
28 changes: 14 additions & 14 deletions app/views/bundle_contexts/new.html.erb
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
<script>
$(document).ready(function() {
jQuery.ajax({
type: "GET",
dataType: "json",
url: "<%=job_runs_path(format: :json)%>",
success: function(data) {
document.getElementById("job-history-table").innerHTML = tmpl("tmpl-job-history-table", data);
}
});
});

</script>
<div class="container mt-3">
<div class="row">
<section class="col-7">
<%= render "bundle_contexts/yaml_form" %>
</section>
<section class="col-5">
<ul class="nav nav-pills nav-fill">
<li class="nav-item">
<a id="project-queue-tab"
data-toggle="tab"
class="nav-link active" href="#project-queue">
Queue of projects
</a>
</li>
<%= render "history/tab_list_item" %>
<%= render "job_runs/recent_history" %>
</ul>
<div class="tab-content" id="jobs-queue-history-content">
<div class="tab-pane fade" id="project-queue" role="tabpanel"
aria-labelledby="project-queue-tab">
</div>
</div>
<%= render "history/tab_pane" %>
</section>
</div>
</div>
31 changes: 0 additions & 31 deletions app/views/history/_jobs_table.erb

This file was deleted.

5 changes: 0 additions & 5 deletions app/views/history/_tab_list_item.erb

This file was deleted.

4 changes: 0 additions & 4 deletions app/views/history/_tab_pane.erb

This file was deleted.

30 changes: 30 additions & 0 deletions app/views/job_runs/_recent_history.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<script type="text/x-tmpl" id="tmpl-job-history-table">
{% for (var i=0; i<o.length; i++) { %}
<tr>
<td><a href="/job_runs/{%= o[i].id %}">{%= o[i].id %}</a></td>
<td>{%= o[i].job_type %}</td>
<td>{%= o[i].sunet_id %}</td>
<td>{%= o[i].output_location ? "done" : "not done" %}</td>
<td>{%= o[i].created_at.split('T')[0] %}</td>
</tr>
{% } %}
</script>

<h4>Recent jobs</h4>
<div class="container">
<%= link_to '[view full history]', job_runs_path %>
</div>
<div class="container">
<table class="table">
<thead>
<tr>
<th>#</th>
<th>Job Type</th>
<th>Created by</th>
<th>Status</th>
<th>Created on</th>
</th>
</thead>
<tbody id="job-history-table">
</table>
</div>
53 changes: 29 additions & 24 deletions app/views/job_runs/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,28 +1,33 @@
<h2>Job Run History</h2>
<div class="container">
<%= link_to '[start new job]', root_path %>
</div>
<div class="container">
<h2>Job Run History</h2>

<%= paginate @job_runs %>
<%= paginate @job_runs %>

<table class="table">
<thead>
<tr>
<th scope="col">ID</th>
<th scope="col">Type</th>
<th scope="col">Creator</th>
<th scope="col">Status</th>
<th scope="col">Created At</th>
</tr>
</thead>
<tbody>
<% @job_runs.each do |job_run| %>
<tr>
<td><%=link_to "Job ##{job_run.id}",job_run%></td>
<td><%=job_run.job_type%></td>
<td><%=job_run.bundle_context.user.sunet_id%></td>
<td><%=job_run.output_location ? "complete" : "not complete"%></td>
<td><%=job_run.created_at.to_formatted_s(:long)%></td>
</tr>
</tbody>
<% end %>
</table>
<table class="table">
<thead>
<tr>
<th scope="col">ID</th>
<th scope="col">Type</th>
<th scope="col">Creator</th>
<th scope="col">Status</th>
<th scope="col">Created At</th>
</tr>
</thead>
<tbody>
<% @job_runs.each do |job_run| %>
<tr>
<td><%=link_to "Job ##{job_run.id}",job_run%></td>
<td><%=job_run.job_type%></td>
<td><%=job_run.bundle_context.user.sunet_id%></td>
<td><%=job_run.output_location ? "complete" : "not complete"%></td>
<td><%=job_run.created_at.to_formatted_s(:long)%></td>
</tr>
<% end %>
</tbody>
</table>

<%= paginate @job_runs %>
</div>
4 changes: 3 additions & 1 deletion app/views/job_runs/show.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<%= link_to '[all jobs]',job_runs_path %>
<div class="container">
<%= link_to '[all jobs]',job_runs_path %>
</div>

<div class="container">
<h2><%= @job_run.job_type.humanize %> #<%= @job_run.id %></h2>
Expand Down
14 changes: 14 additions & 0 deletions spec/controllers/job_runs_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,20 @@
end
end

describe 'GET #index' do
it 'returns http success for html view' do
allow(JobRun).to receive(:find).with('123').and_return(instance_double(JobRun))
get :index
expect(response).to have_http_status(:success)
end

it 'returns http success for json view' do
allow(JobRun).to receive(:find).with('123').and_return(instance_double(JobRun))
get :index, format: 'JSON'
expect(response).to have_http_status(:success)
end
end

describe 'GET #download' do
it 'before job is complete, renders page with flash' do
allow(JobRun).to receive(:find).with('123').and_return(instance_double(JobRun, output_location: nil))
Expand Down
11 changes: 11 additions & 0 deletions spec/views/bundle_contexts/new.html.erb_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
RSpec.describe 'bundle_contexts/new.html.erb', type: :view do
let!(:job_runs) { create_list(:job_run, 2) }

it 'displays a list of job_runs in side panel' do
assign(:bundle_context, BundleContext.new)
assign(:job_runs, JobRun.all.page(1))
render
expect(rendered).to include('<tbody id="job-history-table">') # the element we will render into
expect(rendered).to include('<script type="text/x-tmpl" id="tmpl-job-history-table">') # the JS template that will be used
end
end

0 comments on commit 8a64989

Please sign in to comment.