@hotstaq/admin-panel 0.2.5 → 0.2.7

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.
Files changed (99) hide show
  1. package/.vscode/launch.json +5 -5
  2. package/HotSite.json +2 -2
  3. package/build/{src/AppAPI.d.ts → AppAPI.d.ts} +0 -0
  4. package/build/AppAPI.d.ts.map +1 -0
  5. package/build/{src/AppAPI.js → AppAPI.js} +48 -1
  6. package/build/AppAPI.js.map +1 -0
  7. package/build/WebExport.d.ts +3 -0
  8. package/build/WebExport.d.ts.map +1 -0
  9. package/build/{src/WebExport.js → WebExport.js} +8 -22
  10. package/build/WebExport.js.map +1 -0
  11. package/build/{src/cli.d.ts → cli.d.ts} +0 -0
  12. package/build/cli.d.ts.map +1 -0
  13. package/build/{src/cli.js → cli.js} +2 -2
  14. package/build/cli.js.map +1 -0
  15. package/build/{src/components → components}/admin-button.d.ts +1 -1
  16. package/build/components/admin-button.d.ts.map +1 -0
  17. package/build/{src/components → components}/admin-button.js +1 -5
  18. package/build/components/admin-button.js.map +1 -0
  19. package/build/components/admin-checkbox.d.ts +1 -0
  20. package/build/components/admin-checkbox.d.ts.map +1 -0
  21. package/build/components/admin-checkbox.js +43 -0
  22. package/build/components/admin-checkbox.js.map +1 -0
  23. package/build/{src/components → components}/admin-dashboard.d.ts +2 -2
  24. package/build/components/admin-dashboard.d.ts.map +1 -0
  25. package/build/components/admin-dashboard.js +44 -0
  26. package/build/components/admin-dashboard.js.map +1 -0
  27. package/build/components/admin-edit.d.ts +87 -0
  28. package/build/components/admin-edit.d.ts.map +1 -0
  29. package/build/components/admin-edit.js +297 -0
  30. package/build/components/admin-edit.js.map +1 -0
  31. package/build/{src/components → components}/admin-table-field.d.ts +3 -6
  32. package/build/components/admin-table-field.d.ts.map +1 -0
  33. package/build/components/admin-table-field.js +47 -0
  34. package/build/components/admin-table-field.js.map +1 -0
  35. package/build/{src/components → components}/admin-table-row.d.ts +3 -6
  36. package/build/components/admin-table-row.d.ts.map +1 -0
  37. package/build/components/admin-table-row.js +55 -0
  38. package/build/components/admin-table-row.js.map +1 -0
  39. package/build/{src/components → components}/admin-table.d.ts +36 -4
  40. package/build/components/admin-table.d.ts.map +1 -0
  41. package/build/{src/components → components}/admin-table.js +116 -23
  42. package/build/components/admin-table.js.map +1 -0
  43. package/build/components/admin-text.d.ts +26 -0
  44. package/build/components/admin-text.d.ts.map +1 -0
  45. package/build/components/admin-text.js +57 -0
  46. package/build/components/admin-text.js.map +1 -0
  47. package/build/{src/WebExport.d.ts → index.d.ts} +2 -3
  48. package/build/index.d.ts.map +1 -0
  49. package/build/index.js +18 -0
  50. package/build/index.js.map +1 -0
  51. package/build-web/AdminPanelComponents.js +2 -2
  52. package/build-web/AdminPanelWeb_AppAPI.js +87 -0
  53. package/package.json +8 -7
  54. package/src/AppAPI.ts +55 -2
  55. package/src/WebExport.ts +9 -24
  56. package/src/cli.ts +2 -2
  57. package/src/components/admin-button.ts +2 -2
  58. package/src/components/admin-checkbox.ts +52 -0
  59. package/src/components/admin-dashboard.ts +4 -3
  60. package/src/components/admin-edit.ts +233 -16
  61. package/src/components/admin-table-field.ts +8 -7
  62. package/src/components/admin-table-row.ts +9 -5
  63. package/src/components/admin-table.ts +169 -10
  64. package/src/components/admin-text.ts +24 -4
  65. package/src/index.ts +17 -0
  66. package/tsconfig.json +1 -0
  67. package/webpack.config.cjs +2 -1
  68. package/build/scripts/watch.d.ts +0 -2
  69. package/build/scripts/watch.d.ts.map +0 -1
  70. package/build/scripts/watch.js +0 -127
  71. package/build/scripts/watch.js.map +0 -1
  72. package/build/src/AppAPI.d.ts.map +0 -1
  73. package/build/src/AppAPI.js.map +0 -1
  74. package/build/src/WebExport.d.ts.map +0 -1
  75. package/build/src/WebExport.js.map +0 -1
  76. package/build/src/cli.d.ts.map +0 -1
  77. package/build/src/cli.js.map +0 -1
  78. package/build/src/components/admin-button.d.ts.map +0 -1
  79. package/build/src/components/admin-button.js.map +0 -1
  80. package/build/src/components/admin-dashboard.d.ts.map +0 -1
  81. package/build/src/components/admin-dashboard.js +0 -89
  82. package/build/src/components/admin-dashboard.js.map +0 -1
  83. package/build/src/components/admin-edit.d.ts +0 -39
  84. package/build/src/components/admin-edit.d.ts.map +0 -1
  85. package/build/src/components/admin-edit.js +0 -124
  86. package/build/src/components/admin-edit.js.map +0 -1
  87. package/build/src/components/admin-table-field.d.ts.map +0 -1
  88. package/build/src/components/admin-table-field.js +0 -92
  89. package/build/src/components/admin-table-field.js.map +0 -1
  90. package/build/src/components/admin-table-row.d.ts.map +0 -1
  91. package/build/src/components/admin-table-row.js +0 -99
  92. package/build/src/components/admin-table-row.js.map +0 -1
  93. package/build/src/components/admin-table.d.ts.map +0 -1
  94. package/build/src/components/admin-table.js.map +0 -1
  95. package/build/src/components/admin-text.d.ts +0 -14
  96. package/build/src/components/admin-text.d.ts.map +0 -1
  97. package/build/src/components/admin-text.js +0 -98
  98. package/build/src/components/admin-text.js.map +0 -1
  99. package/scripts/watch.ts +0 -59
