diff --git a/app/controllers/steps_controller.rb b/app/controllers/steps_controller.rb index f7380f2dd..f7e202de5 100644 --- a/app/controllers/steps_controller.rb +++ b/app/controllers/steps_controller.rb @@ -608,6 +608,7 @@ class StepsController < ApplicationController ], tables_attributes: [ :id, + :name, :contents, :_destroy ] diff --git a/app/models/table.rb b/app/models/table.rb index 43dd90893..ca8397a56 100644 --- a/app/models/table.rb +++ b/app/models/table.rb @@ -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 } diff --git a/app/views/steps/_form_tables.html.erb b/app/views/steps/_form_tables.html.erb index f3e3bf6e6..642f51f30 100644 --- a/app/views/steps/_form_tables.html.erb +++ b/app/views/steps/_form_tables.html.erb @@ -8,8 +8,12 @@ <% end %> -
- <%= ff.hidden_field(:contents, value: ff.object.contents_utf_8, class: "hot-contents" ) %> -
+
+ <%# 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") %> +
+ <%= ff.hidden_field(:contents, value: ff.object.contents_utf_8, class: "hot-contents" ) %> +
+
\ No newline at end of file diff --git a/app/views/steps/_step.html.erb b/app/views/steps/_step.html.erb index 9fd81cb73..96a7b89e6 100644 --- a/app/views/steps/_step.html.erb +++ b/app/views/steps/_step.html.erb @@ -47,13 +47,17 @@
<% unless step.tables.blank? then %>
- <%= t("protocols.steps.tables") %> - <% step.tables.each do |table| %> -
- <%= hidden_field(table, :contents, value: table.contents_utf_8, class: "hot-contents") %> -
-
- <% end %> + <% step.tables.each do |table| %> + + <%= custom_auto_link(simple_format(table.name), + link: :urls, + html: { target: '_blank' }) %> + +
+ <%= hidden_field(table, :contents, value: table.contents_utf_8, class: "hot-contents") %> +
+
+ <% end %>
<% end %> diff --git a/config/locales/en.yml b/config/locales/en.yml index 8160159ee..3bf9ddb8c 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -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" diff --git a/db/migrate/20170116143350_add_name_to_tables.rb b/db/migrate/20170116143350_add_name_to_tables.rb new file mode 100644 index 000000000..74ba4ef8d --- /dev/null +++ b/db/migrate/20170116143350_add_name_to_tables.rb @@ -0,0 +1,5 @@ +class AddNameToTables < ActiveRecord::Migration + def change + add_column :tables, :name, :string, default: '' + end +end diff --git a/db/schema.rb b/db/schema.rb index 8b67ce8da..aefec7288 100644 --- a/db/schema.rb +++ b/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: 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