Merge branch 'query-builder' of gitlab.ub.uni-bielefeld.de:sfb1288inf/nopaque into query-builder

This commit is contained in:
Patrick Jentsch 2023-11-13 15:53:17 +01:00
commit 1c18806c9c

View File

@ -68,7 +68,7 @@ nopaque.corpus_analysis.query_builder.QueryBuilder = class QueryBuilder {
}) })
} }
submitQueryChipElement(dataType = undefined, prettyQueryText = undefined, queryText = undefined, index = null, isClosingTag = false, isEditable = false) { submitQueryChipElement(dataType=undefined, prettyQueryText=undefined, queryText=undefined, index=null, isClosingTag=false, isEditable=false) {
if (this.elements.editingModusOn) { if (this.elements.editingModusOn) {
let editedQueryChipElement = this.elements.queryChipElements[this.elements.editedQueryChipElementIndex]; let editedQueryChipElement = this.elements.queryChipElements[this.elements.editedQueryChipElementIndex];
editedQueryChipElement.dataset.type = dataType; editedQueryChipElement.dataset.type = dataType;
@ -81,7 +81,7 @@ nopaque.corpus_analysis.query_builder.QueryBuilder = class QueryBuilder {
} }
} }
queryChipFactory(dataType, prettyQueryText, queryText, index = null, isClosingTag = false, isEditable = false) { queryChipFactory(dataType, prettyQueryText, queryText, index=null, isClosingTag=false, isEditable=false) {
// Creates a new query chip element, adds Eventlisteners for selection, deletion and drag and drop and appends it to the query input field. // Creates a new query chip element, adds Eventlisteners for selection, deletion and drag and drop and appends it to the query input field.
queryText = nopaque.Utils.escape(queryText); queryText = nopaque.Utils.escape(queryText);
prettyQueryText = nopaque.Utils.escape(prettyQueryText); prettyQueryText = nopaque.Utils.escape(prettyQueryText);
@ -93,7 +93,7 @@ nopaque.corpus_analysis.query_builder.QueryBuilder = class QueryBuilder {
</span> </span>
` `
); );
this.actionListeners(queryChipElement); this.addActionListeners(queryChipElement);
queryChipElement.addEventListener('dragstart', this.handleDragStart.bind(this, queryChipElement)); queryChipElement.addEventListener('dragstart', this.handleDragStart.bind(this, queryChipElement));
queryChipElement.addEventListener('dragend', this.handleDragEnd); queryChipElement.addEventListener('dragend', this.handleDragEnd);
@ -119,7 +119,7 @@ nopaque.corpus_analysis.query_builder.QueryBuilder = class QueryBuilder {
this.queryPreviewBuilder(); this.queryPreviewBuilder();
} }
actionListeners(queryChipElement) { addActionListeners(queryChipElement) {
let notQuantifiableDataTypes = ['start-sentence', 'end-sentence', 'start-entity', 'start-empty-entity', 'end-entity', 'token-incidence-modifier']; let notQuantifiableDataTypes = ['start-sentence', 'end-sentence', 'start-entity', 'start-empty-entity', 'end-entity', 'token-incidence-modifier'];
queryChipElement.addEventListener('click', (event) => { queryChipElement.addEventListener('click', (event) => {
if (event.target.classList.contains('chip')) { if (event.target.classList.contains('chip')) {
@ -129,8 +129,7 @@ nopaque.corpus_analysis.query_builder.QueryBuilder = class QueryBuilder {
} }
}); });
let chipActionButtons = queryChipElement.querySelectorAll('.chip-action-button'); let chipActionButtons = queryChipElement.querySelectorAll('.chip-action-button');
// chipActionButtons.forEach(button => { chipActionButtons.forEach(button => {
for (let button of chipActionButtons) {
button.addEventListener('click', (event) => { button.addEventListener('click', (event) => {
if (event.target.dataset.chipAction === 'delete') { if (event.target.dataset.chipAction === 'delete') {
this.deleteChipElement(queryChipElement); this.deleteChipElement(queryChipElement);
@ -140,8 +139,7 @@ nopaque.corpus_analysis.query_builder.QueryBuilder = class QueryBuilder {
this.lockClosingChipElement(queryChipElement); this.lockClosingChipElement(queryChipElement);
} }
}); });
} });
// });
} }
editChipElement(queryChipElement) { editChipElement(queryChipElement) {
@ -175,10 +173,10 @@ nopaque.corpus_analysis.query_builder.QueryBuilder = class QueryBuilder {
let elementIndex = Array.from(this.elements.queryInputField.children).indexOf(attr); let elementIndex = Array.from(this.elements.queryInputField.children).indexOf(attr);
switch (attr.dataset.type) { switch (attr.dataset.type) {
case 'start-sentence': case 'start-sentence':
this.deletingClosingTagHandler(elementIndex, 'end-sentence'); this.deleteClosingTagHandler(elementIndex, 'end-sentence');
break; break;
case 'start-entity': case 'start-entity':
this.deletingClosingTagHandler(elementIndex, 'end-entity'); this.deleteClosingTagHandler(elementIndex, 'end-entity');
break; break;
case 'token': case 'token':
let nextElement = Array.from(this.elements.queryInputField.children)[elementIndex+1]; let nextElement = Array.from(this.elements.queryInputField.children)[elementIndex+1];
@ -196,7 +194,7 @@ nopaque.corpus_analysis.query_builder.QueryBuilder = class QueryBuilder {
this.queryPreviewBuilder(); this.queryPreviewBuilder();
} }
deletingClosingTagHandler(elementIndex, closingTagType) { deleteClosingTagHandler(elementIndex, closingTagType) {
let closingTags = this.elements.queryInputField.querySelectorAll(`[data-type="${closingTagType}"]`); let closingTags = this.elements.queryInputField.querySelectorAll(`[data-type="${closingTagType}"]`);
for (let i = 0; i < closingTags.length; i++) { for (let i = 0; i < closingTags.length; i++) {
let closingTag = closingTags[i]; let closingTag = closingTags[i];
@ -208,7 +206,7 @@ nopaque.corpus_analysis.query_builder.QueryBuilder = class QueryBuilder {
} }
} }
handleDragStart(queryChipElement, event) { handleDragStart(queryChipElement) {
// is called when a query chip is dragged. It creates a dropzone (in form of a chip) for the dragged chip and adds it to the query input field. // is called when a query chip is dragged. It creates a dropzone (in form of a chip) for the dragged chip and adds it to the query input field.
let queryChips = this.elements.queryInputField.querySelectorAll('.query-component'); let queryChips = this.elements.queryInputField.querySelectorAll('.query-component');
if (queryChipElement.dataset.type === 'token-incidence-modifier') { if (queryChipElement.dataset.type === 'token-incidence-modifier') {
@ -232,7 +230,7 @@ nopaque.corpus_analysis.query_builder.QueryBuilder = class QueryBuilder {
}, 0); }, 0);
} }
handleDragEnd(event) { handleDragEnd() {
document.querySelectorAll('.drop-target').forEach(target => target.remove()); document.querySelectorAll('.drop-target').forEach(target => target.remove());
} }