From de2deba617da2a2b19f68e34f56c94df58f52239 Mon Sep 17 00:00:00 2001 From: fire-finch Date: Fri, 20 Jul 2018 05:19:31 +0530 Subject: [PATCH 1/4] SearchBox for Questions --- app/pods/questions/index/controller.js | 21 ++++++++++++++++++++- app/pods/questions/index/template.hbs | 1 + 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/app/pods/questions/index/controller.js b/app/pods/questions/index/controller.js index 83b825f..dcc269e 100644 --- a/app/pods/questions/index/controller.js +++ b/app/pods/questions/index/controller.js @@ -1,8 +1,27 @@ import Controller from '@ember/controller'; +import { task, timeout } from 'ember-concurrency'; export default Controller.extend({ queryParams: ['page', 'limit'], page: 1, - limit: 10 + limit: 10, + searchString: '', + searchTask: task(function * () { + yield timeout(250) + const questions = yield this.get('store').query('question', { + include: 'user', + page: { + number: this.get('page'), + limit: this.get('limit') + }, + filter: { + title: { + $iLike: `%${this.get('searchString')}%` + } + } + }) + this.set('page', 1) + this.set('questions', questions) + }).restartable() }); diff --git a/app/pods/questions/index/template.hbs b/app/pods/questions/index/template.hbs index 3a3d4a3..6af7989 100644 --- a/app/pods/questions/index/template.hbs +++ b/app/pods/questions/index/template.hbs @@ -5,6 +5,7 @@ {{/link-to}} + {{input type="text" class="form-control" placeholder="Filter By Question Name" key-up=(perform searchTask) value=searchString}} {{#each questions as |question|}}
From 9f8aeff33a2787a9d860c0eb0ccd1ef73be6bb65 Mon Sep 17 00:00:00 2001 From: fire-finch Date: Fri, 20 Jul 2018 16:00:18 +0530 Subject: [PATCH 2/4] Fix: Removed limit On Filteration --- app/pods/questions/index/controller.js | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/app/pods/questions/index/controller.js b/app/pods/questions/index/controller.js index dcc269e..ec4f2b1 100644 --- a/app/pods/questions/index/controller.js +++ b/app/pods/questions/index/controller.js @@ -8,12 +8,24 @@ export default Controller.extend({ searchString: '', searchTask: task(function * () { yield timeout(250) + + let searchStr = this.get('searchString').trim() + let pageOpts = {} + this.set('searchString', searchStr) + + if(searchStr === '') { + pageOpts = { + number: 1, + limit: this.get('limit') + } + } else { + pageOpts = { + number: 1 + } + } const questions = yield this.get('store').query('question', { include: 'user', - page: { - number: this.get('page'), - limit: this.get('limit') - }, + page: pageOpts, filter: { title: { $iLike: `%${this.get('searchString')}%` From 12f90d5867591b42c396b1e249c36058180a17ad Mon Sep 17 00:00:00 2001 From: fire-finch Date: Sat, 21 Jul 2018 13:07:01 +0530 Subject: [PATCH 3/4] Removed Pagination From SearchBox Results --- app/pods/questions/index/controller.js | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/app/pods/questions/index/controller.js b/app/pods/questions/index/controller.js index 198e415..fea1aee 100644 --- a/app/pods/questions/index/controller.js +++ b/app/pods/questions/index/controller.js @@ -4,22 +4,15 @@ import { task, timeout } from 'ember-concurrency'; export default Controller.extend({ queryParams: ['page', 'limit'], page: 1, - limit: 2, + limit: 10, searchString: '', searchTask: task(function * () { yield timeout(250) let searchStr = this.get('searchString').trim() - let pageOpts = {} - if(searchStr === '') { - pageOpts = { - limit: this.get('limit') - } - } const questions = yield this.get('store').query('question', { include: 'user', - page: pageOpts, filter: { title: { $iLike: `%${this.get('searchString')}%` From 85037b3da7d10bb52b2d6e7c38d101fb5e31ddd9 Mon Sep 17 00:00:00 2001 From: fire-finch Date: Sat, 21 Jul 2018 16:10:36 +0530 Subject: [PATCH 4/4] Moved searchbox to newline --- app/pods/questions/index/template.hbs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/app/pods/questions/index/template.hbs b/app/pods/questions/index/template.hbs index 3f697f2..a37a2cb 100644 --- a/app/pods/questions/index/template.hbs +++ b/app/pods/questions/index/template.hbs @@ -1,12 +1,15 @@
-
+
{{#link-to 'questions.new' class="white"}} {{/link-to}}
- {{input type="text" class="form-control" placeholder="Filter By Question Name" key-up=(perform searchTask) value=searchString}} -
+
+
+

Filter By Question Name:

{{input type="text" class="form-control" placeholder="Enter Question Name" key-up=(perform searchTask) value=searchString}} +
+
{{#each questions as |question|}}