netcreateorg / netcreate-2018

Please report bugs, problems, ideas in the project Issues page: https://github.com/netcreateorg/netcreate-2018/issues
Other
11 stars 2 forks source link

TOML Template Editor #194

Closed benloh closed 2 years ago

benloh commented 2 years ago

Branch: dev-bl/toml

New Features:


To Test

We've added a few node libraries, so you'll need to run npm ci.

  1. git fetch; checkout dev-bl/toml
  2. npm ci
  3. npm run dev to load your last used database, or ./nc.js --dataset=projectname to load a specific database.

Because the system now uses a new template file, you should see this message in your terminal:

ServerDB - LOADING JSON TEMPLATE ./runtime/<projectname>.template
ServerDB - Converting JSON to TOML...

Your dataset should load, converting your old JSON template to a new TOML templamte format. You might find that your colors, node types, and edge types have changed. We'll fix all of this later.

First, let's just test the new template features:

  1. Click on the "More..." tab.
  2. Click on the new "Edit Template" tab.

You have 6 template tools you can use. Try each one. Refer to the documentation below starting at "WIKI DOCUMENTATION" (this will be copied over to the wiki).

Test Admin Access

  1. Open a browser on another computer and navigate to your server, e.g. http://192.168.1.1:3000.
  2. Make sure NetCreate loads.
  3. You should now be logged in as a regular nonAdmin user.
  4. Click on the "More..." tab
  5. Notice there are now only three tabs available: "Help", "Vocabulary", and "Import/Export". The "Edit Template" tab is not visible.
  6. Add ?admin=true to the url, e.g. http://192.168.1.1:3000?admin=true
  7. Notice the "Edit Template" tab is now available. Only administrators can edit templates, e.g. anyone using http://localhost, http://127.0.0.1, or using ?admin=true.

Other things to test:

CAVEATS / Known Problems




WIKI DOCUMENTATION

New Template Format

As of version 1.4 (this version), the new template format now uses TOML, not JSON. The TOML format is a much more human-friendly file format for settings.

The new template files have an extension of *.template.toml.

TOML files can be edited with any text editor. Visual Studio Code has an extension "Even Better TOML" that will provide syntax highlighting and linting for TOML files.

The old *.template JSON templates are no longer necessary, but you probably want to keep them as reference for converting old projects.

The old template format was much in need of a refresh, having gone through many evolutions and expanded its purpose over time. So in addition to the file format change, we also streamlined some of the configuration fields. This will require you to do some manual conversion of old template files.


Editing Templates

IMPORTANT:

To edit a template:

  1. Start NetCreate on the server
  2. Log onto NetCreate as an admin
  3. Select the "More..." tab
  4. Select the "Edit Template" tab

You can edit the current template in a variety of ways.

"Edit Node Types" / "Edit Edge Types"

Click on the "Edit Node Types" button to edit the node types defined in the current template. Click on the "Edit Edge Types" button to edit the edge types defined in the current template.

