forked from nextgis/nextgisweb
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rewrite raster layer export form to antd
- Loading branch information
Showing
8 changed files
with
137 additions
and
174 deletions.
There are no files selected for viewing
119 changes: 0 additions & 119 deletions
119
nextgisweb/raster_layer/amd/ngw-raster-layer/ExportForm.js
This file was deleted.
Oops, something went wrong.
33 changes: 0 additions & 33 deletions
33
nextgisweb/raster_layer/amd/ngw-raster-layer/template/ExportForm.hbs
This file was deleted.
Oops, something went wrong.
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
114 changes: 114 additions & 0 deletions
114
nextgisweb/raster_layer/nodepkg/export-form/ExportForm.js
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,114 @@ | ||
import settings from "@nextgisweb/pyramid/settings!raster_layer"; | ||
import { route, routeURL } from "@nextgisweb/pyramid/api"; | ||
import { Form } from "@nextgisweb/gui/antd"; | ||
import { FieldsForm, Select, useForm } from "@nextgisweb/gui/fields-form"; | ||
import { LoadingWrapper, SaveButton } from "@nextgisweb/gui/component"; | ||
import { errorModal } from "@nextgisweb/gui/error"; | ||
import { useMemo, useState, useEffect } from "react"; | ||
import i18n from "@nextgisweb/pyramid/i18n!"; | ||
|
||
const srsListToOptions = (srsList) => { | ||
return srsList.map((srs) => { | ||
return { | ||
label: srs.display_name, | ||
value: srs.id, | ||
}; | ||
}); | ||
}; | ||
|
||
const bandListToOptions = (bandList) => { | ||
return bandList.map((band, idx) => { | ||
return { | ||
label: | ||
i18n.gettext("Band") + | ||
" " + | ||
(idx + 1) + | ||
(band !== "Undefined" ? " (" + band + ")" : ""), | ||
value: idx + 1, | ||
}; | ||
}); | ||
}; | ||
|
||
export function ExportForm({ id }) { | ||
const [status, setStatus] = useState("loading"); | ||
const [srsOptions, setSrsOptions] = useState([]); | ||
const [bandOptions, setBandOptions] = useState([]); | ||
const [defaultSrs, setDefaultSrs] = useState(); | ||
const form = useForm()[0]; | ||
|
||
async function load() { | ||
try { | ||
const srsInfo = await route("spatial_ref_sys.collection").get(); | ||
const itemInfo = await route("resource.item", id).get(); | ||
setSrsOptions(srsListToOptions(srsInfo)); | ||
setBandOptions(bandListToOptions(itemInfo.raster_layer.color_interpretation)); | ||
setDefaultSrs(itemInfo.raster_layer.srs.id); | ||
} catch (err) { | ||
errorModal(err); | ||
} finally { | ||
setStatus("loaded"); | ||
} | ||
} | ||
|
||
useEffect(() => load(), []); | ||
|
||
const fields = useMemo( | ||
() => [ | ||
{ | ||
name: "format", | ||
label: i18n.gettext("Format"), | ||
widget: Select, | ||
choices: settings.export_formats.map((format) => ({ | ||
value: format.name, | ||
label: format.display_name, | ||
})), | ||
}, | ||
{ | ||
name: "srs", | ||
label: i18n.gettext("SRS"), | ||
widget: Select, | ||
choices: srsOptions, | ||
}, | ||
{ | ||
name: "bands", | ||
label: i18n.gettext("Bands"), | ||
widget: Select, | ||
mode: "multiple", | ||
choices: bandOptions, | ||
}, | ||
], | ||
[srsOptions, bandOptions] | ||
); | ||
|
||
const exportRaster = () => { | ||
const fields = form.getFieldsValue(); | ||
window.open( | ||
routeURL("resource.export", id) + | ||
"?" + | ||
new URLSearchParams(fields).toString() | ||
); | ||
}; | ||
|
||
if (status === "loading") { | ||
return <LoadingWrapper />; | ||
} | ||
|
||
return ( | ||
<FieldsForm | ||
fields={fields} | ||
form={form} | ||
initialValues={{ | ||
srs: defaultSrs, | ||
bands: bandOptions.map((band) => band.value), | ||
format: settings.export_formats[0].name, | ||
}} | ||
labelCol={{ span: 6 }} | ||
> | ||
<Form.Item> | ||
<SaveButton onClick={exportRaster} icon={null}> | ||
{i18n.gettext("Save")} | ||
</SaveButton> | ||
</Form.Item> | ||
</FieldsForm> | ||
); | ||
} |
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,3 @@ | ||
/** @entrypoint */ | ||
import { ExportForm } from "./ExportForm"; | ||
export default ExportForm; |
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,5 @@ | ||
{ | ||
"name": "@nextgisweb/raster_layer", | ||
"version": "0.0.0", | ||
"type": "module" | ||
} |
This file was deleted.
Oops, something went wrong.
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