-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #554 from kbss-cvut/enhancement#528-ontographer-in…
…tegration Enhancement#528 ontographer integration
- Loading branch information
Showing
8 changed files
with
189 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
src/component/vocabulary/modeling/OpenModelingToolDialog.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
.modeling-vocabulary-select-dialog { | ||
max-width: 80%; | ||
} | ||
|
||
input.vocabulary-checkbox { | ||
position: relative; | ||
margin-left: 0; | ||
margin-right: 0.5rem; | ||
} |
120 changes: 120 additions & 0 deletions
120
src/component/vocabulary/modeling/OpenModelingToolDialog.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
import React from "react"; | ||
import Vocabulary from "../../../model/Vocabulary"; | ||
import { useI18n } from "../../hook/useI18n"; | ||
import ConfirmCancelDialog from "../../misc/ConfirmCancelDialog"; | ||
import { getLocalized } from "../../../model/MultilingualString"; | ||
import { ThunkDispatch } from "../../../util/Types"; | ||
import { useDispatch, useSelector } from "react-redux"; | ||
import { loadRelatedVocabularies } from "../../../action/AsyncVocabularyActions"; | ||
import VocabularyUtils from "../../../util/VocabularyUtils"; | ||
import TermItState from "../../../model/TermItState"; | ||
import { loadVocabularies } from "../../../action/AsyncActions"; | ||
import { Col, Input, Row } from "reactstrap"; | ||
import { getShortLocale } from "../../../util/IntlUtil"; | ||
import "./OpenModelingToolDialog.scss"; | ||
|
||
const COLUMN_COUNT = 3; | ||
|
||
interface OpenModelingToolDialogProps { | ||
open: boolean; | ||
onClose: () => void; | ||
vocabulary: Vocabulary; | ||
} | ||
|
||
const OpenModelingToolDialog: React.FC<OpenModelingToolDialogProps> = ({ | ||
open, | ||
onClose, | ||
vocabulary, | ||
}) => { | ||
const { formatMessage, i18n, locale } = useI18n(); | ||
const dispatch: ThunkDispatch = useDispatch(); | ||
const [relatedVocabularies, setRelatedVocabularies] = React.useState< | ||
string[] | ||
>([]); | ||
const [selectedVocabularies, setSelectedVocabularies] = React.useState< | ||
string[] | ||
>([]); | ||
const modelingToolUrl = useSelector( | ||
(state: TermItState) => state.configuration | ||
).modelingToolUrl; | ||
const vocabularies = useSelector((state: TermItState) => state.vocabularies); | ||
const vocabularyIris = Object.keys(vocabularies); | ||
React.useEffect(() => { | ||
dispatch( | ||
loadRelatedVocabularies(VocabularyUtils.create(vocabulary.iri)) | ||
).then((data) => { | ||
setRelatedVocabularies(data); | ||
// The vocabulary is also among the related vocabularies loaded from the server | ||
setSelectedVocabularies(data); | ||
}); | ||
if (Object.keys(vocabularies).length === 0) { | ||
dispatch(loadVocabularies()); | ||
} | ||
}, [vocabulary.iri, vocabularies, dispatch]); | ||
|
||
const onSelect = (vIri: string) => { | ||
if (selectedVocabularies.includes(vIri)) { | ||
setSelectedVocabularies(selectedVocabularies.filter((v) => v !== vIri)); | ||
} else { | ||
setSelectedVocabularies([...selectedVocabularies, vIri]); | ||
} | ||
}; | ||
const onOpen = () => { | ||
let params = selectedVocabularies | ||
.map((v) => encodeURIComponent(v)) | ||
.join("&vocabulary="); | ||
window.location.href = modelingToolUrl + "?vocabulary=" + params; | ||
}; | ||
|
||
const rowCount = Math.ceil(vocabularyIris.length / COLUMN_COUNT); | ||
const rows = []; | ||
for (let i = 0; i < rowCount; i++) { | ||
const cols = []; | ||
for (let j = 0; j < COLUMN_COUNT; j++) { | ||
const index = i * COLUMN_COUNT + j; | ||
if (index >= vocabularyIris.length) { | ||
break; | ||
} | ||
cols.push( | ||
<Col key={index} md={12 / COLUMN_COUNT}> | ||
<Input | ||
type="checkbox" | ||
checked={selectedVocabularies.includes(vocabularyIris[index])} | ||
disabled={relatedVocabularies.includes(vocabularyIris[index])} | ||
onChange={() => onSelect(vocabularyIris[index])} | ||
className="vocabulary-checkbox" | ||
/> | ||
{getLocalized( | ||
vocabularies[vocabularyIris[index]].label, | ||
getShortLocale(locale) | ||
)} | ||
</Col> | ||
); | ||
} | ||
rows.push( | ||
<Row key={i} className="mb-2"> | ||
{cols} | ||
</Row> | ||
); | ||
} | ||
|
||
return ( | ||
<ConfirmCancelDialog | ||
id="vocabulary-model-dialog" | ||
show={open} | ||
onClose={onClose} | ||
confirmKey="vocabulary.summary.model.open" | ||
onConfirm={onOpen} | ||
title={formatMessage("vocabulary.summary.model.dialog.title", { | ||
vocabulary: getLocalized(vocabulary.label), | ||
})} | ||
size="lg" | ||
className="modeling-vocabulary-select-dialog" | ||
> | ||
<p className="mb-4">{i18n("vocabulary.summary.model.dialog.text")}</p> | ||
{rows} | ||
</ConfirmCancelDialog> | ||
); | ||
}; | ||
|
||
export default OpenModelingToolDialog; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters