-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #383 from wearepal/hedgerow-component-and-team-per…
…misions Hedgerow component and team permissions
- Loading branch information
Showing
19 changed files
with
336 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,7 @@ import { NodeComponent } from './node_component' | |
import { SaveModel } from './modelling/components/save_model_component' | ||
import { getDatasets } from './modelling/components/dataset_component' | ||
import { Extent } from 'ol/extent' | ||
import { ProjectPermissions } from './project_editor' | ||
|
||
// Rete doesn't export `Transform`, so we have to re-define it ourselves | ||
export interface Transform { | ||
|
@@ -40,8 +41,9 @@ export interface ModelViewProps { | |
mask: boolean | ||
maskLayer: string | ||
maskCQL: string | ||
permissions: ProjectPermissions | ||
} | ||
export function ModelView({ visible, initialTransform, setTransform, initialModel, setModel, createOutputLayer, deleteOutputLayer, saveMapLayer, setProcessing, autoProcessing, process, setProcess, saveModel, getDatasets, extent, zoom, mask, maskLayer, maskCQL }: ModelViewProps) { | ||
export function ModelView({ visible, initialTransform, setTransform, initialModel, setModel, createOutputLayer, deleteOutputLayer, saveMapLayer, setProcessing, autoProcessing, process, setProcess, saveModel, getDatasets, extent, zoom, mask, maskLayer, maskCQL, permissions }: ModelViewProps) { | ||
const ref = React.useRef<HTMLDivElement>(null) | ||
const [editor, setEditor] = React.useState<NodeEditor>() | ||
const [engine, setEngine] = React.useState<Engine>() | ||
|
@@ -68,7 +70,7 @@ export function ModelView({ visible, initialTransform, setTransform, initialMode | |
}) | ||
|
||
const engine = new Engine("[email protected]") | ||
createDefaultComponents(saveMapLayer, saveModel, getDatasets, extent, zoom, mask, maskLayer, maskCQL).forEach(component => { | ||
createDefaultComponents(saveMapLayer, saveModel, getDatasets, extent, zoom, mask, maskLayer, maskCQL, permissions).forEach(component => { | ||
editor.register(component) | ||
engine.register(component) | ||
}) | ||
|
92 changes: 92 additions & 0 deletions
92
app/javascript/projects/modelling/components/hedgerow_component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
import { NodeData, WorkerInputs, WorkerOutputs } from "rete/types/core/data" | ||
import { BaseComponent } from "./base_component" | ||
import { Input, Node, Output } from 'rete' | ||
import { ProjectProperties } from "./index" | ||
import { booleanDataSocket } from "../socket_types" | ||
import { maskFromExtentAndShape } from "../bounding_box" | ||
import { retrieveModelData } from "../model_retrieval" | ||
import { createXYZ } from "ol/tilegrid" | ||
import { TypedArray } from "d3" | ||
import { BooleanTileGrid } from "../tile_grid" | ||
|
||
export class HedgerowComponent extends BaseComponent { | ||
ProjectProperties: ProjectProperties | ||
cachedHedgerows: BooleanTileGrid | ||
|
||
constructor(projectProps: ProjectProperties) { | ||
super("Hedgerows") | ||
this.category = "Inputs" | ||
this.ProjectProperties = projectProps | ||
} | ||
|
||
async builder(node: Node) { | ||
node.addOutput(new Output('out', 'Hedgerows', booleanDataSocket)) | ||
} | ||
|
||
async worker(node: NodeData, inputs: WorkerInputs, outputs: WorkerOutputs, ...args: unknown[]) { | ||
|
||
const editorNode = this.editor?.nodes.find(n => n.id === node.id) | ||
if (editorNode === undefined) { return } | ||
|
||
const mask = await maskFromExtentAndShape( | ||
this.ProjectProperties.extent, | ||
this.ProjectProperties.zoom, | ||
this.ProjectProperties.maskLayer, | ||
this.ProjectProperties.maskCQL, | ||
this.ProjectProperties.mask | ||
) | ||
|
||
if (node.outputs['out'].connections.length > 0) | ||
{ | ||
|
||
if(this.cachedHedgerows === undefined) { | ||
|
||
const tileGrid = createXYZ() | ||
const outputTileRange = tileGrid.getTileRangeForExtentAndZ( | ||
this.ProjectProperties.extent, | ||
this.ProjectProperties.zoom | ||
) | ||
const geotiff = await retrieveModelData( | ||
this.ProjectProperties.extent, | ||
'nateng:defra_lcm_hedges', | ||
outputTileRange | ||
) | ||
|
||
const rasters = await geotiff.readRasters({ | ||
bbox: this.ProjectProperties.extent, | ||
width: outputTileRange.getWidth(), | ||
height: outputTileRange.getHeight() | ||
}) | ||
|
||
const image = await geotiff.getImage() | ||
|
||
const result = new BooleanTileGrid( | ||
this.ProjectProperties.zoom, | ||
outputTileRange.minX, | ||
outputTileRange.minY, | ||
outputTileRange.getWidth(), | ||
outputTileRange.getHeight() | ||
) | ||
|
||
for (let i = 0; i < (rasters[0] as TypedArray).length; i++) { | ||
|
||
let x = (outputTileRange.minX + i % image.getWidth()) | ||
let y = (outputTileRange.minY + Math.floor(i / image.getWidth())) | ||
|
||
result.set(x, y, rasters[3][i] === 0 ? false : (mask.get(x, y) === true ? true : false)) | ||
|
||
} | ||
|
||
this.cachedHedgerows = result | ||
outputs['out'] = result | ||
|
||
}else{ | ||
|
||
outputs['out'] = this.cachedHedgerows | ||
|
||
} | ||
} | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
class Permission < ApplicationRecord | ||
has_many :team_permissions, dependent: :destroy | ||
has_many :teams, through: :team_permissions | ||
|
||
after_create :assign_to_all_teams | ||
|
||
private | ||
|
||
def assign_to_all_teams | ||
Team.all.each do |team| | ||
TeamPermission.create(team: team, permission: self, enabled: false) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.