Skip to content

Commit

Permalink
Chaos v mazání typů objektů? #540
Browse files Browse the repository at this point in the history
  • Loading branch information
bindeali committed Sep 13, 2024
1 parent d7ea6a5 commit 9ad1735
Show file tree
Hide file tree
Showing 5 changed files with 104 additions and 14 deletions.
21 changes: 10 additions & 11 deletions src/function/FunctionEditVars.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { LanguageObject } from "./../config/Languages";
import * as _ from "lodash";
import { LinkType } from "../config/Enum";
import { Languages } from "../config/Languages";
import { Locale } from "../config/Locale";
Expand All @@ -11,22 +11,22 @@ import {
WorkspaceElements,
WorkspaceLinks,
WorkspaceTerms,
WorkspaceVocabularies,
WorkspaceVocabularies
} from "../config/Variables";
import { Cardinality } from "../datatypes/Cardinality";
import { graph } from "../graph/Graph";
import { updateDeleteTriples } from "../queries/update/UpdateMiscQueries";
import { LinkConfig } from "../queries/update/UpdateConnectionQueries";
import { LanguageObject } from "./../config/Languages";
import { addClass } from "./FunctionCreateVars";
import { filterEquivalent } from "./FunctionEquivalents";
import {
getActiveSourceConnections,
getActiveTargetConnections,
getLocalStorageKey,
getVocabularyFromScheme,
loadDefaultCardinality,
loadDefaultCardinality
} from "./FunctionGetVars";
import * as _ from "lodash";
import { LinkConfig } from "../queries/update/UpdateConnectionQueries";
import { filterEquivalent } from "./FunctionEquivalents";
import { graph } from "../graph/Graph";
import { updateDeleteTriples } from "../queries/update/UpdateMiscQueries";

