-
Notifications
You must be signed in to change notification settings - Fork 0
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 #109 from ImageMarkup/isic-ui-search-dropdown
Isic UI search dropdown
- Loading branch information
Showing
12 changed files
with
263 additions
and
10 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
const facets = {}; | ||
|
||
function getFacets() { | ||
return facets; | ||
} | ||
|
||
function addFacet(id, values) { | ||
facets[id] = values; | ||
} | ||
|
||
function getFacetOptions(facet) { | ||
return facet.options; | ||
} | ||
|
||
const facetsModel = { | ||
getFacets, | ||
addFacet, | ||
getFacetOptions, | ||
}; | ||
|
||
export default facetsModel; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import constants from "../../constants"; | ||
import appliedFiltersModel from "../../models/appliedFilters"; | ||
import util from "../../utils/util"; | ||
|
||
function attachEvents(searchSuggest, searchInput, toggleButton) { | ||
const suggestList = searchSuggest.getList(); | ||
|
||
const foundCountTemplateID = webix.uid(); | ||
|
||
const foundCountTemplateConfig = { | ||
view: "template", | ||
css: "gallery__filter_suggest_result-template", | ||
id: foundCountTemplateID, | ||
template: obj => `Match ${obj.count} values`, | ||
}; | ||
|
||
const foundCountPopup = webix.ui({ | ||
view: "popup", | ||
css: "gallery__filter_suggest_result-popup", | ||
id: webix.uid(), | ||
width: searchSuggest.config.width, | ||
height: 50, | ||
body: foundCountTemplateConfig, | ||
}); | ||
|
||
const foundCountTemplate = webix.$$(foundCountTemplateID); | ||
|
||
searchSuggest.attachEvent("onBeforeShow", () => { | ||
const searchValue = searchInput.getValue(); | ||
if (searchValue.length < 3 || toggleButton.getValue() === 1) { | ||
searchSuggest.hide(); | ||
return false; | ||
} | ||
return true; | ||
}); | ||
|
||
|
||
suggestList.detachEvent("onItemClick"); | ||
|
||
suggestList.attachEvent("onItemClick", (id, event) => { | ||
const item = suggestList.getItem(id); | ||
const controlId = util.getOptionId(item.key, item.value); | ||
/** @type {webix.ui.checkbox} */ | ||
const control = $$(controlId); | ||
if (control) { | ||
const controlValue = control.getValue(); | ||
control.setValue(!controlValue); | ||
} | ||
if (!event.metaKey && !event.ctrlKey) { | ||
suggestList.hide(); | ||
} | ||
}); | ||
|
||
searchSuggest.attachEvent("onShow", () => { | ||
const filters = appliedFiltersModel.getFiltersArray(); | ||
const suggestData = suggestList.serialize(); | ||
const selectedItems = []; | ||
filters.forEach((f) => { | ||
const found = suggestData.find((item) => { | ||
if (f.id === item.id) { | ||
return true; | ||
} | ||
return false; | ||
}); | ||
if (found) { | ||
selectedItems.push(f.id); | ||
} | ||
}); | ||
suggestList.blockEvent(); | ||
suggestList.select(selectedItems); | ||
suggestList.unblockEvent(); | ||
foundCountTemplate.parse({count: suggestList.count()}); | ||
foundCountPopup.define("width", searchSuggest.config.width); | ||
foundCountPopup.resize(); | ||
foundCountPopup.show(searchSuggest.getNode()); | ||
searchInput.focus(); | ||
}); | ||
} | ||
|
||
const searchSuggestService = { | ||
attachEvents, | ||
}; | ||
|
||
export default searchSuggestService; |
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,51 @@ | ||
import constants from "../../constants"; | ||
import collectionsModel from "../../models/collectionsModel"; | ||
import facetsModel from "../../models/facets"; | ||
import imagesFilters from "../../models/imagesFilters"; | ||
|
||
const filterSuggestions = []; | ||
|
||
function getSuggestionsForFilter() { | ||
return filterSuggestions; | ||
} | ||
|
||
async function buildSuggestionsForFilter() { | ||
const facets = facetsModel.getFacets(); | ||
const collections = collectionsModel.getPinnedCollections(); | ||
const newSuggestions = []; | ||
const filtersData = await imagesFilters.getFiltersData(); | ||
const filterArray = []; | ||
filterArray.push(...filtersData.map(f => f.data).flat(Infinity)); | ||
const facetsKeys = filterArray.map(f => f.id); | ||
facetsKeys.forEach((key) => { | ||
const values = facets[key].map((v) => { | ||
if (key === constants.COLLECTION_KEY) { | ||
const item = collections.find(c => c.id === v); | ||
return { | ||
id: `${key}|${v}`, | ||
key, | ||
value: item?.name ?? "", | ||
optionId: v, | ||
isCollection: true, | ||
}; | ||
} | ||
return { | ||
id: `${key}|${v}`, | ||
key, | ||
value: v, | ||
}; | ||
}).flat(); | ||
newSuggestions.push(...values); | ||
}); | ||
if (newSuggestions.length > 0) { | ||
filterSuggestions.length = 0; | ||
filterSuggestions.push(...newSuggestions); | ||
} | ||
} | ||
|
||
const suggestService = { | ||
buildSuggestionsForFilter, | ||
getSuggestionsForFilter, | ||
}; | ||
|
||
export default suggestService; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
.gallery__filter_suggest_result-template { | ||
font-size: large; | ||
background-color: @btn; | ||
color: @white-txt; | ||
.webix_template { | ||
text-align: center; | ||
} | ||
} |
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
Oops, something went wrong.