Skip to content

Commit 19919a6

Browse files
authored
Merge pull request #121 from ImageMarkup/fix-collections-filtration
2 parents 61ab395 + 862ff7b commit 19919a6

File tree

14 files changed

+1060
-866
lines changed

14 files changed

+1060
-866
lines changed

.eslintrc.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ module.exports = {
4141
["jet-locales", "./sources/locales"],
4242
["app-templates", "./sources/views/templates"],
4343
["app-services", "./sources/services"],
44-
["app-components", "./sources/views/components"]
44+
["app-components", "./sources/views/components"],
45+
["app-models", "./sources/models"]
4546
]
4647
}
4748
}

jsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"app-templates/*": ["views/templates/*"],
88
"app-services/*": ["services/*"],
99
"app-components/*": ["views/components/*"],
10+
"app-models/*": ["models/*"],
1011
}
1112
},
1213
"include": ["sources/**/*"]

package-lock.json

Lines changed: 971 additions & 587 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@
3636
"less-loader": "^10.1.0",
3737
"mini-css-extract-plugin": "^2.4.2",
3838
"terser-webpack-plugin": "^5.2.4",
39-
"webpack": "^5.58.1",
40-
"webpack-cli": "^4.9.0",
39+
"webpack": "^5.99.9",
40+
"webpack-cli": "^6.0.1",
4141
"webpack-dev-server": "^5.2.2"
4242
},
4343
"dependencies": {

sources/models/appliedFilters.js

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import constants from "../constants";
22
import util from "../utils/util";
3-
import collectionsModel from "./collectionsModel";
43
import state from "./state";
54

65
const appliedFilters = new webix.DataCollection();
@@ -521,14 +520,7 @@ function getFiltersFromURL(filtersArray) {
521520
return data;
522521
}
523522
return null;
524-
}
525-
else if (filter.includes(constants.COLLECTION_KEY)) {
526-
const pinnedCollections = collectionsModel.getPinnedCollections();
527-
const id = Number(filter.substring(filter.indexOf("|") + 1));
528-
const collection = pinnedCollections?.find(c => c.id === id);
529-
filterId = `${constants.COLLECTION_KEY}|${collection?.name}`;
530-
}
531-
else {
523+
} else {
532524
filterId = filter;
533525
}
534526
const control = $$(filterId);

sources/models/facets.js

Lines changed: 0 additions & 21 deletions
This file was deleted.

sources/models/imagesFilters.js

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -198,37 +198,6 @@ function getFiltersDataValues() {
198198
return filtersDataValues;
199199
}
200200

