saltcorn-db-code 0.1.0

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.
@@ -0,0 +1,39 @@
1
+ const Workflow = require("@saltcorn/data/models/workflow");
2
+ const { renderRoutineList, renderRoutineDetail } = require("../lib/render-routines");
3
+
4
+ const configuration_workflow = () => new Workflow({ steps: [] });
5
+
6
+ const get_state_fields = () => [
7
+ {
8
+ name: "routine_oid",
9
+ type: "Integer",
10
+ required: false
11
+ },
12
+ {
13
+ name: "kind",
14
+ type: "String",
15
+ required: false
16
+ }
17
+ ];
18
+
19
+ const run = async (tableId, viewname, configuration, state, { req }) => {
20
+ if (!req || !req.user || req.user.role_id !== 1) {
21
+ return `<div class="alert alert-danger">DB Code Console is available to administrators only.</div>`;
22
+ }
23
+
24
+ const baseUrl = `/view/${encodeURIComponent(viewname)}`;
25
+ if (state && state.routine_oid) {
26
+ return renderRoutineDetail(state.routine_oid, { baseUrl, useViewState: true, showWriteActions: true, kind: state.kind || "" });
27
+ }
28
+ return renderRoutineList({ baseUrl, useViewState: true, showWriteActions: true, kind: state.kind || "" });
29
+ };
30
+
31
+ module.exports = {
32
+ name: "DBCodeConsole",
33
+ display_name: "DB Code Console",
34
+ description: "Administrative console for PostgreSQL routines in the current Saltcorn tenant schema.",
35
+ tableless: true,
36
+ configuration_workflow,
37
+ get_state_fields,
38
+ run
39
+ };