mirror of
https://github.com/gristlabs/grist-core.git
synced 2024-10-27 20:44:07 +00:00
feat(ColumnDesc): create column description in database and link it to visual behaviors
This commit is contained in:
parent
0a90fc0c7b
commit
009ebefd96
@ -259,8 +259,7 @@ DetailView.prototype.buildFieldDom = function(field, row) {
|
|||||||
dom.autoDispose(isCellActive),
|
dom.autoDispose(isCellActive),
|
||||||
kd.cssClass(function() { return 'detail_theme_field_' + self.viewSection.themeDef(); }),
|
kd.cssClass(function() { return 'detail_theme_field_' + self.viewSection.themeDef(); }),
|
||||||
dom('div.g_record_detail_label', kd.text(field.displayLabel)),
|
dom('div.g_record_detail_label', kd.text(field.displayLabel)),
|
||||||
// TODO : show the real description
|
dom('div.g_record_detail_description', kd.text(field.description)),
|
||||||
dom('div.g_record_detail_description', kd.text("Description testing")),
|
|
||||||
dom('div.g_record_detail_value',
|
dom('div.g_record_detail_value',
|
||||||
kd.toggleClass('scissors', isCopyActive),
|
kd.toggleClass('scissors', isCopyActive),
|
||||||
kd.toggleClass('record-add', row._isAddRow),
|
kd.toggleClass('record-add', row._isAddRow),
|
||||||
|
@ -20,6 +20,7 @@ export interface ViewFieldRec extends IRowModel<"_grist_Views_section_field">, R
|
|||||||
origCol: ko.Computed<ColumnRec>;
|
origCol: ko.Computed<ColumnRec>;
|
||||||
colId: ko.Computed<string>;
|
colId: ko.Computed<string>;
|
||||||
label: ko.Computed<string>;
|
label: ko.Computed<string>;
|
||||||
|
description: ko.Computed<string>;
|
||||||
|
|
||||||
// displayLabel displays label by default but switches to the more helpful colId whenever a
|
// displayLabel displays label by default but switches to the more helpful colId whenever a
|
||||||
// formula field in the view is being edited.
|
// formula field in the view is being edited.
|
||||||
@ -108,6 +109,7 @@ export function createViewFieldRec(this: ViewFieldRec, docModel: DocModel): void
|
|||||||
this.origCol = ko.pureComputed(() => this.column().origCol());
|
this.origCol = ko.pureComputed(() => this.column().origCol());
|
||||||
this.colId = ko.pureComputed(() => this.column().colId());
|
this.colId = ko.pureComputed(() => this.column().colId());
|
||||||
this.label = ko.pureComputed(() => this.column().label());
|
this.label = ko.pureComputed(() => this.column().label());
|
||||||
|
this.description = ko.pureComputed(() => this.column().description());
|
||||||
|
|
||||||
// displayLabel displays label by default but switches to the more helpful colId whenever a
|
// displayLabel displays label by default but switches to the more helpful colId whenever a
|
||||||
// formula field in the view is being edited.
|
// formula field in the view is being edited.
|
||||||
|
@ -95,11 +95,34 @@ export function buildDescriptionConfig(
|
|||||||
cursor: ko.Computed<CursorPos>,
|
cursor: ko.Computed<CursorPos>,
|
||||||
) {
|
) {
|
||||||
const editedDescription = Observable.create(owner, '');
|
const editedDescription = Observable.create(owner, '');
|
||||||
|
const saveDescription = async (val: string) => {
|
||||||
|
await origColumn.description.saveOnly(val);
|
||||||
|
editedDescription.set('');
|
||||||
|
}
|
||||||
|
|
||||||
|
// We will listen to cursor position and force a blur event on
|
||||||
|
// the text input, which will trigger save before the column observable
|
||||||
|
// will change its value.
|
||||||
|
// Otherwise, blur will be invoked after column change and save handler will
|
||||||
|
// update a different column.
|
||||||
|
let editor: HTMLTextAreaElement | undefined;
|
||||||
|
owner.autoDispose(
|
||||||
|
cursor.subscribe(() => {
|
||||||
|
editor?.blur();
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
return [
|
return [
|
||||||
cssLabel(t("DESCRIPTION")),
|
cssLabel(t("DESCRIPTION")),
|
||||||
cssRow(
|
cssRow(
|
||||||
cssTextArea(editedDescription, {})
|
editor = cssTextArea(fromKo(origColumn.description),
|
||||||
|
{ onInput: false },
|
||||||
|
{ placeholder: t("If necesary, describe the column") },
|
||||||
|
dom.on('input', (e, elem) => {
|
||||||
|
editedDescription.set(elem.value);
|
||||||
|
saveDescription(elem.value)
|
||||||
|
}),
|
||||||
|
)
|
||||||
),
|
),
|
||||||
|
|
||||||
];
|
];
|
||||||
|
@ -237,7 +237,7 @@ export class RightPanel extends Disposable {
|
|||||||
dom.create(buildNameConfig, origColumn, cursor, isMultiSelect),
|
dom.create(buildNameConfig, origColumn, cursor, isMultiSelect),
|
||||||
),
|
),
|
||||||
cssSection(
|
cssSection(
|
||||||
dom.create(buildDescriptionConfig, origColumn, cursor, isMultiSelect),
|
dom.create(buildDescriptionConfig, origColumn, cursor),
|
||||||
),
|
),
|
||||||
cssSeparator(),
|
cssSeparator(),
|
||||||
cssSection(
|
cssSection(
|
||||||
|
@ -4,7 +4,7 @@ import { GristObjCode } from "app/plugin/GristData";
|
|||||||
|
|
||||||
// tslint:disable:object-literal-key-quotes
|
// tslint:disable:object-literal-key-quotes
|
||||||
|
|
||||||
export const SCHEMA_VERSION = 35;
|
export const SCHEMA_VERSION = 36;
|
||||||
|
|
||||||
export const schema = {
|
export const schema = {
|
||||||
|
|
||||||
@ -34,6 +34,7 @@ export const schema = {
|
|||||||
isFormula : "Bool",
|
isFormula : "Bool",
|
||||||
formula : "Text",
|
formula : "Text",
|
||||||
label : "Text",
|
label : "Text",
|
||||||
|
description: "Text",
|
||||||
untieColIdFromLabel : "Bool",
|
untieColIdFromLabel : "Bool",
|
||||||
summarySourceCol : "Ref:_grist_Tables_column",
|
summarySourceCol : "Ref:_grist_Tables_column",
|
||||||
displayCol : "Ref:_grist_Tables_column",
|
displayCol : "Ref:_grist_Tables_column",
|
||||||
@ -239,6 +240,7 @@ export interface SchemaTypes {
|
|||||||
isFormula: boolean;
|
isFormula: boolean;
|
||||||
formula: string;
|
formula: string;
|
||||||
label: string;
|
label: string;
|
||||||
|
description: string;
|
||||||
untieColIdFromLabel: boolean;
|
untieColIdFromLabel: boolean;
|
||||||
summarySourceCol: number;
|
summarySourceCol: number;
|
||||||
displayCol: number;
|
displayCol: number;
|
||||||
|
@ -6,9 +6,9 @@ export const GRIST_DOC_SQL = `
|
|||||||
PRAGMA foreign_keys=OFF;
|
PRAGMA foreign_keys=OFF;
|
||||||
BEGIN TRANSACTION;
|
BEGIN TRANSACTION;
|
||||||
CREATE TABLE IF NOT EXISTS "_grist_DocInfo" (id INTEGER PRIMARY KEY, "docId" TEXT DEFAULT '', "peers" TEXT DEFAULT '', "basketId" TEXT DEFAULT '', "schemaVersion" INTEGER DEFAULT 0, "timezone" TEXT DEFAULT '', "documentSettings" TEXT DEFAULT '');
|
CREATE TABLE IF NOT EXISTS "_grist_DocInfo" (id INTEGER PRIMARY KEY, "docId" TEXT DEFAULT '', "peers" TEXT DEFAULT '', "basketId" TEXT DEFAULT '', "schemaVersion" INTEGER DEFAULT 0, "timezone" TEXT DEFAULT '', "documentSettings" TEXT DEFAULT '');
|
||||||
INSERT INTO _grist_DocInfo VALUES(1,'','','',35,'','');
|
INSERT INTO _grist_DocInfo VALUES(1,'','','',36,'','');
|
||||||
CREATE TABLE IF NOT EXISTS "_grist_Tables" (id INTEGER PRIMARY KEY, "tableId" TEXT DEFAULT '', "primaryViewId" INTEGER DEFAULT 0, "summarySourceTable" INTEGER DEFAULT 0, "onDemand" BOOLEAN DEFAULT 0, "rawViewSectionRef" INTEGER DEFAULT 0);
|
CREATE TABLE IF NOT EXISTS "_grist_Tables" (id INTEGER PRIMARY KEY, "tableId" TEXT DEFAULT '', "primaryViewId" INTEGER DEFAULT 0, "summarySourceTable" INTEGER DEFAULT 0, "onDemand" BOOLEAN DEFAULT 0, "rawViewSectionRef" INTEGER DEFAULT 0);
|
||||||
CREATE TABLE IF NOT EXISTS "_grist_Tables_column" (id INTEGER PRIMARY KEY, "parentId" INTEGER DEFAULT 0, "parentPos" NUMERIC DEFAULT 1e999, "colId" TEXT DEFAULT '', "type" TEXT DEFAULT '', "widgetOptions" TEXT DEFAULT '', "isFormula" BOOLEAN DEFAULT 0, "formula" TEXT DEFAULT '', "label" TEXT DEFAULT '', "untieColIdFromLabel" BOOLEAN DEFAULT 0, "summarySourceCol" INTEGER DEFAULT 0, "displayCol" INTEGER DEFAULT 0, "visibleCol" INTEGER DEFAULT 0, "rules" TEXT DEFAULT NULL, "recalcWhen" INTEGER DEFAULT 0, "recalcDeps" TEXT DEFAULT NULL);
|
CREATE TABLE IF NOT EXISTS "_grist_Tables_column" (id INTEGER PRIMARY KEY, "parentId" INTEGER DEFAULT 0, "parentPos" NUMERIC DEFAULT 1e999, "colId" TEXT DEFAULT '', "type" TEXT DEFAULT '', "widgetOptions" TEXT DEFAULT '', "isFormula" BOOLEAN DEFAULT 0, "formula" TEXT DEFAULT '', "label" TEXT DEFAULT '', "description" TEXT DEFAULT '', "untieColIdFromLabel" BOOLEAN DEFAULT 0, "summarySourceCol" INTEGER DEFAULT 0, "displayCol" INTEGER DEFAULT 0, "visibleCol" INTEGER DEFAULT 0, "rules" TEXT DEFAULT NULL, "recalcWhen" INTEGER DEFAULT 0, "recalcDeps" TEXT DEFAULT NULL);
|
||||||
CREATE TABLE IF NOT EXISTS "_grist_Imports" (id INTEGER PRIMARY KEY, "tableRef" INTEGER DEFAULT 0, "origFileName" TEXT DEFAULT '', "parseFormula" TEXT DEFAULT '', "delimiter" TEXT DEFAULT '', "doublequote" BOOLEAN DEFAULT 0, "escapechar" TEXT DEFAULT '', "quotechar" TEXT DEFAULT '', "skipinitialspace" BOOLEAN DEFAULT 0, "encoding" TEXT DEFAULT '', "hasHeaders" BOOLEAN DEFAULT 0);
|
CREATE TABLE IF NOT EXISTS "_grist_Imports" (id INTEGER PRIMARY KEY, "tableRef" INTEGER DEFAULT 0, "origFileName" TEXT DEFAULT '', "parseFormula" TEXT DEFAULT '', "delimiter" TEXT DEFAULT '', "doublequote" BOOLEAN DEFAULT 0, "escapechar" TEXT DEFAULT '', "quotechar" TEXT DEFAULT '', "skipinitialspace" BOOLEAN DEFAULT 0, "encoding" TEXT DEFAULT '', "hasHeaders" BOOLEAN DEFAULT 0);
|
||||||
CREATE TABLE IF NOT EXISTS "_grist_External_database" (id INTEGER PRIMARY KEY, "host" TEXT DEFAULT '', "port" INTEGER DEFAULT 0, "username" TEXT DEFAULT '', "dialect" TEXT DEFAULT '', "database" TEXT DEFAULT '', "storage" TEXT DEFAULT '');
|
CREATE TABLE IF NOT EXISTS "_grist_External_database" (id INTEGER PRIMARY KEY, "host" TEXT DEFAULT '', "port" INTEGER DEFAULT 0, "username" TEXT DEFAULT '', "dialect" TEXT DEFAULT '', "database" TEXT DEFAULT '', "storage" TEXT DEFAULT '');
|
||||||
CREATE TABLE IF NOT EXISTS "_grist_External_table" (id INTEGER PRIMARY KEY, "tableRef" INTEGER DEFAULT 0, "databaseRef" INTEGER DEFAULT 0, "tableName" TEXT DEFAULT '');
|
CREATE TABLE IF NOT EXISTS "_grist_External_table" (id INTEGER PRIMARY KEY, "tableRef" INTEGER DEFAULT 0, "databaseRef" INTEGER DEFAULT 0, "tableName" TEXT DEFAULT '');
|
||||||
@ -43,14 +43,14 @@ export const GRIST_DOC_WITH_TABLE1_SQL = `
|
|||||||
PRAGMA foreign_keys=OFF;
|
PRAGMA foreign_keys=OFF;
|
||||||
BEGIN TRANSACTION;
|
BEGIN TRANSACTION;
|
||||||
CREATE TABLE IF NOT EXISTS "_grist_DocInfo" (id INTEGER PRIMARY KEY, "docId" TEXT DEFAULT '', "peers" TEXT DEFAULT '', "basketId" TEXT DEFAULT '', "schemaVersion" INTEGER DEFAULT 0, "timezone" TEXT DEFAULT '', "documentSettings" TEXT DEFAULT '');
|
CREATE TABLE IF NOT EXISTS "_grist_DocInfo" (id INTEGER PRIMARY KEY, "docId" TEXT DEFAULT '', "peers" TEXT DEFAULT '', "basketId" TEXT DEFAULT '', "schemaVersion" INTEGER DEFAULT 0, "timezone" TEXT DEFAULT '', "documentSettings" TEXT DEFAULT '');
|
||||||
INSERT INTO _grist_DocInfo VALUES(1,'','','',35,'','');
|
INSERT INTO _grist_DocInfo VALUES(1,'','','',36,'','');
|
||||||
CREATE TABLE IF NOT EXISTS "_grist_Tables" (id INTEGER PRIMARY KEY, "tableId" TEXT DEFAULT '', "primaryViewId" INTEGER DEFAULT 0, "summarySourceTable" INTEGER DEFAULT 0, "onDemand" BOOLEAN DEFAULT 0, "rawViewSectionRef" INTEGER DEFAULT 0);
|
CREATE TABLE IF NOT EXISTS "_grist_Tables" (id INTEGER PRIMARY KEY, "tableId" TEXT DEFAULT '', "primaryViewId" INTEGER DEFAULT 0, "summarySourceTable" INTEGER DEFAULT 0, "onDemand" BOOLEAN DEFAULT 0, "rawViewSectionRef" INTEGER DEFAULT 0);
|
||||||
INSERT INTO _grist_Tables VALUES(1,'Table1',1,0,0,2);
|
INSERT INTO _grist_Tables VALUES(1,'Table1',1,0,0,2);
|
||||||
CREATE TABLE IF NOT EXISTS "_grist_Tables_column" (id INTEGER PRIMARY KEY, "parentId" INTEGER DEFAULT 0, "parentPos" NUMERIC DEFAULT 1e999, "colId" TEXT DEFAULT '', "type" TEXT DEFAULT '', "widgetOptions" TEXT DEFAULT '', "isFormula" BOOLEAN DEFAULT 0, "formula" TEXT DEFAULT '', "label" TEXT DEFAULT '', "untieColIdFromLabel" BOOLEAN DEFAULT 0, "summarySourceCol" INTEGER DEFAULT 0, "displayCol" INTEGER DEFAULT 0, "visibleCol" INTEGER DEFAULT 0, "rules" TEXT DEFAULT NULL, "recalcWhen" INTEGER DEFAULT 0, "recalcDeps" TEXT DEFAULT NULL);
|
CREATE TABLE IF NOT EXISTS "_grist_Tables_column" (id INTEGER PRIMARY KEY, "parentId" INTEGER DEFAULT 0, "parentPos" NUMERIC DEFAULT 1e999, "colId" TEXT DEFAULT '', "type" TEXT DEFAULT '', "widgetOptions" TEXT DEFAULT '', "isFormula" BOOLEAN DEFAULT 0, "formula" TEXT DEFAULT '', "label" TEXT DEFAULT '', "description" TEXT DEFAULT '', "untieColIdFromLabel" BOOLEAN DEFAULT 0, "summarySourceCol" INTEGER DEFAULT 0, "displayCol" INTEGER DEFAULT 0, "visibleCol" INTEGER DEFAULT 0, "rules" TEXT DEFAULT NULL, "recalcWhen" INTEGER DEFAULT 0, "recalcDeps" TEXT DEFAULT NULL);
|
||||||
INSERT INTO _grist_Tables_column VALUES(1,1,1,'manualSort','ManualSortPos','',0,'','manualSort',0,0,0,0,NULL,0,NULL);
|
INSERT INTO _grist_Tables_column VALUES(1,1,1,'manualSort','ManualSortPos','',0,'','manualSort','',0,0,0,0,NULL,0,NULL);
|
||||||
INSERT INTO _grist_Tables_column VALUES(2,1,2,'A','Any','',1,'','A',0,0,0,0,NULL,0,NULL);
|
INSERT INTO _grist_Tables_column VALUES(2,1,2,'A','Any','',1,'','A','',0,0,0,0,NULL,0,NULL);
|
||||||
INSERT INTO _grist_Tables_column VALUES(3,1,3,'B','Any','',1,'','B',0,0,0,0,NULL,0,NULL);
|
INSERT INTO _grist_Tables_column VALUES(3,1,3,'B','Any','',1,'','B','',0,0,0,0,NULL,0,NULL);
|
||||||
INSERT INTO _grist_Tables_column VALUES(4,1,4,'C','Any','',1,'','C',0,0,0,0,NULL,0,NULL);
|
INSERT INTO _grist_Tables_column VALUES(4,1,4,'C','Any','',1,'','C','',0,0,0,0,NULL,0,NULL);
|
||||||
CREATE TABLE IF NOT EXISTS "_grist_Imports" (id INTEGER PRIMARY KEY, "tableRef" INTEGER DEFAULT 0, "origFileName" TEXT DEFAULT '', "parseFormula" TEXT DEFAULT '', "delimiter" TEXT DEFAULT '', "doublequote" BOOLEAN DEFAULT 0, "escapechar" TEXT DEFAULT '', "quotechar" TEXT DEFAULT '', "skipinitialspace" BOOLEAN DEFAULT 0, "encoding" TEXT DEFAULT '', "hasHeaders" BOOLEAN DEFAULT 0);
|
CREATE TABLE IF NOT EXISTS "_grist_Imports" (id INTEGER PRIMARY KEY, "tableRef" INTEGER DEFAULT 0, "origFileName" TEXT DEFAULT '', "parseFormula" TEXT DEFAULT '', "delimiter" TEXT DEFAULT '', "doublequote" BOOLEAN DEFAULT 0, "escapechar" TEXT DEFAULT '', "quotechar" TEXT DEFAULT '', "skipinitialspace" BOOLEAN DEFAULT 0, "encoding" TEXT DEFAULT '', "hasHeaders" BOOLEAN DEFAULT 0);
|
||||||
CREATE TABLE IF NOT EXISTS "_grist_External_database" (id INTEGER PRIMARY KEY, "host" TEXT DEFAULT '', "port" INTEGER DEFAULT 0, "username" TEXT DEFAULT '', "dialect" TEXT DEFAULT '', "database" TEXT DEFAULT '', "storage" TEXT DEFAULT '');
|
CREATE TABLE IF NOT EXISTS "_grist_External_database" (id INTEGER PRIMARY KEY, "host" TEXT DEFAULT '', "port" INTEGER DEFAULT 0, "username" TEXT DEFAULT '', "dialect" TEXT DEFAULT '', "database" TEXT DEFAULT '', "storage" TEXT DEFAULT '');
|
||||||
CREATE TABLE IF NOT EXISTS "_grist_External_table" (id INTEGER PRIMARY KEY, "tableRef" INTEGER DEFAULT 0, "databaseRef" INTEGER DEFAULT 0, "tableName" TEXT DEFAULT '');
|
CREATE TABLE IF NOT EXISTS "_grist_External_table" (id INTEGER PRIMARY KEY, "tableRef" INTEGER DEFAULT 0, "databaseRef" INTEGER DEFAULT 0, "tableName" TEXT DEFAULT '');
|
||||||
|
@ -1188,3 +1188,11 @@ def migration35(tdset):
|
|||||||
))
|
))
|
||||||
|
|
||||||
return tdset.apply_doc_actions(doc_actions)
|
return tdset.apply_doc_actions(doc_actions)
|
||||||
|
|
||||||
|
|
||||||
|
@migration(schema_version=36)
|
||||||
|
def migration36(tdset):
|
||||||
|
"""
|
||||||
|
Add description to column
|
||||||
|
"""
|
||||||
|
return tdset.apply_doc_actions([add_column('_grist_Tables_column', 'description', 'Text')])
|
||||||
|
@ -15,7 +15,7 @@ import six
|
|||||||
|
|
||||||
import actions
|
import actions
|
||||||
|
|
||||||
SCHEMA_VERSION = 35
|
SCHEMA_VERSION = 36
|
||||||
|
|
||||||
def make_column(col_id, col_type, formula='', isFormula=False):
|
def make_column(col_id, col_type, formula='', isFormula=False):
|
||||||
return {
|
return {
|
||||||
@ -70,6 +70,7 @@ def schema_create_actions():
|
|||||||
make_column("isFormula", "Bool"),
|
make_column("isFormula", "Bool"),
|
||||||
make_column("formula", "Text"),
|
make_column("formula", "Text"),
|
||||||
make_column("label", "Text"),
|
make_column("label", "Text"),
|
||||||
|
make_column("description", "Text"),
|
||||||
|
|
||||||
# Normally a change to label changes colId as well, unless untieColIdFromLabel is True.
|
# Normally a change to label changes colId as well, unless untieColIdFromLabel is True.
|
||||||
# (We intentionally pick a variable whose default value is false.)
|
# (We intentionally pick a variable whose default value is false.)
|
||||||
|
Loading…
Reference in New Issue
Block a user