diff --git a/afrc/media/js/views/afrc-search.js b/afrc/media/js/views/afrc-search.js new file mode 100644 index 0000000..5bfc6bb --- /dev/null +++ b/afrc/media/js/views/afrc-search.js @@ -0,0 +1,26 @@ +import createVueApplication from 'arches/arches/app/media/js/utils/create-vue-application'; + +import { definePreset } from '@primevue/themes'; +import Aura from '@primevue/themes/aura'; + +import Search from '@/afrc/Search/SearchPage.vue'; + +export function createAFRCApp() { + const EditableReportPreset = definePreset(Aura, { + components: { + toast: { + summary: { fontSize: '1.5rem' }, + detail: { fontSize: '1.25rem' }, + }, + }, + }); + + const EditableReportTheme = { + theme: { + preset: EditableReportPreset, + }, + }; + createVueApplication(Search, EditableReportTheme).then(vueApp => { + vueApp.mount('#search-mounting-point'); + }); +} \ No newline at end of file diff --git a/afrc/media/js/views/components/plugins/afrc-search-plugin.js b/afrc/media/js/views/components/plugins/afrc-search-plugin.js new file mode 100644 index 0000000..59d495e --- /dev/null +++ b/afrc/media/js/views/components/plugins/afrc-search-plugin.js @@ -0,0 +1,12 @@ +define([ + 'knockout', + 'views/afrc-search', + 'templates/views/components/plugins/afrc-search-plugin.htm', +], function(ko, AFRCSEarchComponent, AFRCSEarchTemplate) { + return ko.components.register('afrc-search-plugin', { + viewModel: function() { + AFRCSEarchComponent.createAFRCApp(); + }, + template: AFRCSEarchTemplate, + }); +}); \ No newline at end of file diff --git a/afrc/media/js/views/search.js b/afrc/media/js/views/search.js deleted file mode 100644 index 5af9874..0000000 --- a/afrc/media/js/views/search.js +++ /dev/null @@ -1,25 +0,0 @@ -import createVueApplication from 'arches/arches/app/media/js/utils/create-vue-application'; - -import { definePreset } from '@primevue/themes'; -import Aura from '@primevue/themes/aura'; - -import Search from '@/afrc/Search/SearchPage.vue'; - -const EditableReportPreset = definePreset(Aura, { - components: { - toast: { - summary: { fontSize: '1.5rem' }, - detail: { fontSize: '1.25rem' }, - }, - }, -}); - -const EditableReportTheme = { - theme: { - preset: EditableReportPreset, - }, -}; - -createVueApplication(Search, EditableReportTheme).then(vueApp => { - vueApp.mount('#search-mounting-point'); -}); diff --git a/afrc/migrations/0002_plugin.py b/afrc/migrations/0002_plugin.py new file mode 100644 index 0000000..616699f --- /dev/null +++ b/afrc/migrations/0002_plugin.py @@ -0,0 +1,30 @@ +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ("models", "11499_add_editlog_resourceinstance_idx"), + ] + + forward_sql = """ + INSERT INTO public.plugins( + pluginid, name, icon, component, componentname, config, slug, sortorder, helptemplate) + VALUES ('929e1b9b-a9dc-4603-ae0a-f129d89d8b66', + '{"en": "Search Reference Collections"}', + 'fa fa-search', + 'views/components/plugins/afrc-search-plugin', + 'afrc-search-plugin', + '{"show": true, "description": {"en": null}, "i18n_properties": ["description"]}', + 'afrc-search', + 1, + '' + ); + """ + reverse_sql = """ + DELETE FROM public.plugins WHERE pluginid = '929e1b9b-a9dc-4603-ae0a-f129d89d8b66'; + """ + + operations = [ + migrations.RunPython(forward_sql, reverse_sql), + ] diff --git a/afrc/src/afrc/Search/SearchPage.vue b/afrc/src/afrc/Search/SearchPage.vue index 0a57e34..cb1af63 100644 --- a/afrc/src/afrc/Search/SearchPage.vue +++ b/afrc/src/afrc/Search/SearchPage.vue @@ -6,21 +6,16 @@ import { useGettext } from "vue3-gettext"; import Toast from "primevue/toast"; import { useToast } from "primevue/usetoast"; import Button from "primevue/button"; -import { - DEFAULT_ERROR_TOAST_LIFE, - ERROR, -} from "@/afrc/Search/constants.ts"; +import { DEFAULT_ERROR_TOAST_LIFE, ERROR } from "@/afrc/Search/constants.ts"; + +import arches from "arches"; import SimpleSearchFilter from "@/afrc/Search/components/SimpleSearchFilter.vue"; import SearchResultItem from "@/afrc/Search/components/SearchResultItem.vue"; import InteractiveMap from "@/afrc/Search/components/InteractiveMap/InteractiveMap.vue"; import { fetchMapData } from "@/afrc/Search/api.ts"; import type { GenericObject } from "@/afrc/Search/types"; -import type { - Basemap, - MapLayer, - MapSource, -} from "@/afrc/Search/types.ts"; +import type { Basemap, MapLayer, MapSource } from "@/afrc/Search/types.ts"; let query = getQueryObject(null); let queryString = ref(JSON.stringify(query)); @@ -94,7 +89,7 @@ const doQuery = function () { const qs = new URLSearchParams(queryObj); - fetch("search/resources" + "?" + qs.toString()) + fetch(arches.urls.search_results + "?" + qs.toString()) .then((response) => response.json()) .then((data) => { console.log(data); @@ -153,18 +148,19 @@ async function fetchSystemMapData() { layer.maplayerid !== "6b9d3c6a-60a4-4630-b4f8-4c5159b68cec", ); - layers.filter((layer: MapLayer) => !layer.isoverlay).forEach((layer: MapLayer) => { - basemaps.value.push({ - name: layer.name, - active: layer.addtomap, - value: layer.name, - id: layer.name, - url: "https://tiles.openfreemap.org/styles/positron" + layers + .filter((layer: MapLayer) => !layer.isoverlay) + .forEach((layer: MapLayer) => { + basemaps.value.push({ + name: layer.name, + active: layer.addtomap, + value: layer.name, + id: layer.name, + url: "https://tiles.openfreemap.org/styles/positron", + }); }); - }); sources.value = mapData.map_sources; - } catch (error) { toast.add({ severity: ERROR, @@ -175,7 +171,7 @@ async function fetchSystemMapData() { } } -onMounted(async () =>{ +onMounted(async () => { doQuery(); await fetchSystemMapData(); dataLoaded.value = true; diff --git a/afrc/src/afrc/Search/api.ts b/afrc/src/afrc/Search/api.ts index ec01685..2654d2f 100644 --- a/afrc/src/afrc/Search/api.ts +++ b/afrc/src/afrc/Search/api.ts @@ -62,5 +62,3 @@ export const createRequest = (url: string) => { export const fetchSettings = createRequest(arches.urls["api-settings"]); export const fetchMapData = createRequest(arches.urls["api-map-data"]); - - diff --git a/afrc/src/afrc/Search/components/InteractiveMap/InteractiveMap.vue b/afrc/src/afrc/Search/components/InteractiveMap/InteractiveMap.vue index 4f2a963..2dfef91 100644 --- a/afrc/src/afrc/Search/components/InteractiveMap/InteractiveMap.vue +++ b/afrc/src/afrc/Search/components/InteractiveMap/InteractiveMap.vue @@ -12,10 +12,7 @@ import BasemapControls from "@/afrc/Search/components/InteractiveMap/components/ import { fetchSettings } from "@/afrc/Search/api.ts"; -import { - DEFAULT_ERROR_TOAST_LIFE, - ERROR, -} from "@/afrc/Search/constants.ts"; +import { DEFAULT_ERROR_TOAST_LIFE, ERROR } from "@/afrc/Search/constants.ts"; import type { Ref } from "vue"; import type { Feature, Map } from "maplibre-gl"; @@ -72,7 +69,6 @@ provide("overlays", props.overlays); provide("basemaps", props.basemaps); provide("selectedDrawnFeature", selectedDrawnFeature); - watch( () => props.basemaps, (updatedBasemaps) => { diff --git a/afrc/src/afrc/Search/components/InteractiveMap/components/InteractionsDrawer.vue b/afrc/src/afrc/Search/components/InteractiveMap/components/InteractionsDrawer.vue index 4350d5a..ed60591 100644 --- a/afrc/src/afrc/Search/components/InteractiveMap/components/InteractionsDrawer.vue +++ b/afrc/src/afrc/Search/components/InteractiveMap/components/InteractionsDrawer.vue @@ -11,10 +11,7 @@ import { import type { Component, Ref } from "vue"; import type { Map } from "maplibre-gl"; -import type { - MapInteractionItem, - Settings, -} from "@/afrc/Search/types.ts"; +import type { MapInteractionItem, Settings } from "@/afrc/Search/types.ts"; const props = defineProps<{ map: Map; diff --git a/afrc/src/afrc/Search/components/InteractiveMap/components/MapComponent.vue b/afrc/src/afrc/Search/components/InteractiveMap/components/MapComponent.vue index 1a0facf..8d6f06f 100644 --- a/afrc/src/afrc/Search/components/InteractiveMap/components/MapComponent.vue +++ b/afrc/src/afrc/Search/components/InteractiveMap/components/MapComponent.vue @@ -132,7 +132,8 @@ watch( if (selected) { updateFeatureSelection(selected as Ref); } - }, {deep: true} + }, + { deep: true }, ); watch( @@ -199,25 +200,28 @@ async function fitBoundsOfFeatures(features: FeatureCollection) { function updateFeatureSelection(selected: Ref) { const layers: Array = []; overlays.forEach((overlay) => { - layers.push(...overlay.layerdefinitions.map( - (layerDefinition) => layerDefinition.id, - )); + layers.push( + ...overlay.layerdefinitions.map( + (layerDefinition) => layerDefinition.id, + ), + ); }); - const features = map.value!.queryRenderedFeatures({layers:layers}); - features.forEach(feature => { - const featureSelected = selected.value.includes(feature.properties?.resourceinstanceid); + const features = map.value!.queryRenderedFeatures({ layers: layers }); + features.forEach((feature) => { + const featureSelected = selected.value.includes( + feature.properties?.resourceinstanceid, + ); map.value!.setFeatureState( { source: "referencecollections", sourceLayer: "referencecollections", id: feature.id, }, - { selected: featureSelected } + { selected: featureSelected }, ); }); } - function addBufferLayer() { map.value!.addSource(BUFFER_LAYER_ID, { type: "geojson", @@ -290,9 +294,7 @@ function createMap() { } function updateBasemap(basemap: Basemap) { - map.value!.setStyle( - basemap.url, - ); + map.value!.setStyle(basemap.url); map.value!.once(IDLE, () => { updateMapOverlays(overlays); @@ -384,7 +386,12 @@ function addOverlayToMap(overlay: MapLayer) { clickedCoordinates.value = [e.lngLat.lng, e.lngLat.lat]; clickedFeatures.value = features; resultsSelected.value = []; - const uniqueResourceIds = new Set(features.map((feature) => feature.properties?.resourceinstanceid as string)); + const uniqueResourceIds = new Set( + features.map( + (feature) => + feature.properties?.resourceinstanceid as string, + ), + ); resultsSelected.value = Array.from(uniqueResourceIds); } else { resultsSelected.value = []; diff --git a/afrc/src/afrc/Search/components/InteractiveMap/components/MapFilter/components/BufferControls.vue b/afrc/src/afrc/Search/components/InteractiveMap/components/MapFilter/components/BufferControls.vue index 13c8547..c94864a 100644 --- a/afrc/src/afrc/Search/components/InteractiveMap/components/MapFilter/components/BufferControls.vue +++ b/afrc/src/afrc/Search/components/InteractiveMap/components/MapFilter/components/BufferControls.vue @@ -6,10 +6,7 @@ import MapboxDraw from "@mapbox/mapbox-gl-draw"; import type { Feature, Map } from "maplibre-gl"; import type { PropType, Ref } from "vue"; -import { - DRAW_UPDATE_EVENT, - METERS, -} from "@/afrc/Search/constants.ts"; +import { DRAW_UPDATE_EVENT, METERS } from "@/afrc/Search/constants.ts"; const { $gettext } = useGettext(); diff --git a/afrc/src/afrc/Search/components/SearchResultItem.vue b/afrc/src/afrc/Search/components/SearchResultItem.vue index c7ec503..12e7f44 100644 --- a/afrc/src/afrc/Search/components/SearchResultItem.vue +++ b/afrc/src/afrc/Search/components/SearchResultItem.vue @@ -19,16 +19,17 @@ function selectResult(resourceid: string) { function clearResult() { resultsSelected.value = []; } -