Skip to content

Commit 466ecd8

Browse files
committed
default layouts for KB
dashjoin/dashjoin-aas#695
1 parent 6723772 commit 466ecd8

5 files changed

Lines changed: 130 additions & 0 deletions

File tree

dashjoin-core/src/main/java/org/dashjoin/service/PojoDatabase.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import java.util.Set;
2424
import java.util.logging.Level;
2525
import java.util.logging.Logger;
26+
import org.apache.commons.io.IOUtils;
2627
import org.dashjoin.function.AbstractConfigurableFunction;
2728
import org.dashjoin.model.AbstractDatabase;
2829
import org.dashjoin.model.Property;
@@ -350,9 +351,36 @@ public List<Map<String, Object>> query(QueryMeta qi, Map<String, Object> argumen
350351
if (qi.query.equals("Table") || qi.query.startsWith("Table/"))
351352
for (Map<String, Object> o : res)
352353
cleanTable(o);
354+
if (qi.query.equals("dj-database"))
355+
for (Map<String, Object> o : res)
356+
if ("com.dashjoin.ai.KnowledgeBase".equals(o.get("djClassName"))) {
357+
// KB default pages are different from other DBs - add defaults if not present
358+
String db = (String) o.get("name");
359+
Map<String, Map<String, Object>> t = (Map<String, Map<String, Object>>) o.get("tables");
360+
if (t != null) {
361+
Map<String, Object> tag = t.get("Tag");
362+
if (tag.get("instanceLayout") == null)
363+
tag.put("instanceLayout", template("/template/Tag/instance.json", db));
364+
if (tag.get("tableLayout") == null)
365+
tag.put("tableLayout", template("/template/Tag/table.json", db));
366+
367+
Map<String, Object> document = t.get("Document");
368+
if (document.get("instanceLayout") == null)
369+
document.put("instanceLayout", template("/template/Document/instance.json", db));
370+
if (document.get("tableLayout") == null)
371+
document.put("tableLayout", template("/template/Document/table.json", db));
372+
}
373+
}
353374
return res;
354375
}
355376

377+
Map<String, Object> template(String name, String db) throws Exception {
378+
String content = IOUtils.toString(getClass().getResourceAsStream(name), StandardCharsets.UTF_8);
379+
content = content.replace("'kb'", "'" + db + "'");
380+
content = content.replace("/kb", "/" + db);
381+
return objectMapper.readValue(content, JSONDatabase.tr);
382+
}
383+
356384
/**
357385
* remove tables that might exist in user data but no longer in the DB and on the remaining tables
358386
* call cleanTable()
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"widget": "page",
3+
"children": [
4+
{
5+
"title": "Edit Tags",
6+
"widget": "edit"
7+
},
8+
{
9+
"text": "Add new tag",
10+
"expression": "",
11+
"print": "($update('kb', 'Document', value.id, {'tags': $append(value.tags, form.tag)});$reload())",
12+
"widget": "button",
13+
"schema": {
14+
"type": "object",
15+
"properties": {
16+
"tag": {
17+
"required": true
18+
}
19+
}
20+
}
21+
},
22+
{
23+
"display": "value",
24+
"title": "Document Info",
25+
"widget": "display"
26+
}
27+
]
28+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
{
2+
"widget": "page",
3+
"children": [
4+
{
5+
"title": "Table: ${value.name}",
6+
"hideColumns": [
7+
"path"
8+
],
9+
"widget": "table"
10+
},
11+
{
12+
"title": "New Document",
13+
"widget": "create",
14+
"schema": {
15+
"type": "object",
16+
"properties": {
17+
"id": {
18+
"type": "string",
19+
"readOnly": true,
20+
"parent": "dj/kb/Document",
21+
"ID": "dj/kb/Document/id",
22+
"pkpos": 0
23+
},
24+
"tags": {
25+
"ID": "dj/kb/Document/tags",
26+
"layout": "select",
27+
"choicesVerb": "GET",
28+
"jsonata": "id",
29+
"choicesUrl": "/rest/database/crud/kb/Tag",
30+
"parent": "dj/kb/Document",
31+
"items": {
32+
"widget": "auto complete",
33+
"ref": "dj/kb/Tag/id",
34+
"type": "string"
35+
},
36+
"type": "array"
37+
},
38+
"document": {
39+
"ID": "dj/kb/Document/document",
40+
"parent": "dj/kb/Document",
41+
"widget": "binary file with metadata",
42+
"multiple": true,
43+
"required": true
44+
}
45+
}
46+
}
47+
},
48+
{
49+
"widget": "dj-table-metadata"
50+
}
51+
]
52+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"widget": "page",
3+
"children": [
4+
{
5+
"display": "($id := value.id; [$all('kb', 'Document')[$id in tags].{'ID': {'database': 'kb', 'table': 'Document', 'pk1': id}, 'tags': tags, 'text': text, 'owner': owner, 'size': size}])",
6+
"title": "Documents with this tag",
7+
"widget": "display"
8+
}
9+
]
10+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"widget": "page",
3+
"children": [
4+
{
5+
"title": "Table: ${value.name}",
6+
"widget": "table"
7+
},
8+
{
9+
"widget": "dj-table-metadata"
10+
}
11+
]
12+
}

0 commit comments

Comments
 (0)