@@ -42,7 +42,6 @@ export class MedicalSourcesComponent implements OnInit {
4242 uploadedFile : File [ ] = [ ]
4343 uploadErrorMsg : string = ""
4444
45- availableLighthouseBrandList : SourceListItem [ ] = [ ]
4645 searchTermUpdate = new BehaviorSubject < string > ( "" ) ;
4746 status : { [ name : string ] : undefined | "token" | "authorize" } = { }
4847
@@ -54,18 +53,7 @@ export class MedicalSourcesComponent implements OnInit {
5453 // aggregations: undefined,
5554 }
5655
57- //limits that are tied to the current result set.
58- resultLimits : {
59- totalItems : number ,
60- scrollComplete : boolean ,
61- platformTypesBuckets : LighthouseSourceSearchAggregation ,
62- categoryBuckets : LighthouseSourceSearchAggregation ,
63- } = {
64- totalItems : 0 ,
65- scrollComplete : false ,
66- platformTypesBuckets : undefined ,
67- categoryBuckets : undefined
68- }
56+
6957
7058
7159 //source of truth for current state
@@ -89,148 +77,13 @@ export class MedicalSourcesComponent implements OnInit {
8977 private modalService : NgbModal ,
9078
9179 ) {
92- this . filterService . filterChanges . subscribe ( ( filterInfo ) => {
93-
94- //this function should only trigger when there's a change to the filter values -- which requires a new query
95- this . availableLighthouseBrandList = [ ]
96- this . resultLimits . totalItems = 0
97- this . resultLimits . scrollComplete = false
98-
99- //update the form with data from route (don't emit a new patch event), then submit query
100- this . querySources ( filterInfo ?. filter ) . subscribe ( null , null , ( ) => { } )
101- } )
10280 }
10381
10482 ngOnInit ( ) : void {
10583
106-
107- // TODO: handle Callbacks from the source connect window
108- const callbackState = this . activatedRoute . snapshot . paramMap . get ( 'state' )
109- if ( callbackState ) {
110-
111- //get the source state information from localstorage
112- let sourceStateInfo = this . lighthouseApi . getSourceState ( callbackState )
113-
114- //move this source from available to connected (with a progress bar)
115- //remove item from available sources list, add to connected sources.
116- let inProgressAvailableIndex = this . availableLighthouseBrandList . findIndex ( ( item ) => item . brand . id == sourceStateInfo . brand_id )
117- if ( inProgressAvailableIndex > - 1 ) {
118- let sourcesInProgress = this . availableLighthouseBrandList . splice ( inProgressAvailableIndex , 1 ) ;
119- }
120- }
121- //we're not in a callback redirect, lets load the sources
122- if ( this . activatedRoute . snapshot . queryParams [ 'query' ] ) {
123- this . searchTermUpdate . next ( this . activatedRoute . snapshot . queryParams [ 'query' ] )
124- }
125-
126-
127- //register a callback for when the search box content changes
128- this . searchTermUpdate
129- . pipe (
130- debounceTime ( 200 ) ,
131- distinctUntilChanged ( ) ,
132- )
133- . subscribe ( value => {
134- let currentQuery = this . filterService . filterForm . value . query || ""
135- if ( value != null && currentQuery != value ) {
136- this . filterService . filterForm . patchValue ( { query : value } )
137- }
138- } ) ;
139-
140- }
141-
142- private querySources ( filter ?: MedicalSourcesFilter ) : Observable < LighthouseSourceSearch > {
143- if ( this . loading ) {
144- return of ( null )
145- }
146- //TODO: pass filter to function.
147- // this.location.replaceState('/dashboard','', this.filter)
148-
149- if ( ! filter ) {
150- filter = this . filterService . toMedicalSourcesFilter ( this . filterForm . value )
151- }
152-
153-
154- filter . fields = [ "*" ] ;
155- this . loading = true
156- var searchObservable = this . lighthouseApi . searchLighthouseSources ( filter ) ;
157- searchObservable . subscribe ( wrapper => {
158- // this.searchResults = wrapper.hits.hits;
159- this . resultLimits . totalItems = wrapper . hits . total . value ;
160-
161- this . availableLighthouseBrandList = this . availableLighthouseBrandList . concat ( wrapper . hits . hits . map ( ( result ) => {
162- return {
163- brand : result . _source ,
164- searchHighlights : result ?. highlight ?. aliases || [ ]
165- }
166- } ) )
167-
168- //check if scroll is complete.
169- if ( ! wrapper ?. hits || ! wrapper ?. hits ?. hits || wrapper ?. hits ?. hits ?. length == 0 || wrapper ?. hits ?. total ?. value == wrapper ?. hits ?. hits ?. length ) {
170- this . resultLimits . scrollComplete = true ;
171- } else {
172- //change the current Page (but don't cause a new query)
173- this . filterService . filterForm . patchValue ( { searchAfter : wrapper . hits . hits [ wrapper . hits . hits . length - 1 ] . sort . join ( "," ) } , { emitEvent : false } )
174- }
175-
176- // .filter((item) => {
177- // return !this.connectedSourceList.find((connectedItem) => connectedItem.metadata.source_type == item.metadata.source_type)
178- // }))
179-
180-
181- if ( wrapper . aggregations ) {
182- this . resultLimits . platformTypesBuckets = wrapper . aggregations . by_platform_type ;
183- this . resultLimits . categoryBuckets = wrapper . aggregations . by_category ;
184- var currentCategories = this . filterForm . get ( 'categories' ) . value ;
185- this . resultLimits . categoryBuckets . buckets . forEach ( ( bucketData ) => {
186- if ( ! currentCategories . hasOwnProperty ( bucketData . key ) ) {
187- ( this . filterForm . get ( 'categories' ) as FormGroup ) . addControl ( bucketData . key , new FormControl ( false ) )
188- }
189- } )
190-
191- var currentPlatformTypes = this . filterForm . get ( 'platformTypes' ) . value ;
192- this . resultLimits . platformTypesBuckets . buckets . forEach ( ( bucketData ) => {
193- if ( ! currentPlatformTypes . hasOwnProperty ( bucketData . key ) ) {
194- ( this . filterForm . get ( 'platformTypes' ) as FormGroup ) . addControl ( bucketData . key , new FormControl ( false ) )
195- }
196- } )
197-
198- //
199- // this.resultLimits.categoryBuckets.forEach((bucketData) => {
200- // if(!this.globalLimits.categories.some((category) => { return category.id === bucketData.key})){
201- // this.globalLimits.categories.push({
202- // id: bucketData.key,
203- // name: bucketData.key,
204- // group: 'custom'
205- // })
206- // }
207- // })
208-
209- // const fileTypes = <FormGroup>this.filterForm.get('fileTypes');
210- // fileTypes.forEach((option: any) => {
211- // checkboxes.addControl(option.title, new FormControl(true));
212- // });
213- }
214-
215- this . loading = false
216- } ,
217- error => {
218- this . loading = false
219- console . error ( "sources FAILED" , error )
220- } ,
221- ( ) => {
222- this . loading = false
223- }
224- ) ;
225- return searchObservable ;
22684 }
22785
22886
229- public onScroll ( ) : void {
230- if ( ! this . resultLimits . scrollComplete ) {
231- this . querySources ( )
232- }
233- }
23487
23588 //OLD FUNCTIONS
23689 //
@@ -367,17 +220,4 @@ export class MedicalSourcesComponent implements OnInit {
367220 } )
368221 }
369222
370- showRequestHealthSystemModal ( ) : Promise < boolean > {
371- return this . modalService . open ( FormRequestHealthSystemComponent ) . result . then < boolean > (
372- ( result ) => {
373- //convert button clicked, .close()
374- return true
375- }
376- ) . catch ( ( reason ) => {
377- // x or cancel button clicked, .dismiss()
378- return false
379- } )
380- }
381-
382-
383223}
0 commit comments