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

dscme-wip #351

Merged
merged 15 commits into from
Dec 12, 2023
Original file line number Diff line number Diff line change
Expand Up @@ -306,4 +306,4 @@ export const GenerateArtifactsMenu: React.FC<{
<ProvidedPreviewDialog.Component />
</>
);
};
};
2 changes: 1 addition & 1 deletion applications/client/src/schema-artifacts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,4 +172,4 @@ export function getSchemaArtifacts(
}

return artifacts;
}
}
477 changes: 477 additions & 0 deletions applications/conceptual-model-editor/package-lock.json

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions applications/conceptual-model-editor/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@
},
"dependencies": {
"@dataspecer/core": "*",
"@dataspecer/core-v2": "^0.0.0",
"@dataspecer/rdfs-adapter": "*",
"@dataspecer/sgov-adapter": "^0.0.0",
"jointjs": "^3.7.0",
"next": "^13.2.4",
"react": "18.2.0",
"react-dom": "18.2.0",
"reactflow": "^11.9.4",
"zod": "^3.21.4"
},
"devDependencies": {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
import { type EntityModel } from "@dataspecer/core-v2/entity-model";
import { BackendPackageService, PackageEditable } from "@dataspecer/core-v2/project";
import { InMemorySemanticModel } from "@dataspecer/core-v2/semantic-model/in-memory";
import { createClass } from "@dataspecer/core-v2/semantic-model/operations";
import { createRdfsModel, createSgovModel } from "@dataspecer/core-v2/semantic-model/simplified";
import { httpFetch } from "@dataspecer/core/io/fetch/fetch-browser";
import { useMemo } from "react";
import { ViewLayout } from "./context/view-context";
import { getOneNameFromLanguageString } from "./util/utils";

export const useBackendConnection = () => {
const BACKEND_URL = "http://localhost:3100";
const service = useMemo(() => new BackendPackageService(BACKEND_URL, httpFetch), []);

const getPackageFromBackend = async (packageId: string) => {
const pckg = await service.getPackage(packageId);
console.log("got package from backend", packageId, pckg);
return pckg;
};

const getModelsFromBackend = async (packageId: string) => {
const models = await service.constructSemanticModelPackageModels(packageId);
console.log(models);
return models;
};

const getViewsFromBackend = async (packageId: string) => {
return constructViewsMock();
};

const updateSemanticModelPackageModels = async (packageId: string, models: EntityModel[]) => {
await service.updateSemanticModelPackageModels(packageId, models);
console.log(`updated models for package ${packageId}`, models);
};

const createPackage = async (packageId: string, packageNameCs: string) => {
const pckg = await service.createPackage(".root", {
id: packageId,
name: { cs: packageNameCs },
tags: [],
} as PackageEditable);
console.log(pckg);
alert(`package ${pckg.id}-${getOneNameFromLanguageString(pckg.name)} logged to console`);
return pckg;
};

const listPackages = () => {
return ["zvířátkový-package", "package-xyz", "testovací-package"];
};

const listViews = () => {
return ["view-1", "view-xyz"];
};

return {
service,
getPackageFromBackend,
updateSemanticModelPackageModels,
listPackages,
listViews,
getModelsFromBackend,
getViewsFromBackend,
createPackage,
};
};

const constructSemanticModelPackageModelsMock = async (packageId: string) => {
if (packageId == "") {
return [] as EntityModel[];
}

const sgov = createSgovModel("https://slovník.gov.cz/sparql", httpFetch);
sgov.allowClass("https://slovník.gov.cz/datový/turistické-cíle/pojem/turistický-cíl");
sgov.allowClass("https://slovník.gov.cz/generický/bezbariérové-přístupy/pojem/bezbariérový-přístup");

const dcterms = await createRdfsModel(
["https://mff-uk.github.io/demo-vocabularies/original/dublin_core_terms.ttl"],
httpFetch
);
dcterms.fetchFromPimStore();

const local = new InMemorySemanticModel();
local.executeOperation(
createClass({
name: { cs: "fejk-třída-pes" },
iri: "https://my-fake.iri.com/fejk-třída-pes",
})
);
local.executeOperation(
createClass({
name: { cs: "fejk-třída-kočka" },
iri: "https://my-fake.iri.com/fejk-třída-kočka",
})
);

const models = [sgov, dcterms, local] as EntityModel[];
return models;
};

const constructViewsMock = async () => {
const viewLayout1 = {
id: "view-1",
name: { cs: "pohled-1" },
elementPositionMap: new Map([
["https://slovník.gov.cz/datový/turistické-cíle/pojem/turistický-cíl", { x: 100, y: 90 }],
["https://slovník.gov.cz/generický/bezbariérové-přístupy/pojem/bezbariérový-přístup", { x: 100, y: 140 }],
]),
} as ViewLayout;

const viewLayoutXyz = {
id: "view-xyz",
name: { cs: "pohled-xyz" },
elementPositionMap: new Map([
["https://slovník.gov.cz/datový/turistické-cíle/pojem/turistický-cíl", { x: 90, y: 100 }],
["https://slovník.gov.cz/generický/bezbariérové-přístupy/pojem/bezbariérový-přístup", { x: 140, y: 100 }],
]),
} as ViewLayout;

return [viewLayout1, viewLayoutXyz];
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// import { SemanticModelClassWithOrigin } from "../context/classes-context";
// import { getNameOf } from "../util/utils";

// export const ExpandableRow = (props: { cls: SemanticModelClassWithOrigin; toggleHandler: () => void }) => {
// const cls = props.cls.cls;
// return (
// <div className="flex flex-row justify-between whitespace-nowrap">
// <span onClick={props.toggleHandler}>
// {allowedClasses.includes(cls.id) ? "✅ " : "❌ "}
// {getNameOf(cls)}
// </span>
// <button className="ml-2 bg-teal-300 px-1" onClick={() => handleOpenDetail(cls)}>
// Detail
// </button>
// </div>
// );
// };
// export const NonExpandableRow = (props: { cls: SemanticModelClassWithOrigin }) => (
// <div className="flex flex-row justify-between whitespace-nowrap">
// {getNameOf(props.cls.cls)}
// <button className="ml-2 bg-teal-300 px-1" onClick={() => handleOpenDetail(props.cls.cls)}>
// Detail
// </button>
// </div>
// );
// export const ModifiableRow = (props: { cls: SemanticModelClassWithOrigin }) => (
// <div className="flex flex-row justify-between whitespace-nowrap">
// {getNameOf(props.cls.cls)}
// <div>
// <button className="ml-2 bg-teal-300 px-1" onClick={() => handleOpenModification(props.cls.cls)}>
// Modify
// </button>
// <button className="ml-0.5 bg-teal-300 px-1" onClick={() => handleOpenDetail(props.cls.cls)}>
// Detail
// </button>
// </div>
// </div>
// );
Loading
Loading