workarea-search_autocomplete 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (88) hide show
  1. checksums.yaml +7 -0
  2. data/.editorconfig +20 -0
  3. data/.eslintrc.json +35 -0
  4. data/.github/workflows/ci.yml +60 -0
  5. data/.gitignore +20 -0
  6. data/.rubocop.yml +3 -0
  7. data/.stylelintrc.json +8 -0
  8. data/CHANGELOG.md +36 -0
  9. data/Gemfile +17 -0
  10. data/README.md +17 -0
  11. data/Rakefile +60 -0
  12. data/app/assets/javascripts/workarea/storefront/search_autocomplete/config.js +12 -0
  13. data/app/assets/javascripts/workarea/storefront/search_autocomplete/modules/search_autocomplete.js +76 -0
  14. data/app/assets/stylesheets/workarea/storefront/search_autocomplete/components/_page_header.scss +9 -0
  15. data/app/assets/stylesheets/workarea/storefront/search_autocomplete/components/_search_autocomplete.scss +53 -0
  16. data/app/controllers/workarea/storefront/searches_controller.decorator +10 -0
  17. data/app/models/workarea/metrics/search_by_week.decorator +37 -0
  18. data/app/view_models/workarea/storefront/search_autocomplete_products_view_model.rb +13 -0
  19. data/app/view_models/workarea/storefront/search_autocomplete_view_model.rb +66 -0
  20. data/app/views/workarea/storefront/searches/_autocomplete_placeholder.html.haml +2 -0
  21. data/app/views/workarea/storefront/searches/autocomplete.html.haml +34 -0
  22. data/bin/rails +25 -0
  23. data/config/initializers/appends.rb +20 -0
  24. data/config/initializers/content.rb +3 -0
  25. data/config/initializers/fields.rb +13 -0
  26. data/config/locales/en.yml +8 -0
  27. data/config/routes.rb +7 -0
  28. data/lib/workarea/search_autocomplete.rb +11 -0
  29. data/lib/workarea/search_autocomplete/engine.rb +8 -0
  30. data/lib/workarea/search_autocomplete/version.rb +5 -0
  31. data/package.json +9 -0
  32. data/script/admin_ci +9 -0
  33. data/script/ci +11 -0
  34. data/script/core_ci +9 -0
  35. data/script/plugins_ci +9 -0
  36. data/script/storefront_ci +9 -0
  37. data/test/dummy/.ruby-version +1 -0
  38. data/test/dummy/Rakefile +6 -0
  39. data/test/dummy/app/assets/config/manifest.js +3 -0
  40. data/test/dummy/app/assets/images/.keep +0 -0
  41. data/test/dummy/app/assets/javascripts/application.js +14 -0
  42. data/test/dummy/app/assets/stylesheets/application.css +15 -0
  43. data/test/dummy/app/controllers/application_controller.rb +2 -0
  44. data/test/dummy/app/controllers/concerns/.keep +0 -0
  45. data/test/dummy/app/helpers/application_helper.rb +2 -0
  46. data/test/dummy/app/jobs/application_job.rb +2 -0
  47. data/test/dummy/app/mailers/application_mailer.rb +4 -0
  48. data/test/dummy/app/models/concerns/.keep +0 -0
  49. data/test/dummy/app/views/layouts/application.html.erb +15 -0
  50. data/test/dummy/app/views/layouts/mailer.html.erb +13 -0
  51. data/test/dummy/app/views/layouts/mailer.text.erb +1 -0
  52. data/test/dummy/bin/bundle +3 -0
  53. data/test/dummy/bin/rails +4 -0
  54. data/test/dummy/bin/rake +4 -0
  55. data/test/dummy/bin/setup +25 -0
  56. data/test/dummy/bin/update +25 -0
  57. data/test/dummy/config.ru +5 -0
  58. data/test/dummy/config/application.rb +34 -0
  59. data/test/dummy/config/boot.rb +5 -0
  60. data/test/dummy/config/environment.rb +5 -0
  61. data/test/dummy/config/environments/development.rb +52 -0
  62. data/test/dummy/config/environments/production.rb +83 -0
  63. data/test/dummy/config/environments/test.rb +45 -0
  64. data/test/dummy/config/initializers/application_controller_renderer.rb +8 -0
  65. data/test/dummy/config/initializers/assets.rb +12 -0
  66. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  67. data/test/dummy/config/initializers/content_security_policy.rb +25 -0
  68. data/test/dummy/config/initializers/cookies_serializer.rb +5 -0
  69. data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  70. data/test/dummy/config/initializers/inflections.rb +16 -0
  71. data/test/dummy/config/initializers/mime_types.rb +4 -0
  72. data/test/dummy/config/initializers/workarea.rb +5 -0
  73. data/test/dummy/config/initializers/wrap_parameters.rb +9 -0
  74. data/test/dummy/config/locales/en.yml +33 -0
  75. data/test/dummy/config/puma.rb +34 -0
  76. data/test/dummy/config/routes.rb +5 -0
  77. data/test/dummy/config/spring.rb +6 -0
  78. data/test/dummy/db/seeds.rb +2 -0
  79. data/test/dummy/lib/assets/.keep +0 -0
  80. data/test/dummy/log/.keep +0 -0
  81. data/test/integration/workarea/storefront/search_autocomplete_integration_test.rb +29 -0
  82. data/test/models/workarea/metrics/search_by_week_autocomplete_test.rb +20 -0
  83. data/test/system/workarea/storefront/search_autocomplete_system_test.rb +171 -0
  84. data/test/teaspoon_env.rb +6 -0
  85. data/test/test_helper.rb +10 -0
  86. data/test/view_models/workarea/storefront/search_autocomplete_view_model_test.rb +125 -0
  87. data/workarea-search_autocomplete.gemspec +23 -0
  88. metadata +148 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 7cab34311e40d6ee51590272548d7851d97c0d3f460f13874f517f1e93df0b6b
