Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion app/models/question.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ export default DS.Model.extend({
description: DS.attr(),
difficulty: DS.attr(),
user: DS.belongsTo('user'),
choices: DS.hasMany('choice')
choices: DS.hasMany('choice'),
tags: DS.hasMany('tag')
})
7 changes: 7 additions & 0 deletions app/models/tag.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import DS from "ember-data";

export default DS.Model.extend({
title: DS.attr(),
user: DS.belongsTo('user'),
questions: DS.hasMany('question')
})
25 changes: 24 additions & 1 deletion app/pods/components/question-editor/component.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,24 @@
import Component from '@ember/component';
import { inject as service } from '@ember/service';
import { task, timeout } from 'ember-concurrency';

export default Component.extend({
currentUser: service(),
store: service(),
api: service(),
notify: service(),
isEditing: false,
tagsFilterTask: task(function * (str) {
yield timeout(250)
const tags = yield this.get('store').query('tag', {
filter: {
title: {
$iLike: `%${str}%`
}
}
})
return tags.toArray()
}),
actions: {
toggleEditing () {
this.toggleProperty('isEditing')
Expand Down Expand Up @@ -48,8 +61,18 @@ export default Component.extend({
}).then(() => {
this.set('correctChoices', [...correctChoices])
})

},
createNewTag() {
const onSuccess = () => this.get('notify').success('New Tag Created')

let newTag = this.store.createRecord('tag', {
title: this.get('tagTitle'),
})

newTag.set('user', this.get('currentUser.user'))
console.log(newTag.user)
newTag.save()
.then(onSuccess)
}
}
});
29 changes: 29 additions & 0 deletions app/pods/components/question-editor/template.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,35 @@
{{/each}}
</ul>

<div class="row">
<div class="col-2">
<label>Tags</label>
</div>
<div class="col-6">
{{#power-select-multiple
search=(perform tagsFilterTask)
selected=question.tags
placeholder="Add tags for this question"
onchange=(action (mut question.tags ))
as |tag|}}
{{tag.title}}
{{/power-select-multiple}}
</div>
</div>
<div class="row"></div>
<div class="row justify-content-center align-items-center">
<div class="col-2">
<label>Create New Tag: </label>
</div>
<div class="col-5 input-group">
{{input type="text" class="input-text" placeholder="Enter Tag's Title" value=tagTitle}}
</div>
<div class="col-5">
<span {{action 'createNewTag'}}>
Save
<i class="far fa-save"></i>
</span></div>
</div>
Created By: <mark>{{question.user.firstname}}</mark>

{{/unless}}
Expand Down
2 changes: 1 addition & 1 deletion app/pods/questions/id/route.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export default Route.extend({
model (params) {
return RSVP.hash({
question: this.store.findRecord('question', params.id, {
include: 'user,choices'
include: 'user,choices,tags'
}),
answers: this.api.request(`/questions/${params.id}/answers`)
})
Expand Down
22 changes: 21 additions & 1 deletion app/pods/questions/index/controller.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import Controller from '@ember/controller';
import { inject as service } from '@ember/service';
import { task, timeout } from 'ember-concurrency';

export default Controller.extend({
store: service(),
queryParams: ['page', 'limit'],
page: 1,
limit: 10,
Expand All @@ -10,18 +12,36 @@ export default Controller.extend({
yield timeout(250)

let searchStr = this.get('searchString').trim()
let selectedTags = []

if(this.get('filterTags')) {
selectedTags = this.get('filterTags')
selectedTags = selectedTags.map(t => +t.id)
}

const questions = yield this.get('store').query('question', {
include: 'user',
filter: {
title: {
$iLike: `%${this.get('searchString')}%`
}
},
tags: selectedTags
}
})
this.set('page', 1)
this.set('questions', questions)
}).restartable(),
tagsFilterTask: task(function * (str) {
yield timeout(250)
const tags = yield this.get('store').query('tag', {
filter: {
title: {
$iLike: `%${str}%`
}
}
})
return tags.toArray()
}),
actions : {
deleteQuestion(question) {
question.destroyRecord()
Expand Down
1 change: 1 addition & 0 deletions app/pods/questions/index/route.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,6 @@ export default Route.extend({
},
setupController (controller, model) {
controller.set("questions", model)
controller.set("tags", model.filterTags)
}
});
12 changes: 12 additions & 0 deletions app/pods/questions/index/template.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,18 @@
<img src="http://online.codingblocks.com/images/searchicon-06d8faf96de7c883b5440b6594e39eda.png" alt="search">
</div>
</div>
<div class="row justify-content-center">
<div class="col-8">
{{#power-select-multiple
search=(perform tagsFilterTask)
selected=filterTags
onchange=(action (pipe (action (mut filterTags)) (perform searchTask)))
placeholder="Filter by tags"
as |tag|}}
{{tag.title}}
{{/power-select-multiple}}
</div>
</div>
<div class="row">
<div class="col-5"></div>
<div class="col-6">
Expand Down
3 changes: 3 additions & 0 deletions ember-cli-build.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ const EmberApp = require('ember-cli/lib/broccoli/ember-app');

module.exports = function(defaults) {
let app = new EmberApp(defaults, {
'ember-composable-helpers': {
// Add conditions
}
// Add options here
});

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"ember-cli-showdown": "^4.4.4",
"ember-cli-sri": "^2.1.0",
"ember-cli-uglify": "^2.0.0",
"ember-composable-helpers": "^2.3.1",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why include this? What helpers are we using?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are using 'pipe' helper in question/index/template.hbs for chaining multiple actions on a single event.

"ember-data": "~3.3.0",
"ember-datetime-picker": "^0.2.1",
"ember-decorators": "^2.2.0",
Expand Down