From 85d44f9f56a8bf58d02cdfd2831dd37fa52cd8b3 Mon Sep 17 00:00:00 2001 From: Matt Borland Date: Fri, 13 Nov 2015 09:01:26 -0700 Subject: [PATCH] Adding Magic Search codebase to Horizon Magic Search is getting integrated into the Horizon codebase as agreed at the Tokyo summit. This Magic Search patch replaces the XStatic package with its own module, and otherwise works as the current XStatic package (changes will be made to accommodate Searchlight features in following patches). This is not simply a copy of what is in GitHub, because there were no tests and little documentation. The code underwent significant restructuring to accommodate the linter and other standards used in Horizon. Change-Id: I9a2b0f3fed1955680a534e8d284da2c8ee68ef16 Implements: blueprint integrate-magic-search --- horizon/karma.conf.js | 3 - .../hz-magic-search-bar.directive.js | 2 +- .../magic-search/hz-magic-search-bar.spec.js | 2 +- .../magic-search/magic-overrides.directive.js | 212 ----- .../magic-overrides.directive.spec.js | 286 ------- .../magic-search/magic-search.controller.js | 383 +++++++++ .../magic-search.controller.spec.js | 803 ++++++++++++++++++ .../magic-search/magic-search.directive.js | 46 + .../widgets/magic-search/magic-search.html | 34 +- .../magic-search/magic-search.module.js | 2 +- .../magic-search/magic-search.service.js | 324 +++++++ .../magic-search/magic-search.service.spec.js | 329 +++++++ .../magic-search/st-magic-search.directive.js | 2 +- .../st-magic-search.directive.spec.js | 2 +- .../framework/widgets/widgets.module.js | 2 +- openstack_dashboard/static_settings.py | 4 - .../templates/horizon/_scripts.html | 2 - requirements.txt | 1 - 18 files changed, 1908 insertions(+), 531 deletions(-) delete mode 100644 horizon/static/framework/widgets/magic-search/magic-overrides.directive.js delete mode 100644 horizon/static/framework/widgets/magic-search/magic-overrides.directive.spec.js create mode 100644 horizon/static/framework/widgets/magic-search/magic-search.controller.js create mode 100644 horizon/static/framework/widgets/magic-search/magic-search.controller.spec.js create mode 100644 horizon/static/framework/widgets/magic-search/magic-search.directive.js create mode 100644 horizon/static/framework/widgets/magic-search/magic-search.service.js create mode 100644 horizon/static/framework/widgets/magic-search/magic-search.service.spec.js diff --git a/horizon/karma.conf.js b/horizon/karma.conf.js index caef3fb0c..27f6248bc 100644 --- a/horizon/karma.conf.js +++ b/horizon/karma.conf.js @@ -100,9 +100,6 @@ module.exports = function (config) { */ '!(horizon)/**/!(*.spec|*.mock).js', - // Magic search requires late ordering due to overriding. - xstaticPath + 'magic_search/data/magic_search.js', - /** * Then, list files for mocks with `mock.js` extension. The order * among them should not be significant. diff --git a/horizon/static/framework/widgets/magic-search/hz-magic-search-bar.directive.js b/horizon/static/framework/widgets/magic-search/hz-magic-search-bar.directive.js index 4839963c6..d091e2111 100644 --- a/horizon/static/framework/widgets/magic-search/hz-magic-search-bar.directive.js +++ b/horizon/static/framework/widgets/magic-search/hz-magic-search-bar.directive.js @@ -15,7 +15,7 @@ 'use strict'; angular - .module('MagicSearch') + .module('horizon.framework.widgets.magic-search') .directive('hzMagicSearchBar', hzMagicSearchBar); hzMagicSearchBar.$inject = ['horizon.framework.widgets.basePath']; diff --git a/horizon/static/framework/widgets/magic-search/hz-magic-search-bar.spec.js b/horizon/static/framework/widgets/magic-search/hz-magic-search-bar.spec.js index 884c8f98a..f4301c636 100644 --- a/horizon/static/framework/widgets/magic-search/hz-magic-search-bar.spec.js +++ b/horizon/static/framework/widgets/magic-search/hz-magic-search-bar.spec.js @@ -23,7 +23,7 @@ beforeEach(module('templates')); beforeEach(module('smart-table')); beforeEach(module('horizon.framework')); - beforeEach(module('MagicSearch')); + beforeEach(module('horizon.framework.widgets.magic-search')); beforeEach(inject(function ($injector) { $compile = $injector.get('$compile'); diff --git a/horizon/static/framework/widgets/magic-search/magic-overrides.directive.js b/horizon/static/framework/widgets/magic-search/magic-overrides.directive.js deleted file mode 100644 index a21d2190b..000000000 --- a/horizon/static/framework/widgets/magic-search/magic-overrides.directive.js +++ /dev/null @@ -1,212 +0,0 @@ -(function () { - 'use strict'; - - angular - .module('MagicSearch') - .directive('magicOverrides', magicOverrides); - - /** - * @ngdoc directive - * @name MagicSearch:magicOverrides - * @description - * A directive to modify and extend Magic Search functionality for use in - * Horizon. - * - * 1. The base Magic Search widget makes Foundation (a responsive front-end - * framework) specific calls in showMenu and hideMenu. In Horizon we use - * Bootstrap, therefore we need to override those methods. - * - * 2. Added 'facetsChanged' listener so we can notify the base Magic Search - * widget that new facets are available. Use this if your table has dynamic - * facets. - * - * 3. Due to the current inconsistencies in the APIs, where some support - * filtering and others do not, we wanted a way to distinguish client-side - * filtering (searching the visible subset) vs server-side filtering - * (another server filter query). - * - * To support this distinction we overrode the methods 'removeFacet' and - * 'initfacets' to emit a 'checkFacets' event. Implementers can add property - * 'isServer' to facets (what triggers the facet icon and color difference). - * - * Each table that incorporates Magic Search is responsible for adding - * property 'isServer' to their facets as they have the intimate knowledge - * of the API supplying the table data. The setting of this property needs - * to be done in the Magic Search supporting JavaScript for each table. - * - * Example: - * Set property 'isServer' on facets that you want to render as server - * facet (server icon, lighter grey color). Note: If the property - * 'isServer' is not set, then facet renders with client icon and darker - * grey color. - * - * scope.$on('checkFacets', function (event, currentSearch) { - * angular.forEach(currentSearch, function (facet) { - * if (apiVersion < 3) { - * facet.isServer = true; - * } - * }); - * }); - * - * 4. Overrode 'initfacets' to fix refresh/bookmark issue where facets - * menu wasn't removing facets that were already on URL. - * - * @restrict A - * @scope - * - * @example - * ``` - *