@@ -5,7 +5,6 @@ import constants from "../../constants";
55import appliedFilterModel from "../../models/appliedFilters" ;
66import collectionsModel from "../../models/collectionsModel" ;
77import diagnosisModel from "../../models/diagnosis" ;
8- import facetsModel from "../../models/facets" ;
98import galleryImagesUrls from "../../models/galleryImagesUrls" ;
109import filtersData from "../../models/imagesFilters" ;
1110import 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 = / ^ d i a g n o s i s _ \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 = / ^ d i a g n o s i s _ \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