Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Snapshot extents options #425

Merged
merged 3 commits into from
Sep 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions app/javascript/controllers/projects_controller.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Controller } from "stimulus"
import * as React from 'react'
import * as ReactDOM from 'react-dom'
import { ProjectEditor } from '../projects/project_editor'
import { ProjectEditor, TeamExtentData } from '../projects/project_editor'
import { Project } from "../projects/state"
import { DBModels } from "../projects/db_models"

Expand All @@ -13,8 +13,9 @@ export default class extends Controller {
projectTeamName: String,
projectDefraHedgerowPermission: Boolean,
projectKewRgb25cmPermission: Boolean,
projectExtents: Array,
backButtonPath: String,
dbModels: Object,
dbModels: Object
}

declare readonly projectIdValue: number
Expand All @@ -23,6 +24,7 @@ export default class extends Controller {
declare readonly projectTeamNameValue: string
declare readonly projectDefraHedgerowPermissionValue: boolean
declare readonly projectKewRgb25cmPermissionValue: boolean
declare readonly projectExtentsValue: Array<any>
declare readonly backButtonPathValue: string
declare readonly dbModelsValue: DBModels

Expand All @@ -41,6 +43,7 @@ export default class extends Controller {
KewRgb25cm: this.projectKewRgb25cmPermissionValue
}
}
teamExtents={this.projectExtentsValue as TeamExtentData[]}
/>,
this.element
)
Expand Down
54 changes: 37 additions & 17 deletions app/javascript/projects/analysis_panel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { GenerateChart } from './analysis_panel_tools/charts'
import './analysis_panel.css'
import { getArea } from 'ol/sphere'
import { fromExtent } from 'ol/geom/Polygon'
import { TeamExtentData } from './project_editor'

export type ChartType = "pie" | "hist" | "bar" | "kde"

Expand Down Expand Up @@ -146,6 +147,7 @@ interface AnalysisPanelProps {
layerStats: (layer: DatasetLayer | ModelOutputLayer) => BooleanTileGrid | NumericTileGrid | CategoricalTileGrid | null
currentTab: number
projectExtent: Extent
ExtentList: TeamExtentData[]
}

let dataSourceType: string = "null"
Expand All @@ -157,7 +159,7 @@ ChartTypeArray.set("NumericTileGrid", ["hist"])



export const AnalysisPanel = ({ selectedArea, setSelectedArea, setShowAP, selectedLayer, layerStats, currentTab, projectExtent }: AnalysisPanelProps) => {
export const AnalysisPanel = ({ selectedArea, setSelectedArea, setShowAP, selectedLayer, layerStats, currentTab, projectExtent, ExtentList }: AnalysisPanelProps) => {

const [chartType, setChartType] = React.useState<ChartType>()
const [chartData, setChartData] = React.useState<ChartData>()
Expand Down Expand Up @@ -364,22 +366,40 @@ export const AnalysisPanel = ({ selectedArea, setSelectedArea, setShowAP, select
</button>
</div>
<div className="modal-body">
<input
id="extent-input"
style={{width: '100%'}}
type="text"
placeholder='min x, min y, max x, max y'
onChange={(e) => {
let valid = false
const extent = e.target.value.split(',').map(Number)
valid = extent.length === 4 && extent.every((coord) => !isNaN(coord)) && extent[0] < extent[2] && extent[1] < extent[3]
if(!valid){
(document.getElementById('save-snapshot-extent-btn') as HTMLButtonElement).disabled = true
}else{
(document.getElementById('save-snapshot-extent-btn') as HTMLButtonElement).disabled = false
}
}}
/>
<div className='row'>
<div className='col-8'>
<input
id="extent-input"
style={{width: '100%'}}
type="text"
placeholder='min x, min y, max x, max y'
onChange={(e) => {
let valid = false
const extent = e.target.value.split(',').map(Number)
valid = extent.length === 4 && extent.every((coord) => !isNaN(coord)) && extent[0] < extent[2] && extent[1] < extent[3]
if(!valid){
(document.getElementById('save-snapshot-extent-btn') as HTMLButtonElement).disabled = true
}else{
(document.getElementById('save-snapshot-extent-btn') as HTMLButtonElement).disabled = false
}
}}
/>
</div>
<select onChange={(e) =>
{
const selectedIndex = Number(e.target.value)
const selectedExtent = ExtentList[selectedIndex]
if (selectedExtent) {
document.getElementById('extent-input')!.setAttribute('value', selectedExtent.value.join(','))
}
}}
className='form-select'>
<option value=''>Select project extent</option>
{ExtentList.map((extent, index) => (
<option key={index} value={index}>{extent.name}</option>
))}
</select>
</div>
</div>
<div className="modal-footer">
<button type="button" className="btn btn-secondary" data-dismiss="modal">Close</button>
Expand Down
9 changes: 8 additions & 1 deletion app/javascript/projects/project_editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ export interface ProjectPermissions {
KewRgb25cm: boolean
}

export interface TeamExtentData {
name: string
value: Extent
}

interface ProjectEditorProps {
projectId: number
projectSource: Project
Expand All @@ -34,8 +39,9 @@ interface ProjectEditorProps {
teamId: number
teamName: string
permissions: ProjectPermissions
teamExtents: TeamExtentData[]
}
export function ProjectEditor({ projectId, projectSource, backButtonPath, dbModels, teamId, teamName, permissions }: ProjectEditorProps) {
export function ProjectEditor({ projectId, projectSource, backButtonPath, dbModels, teamId, teamName, permissions, teamExtents }: ProjectEditorProps) {
const [state, dispatch] = React.useReducer(reduce, {
project: { ...defaultProject, ...projectSource },
hasUnsavedChanges: false,
Expand Down Expand Up @@ -194,6 +200,7 @@ export function ProjectEditor({ projectId, projectSource, backButtonPath, dbMode
}}
currentTab={currentTab}
projectExtent={projectExtent}
ExtentList={teamExtents}
/>
}
{
Expand Down
6 changes: 5 additions & 1 deletion app/models/project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def defra_hedgerow_permission
tp = team.team_permissions.find_by(permission: p)
tp ? tp.enabled : false
end

def kew_rgb25cm_permission
p = Permission.find_by(name: 'kew_rgb25cm')
puts "p: #{p}"
Expand All @@ -63,5 +63,9 @@ def kew_rgb25cm_permission
tp = team.team_permissions.find_by(permission: p)
tp ? tp.enabled : false
end

def extents
team_extents = Extent.where(team_id: team.id).to_json
end

end
1 change: 1 addition & 0 deletions app/views/projects/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
data-projects-project-source-value="<%= @project.source.to_json %>"
data-projects-project-defra-hedgerow-permission-value="<%= @project.defra_hedgerow_permission %>"
data-projects-project-kew-rgb25cm-permission-value="<%= @project.kew_rgb25cm_permission %>"
data-projects-project-extents-value="<%= @project.extents %>"
data-projects-back-button-path-value="<%= team_projects_path(@project.team) %>"
data-projects-db-models-value="<%= render partial: "defs", formats: [:json] %>"
></div>
Loading