This repository has been archived by the owner on Nov 28, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add dropdown filters for post type, author, and tag (#554)
refs TryGhost/Ghost#7860 - removes post type filter links - adds dropdown filters for post type, author, and tag - replaces custom refresh on query params change with Ember's standard `refreshModel` config
- Loading branch information
1 parent
ffa1afb
commit dc351d3
Showing
13 changed files
with
305 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import Controller from 'ember-controller'; | ||
import {readOnly} from 'ember-computed'; | ||
import injectController from 'ember-controller/inject'; | ||
|
||
export default Controller.extend({ | ||
|
||
postsController: injectController('posts'), | ||
|
||
availableTypes: readOnly('postsController.availableTypes'), | ||
selectedType: readOnly('postsController.selectedType'), | ||
availableTags: readOnly('postsController.availableTags'), | ||
selectedTag: readOnly('postsController.selectedTag'), | ||
availableAuthors: readOnly('postsController.availableAuthors'), | ||
selectedAuthor: readOnly('postsController.selectedAuthor') | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,106 @@ | ||
import Controller from 'ember-controller'; | ||
import computed from 'ember-computed'; | ||
import injectService from 'ember-service/inject'; | ||
import get from 'ember-metal/get'; | ||
|
||
export default Controller.extend({ | ||
|
||
queryParams: ['type'], | ||
session: injectService(), | ||
store: injectService(), | ||
|
||
queryParams: ['type', 'author', 'tag'], | ||
type: null, | ||
author: null, | ||
tag: null, | ||
|
||
session: injectService(), | ||
_hasLoadedTags: false, | ||
_hasLoadedAuthors: false, | ||
|
||
showDeletePostModal: false, | ||
|
||
showingAll: computed('type', function () { | ||
return this.get('type') === null; | ||
availableTypes: [{ | ||
name: 'All posts', | ||
value: null | ||
}, { | ||
name: 'Draft posts', | ||
value: 'draft' | ||
}, { | ||
name: 'Published posts', | ||
value: 'published' | ||
}, { | ||
name: 'Scheduled posts', | ||
value: 'scheduled' | ||
}, { | ||
name: 'Pages', | ||
value: 'page' | ||
}], | ||
|
||
showingAll: computed('type', 'author', 'tag', function () { | ||
let {type, author, tag} = this.getProperties(['type', 'author', 'tag']); | ||
|
||
return !type && !author && !tag; | ||
}), | ||
|
||
selectedType: computed('type', function () { | ||
let types = this.get('availableTypes'); | ||
return types.findBy('value', this.get('type')); | ||
}), | ||
|
||
_availableTags: computed(function () { | ||
return this.get('store').peekAll('tag'); | ||
}), | ||
|
||
availableTags: computed('_availableTags.[]', function () { | ||
let tags = this.get('_availableTags'); | ||
let options = tags.toArray(); | ||
|
||
options.unshiftObject({name: 'All tags', slug: null}); | ||
|
||
return options; | ||
}), | ||
|
||
selectedTag: computed('tag', '_availableTags.[]', function () { | ||
let tag = this.get('tag'); | ||
let tags = this.get('availableTags'); | ||
|
||
return tags.findBy('slug', tag); | ||
}), | ||
|
||
_availableAuthors: computed(function () { | ||
return this.get('store').peekAll('user'); | ||
}), | ||
|
||
availableAuthors: computed('_availableAuthors.[]', function () { | ||
let authors = this.get('_availableAuthors'); | ||
let options = authors.toArray(); | ||
|
||
options.unshiftObject({name: 'All authors', slug: null}); | ||
|
||
return options; | ||
}), | ||
|
||
selectedAuthor: computed('author', 'availableAuthors.[]', function () { | ||
let author = this.get('author'); | ||
let authors = this.get('availableAuthors'); | ||
|
||
return authors.findBy('slug', author); | ||
}), | ||
|
||
actions: { | ||
toggleDeletePostModal() { | ||
this.toggleProperty('showDeletePostModal'); | ||
}, | ||
|
||
changeType(type) { | ||
this.set('type', get(type, 'value')); | ||
}, | ||
|
||
changeAuthor(author) { | ||
this.set('author', get(author, 'slug')); | ||
}, | ||
|
||
changeTag(tag) { | ||
this.set('tag', get(tag, 'slug')); | ||
} | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
import {Model} from 'ember-cli-mirage'; | ||
import {Model, belongsTo} from 'ember-cli-mirage'; | ||
|
||
export default Model.extend(); | ||
export default Model.extend({ | ||
author: belongsTo('user') | ||
}); |
Oops, something went wrong.