Skip to content

Commit

Permalink
#352 Templating touchups
Browse files Browse the repository at this point in the history
  • Loading branch information
tariqksoliman committed Mar 29, 2023
1 parent 6d762d0 commit b2307a9
Show file tree
Hide file tree
Showing 12 changed files with 176 additions and 36 deletions.
10 changes: 7 additions & 3 deletions API/Backend/Draw/models/userfiles.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,12 +141,16 @@ const up = async () => {
`ALTER TABLE user_files ADD COLUMN IF NOT EXISTS template json NULL;`
)
.then(() => {
logger("info", `Added template col`, "user_files");
return null;
})
.catch((err) => {
logger("info", `template. Nothing to do...`, "user_files");

logger(
"error",
`Failed to adding user_files.template column. DB tables may be out of sync!`,
"user_files",
null,
err
);
return null;
});
};
Expand Down
9 changes: 9 additions & 0 deletions config/js/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -672,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 @@ -2178,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 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
4 changes: 2 additions & 2 deletions docs/pages/Tools/Draw/Draw.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ There are five files that are group editable with the correct permission. The gr
{
"type": "date",
"field": "g",
"format": "HH:mm:ss",
"default": "now"
"format": "YYYY-MM-DDTHH:mm:ss",
"default": "2000-01-01T00:00:00" // Can be "NOW", "STARTTIME" or "ENDTIME" too for dynamic defaults
}
],
"example_2": [
Expand Down
18 changes: 16 additions & 2 deletions src/essence/Ancillary/Coordinates.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,16 @@ const Coordinates = {
offset: [0, 20],
})

if (!(L_.configData.time && L_.configData.time.enabled === true)) {
if (
!(
L_.configData.time &&
L_.configData.time.enabled === true &&
L_.configData.time.visible === true
)
) {
$('#toggleTimeUI').css({ display: 'none' })
$('#CoordinatesDiv').css({ marginRight: '0px' })
}

if (L_.configData.coordinates) {
// ll
if (L_.configData.coordinates.coordll == false)
Expand Down Expand Up @@ -266,6 +271,15 @@ const Coordinates = {
$('#toggleTimeUI').on('click', toggleTimeUI)
Map_.map.on('mousemove', mouseLngLatMove)
Map_.map.on('click', urlClick)

if (
L_.configData.time &&
L_.configData.time.enabled === true &&
L_.configData.time.visible === true &&
L_.configData.time.initiallyOpen === true
) {
toggleTimeUI()
}
},
refreshDropdown: function () {
const names = []
Expand Down
12 changes: 11 additions & 1 deletion src/essence/Tools/Draw/DrawTool.css
Original file line number Diff line number Diff line change
Expand Up @@ -2577,10 +2577,20 @@
background: var(--color-c);
}

#cmExportGeoJSON,
#cmExportSourceGeoJSON {
display: block;
}
#cmExportGeoJSON > div:last-child,
#cmExportSourceGeoJSON > div:last-child {
font-size: 12px;
text-align: right;
}