201-
function isNeedShow(datasetId) {
202-
const hiddenDatasetIds = [
203-
"5a74e97a11659731f017fabf", // Dermoscopedia (CC-0)
204-
"5a74e98611659731f017fac3" // Dermoscopedia (CC-BY-NC)
205-
];
206-
return hiddenDatasetIds.indexOf(datasetId) === -1;
207-
}
208-
209-
function prepareDatasetFilterData(dataset) {
210-
const result = [];
211-
state.datasetMapForFilters = {};
212-
const options = [];
213-
dataset.forEach((item) => {
214-
if (isNeedShow(item._id)) {
215-
state.datasetMapForFilters[item._id] = item.name;
216-
/* we set id as options value.
217-
we will replace it with "name" from state.datasetForFilters
218-
before rendering checkboxes */
219-
options.push(item._id);
220-
}
221-
});
222-
result.push({
223-
id: "meta.datasetId",
224-
name: "Dataset",
225-
type: "checkbox",
226-
datatype: "objectid",
227-
options
228-
});
229-
return result;
230-
}
231-
232201
function getFiltersData(forceRebuild) {
233202
return new Promise((resolve) => {
234203
// we should rewrite the last item in filtersData (it is place for Database Attributes)

sources/services/ajaxActions.js

Lines changed: 33 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import axios from "axios";
22

3-
import state from "../models/state";
3+
import state from "app-models/state";
4+
45
import logger from "../utils/logger";
56
import util from "../utils/util";
67

@@ -143,61 +144,41 @@ class AjaxActions {
143144

144145
// instead of getHistogram
145146
// New API
146-
getFacets(sourceParams) {
147-
const conditions = sourceParams && sourceParams.conditions ? sourceParams.conditions : null;
148-
const collections = sourceParams && sourceParams.collections ? sourceParams.collections : "";
147+
async getFacets(sourceParams = {}) {
148+
const {conditions = null, collections = ""} = sourceParams;
149149
const params = {
150150
query: conditions,
151151
collections
152152
};
153-
return this._ajaxGet(`${API_URL}images/facets/`, params)
154-
.then((result) => {
155-
const facets = this._parseData(result);
156-
const ids = Object.keys(facets);
157-
ids.forEach((id) => {
158-
facets[id].buckets = facets[id].buckets.map((bucket) => {
159-
if (bucket.key_as_string) {
160-
return {
161-
...bucket,
162-
key: bucket.key_as_string
163-
};
164-
}
165-
return bucket;
166-
});
167-
if (id === "clin_size_long_diam_mm"
168-
|| id === "age_approx") {
169-
let interval;
170-
switch (id) {
171-
case "clin_size_long_diam_mm": {
172-
interval = 10;
173-
break;
174-
}
175-
case "age_approx": {
176-
interval = 5;
177-
break;
178-
}
179-
case "mel_thick_mm": {
180-
interval = 0.5;
181-
break;
182-
}
183-
default: {
184-
break;
185-
}
186-
}
187-
facets[id].buckets = facets[id].buckets.map((bucket) => {
188-
const newBucket = {
189-
...bucket,
190-
key: `[${bucket.key}-${bucket.key + interval})`,
191-
from: bucket.key,
192-
to: `${bucket.key + interval}`
193-
};
194-
return newBucket;
195-
});
196-
}
197-
});
198-
return facets;
199-
})
200-
.catch(parseError);
153+
154+
try {
155+
const result = await this._ajaxGet(`${API_URL}images/facets/`, params);
156+
const facets = this._parseData(result);
157+
const intervalMap = {
158+
clin_size_long_diam_mm: 10,
159+
age_approx: 5,
160+
};
161+
162+
Object.entries(facets).forEach(([id, facet]) => {
163+
facet.buckets = facet.buckets.map(bucket => ({
164+
...bucket,
165+
key: bucket.key_as_string ?? bucket.key
166+
}));
167+
168+
if (intervalMap[id]) {
169+
const interval = intervalMap[id];
170+
facet.buckets = facet.buckets.map(bucket => ({
171+
...bucket,
172+
key: `[${bucket.key}-${bucket.key + interval})`,
173+
from: bucket.key,
174+
to: bucket.key + interval
175+
}));
176+
}
177+
});
178+
return facets;
179+
} catch (error) {
180+
return parseError(error);
181+
}
201182
}
202183

203184
getAllImages(sourceParams, annotatedImages) {

sources/services/gallery/filter.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,7 @@ function updateFiltersFormControl(data) {
116116
case "rangeCheckbox":
117117
case "checkbox":
118118
{
119-
const controlId = util.getOptionId(data.key, data.value);
120-
const control = $$(controlId);
119+
const control = $$(data.id);
121120
if (control) {
122121
// we do not need to call onChange event for the control. so we block event
123122
control.blockEvent();

sources/services/gallery/gallery.js

Lines changed: 37 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import constants from "../../constants";
55
import appliedFilterModel from "../../models/appliedFilters";
66
import collectionsModel from "../../models/collectionsModel";
77
import diagnosisModel from "../../models/diagnosis";
8-
import facetsModel from "../../models/facets";
98
import galleryImagesUrls from "../../models/galleryImagesUrls";
109
import filtersData from "../../models/imagesFilters";
1110
import lesionsModel from "../../models/lesionsModel";
@@ -1139,15 +1138,6 @@ class GalleryService {
11391138
state.imagesTotalCounts = {};
11401139
state.imagesTotalCounts.passedFilters = {};
11411140
const images = await ajax.getImages();
1142-
const pinnedCollectionOptions = {
1143-
limit: 0,
1144-
pinned: true,
1145-
sort: "name",
1146-
};
1147-
const pinnedCollectionsData = await ajax.getCollections(pinnedCollectionOptions);
1148-
collectionsModel.clearPinnedCollections();
1149-
collectionsModel.setPinnedCollections(pinnedCollectionsData);
1150-
11511141
state.imagesTotalCounts.passedFilters.count = images.count ? images.count : 0;
11521142
this._updateContentHeaderTemplate(
11531143
{
@@ -1157,36 +1147,9 @@ class GalleryService {
11571147
}
11581148
);
11591149
this._updatePagerCount(state.imagesTotalCounts.passedFilters.count);
1160-
const diagnosisRegex = /^diagnosis_\d$/;
1161-
const facets = await ajax.getFacets();
1162-
const facetsIds = Object.keys(facets);
1163-
facetsIds.forEach((id) => {
1164-
state.imagesTotalCounts[id] = webix.copy(facets[id].buckets);
1165-
if (id !== constants.COLLECTION_KEY) {
1166-
state.imagesTotalCounts[id].push({
1167-
key: constants.MISSING_KEY_VALUE,
1168-
doc_count: facets[id]?.meta?.missing_count
1169-
});
1170-
}
1171-
if (id === constants.COLLECTION_KEY) {
1172-
state.imagesTotalCounts[id].length = 0;
1173-
pinnedCollectionsData.results.forEach((pc) => {
1174-
state.imagesTotalCounts[id].push({
1175-
key: pc.id,
1176-
name: pc.name,
1177-
});
1178-
});
1179-
}
1180-
if (diagnosisRegex.test(id)) {
1181-
diagnosisModel.addDisplayDiagnosis(facets[id].buckets.map(d => d.key));
1182-
}
1183-
const facetValues = state.imagesTotalCounts[id].map(
1184-
f => f.key
1185-
);
1186-
facetsModel.addFacet(id, facetValues);
1187-
});
1150+
await this._loadFacetsAndCollectionsIntoState();
11881151
if (this._searchSuggest) {
1189-
await suggestService.buildSuggestionsForFilter(this._searchSuggest);
1152+
await suggestService.buildSuggestionsForFilter();
11901153
const suggestions = suggestService.getSuggestionsForFilter();
11911154
this._searchSuggest.getList().parse(suggestions);
11921155
}
@@ -1244,6 +1207,38 @@ class GalleryService {
12441207
}
12451208
}
12461209

1210+
async _loadFacetsAndCollectionsIntoState() {
1211+
const pinnedCollectionOptions = {
1212+
limit: 0,
1213+
pinned: true,
1214+
sort: "name",
1215+
};
1216+
const pinnedCollectionsData = await ajax.getCollections(pinnedCollectionOptions);
1217+
collectionsModel.clearPinnedCollections();
1218+
collectionsModel.setPinnedCollections(pinnedCollectionsData);
1219+
state.imagesTotalCounts[constants.COLLECTION_KEY] = pinnedCollectionsData.results.map(pc => ({
1220+
key: pc.id,
1221+
name: pc.name,
1222+
}));
1223+
1224+
const diagnosisRegex = /^diagnosis_\d$/;
1225+
const facets = await ajax.getFacets();
1226+
Object.entries(facets).forEach(([id, facet]) => {
1227+
state.imagesTotalCounts[id] = [
1228+
...webix.copy(facet.buckets),
1229+
{
1230+
key: constants.MISSING_KEY_VALUE,
1231+
doc_count: facet?.meta?.missing_count || 0,
1232+
}
1233+
];
1234+
1235+
if (diagnosisRegex.test(id)) {
1236+
const diagnosisKeys = facet.buckets.map(bucket => bucket.key);
1237+
diagnosisModel.addDisplayDiagnosis(diagnosisKeys);
1238+
}
1239+
});
1240+
}
1241+
12471242
async _reload(offsetSource, limitSource) {
12481243
if (await state.auth.isTermsOfUseAccepted()) {
12491244
let limit = limitSource || this._pager.data.size;
@@ -1567,6 +1562,9 @@ class GalleryService {
15671562
}
15681563

15691564
_clearActiveListData(clearModifyObjects) {
1565+
this._activeCartList.data.each(item => {
1566+
item.imageShown = false;
1567+
});
15701568
this._activeCartList.clearAll();
15711569
if (!clearModifyObjects) modifiedObjects.clearAll();
15721570
this._view.$scope.hideList();

0 commit comments

Comments
 (0)