@@ -33,10 +33,6 @@ qx.Class.define("osparc.dashboard.SearchBarFilterProjects", {
3333
3434 this . __buildLayout ( ) ;
3535
36- // this.__buildFiltersMenu();
37-
38- // this.__attachEventHandlers();
39-
4036 this . __currentFilter = null ;
4137
4238 qx . core . Init . getApplication ( ) . getRoot ( ) . add ( this ) ;
@@ -142,292 +138,5 @@ qx.Class.define("osparc.dashboard.SearchBarFilterProjects", {
142138 } ; ;
143139 document . addEventListener ( "mousedown" , tapListener ) ;
144140 } ,
145-
146- __buildFiltersMenu : function ( ) {
147- if ( this . __filtersMenu === null ) {
148- this . __filtersMenu = new qx . ui . menu . Menu ( ) ;
149- }
150- const menu = this . __filtersMenu ;
151- menu . removeAll ( ) ;
152-
153- const sharedWithButton = new qx . ui . menu . Button ( this . tr ( "Shared with" ) , "@FontAwesome5Solid/share-alt/12" ) ;
154- this . __addSharedWith ( sharedWithButton ) ;
155- menu . add ( sharedWithButton ) ;
156-
157- if ( [ "study" , "template" ] . includes ( this . __resourceType ) ) {
158- const tagsButton = new qx . ui . menu . Button ( this . tr ( "Tags" ) , "@FontAwesome5Solid/tags/12" ) ;
159- osparc . utils . Utils . setIdToWidget ( tagsButton , "searchBarFilter-tags-button" ) ;
160- this . __addTags ( tagsButton ) ;
161- menu . add ( tagsButton ) ;
162-
163- const classifiersButton = new qx . ui . menu . Button ( this . tr ( "Classifiers" ) , "@FontAwesome5Solid/search/12" ) ;
164- this . __addClassifiers ( classifiersButton ) ;
165- menu . add ( classifiersButton ) ;
166- }
167-
168- if ( this . __resourceType === "service" ) {
169- const appTypeButton = new qx . ui . menu . Button ( this . tr ( "App Type" ) , "@FontAwesome5Solid/cogs/12" ) ;
170- this . __addAppTypes ( appTypeButton ) ;
171- menu . add ( appTypeButton ) ;
172- }
173- } ,
174-
175- __attachEventHandlers : function ( ) {
176- const textField = this . getChildControl ( "text-field" ) ;
177- textField . addListener ( "tap" , ( ) => this . __showFilterMenu ( ) , this ) ;
178- textField . addListener ( "deactivate" , ( ) => this . __hideFilterMenu ( ) , this ) ;
179- textField . addListener ( "keypress" , e => {
180- if ( e . getKeyIdentifier ( ) === "Enter" ) {
181- this . __filter ( ) ;
182- } else {
183- this . __hideFilterMenu ( ) ;
184- }
185- } , this ) ;
186- textField . addListener ( "changeValue" , ( ) => this . __filter ( ) , this ) ;
187-
188- const resetButton = this . getChildControl ( "reset-button" ) ;
189- resetButton . addListener ( "execute" , ( ) => this . __resetFilters ( ) , this ) ;
190-
191- osparc . store . Store . getInstance ( ) . addListener ( "changeTags" , ( ) => this . __buildFiltersMenu ( ) , this ) ;
192- } ,
193-
194- getTextFilterValue : function ( ) {
195- return this . getChildControl ( "text-field" ) . getValue ( ) ;
196- } ,
197-
198- __showFilterMenu : function ( ) {
199- if ( this . getTextFilterValue ( ) ) {
200- return ;
201- }
202-
203- const textField = this . getChildControl ( "text-field" ) ;
204- const element = textField . getContentElement ( ) . getDomElement ( ) ;
205- const {
206- top,
207- left
208- } = qx . bom . element . Location . get ( element ) ;
209- this . __filtersMenu . setLayoutProperties ( {
210- top : top + 30 ,
211- left : left
212- } ) ;
213-
214- this . __filtersMenu . show ( ) ;
215- } ,
216-
217- __hideFilterMenu : function ( ) {
218- this . __filtersMenu . exclude ( ) ;
219- } ,
220-
221- __addTags : function ( menuButton ) {
222- const tags = osparc . store . Tags . getInstance ( ) . getTags ( ) ;
223- menuButton . setVisibility ( tags . length ? "visible" : "excluded" ) ;
224- if ( tags . length ) {
225- const tagsMenu = new qx . ui . menu . Menu ( ) ;
226- osparc . utils . Utils . setIdToWidget ( tagsMenu , "searchBarFilter-tags-menu" ) ;
227- tags . forEach ( tag => {
228- const tagButton = new qx . ui . menu . Button ( tag . getName ( ) , "@FontAwesome5Solid/tag/12" ) ;
229- tagButton . getChildControl ( "icon" ) . setTextColor ( tag . getColor ( ) ) ;
230- tagsMenu . add ( tagButton ) ;
231- tagButton . addListener ( "execute" , ( ) => this . addTagActiveFilter ( tag ) , this ) ;
232- } ) ;
233- menuButton . setMenu ( tagsMenu ) ;
234- }
235- } ,
236-
237- __addSharedWith : function ( menuButton ) {
238- const options = this . self ( ) . getSharedWithOptions ( this . __resourceType ) ;
239- const sharedWithMenu = new qx . ui . menu . Menu ( ) ;
240- const sharedWithRadioGroup = new qx . ui . form . RadioGroup ( ) ;
241- options . forEach ( ( option , idx ) => {
242- const button = new qx . ui . menu . RadioButton ( option . label ) ;
243- sharedWithMenu . add ( button ) ;
244- button . addListener ( "execute" , ( ) => this . setSharedWithActiveFilter ( option . id , option . label ) , this ) ;
245- sharedWithRadioGroup . add ( button ) ;
246- // preselect show-all
247- if ( idx === 0 ) {
248- sharedWithRadioGroup . setSelection ( [ button ] ) ;
249- }
250- } ) ;
251- menuButton . setMenu ( sharedWithMenu ) ;
252- } ,
253-
254- __addClassifiers : function ( menuButton ) {
255- const classifiers = osparc . store . Store . getInstance ( ) . getClassifiers ( ) ;
256- menuButton . setVisibility ( classifiers && classifiers . length ? "visible" : "excluded" ) ;
257- if ( classifiers && classifiers . length ) {
258- const classifiersMenu = new qx . ui . menu . Menu ( ) ;
259- classifiers . forEach ( classifier => {
260- const classifierButton = new qx . ui . menu . Button ( classifier . display_name ) ;
261- classifiersMenu . add ( classifierButton ) ;
262- classifierButton . addListener ( "execute" , ( ) => this . __addChip ( "classifier" , classifier . classifier , classifier . display_name ) , this ) ;
263- } ) ;
264- menuButton . setMenu ( classifiersMenu ) ;
265- }
266- } ,
267-
268- __addAppTypes : function ( menuButton ) {
269- const serviceTypeMenu = new qx . ui . menu . Menu ( ) ;
270- menuButton . setMenu ( serviceTypeMenu ) ;
271-
272- const iconSize = 14 ;
273- const serviceTypes = osparc . service . Utils . TYPES ;
274- Object . keys ( serviceTypes ) . forEach ( serviceId => {
275- if ( ! [ "computational" , "dynamic" ] . includes ( serviceId ) ) {
276- return ;
277- }
278- const serviceType = serviceTypes [ serviceId ] ;
279- const serviceTypeButton = new qx . ui . menu . Button ( serviceType . label , serviceType . icon + iconSize ) ;
280- serviceTypeButton . getChildControl ( "icon" ) . set ( {
281- alignX : "center" ,
282- } ) ;
283- serviceTypeMenu . add ( serviceTypeButton ) ;
284- serviceTypeButton . addListener ( "execute" , ( ) => this . __addChip ( "app-type" , serviceId , serviceType . label ) , this ) ;
285- } ) ;
286-
287- // hypertools filter
288- const hypertoolTypeButton = new qx . ui . menu . Button ( "Hypertools" , null ) ;
289- hypertoolTypeButton . exclude ( ) ;
290- osparc . store . Templates . getHypertools ( )
291- . then ( hypertools => {
292- hypertoolTypeButton . setVisibility ( hypertools . length > 0 ? "visible" : "excluded" ) ;
293- } ) ;
294- osparc . utils . Utils . replaceIconWithThumbnail ( hypertoolTypeButton , osparc . data . model . StudyUI . HYPERTOOL_ICON , 18 ) ;
295- serviceTypeMenu . add ( hypertoolTypeButton ) ;
296- hypertoolTypeButton . addListener ( "execute" , ( ) => this . __addChip ( "app-type" , "hypertool" , "Hypertools" ) , this ) ;
297- } ,
298-
299- addTagActiveFilter : function ( tag ) {
300- this . __addChip ( "tag" , tag . getTagId ( ) , tag . getName ( ) ) ;
301- } ,
302-
303- setTagsActiveFilter : function ( tagIds ) {
304- const tags = osparc . store . Tags . getInstance ( ) . getTags ( ) ;
305- tags . forEach ( tag => {
306- const tagId = tag . getTagId ( ) ;
307- if ( tagIds . includes ( tagId ) ) {
308- this . __addChip ( "tag" , tagId , tag . getName ( ) ) ;
309- } else {
310- this . __removeChip ( "tag" , tagId , tag . getName ( ) ) ;
311- }
312- } ) ;
313- } ,
314-
315-
316- setSharedWithActiveFilter : function ( optionId , optionLabel ) {
317- this . __removeChips ( "shared-with" ) ;
318- if ( optionId === "show-all" ) {
319- this . __filter ( ) ;
320- } else {
321- this . __addChip ( "shared-with" , optionId , optionLabel ) ;
322- }
323- } ,
324-
325- setAppTypeActiveFilter : function ( appType , optionLabel ) {
326- this . __removeChips ( "app-type" ) ;
327- if ( appType && optionLabel ) {
328- this . __addChip ( "app-type" , appType , optionLabel ) ;
329- } else {
330- this . __filter ( ) ;
331- }
332- } ,
333-
334- // this widget pops up a larger widget with all filters visible
335- // and lets users search between projects, templates, public projects and, eventually, files
336- popUpSearchBarFilter : function ( ) {
337-
338- } ,
339-
340- __addChip : function ( type , id , label ) {
341- const activeFilter = this . getChildControl ( "active-filters" ) ;
342- const chipFound = activeFilter . getChildren ( ) . find ( chip => chip . type === type && chip . id === id ) ;
343- if ( chipFound ) {
344- return ;
345- }
346- const chip = this . __createChip ( type , id , label ) ;
347- activeFilter . add ( chip ) ;
348- this . __filter ( ) ;
349- } ,
350-
351- __createChip : function ( chipType , chipId , chipLabel ) {
352- const chipButton = new qx . ui . form . Button ( ) . set ( {
353- label : osparc . utils . Utils . capitalize ( chipType ) + " = '" + chipLabel + "'" ,
354- icon : "@MaterialIcons/close/12" ,
355- toolTipText : chipLabel ,
356- appearance : "chip-button"
357- } ) ;
358- chipButton . type = chipType ;
359- chipButton . id = chipId ;
360- chipButton . addListener ( "execute" , ( ) => this . __removeChip ( chipType , chipId ) , this ) ;
361- return chipButton ;
362- } ,
363-
364- __removeChip : function ( type , id ) {
365- const activeFilter = this . getChildControl ( "active-filters" ) ;
366- const chipFound = activeFilter . getChildren ( ) . find ( chip => chip . type === type && chip . id === id ) ;
367- if ( chipFound ) {
368- activeFilter . remove ( chipFound ) ;
369- this . __filter ( ) ;
370- }
371- } ,
372-
373- __removeChips : function ( type ) {
374- const activeFilter = this . getChildControl ( "active-filters" ) ;
375- if ( type ) {
376- const chipsFounds = activeFilter . getChildren ( ) . filter ( chip => chip . type === type ) ;
377- for ( let i = chipsFounds . length - 1 ; i >= 0 ; i -- ) {
378- activeFilter . remove ( chipsFounds [ i ] ) ;
379- }
380- } else {
381- activeFilter . removeAll ( ) ;
382- }
383- } ,
384-
385- resetFilters : function ( ) {
386- this . __removeChips ( ) ;
387- this . getChildControl ( "text-field" ) . resetValue ( ) ;
388- } ,
389-
390- __resetFilters : function ( ) {
391- this . resetFilters ( ) ;
392- this . __filter ( ) ;
393- } ,
394-
395- getFilterData : function ( ) {
396- const filterData = {
397- tags : [ ] ,
398- classifiers : [ ] ,
399- sharedWith : null ,
400- appType : null ,
401- text : ""
402- } ;
403- const textFilter = this . getTextFilterValue ( ) ;
404- filterData [ "text" ] = textFilter ? textFilter : "" ;
405- this . getChildControl ( "active-filters" ) . getChildren ( ) . forEach ( chip => {
406- switch ( chip . type ) {
407- case "tag" :
408- filterData . tags . push ( chip . id ) ;
409- break ;
410- case "classifier" :
411- filterData . classifiers . push ( chip . id ) ;
412- break ;
413- case "shared-with" :
414- filterData . sharedWith = chip . id === "show-all" ? null : chip . id ;
415- break ;
416- case "app-type" :
417- filterData . appType = chip . id ;
418- break ;
419- }
420- } ) ;
421- return filterData ;
422- } ,
423-
424- __filter : function ( ) {
425- const filterData = this . getFilterData ( ) ;
426- if ( JSON . stringify ( this . __currentFilter ) !== JSON . stringify ( filterData ) ) {
427- this . __currentFilter = filterData ;
428- this . fireDataEvent ( "filterChanged" , filterData ) ;
429- this . _filterChange ( filterData ) ;
430- }
431- }
432141 }
433142} ) ;
0 commit comments