Skip to content

Commit

Permalink
feat: publication/modification de pyramide raster en WMTS #470
Browse files Browse the repository at this point in the history
  • Loading branch information
ocruze committed Oct 22, 2024
1 parent 1a526b6 commit 4835c58
Show file tree
Hide file tree
Showing 24 changed files with 662 additions and 87 deletions.
1 change: 1 addition & 0 deletions assets/@types/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ export type Configuration = ConfigurationDetailResponseDto & {
tags: {
datasheet_name?: string;
};
pyramid?: PyramidVector | PyramidRaster;
};

export type Offering = OfferingDetailResponseDto;
Expand Down
3 changes: 2 additions & 1 deletion assets/@types/ol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import VectorLayer from "ol/layer/Vector";
import VectorTileLayer from "ol/layer/VectorTile";
import TileWMS from "ol/source/TileWMS";
import VectorSource from "ol/source/Vector";
import WMTS from "ol/source/WMTS";

export interface Capabilities {
ServiceIdentification: ServiceIdentification;
Expand Down Expand Up @@ -120,4 +121,4 @@ export interface TileMatrixEntity {
MatrixHeight: number;
}

export type LayerTypes = VectorLayer<VectorSource<Geometry>> | VectorTileLayer | TileLayer<TileWMS>;
export type LayerTypes = VectorLayer<VectorSource<Geometry>> | VectorTileLayer | TileLayer<TileWMS> | TileLayer<WMTS>;
12 changes: 6 additions & 6 deletions assets/entrepot/api/pyramidRaster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ const add = (datastoreId: string, formData: FormData | object) => {
);
};

