DataTable - keep enhancement · actframework/actframework@7b55355 · GitHub
Skip to content

Commit 7b55355

Browse files
committed
DataTable - keep enhancement
1 parent a141e7f commit 7b55355

9 files changed

Lines changed: 40 additions & 10 deletions

File tree

‎legacy-testapp/pom.xml‎

Lines changed: 2 additions & 2 deletions

‎src/main/java/act/Act.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -860,7 +860,7 @@ private static void processEnvironment(AppDescriptor descriptor) {
860860
}
861861

862862
public static void registerMimeTypes() {
863-
MimeType.findByContentType("text/html").createAlias(DataTable.HTML_TABLE);
863+
MimeType.registerMimeType(DataTable.HTML_TABLE, "text/x-html-table");
864864
}
865865

866866
public static void registerTypeConverters() {

‎src/main/java/act/app/util/SimpleRestfulServiceBase.java‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,13 @@ public SimpleRestfulServiceBase(DAO_TYPE dao) {
6565
this.dao = $.requireNotNull(dao);
6666
}
6767

68+
@Before
69+
public void setPropertySpec(String _propSpec) {
70+
if ($.bool(_propSpec)) {
71+
PropertySpec.current.set(_propSpec);
72+
}
73+
}
74+
6875
/**
6976
* Sub type can override this method to update the query `q` to ensure
7077
* the returned data list is only accessible to the current login user.
@@ -176,6 +183,7 @@ protected void onDeletingEntity(MODEL_TYPE entity) {}
176183
* @return ${MODEL_TYPE} records as specified above.
177184
*/
178185
@GetAction
186+
@PropertySpec("-idAsStr,-v")
179187
public Iterable<MODEL_TYPE> list(int _page, int _pageSize, String _orderBy) {
180188
E.illegalArgumentIf(_page < 0, "page number is less than zero");
181189
E.illegalArgumentIf(_pageSize < 0, "page size is less than zero");
@@ -198,6 +206,7 @@ public Iterable<MODEL_TYPE> list(int _page, int _pageSize, String _orderBy) {
198206
* @return a ${MODEL_TYPE} record specified by URL path variable `model`
199207
*/
200208
@GetAction("{entity}")
209+
@PropertySpec("-idAsStr,-v")
201210
public MODEL_TYPE get(@DbBind MODEL_TYPE entity) {
202211
onGettingEntity(entity);
203212
return entity;

‎src/main/java/act/controller/Controller.java‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1987,7 +1987,16 @@ public static Result inferResult(HandlerMethodMetaInfo meta, Object v, ActionCon
19871987
}
19881988
context.renderArg("table", dataTable);
19891989
if (fullPage) {
1990-
context.renderArg("title", "Data table - " + context.handlerMethod().getName());
1990+
String s = context.actionPath();
1991+
if (s.contains(".")) {
1992+
String methodName = S.cut(s).afterLast(".");
1993+
String className = S.cut(s).beforeLast(".");
1994+
if (className.contains(".")) {
1995+
className = S.cut(className).afterLast(".");
1996+
}
1997+
s = S.concat(className, ".", methodName);
1998+
}
1999+
context.renderArg("title", s);
19912000
}
19922001
req.accept(H.Format.HTML);
19932002
return RenderTemplate.get();

‎src/main/java/act/handler/builtin/controller/impl/ReflectedHandlerInvoker.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -890,7 +890,7 @@ private Class[] paramTypes(App app) {
890890
}
891891

892892
private void processForceResponse(ActionContext actionContext) {
893-
if (null != forceResponseContentType) {
893+
if (null != forceResponseContentType && $.not(actionContext.paramVal("_accept"))) {
894894
actionContext.accept(forceResponseContentType);
895895
}
896896
if (null != forceResponseStatus) {

‎src/main/java/act/util/DataTable.java‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,11 @@ private void initRows(Object data) {
314314
rowCount = col.size();
315315
rows = col;
316316
} else if (data instanceof Iterable) {
317+
Iterable iterable = $.cast(data);
318+
if (iterable.iterator() == iterable) {
319+
initRows(C.list(iterable));
320+
return;
321+
}
317322
rows = $.cast(data);
318323
rowCount = -1;
319324
} else {
@@ -346,7 +351,7 @@ private void initHeading(Object data, PropertySpec.MetaInfo colSpec) {
346351
}
347352
}
348353
if (null == labelLookup) {
349-
setLabelLookup(C.<String, String>Map());
354+
setLabelLookup(C.<String, String>newMap());
350355
}
351356
// explore data rows to probe fields
352357
E.illegalArgumentIf(0 == rowCount, "Unable to probe table heading: no data found");

‎src/main/resources/asset/~act/css/act_data_table.css‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
table.act_data_table {
22
border-collapse: collapse;
33
font-size: 11pt;
4+
font-family: cousine, "Droid Sans Mono Dotted", "Envy Code R", "Fira Code", Monaco, monospaced;
45
}
56
table.act_data_table th {
67
background-color: #007;
@@ -19,4 +20,8 @@ table.act_data_table td {
1920
}
2021
.act_data_table_left {
2122
text-align: left
22-
}
23+
}
24+
table.act_data_table pre {
25+
margin: 0;
26+
font-family: cousine, "Droid Sans Mono Dotted", "Envy Code R", "Fira Code", Monaco, monospaced;
27+
}

‎src/main/resources/rythm/~table.html‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!DOCTYPE html>
2-
@import act.util.DataTable, org.osgl.Lang
2+
@import act.util.DataTable, org.osgl.Lang, org.osgl.util.S
33
@args DataTable table
44
<table class="act_data_table">
55
<thead>
@@ -26,7 +26,9 @@
2626
@def String toString(Object v) {
2727
if (null == v) return "";
2828
if (!Lang.isSimpleType(v.getClass())) {
29-
return "<pre>" + com.alibaba.fastjson.JSON.toJSONString(v, true) + "</pre>";
29+
String s = com.alibaba.fastjson.JSON.toJSONString(v, true);
30+
s = S.strip(s).of(S.DOUBLE_QUOTES);
31+
return "<pre>" + s + "</pre>";
3032
}
3133
return v.toString();
3234
}

‎testapps/GHIssues/src/main/java/ghissues/Gh1104.java‎

Lines changed: 1 addition & 1 deletion

0 commit comments

Comments
 (0)