mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-11-10 00:11:22 +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() {
|
root.find('div.hot-table').each(function() {
|
||||||
var $container = $(this).find('.step-result-hot-table');
|
var $container = $(this).find('.step-result-hot-table');
|
||||||
var contents = $(this).find('.hot-contents');
|
var contents = $(this).find('.hot-contents');
|
||||||
|
var metadata = $(this).find('.hot-metadata');
|
||||||
$container.handsontable({
|
$container.handsontable({
|
||||||
width: '100%',
|
width: '100%',
|
||||||
startRows: 5,
|
startRows: 5,
|
||||||
|
|
@ -27,23 +27,14 @@
|
||||||
colHeaders: true,
|
colHeaders: true,
|
||||||
fillHandle: false,
|
fillHandle: false,
|
||||||
formulas: true,
|
formulas: true,
|
||||||
cells: function(row, col) {
|
data: JSON.parse(contents.attr('value')).data,
|
||||||
var cellProperties = {};
|
cell: JSON.parse(metadata.val() || '{}').cells || [],
|
||||||
|
readOnly: true
|
||||||
if (col >= 0) {
|
|
||||||
cellProperties.readOnly = true;
|
|
||||||
} else {
|
|
||||||
cellProperties.readOnly = false;
|
|
||||||
}
|
|
||||||
return cellProperties;
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
let hot = $container.handsontable('getInstance');
|
let hot = $container.handsontable('getInstance');
|
||||||
let data = JSON.parse(contents.attr('value'));
|
|
||||||
if (Array.isArray(data.data)) hot.loadData(data.data);
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
hot.render()
|
hot.render();
|
||||||
}, 0)
|
}, 500);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@
|
||||||
var $container = $(this).find('.hot');
|
var $container = $(this).find('.hot');
|
||||||
var data = null;
|
var data = null;
|
||||||
var contents = $(this).find('.hot-contents');
|
var contents = $(this).find('.hot-contents');
|
||||||
|
var metadata = JSON.parse($(this).find('.hot-metadata').val() || '{}');
|
||||||
if (contents.attr('value')) {
|
if (contents.attr('value')) {
|
||||||
data = JSON.parse(contents.attr('value')).data;
|
data = JSON.parse(contents.attr('value')).data;
|
||||||
}
|
}
|
||||||
|
|
@ -21,6 +22,7 @@
|
||||||
rowHeaders: true,
|
rowHeaders: true,
|
||||||
colHeaders: true,
|
colHeaders: true,
|
||||||
contextMenu: true,
|
contextMenu: true,
|
||||||
|
cell: metadata.cells || [],
|
||||||
formulas: true,
|
formulas: true,
|
||||||
preventOverflow: 'horizontal',
|
preventOverflow: 'horizontal',
|
||||||
afterChange: function() {
|
afterChange: function() {
|
||||||
|
|
@ -34,8 +36,16 @@
|
||||||
$form.submit(function(){
|
$form.submit(function(){
|
||||||
var hot = $('.hot').handsontable('getInstance');
|
var hot = $('.hot').handsontable('getInstance');
|
||||||
var contents = $('.hot-contents');
|
var contents = $('.hot-contents');
|
||||||
|
var metadata = $('.hot-metadata');
|
||||||
var data = JSON.stringify({data: hot.getData()});
|
var data = JSON.stringify({data: hot.getData()});
|
||||||
contents.attr('value', data);
|
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;
|
return true;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -170,7 +170,8 @@ class ResultTablesController < ApplicationController
|
||||||
:name, :archived,
|
:name, :archived,
|
||||||
table_attributes: [
|
table_attributes: [
|
||||||
:id,
|
:id,
|
||||||
:contents
|
:contents,
|
||||||
|
:metadata
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -60,7 +60,7 @@ module StepElements
|
||||||
private
|
private
|
||||||
|
|
||||||
def table_params
|
def table_params
|
||||||
params.permit(:name, :contents)
|
params.permit(:name, :contents, metadata: {})
|
||||||
end
|
end
|
||||||
|
|
||||||
def load_table
|
def load_table
|
||||||
|
|
|
||||||
|
|
@ -158,6 +158,13 @@
|
||||||
|
|
||||||
let tableData = JSON.stringify({data: this.tableObject.getData()});
|
let tableData = JSON.stringify({data: this.tableObject.getData()});
|
||||||
this.element.attributes.orderable.contents = tableData;
|
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.update();
|
||||||
this.editingTable = false;
|
this.editingTable = false;
|
||||||
},
|
},
|
||||||
|
|
@ -167,6 +174,7 @@
|
||||||
loadTableData() {
|
loadTableData() {
|
||||||
let container = this.$refs.hotTable;
|
let container = this.$refs.hotTable;
|
||||||
let data = JSON.parse(this.element.attributes.orderable.contents);
|
let data = JSON.parse(this.element.attributes.orderable.contents);
|
||||||
|
let metadata = this.element.attributes.orderable.metadata || {};
|
||||||
this.tableObject = new Handsontable(container, {
|
this.tableObject = new Handsontable(container, {
|
||||||
data: data.data,
|
data: data.data,
|
||||||
width: '100%',
|
width: '100%',
|
||||||
|
|
@ -174,6 +182,7 @@
|
||||||
startCols: 5,
|
startCols: 5,
|
||||||
rowHeaders: true,
|
rowHeaders: true,
|
||||||
colHeaders: true,
|
colHeaders: true,
|
||||||
|
cell: metadata.cells || [],
|
||||||
contextMenu: this.editingTable,
|
contextMenu: this.editingTable,
|
||||||
formulas: true,
|
formulas: true,
|
||||||
preventOverflow: 'horizontal',
|
preventOverflow: 'horizontal',
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ class TableSerializer < ActiveModel::Serializer
|
||||||
include Canaid::Helpers::PermissionsHelper
|
include Canaid::Helpers::PermissionsHelper
|
||||||
include Rails.application.routes.url_helpers
|
include Rails.application.routes.url_helpers
|
||||||
|
|
||||||
attributes :name, :contents, :urls, :icon
|
attributes :name, :contents, :urls, :icon, :metadata
|
||||||
|
|
||||||
def contents
|
def contents
|
||||||
object.contents_utf_8
|
object.contents_utf_8
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@
|
||||||
<div class="editable-table">
|
<div class="editable-table">
|
||||||
<%= f.fields_for :table do |ff| %>
|
<%= f.fields_for :table do |ff| %>
|
||||||
<%= ff.hidden_field(:contents, value: ff.object.contents_utf_8, class: "hot-contents" ) %>
|
<%= 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 class="hot">
|
||||||
</div>
|
</div>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@
|
||||||
<div class="editable-table" style="margin-bottom: 25px;">
|
<div class="editable-table" style="margin-bottom: 25px;">
|
||||||
<%= f.fields_for :table do |ff| %>
|
<%= f.fields_for :table do |ff| %>
|
||||||
<%= ff.hidden_field(:contents, value: ff.object.contents, class: "hot-contents" ) %>
|
<%= 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 class="hot">
|
||||||
</div>
|
</div>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
<div class="hot-table">
|
<div class="hot-table">
|
||||||
<%= hidden_field(result.table, :contents, value: result.table.contents_utf_8, class: "hot-contents" ) %>
|
<%= 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 class="step-result-hot-table">
|
||||||
</div>
|
</div>
|
||||||
</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,
|
my_module_status_id bigint,
|
||||||
status_changing boolean DEFAULT false,
|
status_changing boolean DEFAULT false,
|
||||||
changing_from_my_module_status_id bigint,
|
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,
|
last_modified_by_id bigint,
|
||||||
data_vector tsvector,
|
data_vector tsvector,
|
||||||
name character varying DEFAULT ''::character varying,
|
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'),
|
('20220914124900'),
|
||||||
('20221007113010'),
|
('20221007113010'),
|
||||||
('20221028085051'),
|
('20221028085051'),
|
||||||
('20221222123021');
|
('20221122132857'),
|
||||||
|
('20221222123021'),
|
||||||
|
('20230206095817');
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue