FEATURE: Add seen/unseen filters to advanced search UI.

https://meta.discourse.org/t/advanced-search-posts-that-i-have-seen/57966
This commit is contained in:
Guo Xiang Tan 2017-03-09 10:45:43 +08:00
parent 9cc79363e0
commit b419a5765e
4 changed files with 21 additions and 15 deletions

View File

@ -14,11 +14,10 @@ const REGEXP_MIN_POST_COUNT_PREFIX = /^min_post_count:/ig;
const REGEXP_POST_TIME_PREFIX = /^(before|after):/ig;
const REGEXP_TAGS_REPLACE = /(^(tags?:|#(?=[a-z0-9\-]+::tag))|::tag\s?$)/ig;
const REGEXP_IN_MATCH = /^in:(posted|watching|tracking|bookmarks|first|pinned|unpinned)/ig;
const REGEXP_IN_MATCH = /^in:(posted|watching|tracking|bookmarks|first|pinned|unpinned|wiki|unseen)/ig;
const REGEXP_SPECIAL_IN_LIKES_MATCH = /^in:likes/ig;
const REGEXP_SPECIAL_IN_PRIVATE_MATCH = /^in:private/ig;
const REGEXP_SPECIAL_IN_WIKI_MATCH = /^in:wiki/ig;
const REGEXP_SPECIAL_IN_SEEN_MATCH = /^in:seen/ig;
const REGEXP_CATEGORY_SLUG = /^(\#[a-zA-Z0-9\-:]+)/ig;
const REGEXP_CATEGORY_ID = /^(category:[0-9]+)/ig;
@ -28,6 +27,7 @@ export default Em.Component.extend({
classNames: ['search-advanced-options'],
inOptions: [
{name: I18n.t('search.advanced.filters.unseen'), value: "unseen"},
{name: I18n.t('search.advanced.filters.posted'), value: "posted"},
{name: I18n.t('search.advanced.filters.watching'), value: "watching"},
{name: I18n.t('search.advanced.filters.tracking'), value: "tracking"},
@ -35,6 +35,7 @@ export default Em.Component.extend({
{name: I18n.t('search.advanced.filters.first'), value: "first"},
{name: I18n.t('search.advanced.filters.pinned'), value: "pinned"},
{name: I18n.t('search.advanced.filters.unpinned'), value: "unpinned"},
{name: I18n.t('search.advanced.filters.wiki'), value: "wiki"},
],
statusOptions: [
{name: I18n.t('search.advanced.statuses.open'), value: "open"},
@ -75,7 +76,7 @@ export default Em.Component.extend({
in: {
likes: false,
private: false,
wiki: false
seen: false
}
},
status: '',
@ -102,7 +103,7 @@ export default Em.Component.extend({
this.setSearchedTermValue('searchedTerms.in', REGEXP_IN_PREFIX, REGEXP_IN_MATCH);
this.setSearchedTermSpecialInValue('searchedTerms.special.in.likes', REGEXP_SPECIAL_IN_LIKES_MATCH);
this.setSearchedTermSpecialInValue('searchedTerms.special.in.private', REGEXP_SPECIAL_IN_PRIVATE_MATCH);
this.setSearchedTermSpecialInValue('searchedTerms.special.in.wiki', REGEXP_SPECIAL_IN_WIKI_MATCH);
this.setSearchedTermSpecialInValue('searchedTerms.special.in.seen', REGEXP_SPECIAL_IN_SEEN_MATCH);
this.setSearchedTermValue('searchedTerms.status', REGEXP_STATUS_PREFIX);
this.setSearchedTermValueForPostTime();
this.setSearchedTermValue('searchedTerms.min_post_count', REGEXP_MIN_POST_COUNT_PREFIX);
@ -438,15 +439,15 @@ export default Em.Component.extend({
}
},
@observes('searchedTerms.special.in.wiki')
updateSearchTermForSpecialInWiki() {
const match = this.filterBlocks(REGEXP_SPECIAL_IN_WIKI_MATCH);
const inFilter = this.get('searchedTerms.special.in.wiki');
@observes('searchedTerms.special.in.seen')
updateSearchTermForSpecialInSeen() {
const match = this.filterBlocks(REGEXP_SPECIAL_IN_SEEN_MATCH);
const inFilter = this.get('searchedTerms.special.in.seen');
let searchTerm = this.get('searchTerm') || '';
if (inFilter) {
if (match.length === 0) {
searchTerm += ` in:wiki`;
searchTerm += ` in:seen`;
this.set('searchTerm', searchTerm.trim());
}
} else if (match.length !== 0) {

View File

@ -53,7 +53,7 @@
<section class='field'>
<label>{{input type="checkbox" class="in-likes" checked=searchedTerms.special.in.likes}} {{i18n "search.advanced.filters.likes"}}</label>
<label>{{input type="checkbox" class="in-private" checked=searchedTerms.special.in.private}} {{i18n "search.advanced.filters.private"}}</label>
<label>{{input type="checkbox" class="in-wiki" checked=searchedTerms.special.in.wiki}} {{i18n "search.advanced.filters.wiki"}}</label>
<label>{{input type="checkbox" class="in-seen" checked=searchedTerms.special.in.seen}} {{i18n "search.advanced.filters.seen"}}</label>
</section>
{{combo-box id="in" valueAttribute="value" content=inOptions value=searchedTerms.in none="user.locale.any"}}
</div>

View File

@ -1316,6 +1316,8 @@ en:
first: are the very first post
pinned: are pinned
unpinned: are not pinned
seen: I've read
unseen: I've not read
wiki: are wiki
statuses:
label: Where topics

View File

@ -233,15 +233,18 @@ test("update in:private filter through advanced search ui", assert => {
});
});
test("update in:wiki filter through advanced search ui", assert => {
test("update in:seen filter through advanced search ui", assert => {
visit("/search");
fillIn('.search input.full-page-search', 'none');
click('.search-advanced-btn');
click('.search-advanced-options .in-wiki');
click('.search-advanced-options .in-seen');
andThen(() => {
assert.ok(exists('.search-advanced-options .in-wiki:checked'), 'has "are wiki" populated');
assert.equal(find('.search input.full-page-search').val(), "none in:wiki", 'has updated search term to "none in:wiki"');
assert.ok(exists('.search-advanced-options .in-seen:checked'), 'it should check the right checkbox');
assert.equal(find('.search input.full-page-search').val(), "none in:seen",
'it should update the search term'
);
});
});