export function trimLanguageObjectInput(input: LanguageObject): LanguageObject {
return _.mapValues(input, (i) => i.trim());
Expand Down Expand Up @@ -206,9 +206,8 @@ export function setElementShape(
elem.attr({
bodyDiamond: {
display: "block",
points: `${width / 2},${-(height / 2)} ${width * (9 / 8)},${
height / 2
} ${width / 2},${height * (3 / 2)} ${-(width / 8)},${height / 2}`,
points: `${width / 2},${-(height / 2)} ${width * (9 / 8)},${height / 2
} ${width / 2},${height * (3 / 2)} ${-(width / 8)},${height / 2}`,
stroke: "black",
fill: WorkspaceVocabularies[
getVocabularyFromScheme(WorkspaceTerms[elem.id].inScheme)
Expand Down
5 changes: 4 additions & 1 deletion src/function/FunctionElem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
import { updateCreateDiagram } from "../queries/update/UpdateDiagramQueries";
import {
updateProjectElement,
updateProjectElementData,
updateProjectElementDiagram,
} from "../queries/update/UpdateElementQueries";
import {
Expand Down Expand Up @@ -445,6 +446,7 @@ export function removeElement(elem: string): string[] {
const writeGraphs = Object.keys(WorkspaceVocabularies)
.filter((vocab) => !WorkspaceVocabularies[vocab].readOnly)
.map((vocab) => WorkspaceVocabularies[vocab].graph);
WorkspaceElements[elem].active = false;
return [
...deleteConcept(elem),
updateDeleteTriples(
Expand All @@ -454,6 +456,7 @@ export function removeElement(elem: string): string[] {
false,
false
),
updateDeleteTriples(elem, writeGraphs, true, true, true)
updateDeleteTriples(elem, writeGraphs, true, true, true),
updateProjectElementData(true, elem),
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,20 @@ export class DetailElementDescription extends React.Component<Props, State> {
}

componentWillUnmount() {
if (!this.state.readOnly) this.save();
if (this.props.id in WorkspaceElements && !this.state.readOnly) {
if (
WorkspaceTerms[this.props.id].altLabels === this.state.inputAltLabels &&
WorkspaceTerms[this.props.id].definitions ===
this.state.inputDefinitions &&
WorkspaceTerms[this.props.id].descriptions ===
this.state.inputDescriptions &&
WorkspaceTerms[this.props.id].source === this.state.inputSource &&
WorkspaceElements[this.props.id].selectedLabel ===
this.state.selectedLabel
)
return;
else this.save();
}
}

componentDidUpdate(prevProps: Readonly<Props>, prevState: Readonly<State>) {
Expand Down
6 changes: 5 additions & 1 deletion src/queries/get/InitQueries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,11 @@ export async function getElementsConfig(
const query = [
"PREFIX og: <http://onto.fel.cvut.cz/ontologies/application/ontoGrapher/>",
"PREFIX skos: <http://www.w3.org/2004/02/skos/core#> ",
"select ?elem ?scheme ?name ?vocabulary where {",
"select ?elem ?scheme ?name ?vocabulary ?active where {",
"graph ?graph {",
"?elem a og:element .",
"optional {?elem og:name ?name.}",
"optional {?elem og:active ?active.}",
"optional {?elem og:vocabulary ?vocabulary.}",
"?elem og:scheme ?scheme .",
"}",
Expand Down Expand Up @@ -63,6 +64,9 @@ export async function getElementsConfig(
targetLinks: [],
};
}
if (result.active) {
elements[iri].active = result.active.value === "true"
}
if (
result.name &&
!elements[iri].selectedLabel![result.name["xml:lang"]]
Expand Down
71 changes: 71 additions & 0 deletions src/queries/update/UpdateElementQueries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,77 @@ import {
import { getVocabularyFromScheme } from "../../function/FunctionGetVars";
import { qb } from "../QueryBuilder";

export function updateProjectElementData(del: boolean, ...iris: string[]): string {
const diagramGraphs = Object.values(Diagrams)
.filter((diag) => !diag.toBeDeleted)
.map((diag) => diag.graph);
const data: { [key: string]: string[] } = {};
diagramGraphs.forEach((diag) => (data[diag] = []));
const deletes: string[] = [];
const inserts: string[] = [];
if (iris.length === 0) return "";
for (const iri of iris) {
checkElem(iri);
const vocabElem = WorkspaceTerms[iri];
const scheme = vocabElem.inScheme;
const vocab = getVocabularyFromScheme(vocabElem.inScheme);
const names = Object.entries(WorkspaceElements[iri].selectedLabel)
.filter(
([key, value]) =>
key in Languages && value && WorkspaceTerms[iri].labels[key] !== value
)
.map(([key, value]) => qb.ll(value, key));

const ogStatements: string[] = [
qb.s(qb.i(iri), "rdf:type", "og:element"),
qb.s(qb.i(iri), "og:scheme", qb.i(scheme)),
qb.s(qb.i(iri), "og:vocabulary", qb.i(getVocabularyFromScheme(scheme))),
qb.s(qb.i(iri), "og:name", qb.a(names), names.length > 0),
qb.s(qb.i(iri), "og:active", qb.ll(WorkspaceElements[iri].active)),
];
Object.values(Diagrams)
.filter((diag) => !diag.toBeDeleted)
.map((diag) => diag.graph)
.forEach((graph) => data[graph].push(...ogStatements));

if (WorkspaceVocabularies[vocab].readOnly) continue;
if (!(vocab in data)) data[vocab] = [];

if (del) {
const deleteStatements = [
qb.s(qb.i(iri), "og:name", "?name"),
qb.s(qb.i(iri), "og:active", "?active"),
];
deletes.push(
...diagramGraphs.map((graph) =>
DELETE`${qb.g(graph, deleteStatements)}`.WHERE`${qb.g(
graph,
deleteStatements
)}`.build()
),
);
}
AppSettings.changedVocabularies.push(
getVocabularyFromScheme(WorkspaceTerms[iri].inScheme)
);
}

for (const vocab in data) {
if (vocab in WorkspaceVocabularies) {
const graph = WorkspaceVocabularies[vocab].graph;
if (WorkspaceVocabularies[vocab].readOnly)
throw new Error(`Attempted to write to read-only graph ${graph}`);
inserts.push(INSERT.DATA`${qb.g(graph, data[vocab])}`.build());
}
}
inserts.push(
...diagramGraphs.map((graph) =>
INSERT.DATA`${qb.g(graph, data[graph])}`.build()
)
);
return qb.combineQueries(...deletes, ...inserts);
}

export function updateProjectElement(del: boolean, ...iris: string[]): string {
const diagramGraphs = Object.values(Diagrams)
.filter((diag) => !diag.toBeDeleted)
Expand Down

0 comments on commit 9ad1735

Please sign in to comment.