add table name in protocol step

This commit is contained in:
Mojca Lorber 2017-01-16 17:11:08 +01:00
parent cf72da5635
commit b3c423c582
7 changed files with 34 additions and 15 deletions

View file

@ -608,6 +608,7 @@ class StepsController < ApplicationController
],
tables_attributes: [
:id,
:name,
:contents,
:_destroy
]

View file

@ -1,6 +1,9 @@
class Table < ActiveRecord::Base
include SearchableModel
auto_strip_attributes :name, nullify: false
validates :name,
length: { maximum: Constants::NAME_MAX_LENGTH }
validates :contents,
presence: true,
length: { maximum: Constants::TABLE_JSON_MAX_SIZE_MB.megabytes }

View file

@ -8,8 +8,12 @@
<% end %>
</div>
</div>
<div data-role="editable-table" class="panel-body">
<%= ff.hidden_field(:contents, value: ff.object.contents_utf_8, class: "hot-contents" ) %>
<div class="hot"></div>
<div class="panel-body">
<%# byebug %>
<%= ff.text_area :name, label: t("protocols.steps.new.table_name"), class: "table_name", autofocus: true, placeholder: t("protocols.steps.new.table_name_placeholder") %>
<div data-role="editable-table" class="panel-body">
<%= ff.hidden_field(:contents, value: ff.object.contents_utf_8, class: "hot-contents" ) %>
<div class="hot"></div>
</div>
</div>
</div>

View file

@ -47,13 +47,17 @@
<hr>
<% unless step.tables.blank? then %>
<div class="col-xs-12">
<strong><%= t("protocols.steps.tables") %></strong>
<% step.tables.each do |table| %>
<div data-role="hot-table" class="hot-table">
<%= hidden_field(table, :contents, value: table.contents_utf_8, class: "hot-contents") %>
<div data-role="step-hot-table" class="step-result-hot-table"></div>
</div>
<% end %>
<% step.tables.each do |table| %>
<strong>
<%= custom_auto_link(simple_format(table.name),
link: :urls,
html: { target: '_blank' }) %>
</strong>
<div data-role="hot-table" class="hot-table">
<%= hidden_field(table, :contents, value: table.contents_utf_8, class: "hot-contents") %>
<div data-role="step-hot-table" class="step-result-hot-table"></div>
</div>
<% end %>
</div>
<% end %>

View file

@ -1350,7 +1350,8 @@ en:
checklist_add_item: "Add item"
add_checklist: "Add checklist"
table_panel_title: "Table"
table_placeholder: "Table contents"
table_name: "Table title"
table_name_placeholder: "Table title"
add_table: "Add table"
asset_panel_title: "File"
add_asset: "Add file"

View file

@ -0,0 +1,5 @@
class AddNameToTables < ActiveRecord::Migration
def change
add_column :tables, :name, :string, default: ''
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: 20161208145354) do
ActiveRecord::Schema.define(version: 20170116143350) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@ -551,12 +551,13 @@ ActiveRecord::Schema.define(version: 20161208145354) do
add_index "steps", ["user_id"], name: "index_steps_on_user_id", using: :btree
create_table "tables", force: :cascade do |t|
t.binary "contents", null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.binary "contents", null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.integer "created_by_id"
t.integer "last_modified_by_id"
t.tsvector "data_vector"
t.string "name", default: ""
end
add_index "tables", ["created_at"], name: "index_tables_on_created_at", using: :btree