4
+ data.tar.gz: e300b27a52950b6cecfa00685c20a6a67b8886fcf025ac2c636f61398a61599e
5
+ SHA512:
6
+ metadata.gz: a7868dcbf6741b677bec1fb7b00b5fe459f531a9912bccfa3a2a88e5b4bab570be7d71f6831e93f7e726d5bd55cc8c7b0e7839d5821c9e99624f4c623b6c348e
7
+ data.tar.gz: 396b33e63da8fba698fb99948a4ccddb134209f8cbf203a348cb0a4bbfe511674e4b6478df2c0f65bf64c0e5cd05a4783a618046fb4768ad44ea24734423fc55
data/.editorconfig ADDED
@@ -0,0 +1,20 @@
1
+ # editorconfig.org
2
+ root = true
3
+
4
+ [*]
5
+ charset = utf-8
6
+ indent_style = space
7
+ end_of_line = lf
8
+ trim_trailing_whitespace = true
9
+ insert_final_newline = true
10
+
11
+ [{*.rb,*.haml,*.decorator,*.yml,*.yaml,*.jbuilder}]
12
+ indent_size = 2
13
+ indent_style = space
14
+
15
+ [{*.js,*.jst,*.ejs,*.scss,*.js.erb}]
16
+ indent_size = 4
17
+
18
+ [*.md]
19
+ indent_size = 4
20
+ trim_trailing_whitespace = false
data/.eslintrc.json ADDED
@@ -0,0 +1,35 @@
1
+ {
2
+ "extends": "eslint:recommended",
3
+ "rules": {
4
+ "semi": ["error", "always"],
5
+ "eqeqeq": ["error", "always"]
6
+ },
7
+ "globals": {
8
+ "window": true,
9
+ "document": true,
10
+ "WORKAREA": true,
11
+ "$": true,
12
+ "jQuery": true,
13
+ "_": true,
14
+ "feature": true,
15
+ "JST": true,
16
+ "Turbolinks": true,
17
+ "I18n": true,
18
+ "Chart": true,
19
+ "Dropzone": true,
20
+ "strftime": true,
21
+ "Waypoint": true,
22
+ "wysihtml": true,
23
+ "LocalTime": true,
24
+ "describe": true,
25
+ "after": true,
26
+ "afterEach": true,
27
+ "before": true,
28
+ "beforeEach": true,
29
+ "it": true,
30
+ "expect": true,
31
+ "sinon": true,
32
+ "fixture": true,
33
+ "chai": true
34
+ }
35
+ }
@@ -0,0 +1,60 @@
1
+ name: CI
2
+ on: [push]
3
+
4
+ jobs:
5
+ static_analysis:
6
+ runs-on: ubuntu-latest
7
+ steps:
8
+ - uses: actions/checkout@v1
9
+ - uses: workarea-commerce/ci/bundler-audit@v1
10
+ - uses: workarea-commerce/ci/rubocop@v1
11
+ - uses: workarea-commerce/ci/eslint@v1
12
+ with:
13
+ args: '**/*.js'
14
+ - uses: workarea-commerce/ci/stylelint@v1
15
+ with:
16
+ args: '**/*.scss'
17
+
18
+ admin_tests:
19
+ runs-on: ubuntu-latest
20
+ steps:
21
+ - uses: actions/checkout@v1
22
+ - uses: actions/setup-ruby@v1
23
+ with:
24
+ ruby-version: 2.6.x
25
+ - uses: workarea-commerce/ci/test@v1
26
+ with:
27
+ command: bin/rails app:workarea:test:admin
28
+
29
+ core_tests:
30
+ runs-on: ubuntu-latest
31
+ steps:
32
+ - uses: actions/checkout@v1
33
+ - uses: actions/setup-ruby@v1
34
+ with:
35
+ ruby-version: 2.6.x
36
+ - uses: workarea-commerce/ci/test@v1
37
+ with:
38
+ command: bin/rails app:workarea:test:core
39
+
40
+ storefront_tests:
41
+ runs-on: ubuntu-latest
42
+ steps:
43
+ - uses: actions/checkout@v1
44
+ - uses: actions/setup-ruby@v1
45
+ with:
46
+ ruby-version: 2.6.x
47
+ - uses: workarea-commerce/ci/test@v1
48
+ with:
49
+ command: bin/rails app:workarea:test:storefront
50
+
51
+ plugins_tests:
52
+ runs-on: ubuntu-latest
53
+ steps:
54
+ - uses: actions/checkout@v1
55
+ - uses: actions/setup-ruby@v1
56
+ with:
57
+ ruby-version: 2.6.x
58
+ - uses: workarea-commerce/ci/test@v1
59
+ with:
60
+ command: bin/rails app:workarea:test:plugins
data/.gitignore ADDED
@@ -0,0 +1,20 @@
1
+ .bundle/
2
+ log/*.log
3
+ pkg/
4
+ test/dummy/log/*.log
5
+ test/dummy/tmp/
6
+ .DS_Store
7
+ .byebug_history
8
+ .bundle/
9
+ .sass-cache/
10
+ Gemfile.lock
11
+ pkg/
12
+ test/dummy/tmp/
13
+ test/dummy/public/
14
+ log/*.log
15
+ test/dummy/log/*.log
16
+ test/dummy/db/*.sqlite3
17
+ test/dummy/db/*.sqlite3-journal
18
+ node_modules
19
+ yarn.lock
20
+ .rubocop-http*
data/.rubocop.yml ADDED
@@ -0,0 +1,3 @@
1
+ inherit_from:
2
+ - https://raw.githubusercontent.com/workarea-commerce/workarea/master/.rubocop.yml
3
+
data/.stylelintrc.json ADDED
@@ -0,0 +1,8 @@
1
+ {
2
+ "extends": "stylelint-config-recommended-scss",
3
+ "rules": {
4
+ "block-no-empty": null,
5
+ "no-descending-specificity": null,
6
+ "property-no-unknown": [true, { "ignoreProperties": ["mso-hide"] }]
7
+ }
8
+ }
data/CHANGELOG.md ADDED
@@ -0,0 +1,36 @@
1
+ Workarea Search Autocomplete 1.0.0 (2019-11-26)
2
+ --------------------------------------------------------------------------------
3
+
4
+ * Fix Name of Append Point
5
+
6
+ This append point should be prefixed with `storefront.` in order to
7
+ notate where it is output on the site.
8
+
9
+ SEARCHAUTO-1
10
+ Tom Scott
11
+
12
+ * Improve Search Autocomplete UI
13
+
14
+ * Hide UI when input is empty
15
+ * Add contentable area to UI
16
+ * Display Trending Products/Searches when no results are available
17
+ * Add append point for content search
18
+
19
+ SEARCHAUTO-1
20
+ Curt Howard
21
+
22
+ * Fix case sensitivity
23
+
24
+ Fix #3
25
+ Ben Crouse
26
+
27
+ * Update config fields to be administrable fields
28
+
29
+ Matt Duffy
30
+
31
+ * Add backend implementation
32
+
33
+ Ben Crouse
34
+
35
+
36
+
data/Gemfile ADDED
@@ -0,0 +1,17 @@
1
+ source 'https://rubygems.org'
2
+ git_source(:github) { |repo| "https://github.com/#{repo}.git" }
3
+
4
+ # Declare your gem's dependencies in workarea-search_autocomplete.gemspec.
5
+ # Bundler will treat runtime dependencies like base dependencies, and
6
+ # development dependencies will be added by default to the :development group.
7
+ gemspec
8
+
9
+ # Declare any dependencies that are still in development here instead of in
10
+ # your gemspec. These might include edge Rails or gems from your path or
11
+ # Git. Remember to move these dependencies to your gemspec before releasing
12
+ # your gem to rubygems.org.
13
+
14
+ # To use a debugger
15
+ # gem 'byebug', group: [:development, :test]
16
+
17
+ gem 'workarea', github: 'workarea-commerce/workarea'
data/README.md ADDED
@@ -0,0 +1,17 @@
1
+ Workarea Search Autocomplete
2
+ ================================================================================
3
+
4
+ Search Autocomplete plugin for the Workarea platform.
5
+
6
+
7
+ Workarea Platform Documentation
8
+ --------------------------------------------------------------------------------
9
+
10
+ See [http://developer.workarea.com](http://developer.workarea.com) for Workarea platform documentation.
11
+
12
+ Copyright & Licensing
13
+ --------------------------------------------------------------------------------
14
+
15
+ Copyright Workarea 2019. All rights reserved.
16
+
17
+ For licensing, contact sales@workarea.com.
data/Rakefile ADDED
@@ -0,0 +1,60 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+ RDoc::Task.new(:rdoc) do |rdoc|
9
+ rdoc.rdoc_dir = 'rdoc'
10
+ rdoc.title = 'Workarea Search Autocomplete'
11
+ rdoc.options << '--line-numbers'
12
+ rdoc.rdoc_files.include('README.md')
13
+ rdoc.rdoc_files.include('lib/**/*.rb')
14
+ end
15
+
16
+ APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__)
17
+ load 'rails/tasks/engine.rake'
18
+ load 'rails/tasks/statistics.rake'
19
+ load 'workarea/changelog.rake'
20
+
21
+ require 'rake/testtask'
22
+ Rake::TestTask.new(:test) do |t|
23
+ t.libs << 'lib'
24
+ t.libs << 'test'
25
+ t.pattern = 'test/**/*_test.rb'
26
+ t.verbose = false
27
+ end
28
+ task default: :test
29
+
30
+ $LOAD_PATH.unshift File.expand_path('../lib', __FILE__)
31
+ require 'workarea/search_autocomplete/version'
32
+
33
+ desc "Release version #{Workarea::SearchAutocomplete::VERSION} of the gem"
34
+ task :release do
35
+ host = "https://#{ENV['BUNDLE_GEMS__WEBLINC__COM']}@gems.weblinc.com"
36
+
37
+ #Rake::Task['workarea:changelog'].execute
38
+ #system 'git add CHANGELOG.md'
39
+ #system 'git commit -m "Update CHANGELOG"'
40
+ #system 'git push origin HEAD'
41
+
42
+ system "git tag -a v#{Workarea::SearchAutocomplete::VERSION} -m 'Tagging #{Workarea::SearchAutocomplete::VERSION}'"
43
+ system 'git push --tags'
44
+
45
+ system "gem build workarea-search_autocomplete.gemspec"
46
+ system "gem push workarea-search_autocomplete-#{Workarea::SearchAutocomplete::VERSION}.gem"
47
+ system "gem push workarea-search_autocomplete-#{Workarea::SearchAutocomplete::VERSION}.gem --host #{host}"
48
+ system "rm workarea-search_autocomplete-#{Workarea::SearchAutocomplete::VERSION}.gem"
49
+ end
50
+
51
+ desc 'Run the JavaScript tests'
52
+ ENV['TEASPOON_RAILS_ENV'] = File.expand_path('../test/dummy/config/environment', __FILE__)
53
+ task teaspoon: 'app:teaspoon'
54
+
55
+ desc 'Start a server at http://localhost:3000/teaspoon for JavaScript tests'
56
+ task :teaspoon_server do
57
+ Dir.chdir("test/dummy")
58
+ teaspoon_env = File.expand_path('../test/teaspoon_env.rb', __FILE__)
59
+ system "RAILS_ENV=test TEASPOON_ENV=#{teaspoon_env} rails s"
60
+ end
@@ -0,0 +1,12 @@
1
+ (function () {
2
+ 'use strict';
3
+
4
+ WORKAREA.config.searchAutocomplete = {
5
+ selector: '#storefront_search',
6
+ delays: {
7
+ input: 500,
8
+ change: 250,
9
+ focus: 0
10
+ }
11
+ };
12
+ })();
@@ -0,0 +1,76 @@
1
+ /**
2
+ * @namespace WORKAREA.searchAutocomplete
3
+ */
4
+
5
+ WORKAREA.registerModule('searchAutocomplete', (function () {
6
+ 'use strict';
7
+
8
+ var cache = {},
9
+ hide = function () {
10
+ $('#search_autocomplete')
11
+ .addClass('visually-hidden')
12
+ .removeClass('search-autocomplete--visible')
13
+ .closest('.page-header__search-value')
14
+ .removeClass('page-header__search-value--autocomplete');
15
+ },
16
+
17
+ render = function (response) {
18
+ $('#search_autocomplete')
19
+ .removeClass('visually-hidden')
20
+ .addClass('search-autocomplete--visible')
21
+ .empty()
22
+ .append(response)
23
+ .closest('.page-header__search-value')
24
+ .addClass('page-header__search-value--autocomplete');
25
+ },
26
+
27
+ handleUserClick = function (event) {
28
+ if (_.isEmpty($(event.target).closest($('#search_autocomplete')))) {
29
+ hide();
30
+ }
31
+ },
32
+
33
+ handleUserInput = function (event) {
34
+ var endpoint = WORKAREA.routes.storefront.autocompleteSearchPath({
35
+ q: event.target.value
36
+ });
37
+
38
+ if (cache[endpoint]) {
39
+ render(cache[endpoint]);
40
+ } else {
41
+ $.get(endpoint)
42
+ .fail(function () { hide(); })
43
+ .done(function (response) {
44
+ cache[endpoint] = response;
45
+ render(response);
46
+ });
47
+ }
48
+
49
+ },
50
+
51
+ getDelay = function (type) {
52
+ if (WORKAREA.environment.isTest) {
53
+ return 0;
54
+ } else {
55
+ return WORKAREA.config.searchAutocomplete.delays[type];
56
+ }
57
+ },
58
+
59
+ /**
60
+ * @method
61
+ * @name init
62
+ * @memberof WORKAREA.searchAutocomplete
63
+ */
64
+ init = function ($scope) {
65
+ $(WORKAREA.config.searchAutocomplete.selector, $scope)
66
+ .on('focus', _.debounce(handleUserInput, getDelay('focus')))
67
+ .on('input', _.debounce(handleUserInput, getDelay('input')))
68
+ .on('change', _.debounce(handleUserInput, getDelay('change')));
69
+ };
70
+
71
+ $(window).on('click', handleUserClick);
72
+
73
+ return {
74
+ init: init
75
+ };
76
+ }()));
@@ -0,0 +1,9 @@
1
+ /*------------------------------------*\
2
+ #PAGE-HEADER
3
+ \*------------------------------------*/
4
+
5
+ /**
6
+ * Provide a positioning context for the Search Autocomplete UI
7
+ */
8
+
9
+ .page-header__search-value--autocomplete { position: relative; }
@@ -0,0 +1,53 @@
1
+ /*------------------------------------*\
2
+ #SEARCH-AUTOCOMPLETE
3
+ \*------------------------------------*/
4
+
5
+ $search-autocomplete-bg-color: $background-color !default;
6
+ $search-autocomplete-border: 1px solid $black !default;
7
+
8
+ $search-autocomplete-z-indexes: ();
9
+ @each $name in $page-container {
10
+ $search-autocomplete-z-indexes: append($search-autocomplete-z-indexes, $name);
11
+
12
+ @if $name == page-header {
13
+ $search-autocomplete-z-indexes: append($search-autocomplete-z-indexes, search-autocomplete);
14
+ }
15
+ }
16
+
17
+ .search-autocomplete {
18
+ display: none;
19
+ background: $search-autocomplete-bg-color;
20
+ border: $search-autocomplete-border;
21
+ padding: $spacing-unit;
22
+
23
+ @include respond-to($medium-breakpoint) {
24
+ display: block;
25
+ width: 90vw;
26
+ }
27
+
28
+ @include respond-to($x-wide-breakpoint) {
29
+ width: 1050px;
30
+ }
31
+ }
32
+
33
+ .search-autocomplete--visible {
34
+ position: absolute;
35
+ top: 100%;
36
+ right: 0;
37
+ z-index: index($search-autocomplete-z-indexes, search-autocomplete);
38
+ }
39
+
40
+
41
+ .search-autocomplete__products {
42
+ text-align: left;
43
+ }
44
+
45
+
46
+ .search-autocomplete__searches {
47
+ @extend %list-reset;
48
+ text-align: right;
49
+ }
50
+
51
+ .search-autocomplete__searches-item {}
52
+
53
+ .search-autocomplete__searches-link {}