Skip to content

Commit

Permalink
add to edit
Browse files Browse the repository at this point in the history
  • Loading branch information
paulthatjazz committed May 28, 2024
1 parent 4e0b82b commit 611a881
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 3 deletions.
2 changes: 2 additions & 0 deletions app/controllers/projects_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ def update
existing_source = @project.source || {}
existing_source["name"] = params.require(:project).require(:name)
existing_source["extent"] = params.require(:project).require(:extent).split(",").map(&:to_f)
existing_source["cql"] = params.require(:project).require(:cql)
existing_source["layer"] = params.require(:project).require(:layer)

if @project.update(source: existing_source)
if params[:commit] == 'Save and open project'
Expand Down
37 changes: 34 additions & 3 deletions app/views/projects/edit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@
<div id="map" style="width: 100%; height: 400px; margin-bottom: 10px;"></div>
<div id="guide" style="margin-bottom: 10px"></div>

<div class="row">
<%= f.hidden_field :layer, class: 'form-control', value: (@project.layer.present? ? @project.layer : '') %>
<%= f.hidden_field :cql, class: 'form-control', value: (@project.cql.present? ? @project.cql : '') %>
</div>


<%= link_to 'Cancel', :back, class: 'btn btn-secondary' %>
<%= f.submit 'Save and open project', class: 'btn btn-primary' %>
Expand All @@ -48,16 +53,42 @@
</div>
<script>

var extents = <%= raw @extents.to_json %>;

document.addEventListener("turbolinks:load", () =>{

var extents = <%= raw @extents.to_json %>;

const projEx = document.getElementById('PROJEDIT303')
if(!projEx) return


const hardcoded_extents = [
{ id: -1, name: "✨Wealden", value: [ -4034.29345383, 6591225.55995304, 44295.78978777, 6647418.730598 ], layer_source: "shapefiles:westminster_const", layer_cql: "Name='Wealden Co Const'" },
{ id: -2, name: "✨Brighton Pravilion", value: [ -21125.72504206, 6589221.35051539, -9227.54925854, 6602279.95570845 ], layer_source: "shapefiles:westminster_const", layer_cql: "Name='Brighton, Pavilion Boro Const'" },
]

extents = [...extents, ...hardcoded_extents]

const extent_select = document.getElementById('project_value')
if(!extent_select) return
extent_select.innerHTML = ''

extents.forEach(extent => {
const option = document.createElement('option')
option.value = extent.id
option.text = extent.name
extent_select.appendChild(option)
})

document.getElementById('project_value').addEventListener('change', () => {
const valueId = document.getElementById('project_value').value
const value = extents.find(ext => ext.id == valueId).value
const extent = value ?? [-49469.089243, 6570068.329224, 55641.379277, 6669018.450996]

// Layer and CQL for advanced extents
const layer = extents.find(ext => ext.id == valueId).layer_source || ''
const cql = extents.find(ext => ext.id == valueId).layer_cql || ''
document.getElementById('project_layer').value = layer
document.getElementById('project_cql').value = cql

document.getElementById('project_extent').value = extent.join(', ')
mapUpdate('PROJEDIT303')
})
Expand Down

0 comments on commit 611a881

Please sign in to comment.