Skip to content

Commit

Permalink
fix: fix diagnosis tree.
Browse files Browse the repository at this point in the history
fix: minor fixes
  • Loading branch information
volishevko committed Dec 5, 2024
1 parent 642925d commit 8161ae2
Show file tree
Hide file tree
Showing 6 changed files with 250 additions and 146 deletions.
4 changes: 4 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
<symbol viewBox="0 0 26 26" id="close-icon">
<path d="M13 0C5.832 0 0 5.832 0 13s5.832 13 13 13 13-5.832 13-13S20.168 0 13 0zm0 2c6.086 0 11 4.914 11 11s-4.914 11-11 11S2 19.086 2 13 6.914 2 13 2zM9.22 7.78L7.78 9.22 11.563 13l-3.78 3.78 1.437 1.44L13 14.437l3.78 3.78 1.44-1.437L14.437 13l3.78-3.78-1.437-1.44L13 11.563l-3.78-3.78z"></path>
</symbol>
<symbol viewBox="0 0 24 24" id="remove-filter-icon">
<path d="M8.5 9C8.10948 9.39052 8.10948 10.0237 8.5 10.4142L10.3358 12.25L8.5 14.0858C8.10948 14.4763 8.10948 15.1095 8.5 15.5C8.89052 15.8905 9.52369 15.8905 9.91421 15.5L11.75 13.6642L13.5858 15.5C13.9763 15.8905 14.6095 15.8905 15 15.5C15.3905 15.1095 15.3905 14.4763 15 14.0858L13.1642 12.25L15 10.4142C15.3905 10.0237 15.3905 9.39052 15 9C14.6095 8.60948 13.9763 8.60948 13.5858 9L11.75 10.8358L9.91421 9C9.52369 8.60948 8.89052 8.60948 8.5 9Z" fill="#9799A0"/>
<path fill-rule="evenodd" clip-rule="evenodd" d="M24 12C24 18.6274 18.6274 24 12 24C5.37258 24 0 18.6274 0 12C0 5.37258 5.37258 0 12 0C18.6274 0 24 5.37258 24 12ZM22 12C22 17.5228 17.5228 22 12 22C6.47715 22 2 17.5228 2 12C2 6.47715 6.47715 2 12 2C17.5228 2 22 6.47715 22 12Z" fill="#9799A0"/>"
</symbol>
<symbol viewBox="0 0 26 26" id="diagnosis-icon">
<path d="M11 4L9 6v2H6c-1.142 0-1.864 1-2 2L3 20c-.108 1 .557 2 2 2h16c1.444 0 2.108-1 2-2l-1-10c-.136-1-.955-2-2-2h-3V6l-2-2h-4zm0 2h4v2h-4V6zm1 5h2v3h3v2h-3v3h-2v-3H9v-2h3v-3z"></path>
</symbol>
Expand Down
16 changes: 15 additions & 1 deletion sources/models/appliedFilters.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ function processNewFilter(filter) {
switch (filter.view) {
case "checkbox":
case "rangeCheckbox":
case constants.FILTER_ELEMENT_TYPE.TREE_CHECKBOX:
{
let checkboxId = util.getOptionId(filter.key, filter.optionId ?? filter.value);
if (filter.remove) {
Expand All @@ -100,6 +99,21 @@ function processNewFilter(filter) {
}
break;
}
case constants.FILTER_ELEMENT_TYPE.TREE_CHECKBOX: {
const optionId = filter.optionId;
if (filter.remove) {
if (appliedFilters.exists(optionId)) {
appliedFilters.remove(optionId);
}
}
else {
filter.id = optionId;
if (!appliedFilters.exists(optionId)) {
appliedFilters.add(filter);
}
}
break;
}
case "rangeSlider":
{
break;
Expand Down
102 changes: 35 additions & 67 deletions sources/services/gallery/filter.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,8 @@ function _setFilterCounts(controlView, totalCount, currentCount) {
controlView.refresh();
}

function _setDiagnosisFilterCounts(controlView, totalCount, currentCount) {
const oldLabel = controlView.config.labelRight;
const lastBracketIndex = oldLabel.lastIndexOf("("); // counts is in () in label. We should remove old counts and set new counts
const baseLabelText = lastBracketIndex === -1
? oldLabel
: oldLabel.substring(0, lastBracketIndex);
function _setDiagnosisFilterCounts(treeView, option, totalCount, currentCount) {
const baseLabelText = option.id;
let firstNumberHtml;
if (totalCount === currentCount) {
firstNumberHtml = "";
Expand All @@ -88,14 +84,9 @@ function _setDiagnosisFilterCounts(controlView, totalCount, currentCount) {
else {
firstNumberHtml = `${currentCount} / `;
}
const newLabel = `${baseLabelText}(${firstNumberHtml}${totalCount})`;
controlView.define("labelRight", newLabel);
controlView.getNode().setAttribute("title", newLabel);
controlView.refresh();
}

function hideControl(controlView) {
controlView.define("hidden", true);
const newLabel = `${baseLabelText} (${firstNumberHtml}${totalCount})`;
option.name = newLabel;
treeView.updateItem(option.id, option);
}

function updateFiltersFormControl(data) {
Expand All @@ -120,7 +111,7 @@ function updateFiltersFormControl(data) {
}
case constants.FILTER_ELEMENT_TYPE.TREE_CHECKBOX:
{
updateTreeCheckboxControl(data, true);
updateTreeCheckboxControl(data);
break;
}
case "rangeFilter":
Expand All @@ -134,58 +125,37 @@ function updateFiltersFormControl(data) {
}
}

function updateTreeCheckboxControl(data, updateParentFlag) {
const controlId = util.getOptionId("diagnosis", data.optionId);
const control = $$(controlId);
if (control) {
function updateTreeCheckboxControl(data) {
const treeView = $$(data.viewId);
if (treeView) {
// we do not need to call onChange event for the control. so we block event
control.blockEvent();
treeView.blockEvent();
/* remove key is from "filtersChanged" event parameters.
Its value is inverse for checkbox value */
control.setValue(!data.remove);
control.unblockEvent();
if (updateParentFlag && control.config.attributes.parentId) {
const isIndeterminate = !data.remove;
const parentElement = $$(control.config.attributes.parentId);
changeParentState(parentElement, isIndeterminate, !data.remove);
if (!treeView.isVisible()) {
treeView.show();
}
}
if (data.children) {
const remove = data.remove;
data.children.forEach((c) => {
const child = webix.copy(c);
child.remove = remove;
child.optionId = child.id;
updateTreeCheckboxControl(child, false);
});
}
if (data.data) {
const remove = data.remove;
data.data.forEach((c) => {
const child = webix.copy(c);
child.remove = remove;
child.optionId = child.id;
updateTreeCheckboxControl(child, false);
});
treeView.checkItem(data.id);
treeView.open(data.id);
const parentId = treeView.getParentId(data.id);
if (parentId) {
const parent = treeView.getItem(parentId);
changeParentState(treeView, parent);
}
treeView.unblockEvent();
}
}

function changeParentState(element, isIndeterminate, status) {
if (isIndeterminate) {
const elementNode = element.getInputNode();
if (elementNode) {
elementNode.indeterminate = true;
const parentId = element?.config?.attributes?.parentId;
if (parentId) {
const parentElement = $$(parentId);
changeParentState(parentElement, isIndeterminate, status);
}
}
function changeParentState(treeView, option) {
treeView.open(option.id);
if (option.checked) {
// TODO: fix uncheck all items
// treeView.uncheckItem(parent.id);
}
else {
element.blockEvent();
element.setValue(status);
element.unblockEvent();
const parentId = treeView.getParentId(option.id);
if (parentId) {
const parentOption = treeView.getItem(parentId);
changeParentState(treeView, parentOption);
}
}

Expand Down Expand Up @@ -231,6 +201,7 @@ function updateFiltersCounts(countsAfterFiltration) {
const controlKey = "diagnosis";
const diagnosisValues = diagnosisModel.getDiagnosisValuesByLevel(filterKey);
const displayDiagnosis = diagnosisModel.getDisplayDiagnosis();
const treeView = $$(`treeTable-${controlKey}`);
diagnosisValues.forEach((v) => {
let value = values.find(item => item.key === v);
if (!value) {
Expand Down Expand Up @@ -259,15 +230,12 @@ function updateFiltersCounts(countsAfterFiltration) {
docCounts[filterKey] += value.key !== constants.MISSING_KEY_VALUE
? value.doc_count
: 0;
const controlId = util.getOptionId(
controlKey,
prepareOptionName(value.fullKey, filterKey)
);
const controlView = $$(controlId);
if (controlView) {
_setDiagnosisFilterCounts(controlView, value.doc_count, currentCount);
const optionId = prepareOptionName(value.fullKey, filterKey);
const option = treeView?.getItem(optionId);
if (option) {
_setDiagnosisFilterCounts(treeView, option, value.doc_count, currentCount);
if (!displayDiagnosis.find(item => item === v)) {
hideControl(controlView);
treeView.remove(optionId);
}
}
});
Expand Down
14 changes: 14 additions & 0 deletions sources/styles/pages.less
Original file line number Diff line number Diff line change
Expand Up @@ -1150,6 +1150,20 @@
.collapssible-filter-tree {
padding-left: 0px;
border-width: 0px !important;
padding-left: 19px;
position: relative;
text-transform: uppercase;
cursor: pointer;
}

.filter-tree-table {
.webix_tree_open::before {
content: "\F027" !important;
}

.webix_tree_close::before {
content: "\F028" !important;
}
}

.select-all-template,
Expand Down
Loading

0 comments on commit 8161ae2

Please sign in to comment.