/*FILE INFO TEMPLATE MODAL*/
#drawToolFileTemplateEditModal {
background: var(--color-a-5);
min-width: 600px;
min-width: 624px;
}
#drawToolFileTemplateEditModalTitle {
padding: 0px 0px 0px 10px;
Expand Down
25 changes: 19 additions & 6 deletions src/essence/Tools/Draw/DrawTool.js
Original file line number Diff line number Diff line change
Expand Up @@ -1187,16 +1187,29 @@ var DrawTool = {
}
}
},
enforceTemplate(geojson, templateObj) {
enforceTemplate(geojson, templateObj, force) {
if (templateObj == null || templateObj.template == null) return geojson
const templateEnforcedFeatures = []
geojson.features.forEach((f) => {
const newF = JSON.parse(JSON.stringify(f))
newF.properties = newF.properties || {}
templateObj.template.forEach((t) => {
if (!newF.properties.hasOwnProperty([t.field]))
newF.properties[t.field] = t.default
})
if (force) {
newF.properties = newF.properties || {}
const forcedTemplateProperties = {}
templateObj.template.forEach((t) => {
if (!newF.properties.hasOwnProperty([t.field]))
forcedTemplateProperties[t.field] = t.default
else
forcedTemplateProperties[t.field] =
newF.properties[t.field]
})
newF.properties = forcedTemplateProperties
} else {
newF.properties = newF.properties || {}
templateObj.template.forEach((t) => {
if (!newF.properties.hasOwnProperty([t.field]))
newF.properties[t.field] = t.default
})
}
templateEnforcedFeatures.push(newF)
})
geojson.features = templateEnforcedFeatures
Expand Down
4 changes: 2 additions & 2 deletions src/essence/Tools/Draw/DrawTool_FileModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,12 @@ const DrawTool_FileModal = {
}

const templateItems = ['NONE']
.concat(Object.keys(DrawTool.vars.templates))
.concat(Object.keys(templates))
.concat(Object.keys(allTemplates).sort())

allTemplates = {
...allTemplates,
...JSON.parse(JSON.stringify(DrawTool.vars.templates || {})),
...JSON.parse(JSON.stringify(templates || {})),
}

let body = false
Expand Down
17 changes: 14 additions & 3 deletions src/essence/Tools/Draw/DrawTool_Files.js
Original file line number Diff line number Diff line change
Expand Up @@ -531,8 +531,15 @@ var Files = {

hideContextMenu(true)

const fileId = elm.attr('file_id')
const file = DrawTool.getFileObjectWithId(fileId)

const hasTemplate = file?.template?.template != null

let rect = $(this).get(0).getBoundingClientRect()

// Export GeoJSON
// Export GeoJSON [Forced Template]
// prettier-ignore
let markup = [
"<div id='drawToolDrawFilesListElemContextMenu' style='top: " +
Expand All @@ -543,8 +550,10 @@ var Files = {
rect.width +
"px; z-index: 2000; font-size: 14px;'>",
'<ul>',
(!isHead && L_.Coordinates.mainType != 'll') ? `<li id='cmExportGeoJSON' convert='true'><i class='mdi mdi-download mdi-14px'></i>Export GeoJSON (${L_.Coordinates.getMainTypeName()})</li>` : "",
!isHead ? `<li id='cmExportSourceGeoJSON' convert='true'><i class='mdi mdi-download mdi-14px'></i>Export GeoJSON ${L_.Coordinates.mainType != 'll' ? '(lonlat)' : '' }</li>` : "",
(!isHead && L_.Coordinates.mainType != 'll') ? `<li id='cmExportGeoJSON' convert='true'><div><i class='mdi mdi-download mdi-14px'></i>Export GeoJSON</div><div>Coords: (${L_.Coordinates.getMainTypeName()})</div></li>` : "",
!isHead ? `<li id='cmExportSourceGeoJSON' convert='true'><div><i class='mdi mdi-download mdi-14px'></i>Export GeoJSON</div><div>${L_.Coordinates.mainType != 'll' ? 'Coords: lonlat' : '' }</div></li>` : "",
(!isHead && hasTemplate && L_.Coordinates.mainType != 'll') ? `<li id='cmExportGeoJSON' convert='true' templateforced='true' title='All feature properties foreign to the template will be removed.'><div><i class='mdi mdi-download mdi-14px'></i>Export GeoJSON</div><div>Restrict to Template</div></li>` : "",
(!isHead && hasTemplate) ? `<li id='cmExportSourceGeoJSON' convert='true' templateforced='true' title='All feature properties foreign to the template will be removed.'><div><i class='mdi mdi-download mdi-14px'></i>Export GeoJSON</div><div>Restrict to Template</div></li>` : "",
//"<li id='cmExportShp'>Export as .shp</li>",
(!isHead && !isPub) ? `<li id='cmToggleLabels'><i class='mdi mdi-label-outline mdi-14px'></i>Toggle Labels</li>` : "",
isHead ? `<li id='drawToolcmRenameTagFol'><i class='mdi mdi-rename-box mdi-14px'></i>Rename ${activeTagFolType === 'tags' ? "Tag" : "Folder"}</li>` : "",
Expand All @@ -569,6 +578,7 @@ var Files = {
(function (body, isPub) {
return function () {
const convert = $(this).attr('convert')
const templateForced = $(this).attr('templateforced')
DrawTool.getFile(body, function (d) {
let geojson = d.geojson
let filename = ''
Expand Down Expand Up @@ -619,7 +629,8 @@ var Files = {
)
geojson = DrawTool.enforceTemplate(
geojson,
d?.file?.[0]?.template
d?.file?.[0]?.template,
templateForced
)
F_.downloadObject(geojson, filename, '.geojson')
})
Expand Down
7 changes: 7 additions & 0 deletions src/essence/Tools/Draw/DrawTool_Templater.css
Original file line number Diff line number Diff line change
Expand Up @@ -185,18 +185,25 @@
width: 300px !important;
}

.drawToolTemplaterLiBodyDropdown_format,
.drawToolTemplaterLiType > div {
width: 150px;
height: 30px;
background: var(--color-a2);
}
.drawToolTemplaterLiBodyDropdown_format {
width: 200px;
}
.drawToolTemplaterLiBodyDropdown_format .dropy,
.drawToolTemplaterLiType > div .dropy {
margin-bottom: 0;
}
.drawToolTemplaterLiBodyDropdown_format .dropy__title,
.drawToolTemplaterLiType > div .dropy__title {
line-height: 13px;
font-size: 14px;
}
.drawToolTemplaterLiBodyDropdown_format .dropy__title > i,
.drawToolTemplaterLiType > div .dropy__title > i {
transform: translateY(30%);
}
Expand Down
Loading

0 comments on commit b2307a9

Please sign in to comment.