@saltcorn/history-control 0.5.1 → 0.5.3
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/package.json +1 -1
- package/rowdiffview.js +42 -15
package/package.json
CHANGED
package/rowdiffview.js
CHANGED
|
@@ -23,6 +23,7 @@ const {
|
|
|
23
23
|
button,
|
|
24
24
|
} = require("@saltcorn/markup/tags");
|
|
25
25
|
const { radio_group, checkbox_group } = require("@saltcorn/markup/helpers");
|
|
26
|
+
const { picked_fields_to_query } = require("@saltcorn/data/plugin-helper");
|
|
26
27
|
const moment = require("moment");
|
|
27
28
|
|
|
28
29
|
const get_state_fields = () => [
|
|
@@ -125,29 +126,55 @@ const run = async (
|
|
|
125
126
|
|
|
126
127
|
let hist = await table.get_history(id);
|
|
127
128
|
|
|
129
|
+
if (!hist || !hist.length) return "No versions recorded";
|
|
130
|
+
|
|
128
131
|
let last = 0;
|
|
129
132
|
let last_changed_by = undefined;
|
|
130
|
-
hist = hist.filter((row) => {
|
|
131
|
-
const myEpoch = Math.round(new Date(row._time).getTime() / 1000);
|
|
132
|
-
if (
|
|
133
|
-
myEpoch - last > min_interval_secs ||
|
|
134
|
-
(row._userid && row._userid !== last_changed_by)
|
|
135
|
-
) {
|
|
136
|
-
//include
|
|
137
|
-
last = myEpoch;
|
|
138
|
-
last_changed_by = row._userid;
|
|
139
|
-
return true;
|
|
140
|
-
} else return false;
|
|
141
|
-
});
|
|
142
133
|
|
|
143
|
-
|
|
144
|
-
|
|
134
|
+
hist = hist
|
|
135
|
+
.filter((row) => {
|
|
136
|
+
const myEpoch = Math.round(new Date(row._time).getTime() / 1000);
|
|
137
|
+
if (
|
|
138
|
+
myEpoch - last > min_interval_secs ||
|
|
139
|
+
(row._userid && row._userid !== last_changed_by)
|
|
140
|
+
) {
|
|
141
|
+
//include
|
|
142
|
+
last = myEpoch;
|
|
143
|
+
last_changed_by = row._userid;
|
|
144
|
+
return true;
|
|
145
|
+
} else return false;
|
|
146
|
+
})
|
|
147
|
+
.reverse();
|
|
148
|
+
const view = View.findOne({ name: show_view });
|
|
149
|
+
|
|
150
|
+
const { joinFields } = picked_fields_to_query(
|
|
151
|
+
view.configuration.columns,
|
|
152
|
+
table.fields,
|
|
153
|
+
view.configurationlayout,
|
|
154
|
+
extraArgs.req,
|
|
155
|
+
table
|
|
156
|
+
);
|
|
157
|
+
for (const [nm, jf] of Object.entries(joinFields)) {
|
|
158
|
+
const refVals = new Set(hist.map((r) => r[jf.ref]));
|
|
159
|
+
const refField = table.getField(jf.ref);
|
|
160
|
+
const reftable = Table.findOne(refField.reftable_name);
|
|
161
|
+
const rows = await reftable.getRows({
|
|
162
|
+
[reftable.pk_name]: { in: [...refVals] },
|
|
163
|
+
});
|
|
164
|
+
const rowsByVal = {};
|
|
165
|
+
rows.forEach((r) => {
|
|
166
|
+
rowsByVal[r[reftable.pk_name]] = r;
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
hist.forEach((h) => {
|
|
170
|
+
h[nm] = rowsByVal[h[jf.ref]]?.[jf.target];
|
|
171
|
+
});
|
|
172
|
+
}
|
|
145
173
|
|
|
146
174
|
const userIds = new Set(hist.map((h) => h._userid));
|
|
147
175
|
const users = await User.find({ id: { in: [...userIds] } });
|
|
148
176
|
const emails = {};
|
|
149
177
|
users.forEach((u) => (emails[u.id] = u.email));
|
|
150
|
-
const view = View.findOne({ name: show_view });
|
|
151
178
|
const rendered = await view.viewtemplateObj.renderRows(
|
|
152
179
|
table,
|
|
153
180
|
view.name,
|