├── .editorconfig ├── .ember-cli ├── .eslintignore ├── .eslintrc.js ├── .github └── workflows │ └── ci.yml ├── .gitignore ├── .npmignore ├── .prettierignore ├── .prettierrc.js ├── .template-lintrc.js ├── .travis.yml ├── .watchmanconfig ├── CHANGELOG.md ├── LICENSE ├── README.md ├── addon ├── .gitkeep ├── index.js └── util │ └── filter.js ├── app └── .gitkeep ├── blueprints └── ember-cli-filter-by-query │ └── index.js ├── config ├── ember-try.js └── environment.js ├── ember-cli-build.js ├── index.js ├── package.json ├── testem.js ├── tests ├── .jshintrc ├── dummy │ ├── app │ │ ├── app.js │ │ ├── components │ │ │ └── .gitkeep │ │ ├── controllers │ │ │ └── .gitkeep │ │ ├── helpers │ │ │ └── .gitkeep │ │ ├── index.html │ │ ├── models │ │ │ └── .gitkeep │ │ ├── resolver.js │ │ ├── router.js │ │ ├── routes │ │ │ └── .gitkeep │ │ ├── styles │ │ │ └── app.css │ │ └── templates │ │ │ ├── application.hbs │ │ │ └── components │ │ │ └── .gitkeep │ ├── config │ │ ├── environment.js │ │ ├── optional-features.json │ │ └── targets.js │ └── public │ │ ├── crossdomain.xml │ │ └── robots.txt ├── helpers │ ├── destroy-app.js │ ├── module-for-acceptance.js │ ├── resolver.js │ └── start-app.js ├── index.html ├── test-helper.js └── unit │ ├── .gitkeep │ ├── computed-filter-by-query-test.js │ └── filter-by-query-test.js └── vendor └── .gitkeep /.editorconfig: -------------------------------------------------------------------------------- 1 | # EditorConfig helps developers define and maintain consistent 2 | # coding styles between different editors and IDEs 3 | # editorconfig.org 4 | 5 | root = true 6 | 7 | [*] 8 | end_of_line = lf 9 | charset = utf-8 10 | trim_trailing_whitespace = true 11 | insert_final_newline = true 12 | indent_style = space 13 | indent_size = 2 14 | 15 | [*.hbs] 16 | insert_final_newline = false 17 | 18 | [*.{diff,md}] 19 | trim_trailing_whitespace = false 20 | -------------------------------------------------------------------------------- /.ember-cli: -------------------------------------------------------------------------------- 1 | { 2 | /** 3 | Ember CLI sends analytics information by default. The data is completely 4 | anonymous, but there are times when you might want to disable this behavior. 5 | 6 | Setting `disableAnalytics` to true will prevent any data from being sent. 7 | */ 8 | "disableAnalytics": false, 9 | 10 | /** 11 | Setting `isTypeScriptProject` to true will force the blueprint generators to generate TypeScript 12 | rather than JavaScript by default, when a TypeScript version of a given blueprint is available. 13 | */ 14 | "isTypeScriptProject": false 15 | } 16 | -------------------------------------------------------------------------------- /.eslintignore: -------------------------------------------------------------------------------- 1 | # unconventional js 2 | /blueprints/*/files/ 3 | /vendor/ 4 | 5 | # compiled output 6 | /dist/ 7 | /tmp/ 8 | 9 | # dependencies 10 | /bower_components/ 11 | /node_modules/ 12 | 13 | # misc 14 | /coverage/ 15 | !.* 16 | .*/ 17 | .eslintcache 18 | 19 | # ember-try 20 | /.node_modules.ember-try/ 21 | /bower.json.ember-try 22 | /npm-shrinkwrap.json.ember-try 23 | /package.json.ember-try 24 | /package-lock.json.ember-try 25 | /yarn.lock.ember-try 26 | -------------------------------------------------------------------------------- /.eslintrc.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | module.exports = { 4 | root: true, 5 | parser: 'babel-eslint', 6 | parserOptions: { 7 | ecmaVersion: 2018, 8 | sourceType: 'module', 9 | ecmaFeatures: { 10 | legacyDecorators: true, 11 | }, 12 | }, 13 | plugins: ['ember'], 14 | extends: [ 15 | 'eslint:recommended', 16 | 'plugin:ember/recommended', 17 | 'plugin:prettier/recommended', 18 | ], 19 | env: { 20 | browser: true, 21 | }, 22 | rules: {}, 23 | overrides: [ 24 | // node files 25 | { 26 | files: [ 27 | './.eslintrc.js', 28 | './.prettierrc.js', 29 | './.template-lintrc.js', 30 | './ember-cli-build.js', 31 | './index.js', 32 | './testem.js', 33 | './blueprints/*/index.js', 34 | './config/**/*.js', 35 | './tests/dummy/config/**/*.js', 36 | ], 37 | parserOptions: { 38 | sourceType: 'script', 39 | }, 40 | env: { 41 | browser: false, 42 | node: true, 43 | }, 44 | plugins: ['node'], 45 | extends: ['plugin:node/recommended'], 46 | }, 47 | { 48 | // test files 49 | files: ['tests/**/*-test.{js,ts}'], 50 | extends: ['plugin:qunit/recommended'], 51 | }, 52 | ], 53 | }; 54 | -------------------------------------------------------------------------------- /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | # This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node 2 | # For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions 3 | 4 | name: Node.js CI 5 | 6 | on: 7 | push: 8 | branches: 9 | - master 10 | pull_request: {} 11 | 12 | concurrency: 13 | group: ci-${{ github.head_ref || github.ref }} 14 | cancel-in-progress: true 15 | 16 | jobs: 17 | test: 18 | name: "Tests" 19 | runs-on: ubuntu-latest 20 | 21 | steps: 22 | - uses: actions/checkout@v3 23 | - name: Install Node 24 | uses: actions/setup-node@v3 25 | with: 26 | node-version: 12.x 27 | # cache: npm 28 | - name: Install dependencies 29 | run: | 30 | if [ -e yarn.lock ]; then 31 | yarn install --frozen-lockfile 32 | elif [ -e package-lock.json ]; then 33 | npm ci 34 | else 35 | npm i 36 | fi 37 | - name: Lint 38 | run: npm run lint 39 | - name: Run Tests 40 | run: npm run test:ember 41 | 42 | floating: 43 | name: "Floating Dependencies" 44 | runs-on: ubuntu-latest 45 | 46 | steps: 47 | - uses: actions/checkout@v3 48 | - uses: actions/setup-node@v3 49 | with: 50 | node-version: 12.x 51 | # cache: npm 52 | - name: Install Dependencies 53 | run: npm install --no-shrinkwrap 54 | - name: Run Tests 55 | run: npm run test:ember 56 | 57 | try-scenarios: 58 | name: ${{ matrix.try-scenario }} 59 | runs-on: ubuntu-latest 60 | needs: "test" 61 | 62 | strategy: 63 | fail-fast: false 64 | matrix: 65 | try-scenario: 66 | - ember-lts-3.24 67 | - ember-lts-3.28 68 | - ember-release 69 | - ember-beta 70 | - ember-canary 71 | - ember-classic 72 | - embroider-safe 73 | - embroider-optimized 74 | 75 | steps: 76 | - uses: actions/checkout@v3 77 | - name: Install Node 78 | uses: actions/setup-node@v3 79 | with: 80 | node-version: 12.x 81 | # cache: npm 82 | - name: Install dependencies 83 | run: | 84 | if [ -e yarn.lock ]; then 85 | yarn install --frozen-lockfile 86 | elif [ -e package-lock.json ]; then 87 | npm ci 88 | else 89 | npm i 90 | fi 91 | - name: Run Tests 92 | run: ./node_modules/.bin/ember try:one ${{ matrix.try-scenario }} -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/ignore-files/ for more about ignoring files. 2 | 3 | # compiled output 4 | /dist 5 | /tmp 6 | 7 | # dependencies 8 | /node_modules 9 | /bower_components 10 | 11 | # misc 12 | /.sass-cache 13 | /connect.lock 14 | /coverage/* 15 | /libpeerconnection.log 16 | npm-debug.log* 17 | yarn-error.log 18 | testem.log 19 | package-lock.json 20 | 21 | # ember-try 22 | .node_modules.ember-try/ 23 | bower.json.ember-try 24 | package.json.ember-try 25 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | # compiled output 2 | /dist/ 3 | /tmp/ 4 | 5 | # dependencies 6 | /bower_components/ 7 | 8 | # misc 9 | /.bowerrc 10 | /.editorconfig 11 | /.ember-cli 12 | /.env* 13 | /.eslintcache 14 | /.eslintignore 15 | /.eslintrc.js 16 | /.git/ 17 | /.github/ 18 | /.gitignore 19 | /.prettierignore 20 | /.prettierrc.js 21 | /.template-lintrc.js 22 | /.travis.yml 23 | /.watchmanconfig 24 | /bower.json 25 | /config/ember-try.js 26 | /CONTRIBUTING.md 27 | /ember-cli-build.js 28 | /testem.js 29 | /tests/ 30 | /yarn-error.log 31 | /yarn.lock 32 | .gitkeep 33 | 34 | # ember-try 35 | /.node_modules.ember-try/ 36 | /bower.json.ember-try 37 | /npm-shrinkwrap.json.ember-try 38 | /package.json.ember-try 39 | /package-lock.json.ember-try 40 | /yarn.lock.ember-try 41 | -------------------------------------------------------------------------------- /.prettierignore: -------------------------------------------------------------------------------- 1 | # unconventional js 2 | /blueprints/*/files/ 3 | /vendor/ 4 | 5 | # compiled output 6 | /dist/ 7 | /tmp/ 8 | 9 | # dependencies 10 | /bower_components/ 11 | /node_modules/ 12 | 13 | # misc 14 | /coverage/ 15 | !.* 16 | .eslintcache 17 | .lint-todo/ 18 | 19 | # ember-try 20 | /.node_modules.ember-try/ 21 | /bower.json.ember-try 22 | /npm-shrinkwrap.json.ember-try 23 | /package.json.ember-try 24 | /package-lock.json.ember-try 25 | /yarn.lock.ember-try 26 | -------------------------------------------------------------------------------- /.prettierrc.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | module.exports = { 4 | singleQuote: true, 5 | }; 6 | -------------------------------------------------------------------------------- /.template-lintrc.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | module.exports = { 4 | extends: 'recommended', 5 | }; 6 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | --- 2 | language: node_js 3 | node_js: 4 | - '12' 5 | 6 | dist: xenial 7 | 8 | addons: 9 | chrome: stable 10 | 11 | cache: 12 | directories: 13 | - $HOME/.npm 14 | - $HOME/.cache # includes bowers cache 15 | 16 | env: 17 | global: 18 | # See https://git.io/vdao3 for details. 19 | - JOBS=1 20 | matrix: 21 | # we recommend new addons test the current and previous LTS 22 | # as well as latest stable release (bonus points to beta/canary) 23 | - EMBER_TRY_SCENARIO=ember-lts-3.24 24 | - EMBER_TRY_SCENARIO=ember-lts-3.28 25 | - EMBER_TRY_SCENARIO=ember-release 26 | 27 | matrix: 28 | allow_failures: 29 | - env: EMBER_TRY_SCENARIO=ember-beta 30 | - env: EMBER_TRY_SCENARIO=ember-canary 31 | - env: EMBER_TRY_SCENARIO=embroider-safe 32 | - env: EMBER_TRY_SCENARIO=embroider-optimized 33 | 34 | branches: 35 | only: 36 | - master 37 | 38 | script: 39 | - npm run lint:js 40 | - npm test 41 | -------------------------------------------------------------------------------- /.watchmanconfig: -------------------------------------------------------------------------------- 1 | { 2 | "ignore_dirs": ["tmp", "dist"] 3 | } 4 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ### 1.3.2 (March 02, 2021) 2 | 3 | - [#13](https://github.com/lazybensch/ember-cli-filter-by-query/pull/13) [BUGFIX] Don't set options.limit to array.length 4 | 5 | ### 1.3.1 (February 07, 2020) 6 | 7 | - [ENHANCEMENT] Make get compatible with @glimmer/component 8 | - [BUGFIX] Switch Travis to node 10 9 | 10 | ### 1.3.0 (March 03, 2018) 11 | 12 | - [#12](https://github.com/lazybensch/ember-cli-filter-by-query/pull/12) [ENHANCEMENT] Remove sifter.js bower dependency 13 | 14 | ### 1.2.0 (March 12, 2016) 15 | 16 | - [#11](https://github.com/lazybensch/ember-cli-filter-by-query/pull/11) [ENHANCEMENT] Support ember-cli 2.4.2 17 | 18 | ### 1.1.0 (July 04, 2015) 19 | 20 | - [#8](https://github.com/lazybensch/ember-cli-filter-by-query/pull/8) [FEATURE] Add no-sort option 21 | 22 | ### 1.0.3 (July 04, 2015) 23 | 24 | - [#6](https://github.com/lazybensch/ember-cli-filter-by-query/pull/6) [BUGFIX] fixes regression with ember data 1.0.0-beta.19 25 | 26 | ### 1.0.0 (July 04, 2015) 27 | 28 | - [#2](https://github.com/lazybensch/ember-cli-filter-by-query/pull/2) [FEATURE] support for additional filter options 29 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | 203 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Ember-cli-filter-by-query 2 | 3 | 4 | 5 | [![Build Status](https://travis-ci.org/lazybensch/ember-cli-filter-by-query.svg)](https://travis-ci.org/lazybensch/ember-cli-filter-by-query) [![Code Climate](https://codeclimate.com/github/lazybensch/ember-cli-filter-by-query/badges/gpa.svg)](https://codeclimate.com/github/lazybensch/ember-cli-filter-by-query) 6 | 7 | This addon provides you with a computed property macro to filter an array of objects based on a given search query. Other related addons often export components that might not suit your needs, `ember-cli-filter-by-query` only exports the macro and the filtering function itself so you can do whatever you want with it. Since the filtered list will always be sorted based on similarity to the search query a popular usecase could be autocompletion. 8 | 9 | Under the hood it uses [sifter.js](https://github.com/brianreavis/sifter.js/), which is _most likely_ faster then any filter solution you or I could come up with ;) 10 | 11 | ## Requirements 12 | - As of version 1.4.0 requires Ember 3.24 or higher (4.x included). For older Ember versions use version 1.3.2 or lower. 13 | 14 | ## Example 15 | 16 | ```javascript 17 | import computedFilterByQuery from 'ember-cli-filter-by-query'; 18 | 19 | Guy = DS.Model.extend({ 20 | filteredList: computedFilterByQuery('friends', 'name', 'query'), 21 | }); 22 | ``` 23 | 24 | `filteredList` will include all friends, whos names match the value of the `query` property - sorted by similarity to the search term. You can also pass an array of property keys as the second argument and both will be matched - ordered with preceding priority. 25 | 26 | ```javascript 27 | import computedFilterByQuery from 'ember-cli-filter-by-query'; 28 | 29 | Guy = DS.Model.extend({ 30 | filteredList: computedFilterByQuery('friends', ['name', 'surname'], 'query'), 31 | }); 32 | ``` 33 | 34 | `filteredList` will recompute, whenever the value of `guy.get('query')` or `guy.get('friends.@each.{name,surname}')` changes. If you are in need of the underlying filter method and don't want to wrap that in a computed property macro, you can access it too: 35 | 36 | ```javascript 37 | import filterByQuery from 'ember-cli-filter-by-query/util/filter'; 38 | 39 | filterByQuery(guy.get('friends'), ['name', 'surname'], controller.get('query')); 40 | ``` 41 | 42 | Notice that in this case, the first and last argument can't be property keys anymore but have to be the actual array and query. 43 | 44 | ## additional Options 45 | 46 | It is possible to pass a set of different options to the computed property macro aswell as to the utility function. 47 | 48 | | Option | Type | Description | 49 | | ----------- | :------ | :--------------------------------------------------------------------------------------------------------------------- | 50 | | filter | boolean | If `false`, items with a score of zero will not be filtered out of the result-set. | 51 | | conjunction | string | Determines how multiple search terms are joined ("and" or "or"). | 52 | | sort | boolean | Default is `true`. If `true`, the output is sorted by score. If `false`, the output is in the same order as the input. | 53 | 54 | ```javascript 55 | import computedFilterByQuery from 'ember-cli-filter-by-query'; 56 | 57 | Guy = DS.Model.extend({ 58 | 59 | smallList: computedFilterByQuery( 'friends', ['name', 'surname'], 'query', {conjunction: 'and' }) 60 | // this will only list friends whos name or surname include every word in the query 61 | 62 | largeList: computedFilterByQuery( 'friends', ['name', 'surname'], 'query', {conjunction: 'or' }) 63 | // this will list friends whos name or surname include at least one word of the query 64 | 65 | }); 66 | ``` 67 | 68 | ## Installation 69 | 70 | To use this addon in your project, just type: 71 | 72 | ``` 73 | $ ember install ember-cli-filter-by-query 74 | ``` 75 | 76 | or for older versions of ember-cli _(pre 1.4.0)_: 77 | 78 | ``` 79 | $ npm install --save-dev ember-cli-filter-by-query 80 | $ ember generate ember-cli-filter-by-query 81 | ``` 82 | 83 | and then import the function wherever you need it: 84 | 85 | ``` 86 | import computedFilterByQuery from 'ember-cli-filter-by-query'; 87 | ``` 88 | 89 | or 90 | 91 | ``` 92 | import filterByQuery from 'ember-cli-filter-by-query/util/filter'; 93 | ``` 94 | 95 | ## Contributing 96 | 97 | I am happy about any contributions or PRs. If you are missing some piece of functionality please open an issue. This addon is quite simple and can be extended easily. It is using sifter.js internally which has a richer API than what i am exposing here. 98 | 99 | - `git clone https://github.com/lazybensch/ember-cli-filter-by-query` 100 | - `cd ember-cli-filter-by-query` 101 | - `npm install` 102 | - `bower install` // As of ember-cli-filter-by-query 1.3.0 this step is not needed. 103 | - `ember test` 104 | 105 | ## Changelog 106 | 107 | - **1.4.0** 108 | - Updated to support Ember 4.x -------------------------------------------------------------------------------- /addon/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lazybensch/ember-cli-filter-by-query/fcd90d28908f06cfc7c6e1b9f822e295eafa8390/addon/.gitkeep -------------------------------------------------------------------------------- /addon/index.js: -------------------------------------------------------------------------------- 1 | import { makeArray } from '@ember/array'; 2 | import { computed, get } from '@ember/object'; 3 | import filterByQuery from 'ember-cli-filter-by-query/util/filter'; 4 | 5 | var computedFilterByQuery = function ( 6 | dependentKey, 7 | propertyKeys, 8 | queryKey, 9 | options 10 | ) { 11 | propertyKeys = makeArray(propertyKeys); 12 | 13 | return computed( 14 | queryKey, 15 | '' + dependentKey + '.@each.{' + propertyKeys.join(',') + '}', 16 | function () { 17 | var array = get(this, dependentKey); 18 | var query = get(this, queryKey) || ''; 19 | 20 | return filterByQuery(array, propertyKeys, query, options); 21 | } 22 | ); 23 | }; 24 | 25 | export default computedFilterByQuery; 26 | -------------------------------------------------------------------------------- /addon/util/filter.js: -------------------------------------------------------------------------------- 1 | import { A, makeArray } from '@ember/array'; 2 | import { typeOf } from '@ember/utils'; 3 | import { get } from '@ember/object'; 4 | import Sifter from 'sifter'; 5 | 6 | var filterByQuery = function (array, propertyKeys, query, options) { 7 | if (!query) { 8 | return A(array); 9 | } 10 | 11 | options = typeOf(options) === 'undefined' ? {} : options; 12 | propertyKeys = makeArray(propertyKeys); 13 | var input, sifter, result, sort; 14 | sort = 'sort' in options ? options.sort : true; 15 | delete options['sort']; 16 | 17 | input = array.map(function (item) { 18 | var hash = {}; 19 | propertyKeys.forEach(function (key) { 20 | hash[key] = get(item, key); 21 | }); 22 | return hash; 23 | }); 24 | 25 | options.fields = options.fields || propertyKeys; 26 | if (sort) { 27 | options.sort = propertyKeys.map(function (key) { 28 | return { field: key, direction: 'asc' }; 29 | }); 30 | } 31 | 32 | sifter = new Sifter(input); 33 | if (!sort) { 34 | sifter.getSortFunction = function () { 35 | return null; 36 | }; 37 | } 38 | result = sifter.search(query, options); 39 | 40 | return A( 41 | result.items.map(function (item) { 42 | return A(array).objectAt(item.id); 43 | }) 44 | ); 45 | }; 46 | 47 | export default filterByQuery; 48 | -------------------------------------------------------------------------------- /app/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lazybensch/ember-cli-filter-by-query/fcd90d28908f06cfc7c6e1b9f822e295eafa8390/app/.gitkeep -------------------------------------------------------------------------------- /blueprints/ember-cli-filter-by-query/index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | module.exports = { 4 | normalizeEntityName: function () {}, 5 | }; 6 | -------------------------------------------------------------------------------- /config/ember-try.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const getChannelURL = require('ember-source-channel-url'); 4 | const { embroiderSafe, embroiderOptimized } = require('@embroider/test-setup'); 5 | 6 | module.exports = async function () { 7 | return { 8 | scenarios: [ 9 | { 10 | name: 'ember-lts-3.24', 11 | npm: { 12 | devDependencies: { 13 | 'ember-source': '~3.24.3', 14 | }, 15 | }, 16 | }, 17 | { 18 | name: 'ember-lts-3.28', 19 | npm: { 20 | devDependencies: { 21 | 'ember-source': '~3.28.0', 22 | }, 23 | }, 24 | }, 25 | { 26 | name: 'ember-release', 27 | npm: { 28 | devDependencies: { 29 | 'ember-source': await getChannelURL('release'), 30 | }, 31 | }, 32 | }, 33 | { 34 | name: 'ember-beta', 35 | npm: { 36 | devDependencies: { 37 | 'ember-source': await getChannelURL('beta'), 38 | }, 39 | }, 40 | }, 41 | { 42 | name: 'ember-canary', 43 | npm: { 44 | devDependencies: { 45 | 'ember-source': await getChannelURL('canary'), 46 | }, 47 | }, 48 | }, 49 | { 50 | name: 'ember-classic', 51 | env: { 52 | EMBER_OPTIONAL_FEATURES: JSON.stringify({ 53 | 'application-template-wrapper': true, 54 | 'default-async-observers': false, 55 | 'template-only-glimmer-components': false, 56 | }), 57 | }, 58 | npm: { 59 | devDependencies: { 60 | 'ember-source': '~3.28.0', 61 | }, 62 | ember: { 63 | edition: 'classic', 64 | }, 65 | }, 66 | }, 67 | embroiderSafe(), 68 | embroiderOptimized(), 69 | ], 70 | }; 71 | }; 72 | -------------------------------------------------------------------------------- /config/environment.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | module.exports = function (/* environment, appConfig */) { 4 | return {}; 5 | }; 6 | -------------------------------------------------------------------------------- /ember-cli-build.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const EmberAddon = require('ember-cli/lib/broccoli/ember-addon'); 4 | 5 | module.exports = function (defaults) { 6 | let app = new EmberAddon(defaults, { 7 | // Add options here 8 | }); 9 | 10 | /* 11 | This build file specifies the options for the dummy test app of this 12 | addon, located in `/tests/dummy` 13 | This build file does *not* influence how the addon or the app using it 14 | behave. You most likely want to be modifying `./index.js` or app's build file 15 | */ 16 | 17 | const { maybeEmbroider } = require('@embroider/test-setup'); 18 | return maybeEmbroider(app, { 19 | skipBabel: [ 20 | { 21 | package: 'qunit', 22 | }, 23 | ], 24 | }); 25 | }; 26 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | /* eslint-env node */ 2 | 'use strict'; 3 | 4 | module.exports = { 5 | name: 'ember-cli-filter-by-query', 6 | 7 | init: function () { 8 | this._super.init && this._super.init.apply(this, arguments); 9 | }, 10 | }; 11 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "ember-cli-filter-by-query", 3 | "version": "1.4.0", 4 | "description": "Provides you with a computed property that filters an array by a given search query. The output is sorted by similarity to the query.", 5 | "keywords": [ 6 | "ember-addon", 7 | "ember-cli-filter-by-query", 8 | "computed property", 9 | "utility", 10 | "filter", 11 | "sifter", 12 | "search query" 13 | ], 14 | "repository": { 15 | "type": "git", 16 | "url": "https://github.com/lazybensch/ember-cli-filter-by-query.git" 17 | }, 18 | "license": "Apache-2.0", 19 | "author": "Benjamin Schoenburg lazybensch@gmail.com", 20 | "directories": { 21 | "doc": "doc", 22 | "test": "tests" 23 | }, 24 | "scripts": { 25 | "build": "ember build --environment=production", 26 | "lint": "npm-run-all --aggregate-output --continue-on-error --parallel \"lint:!(fix)\"", 27 | "lint:fix": "npm-run-all --aggregate-output --continue-on-error --parallel lint:*:fix", 28 | "lint:hbs": "ember-template-lint .", 29 | "lint:hbs:fix": "ember-template-lint . --fix", 30 | "lint:js": "eslint . --cache", 31 | "lint:js:fix": "eslint . --fix", 32 | "start": "ember serve", 33 | "test": "npm-run-all lint test:*", 34 | "test:ember": "ember test", 35 | "test:ember-compatibility": "ember try:each" 36 | }, 37 | "dependencies": { 38 | "ember-auto-import": "^2.4.1", 39 | "ember-cli-babel": "^7.26.11", 40 | "ember-cli-htmlbars": "^6.0.1", 41 | "sifter": "^0.5.3" 42 | }, 43 | "devDependencies": { 44 | "@ember/optional-features": "^2.0.0", 45 | "@ember/test-helpers": "^2.6.0", 46 | "@embroider/test-setup": "^1.5.0", 47 | "@glimmer/component": "^1.0.4", 48 | "@glimmer/tracking": "^1.0.4", 49 | "babel-eslint": "^10.1.0", 50 | "broccoli-asset-rev": "^3.0.0", 51 | "ember-cli": "~4.3.0", 52 | "ember-cli-dependency-checker": "^3.3.1", 53 | "ember-cli-inject-live-reload": "^2.1.0", 54 | "ember-cli-sri": "^2.1.1", 55 | "ember-cli-terser": "^4.0.2", 56 | "ember-disable-prototype-extensions": "^1.1.3", 57 | "ember-export-application-global": "^2.0.1", 58 | "ember-load-initializers": "^2.1.2", 59 | "ember-page-title": "^7.0.0", 60 | "ember-qunit": "^5.1.5", 61 | "ember-resolver": "^8.0.3", 62 | "ember-source": "~4.3.0", 63 | "ember-source-channel-url": "^3.0.0", 64 | "ember-template-lint": "^4.3.0", 65 | "ember-try": "^2.0.0", 66 | "eslint": "^7.32.0", 67 | "eslint-config-prettier": "^8.5.0", 68 | "eslint-plugin-ember": "^10.5.9", 69 | "eslint-plugin-node": "^11.1.0", 70 | "eslint-plugin-prettier": "^4.0.0", 71 | "eslint-plugin-qunit": "^7.2.0", 72 | "loader.js": "^4.7.0", 73 | "npm-run-all": "^4.1.5", 74 | "prettier": "^2.6.1", 75 | "qunit": "^2.18.0", 76 | "qunit-dom": "^2.0.0", 77 | "webpack": "^5.70.0" 78 | }, 79 | "engines": { 80 | "node": "12.* || 14.* || >= 16" 81 | }, 82 | "ember": { 83 | "edition": "octane" 84 | }, 85 | "ember-addon": { 86 | "configPath": "tests/dummy/config" 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /testem.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | test_page: 'tests/index.html?hidepassed', 3 | disable_watching: true, 4 | launch_in_ci: ['Chrome'], 5 | launch_in_dev: ['Chrome'], 6 | browser_start_timeout: 120, 7 | browser_args: { 8 | Chrome: { 9 | mode: 'ci', 10 | args: [ 11 | // --no-sandbox is needed when running Chrome inside a container 12 | process.env.TRAVIS ? '--no-sandbox' : null, 13 | 14 | '--disable-gpu', 15 | '--headless', 16 | '--remote-debugging-port=0', 17 | '--window-size=1440,900', 18 | ].filter(Boolean), 19 | }, 20 | }, 21 | }; 22 | -------------------------------------------------------------------------------- /tests/.jshintrc: -------------------------------------------------------------------------------- 1 | { 2 | "predef": [ 3 | "document", 4 | "window", 5 | "location", 6 | "setTimeout", 7 | "$", 8 | "-Promise", 9 | "define", 10 | "console", 11 | "visit", 12 | "exists", 13 | "fillIn", 14 | "click", 15 | "keyEvent", 16 | "triggerEvent", 17 | "find", 18 | "findWithAssert", 19 | "wait", 20 | "DS", 21 | "andThen", 22 | "currentURL", 23 | "currentPath", 24 | "currentRouteName" 25 | ], 26 | "node": false, 27 | "browser": false, 28 | "boss": true, 29 | "curly": true, 30 | "debug": false, 31 | "devel": false, 32 | "eqeqeq": true, 33 | "evil": true, 34 | "forin": false, 35 | "immed": false, 36 | "laxbreak": false, 37 | "newcap": true, 38 | "noarg": true, 39 | "noempty": false, 40 | "nonew": false, 41 | "nomen": false, 42 | "onevar": false, 43 | "plusplus": false, 44 | "regexp": false, 45 | "undef": true, 46 | "sub": true, 47 | "strict": false, 48 | "white": false, 49 | "eqnull": true, 50 | "esnext": true, 51 | "unused": true 52 | } 53 | -------------------------------------------------------------------------------- /tests/dummy/app/app.js: -------------------------------------------------------------------------------- 1 | import Application from '@ember/application'; 2 | import Resolver from 'ember-resolver'; 3 | import loadInitializers from 'ember-load-initializers'; 4 | import config from 'dummy/config/environment'; 5 | 6 | export default class App extends Application { 7 | modulePrefix = config.modulePrefix; 8 | podModulePrefix = config.podModulePrefix; 9 | Resolver = Resolver; 10 | } 11 | 12 | loadInitializers(App, config.modulePrefix); 13 | -------------------------------------------------------------------------------- /tests/dummy/app/components/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lazybensch/ember-cli-filter-by-query/fcd90d28908f06cfc7c6e1b9f822e295eafa8390/tests/dummy/app/components/.gitkeep -------------------------------------------------------------------------------- /tests/dummy/app/controllers/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lazybensch/ember-cli-filter-by-query/fcd90d28908f06cfc7c6e1b9f822e295eafa8390/tests/dummy/app/controllers/.gitkeep -------------------------------------------------------------------------------- /tests/dummy/app/helpers/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lazybensch/ember-cli-filter-by-query/fcd90d28908f06cfc7c6e1b9f822e295eafa8390/tests/dummy/app/helpers/.gitkeep -------------------------------------------------------------------------------- /tests/dummy/app/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Dummy 7 | 8 | 9 | 10 | {{content-for "head"}} 11 | 12 | 13 | 14 | 15 | {{content-for "head-footer"}} 16 | 17 | 18 | {{content-for "body"}} 19 | 20 | 21 | 22 | 23 | {{content-for "body-footer"}} 24 | 25 | 26 | -------------------------------------------------------------------------------- /tests/dummy/app/models/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lazybensch/ember-cli-filter-by-query/fcd90d28908f06cfc7c6e1b9f822e295eafa8390/tests/dummy/app/models/.gitkeep -------------------------------------------------------------------------------- /tests/dummy/app/resolver.js: -------------------------------------------------------------------------------- 1 | import Resolver from 'ember-resolver'; 2 | 3 | export default Resolver; 4 | -------------------------------------------------------------------------------- /tests/dummy/app/router.js: -------------------------------------------------------------------------------- 1 | import EmberRouter from '@ember/routing/router'; 2 | import config from 'dummy/config/environment'; 3 | 4 | export default class Router extends EmberRouter { 5 | location = config.locationType; 6 | rootURL = config.rootURL; 7 | } 8 | 9 | Router.map(function () {}); 10 | -------------------------------------------------------------------------------- /tests/dummy/app/routes/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lazybensch/ember-cli-filter-by-query/fcd90d28908f06cfc7c6e1b9f822e295eafa8390/tests/dummy/app/routes/.gitkeep -------------------------------------------------------------------------------- /tests/dummy/app/styles/app.css: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lazybensch/ember-cli-filter-by-query/fcd90d28908f06cfc7c6e1b9f822e295eafa8390/tests/dummy/app/styles/app.css -------------------------------------------------------------------------------- /tests/dummy/app/templates/application.hbs: -------------------------------------------------------------------------------- 1 | {{outlet}} -------------------------------------------------------------------------------- /tests/dummy/app/templates/components/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lazybensch/ember-cli-filter-by-query/fcd90d28908f06cfc7c6e1b9f822e295eafa8390/tests/dummy/app/templates/components/.gitkeep -------------------------------------------------------------------------------- /tests/dummy/config/environment.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | module.exports = function (environment) { 4 | let ENV = { 5 | modulePrefix: 'dummy', 6 | environment, 7 | rootURL: '/', 8 | locationType: 'history', 9 | EmberENV: { 10 | FEATURES: { 11 | // Here you can enable experimental features on an ember canary build 12 | // e.g. 'with-controller': true 13 | }, 14 | EXTEND_PROTOTYPES: { 15 | // Prevent Ember Data from overriding Date.parse. 16 | Date: false, 17 | }, 18 | }, 19 | 20 | APP: { 21 | // Here you can pass flags/options to your application instance 22 | // when it is created 23 | }, 24 | }; 25 | 26 | if (environment === 'development') { 27 | // ENV.APP.LOG_RESOLVER = true; 28 | // ENV.APP.LOG_ACTIVE_GENERATION = true; 29 | // ENV.APP.LOG_TRANSITIONS = true; 30 | // ENV.APP.LOG_TRANSITIONS_INTERNAL = true; 31 | // ENV.APP.LOG_VIEW_LOOKUPS = true; 32 | } 33 | 34 | if (environment === 'test') { 35 | // Testem prefers this... 36 | ENV.locationType = 'none'; 37 | 38 | // keep test console output quieter 39 | ENV.APP.LOG_ACTIVE_GENERATION = false; 40 | ENV.APP.LOG_VIEW_LOOKUPS = false; 41 | 42 | ENV.APP.rootElement = '#ember-testing'; 43 | ENV.APP.autoboot = false; 44 | } 45 | 46 | if (environment === 'production') { 47 | // here you can enable a production-specific feature 48 | } 49 | 50 | return ENV; 51 | }; 52 | -------------------------------------------------------------------------------- /tests/dummy/config/optional-features.json: -------------------------------------------------------------------------------- 1 | { 2 | "application-template-wrapper": false, 3 | "default-async-observers": true, 4 | "jquery-integration": false, 5 | "template-only-glimmer-components": true 6 | } 7 | -------------------------------------------------------------------------------- /tests/dummy/config/targets.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const browsers = [ 4 | 'last 1 Chrome versions', 5 | 'last 1 Firefox versions', 6 | 'last 1 Safari versions', 7 | ]; 8 | 9 | // Ember's browser support policy is changing, and IE11 support will end in 10 | // v4.0 onwards. 11 | // 12 | // See https://deprecations.emberjs.com/v3.x#toc_3-0-browser-support-policy 13 | // 14 | // If you need IE11 support on a version of Ember that still offers support 15 | // for it, uncomment the code block below. 16 | // 17 | // const isCI = Boolean(process.env.CI); 18 | // const isProduction = process.env.EMBER_ENV === 'production'; 19 | // 20 | // if (isCI || isProduction) { 21 | // browsers.push('ie 11'); 22 | // } 23 | 24 | module.exports = { 25 | browsers, 26 | }; 27 | -------------------------------------------------------------------------------- /tests/dummy/public/crossdomain.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 15 | 16 | -------------------------------------------------------------------------------- /tests/dummy/public/robots.txt: -------------------------------------------------------------------------------- 1 | # http://www.robotstxt.org 2 | User-agent: * 3 | Disallow: 4 | -------------------------------------------------------------------------------- /tests/helpers/destroy-app.js: -------------------------------------------------------------------------------- 1 | import { run } from '@ember/runloop'; 2 | 3 | export default function destroyApp(application) { 4 | run(application, 'destroy'); 5 | } 6 | -------------------------------------------------------------------------------- /tests/helpers/module-for-acceptance.js: -------------------------------------------------------------------------------- 1 | import { module } from 'qunit'; 2 | import { resolve } from 'rsvp'; 3 | import startApp from '../helpers/start-app'; 4 | import destroyApp from '../helpers/destroy-app'; 5 | 6 | export default function (name, options = {}) { 7 | module(name, { 8 | beforeEach() { 9 | this.application = startApp(); 10 | 11 | if (options.beforeEach) { 12 | return options.beforeEach.apply(this, arguments); 13 | } 14 | }, 15 | 16 | afterEach() { 17 | let afterEach = 18 | options.afterEach && options.afterEach.apply(this, arguments); 19 | return resolve(afterEach).then(() => destroyApp(this.application)); 20 | }, 21 | }); 22 | } 23 | -------------------------------------------------------------------------------- /tests/helpers/resolver.js: -------------------------------------------------------------------------------- 1 | import Resolver from 'ember-resolver'; 2 | import config from '../../config/environment'; 3 | 4 | const resolver = Resolver.create(); 5 | 6 | resolver.namespace = { 7 | modulePrefix: config.modulePrefix, 8 | podModulePrefix: config.podModulePrefix, 9 | }; 10 | 11 | export default resolver; 12 | -------------------------------------------------------------------------------- /tests/helpers/start-app.js: -------------------------------------------------------------------------------- 1 | import Application from '../../app'; 2 | import config from '../../config/environment'; 3 | import { merge } from '@ember/polyfills'; 4 | import { run } from '@ember/runloop'; 5 | 6 | export default function startApp(attrs) { 7 | let attributes = merge({}, config.APP); 8 | attributes.autoboot = true; 9 | attributes = merge(attributes, attrs); // use defaults, but you can override; 10 | 11 | return run(() => { 12 | let application = Application.create(attributes); 13 | application.setupForTesting(); 14 | application.injectTestHelpers(); 15 | return application; 16 | }); 17 | } 18 | -------------------------------------------------------------------------------- /tests/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Dummy Tests 7 | 8 | 9 | 10 | {{content-for "head"}} {{content-for "test-head"}} 11 | 12 | 13 | 14 | 15 | 16 | {{content-for "head-footer"}} {{content-for "test-head-footer"}} 17 | 18 | 19 | {{content-for "body"}} {{content-for "test-body"}} 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | {{content-for "body-footer"}} {{content-for "test-body-footer"}} 28 | 29 | 30 | -------------------------------------------------------------------------------- /tests/test-helper.js: -------------------------------------------------------------------------------- 1 | import Application from '../app'; 2 | import config from '../config/environment'; 3 | import { setApplication } from '@ember/test-helpers'; 4 | import { start } from 'ember-qunit'; 5 | 6 | setApplication(Application.create(config.APP)); 7 | 8 | start(); 9 | -------------------------------------------------------------------------------- /tests/unit/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lazybensch/ember-cli-filter-by-query/fcd90d28908f06cfc7c6e1b9f822e295eafa8390/tests/unit/.gitkeep -------------------------------------------------------------------------------- /tests/unit/computed-filter-by-query-test.js: -------------------------------------------------------------------------------- 1 | import computedFilterByQuery from 'ember-cli-filter-by-query'; 2 | import { module, test } from 'qunit'; 3 | import EmberObject from '@ember/object'; 4 | 5 | var obj, germany, algeria, nigeria; 6 | var france, russia, mexico, somalia, brittain; 7 | 8 | module('computed property test', function (hooks) { 9 | // setupTest(hooks); 10 | 11 | hooks.beforeEach(function () { 12 | class Type extends EmberObject { 13 | @computedFilterByQuery('list', 'country', 'query') foo; 14 | @computedFilterByQuery('list', 'continent', 'query') bar; 15 | @computedFilterByQuery('list', ['continent', 'country'], 'query') baz; 16 | } 17 | 18 | germany = EmberObject.create({ 19 | country: 'Germany', 20 | capital: 'Berlin', 21 | continent: 'Europe', 22 | }); 23 | 24 | algeria = EmberObject.create({ 25 | country: 'Algeria', 26 | capital: 'Algiers', 27 | continent: 'Africa', 28 | }); 29 | 30 | nigeria = EmberObject.create({ 31 | country: 'Nigeria', 32 | capital: 'Abuja', 33 | continent: 'Africa', 34 | }); 35 | 36 | france = EmberObject.create({ 37 | country: 'France', 38 | capital: 'Paris', 39 | continent: 'Europe', 40 | }); 41 | 42 | russia = EmberObject.create({ 43 | country: 'Russia', 44 | capital: 'Moscow', 45 | continent: 'Europe/Asia', 46 | }); 47 | 48 | mexico = EmberObject.create({ 49 | country: 'Mexico', 50 | capital: 'Mexico City', 51 | continent: 'North America', 52 | }); 53 | 54 | somalia = EmberObject.create({ 55 | country: 'Somalia', 56 | capital: 'Mogadishu', 57 | continent: 'Africa', 58 | }); 59 | 60 | brittain = EmberObject.create({ 61 | country: 'Great Brittain', 62 | capital: 'London', 63 | continent: 'Europe', 64 | }); 65 | 66 | obj = Type.create({ 67 | list: [ 68 | brittain, 69 | germany, 70 | algeria, 71 | nigeria, 72 | somalia, 73 | mexico, 74 | russia, 75 | france, 76 | ], 77 | }); 78 | }); 79 | 80 | test('it filters a list', function (assert) { 81 | assert.expect(3); 82 | 83 | obj.set('query', 'ger'); 84 | assert.deepEqual( 85 | obj.get('foo'), 86 | [germany, algeria, nigeria], 87 | 'it only includes matches' 88 | ); 89 | 90 | obj.set('query', 'europe'); 91 | assert.deepEqual(obj.get('bar.length'), 4, 'filters case insensitive'); 92 | 93 | obj.set('query', 'ri'); 94 | assert.deepEqual(obj.get('baz.length'), 5, 'respects property key order'); 95 | }); 96 | }); 97 | -------------------------------------------------------------------------------- /tests/unit/filter-by-query-test.js: -------------------------------------------------------------------------------- 1 | import filterByQuery from 'ember-cli-filter-by-query/util/filter'; 2 | import { module, test } from 'qunit'; 3 | 4 | module('utility function test', function () { 5 | test('filters with "or" conjunction', function (assert) { 6 | var input, output; 7 | assert.expect(1); 8 | 9 | input = [ 10 | { id: 1, foo: 'psopao', bar: 'opoko' }, 11 | { id: 2, foo: 'aapoko', bar: 'aaa' }, 12 | { id: 3, foo: 'prsss', bar: 'aa' }, 13 | ]; 14 | 15 | output = filterByQuery(input, ['foo', 'bar'], 'po aa', { 16 | conjunction: 'or', 17 | }); 18 | assert.deepEqual(output, [input[1], input[2], input[0]]); 19 | }); 20 | 21 | test('filters with "and" conjunction', function (assert) { 22 | var input, output; 23 | assert.expect(1); 24 | 25 | input = [ 26 | { id: 1, foo: 'psopao', bar: 'opoko' }, 27 | { id: 2, foo: 'aapoko', bar: 'aaa' }, 28 | { id: 3, foo: 'prsss', bar: 'aa' }, 29 | ]; 30 | 31 | output = filterByQuery(input, ['foo', 'bar'], 'po aa', { 32 | conjunction: 'and', 33 | }); 34 | assert.deepEqual(output, [input[1]]); 35 | }); 36 | 37 | test('sort: true & sort: false', function (assert) { 38 | var input, output; 39 | assert.expect(3); 40 | 41 | input = [ 42 | { id: 1, foo: 'psopao', bar: 'opoko' }, 43 | { id: 2, foo: 'aapoko', bar: 'aaa' }, 44 | { id: 3, foo: 'prsss', bar: 'aa' }, 45 | ]; 46 | 47 | output = filterByQuery(input, ['foo', 'bar'], 'po aa', {}); 48 | assert.deepEqual(output, [input[1], input[2], input[0]]); 49 | 50 | output = filterByQuery(input, ['foo', 'bar'], 'po aa', { sort: true }); 51 | assert.deepEqual(output, [input[1], input[2], input[0]]); 52 | 53 | output = filterByQuery(input, ['foo', 'bar'], 'po aa', { sort: false }); 54 | assert.deepEqual(output, [input[0], input[1], input[2]]); 55 | }); 56 | }); 57 | -------------------------------------------------------------------------------- /vendor/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lazybensch/ember-cli-filter-by-query/fcd90d28908f06cfc7c6e1b9f822e295eafa8390/vendor/.gitkeep --------------------------------------------------------------------------------