ontodev/nanobot.rs

Possibility to overwrite form to add row

Closed this issue · 2 comments

It's possible to overwrite the form to edit a row using a column in the table.tsv to pass the name of the new template, as shown in this block:

<td>
<a class="btn btn-sm" href="{{ table.href }}/row/{{ cell.value }}?view={{ table.edit_view or 'form' }}"><i
class="bi-pencil" style="color: #adb5bd;"></i></a>
</td>

Could this be extended to adding a row? The href would be similar to the edit part. We could use another column in table.tsv or the same as in the edit.

{% if table.table != "message" %}
<a class="btn btn-outline-success" href="{{ table.table }}?view=form">Add row</a>
{% endif %}

This is a good feature. I'll think about how I want to support this in general. I just checked that it's already possible to make this work for your own project:

  1. add an "edit_view" column to the "table" table
  2. add a corresponding entry to the "column" table
  3. change the table.html template to use "edit_view": <a class="btn btn-outline-success" href="{{ table.table }}?view={{ table.edit_view or 'form' }}">Add row</a>
  4. set "edit_view" to 'foo' for a table "bar"

When viewing the page for the "bar" table, clicking "Format" > "JSON (page, pretty)" shows you all the information that is fed into the template, including a top-level "table" key with all the values from the "bar" row of the "table" table.

In short: You can add any columns you want to the "table" table, they will appear under the "table" key, and you can use them in your template. You don't need to change Nanobot's Rust code to do any of this.

Yes, I did precisely this. I just wanted to suggest the change in the source instead of overwriting the table template only for changing the href address 😄