diff --git a/app/rdf/namespace.ts b/app/rdf/namespace.ts index 1d3d1cb8b..3d5eb95d4 100644 --- a/app/rdf/namespace.ts +++ b/app/rdf/namespace.ts @@ -24,5 +24,6 @@ export const adminVocabulary = namespace("https://ld.admin.ch/vocabulary/"); export const cube = namespace("https://cube.link/"); export const cubeView = namespace("https://cube.link/view/"); export const cubeMeta = namespace("https://cube.link/meta/"); +export const view = namespace("https://cube.link/view/"); export const visualizeAdmin = namespace("https://visualize.admin.ch/"); diff --git a/app/rdf/queries.ts b/app/rdf/queries.ts index 09b7cae97..c7709589c 100644 --- a/app/rdf/queries.ts +++ b/app/rdf/queries.ts @@ -5,7 +5,7 @@ import { CubeDimension, Filter, LookupSource, - View, + View as RDFView, } from "rdf-cube-view-query"; import rdf from "rdf-ext"; import { Literal, NamedNode } from "rdf-js"; @@ -44,6 +44,23 @@ import { loadResourceLiterals } from "./query-literals"; import { loadUnversionedResources } from "./query-sameas"; import { loadUnits } from "./query-unit-labels"; +// FIXME: Remove once sorting is removed (https://github.com/zazuko/rdf-cube-view-query/pull/96) +const View = RDFView; +View.prototype.setDefaultColumns = function () { + const orderingColumns = this.dimensions.map((dimension) => ({ + // @ts-ignore + iri: dimension.cubeDimensions[0].path.value, + term: dimension.ptr.term, + })); + + const projectionPtr = this.ptr.out(ns.view.projection); + projectionPtr.addList( + ns.view.columns, + // @ts-ignore + orderingColumns.map((dimension) => dimension.term) + ); +}; + const DIMENSION_VALUE_UNDEFINED = ns.cube.Undefined.value; /** Adds a suffix to an iri to mark its label */ @@ -598,7 +615,7 @@ const buildFilters = ({ locale, }: { cube: Cube; - view: View; + view: RDFView; filters: Filters; locale: string; }): Filter[] => { @@ -698,7 +715,7 @@ async function fetchViewObservations({ disableDistinct, }: { limit: number | undefined; - observationsView: View; + observationsView: RDFView; disableDistinct: boolean; }) { /** @@ -783,7 +800,7 @@ function buildDimensions({ observationFilters, raw, }: { - cubeView: View; + cubeView: RDFView; dimensions: Maybe; cubeDimensions: ResolvedDimension[]; cube: Cube; diff --git a/app/typings/rdf.d.ts b/app/typings/rdf.d.ts index 55947985c..b272976f2 100644 --- a/app/typings/rdf.d.ts +++ b/app/typings/rdf.d.ts @@ -97,6 +97,7 @@ declare module "rdf-cube-view-query" { }): Promise[]>; addDimension(dimension: Dimension): View; createDimension(options: $FixMe): Dimension; + setDefaultColumns(): void; } export class Source extends Node { constructor(