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

Fixes for 76 search_filters and create_spatial_views sql files #1356

Open
wants to merge 8 commits into
base: 76_upgrade
Choose a base branch
from
169 changes: 169 additions & 0 deletions arches_her/migrations/0002_move_pkg_sql.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
from django.db import migrations, models
from django.utils.translation import gettext as _


class Migration(migrations.Migration):

dependencies = [
("arches_her", "0001_initial")
]

def add_map_layers(apps, schema_editor):
MapLayer = apps.get_model("models", "MapLayer")

# Add/update map layers previously in preliminary_sql/search_overlays.sql
# Previously layers were added using random uuid1, so name is only primary identifier

existing_map = MapLayer.objects.filter(layerdefinitions__contains=[{"source":"search-results-hashes"}])
if not existing_map:
MapLayer.objects.update_or_create(
maplayerid="ede8a6af-110a-4dab-9d0b-f0eccb4cef86",
name="Search Results Heat Map",
layerdefinitions=[
{
"source": "search-results-hashes",
"paint": {
"heatmap-intensity": ["interpolate", ["linear"], ["zoom"], 0, 1, 20, 5],
"heatmap-weight": ["interpolate", ["linear"], ["get", "doc_count"], 0, 0, 6, 1],
"heatmap-color": [
"interpolate",
["linear"],
["heatmap-density"],
0,
"#ffffb2",
0.2,
"#fed976",
0.4,
"#feb24c",
0.6,
"#fd8d3c",
0.8,
"#f03b20",
0.9,
"#fff",
1,
"#bd0026",
],
"heatmap-radius": ["interpolate", ["linear"], ["zoom"], 0, 2, 9, 40, 15, 90, 20, 190],
"heatmap-opacity": 0.6,
},
"minzoom": 9,
"maxzoom": 17,
"type": "heatmap",
"id": "search-results-heat",
}
],
isoverlay=True,
icon="ion-search",
activated=True,
addtomap=False,
searchonly=True,
sortorder=0,
ispublic=True,
)

existing_map = MapLayer.objects.filter(layerdefinitions__contains=[{"source":"search-results-points"}])
if not existing_map:
MapLayer.objects.update_or_create(
maplayerid="77ec30f0-3dda-499a-a126-c67d41f7ba3a",
name="Map Markers",
layerdefinitions=[
{
"layout": {"icon-image": "marker-15", "icon-allow-overlap": True, "icon-offset": [0, -6], "icon-size": 1},
"source": "search-results-points",
"filter": ["all", ["==", "$type", "Point"], ["!=", "highlight", True]],
"paint": {},
"type": "symbol",
"id": "search-results-points-markers",
},
{
"layout": {"icon-image": "marker-15", "icon-allow-overlap": True, "icon-offset": [0, -6], "icon-size": 1.3},
"source": "search-results-points",
"filter": ["all", ["==", "$type", "Point"], ["==", "highlight", True]],
"paint": {},
"type": "symbol",
"id": "search-results-points-markers-highlighted",
},
{
"layout": {"visibility": "visible"},
"source": "search-results-points",
"filter": ["all", ["==", "$type", "Point"], ["==", "highlight", True]],
"paint": {"circle-translate": [0, -25], "circle-color": "rgba(0,0,0,0)", "circle-radius": 16},
"type": "circle",
"id": "search-results-points-markers-point-highlighted",
},
{
"layout": {"visibility": "visible"},
"source": "search-results-points",
"filter": ["all", ["==", "$type", "Point"]],
"paint": {"circle-translate": [0, -16], "circle-color": "rgba(0,0,0,0)", "circle-radius": 11},
"type": "circle",
"id": "search-results-points-markers-point",
},
],
isoverlay=True,
icon="ion-location",
activated=True,
addtomap=True,
searchonly=True,
sortorder=0,
ispublic=True,
)

