diff --git a/config/plugins/webhooks/demo/search/static/script.js b/config/plugins/webhooks/demo/search/static/script.js index b9713dae8aa..6a54efb0c51 100644 --- a/config/plugins/webhooks/demo/search/static/script.js +++ b/config/plugins/webhooks/demo/search/static/script.js @@ -38,7 +38,8 @@ $(document).ready(function() { e.stopPropagation(); if ( $( '.search-screen-overlay' ).is( ':visible' ) ){ self.removeOverlay(); - } else{ + } + else { self.clearSearchResults(); self.showOverlay(); self.showSearchResult(); @@ -152,38 +153,38 @@ $(document).ready(function() { /** Search with a filter */ searchWithAFilter: function( self, type, query ) { - switch( type ) { - case "all": - self.searchAllFilters( self, query ); + switch( type ) { + case "all": + self.searchAllFilters( self, query ); break; - case "tools": - self.searchTools( query ); + case "tools": + self.searchTools( query ); break; - case "history": - self.searchHistory( query ); + case "history": + self.searchHistory( query ); break; - case "data_library": - self.searchDataLibrary( query ); + case "data_library": + self.searchDataLibrary( query ); break; case "workflow": self.searchWorkflow( query ); - break; - } + break; + } }, /** Search in all categories */ searchAllFilters: function( self, query ) { - self.clearSearchResults(); - self.setActiveFilter( '.all-filter' ); - self.showSearchResult(); - // Show default links above search results - self.showDefaultLinks(); - // Search for history - self.searchHistory( query ); - // Search for tools - self.searchTools( query ); - // Search for data libraries - self.searchDataLibrary( query ); + self.clearSearchResults(); + self.setActiveFilter( '.all-filter' ); + self.showSearchResult(); + // Show default links above search results + self.showDefaultLinks(); + // Search for history + self.searchHistory( query ); + // Search for tools + self.searchTools( query ); + // Search for data libraries + self.searchDataLibrary( query ); // Search for workflows only when the user is authenticated if( window.Galaxy.user.id ) { self.searchWorkflow( query ); @@ -192,10 +193,10 @@ $(document).ready(function() { /** Search in tools */ searchTools: function( query ) { - var url = Galaxy.root + 'api/tools'; - $.get( url, { q: query }, function ( search_result ) { - toolSearch = new SearchItemsView( { 'tools': search_result } ); - }, "json" ); + var url = Galaxy.root + 'api/tools'; + $.get( url, { q: query }, function ( search_result ) { + toolSearch = new SearchItemsView( { 'tools': search_result } ); + }, "json" ); }, /** Search in history */ @@ -294,17 +295,17 @@ $(document).ready(function() { $el_filter_link = $( '.overlay-filters a' ), active = 'filter-active', inactive = 'filter-inactive'; - if( !$el_filter.hasClass( active ) ) { + if( !$el_filter.hasClass( active ) ) { $el_filter_link.addClass( inactive ).removeClass( active ); - $el_filter.addClass( active ).removeClass( inactive ); - } + $el_filter.addClass( active ).removeClass( inactive ); + } }, /** Apply the text decoration to the search overlay filters */ applyTextDecorations: function( self ) { var active = 'filter-active', inactive = 'filter-inactive'; - $( '.search-results' ).html( "" ); + $( '.search-results' ).html( "" ); $( '.overlay-filters a' ).addClass( inactive ).removeClass( active ); $( self ).removeClass( inactive ).addClass( active ); }, @@ -346,13 +347,13 @@ $(document).ready(function() { switch( type ) { case "tools": data.tools = item[ type ]; - break; + break; case "history": data.history = item[ type ]; - break; + break; case "data_library": data.data_library = item[ type ]; - break; + break; case "workflow": data.workflow = item[ type ]; } @@ -390,8 +391,8 @@ $(document).ready(function() { // If the selected filter has no data data = items[ filter ]; if ( !data || data.length === 0 ) { - this.showEmptySection( $el_search_result ); - return; + this.showEmptySection( $el_search_result ); + return; } // Make individual section this.makeSection( filter, data ); @@ -407,29 +408,29 @@ $(document).ready(function() { makeSection: function( filter, data ) { switch( filter ) { case "tools": - this.makeToolSection( data ); + this.makeToolSection( data ); break; case "history": - this.makeCustomSearchSection( { 'name': 'History', + this.makeCustomSearchSection( { 'name': 'History', 'id': 'history', 'class_name': 'search-section search-history', 'link_class_name': 'history-search-link', 'data': data } ); break; case "data_library": - this.makeCustomSearchSection( { 'name': 'Data Library', + this.makeCustomSearchSection( { 'name': 'Data Library', 'id': 'datalibrary', 'class_name': 'search-section search-datalib', 'link_class_name': 'datalib-search-link', 'data': data } ); break; - case "workflow": - this.makeCustomSearchSection( { 'name': 'Workflow', + case "workflow": + this.makeCustomSearchSection( { 'name': 'Workflow', 'id': 'workflow', 'class_name': 'search-section search-workflow', 'link_class_name': 'workflow-search-link', 'data': data } ); - break; + break; } }, @@ -439,10 +440,10 @@ $(document).ready(function() { self = this; // Loop through the data and make the available sections for( var type in data ) { - if( data[ type ] && data[ type ].length > 0 ) { - has_result = true; - self.makeSection( type, data[type] ); - } + if( data[ type ] && data[ type ].length > 0 ) { + has_result = true; + self.makeSection( type, data[type] ); + } } }, @@ -452,119 +453,118 @@ $(document).ready(function() { localStorageObject = null; localStorageObject = self.getStorageObject( self, window.Galaxy.user.id, type ); if( localStorageObject ) { - _.each( localStorageObject, function ( item, item_key ) { - if( item_key === item_id ) { - present = true; - } - }); - return present; - } + _.each( localStorageObject, function ( item, item_key ) { + if( item_key === item_id ) { + present = true; + } + }); + return present; + } }, /** Create collection of templates of all sections and links for tools */ makeToolSection: function( search_result ) { - var template_dict = [], - tool_template = "", - self = this, - $el_search_result = $( '.search-results' ), + var template_dict = [], + tool_template = "", + self = this, + $el_search_result = $( '.search-results' ), removed_results_key = "removed_results", pinned_results_key = "pinned_results", class_tool_link = "tool-search-link"; - _.each( search_result, function( item ) { - var all_sections = Galaxy.toolPanel.attributes.layout.models; - _.each( all_sections, function( section ) { - if( section.attributes.model_class === "ToolSection" ) { - var all_tools = section.attributes.elems, - is_present = false, - tools_template = "", - section_header_id = "", - section_header_name = ""; - _.each( all_tools, function( tool ) { - if( tool.id === item ) { - var attrs = tool.attributes; - if( !self.checkItemPresent( attrs.id, removed_results_key, self ) ) { - is_present = true; - tools_template = tools_template + self._buildLinkTemplate( attrs.id, - attrs.link, - attrs.name, - attrs.description, - attrs.target, - class_tool_link, - self.checkItemPresent( attrs.id, - pinned_results_key, self ), - attrs.version, - attrs.min_width, - attrs.form_style ); + + _.each( Galaxy.config.toolbox_in_panel, function( section ) { + if( section.model_class === "ToolSection" ) { + var all_tools = section.elems, + is_present = false, + tools_template = "", + section_header_id = "", + section_header_name = ""; + _.each( all_tools, function( tool ) { + if( _.contains( search_result, tool.id ) ) { + var attrs = tool.attributes; + if( !self.checkItemPresent( tool.id, removed_results_key, self ) ) { + is_present = true; + tools_template = tools_template + self._buildLinkTemplate( attrs.id, + attrs.link, + attrs.name, + attrs.description, + attrs.target, + class_tool_link, + self.checkItemPresent( attrs.id, pinned_results_key, self ), + attrs.version, + attrs.min_width, + attrs.form_style ); + } } + }); + if( is_present ) { + section_header_id = section.id; + section_header_name = section.name; + template_dict = self.appendTemplate( template_dict, + section_header_id, + section_header_name, + tools_template ); } - }); - if( is_present ) { - section_header_id = section.attributes.id; - section_header_name = section.attributes.name; - template_dict = self.appendTemplate( template_dict, - section_header_id, - section_header_name, - tools_template ); } - } - else if( section.attributes.model_class === "Tool" || section.attributes.model_class === "DataSourceTool" ) { - var attributes = section.attributes; - if( item === attributes.id ) { - if( !self.checkItemPresent( attributes.id, removed_results_key, self ) ) { - tool_template = tool_template + self._buildLinkTemplate( attributes.id, attributes.link, + else if( section.model_class === "Tool" || section.model_class === "DataSourceTool" ) { + var attributes = section.attributes; + if( item === attributes.id ) { + if( !self.checkItemPresent( attributes.id, removed_results_key, self ) ) { + tool_template = tool_template + self._buildLinkTemplate( attributes.id, attributes.link, attributes.name, attributes.description, attributes.target, class_tool_link, self.checkItemPresent( attributes.id, pinned_results_key, self ), attributes.version, attributes.min_width, attributes.form_style ); + } } } - } }); - }); - // Remove the tool search result section if already present - $el_search_result.find( '.search-tools' ).remove(); - // Make template for sections and tools - self.makeToolSearchResultTemplate( template_dict, tool_template ); + // Remove the tool search result section if already present + $el_search_result.find( '.search-tools' ).remove(); + // Make template for sections and tools + self.makeToolSearchResultTemplate( template_dict, tool_template ); }, /** Append the template or creates a new section */ appendTemplate: function( collection, id, name, text ) { - var is_present = false; - _.each( collection, function( item ) { - if( id === item.id ) { - item.template = item.template + text; - is_present = true; + var is_present = false; + _.each( collection, function( item ) { + if( id === item.id ) { + item.template = item.template + text; + is_present = true; + } + }); + if(!is_present) { + collection.push( { id: id, template: text, name: name } ); } - }); - if(!is_present) { - collection.push( { id: id, template: text, name: name } ); - } - return collection; + return collection; }, /** Register tool search link click */ registerToolLinkClick: function( self ) { - $( ".tool-search-link" ).click(function( e ) { + $( ".tool-search-link" ).click(function( e ) { e.preventDefault(); self.saveMostUsedToolsCount( this, self ); - self.searchedToolLink( self, e ); - }); + self.searchedToolLink( self, e ); + }); $( ".most-used-tools" ).click(function( e ) { e.preventDefault(); self.saveMostUsedToolsCount( this, self ); - self.searchedToolLink( self, e ); - }); + self.searchedToolLink( self, e ); + }); }, /** Save count of the most used tools */ saveMostUsedToolsCount: function( el, self ) { var item = {}; - item = { 'id': $( el ).attr( 'data-id' ), - 'desc': $( el )[0].innerText, - 'link': $( el ).attr( 'href' ), - 'target': $( el ).attr( 'target' ), - 'formstyle': $( el ).attr( 'data-formstyle' ), - 'version': $( el ).attr( 'data-version' ) }; + item = { + 'id': $( el ).attr( 'data-id' ), + 'desc': $( el )[0].innerText, + 'link': $( el ).attr( 'href' ), + 'target': $( el ).attr( 'target' ), + 'formstyle': $( el ).attr( 'data-formstyle' ), + 'version': $( el ).attr( 'data-version' ) + }; self.setStorageObject( self, window.Galaxy.user.id, 'most_used_tools', item, 1 ); }, @@ -577,7 +577,7 @@ $(document).ready(function() { if( $el_removeditems.children().length === 0 ) { $el_removeditems.append( self._templateNoItems() ); } - }); + }); // Register the click of trash icon in elements of favorites section $( '.remove-fav' ).click(function( e ) { var $el_favourites = $( '.fav-header' ), @@ -599,13 +599,13 @@ $(document).ready(function() { $el_remove_item.removeClass( 'hide' ).addClass( 'show' ); } }); - }); + }); }, /** Remove items from data storage for trash icon */ removeItems: function( self, _self, e, type ) { e.preventDefault(); - e.stopPropagation(); + e.stopPropagation(); self.removeFromDataStorage( self, $( _self ).parent(), type ); $( _self ).parent().remove(); }, @@ -614,16 +614,16 @@ $(document).ready(function() { registerLinkActionClickEvent: function( self, $el, $el_parent_section ) { // Register click of trash icon in search results // and move item to excluded section - $el.find( ".remove-item" ).click(function( e ) { - e.preventDefault(); - e.stopPropagation(); - self.setStorage( self, $( this ).parent() ); - $( this ).parent().remove(); - // If there are not elements left, remove the section - if( $el_parent_section.find( '.remove-item' ).length === 0 ) { - $el_parent_section.remove(); - } - }); + $el.find( ".remove-item" ).click(function( e ) { + e.preventDefault(); + e.stopPropagation(); + self.setStorage( self, $( this ).parent() ); + $( this ).parent().remove(); + // If there are not elements left, remove the section + if( $el_parent_section.find( '.remove-item' ).length === 0 ) { + $el_parent_section.remove(); + } + }); // Register click of pin icon to add the element to favorites section $el.find( ".pin-item" ).click(function( e ) { var $el_this = $( this ), @@ -632,7 +632,7 @@ $(document).ready(function() { titles_added = 'Added to favourites', class_removeitem = '.remove-item'; e.preventDefault(); - e.stopPropagation(); + e.stopPropagation(); // Toggle between pin and unpin // If pinned, then unpin and vice-versa if( $el_this.hasClass( class_pinned ) ) { @@ -652,7 +652,7 @@ $(document).ready(function() { if( self.getActiveFilter() === "all" ) { self.showPinnedItems( '.fav-header' ); } - }); + }); }, /** Set localstorage for pinned items */ @@ -664,17 +664,17 @@ $(document).ready(function() { /** Build removed links */ showRemovedLinks: function() { - var self = this, + var self = this, $el_removed_result = $( '.removed-items' ), html_text = "", $el_span = null, removed_results_html = null, title_restore_search = "Restore to search"; $el_removed_result.html( "" ); - // Build the removed result from web storage + // Build the removed result from web storage removed_results_html = self.getStorageObject( self, window.Galaxy.user.id, 'removed_results' ); for( item in removed_results_html ) { - html_text = html_text + removed_results_html[ item ]; + html_text = html_text + removed_results_html[ item ]; } // Build html if there is an item if( html_text.length > 0 ) { @@ -686,7 +686,7 @@ $(document).ready(function() { $el_span.removeClass( 'remove-item' ).addClass( 'restore-item' ); // Update the title of the delete icon $el_span.attr( 'title', title_restore_search ); - self.registerRemoveLinkClicks( self ); + self.registerRemoveLinkClicks( self ); } else { $el_removed_result.append( self._templateNoItems() ); @@ -696,9 +696,9 @@ $(document).ready(function() { /** Display pinned items */ showPinnedItems: function( class_name ) { var self = this, - pinned_results = {}, + pinned_results = {}, $el_search_results = $( '.search-results' ), - html_text = "", + html_text = "", fav_header = "", title = 'Remove from favourites'; pinned_results = self.getStorageObject( self, window.Galaxy.user.id, 'pinned_results' ); @@ -770,7 +770,7 @@ $(document).ready(function() { if( html_text.length > 0 ) { used_tools_header = self._buildHeaderTemplate( 'used_tools_header', title, class_name ); $el_most_used_tools_result.append( used_tools_header ); - $el_most_used_tools_result.find( '.used-tools-header' ).append( "
" + html_text + "
" ); + $el_most_used_tools_result.find( '.used-tools-header' ).append( "
" + html_text + "
" ); self.registerToolLinkClick( self ); } }, @@ -916,10 +916,10 @@ $(document).ready(function() { /** Remove the delete item from localstorage */ removeFromDataStorage: function( self, $el, type ) { - var link_id = "", - elem = $el[0].outerHTML; + var link_id = "", + elem = $el[0].outerHTML; // Get the id of the link - link_id = ( $( elem ).attr( 'id' ) ? $( elem ).attr( 'id' ) : $( elem ).attr( 'data-id' ) ); + link_id = ( $( elem ).attr( 'id' ) ? $( elem ).attr( 'id' ) : $( elem ).attr( 'data-id' ) ); // Delete it from web storage self.deleteFromStorage( self, window.Galaxy.user.id, type, link_id ); }, @@ -931,7 +931,7 @@ $(document).ready(function() { /** Set localstorage for the removed links */ setStorage: function( self, $el ) { - self.setLocalStorageForRemovedLinks( self, $el[0].outerHTML ); + self.setLocalStorageForRemovedLinks( self, $el[0].outerHTML ); }, /** Build web storage object based on whether user is logged in */ @@ -949,10 +949,10 @@ $(document).ready(function() { if( !storageObject[ type ] ) { storageObject[ type ] = {}; } - } - else { - storageObject[ type ] = {}; - } + } + else { + storageObject[ type ] = {}; + } // Check for html strings and set element to web storage if( isNaN( elem ) ) { @@ -974,7 +974,7 @@ $(document).ready(function() { } } // Set the object to key - storageType.setItem( key, JSON.stringify( storageObject ) ); + storageType.setItem( key, JSON.stringify( storageObject ) ); }, /** Return the web storage object */ @@ -1011,7 +1011,7 @@ $(document).ready(function() { /** Return links template */ _buildLinkTemplate: function( id, link, name, description, target, cls, isBookmarked, version, min_width, form_style ) { - var template = "", + var template = "", bookmark_class = (isBookmarked ? "pinned-item" : ""), bookmark_title = (isBookmarked ? "Added to favourites" : "Add to favourites") ; template = "" + - ( ( isBookmarked ) ? "" : - " " ) + - name + " " + (description ? description : "") + ""; - return template; + template = template + "'>" + + ( ( isBookmarked ) ? "" : + " " ) + + name + " " + (description ? description : "") + ""; + return template; }, /** Build section header template */ _buildHeaderTemplate: function( id, name, cls ) { - return "
" + name + "
"; + return "
" + name + "
"; }, /** Template for no results for any query */ _templateNoResults: function() { - return '
No results. Please search with different keywords
'; + return '
No results. Please search with different keywords
'; }, /** Template for no items when links are removed */