@@ -176,11 +176,98 @@ class data
176
176
  return (promise);
177
177
  }
178
178
 
179
+ /**
180
+ * The JSON object to send to the server.
181
+ *
182
+ * @typedef {Object} DATA_EDIT_JSON_OBJECT_TYPE
183
+ * @property {string} schema The schema to edit data in.
184
+ * @property {string} whereFields The where fields and their values to select from the database. A key/value object must be passed. Example: { "name": "Test_User" }
185
+ * @property {string} fields The fields and their values to update in the database. A key/value object must be passed. Example: { "name": "Test_User" }
186
+ */
187
+
188
+ /**
189
+ * The edit method.
190
+ *
191
+ * @param {DATA_EDIT_JSON_OBJECT_TYPE} jsonObj
192
+ *
193
+ * @returns {string} Returns true if successful.
194
+ */
195
+ edit (jsonObj)
196
+ {
197
+ var promise = new Promise ((resolve, reject) =>
198
+ {
199
+ const url = `${this.baseUrl}/v1/data/edit`;
200
+ const auth = null;
201
+
202
+ if (this.authorization != null)
203
+ {
204
+ if (this.authorization.toAuthorizationHeaderString != null)
205
+ auth = this.authorization.toAuthorizationHeaderString ();
206
+ }
207
+
208
+
209
+ jsonObj = HotStaqProcessJSONObject (jsonObj);
210
+ HotStaqPostJSONObject ("POST", url, jsonObj, auth).then (
211
+ function (response)
212
+ {
213
+ var result = response.json ();
214
+
215
+ resolve (result);
216
+ });
217
+ });
218
+
219
+ return (promise);
220
+ }
221
+
222
+ /**
223
+ * The JSON object to send to the server.
224
+ *
225
+ * @typedef {Object} DATA_REMOVE_JSON_OBJECT_TYPE
226
+ * @property {string} schema The schema to remove data from.
227
+ * @property {string} whereFields The where fields and their values to select from the database. A key/value object must be passed. Example: { "name": "Test_User" }
228
+ * @property {int} limit The max number of results to delete.
229
+ */
230
+
231
+ /**
232
+ * The remove method.
233
+ *
234
+ * @param {DATA_REMOVE_JSON_OBJECT_TYPE} jsonObj
235
+ *
236
+ * @returns {string} Returns true if successful.
237
+ */
238
+ remove (jsonObj)
239
+ {
240
+ var promise = new Promise ((resolve, reject) =>
241
+ {
242
+ const url = `${this.baseUrl}/v1/data/remove`;
243
+ const auth = null;
244
+
245
+ if (this.authorization != null)
246
+ {
247
+ if (this.authorization.toAuthorizationHeaderString != null)
248
+ auth = this.authorization.toAuthorizationHeaderString ();
249
+ }
250
+
251
+
252
+ jsonObj = HotStaqProcessJSONObject (jsonObj);
253
+ HotStaqPostJSONObject ("POST", url, jsonObj, auth).then (
254
+ function (response)
255
+ {
256
+ var result = response.json ();
257
+
258
+ resolve (result);
259
+ });
260
+ });
261
+
262
+ return (promise);
263
+ }
264
+
179
265
  /**
180
266
  * The JSON object to send to the server.
181
267
  *
182
268
  * @typedef {Object} DATA_LIST_JSON_OBJECT_TYPE
183
269
  * @property {string} schema The schema to access.
270
+ * @property {array} whereFields The where fields and their values to select from the database. A key/value object must be passed. Example: { "name": "Test_User" }
184
271
  * @property {array} fields The list of fields in the schema to access.
185
272
  * @property {int} offset The offset.
186
273
  * @property {int} limit The max number of results to return. Default is 20.
package/package.json CHANGED
@@ -1,15 +1,15 @@
1
1
  {
2
2
  "name": "@hotstaq/admin-panel",
3
3
  "description": "",
4
- "version": "0.2.5",
5
- "main": "build/src/AppAPI.js",
4
+ "version": "0.2.7",
5
+ "main": "build/index.js",
6
6
  "scripts": {
7
7
  "start": "hotstaq --hotsite ./HotSite.json --env-file ./.env run --server-type web-api",
8
8
  "dev": "hotstaq --hotsite ./HotSite.json --development-mode run --server-type web-api --web-http-port 8080",
9
- "test": "hotstaq --dev --env-file .env run --server-type web-api",
9
+ "test": "hotstaq --dev --env-file .env run --server-type web-api --web-test",
10
10
  "build": "tsc --build ./tsconfig.json",
11
- "build-web": "hotstaq create --copy-libraries-to-location ./public/js/ app && hotstaq module build && webpack --mode=production && cp -f ./build-web/AdminPanelComponents.js ./public/js/AdminPanelComponents.js && hotstaq generate --copy-to ./public/js/",
12
- "build-web-debug": "hotstaq create --copy-libraries-to-location ./public/js/ app && hotstaq module build && webpack --mode=development && cp -f ./build-web/AdminPanelComponents.js ./public/js/AdminPanelComponents.js && hotstaq generate --copy-to ./public/js/",
11
+ "build-web": "npm run build && hotstaq create --copy-libraries-to-location ./public/js/ app && webpack --mode=production && cp -f ./build-web/AdminPanelComponents.js ./public/js/AdminPanelComponents.js && hotstaq module build && hotstaq generate --copy-to ./public/js/",
12
+ "build-web-debug": "npm run build && hotstaq create --copy-libraries-to-location ./public/js/ app && cp -f ./public/js/HotStaq.js ./public/js/HotStaq.min.js && webpack --mode=development && cp -f ./build-web/AdminPanelComponents.js ./public/js/AdminPanelComponents.js && hotstaq module build && hotstaq generate --copy-to ./public/js/",
13
13
  "build-doc": "hotstaq generate --generate-type openapi-3.0.0-yaml",
14
14
  "prepublishOnly": "npm run build && npm run build-web"
15
15
  },
@@ -17,16 +17,17 @@
17
17
  "author": "FreeLight, Inc",
18
18
  "license": "MIT",
19
19
  "dependencies": {
20
- "@hotstaq/dataroute": "^0.2.0",
20
+ "@hotstaq/dataroute": "^0.2.2",
21
21
  "@popperjs/core": "^2.11.6",
22
22
  "bootstrap": "^5.2.3",
23
23
  "chart.js": "^2.9.4",
24
24
  "dotenv": "^10.0.0",
25
25
  "feather-icons": "^4.29.0",
26
- "hotstaq": "^0.8.4",
26
+ "hotstaq": "^0.8.12",
27
27
  "jquery": "^3.6.3"
28
28
  },
29
29
  "devDependencies": {
30
+ "@types/bootstrap": "^5.2.6",
30
31
  "@types/express": "^4.17.13",
31
32
  "@types/formidable": "^1.2.4",
32
33
  "@types/fs-extra": "^9.0.12",
package/src/AppAPI.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { HotAPI, HotServer, HotClient, HotRoute,
2
2
  HotRouteMethod, MySQLSchema,
3
- ServerAuthorizationFunction, HotStaq, HotServerType } from "hotstaq";
3
+ ServerAuthorizationFunction, HotStaq, HotServerType, DeveloperMode, HotDBMySQL } from "hotstaq";
4
4
  import { DataRoute } from "@hotstaq/dataroute";
5
5
 
6
6
  /**
@@ -28,6 +28,59 @@ export class AppAPI extends HotAPI
28
28
  return (true);
29
29
  };
30
30
 
31
- this.addRoute (new DataRoute (this));
31
+ this.addRoute (new DataRoute (this, async (db: HotDBMySQL) =>
32
+ {
33
+ if (this.connection.processor.mode === DeveloperMode.Development)
34
+ {
35
+ await db.query (
36
+ `create table if not exists users (
37
+ id INT(10) NOT NULL AUTO_INCREMENT,
38
+ name VARCHAR(256) DEFAULT '',
39
+ email VARCHAR(256) DEFAULT '',
40
+ password VARCHAR(256) DEFAULT '',
41
+ verified INT(1) DEFAULT '0',
42
+ registered DATETIME DEFAULT NOW(),
43
+ enabled INT(1) DEFAULT '1',
44
+ PRIMARY KEY (id)
45
+ )`);
46
+
47
+ let results: any = await db.queryOne (`select COUNT(*) from users;`);
48
+
49
+ if (results.results["COUNT(*)"] < 1)
50
+ {
51
+ let testUsers = [{
52
+ name: "John",
53
+ email: "test1@freelight.org",
54
+ password: "a867h398jdg",
55
+ verified: true
56
+ },
57
+ {
58
+ name: "Jane",
59
+ email: "test2@freelight.org",
60
+ password: "ai97w3a98w3498",
61
+ verified: true
62
+ }
63
+ ];
64
+
65
+ for (let iIdx = 0; iIdx < testUsers.length; iIdx++)
66
+ {
67
+ let testUser = testUsers[iIdx];
68
+ let verified: number = 0;
69
+
70
+ if (testUser.verified === true)
71
+ verified = 1;
72
+
73
+ let result: any = await db.query (
74
+ `INSERT INTO users (name, email, password, verified) VALUES (?, ?, ?, ?);`,
75
+ [testUser.name, testUser.email, testUser.password, verified]);
76
+
77
+ if (result.error != null)
78
+ throw new Error (result.error);
79
+
80
+ let id: number = result.results["insertId"];
81
+ }
82
+ }
83
+ }
84
+ }));
32
85
  }
33
86
  }
package/src/WebExport.ts CHANGED
@@ -1,11 +1,3 @@
1
- import { AdminButton } from "./components/admin-button";
2
- import { AdminDashboard } from "./components/admin-dashboard";
3
- import { AdminEdit } from "./components/admin-edit";
4
- import { AdminTable } from "./components/admin-table";
5
- import { AdminTableField } from "./components/admin-table-field";
6
- import { AdminTableRow } from "./components/admin-table-row";
7
- import { AdminText } from "./components/admin-text";
8
-
9
1
  async function buildAssets (): Promise<any>
10
2
  {
11
3
  return ({
@@ -19,23 +11,16 @@ async function buildAssets (): Promise<any>
19
11
  js: ["./assets/js/*.*", "./build-web/AdminPanelComponents.js"],
20
12
  componentLibrary: "AdminPanelComponentsWeb",
21
13
  components: [
22
- AdminButton,
23
- AdminDashboard,
24
- AdminEdit,
25
- AdminTable,
26
- AdminTableField,
27
- AdminTableRow,
28
- AdminText]
14
+ "AdminButton",
15
+ "AdminDashboard",
16
+ "AdminEdit",
17
+ "AdminTable",
18
+ "AdminTableField",
19
+ "AdminTableRow",
20
+ "AdminText"]
29
21
  });
30
22
  }
31
23
 
32
24
  export {
33
- buildAssets,
34
- AdminButton,
35
- AdminDashboard,
36
- AdminEdit,
37
- AdminTable,
38
- AdminTableField,
39
- AdminTableRow,
40
- AdminText
41
- };
25
+ buildAssets
26
+ };
package/src/cli.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { HotCLI } from "hotstaq";
2
2
 
3
3
  let cli: HotCLI = new HotCLI ();
4
- cli.setup (process.argv).then (async () =>
4
+ cli.setup ().then (async () =>
5
5
  {
6
- await cli.start ();
6
+ await cli.start (process.argv);
7
7
  });
@@ -9,11 +9,11 @@ export class AdminButton extends HotComponent
9
9
  this.tag = "admin-button";
10
10
  }
11
11
 
12
- async buttonClicked ()
12
+ async buttonClicked (): Promise<void>
13
13
  {
14
14
  }
15
15
 
16
- async output ()
16
+ output (): string
17
17
  {
18
18
  return (`<button id = "${this.htmlElements[0].id}" onclick = "this.buttonClicked ();"></button>`);
19
19
  }
@@ -0,0 +1,52 @@
1
+ // import { HotStaq, Hot, HotAPI, HotComponent, HotComponentOutput } from "hotstaq";
2
+
3
+ // export class AdminCheckbox extends HotComponent
4
+ // {
5
+ // /**
6
+ // * The associated database field.
7
+ // */
8
+ // field: string;
9
+
10
+ // constructor (copy: HotComponent | HotStaq, api: HotAPI)
11
+ // {
12
+ // super (copy, api);
13
+
14
+ // this.tag = "admin-checkbox";
15
+ // this.field = "";
16
+ // }
17
+
18
+ // /**
19
+ // * Corrects the placement of the text elements for modals.
20
+ // */
21
+ // onPostPlace (parentHtmlElement: HTMLElement, htmlElement: HTMLElement): HTMLElement
22
+ // {
23
+ // let placeHereArray = parentHtmlElement.querySelectorAll (`hot-place-here[type="modal"]`);
24
+
25
+ // if (placeHereArray.length > 0)
26
+ // {
27
+ // let placeHere = placeHereArray[0];
28
+ // parentHtmlElement.removeChild (htmlElement);
29
+ // placeHere.appendChild (htmlElement);
30
+
31
+ // // @ts-ignore
32
+ // parentHtmlElement.hotComponent.fieldElements[this.field] = htmlElement.querySelector ("input");
33
+ // }
34
+
35
+ // return (null);
36
+ // }
37
+
38
+ // output (): string | HotComponentOutput[]
39
+ // {
40
+ // let value: string = "";
41
+
42
+ // if (this.value != null)
43
+ // {
44
+ // if ((this.value === true) || (this.value === 1))
45
+ // value = "checked";
46
+ // }
47
+
48
+ // return (`<div>
49
+ // <label class="form-label">${this.inner}</label><input class="form-control" type = "checkbox" ${value} />
50
+ // </div>`);
51
+ // }
52
+ // }
@@ -23,15 +23,16 @@ export class AdminDashboard extends HotComponent
23
23
  /**
24
24
  * Add this table field to the table
25
25
  */
