Skip to content

Commit

Permalink
#352 [New Feature]: DrawTool - Feature Property Templates (#353)
Browse files Browse the repository at this point in the history
* #352 Templating 1

* #352 Templating 2

* #352 Templating 3

* #352 Update Modal for templating

* #352 Migrate DrawTool Templating

* #352 Templating touchups
  • Loading branch information
tariqksoliman authored Mar 29, 2023
1 parent 2e3450f commit a66c7af
Show file tree
Hide file tree
Showing 26 changed files with 2,879 additions and 488 deletions.
29 changes: 28 additions & 1 deletion API/Backend/Draw/models/userfiles.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ const attributes = {
defaultValue: "0",
unique: false,
},
template: {
type: Sequelize.JSON,
allowNull: true,
defaultValue: null,
},
};

const options = {
Expand Down Expand Up @@ -128,5 +133,27 @@ const makeMasterFiles = (intents) => {
}
};

// Adds to the table, never removes
const up = async () => {
// template column
await sequelize
.query(
`ALTER TABLE user_files ADD COLUMN IF NOT EXISTS template json NULL;`
)
.then(() => {
return null;
})
.catch((err) => {
logger(
"error",
`Failed to adding user_files.template column. DB tables may be out of sync!`,
"user_files",
null,
err
);
return null;
});
};

