Merge branch 'ZmagoD-zd_add_image_to_project_preview' into experiment-level

This commit is contained in:
zmagod 2016-08-10 11:34:04 +02:00
commit f9cb44c6a5
14 changed files with 241 additions and 89 deletions

View file

@ -2,7 +2,7 @@ FROM rails:4.2.5
MAINTAINER BioSistemika <info@biosistemika.com>
# additional dependecies
RUN apt-get update -qq && apt-get install -y default-jre-headless unison sudo --no-install-recommends && rm -rf /var/lib/apt/lists/*
RUN apt-get update -qq && apt-get install -y default-jre-headless unison sudo graphviz --no-install-recommends && rm -rf /var/lib/apt/lists/*
# heroku tools
RUN wget -O- https://toolbelt.heroku.com/install-ubuntu.sh | sh

View file

@ -52,6 +52,7 @@ gem 'aws-sdk', '~> 2.2.8'
gem 'aws-sdk-v1'
gem 'delayed_job_active_record'
gem 'devise-async'
gem 'ruby-graphviz', '~> 1.2' # Graphviz for rails
group :development, :test do
gem 'byebug'

View file

@ -38,21 +38,19 @@ GEM
tzinfo (~> 1.1)
ajax-datatables-rails (0.3.1)
railties (>= 3.1)
algorithms (0.6.1)
ansi (1.5.0)
arel (6.0.3)
aspector (0.14.0)
ast (2.3.0)
autoprefixer-rails (6.1.2)
autoprefixer-rails (6.4.0.1)
execjs
json
awesome_print (1.7.0)
aws-sdk (2.2.8)
aws-sdk-resources (= 2.2.8)
aws-sdk-core (2.2.8)
aws-sdk (2.2.37)
aws-sdk-resources (= 2.2.37)
aws-sdk-core (2.2.37)
jmespath (~> 1.0)
aws-sdk-resources (2.2.8)
aws-sdk-core (= 2.2.8)
aws-sdk-resources (2.2.37)
aws-sdk-core (= 2.2.37)
aws-sdk-v1 (1.66.0)
json (~> 1.4)
nokogiri (>= 1.4.4)
@ -63,34 +61,34 @@ GEM
rack (>= 0.9.0)
binding_of_caller (0.7.2)
debug_inspector (>= 0.0.1)
bootstrap-sass (3.3.6)
bootstrap-sass (3.3.7)
autoprefixer-rails (>= 5.2.1)
sass (>= 3.3.4)
bootstrap-select-rails (1.6.3)
bootstrap3-datetimepicker-rails (4.15.35)
momentjs-rails (>= 2.8.1)
bootstrap_form (2.3.0)
bootstrap_form (2.4.0)
builder (3.2.2)
byebug (8.2.1)
byebug (9.0.5)
climate_control (0.0.3)
activesupport (>= 3.0)
cocaine (0.5.8)
climate_control (>= 0.0.3, < 1.0)
coderay (1.1.1)
coffee-rails (4.1.0)
coffee-rails (4.2.1)
coffee-script (>= 2.2.0)
railties (>= 4.0.0, < 5.0)
railties (>= 4.0.0, < 5.2.x)
coffee-script (2.4.1)
coffee-script-source
execjs
coffee-script-source (1.10.0)
commit_param_routing (0.0.1)
concurrent-ruby (1.0.0)
concurrent-ruby (1.0.2)
debug_inspector (0.0.2)
delayed_job (4.1.1)
activesupport (>= 3.0, < 5.0)
delayed_job_active_record (4.1.0)
activerecord (>= 3.0, < 5)
delayed_job (4.1.2)
activesupport (>= 3.0, < 5.1)
delayed_job_active_record (4.1.1)
activerecord (>= 3.0, < 5.1)
delayed_job (>= 3.0, < 5)
devise (3.5.6)
bcrypt (~> 3.0)
@ -99,29 +97,29 @@ GEM
responders
thread_safe (~> 0.1)
warden (~> 1.2.3)
devise-async (0.10.1)
devise (~> 3.2)
devise_invitable (1.5.5)
actionmailer (>= 3.2.6, < 5)
devise-async (0.10.2)
devise (>= 3.2, < 4.0)
devise_invitable (1.6.1)
actionmailer (>= 3.2.6)
devise (>= 3.2.0)
erubis (2.7.0)
execjs (2.6.0)
faker (1.6.1)
execjs (2.7.0)
faker (1.6.6)
i18n (~> 0.5)
figaro (1.1.1)
thor (~> 0.14)
globalid (0.3.6)
globalid (0.3.7)
activesupport (>= 4.1.0)
hammerjs-rails (2.0.4)
i18n (0.7.0)
i18n-js (3.0.0.rc11)
i18n (~> 0.6)
i18n-js (3.0.0.rc13)
i18n (~> 0.6, >= 0.6.6)
introjs-rails (1.0.0)
sass-rails (>= 3.2)
thor (~> 0.14)
jmespath (1.1.3)
jquery-rails (4.0.5)
rails-dom-testing (~> 1.0)
jmespath (1.3.1)
jquery-rails (4.1.1)
rails-dom-testing (>= 1, < 3)
railties (>= 4.2.0)
thor (>= 0.14, < 2.0)
jquery-scrollto-rails (1.4.3)
@ -131,33 +129,35 @@ GEM
turbolinks
jquery-ui-rails (5.0.5)
railties (>= 3.2.16)
js_cookie_rails (1.0.1)
js_cookie_rails (2.1.2)
railties (>= 3.1)
json (1.8.3)
kaminari (0.16.3)
kaminari (0.17.0)
actionpack (>= 3.0.0)
activesupport (>= 3.0.0)
lazy_priority_queue (0.1.1)
little-plugger (1.1.4)
logging (2.0.0)
little-plugger (~> 1.1)
multi_json (~> 1.10)
loofah (2.0.3)
nokogiri (>= 1.5.9)
mail (2.6.3)
mime-types (>= 1.16, < 3)
mail (2.6.4)
mime-types (>= 1.16, < 4)
mime-types (1.25.1)
mime-types-data (3.2016.0521)
mimemagic (0.3.0)
mini_portile2 (2.1.0)
minitest (5.9.0)
minitest-reporters (1.1.10)
minitest-reporters (1.1.11)
ansi
builder
minitest (>= 5.0)
ruby-progressbar
momentjs-rails (2.10.6)
momentjs-rails (2.11.1)
railties (>= 3.1)
multi_json (1.11.2)
nested_form_fields (0.7.4)
multi_json (1.12.1)
nested_form_fields (0.7.8)
coffee-rails (>= 3.2.1)
jquery-rails
rails (>= 3.2.0)
@ -165,7 +165,7 @@ GEM
mini_portile2 (~> 2.1.0)
pkg-config (~> 1.1.7)
orm_adapter (0.5.0)
paperclip (4.3.2)
paperclip (4.3.7)
activemodel (>= 3.2.0)
activesupport (>= 3.2.0)
cocaine (~> 0.5.5)
@ -176,7 +176,7 @@ GEM
pg (0.18.4)
pkg-config (1.1.7)
powerpack (0.1.1)
puma (2.15.3)
puma (3.6.0)
rack (1.6.4)
rack-test (0.6.3)
rack (>= 1.0)
@ -202,8 +202,8 @@ GEM
rails_12factor (0.0.3)
rails_serve_static_assets
rails_stdout_logging
rails_serve_static_assets (0.0.4)
rails_stdout_logging (0.0.4)
rails_serve_static_assets (0.0.5)
rails_stdout_logging (0.0.5)
railties (4.2.5)
actionpack (= 4.2.5)
activesupport (= 4.2.5)
@ -211,13 +211,14 @@ GEM
thor (>= 0.18.1, < 2.0)
rainbow (2.1.0)
rake (11.2.2)
rdoc (4.2.0)
redcarpet (3.3.3)
rdoc (4.2.2)
json (~> 1.4)
redcarpet (3.3.4)
remotipart (1.2.1)
responders (2.2.0)
railties (>= 4.2.0, < 5.1)
rgl (0.5.1)
algorithms (~> 0.6.1)
rgl (0.5.2)
lazy_priority_queue (~> 0.1.0)
stream (~> 0.5.0)
roo (2.1.1)
nokogiri (~> 1)
@ -227,12 +228,13 @@ GEM
powerpack (~> 0.1)
rainbow (>= 1.99.1, < 3.0)
ruby-progressbar (~> 1.7)
ruby-progressbar (1.8.1)
unicode-display_width (~> 1.0, >= 1.0.1)
rubyzip (1.1.7)
sass (3.4.20)
sass-rails (5.0.4)
railties (>= 4.0.0, < 5.0)
ruby-graphviz (1.2.2)
ruby-progressbar (1.8.1)
rubyzip (1.2.0)
sass (3.4.22)
sass-rails (5.0.6)
railties (>= 4.0.0, < 6)
sass (~> 3.1)
sprockets (>= 2.8, < 4.0)
sprockets-rails (>= 2.0, < 4.0)
@ -243,38 +245,38 @@ GEM
shoulda-context (1.2.1)
shoulda-matchers (3.1.1)
activesupport (>= 4.0.0)
skylight (0.10.0)
skylight (0.10.5)
activesupport (>= 3.0.0)
spinjs-rails (1.4)
rails (>= 3.1)
sprockets (3.5.2)
sprockets (3.7.0)
concurrent-ruby (~> 1.0)
rack (> 1, < 3)
sprockets-rails (2.3.3)
actionpack (>= 3.0)
activesupport (>= 3.0)
sprockets (>= 2.8, < 4.0)
sprockets-rails (3.1.1)
actionpack (>= 4.0)
activesupport (>= 4.0)
sprockets (>= 3.0.0)
stream (0.5)
thor (0.19.1)
thread_safe (0.3.5)
tilt (2.0.1)
turbolinks (2.5.3)
coffee-rails
tilt (2.0.5)
turbolinks (5.0.1)
turbolinks-source (~> 5)
turbolinks-source (5.0.0)
tzinfo (1.2.2)
thread_safe (~> 0.1)
uglifier (2.7.2)
execjs (>= 0.3.0)
json (>= 1.8.0)
uglifier (3.0.1)
execjs (>= 0.3.0, < 3)
underscore-rails (1.8.3)
unicode-display_width (1.1.0)
warden (1.2.6)
rack (>= 1.0)
web-console (2.2.1)
web-console (2.3.0)
activemodel (>= 4.0)
binding_of_caller (>= 0.7.2)
railties (>= 4.0)
sprockets-rails (>= 2.0, < 4.0)
wicked_pdf (1.0.3)
wicked_pdf (1.0.6)
wkhtmltopdf-heroku (2.12.3.0)
yomu (0.2.4)
json (~> 1.8)
@ -327,6 +329,7 @@ DEPENDENCIES
rgl
roo (~> 2.1.0)
rubocop
ruby-graphviz (~> 1.2)
sass-rails (~> 5.0)
sdoc (~> 0.4.0)
shoulda-context

View file

@ -154,6 +154,12 @@ Or create new heroku application by executing following command.
heroku create
```
Add graphviz buildpack:
```
heroku buildpacks:add --index 2 https://github.com/weibeld/heroku-buildpack-graphviz.git
```
Before pushing to heroku master branch, some environmental variables should be set.
### Heroku environmental variables

View file

@ -409,14 +409,16 @@ li.module-hover {
// EXPERIMENT PANEL
.experiment-panel{
.experiment-panel {
max-width: 650px;
margin: 0 auto;
margin-top: 25px;
margin-bottom: 15px;
@include box-shadow(0px 4px 8px 0px $color-dove-gray);
}
.workflowimg-container {
margin: 15px 0;
}
// SHOW
.center-btn{
margin: 0 auto;

View file

@ -231,6 +231,9 @@ class CanvasController < ApplicationController
end
end
# Create workflow image
@experiment.delay.generate_workflow_img
flash[:success] = t(
"experiments.canvas.update.success_flash")
redirect_to canvas_experiment_path(@experiment)

View file

@ -63,7 +63,8 @@ class ExperimentsController < ApplicationController
if @experiment.save
flash[:success] = t('experiments.update.success_flash',
experiment: @experiment.name)
redirect_to canvas_experiment_path(@experiment)
redirect_to project_path(@experiment.project)
else
flash[:alert] = t('experiments.update.error_flash')
redirect_to :back

View file

@ -1,3 +1,5 @@
require 'graphviz'
class Experiment < ActiveRecord::Base
include ArchivableModel, SearchableModel
@ -11,6 +13,10 @@ class Experiment < ActiveRecord::Base
has_many :my_module_groups, inverse_of: :experiment, dependent: :destroy
has_many :report_elements, inverse_of: :experiment, dependent: :destroy
has_attached_file :workflowimg
validates_attachment :workflowimg,
content_type: { content_type: ["image/png"] }
validates :name,
presence: true,
length: { minimum: 4, maximum: 50 },
@ -195,6 +201,111 @@ class Experiment < ActiveRecord::Base
return true
end
# This method generate the workflow image and saves it as
# experiment attachment
def generate_workflow_img
graph = GraphViz.new(:G,
type: :digraph,
use: :neato)
graph[:size] = '5,3'
graph.node[color: '#d2d2d2',
style: :filled,
fontcolor: '#555555',
shape: 'circle',
fontname: 'Arial',
fontsize: '16.0']
graph.edge[color: '#d2d2d2']
label = 'T'
subg = {}
if my_module_groups.many?
my_module_groups.each_with_index do |group, gindex|
subgraph_name = "cluster-#{gindex}"
subg[subgraph_name] = graph.subgraph(rank: 'same')
group.ordered_modules.each_with_index do |my_module, index|
if my_module.outputs.any?
parent = subg[subgraph_name]
.add_nodes("#{subgraph_name}-#{index}",
label: label,
pos: "#{my_module.x},-#{my_module.y}!")
my_module.outputs.each_with_index do |output, i|
child_mod = MyModule.find_by_id(output.input_id)
child_node = subg[subgraph_name]
.add_nodes("#{subgraph_name}-O#{child_mod.id}-#{i}",
label: label,
pos: "#{child_mod.x},-#{child_mod.y}!")
subg[subgraph_name].add_edges(parent, child_node)
end
elsif my_module.inputs.any?
parent = subg[subgraph_name]
.add_nodes("#{subgraph_name}-#{index}",
label: label,
pos: "#{my_module.x},-#{my_module.y}!")
my_module.inputs.each_with_index do |input, i|
child_mod = MyModule.find_by_id(input.output_id)
child_node = subg[subgraph_name]
.add_nodes("#{subgraph_name}-I#{child_mod.id}-#{i}",
label: label,
pos: "#{child_mod.x},-#{child_mod.y}!")
subg[subgraph_name].add_edges(child_node, parent)
end
end
end
end
else
my_module_groups.each do |group|
group.ordered_modules.each_with_index do |my_module, index|
if my_module.outputs.any?
parent = graph.add_nodes("N-#{index}",
label: label,
pos: "#{my_module.x},-#{my_module.y}!")
my_module.outputs.each_with_index do |output, i|
child_mod = MyModule.find_by_id(output.input_id)
child_node = graph
.add_nodes("N-O#{child_mod.id}-#{i}",
label: label,
pos: "#{child_mod.x},-#{child_mod.y}!")
graph.add_edges(parent, child_node)
end
elsif my_module.inputs.any?
parent = graph.add_nodes("N-#{index}",
label: label,
pos: "#{my_module.x},-#{my_module.y}!")
my_module.inputs.each_with_index do |input, i|
child_mod = MyModule.find_by_id(input.output_id)
child_node = graph
.add_nodes("N-I#{child_mod.id}-#{i}",
label: label,
pos: "#{child_mod.x},-#{child_mod.y}!")
graph.add_edges(child_node, parent)
end
end
end
end
end
file_location = Tempfile.open(['wimg', '.png'],
Rails.root.join('tmp'))
graph.output(png: file_location.path)
begin
file = File.open(file_location)
self.workflowimg = file
file.close
save!
rescue => ex
logger.error ex.message
end
end
private
# Archive all modules. Receives an array of module integer IDs.

View file

@ -268,6 +268,7 @@ class Organization < ActiveRecord::Base
end
end
end
# project.experiments.each |experiment|
self.space_taken = [st, MINIMAL_ORGANIZATION_SPACE_TAKEN].max
Rails::logger.info "Organization #{self.id}: " +
"space (re)calculated to: " +

View file

@ -105,7 +105,7 @@ class Project < ActiveRecord::Base
end
def active_experiments
experiments.is_archived(false)
experiments.is_archived(false).order('created_at DESC')
end
def archived_experiments

View file

@ -16,10 +16,12 @@
<% end %>
</div>
</div>
<% @project.active_experiments.each do |experiment| %>
<%= render partial: 'projects/show/experiment',
locals: { experiment: experiment } %>
<% end %>
<div class="row">
<% @project.active_experiments.each_with_index do |experiment, index| %>
<%= render partial: 'projects/show/experiment',
locals: { experiment: experiment } %>
<%= content_tag(:div, '', class: 'clearfix visible-lg-block') if (index + 1) % 2 == 0 %>
<% end %>
</div>
<%= javascript_include_tag("projects/show") %>

View file

@ -2,10 +2,9 @@
<div class="panel panel-default experiment-panel"
data-id="<%= experiment.id %>">
<div class="panel-heading">
<h3 class="panel-title"><%= link_to experiment.name, canvas_experiment_path(experiment) %></h3>
<span class="dropdown pull-right">
<button class="btn btn-default dropdown-toggle"
<div class="dropdown pull-right">
<button class="btn btn-link dropdown-toggle"
type="button"
id="exActionsMenu-<%= experiment.id %>"
data-toggle="dropdown"
@ -29,12 +28,22 @@
data: { confirm: t('experiments.canvas.archive_confirm') } %></li>
<% end %>
</ul>
</span>
</div>
<h3 class="panel-title"><%= link_to experiment.name, canvas_experiment_path(experiment) %></h3>
</div>
<div class="panel-body">
<% if experiment.workflowimg? %>
<div class="workflowimg-container">
<%= link_to image_tag(experiment.workflowimg.expiring_url(30),
class: 'img-responsive center-block'),
canvas_experiment_path(experiment) %>
</div>
<% end %>
<span>
<span class="glyphicon glyphicon-calendar" aria-hidden="true"></span>
<%= localize(experiment.created_at, format: t('time.formats.full_date')) %>
<%= localize(experiment.created_at, format: t('time.formats.full_date')) %> - <%= localize(experiment.updated_at, format: t('time.formats.full_date')) %>
</span>
<p><%= experiment.description %></p>
</div>

View file

@ -0,0 +1,9 @@
class AddAttachmentWorkflowimgToExperiments < ActiveRecord::Migration
def self.up
add_attachment :experiments, :workflowimg
end
def self.down
remove_attachment :experiments, :workflowimg
end
end

View file

@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20160803082801) do
ActiveRecord::Schema.define(version: 20160808083040) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@ -138,18 +138,22 @@ ActiveRecord::Schema.define(version: 20160803082801) do
add_index "delayed_jobs", ["queue"], name: "delayed_jobs_queue", using: :btree
create_table "experiments", force: :cascade do |t|
t.string "name", null: false
t.string "name", null: false
t.text "description"
t.integer "project_id", null: false
t.integer "created_by_id", null: false
t.integer "last_modified_by_id", null: false
t.boolean "archived", default: false, null: false
t.integer "project_id", null: false
t.integer "created_by_id", null: false
t.integer "last_modified_by_id", null: false
t.boolean "archived", default: false, null: false
t.integer "archived_by_id"
t.datetime "archived_on"
t.integer "restored_by_id"
t.datetime "restored_on"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "workflowimg_file_name"
t.string "workflowimg_content_type"
t.integer "workflowimg_file_size"
t.datetime "workflowimg_updated_at"
end
add_index "experiments", ["archived_by_id"], name: "index_experiments_on_archived_by_id", using: :btree