existing_map = MapLayer.objects.filter(layerdefinitions__contains=[{"source":"search-results-hex"}])
if not existing_map:
MapLayer.objects.update_or_create(
maplayerid="604bd229-85ca-42db-a7ef-eb2ed81e8537",
name="Hex",
layerdefinitions=[
{
"layout": {},
"source": "search-results-hex",
"filter": ["==", "id", ""],
"paint": {
"fill-extrusion-color": "#54278f",
"fill-extrusion-height": {"property": "doc_count", "type": "exponential", "stops": [[0, 0], [500, 5000]]},
"fill-extrusion-opacity": 0.85,
},
"type": "fill-extrusion",
"id": "search-results-hex-outline-highlighted",
},
{
"layout": {},
"source": "search-results-hex",
"filter": ["all", [">", "doc_count", 0]],
"paint": {
"fill-extrusion-color": {
"property": "doc_count",
"stops": [[1, "#f2f0f7"], [5, "#cbc9e2"], [10, "#9e9ac8"], [20, "#756bb1"], [50, "#54278f"]],
},
"fill-extrusion-height": {"property": "doc_count", "type": "exponential", "stops": [[0, 0], [500, 5000]]},
"fill-extrusion-opacity": 0.5,
},
"type": "fill-extrusion",
"id": "search-results-hex",
},
],
isoverlay=True,
icon="ion-funnel",
activated=True,
addtomap=False,
searchonly=True,
sortorder=0,
ispublic=True,
)

def remove_map_layers(apps, schema_editor):
MapLayer = apps.get_model("models", "MapLayer")

for map_layers in MapLayer.objects.filter(name__in=[
"Search Results Heat Map",
"Map Markers",
"Hex"
]):
map_layers.delete()


operations = [
migrations.RunPython(add_map_layers, remove_map_layers),
]
73 changes: 73 additions & 0 deletions arches_her/migrations/0003_add_bng_search_view.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
from django.db import migrations, models
from django.utils.translation import gettext as _


class Migration(migrations.Migration):

dependencies = [
("arches_her", "0002_move_pkg_sql"),
("models", "10804_core_search_filters"),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this 10804_core_search_filters dependency may cause problems because it is already a dependency of another arches migration, 11117_add_bulk_concept_editor.

I think it should probably be changed to the last migration in arches 7.6 (11499_add_editlog_resourceinstance_idx) and moved to be the first dependency of 0002_move_pkg_sql.py. That way you finish Arches 7.6 migrations, and then resume the arches_her migrations at 0002_move_pkg_sql .

In other words, make sure Arches updates to 11499_add_editlog_resourceinstance_idx before 0002_move_pkg_sql runs, then run 0003_add_bng_search_view.

]

def add_bng_component_to_search_view(apps, scheme_editor):
SearchComponent = apps.get_model("models", "SearchComponent")

standard_search_view = SearchComponent.objects.get(searchcomponentid="69695d63-6f03-4536-8da9-841b07116381")
standard_search_view.config["linkedSearchFilters"].append(
{
"componentname": "bng-filter",
"layoutSortorder": 14,
"searchcomponentid": "25ca3536-9eb4-4fd5-b2a5-badfd9a266de"
}
)
standard_search_view.save()

def remove_bng_component_from_search_view(apps, scheme_editor):
SearchComponent = apps.get_model("models", "SearchComponent")

standard_search_view = SearchComponent.objects.get(searchcomponentid="69695d63-6f03-4536-8da9-841b07116381")
for search_filter in standard_search_view.config["linkedSearchFilters"]:
if search_filter["searchcomponentid"] == "25ca3536-9eb4-4fd5-b2a5-badfd9a266de":
standard_search_view.config["linkedSearchFilters"].remove(search_filter)
standard_search_view.save()


def apply_bng_layout_type(apps, scheme_editor):
SearchComponent = apps.get_model("models", "SearchComponent")

SearchComponent.objects.update_or_create(
searchcomponentid="25ca3536-9eb4-4fd5-b2a5-badfd9a266de",
name="BNG Filter",
icon="fa fa-compass",
modulename="bng-filter.py",
classname="BngFilter",
componentpath="views/components/search/bng-filter",
componentname="bng-filter",
defaults={
"config":{"layoutType": "popup"}, # add previous layout type into new config
"type":"bng-filter-type" # previously "popup" which has now moved
}
)

def revert_bng_layout_type(apps, scheme_editor):
SearchComponent = apps.get_model("models", "SearchComponent")

# Revert BNG search component to how it used to be
SearchComponent.objects.update_or_create(
searchcomponentid="25ca3536-9eb4-4fd5-b2a5-badfd9a266de",
name="BNG Filter",
icon="fa fa-compass",
modulename="bng-filter.py",
classname="BngFilter",
componentpath="views/components/search/bng-filter",
componentname="bng-filter",
defaults={
"config":{},
"type":"popup"
}
)

operations = [
migrations.RunPython(add_bng_component_to_search_view, remove_bng_component_from_search_view),
migrations.RunPython(apply_bng_layout_type, revert_bng_layout_type)
]
Loading
Loading