mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2024-12-25 01:03:18 +08:00
Save handson table metadata [SCI-7834]
This commit is contained in:
parent
958f9784b0
commit
3849b1a7a1
11 changed files with 46 additions and 21 deletions
|
@ -18,7 +18,7 @@
|
|||
root.find('div.hot-table').each(function() {
|
||||
var $container = $(this).find('.step-result-hot-table');
|
||||
var contents = $(this).find('.hot-contents');
|
||||
|
||||
var metadata = $(this).find('.hot-metadata');
|
||||
$container.handsontable({
|
||||
width: '100%',
|
||||
startRows: 5,
|
||||
|
@ -27,23 +27,14 @@
|
|||
colHeaders: true,
|
||||
fillHandle: false,
|
||||
formulas: true,
|
||||
cells: function(row, col) {
|
||||
var cellProperties = {};
|
||||
|
||||
if (col >= 0) {
|
||||
cellProperties.readOnly = true;
|
||||
} else {
|
||||
cellProperties.readOnly = false;
|
||||
}
|
||||
return cellProperties;
|
||||
}
|
||||
data: JSON.parse(contents.attr('value')).data,
|
||||
cell: JSON.parse(metadata.val() || '{}').cells || [],
|
||||
readOnly: true
|
||||
});
|
||||
let hot = $container.handsontable('getInstance');
|
||||
let data = JSON.parse(contents.attr('value'));
|
||||
if (Array.isArray(data.data)) hot.loadData(data.data);
|
||||
setTimeout(() => {
|
||||
hot.render()
|
||||
}, 0)
|
||||
hot.render();
|
||||
}, 500);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
var $container = $(this).find('.hot');
|
||||
var data = null;
|
||||
var contents = $(this).find('.hot-contents');
|
||||
var metadata = JSON.parse($(this).find('.hot-metadata').val() || '{}');
|
||||
if (contents.attr('value')) {
|
||||
data = JSON.parse(contents.attr('value')).data;
|
||||
}
|
||||
|
@ -21,6 +22,7 @@
|
|||
rowHeaders: true,
|
||||
colHeaders: true,
|
||||
contextMenu: true,
|
||||
cell: metadata.cells || [],
|
||||
formulas: true,
|
||||
preventOverflow: 'horizontal',
|
||||
afterChange: function() {
|
||||
|
@ -34,8 +36,16 @@
|
|||
$form.submit(function(){
|
||||
var hot = $('.hot').handsontable('getInstance');
|
||||
var contents = $('.hot-contents');
|
||||
var metadata = $('.hot-metadata');
|
||||
var data = JSON.stringify({data: hot.getData()});
|
||||
contents.attr('value', data);
|
||||
metadata.attr('value', JSON.stringify({cells: hot.getCellsMeta().map((x) => {
|
||||
return {
|
||||
col: x.col,
|
||||
row: x.row,
|
||||
className: x.className || ''
|
||||
}
|
||||
})}))
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
|
|
@ -170,7 +170,8 @@ class ResultTablesController < ApplicationController
|
|||
:name, :archived,
|
||||
table_attributes: [
|
||||
:id,
|
||||
:contents
|
||||
:contents,
|
||||
:metadata
|
||||
]
|
||||
)
|
||||
end
|
||||
|
|
|
@ -60,7 +60,7 @@ module StepElements
|
|||
private
|
||||
|
||||
def table_params
|
||||
params.permit(:name, :contents)
|
||||
params.permit(:name, :contents, metadata: {})
|
||||
end
|
||||
|
||||
def load_table
|
||||
|
|
|
@ -158,6 +158,13 @@
|
|||
|
||||
let tableData = JSON.stringify({data: this.tableObject.getData()});
|
||||
this.element.attributes.orderable.contents = tableData;
|
||||
this.element.attributes.orderable.metadata = {cells: this.tableObject.getCellsMeta().map((x) => {
|
||||
return {
|
||||
col: x.col,
|
||||
row: x.row,
|
||||
className: x.className || ''
|
||||
}
|
||||
})};
|
||||
this.update();
|
||||
this.editingTable = false;
|
||||
},
|
||||
|
@ -167,6 +174,7 @@
|
|||
loadTableData() {
|
||||
let container = this.$refs.hotTable;
|
||||
let data = JSON.parse(this.element.attributes.orderable.contents);
|
||||
let metadata = this.element.attributes.orderable.metadata || {};
|
||||
this.tableObject = new Handsontable(container, {
|
||||
data: data.data,
|
||||
width: '100%',
|
||||
|
@ -174,6 +182,7 @@
|
|||
startCols: 5,
|
||||
rowHeaders: true,
|
||||
colHeaders: true,
|
||||
cell: metadata.cells || [],
|
||||
contextMenu: this.editingTable,
|
||||
formulas: true,
|
||||
preventOverflow: 'horizontal',
|
||||
|
|
|
@ -4,7 +4,7 @@ class TableSerializer < ActiveModel::Serializer
|
|||
include Canaid::Helpers::PermissionsHelper
|
||||
include Rails.application.routes.url_helpers
|
||||
|
||||
attributes :name, :contents, :urls, :icon
|
||||
attributes :name, :contents, :urls, :icon, :metadata
|
||||
|
||||
def contents
|
||||
object.contents_utf_8
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
<div class="editable-table">
|
||||
<%= f.fields_for :table do |ff| %>
|
||||
<%= ff.hidden_field(:contents, value: ff.object.contents_utf_8, class: "hot-contents" ) %>
|
||||
<%= ff.hidden_field(:metadata, value: ff.object.metadata, class: "hot-metadata" ) %>
|
||||
<div class="hot">
|
||||
</div>
|
||||
<% end %>
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
<div class="editable-table" style="margin-bottom: 25px;">
|
||||
<%= f.fields_for :table do |ff| %>
|
||||
<%= ff.hidden_field(:contents, value: ff.object.contents, class: "hot-contents" ) %>
|
||||
<%= ff.hidden_field(:metadata, value: ff.object.metadata, class: "hot-metadata" ) %>
|
||||
<div class="hot">
|
||||
</div>
|
||||
<% end %>
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
<div class="hot-table">
|
||||
<%= hidden_field(result.table, :contents, value: result.table.contents_utf_8, class: "hot-contents" ) %>
|
||||
<%= hidden_field(result.table, :metadata, value: result.table.metadata, class: "hot-metadata" ) %>
|
||||
<div class="step-result-hot-table">
|
||||
</div>
|
||||
</div>
|
||||
|
|
7
db/migrate/20230206095817_add_metadata_to_table.rb
Normal file
7
db/migrate/20230206095817_add_metadata_to_table.rb
Normal file
|
@ -0,0 +1,7 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class AddMetadataToTable < ActiveRecord::Migration[6.1]
|
||||
def change
|
||||
add_column :tables, :metadata, :jsonb
|
||||
end
|
||||
end
|
|
@ -1031,7 +1031,8 @@ CREATE TABLE public.my_modules (
|
|||
my_module_status_id bigint,
|
||||
status_changing boolean DEFAULT false,
|
||||
changing_from_my_module_status_id bigint,
|
||||
last_transition_error jsonb
|
||||
last_transition_error jsonb,
|
||||
provisioning_status integer
|
||||
);
|
||||
|
||||
|
||||
|
@ -2681,7 +2682,8 @@ CREATE TABLE public.tables (
|
|||
last_modified_by_id bigint,
|
||||
data_vector tsvector,
|
||||
name character varying DEFAULT ''::character varying,
|
||||
team_id integer
|
||||
team_id integer,
|
||||
metadata jsonb
|
||||
);
|
||||
|
||||
|
||||
|
@ -8595,6 +8597,8 @@ INSERT INTO "schema_migrations" (version) VALUES
|
|||
('20220914124900'),
|
||||
('20221007113010'),
|
||||
('20221028085051'),
|
||||
('20221222123021');
|
||||
('20221122132857'),
|
||||
('20221222123021'),
|
||||
('20230206095817');
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue