@saltcorn/history-control 0.5.3 → 0.5.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/common.js +20 -6
- package/package.json +1 -1
- package/rowdiffview.js +19 -4
- package/table-provider.js +6 -1
package/common.js
CHANGED
|
@@ -40,17 +40,31 @@ const get_where_vals = (table_name, whereFull) => {
|
|
|
40
40
|
const runQuery = async (table, whereFull, opts) => {
|
|
41
41
|
const schemaPrefix = db.getTenantSchemaPrefix();
|
|
42
42
|
const { where, values } = get_where_vals(table.name, whereFull);
|
|
43
|
-
|
|
44
|
-
|
|
43
|
+
let joinTs = [],
|
|
44
|
+
joinF = [];
|
|
45
|
+
// console.log(table.fields);
|
|
46
|
+
|
|
47
|
+
Object.entries(opts?.joinFields || {}).forEach(([nm, { ref, target }]) => {
|
|
48
|
+
const keyField = table.getField(ref);
|
|
49
|
+
const reftable_name = `${schemaPrefix}"${
|
|
50
|
+
ref === "_userid" ? "users" : db.sqlsanitize(keyField.reftable_name)
|
|
51
|
+
}"`;
|
|
52
|
+
joinF.push(`${reftable_name}."${target}" as "${nm}"`);
|
|
53
|
+
joinTs.push(`${reftable_name} on h."${ref}" = ${reftable_name}."id"`);
|
|
54
|
+
});
|
|
55
|
+
const sql = `select
|
|
56
|
+
_version || '_'|| h.id as _version_id,
|
|
45
57
|
_version = (select max(ih._version) from ${schemaPrefix}"${db.sqlsanitize(
|
|
46
58
|
table.name
|
|
47
59
|
)}__history" ih where ih.id = h.id) as _is_latest,
|
|
48
60
|
not exists(select id from ${schemaPrefix}"${db.sqlsanitize(
|
|
49
61
|
table.name
|
|
50
|
-
)}" t where t.id = h.id) as _deleted,
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
62
|
+
)}" t where t.id = h.id) as _deleted,
|
|
63
|
+
*${
|
|
64
|
+
joinF.length ? `, ${joinF.join()}` : ``
|
|
65
|
+
} from ${schemaPrefix}"${db.sqlsanitize(table.name)}__history" h ${
|
|
66
|
+
joinTs.length ? ` JOIN ${joinTs.join(" JOIN ")}` : ``
|
|
67
|
+
} ${where.length ? ` ${where}` : ""}${
|
|
54
68
|
opts.orderBy && opts.orderBy !== "_version_id"
|
|
55
69
|
? ` order by "${db.sqlsanitize(opts.orderBy)}"${
|
|
56
70
|
opts.orderDesc ? " DESC" : ""
|
package/package.json
CHANGED
package/rowdiffview.js
CHANGED
|
@@ -20,6 +20,7 @@ const {
|
|
|
20
20
|
select,
|
|
21
21
|
option,
|
|
22
22
|
h2,
|
|
23
|
+
time,
|
|
23
24
|
button,
|
|
24
25
|
} = require("@saltcorn/markup/tags");
|
|
25
26
|
const { radio_group, checkbox_group } = require("@saltcorn/markup/helpers");
|
|
@@ -183,6 +184,7 @@ const run = async (
|
|
|
183
184
|
hist,
|
|
184
185
|
state
|
|
185
186
|
);
|
|
187
|
+
|
|
186
188
|
return div(
|
|
187
189
|
{
|
|
188
190
|
class: ["accordion"],
|
|
@@ -190,6 +192,21 @@ const run = async (
|
|
|
190
192
|
},
|
|
191
193
|
rendered.map((html, ix) => {
|
|
192
194
|
const row = hist[ix];
|
|
195
|
+
let d = row._time;
|
|
196
|
+
const jsdate = d;
|
|
197
|
+
const locale = (req) => {
|
|
198
|
+
//console.log(req && req.getLocale ? req.getLocale() : undefined);
|
|
199
|
+
return req?.getLocale?.() || "en";
|
|
200
|
+
};
|
|
201
|
+
const loc = locale(extraArgs.req);
|
|
202
|
+
let format = date_format || "YYYY-MM-DD HH:mm";
|
|
203
|
+
let timeHtml = time(
|
|
204
|
+
{
|
|
205
|
+
datetime: new Date(d).toISOString(),
|
|
206
|
+
"locale-date-format": encodeURIComponent(JSON.stringify(format)),
|
|
207
|
+
},
|
|
208
|
+
moment(jsdate).locale(loc).format(format)
|
|
209
|
+
);
|
|
193
210
|
return div(
|
|
194
211
|
{ class: "accordion-item" },
|
|
195
212
|
h2(
|
|
@@ -203,10 +220,8 @@ const run = async (
|
|
|
203
220
|
"aria-expanded": "false",
|
|
204
221
|
"aria-controls": `a${stateHash}tab${ix}`,
|
|
205
222
|
},
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
: row._time.toString(),
|
|
209
|
-
" - ",
|
|
223
|
+
timeHtml,
|
|
224
|
+
" - ",
|
|
210
225
|
emails[row._userid]
|
|
211
226
|
)
|
|
212
227
|
),
|
package/table-provider.js
CHANGED
|
@@ -66,7 +66,7 @@ module.exports = {
|
|
|
66
66
|
{ name: "_is_latest", label: "Is latest", type: "Bool" },
|
|
67
67
|
{ name: "_deleted", label: "Deleted", type: "Bool" },
|
|
68
68
|
{ name: "_time", label: "Time", type: "Date" },
|
|
69
|
-
{ name: "_userid", label: "User ID", type: "
|
|
69
|
+
{ name: "_userid", label: "User ID", type: "Key to users" },
|
|
70
70
|
{
|
|
71
71
|
name: "_restore_of_version",
|
|
72
72
|
label: "Restore of version",
|
|
@@ -98,6 +98,11 @@ module.exports = {
|
|
|
98
98
|
const qres = await runQuery(table, where, opts);
|
|
99
99
|
return qres.rows;
|
|
100
100
|
},
|
|
101
|
+
getJoinedRows: async (opts) => {
|
|
102
|
+
const table = Table.findOne({ name: cfg.table });
|
|
103
|
+
const qres = await runQuery(table, opts?.where || {}, opts);
|
|
104
|
+
return qres.rows;
|
|
105
|
+
},
|
|
101
106
|
};
|
|
102
107
|
},
|
|
103
108
|
},
|