-
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.
- Loading branch information
1 parent
6c15023
commit c4f8908
Showing
8 changed files
with
180 additions
and
6 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,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 facetsKeys = Object.keys(facets); | ||
const collections = collectionsModel.getAllCollections(); | ||
const newSuggestions = []; | ||
const filtersData = await imagesFilters.getFiltersData(); | ||
const filterArray = []; | ||
filterArray.push(...filtersData.map(f => f.data).flat(Infinity)); | ||
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
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,26 @@ | ||
function getView() { | ||
/** @type {webix.ui.suggestConfig} */ | ||
const view = { | ||
view: "suggest", | ||
width: 70, | ||
yCount: 10, | ||
keyPressTimeout: 500, | ||
body: { | ||
multiselect: true, | ||
}, | ||
}; | ||
|
||
return view; | ||
} | ||
|
||
function getConfig(id) { | ||
const config = getView(); | ||
config.id = id; | ||
return config; | ||
} | ||
|
||
const searchSuggest = { | ||
getConfig, | ||
}; | ||
|
||
export default searchSuggest; |