Skip to content

Commit

Permalink
DMN result columns can be referenced in the template note.
Browse files Browse the repository at this point in the history
  • Loading branch information
joleaf committed Aug 31, 2024
1 parent 8170895 commit 8ff8f22
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 26 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

All changes to this plugin are listed here.

## 0.5.0 (2024-08-31)

### New

- Reference output columns in template notes.

## 0.4.2 (2024-08-01)

### Updated
Expand Down
32 changes: 16 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,22 +48,22 @@ variables:

You can customize the view with the following parameters:

| Parameter | Description | Values |
|-----------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------|
| url | The url of the *.dmn file (required). | Relative/Absolute path, or `[[*.dmn]]` as markdown link. |
| decisionId | An ID (or Name) of a decision table to evaluate (required). | String value |
| title | An optional h1 rendered before the DMN output. | String value |
| title1 | An optional h1 rendered before the DMN output. | String value |
| title2 | An optional h2 rendered before the DMN output. | String value |
| title3 | An optional h3 rendered before the DMN output. | String value |
| title4 | An optional h4 rendered before the DMN output. | String value |
| title5 | An optional h5 rendered before the DMN output. | String value |
| title6 | An optional h6 rendered before the DMN output. | String value |
| text | An optional span text rendered before the DMN output. | String value |
| textafter | An optional span text rendered after the DMN output. | String value |
| noresultmessage | An optional message if the evaluation returns no result. | String value (Default: "No result") |
| variables | A map of variables used as input | YAML Object | - |
| template | Render the result in a template file. The template file is another Note and should contain `{{result}}` where the result of the DMN evaluation is parsed. Other variables or fontmatter data can be referred as well. Note that the `title*` and `text` are ignored. | Relative/Absolute path, or `[[...]]` as markdown link. | - |
| Parameter | Description | Values |
|-----------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------|
| url | The url of the *.dmn file (required). | Relative/Absolute path, or `[[*.dmn]]` as markdown link. |
| decisionId | An ID (or Name) of a decision table to evaluate (required). | String value |
| title | An optional h1 rendered before the DMN output. | String value |
| title1 | An optional h1 rendered before the DMN output. | String value |
| title2 | An optional h2 rendered before the DMN output. | String value |
| title3 | An optional h3 rendered before the DMN output. | String value |
| title4 | An optional h4 rendered before the DMN output. | String value |
| title5 | An optional h5 rendered before the DMN output. | String value |
| title6 | An optional h6 rendered before the DMN output. | String value |
| text | An optional span text rendered before the DMN output. | String value |
| textafter | An optional span text rendered after the DMN output. | String value |
| noresultmessage | An optional message if the evaluation returns no result. | String value (Default: "No result") |
| variables | A map of variables used as input | YAML Object | - |
| template | Render the result in a template file. The template file is another markdown file and should contain `{{result}}` where the result of the DMN evaluation is parsed. Other variables and frontmatter variables can be referenced as well (e.g., `{{variableX}}`). Furthermore, the name of the result columns of the DMN can be used to print individual values (if the DMN returns more than one column). If the DMN returns multiple rows (Hit Policy collect), than the variables can be indexed, e.g., `{{val1}}`. | Relative/Absolute path, or `[[...]]` as markdown link. | - |

### Example

Expand Down
24 changes: 19 additions & 5 deletions main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export default class ObsidianDmnEvalPlugin extends Plugin {
}
let jarPath = this.getJarPath();
const parameterCopy = parameters;
console.log(dmnParams);
// console.log(dmnParams);
exec("java -jar " + jarPath + " " + dmnParams, async (error, stdout, stderr) => {
if (error) {
console.error(`DMN error: ${error.message}`);
Expand Down Expand Up @@ -223,7 +223,7 @@ export default class ObsidianDmnEvalPlugin extends Plugin {
}
}

await MarkdownRenderer.renderMarkdown(mdContent, rootElement, mdFile.path, new Component());
await MarkdownRenderer.render(this.app, mdContent, rootElement, mdFile.path, new Component());
return true;
}
return false;
Expand All @@ -234,13 +234,16 @@ export default class ObsidianDmnEvalPlugin extends Plugin {
}

private renderSingleResultMd(line: string, mdContent: string): string {
return mdContent.replace("{{result}}", line.split("::")[1]);
const [key, value] = line.split("::");
return mdContent.replace("{{result}}", value).replace("{{" + key + "}}", value);
}

private renderResultListMd(lines: string[], mdContent: string) {
let newMdList = '';
lines.forEach(value => {
newMdList += "- " + value.split("::")[1] + '\n';
lines.forEach((line, index) => {
const [key, value] = line.split("::");
newMdList += "- " + value + '\n';
mdContent = mdContent.replace("{{" + key + (1 + index) + "}}", value);
});
return mdContent.replace("{{result}}", newMdList);
}
Expand All @@ -253,6 +256,17 @@ export default class ObsidianDmnEvalPlugin extends Plugin {
mdTable += '---|';
});
mdTable += '\n';
console.log(lines);
lines.forEach((line, index) => {
const results = line.split("||");
results.forEach(result => {
const [key, value] = result.split("::");
mdContent = mdContent.replace("{{" + key + (1 + index) + "}}", value);
if (index == 0) {
mdContent = mdContent.replace("{{" + key + "}}", value);
}
});
});

lines.forEach(line => {
mdTable += '|';
Expand Down
4 changes: 2 additions & 2 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"id": "dmn-eval",
"name": "DMN Eval",
"version": "0.4.2",
"version": "0.5.0",
"minAppVersion": "0.15.0",
"description": "This plugin enables evaluating/executing DMN",
"description": "This plugin enables evaluating DMNs in an obsidian note.",
"author": "JoLeaf",
"authorUrl": "https://github.com/JoLeaf",
"fundingUrl": "https://ko-fi.com/joleaf",
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "dmn-eval",
"version": "0.4.2",
"description": "This plugin enables evaluating/executing DMNs.",
"version": "0.5.0",
"description": "This plugin enables evaluating DMNs in an obsidian note.",
"main": "main.js",
"scripts": {
"dev": "node esbuild.config.mjs",
Expand Down
3 changes: 2 additions & 1 deletion versions.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@
"0.3.0": "0.15.0",
"0.4.0": "0.15.0",
"0.4.1": "0.15.0",
"0.4.2": "0.15.0"
"0.4.2": "0.15.0",
"0.5.0": "0.15.0"
}

0 comments on commit 8ff8f22

Please sign in to comment.