// export User model for use in other files.
module.exports = { Userfiles, UserfilesTEST, makeMasterFiles };
module.exports = { Userfiles, UserfilesTEST, makeMasterFiles, up };
6 changes: 6 additions & 0 deletions API/Backend/Draw/routes/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ router.post("/make", function (req, res, next) {
intent: req.body.intent,
public: "1",
hidden: "0",
template: req.body.template ? JSON.parse(req.body.template) : null,
};

// Insert new userfile into the user_files table
Expand Down Expand Up @@ -424,6 +425,11 @@ router.post("/change", function (req, res, next) {
) {
toUpdateTo.public = req.body.public;
}
if (req.body.hasOwnProperty("template") && req.body.template != null) {
try {
toUpdateTo.template = JSON.parse(req.body.template);
} catch (err) {}
}

let updateObj = {
where: {
Expand Down
4 changes: 4 additions & 0 deletions API/Backend/Draw/setup.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const routeFiles = require("./routes/files");
const routerFiles = routeFiles.router;
const routerDraw = require("./routes/draw").router;
const ufiles = require("./models/userfiles");

let setup = {
//Once the app initializes
Expand All @@ -27,6 +28,9 @@ let setup = {
onceStarted: (s) => {},
//Once all tables sync
onceSynced: (s) => {
if (typeof ufiles.up === "function") {
ufiles.up();
}
routeFiles.makeMasterFiles([
"roi",
"campaign",
Expand Down
29 changes: 22 additions & 7 deletions config/js/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -623,10 +623,7 @@ function initialize() {
) {
$("#tab_look #look_fullscreen").prop("checked", true);
}
if (
cData.look &&
(cData.look.info == true)
) {
if (cData.look && cData.look.info == true) {
$("#tab_look #look_info").prop("checked", true);
}
$("#tab_look #look_infourl").val(
Expand Down Expand Up @@ -675,6 +672,10 @@ function initialize() {
"checked",
cData.time.visible ? true : false
);
$("#tab_time #time_initiallyOpen").prop(
"checked",
cData.time.initiallyOpen ? true : false
);
}
$("#tab_time #time_format").val(
cData.time ? cData.time.format : "%Y-%m-%dT%H:%M:%SZ"
Expand Down Expand Up @@ -2181,6 +2182,11 @@ function save(returnJSON) {
} else {
json.time.visible = false;
}
if ($("#tab_time #time_initiallyOpen").prop("checked")) {
json.time.initiallyOpen = true;
} else {
json.time.initiallyOpen = false;
}
json.time.format = $("#tab_time #time_format").val();
json.time.initialstart = $("#tab_time #time_initialstart").val();
json.time.initialend = $("#tab_time #time_initialend").val();
Expand All @@ -2204,9 +2210,18 @@ function save(returnJSON) {
);
return;
}
toolsjson["variables"] = JSON.parse(
editors[tData[i].name].getValue()
);
try {
toolsjson["variables"] = JSON.parse(
editors[tData[i].name].getValue()
);
} catch (err) {
toast(
"error",
`Error: ${tData[i].name} tool json is badly formed.`,
5000
);
return;
}
}
}
json.tools.push(toolsjson);
Expand Down
6 changes: 5 additions & 1 deletion docs/pages/Configure/Tabs/Time/Time_Tab.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ This enables the user interface for Time. If disabled, global time will not be u

### Visible

Whether or not the Time user interface should be visible.
Whether or not the Time user interface should be visible. This allows time to be enabled while restricting users from using its UI.

### Initially Open

If enabled and visible, the Time UI will be initially open on the bottom of the screen.

## Time Format

Expand Down
72 changes: 69 additions & 3 deletions docs/pages/Tools/Draw/Draw.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,84 @@ There are five files that are group editable with the correct permission. The gr
"done"
],
"hoverLengthOnLines": false
"leadsCanEditFileInfo": false
"leadsCanEditFileInfo": false,
"templates": {
"example_1": [
{
"type": "slider",
"field": "a",
"min": 0,
"max": 100,
"step": 1,
"default": 0
},
{
"type": "number",
"field": "b",
"min": 0,
"max": 100,
"step": 1,
"required": true,
"default": 3
},
{
"type": "text",
"field": "c",
"minLength": 2,
"maxLength": 4,
"required": true,
"regex": null,
"default": null
},
{
"type": "textarea",
"field": "d",
"maxLength": 10,
"required": true,
"default": "hi"
},
{
"type": "checkbox",
"field": "e",
"default": true
},
{
"type": "dropdown",
"field": "f",
"items": [
"Yes",
"No",
"Maybe"
],
"default": "No"
},
{
"type": "date",
"field": "g",
"format": "YYYY-MM-DDTHH:mm:ss",
"default": "2000-01-01T00:00:00" // Can be "NOW", "STARTTIME" or "ENDTIME" too for dynamic defaults
}
],
"example_2": [
{
"type": "checkbox",
"field": "h",
"default": false
}
]
}
}
```

_"intents"_: The names in quotes will be the group file names.
_"preferredTags"_: Users can attach tags or keyword to files to organize them. Preferred Tags are curated tags and promoted over user generated ones.
_"hoverLengthOnLines"_: If true, the hover text for line features will include the total length of the line in meters.
_"leadsCanEditFileInfo"_: If true, lead roles can edit the file info, (name, description, tags, folder, make private) of any user's public file.
_"templates"_: Templates create forms for feature properties. For instance, all features in a given draw file could, in the feature's edit panel, have the field "Reviewed" be togglable via a checkbox. Users may make their own templates too but the ones configured here are promoted and cannot be delete.

## Tool Use

The Draw Tool has three panels: one for making files and controlling the intial feature creation, another for editing features and their properties, and lastly a panel for controlling the edit history. You can navigate between the panels by clicking on the icons at the top: Pencil icon (default) for panel 1, Shapes icon for panel 2, and Clock icon for panel 3.
The Draw Tool has three panels: one for making files and controlling the initial feature creation, another for editing features and their properties, and lastly a panel for controlling the edit history. You can navigate between the panels by clicking on the icons at the top: Pencil icon (default) for panel 1, Shapes icon for panel 2, and Clock icon for panel 3.

### Panels

Expand All @@ -59,7 +125,7 @@ This panel creates files, manages them, and is where you initially make features

#### Panel 2

The shapes panel shows all the currently drawn features is a list. It serves as a quick way to view, select (and group select with CTRL and SHIFT) and navigate to the cooresponding features on the map. The bottom section allows users to copy selected features to other files.
The shapes panel shows all the currently drawn features is a list. It serves as a quick way to view, select (and group select with CTRL and SHIFT) and navigate to the corresponding features on the map. The bottom section allows users to copy selected features to other files.

#### Panel 3

Expand Down
2 changes: 1 addition & 1 deletion docs/pages/Tools/Identifier/Identifier.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ parent: Tools

# Identifier

Mouse over to query underlying datasets. This will read the raw values from a georeferenced dataset, which can be any bitdepth (8,16,32). You can set up multiple file to return values from.
Mouse over to query underlying datasets. This will read the raw values from a geo-referenced dataset, which can be any bit-depth (8,16,32). You can set up multiple file to return values from.

### Raw Variables

Expand Down
52 changes: 28 additions & 24 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 0 additions & 10 deletions run/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -598,16 +598,6 @@ setups.getBackendSetups(function (setups) {
}
);

//help
app.get(
`${ROOT_PATH}/help`,
ensureUser(),
ensureGroup(permissions.users),
(req, res) => {
res.render("help", {});
}
);

// API
//TEST
app.post(`${ROOT_PATH}/api/test`, function (req, res) {
Expand Down
Loading

0 comments on commit a66c7af

Please sign in to comment.