"Edit Node Types" and "Edit Edge Types" allows you to quickly edit just the node type or edge type instead of having to edit the whole current template (that's what "Edit Current Template" does). The basic functionality is the same as "Edit Current Template".

You can set:

When you are happy with the changes, click "Save". The template will be updated, the graph redrawn, and the changes written to the current template file on the server.

What happens when you change the label? The label field determines what is displayed in the popup menu for Type in the Node Editor or Edge Editor. If you change an existing label:

New "color" setting for Edge Types

"Edit Current Template"

Clicking "Edit Current Template" will open the current template in the json-editor. You can then change any value in the template, and hit "Save" to save the changes.

IMPORTANT:

Missing Properties: Use "Object Properties"

The json-editor only displays properties that have been defined in the *.template.toml file. In some cases, if for instance you've imported/converted a JSON file or created a new TOML template file from scratch, you may find that you had inadvertently ommitted a property that you would like to change. These properties will not be available in the editor for modification.

In these cases, you CAN actually add the property by clicking on the "Object Properties" button next to the header section. For instance, if you find yourself wanting to set the searchColor but it was not included in the current template, and is therefore not visible, you would:

  1. Edit Current Template
  2. Click "Object Properties" next to the main "NetCreate Tempalte" heading
  3. Scroll down and check the "searchColor" property
  4. The parameter should immediately appear in the editor (you might have to scroll down to see it)

This should only allow you to add properties that have been previously defined in the schema.

"Download Current Template"

Clicking "Download Current Template" will allow you to download the currently loaded template to a file on your local hard disk via your browser. The file will have the same name as the template file on the server.

The downloaded file is in TOML format.

You can use this to save backups or as a starting point for defining new templates.

"New Template"

Clicking "New Template" will replace the currently loaded template with a new blank template cloned from the _default.template.toml file in build/app/assets/templates/_default.template.toml. If you save the file it will be saved with the name of the current dataset. E.g. if you had tacitus.json open, and clicked "New Template" then saved the changes, you would now have a tacitus.template.toml file.

The main use model here is if you are creating a new dataset, try some changes, and decide you don't like them and want to start fresh with a new template, you can do so without quitting and restarting the app and deleting the old template file.

"Import Template"

Click "Choose File" and then select a *.template.toml file to replace the current template file with a new TOML template file.

After you import the template, the editor will be shown. Review it to make sure it's what you want. Make any changes. Then click "Save" to save the template to the server and reload the dataset with the new template.

NOTE: If you don't click "Save", the imported template will not be applied to the current dataset. You can just click "Cancel" to leave your original template as-is.

This is probably the easiest way to create a new dataset and clone the template from another dataset without restarting the server.

"Save" / "Cancel" Buttons

All of the template editors will show a "Cancel" and "Save" buttons once you've started editing.

Saves will overwrite the exisitng <projectname>.template.toml file. The previous version will be saved with a timestamp, so it should be relatively easy to revert if you need to. But we'll need to keep an eye on accumulating versions and perhaps figure out a solution for this.


SCHEMA

JSON-Editor requires a JSON schema definition in order to properly render the template for editing. The schema is defined in build/app/view/netcreate/template-logic.js. The schema is intimately tied to the internal data structures, so we do not recommend changing the schema.

Any template data that are loaded rely on the schema for validation and formatting.

This is a description of the schema.

General Template Settings

These are general settings that apply to the whole template and are saved at the root level of the data structure.

Fields

The data fields for each node and edge are defined in nodeDefs and edgeDefs.

Each Node Definition and Edge Definition field has required subfields.

The select type requires options

Options

Only for fields with type = 'select' you also need to define the options that are availabel. Each option consists of:

Built-in Fields

In addition to the custom subfields, there are a number of built-in subfields. These are in the template primarily so the author can specify the exportLabel for these fields. These fields are created automatically if they are missing. Their values are automatically set by the system.

Migrating from JSON to TOML

If you are trying to work with a circa v1.3 data set that uses the old JSON template format, here are a few tips:

1. Use Auto-Conversion

If you have a matching <projectname>.template JSON file, the app will automatically try to load the old template format and convert it to the new TOML format, saving the file as <projectname>.template.toml.

2. Manual Migration

You can of course decide to update the template files by hand. I would recommend starting with the _default.template.toml file and copying over changes from the old template rather than starting from scratch. Here's a summary of the changes in the file format.

benloh commented 2 years ago

@kalanicraig @jdanish I think the template editing is in a stable enough state for you to give it a whirl. It's definitely still rough around the edges. Please make sure you read the CAVEATS section. But let me know if this is what you had in mind.

In the mean time, I will turn towards figuring out how to handle changes to the options (e.g. combining or spiltting) and fix the edge cases.

netcreateorg commented 2 years ago

Awesome, thanks. Confirming we have seen this and have begun tinkering. Looks awesome.

benloh commented 2 years ago

@kalanicraig @jdanish Template editing is now disabled when editing a node or edge. And node or edge editing is now disabled when editing a template. Please pull the latest to test.

To Test Template/Node Edit Disabling

  1. Pull latest
  2. Start app
  3. Log in as adminstrator
  4. Click on "More..." and select "Edit Template"
  5. You should see the Template edit buttons
  6. Click on a Node in the graph.
  7. Note that the "Edit Node" button on the selected node is enabled
  8. Click on the "Edit Node" button.
  9. Note the Template buttons are now removed and a message is displayed.
  10. Click on an Edge
  11. Click on "Edit Edge"
  12. Cancel the Node edit. Note the Template buttons are still hidden.
  13. Cancel the Edge edit. Note the Template buttons are now visible.
  14. Click on "Edit Node Types"
  15. Note that editing nodes and edges is now disabled:
    • "Add New Node" is disabled
    • "Edit Node" is disabled
    • "Edit Edge" is disabled for any open Edge.
    • "Add New Edge" is disabled
  16. Click on "Save" or "Cancel" the Template edit.
  17. Note the node and edge edit buttons should now be re-enabled.

I believe this covers most of the situations. Please let me know if I missed one.

benloh commented 2 years ago

@kalanicraig @jdanish Just FYI there's a known bug in the JSON-to-TOML migration where "type" fields with options (e.g. node type, or edge type) are inadvertently converted to "strings", so the popup menu does not display in the Filters. This is fixed in da520dc1177c40b56995fc49745ce9be9f15a767 in the dev-bl/flatten branch

kalanicraig commented 2 years ago

General Display Issues

Template Guide/Form issues

Template Default issues

benloh commented 2 years ago

Node/edge table listings and node labels in graph are greyed out

This is probably a result of default transparency migration problem that Joshua and I were discussing here: https://github.com/netcreateorg/netcreate-2018/pull/198#issuecomment-1024474072

If you change the nodeDefaultTransparency to 1.0 I think this problem should be fixed for now.

But popping up a level, we do need to revisit the use of transparency. I'll create a new issue for that: #199

Is "template name" a no-space name sort of thing? Needs guidance/example akin to Template Description

This can be anything and use spaces. It is only what is displayed on-screen.
The file name is currently determined by the dataset file that you load. I'm guessing that the two of you will want to tweak some of the defaults and descriptions. Currently these are all set in template-logic.js. I'll pull out the schema so it can be easier to edit in isolation.

How does delete behavior work? Form suggests that "hideDeleteNodeButton" will hide for all non-admins and hide for regular users but it seems like it just hides/shows for anyone with an access token. The dropdown should probably be "No Delete/Admin Delete/All Users Delete" or similar.

This should be a checkbox. A lot of little details like this to be set in the schema.

The current delete behavior should be this:

So unless you were accessing the server on another computer AND did not have ?admin=true, the delete button should not have shown. If that's not the case, then something is broken.

Are you saying that you would like to enable deletion for people other than admins?

On template edit of any kind: if there are no edge colors selected, edges defaults to black. All edges should default to gray.

This might need to get resolved with #199. Currently edges default to black, but the default transparency of 0.5 lightens the line. But all of this needs to get coordinated with the transparency settings in #199. I'll try to change the default.

New template does not auto-create an "unselected" node and edge type. Is this an expected behavior

I'm fixing this right now. See https://github.com/netcreateorg/netcreate-2018/pull/198#issuecomment-1024362990

benloh commented 2 years ago

Issue: Node/Edge vs Template Edit disabling does not work over the network.

benloh commented 2 years ago

Node/Template disabling fixes are in #200. OK to merge.