Skip to content

Commit aa8ae1c

Browse files
committed
feat: general improvements
1 parent 8040061 commit aa8ae1c

5 files changed

Lines changed: 52 additions & 11 deletions

File tree

src/WebExpress.WebApp.Test/WebControl/UnitTestControlWebAppContent.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ public void Id(string id, string expected)
3030
// test execution
3131
var html = control.Render(context, visualTree);
3232

33+
// validation
3334
AssertExtensions.EqualWithPlaceholders(expected, html);
3435
}
3536
}

src/WebExpress.WebApp/Assets/js/webexpress.webapp.modalform.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,10 @@ webexpress.webapp.ModalFormCtrl = class extends webexpress.webui.ModalFormCtrl {
88

99
/**
1010
* Constructor
11-
* @param {HTMLElement} element - The DOM element associated with the modal control.
1211
*/
13-
constructor(form) {
12+
constructor() {
1413
super(document.createElement("div"));
1514

1615
document.body.appendChild(this._element);
17-
18-
this._selector = form;
1916
}
2017
};

src/WebExpress.WebApp/Assets/js/webexpress.webapp.table.js

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ webexpress.webapp.TableCtrl = class extends webexpress.webui.TableCtrl {
168168
this._hasOptions = true;
169169
row.options.forEach(option => {
170170
if (option.command === "edit") {
171-
option.action = () => this._editRow(row.id, option.uri);
171+
option.action = () => this._editRow(row.id, this._columns, row.cells, option.uri);
172172
}
173173
if (option.command === "delete") {
174174
option.action = () => this._deleteRow(row.id);
@@ -194,9 +194,11 @@ webexpress.webapp.TableCtrl = class extends webexpress.webui.TableCtrl {
194194
/**
195195
* Edit a row and send a PUT request to the REST API.
196196
* @param {number} rowId - The ID of the row to be edited.
197+
* @param {Array} columns - The column of the table.
198+
* @param {Array} cells - The cells of the row to be edited.
197199
* @param {string} uri - The uri for the form to be used for editing.
198200
*/
199-
_editRow(rowId, uri) {
201+
_editRow(rowId, columns, cells, uri) {
200202
const editModal = new webexpress.webapp.ModalFormCtrl();
201203
editModal._uri = uri;
202204
editModal._selector = uri?.includes("#") ? "#" + uri.split("#")[1] : "form";
@@ -211,6 +213,40 @@ webexpress.webapp.TableCtrl = class extends webexpress.webui.TableCtrl {
211213
.catch(error => console.error(`Failed to edit row with ID ${rowId}.`, error));
212214
});
213215

216+
// Fill the form fields with the row's values after the form is rendered
217+
editModal._element.addEventListener(webexpress.webui.Event.UPDATED_EVENT, (event) => {
218+
const form = event.detail.form;
219+
if (form === editModal._form) {
220+
columns.forEach((column, index) => {
221+
const value = cells[index]?.text || "";
222+
// try standard form field
223+
let field = editModal._form.elements.namedItem(column.name);
224+
if (field) {
225+
field.value = value;
226+
} else {
227+
const editorContainer = form.querySelector(`[name="${column.name}"]`);
228+
if (editorContainer) {
229+
// check which editor type is present
230+
let editorType = "default";
231+
if (editorContainer.classList.contains("wx-webui-editor")) {
232+
editorType = "wx-webui-editor";
233+
}
234+
235+
// handle various editors
236+
switch (editorType) {
237+
case "wx-webui-editor":
238+
editorContainer.innerHTML = value;
239+
break;
240+
default:
241+
// fallback: set innerHTML directly
242+
editorContainer.innerHTML = value;
243+
}
244+
}
245+
}
246+
});
247+
}
248+
});
249+
214250
editModal.show();
215251
}
216252

src/WebExpress.WebApp/WebRestApi/RestApiCrudTable.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,14 @@ public RestApiCrudTable()
4343
prop => prop,
4444
prop =>
4545
{
46-
var name = (RestTableColumnNameAttribute)Attribute.GetCustomAttribute(prop, typeof(RestTableColumnNameAttribute));
46+
var name = prop.Name;
47+
var label = (RestTableColumnNameAttribute)Attribute.GetCustomAttribute(prop, typeof(RestTableColumnNameAttribute));
4748
var isHidden = Attribute.IsDefined(prop, typeof(RestTableColumnHiddenAttribute));
4849

49-
return new RestApiCrudTableColumn(name.Name)
50+
return new RestApiCrudTableColumn()
5051
{
52+
Name = name,
53+
Label = label?.Name ?? name,
5154
Visible = !isHidden
5255
};
5356
}

src/WebExpress.WebApp/WebRestApi/RestApiCrudTableColumn.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ namespace WebExpress.WebApp.WebRestApi
77
/// </summary>
88
public class RestApiCrudTableColumn
99
{
10+
/// <summary>
11+
/// Returns or sets the name of the associated property of the item that corresponds to the column.
12+
/// </summary>
13+
[JsonPropertyName("name")]
14+
public string Name { get; set; }
15+
1016
/// <summary>
1117
/// Returns or sets a value indicating whether the element is visible.
1218
/// </summary>
@@ -40,10 +46,8 @@ public class RestApiCrudTableColumn
4046
/// <summary>
4147
/// Initializes a new instance of the class.
4248
/// </summary>
43-
/// <param name="label">The label of the column.</param>
44-
public RestApiCrudTableColumn(string label)
49+
public RestApiCrudTableColumn()
4550
{
46-
Label = label;
4751
}
4852
}
4953
}

0 commit comments

Comments
 (0)