const publishWmsRaster = (datastoreId: string, pyramidId: string, formData: FormData | object) => {
const url = SymfonyRouting.generate("cartesgouvfr_api_pyramid_raster_wms_raster_add", { datastoreId, pyramidId });
const publishWmsRasterWmts = (datastoreId: string, pyramidId: string, type: string, formData: FormData | object) => {
const url = SymfonyRouting.generate("cartesgouvfr_api_pyramid_raster_wms_raster_wmts_add", { datastoreId, pyramidId, type });
return jsonFetch<Service>(
url,
{
Expand All @@ -32,8 +32,8 @@ const publishWmsRaster = (datastoreId: string, pyramidId: string, formData: Form
);
};

const editWmsRaster = (datastoreId: string, pyramidId: string, offeringId: string, formData: FormData | object) => {
const url = SymfonyRouting.generate("cartesgouvfr_api_pyramid_raster_wms_raster_edit", { datastoreId, pyramidId, offeringId });
const editWmsRasterWmts = (datastoreId: string, pyramidId: string, offeringId: string, type: string, formData: FormData | object) => {
const url = SymfonyRouting.generate("cartesgouvfr_api_pyramid_raster_wms_raster_wmts_edit", { datastoreId, pyramidId, offeringId, type });
return jsonFetch<Service>(
url,
{
Expand All @@ -49,6 +49,6 @@ const editWmsRaster = (datastoreId: string, pyramidId: string, offeringId: strin

export default {
add,
publishWmsRaster,
editWmsRaster,
publishWmsRasterWmts,
editWmsRasterWmts: editWmsRasterWmts,
};
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,6 @@ const PyramidRasterListItem: FC<PyramidRasterListItemProps> = ({ datasheetName,
onClick={toggleShowDescription}
/>
{pyramid.name}
{pyramid.tags?.is_sample === "true" && (
<Badge noIcon={true} severity={"info"} className={fr.cx("fr-ml-2v")}>
Echantillon
</Badge>
)}
</div>
</div>

Expand Down Expand Up @@ -169,6 +164,8 @@ const PyramidRasterListItem: FC<PyramidRasterListItemProps> = ({ datasheetName,
.push();
break;
case OfferingTypeEnum.WMTSTMS:
routes.datastore_pyramid_raster_wmts_service_new({ datastoreId, pyramidId: pyramid._id, datasheetName }).push();
break;
default:
throw new Error(`Publication ${serviceType} n'est pas encore implémentée`);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,25 @@ import { fr } from "@codegouvfr/react-dsfr";
import { useQuery } from "@tanstack/react-query";
import { FC, useMemo } from "react";

import api from "../../../../api";
import type { PyramidRaster, PyramidVector, Service, VectorDb } from "../../../../../@types/app";
import { ConfigurationTypeEnum, StoredDataTypeEnum } from "../../../../../@types/app";
import LoadingText from "../../../../../components/Utils/LoadingText";
import RQKeys from "../../../../../modules/entrepot/RQKeys";
import { ConfigurationTypeEnum, PyramidVector, Service, VectorDb } from "../../../../../@types/app";
import api from "../../../../api";

type ServiceDescProps = {
service: Service;
datastoreId: string;
};
const ServiceDesc: FC<ServiceDescProps> = ({ service, datastoreId }) => {
/**
* - si le service est du type ConfigurationTypeEnum.WMTSTMS, service.configuration.type_infos.used_data?.[0].stored_data est pyramidUsedId. Il faut donc faire une autre requête pour récupérer les infos de vectorDb
* - si le service est du type ConfigurationTypeEnum.WMTSTMS ou ConfigurationTypeEnum.WMSRASTER, service.configuration.type_infos.used_data?.[0].stored_data est pyramidUsedId. Il faut donc faire une autre requête pour récupérer les infos de vectorDb
* - si le service est du type ConfigurationTypeEnum.WFS ou ConfigurationTypeEnum.WMSVECTOR, service.configuration.type_infos.used_data?.[0].stored_data est vectorDbUsedId
* - il y aura peut-être d'autres cas à gérer
*/

const pyramidUsedId = useMemo(() => {
if (service.configuration.type === ConfigurationTypeEnum.WMTSTMS) {
if ([ConfigurationTypeEnum.WMTSTMS, ConfigurationTypeEnum.WMSRASTER].includes(service.configuration.type)) {
return service.configuration.type_infos.used_data?.[0].stored_data;
}
}, [service]);
Expand All @@ -30,14 +31,14 @@ const ServiceDesc: FC<ServiceDescProps> = ({ service, datastoreId }) => {
if (pyramidUsedId === undefined) {
return Promise.reject();
}
return api.storedData.get<PyramidVector>(datastoreId, pyramidUsedId, { signal });
return api.storedData.get<PyramidVector | PyramidRaster>(datastoreId, pyramidUsedId, { signal });
},
staleTime: 600000,
enabled: !!pyramidUsedId,
});

const vectorDbUsedId = useMemo(() => {
if (service.configuration.type === ConfigurationTypeEnum.WMTSTMS) {
if ([ConfigurationTypeEnum.WMTSTMS, ConfigurationTypeEnum.WMSRASTER].includes(service.configuration.type)) {
return pyramidUsedQuery.data?.tags.vectordb_id;
} else if ([ConfigurationTypeEnum.WFS, ConfigurationTypeEnum.WMSVECTOR].includes(service.configuration.type)) {
return service.configuration.type_infos.used_data?.[0].stored_data;
Expand Down Expand Up @@ -83,7 +84,15 @@ const ServiceDesc: FC<ServiceDescProps> = ({ service, datastoreId }) => {
style={{ backgroundColor: fr.colors.decisions.background.default.grey.default }}
>
<div className={fr.cx("fr-col", "fr-col-md-4")}>
<span className={fr.cx("ri-stack-line")} /> Pyramide de tuiles vectorielles utilisée
<span className={fr.cx("ri-stack-line")} />{" "}
{(() => {
switch (pyramidUsedQuery.data.type) {
case StoredDataTypeEnum.ROK4PYRAMIDVECTOR:
return "Pyramide de tuiles vectorielles utilisée";
case StoredDataTypeEnum.ROK4PYRAMIDRASTER:
return "Pyramide de tuiles raster utilisée";
}
})()}
</div>
<div className={fr.cx("fr-col")}>
<ul className={fr.cx("fr-raw-list")}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ import { FC } from "react";
import { createPortal } from "react-dom";
import { symToStr } from "tsafe/symToStr";

import { OfferingStatusEnum, OfferingTypeEnum, StoredDataTypeEnum, type Service } from "../../../../../@types/app";
import OfferingStatusBadge from "../../../../../components/Utils/Badges/OfferingStatusBadge";
import MenuList from "../../../../../components/Utils/MenuList";
import Wait from "../../../../../components/Utils/Wait";
import useToggle from "../../../../../hooks/useToggle";
import RQKeys from "../../../../../modules/entrepot/RQKeys";
import { routes } from "../../../../../router/router";
import { useSnackbarStore } from "../../../../../stores/SnackbarStore";
import { OfferingStatusEnum, OfferingTypeEnum, type Service } from "../../../../../@types/app";
import { formatDateFromISO, offeringTypeDisplayName } from "../../../../../utils";
import api from "../../../../api";
import ServiceDesc from "./ServiceDesc";
Expand Down Expand Up @@ -154,17 +154,28 @@ const ServicesListItem: FC<ServicesListItemProps> = ({ service, datasheetName, d
}).link;

case OfferingTypeEnum.WMTSTMS:
return routes.datastore_pyramid_vector_tms_service_edit({
datastoreId,
pyramidId: service.configuration.type_infos.used_data[0].stored_data,
offeringId: service._id,
datasheetName,
}).link;
switch (service.configuration.pyramid?.type) {
case StoredDataTypeEnum.ROK4PYRAMIDVECTOR:
return routes.datastore_pyramid_vector_tms_service_edit({
datastoreId,
pyramidId: service.configuration.type_infos.used_data[0].stored_data,
offeringId: service._id,
datasheetName,
}).link;
case StoredDataTypeEnum.ROK4PYRAMIDRASTER:
return routes.datastore_pyramid_raster_wmts_service_edit({
datastoreId,
pyramidId: service.configuration.type_infos.used_data[0].stored_data,
offeringId: service._id,
datasheetName,
}).link;

default:
return routes.page_not_found().link;
}

default:
return {
onClick: () => console.warn("Action non implémentée"),
};
return routes.page_not_found().link;
}
})(),
},
Expand Down
20 changes: 17 additions & 3 deletions assets/entrepot/pages/service/default-values.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,18 @@ import { WmsVectorServiceFormValuesType } from "./wms-vector/WmsVectorServiceFor
const DEFAULT_CHARSET = "utf8";
const DEFAULT_LANGUAGE = { language: "français", code: "fre" };

export const getEndpointSuffix = (endpointType: EndpointTypeEnum) => {
export const getEndpointSuffix = (endpointType: EndpointTypeEnum | string) => {
switch (endpointType) {
case EndpointTypeEnum.WFS:
return "wfs";
case EndpointTypeEnum.WMSVECTOR:
return "wmsv";
case EndpointTypeEnum.WMSRASTER:
return "wmsr";
case EndpointTypeEnum.WMTSTMS:
case "tms":
return "tms";
case "wmts":
return "wmts";
default:
return "other"; // TODO
}
Expand Down Expand Up @@ -181,7 +183,7 @@ export const getPyramidVectorTmsServiceFormDefaultValues = (
attribution_url: offering?.configuration.attribution?.url,
};
} else {
const suffix = getEndpointSuffix(EndpointTypeEnum.WMTSTMS);
const suffix = getEndpointSuffix("tms");
const storedDataName = pyramid?.name ?? "";
const nice = removeDiacritics(storedDataName.toLowerCase()).replace(/ /g, "_");

Expand Down Expand Up @@ -214,3 +216,15 @@ export const getPyramidRasterWmsRasterServiceFormDefaultValues = (offering?: Ser
technical_name: `${nice}_${suffix}`,
};
};

export const getPyramidRasterWmtsServiceFormDefaultValues = (offering?: Service | null, editMode?: boolean, pyramid?: StoredData, metadata?: Metadata) => {
// NOTE : a priori à peu près la même chose que la publication d'une pyramide vecteur en tms
const suffix = getEndpointSuffix("wmts");
const storedDataName = pyramid?.name ?? "";
const nice = removeDiacritics(storedDataName.toLowerCase()).replace(/ /g, "_");

return {
...getPyramidVectorTmsServiceFormDefaultValues(offering, editMode, pyramid, metadata),
technical_name: `${nice}_${suffix}`,
};
};
6 changes: 4 additions & 2 deletions assets/entrepot/pages/service/view/ServiceView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Tabs, TabsProps } from "@codegouvfr/react-dsfr/Tabs";
import { useQuery } from "@tanstack/react-query";
import { FC, useEffect, useMemo, useState } from "react";

import { CartesStyle, OfferingStatusEnum, OfferingTypeEnum, Service, TypeInfosWithBbox } from "../../../../@types/app";
import { type CartesStyle, OfferingStatusEnum, OfferingTypeEnum, type Service, StoredDataTypeEnum, type TypeInfosWithBbox } from "../../../../@types/app";
import DatastoreLayout from "../../../../components/Layout/DatastoreLayout";
import LoadingText from "../../../../components/Utils/LoadingText";
import type { MapInitial } from "../../../../components/Utils/RMap";
Expand Down Expand Up @@ -63,7 +63,9 @@ const ServiceView: FC<ServiceViewProps> = ({ datastoreId, offeringId, datasheetN

// ONGLETS
const tabs: TabsProps["tabs"] = useMemo(() => {
const canManageStyles = serviceQuery.data?.type === OfferingTypeEnum.WFS || serviceQuery.data?.type === OfferingTypeEnum.WMTSTMS;
const canManageStyles =
serviceQuery.data?.type === OfferingTypeEnum.WFS ||
(serviceQuery.data?.type === OfferingTypeEnum.WMTSTMS && serviceQuery.data.configuration.pyramid?.type === StoredDataTypeEnum.ROK4PYRAMIDVECTOR);

const _tabs: TabsProps["tabs"] = [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ const PyramidRasterWmsRasterServiceForm: FC<PyramidRasterWmsRasterServiceFormPro
const createServiceMutation = useMutation<Service, CartesApiException>({
mutationFn: () => {
const formValues = getFormValues();
return api.pyramidRaster.publishWmsRaster(datastoreId, pyramidId, formValues);
return api.pyramidRaster.publishWmsRasterWmts(datastoreId, pyramidId, ConfigurationTypeEnum.WMSRASTER, formValues);
},
onSuccess() {
// queryClient.invalidateQueries({ queryKey: RQKeys.datastore_datasheet(datastoreId, datasheetName) });
// routes.datastore_datasheet_view({ datastoreId, datasheetName: datasheetName, activeTab: "services" }).push();
queryClient.invalidateQueries({ queryKey: RQKeys.datastore_datasheet(datastoreId, datasheetName) });
routes.datastore_datasheet_view({ datastoreId, datasheetName: datasheetName, activeTab: "services" }).push();
},
});

Expand All @@ -71,7 +71,7 @@ const PyramidRasterWmsRasterServiceForm: FC<PyramidRasterWmsRasterServiceFormPro
}

const formValues = getFormValues();
return api.pyramidRaster.editWmsRaster(datastoreId, pyramidId, offeringId, formValues);
return api.pyramidRaster.editWmsRasterWmts(datastoreId, pyramidId, offeringId, ConfigurationTypeEnum.WMSRASTER, formValues);
},
onSuccess() {
if (offeringId !== undefined) {
Expand Down
Loading

0 comments on commit 4835c58

Please sign in to comment.