mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-11-08 07:21:03 +08:00
add workflow image to project overview page [fixes SCI-41]
This commit is contained in:
parent
4bd489d29c
commit
1a56396eb5
9 changed files with 75 additions and 15 deletions
|
|
@ -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
|
||||
|
|
|
|||
1
Gemfile
1
Gemfile
|
|
@ -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'
|
||||
|
|
|
|||
|
|
@ -231,6 +231,9 @@ class CanvasController < ApplicationController
|
|||
end
|
||||
end
|
||||
|
||||
# Create workflow image
|
||||
@experiment.generate_workflow_img
|
||||
|
||||
flash[:success] = t(
|
||||
"experiments.canvas.update.success_flash")
|
||||
redirect_to canvas_experiment_path(@experiment)
|
||||
|
|
|
|||
|
|
@ -57,12 +57,8 @@ class ExperimentsController < ApplicationController
|
|||
if @experiment.save
|
||||
flash[:success] = t('experiments.update.success_flash',
|
||||
experiment: @experiment.name)
|
||||
<<<<<<< HEAD
|
||||
|
||||
|
||||
redirect_to canvas_experiment_path(@experiment)
|
||||
=======
|
||||
redirect_to project_path(@experiment.project)
|
||||
>>>>>>> a4ec5585965a7a8e565d7ee9072a26e52ccd9fd3
|
||||
else
|
||||
flash[:alert] = t('experiments.update.error_flash')
|
||||
redirect_to :back
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
require 'graphviz'
|
||||
|
||||
class Experiment < ActiveRecord::Base
|
||||
include ArchivableModel, SearchableModel
|
||||
|
||||
|
|
@ -11,6 +13,9 @@ 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_content_type :workflowimg, content_type: /\Aimage\/.*\Z/
|
||||
|
||||
validates :name,
|
||||
presence: true,
|
||||
length: { minimum: 4, maximum: 50 },
|
||||
|
|
@ -195,6 +200,43 @@ class Experiment < ActiveRecord::Base
|
|||
return true
|
||||
end
|
||||
|
||||
def generate_workflow_img
|
||||
graph = GraphViz.new( :G, type: :digraph, use: :neato )
|
||||
label = 'T'
|
||||
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, shape: 'circle', 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, shape: 'circle', 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, shape: 'circle', 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, shape: 'circle', pos: "#{child_mod.x},-#{child_mod.y}!")
|
||||
graph.add_edges(child_node, parent)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
graph[:size] = '5,3'
|
||||
file_location = "/tmp/workflowimg_#{Process.pid}.png"
|
||||
graph.output(png: file_location)
|
||||
|
||||
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.
|
||||
|
|
|
|||
|
|
@ -32,6 +32,9 @@
|
|||
</span>
|
||||
</div>
|
||||
<div class="panel-body">
|
||||
<% if experiment.workflowimg? %>
|
||||
<%= image_tag experiment.workflowimg, class: 'img-responsive center-block' %>
|
||||
<% end %>
|
||||
<span>
|
||||
<span class="glyphicon glyphicon-calendar" aria-hidden="true"></span>
|
||||
<%= localize(experiment.created_at, format: t('time.formats.full_date')) %>
|
||||
|
|
|
|||
|
|
@ -111,7 +111,7 @@ Rails.application.routes.draw do
|
|||
get 'users/edit', to: 'user_projects#index_edit'
|
||||
end
|
||||
|
||||
resources :experiments, only: :show do
|
||||
resources :experiments do
|
||||
member do
|
||||
get 'canvas' # Overview/structure for single experiment
|
||||
# AJAX-loaded canvas edit mode (from canvas)
|
||||
|
|
|
|||
|
|
@ -0,0 +1,11 @@
|
|||
class AddAttachmentWorkflowimgToExperiments < ActiveRecord::Migration
|
||||
def self.up
|
||||
change_table :experiments do |t|
|
||||
t.attachment :workflowimg
|
||||
end
|
||||
end
|
||||
|
||||
def self.down
|
||||
remove_attachment :experiments, :workflowimg
|
||||
end
|
||||
end
|
||||
20
db/schema.rb
20
db/schema.rb
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue