Skip to content

Commit

Permalink
Exportable esri vector services ready to go!
Browse files Browse the repository at this point in the history
  • Loading branch information
underbluewaters committed Feb 8, 2024
1 parent 42f79f6 commit 1735e53
Show file tree
Hide file tree
Showing 18 changed files with 650 additions and 240 deletions.
1 change: 1 addition & 0 deletions packages/api/generated-schema-clean.gql
Original file line number Diff line number Diff line change
Expand Up @@ -13394,6 +13394,7 @@ type TableOfContentsItem implements Node {
ftsSimple: String
ftsSv: String
geoprocessingReferenceId: String
hasArcgisVectorLayer: Boolean
hasMetadata: Boolean
hasOriginalSourceUpload: Boolean
hideChildren: Boolean!
Expand Down
1 change: 1 addition & 0 deletions packages/api/generated-schema.gql
Original file line number Diff line number Diff line change
Expand Up @@ -13394,6 +13394,7 @@ type TableOfContentsItem implements Node {
ftsSimple: String
ftsSv: String
geoprocessingReferenceId: String
hasArcgisVectorLayer: Boolean
hasMetadata: Boolean
hasOriginalSourceUpload: Boolean
hideChildren: Boolean!
Expand Down
108 changes: 108 additions & 0 deletions packages/api/migrations/committed/000297.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
--! Previous: sha1:ab079f30cd7bd38724ad2f66c10fb1c4add93c5b
--! Hash: sha1:c66ad84cc3b4148765b9252e0ff0fb86a603d8c0

-- Enter migration here
update table_of_contents_items set enable_download = false where id = any (
select
table_of_contents_items.id
from
table_of_contents_items
join
data_layers
on
table_of_contents_items.data_layer_id = data_layers.id
join
data_sources
on
data_layers.data_source_id = data_sources.id
where
data_sources.type = 'arcgis-vector' and
table_of_contents_items.is_draft = true
);

CREATE OR REPLACE FUNCTION public.table_of_contents_items_primary_download_url(item public.table_of_contents_items) RETURNS text
LANGUAGE sql STABLE SECURITY DEFINER
AS $$
with related_data_source as (
select
*
from
data_sources
where
data_sources.id = (
select
data_layers.data_source_id
from
data_layers
where
data_layers.id = item.data_layer_id and
data_sources.type = 'arcgis-vector'
)
)
select
case
when item.enable_download = false then null
when item.data_layer_id is null then null
when item.is_folder = true then null
when (exists(select * from related_data_source)) then (
select
'https://arcgis-export.seasketch.org/?download=' || item.title || '&location=' || url
from
related_data_source
limit 1
)
else (
select
data_upload_outputs.url || '?download=' || data_upload_outputs.original_filename
from
data_upload_outputs
where
data_upload_outputs.data_source_id = (
select
data_layers.data_source_id
from
data_layers
where
data_layers.id = item.data_layer_id
)
and
data_upload_outputs.is_original = true
limit 1
)
end;
$$;

create or replace function table_of_contents_items_has_arcgis_vector_layer(item table_of_contents_items)
returns boolean
language sql
stable
as $$
select exists(select * from data_layers where data_layers.id = item.data_layer_id and exists(select * from data_sources where data_sources.id = data_layers.data_source_id and data_sources.type = 'arcgis-vector'));
$$;

grant execute on function table_of_contents_items_has_arcgis_vector_layer(table_of_contents_items) to anon;


create or replace function projects_downloadable_layers_count(p projects)
returns int
language sql
stable
as $$
select count(id)::int from table_of_contents_items where project_id = p.id and is_draft = true and is_folder = false and enable_download = true and (
table_of_contents_items_has_original_source_upload(table_of_contents_items.*)
or
table_of_contents_items_has_arcgis_vector_layer(table_of_contents_items.*)
);
$$;

create or replace function projects_eligable_downloadable_layers_count(p projects)
returns int
language sql
stable
as $$
select count(id)::int from table_of_contents_items where project_id = p.id and is_draft = true and is_folder = false and enable_download = false and (
table_of_contents_items_has_original_source_upload(table_of_contents_items.*)
or
table_of_contents_items_has_arcgis_vector_layer(table_of_contents_items.*)
);
$$;
116 changes: 70 additions & 46 deletions packages/api/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -10307,7 +10307,11 @@ when users request layers be displayed on the map.
CREATE FUNCTION public.projects_downloadable_layers_count(p public.projects) RETURNS integer
LANGUAGE sql STABLE
AS $$
select count(id)::int from table_of_contents_items where project_id = p.id and is_draft = true and is_folder = false and enable_download = true and table_of_contents_items_has_original_source_upload(table_of_contents_items.*);
select count(id)::int from table_of_contents_items where project_id = p.id and is_draft = true and is_folder = false and enable_download = true and (
table_of_contents_items_has_original_source_upload(table_of_contents_items.*)
or
table_of_contents_items_has_arcgis_vector_layer(table_of_contents_items.*)
);
$$;


Expand Down Expand Up @@ -10345,28 +10349,14 @@ then use the `publishTableOfContents` mutation when it is ready for end-users.
CREATE FUNCTION public.projects_eligable_downloadable_layers_count(p public.projects) RETURNS integer
LANGUAGE sql STABLE
AS $$
select count(id)::int from table_of_contents_items where project_id = p.id and is_draft = true and is_folder = false and enable_download = false and table_of_contents_items_has_original_source_upload(table_of_contents_items.*);
$$;


--
-- Name: projects_has_downloadable_layers(public.projects); Type: FUNCTION; Schema: public; Owner: -
--

CREATE FUNCTION public.projects_has_downloadable_layers(p public.projects) RETURNS boolean
LANGUAGE sql STABLE
AS $$
select count(id) > 0 from table_of_contents_items where project_id = p.id and is_draft = true and is_folder = false and enable_download = true;
select count(id)::int from table_of_contents_items where project_id = p.id and is_draft = true and is_folder = false and enable_download = false and (
table_of_contents_items_has_original_source_upload(table_of_contents_items.*)
or
table_of_contents_items_has_arcgis_vector_layer(table_of_contents_items.*)
);
$$;


--
-- Name: FUNCTION projects_has_downloadable_layers(p public.projects); Type: COMMENT; Schema: public; Owner: -
--

COMMENT ON FUNCTION public.projects_has_downloadable_layers(p public.projects) IS 'Returns true if the project has any layers that have enable_download = true. Useful when used in conjunction with set_enable_download_for_all_overlays()';


--
-- Name: projects_imported_arcgis_services(public.projects); Type: FUNCTION; Schema: public; Owner: -
--
Expand Down Expand Up @@ -13124,6 +13114,17 @@ CREATE FUNCTION public.table_of_contents_items_download_options(item public.tabl
COMMENT ON FUNCTION public.table_of_contents_items_download_options(item public.table_of_contents_items) IS '@simpleCollections only';


--
-- Name: table_of_contents_items_has_arcgis_vector_layer(public.table_of_contents_items); Type: FUNCTION; Schema: public; Owner: -
--

CREATE FUNCTION public.table_of_contents_items_has_arcgis_vector_layer(item public.table_of_contents_items) RETURNS boolean
LANGUAGE sql STABLE
AS $$
select exists(select * from data_layers where data_layers.id = item.data_layer_id and exists(select * from data_sources where data_sources.id = data_layers.data_source_id and data_sources.type = 'arcgis-vector'));
$$;


--
-- Name: table_of_contents_items_has_metadata(public.table_of_contents_items); Type: FUNCTION; Schema: public; Owner: -
--
Expand Down Expand Up @@ -13194,29 +13195,52 @@ CREATE FUNCTION public.table_of_contents_items_is_custom_gl_source(t public.tabl
CREATE FUNCTION public.table_of_contents_items_primary_download_url(item public.table_of_contents_items) RETURNS text
LANGUAGE sql STABLE SECURITY DEFINER
AS $$
with related_data_source as (
select
*
from
data_sources
where
data_sources.id = (
select
data_layers.data_source_id
from
data_layers
where
data_layers.id = item.data_layer_id and
data_sources.type = 'arcgis-vector'
)
)
select
case
when item.enable_download = false then null
when item.data_layer_id is null then null
else
(
select
when item.is_folder = true then null
when (exists(select * from related_data_source)) then (
select
'https://arcgis-export.seasketch.org/?download=' || item.title || '&location=' || url
from
related_data_source
limit 1
)
else (
select
data_upload_outputs.url || '?download=' || data_upload_outputs.original_filename
from
data_upload_outputs
where
data_upload_outputs.data_source_id = (
select
data_layers.data_source_id
from
data_layers
where
data_layers.id = item.data_layer_id
)
and
data_upload_outputs.is_original = true
limit 1
)
from
data_upload_outputs
where
data_upload_outputs.data_source_id = (
select
data_layers.data_source_id
from
data_layers
where
data_layers.id = item.data_layer_id
)
and
data_upload_outputs.is_original = true
limit 1
)
end;
$$;

Expand Down Expand Up @@ -25322,14 +25346,6 @@ REVOKE ALL ON FUNCTION public.projects_eligable_downloadable_layers_count(p publ
GRANT ALL ON FUNCTION public.projects_eligable_downloadable_layers_count(p public.projects) TO seasketch_user;


--
-- Name: FUNCTION projects_has_downloadable_layers(p public.projects); Type: ACL; Schema: public; Owner: -
--

REVOKE ALL ON FUNCTION public.projects_has_downloadable_layers(p public.projects) FROM PUBLIC;
GRANT ALL ON FUNCTION public.projects_has_downloadable_layers(p public.projects) TO seasketch_user;


--
-- Name: FUNCTION projects_imported_arcgis_services(p public.projects); Type: ACL; Schema: public; Owner: -
--
Expand Down Expand Up @@ -29015,6 +29031,14 @@ REVOKE ALL ON FUNCTION public.table_of_contents_items_download_options(item publ
GRANT ALL ON FUNCTION public.table_of_contents_items_download_options(item public.table_of_contents_items) TO anon;


--
-- Name: FUNCTION table_of_contents_items_has_arcgis_vector_layer(item public.table_of_contents_items); Type: ACL; Schema: public; Owner: -
--

REVOKE ALL ON FUNCTION public.table_of_contents_items_has_arcgis_vector_layer(item public.table_of_contents_items) FROM PUBLIC;
GRANT ALL ON FUNCTION public.table_of_contents_items_has_arcgis_vector_layer(item public.table_of_contents_items) TO anon;


--
-- Name: FUNCTION table_of_contents_items_has_metadata(toc public.table_of_contents_items); Type: ACL; Schema: public; Owner: -
--
Expand Down
42 changes: 42 additions & 0 deletions packages/client/src/admin/data/LayerTableOfContentsItemEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,48 @@ export default function LayerTableOfContentsItemEditor(
)}
</div>

{source?.type === DataSourceTypes.ArcgisVector && (
<div className="mt-5">
<div className="flex">
<div className={`flex-1 text-sm font-medium text-gray-700`}>
<Trans ns={["admin"]}>Enable data download</Trans>
</div>
<div className="flex-none">
<Switch
isToggled={
downloadEnabled === undefined
? item.enableDownload
: downloadEnabled
}
onClick={() =>
setDownloadEnabled(
!(downloadEnabled === undefined
? item.enableDownload
: downloadEnabled)
)
}
/>
</div>
</div>

<p className="text-sm text-gray-500 mt-1">
<Trans ns={["admin"]}>
If enabled, users will have the ability to download raw
feature data as a GeoJSON file. SeaSketch will extract vector
features from the service using the{" "}
<a
className="text-primary-500"
href="https://developers.arcgis.com/rest/services-reference/enterprise/query-feature-service-layer-.htm"
target="_blank"
>
ArcGIS REST API query endpoint
</a>
. Data may be cached and up to 3 hours old.
</Trans>
</p>
</div>
)}

{(source?.type === DataSourceTypes.Geojson ||
source?.type === DataSourceTypes.SeasketchVector ||
source?.type === DataSourceTypes.SeasketchMvt) && (
Expand Down
6 changes: 6 additions & 0 deletions packages/client/src/admin/data/TableOfContentsEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ import DataDownloadDefaultSettingModal from "./DataDownloadDefaultSettingModal";
import getSlug from "../../getSlug";
import { useGlobalErrorHandler } from "../../components/GlobalErrorHandler";
import useDialog from "../../components/useDialog";
import Warning from "../../components/Warning";

const LazyArcGISCartModal = React.lazy(
() =>
Expand Down Expand Up @@ -374,6 +375,11 @@ export default function TableOfContentsEditor() {
}
/>
)}
{tocQuery.error && (
<Warning level="error">
{tocQuery.error.message || "An error occurred"}
</Warning>
)}
<div
className="flex-1 overflow-y-auto p-2 px-8"
onContextMenu={(e) => e.preventDefault()}
Expand Down
2 changes: 1 addition & 1 deletion packages/client/src/components/Modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ export default function Modal(props: ModalProps) {
<Dialog.Title
tabIndex={-1}
as="h3"
className={`p-6 text-lg leading-6 font-medium text-gray-900 ${
className={`truncate p-6 text-lg leading-6 font-medium text-gray-900 ${
props.tabs !== undefined ? "pb-0" : "pb-4"
} ${
(props.tabs !== undefined || props.scrollable) &&
Expand Down
Loading

0 comments on commit 1735e53

Please sign in to comment.