Adding Recent Searches to a Search Console

You can add the "Recent Searches" menu to any search console. When the user runs a search, the console saves the search parameters. When the user returns to the same view, even after closing and reopening the browser, the console will display saved searches in the menu.

There are limitations on how recent searches work:

  • The list of recent searches is specific to each view. If the user previously ran searches in view A, these searches will be available as recent searches in view A, but not in any other view.
  • The list of recent searches is stored in the browser's client-side storage. Recent searches may not be available depending on the browser security settings.
  • If the user moves to a different workstation, or installs a different browser, the list of recent searches will be empty until the user runs some searches again.

To enable recent searches for a specific search console:

1. Define a menu to display recent searches in the console panel:

<action type="menu" id="recentSearchMenu"> <title>Recent</title> </action>

2. After the view loads, populate the list of searches from search history:

/**
* Displays recent searches in the UI.
*/
displayRecentSearches: function() {
// get the recent searches from the panels's client-side storage
var recentSearches = this.locationFilter.getSidecar().recentSearches;
// clear the menu
var recentSearchMenu = this.locationFilter.actions.get('recentSearchMenu');
recentSearchMenu.clear();
// populate the menu
for (var s = 0; s < recentSearches.length; s++) {
var search = recentSearches[s];
recentSearchMenu.addAction(s, search.getTitle(),
this.onSelectRecentSearch.createDelegate(this, [search]));
}
},

3. When the user another search, add the search restriction to the search history:

/**
* Adds another search to the search history.
*/
addRecentSearch: function() {
var search = this.locationFilter.getFieldRestriction();
search.removeClause('recentSearches');
var sidecar = this.locationFilter.getSidecar();
sidecar.recentSearches.add(search);
sidecar.save();
},

4. When the user selects a search from the menu, run the search:

/**
* Called when the user selects a recent search.
* @param search Ab.view.Restriction.
*/
onSelectRecentSearch: function(search) {
// populate the search console with search values
this.locationFilter.setFieldRestriction(search);
// run the search
this.locationFilter_onFilterLocations();
},

Example: http://localhost:8080/archibus/ab-sp-console.axvw