26
- // @ts-ignore
27
- async onPostPlace (parentHtmlElement: HTMLElement, htmlElement: HTMLElement): Promise<HTMLElement>
26
+ onPostPlace (parentHtmlElement: HTMLElement, htmlElement: HTMLElement): HTMLElement
28
27
  {
29
28
  // Set the base API url to use for this dashboard.
30
29
  if (this.base != "")
31
30
  Hot.Data.baseUrl = this.base;
31
+
32
+ return (null);
32
33
  }
33
34
 
34
- async output (): Promise<string>
35
+ output (): string
35
36
  {
36
37
  return (`
37
38
  <main class="col-md-9 ms-sm-auto col-lg-10 px-md-4">
@@ -1,4 +1,8 @@
1
- import { HotStaq, Hot, HotAPI, HotComponent } from "hotstaq";
1
+ import { HotStaq, Hot, HotAPI, HotComponent, HotComponentOutput } from "hotstaq";
2
+
3
+ import bootstrap from "bootstrap";
4
+
5
+ import { AdminTable } from "./admin-table";
2
6
 
3
7
  export class AdminEdit extends HotComponent
4
8
  {
@@ -26,6 +30,25 @@ export class AdminEdit extends HotComponent
26
30
  * The modal id.
27
31
  */
28
32
  modalId: string;
33
+ /**
34
+ * The bootstrap modal instance.
35
+ */
36
+ modal: bootstrap.Modal;
37
+ /**
38
+ * If set to true, this will close the modal when save is clicked.
39
+ */
40
+ closeOnSave: boolean;
41
+ /**
42
+ * The type of modal to open. Can be:
43
+ * * add
44
+ * * edit
45
+ * * remove
46
+ */
47
+ protected modalType: string;
48
+ /**
49
+ * The selected fields.
50
+ */
51
+ protected selectedFields: any[];
29
52
 
30
53
  constructor (copy: HotComponent | HotStaq, api: HotAPI)
31
54
  {
@@ -40,6 +63,130 @@ export class AdminEdit extends HotComponent
40
63
  this.fieldElements = {};
41
64
 
42
65
  this.modalId = "";
66
+ this.modal = null;
67
+ this.modalType = "add";
68
+ this.closeOnSave = true;
69
+ this.selectedFields = [];
70
+ }
71
+
72
+ /**
73
+ * The event that can be called when the add button is clicked.
74
+ * This is called before the add modal opens.
75
+ */
76
+ onAddClicked: () => Promise<boolean> = null;
77
+
78
+ /**
79
+ * Executes when the add button is clicked.
80
+ */
81
+ async addClicked (): Promise<void>
82
+ {
83
+ if (this.onAddClicked != null)
84
+ {
85
+ let result = await this.onAddClicked ();
86
+
87
+ if (result === false)
88
+ return;
89
+ }
90
+
91
+ this.modalType = "add";
92
+
93
+ // Clear the values in each field.
94
+ for (let key in this.fieldElements)
95
+ {
96
+ let fieldElement = this.fieldElements[key];
97
+
98
+ fieldElement.value = "";
99
+ }
100
+
101
+ this.selectedFields = [];
102
+
103
+ bootstrap.Modal.getInstance (`#${this.modalId}`).show ();
104
+ }
105
+
106
+ /**
107
+ * The event that can be called when the edit button is clicked.
108
+ * This is called before the edit modal opens.
109
+ */
110
+ onEditClicked: () => Promise<boolean> = null;
111
+
112
+ /**
113
+ * Executes when the edit button is clicked.
114
+ */
115
+ async editClicked (): Promise<void>
116
+ {
117
+ if (this.onEditClicked != null)
118
+ {
119
+ let result = await this.onEditClicked ();
120
+
121
+ if (result === false)
122
+ return;
123
+ }
124
+
125
+ this.modalType = "edit";
126
+ let attachedList = document.getElementById (this.attached_list);
127
+
128
+ // @ts-ignore
129
+ let hotComponent: AdminTable = attachedList.hotComponent;
130
+ let selectedField = hotComponent.getSelected ();
131
+
132
+ if (selectedField != null)
133
+ {
134
+ for (let key in this.fieldElements)
135
+ {
136
+ let fieldElement = this.fieldElements[key];
137
+
138
+ if (fieldElement != null)
139
+ {
140
+ // @ts-ignore
141
+ let value = selectedField[key];
142
+
143
+ fieldElement.value = value;
144
+ }
145
+ }
146
+
147
+ this.selectedFields = [selectedField];
148
+
149
+ bootstrap.Modal.getInstance (`#${this.modalId}`).show ();
150
+ }
151
+ }
152
+
153
+ /**
154
+ * The event that can be called when the remove button is clicked.
155
+ * This is called before the remove modal opens.
156
+ */
157
+ onRemoveClicked: () => Promise<boolean> = null;
158
+
159
+ /**
160
+ * Executes when the remove button is clicked.
161
+ */
162
+ async removeClicked (): Promise<void>
163
+ {
164
+ if (this.onRemoveClicked != null)
165
+ {
166
+ let result = await this.onRemoveClicked ();
167
+
168
+ if (result === false)
169
+ return;
170
+ }
171
+
172
+ this.modalType = "remove";
173
+
174
+ // @ts-ignore
175
+ let hotComponent: AdminTable = attachedList.hotComponent;
176
+ let checkedRows = hotComponent.getCheckedRows ();
177
+
178
+ if (checkedRows != null)
179
+ {
180
+ const confirmed: boolean = confirm ("Are you sure you want to remove this item?");
181
+
182
+ if (confirmed === true)
183
+ {
184
+ await Hot.jsonRequest (`${Hot.Data.baseUrl}/v1/data/remove`, {
185
+ schema: this.schema,
186
+ whereFields: checkedRows
187
+ });
188
+ }
189
+ }
43
190
  }
44
191
 
45
192
  /**
@@ -52,26 +199,89 @@ export class AdminEdit extends HotComponent
52
199
  for (let key in this.fieldElements)
53
200
  {
54
201
  let fieldElement = this.fieldElements[key];
55
- let value = fieldElement.value;
56
202
 
57
- values[key] = value;
203
+ if (fieldElement != null)
204
+ {
205
+ let value = fieldElement.value;
206
+ let fieldType: string = fieldElement.parentNode.hotComponent.field_type;
207
+
208
+ if (fieldType === "remove")
209
+ continue;
210
+
211
+ values[key] = value;
212
+ }
58
213
  }
59
214
 
60
- await Hot.jsonRequest (`${Hot.Data.baseUrl}/v1/data/add`, {
61
- schema: this.schema,
62
- fields: values
63
- });
215
+ if (this.modalType === "add")
216
+ {
217
+ await Hot.jsonRequest (`${Hot.Data.baseUrl}/v1/data/add`, {
218
+ schema: this.schema,
219
+ fields: values
220
+ });
221
+ }
64
222
 
65
- let attachedList = document.getElementById (this.attached_list);
223
+ if (this.modalType === "edit")
224
+ {
225
+ if (this.selectedFields.length === 0)
226
+ {
227
+ alert ("No item(s) selected!");
66
228
 
67
- // @ts-ignore
68
- await attachedList.hotComponent.refreshList ();
229
+ return;
230
+ }
231
+
232
+ let selectedField = this.selectedFields[0];
233
+ let whereFields: any = {};
234
+
235
+ for (let key in selectedField)
236
+ {
237
+ let fieldElement = this.fieldElements[key];
238
+ let value = selectedField[key];
239
+
240
+ if (fieldElement != null)
241
+ {
242
+ let fieldType: string = fieldElement.parentNode.hotComponent.field_type;
243
+
244
+ if (fieldType === "remove")
245
+ continue;
246
+ }
247
+
248
+ whereFields[key] = value;
249
+ }
69
250
 
251
+ await Hot.jsonRequest (`${Hot.Data.baseUrl}/v1/data/edit`, {
252
+ schema: this.schema,
253
+ whereFields: whereFields,
254
+ fields: values
255
+ });
256
+ }
257
+
258
+ let attachedList = document.getElementById (this.attached_list);
70
259
  // @ts-ignore
71
- $(`#${this.modalId}`).modal ("hide");
260
+ let table: AdminTable = attachedList.hotComponent;
261
+
262
+ await table.refreshList ();
263
+
264
+ if (this.closeOnSave === true)
265
+ {
266
+ bootstrap.Modal.getInstance (`#${this.modalId}`).hide ();
267
+ }
268
+ }
269
+
270
+ /**
271
+ * Get the list of data from the server.
272
+ */
273
+ onPostPlace (parentHtmlElement: HTMLElement, htmlElement: HTMLElement): HTMLElement
274
+ {
275
+ this.modal = new bootstrap.Modal ($(`#${this.modalId}`)[0], {
276
+ "backdrop": true,
277
+ "keyboard": true,
278
+ "focus": true
279
+ });
280
+
281
+ return (null);
72
282
  }
73
283
 
74
- async output ()
284
+ output (): string | HotComponentOutput[]
75
285
  {
76
286
  if (this.name === "")
77
287
  throw new Error (`You must specify a name for each admin-edit element!`);
@@ -99,12 +309,19 @@ export class AdminEdit extends HotComponent
99
309
  </div>
100
310
  </div>
101
311
  <!-- ${this.title} Modal End -->`,
102
- parentSelector: "body"
312
+ documentSelector: "body"
313
+ },
314
+ {
315
+ html: `<button id = "${this.modalId}-add-btn" type="button" class="btn btn-sm btn-outline-secondary" onclick = "this.addClicked ();">Add</button>`,
316
+ documentSelector: `hot-place-here[name="buttons"]`
317
+ },
318
+ {
319
+ html: `<button id = "${this.modalId}-edit-btn" type="button" class="btn btn-sm btn-outline-secondary" onclick = "this.editClicked ();">Edit</button>`,
320
+ documentSelector: `hot-place-here[name="buttons"]`
103
321
  },
104
322
  {
105
- html: `<button id = "${this.modalId}-add-btn" type="button" class="btn btn-sm btn-outline-secondary" data-bs-toggle="modal" data-bs-target="#${this.modalId}">Add</button>`,
106
- //`<button id = "${this.modalId}-add-btn" type="button" class="btn btn-sm btn-outline-secondary" data-bs-toggle="modal" onclick = "$('#${this.modalId}').modal ('show');">Add</button>`,
107
- parentSelector: `hot-place-here[name="buttons"]`
323
+ html: `<button id = "${this.modalId}-edit-btn" type="button" class="btn btn-sm btn-outline-secondary" onclick = "this.removeClicked ();">Remove</button>`,
324
+ documentSelector: `hot-place-here[name="buttons"]`
108
325
  }]);
109
326
  }
110
327
  }
@@ -1,4 +1,4 @@
1
- import { HotStaq, Hot, HotAPI, HotComponent } from "hotstaq";
1
+ import { HotStaq, Hot, HotAPI, HotComponent, HotComponentOutput } from "hotstaq";
2
2
 
3
3
  export class AdminTableField extends HotComponent
4
4
  {
@@ -18,21 +18,22 @@ export class AdminTableField extends HotComponent
18
18
  /**
19
19
  * Add this table field to the table
20
20
  */
21
- // @ts-ignore
22
- async onPostPlace (parentHtmlElement: HTMLElement, htmlElement: HTMLElement): Promise<HTMLElement>
21
+ onPostPlace (parentHtmlElement: HTMLElement, htmlElement: HTMLElement): HTMLElement
23
22
  {
24
- // @ts-ignore
25
- let hotComponent = parentHtmlElement.parentNode.parentNode.parentNode.hotComponent;
23
+ // @ts-ignore - looool. Add a better way to get the parent HotComponent.
24
+ let hotComponent = parentHtmlElement.parentNode.parentNode.parentNode.parentNode.hotComponent;
26
25
 
27
26
  if (hotComponent != null)
28
27
  hotComponent.addHeaderDataOnly (this, htmlElement);
28
+
29
+ return (null);
29
30
  }
30
31
 
31
- async output ()
32
+ output (): string | HotComponentOutput[]
32
33
  {
33
34
  return ([{
34
35
  html: `<th>${this.inner}</th>`,
35
- placeHereParent: "header"
36
+ documentSelector: "[hot-place-here='header']"
36
37
  }]);
37
38
  }
38
39
  }