Skip to content

Commit

Permalink
Merge pull request #772 from Martii/Issue-641
Browse files Browse the repository at this point in the history
Add inverse filter list

Auto-merge
  • Loading branch information
Martii committed Oct 20, 2015
2 parents 89e2321 + b12f1c7 commit b9f1765
Show file tree
Hide file tree
Showing 11 changed files with 84 additions and 29 deletions.
2 changes: 1 addition & 1 deletion controllers/group.js
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ exports.view = function (aReq, aRes, aNext) {

// Empty list
options.scriptListIsEmptyMessage = 'No scripts.';
if (options.isFlagged) {
if (!!options.isFlagged) {
if (options.librariesOnly) {
options.scriptListIsEmptyMessage = 'No flagged libraries.';
} else {
Expand Down
10 changes: 5 additions & 5 deletions controllers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ exports.home = function (aReq, aRes) {

// Empty list
options.scriptListIsEmptyMessage = 'No scripts.';
if (options.isFlagged) {
if (!!options.isFlagged) {
if (options.librariesOnly) {
options.scriptListIsEmptyMessage = 'No flagged libraries.';
} else {
Expand All @@ -134,13 +134,13 @@ exports.home = function (aReq, aRes) {

// Heading
if (options.librariesOnly) {
options.pageHeading = options.isFlagged ? 'Flagged Libraries' : 'Libraries';
options.pageHeading = !!options.isFlagged ? 'Flagged Libraries' : 'Libraries';
} else {
options.pageHeading = options.isFlagged ? 'Flagged Scripts' : 'Scripts';
options.pageHeading = !!options.isFlagged ? 'Flagged Scripts' : 'Scripts';
}

// Page metadata
if (options.isFlagged) {
if (!!options.isFlagged) {
if (options.librariesOnly) {
pageMetadata(options, ['Flagged Libraries', 'Moderation']);
} else {
Expand All @@ -155,7 +155,7 @@ exports.home = function (aReq, aRes) {

async.parallel([
function (aCallback) {
if (!options.isFlagged || !options.isAdmin) { // NOTE: Watchpoint
if (!!!options.isFlagged || !options.isAdmin) { // NOTE: Watchpoint
aCallback();
return;
}
Expand Down
12 changes: 6 additions & 6 deletions controllers/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,17 +223,17 @@ exports.userListPage = function (aReq, aRes, aNext) {

// Empty list
options.userListIsEmptyMessage = 'No users.';
if (options.isFlagged) {
if (!!options.isFlagged) {
options.userListIsEmptyMessage = 'No flagged users.';
} else if (options.searchBarValue) {
options.userListIsEmptyMessage = 'We couldn\'t find any users by this name.';
}

// Heading
options.pageHeading = options.isFlagged ? 'Flagged Users' : 'Users';
options.pageHeading = !!options.isFlagged ? 'Flagged Users' : 'Users';

// Page metadata
if (options.isFlagged) {
if (!!options.isFlagged) {
pageMetadata(options, ['Flagged Users', 'Moderation']);
}
}
Expand All @@ -248,7 +248,7 @@ exports.userListPage = function (aReq, aRes, aNext) {

async.parallel([
function (aCallback) {
if (!options.isFlagged || !options.isAdmin) { // NOTE: Watchpoint
if (!!!options.isFlagged || !options.isAdmin) { // NOTE: Watchpoint
aCallback();
return;
}
Expand Down Expand Up @@ -524,7 +524,7 @@ exports.userScriptListPage = function (aReq, aRes, aNext) {

// Empty list
options.scriptListIsEmptyMessage = 'No scripts.';
if (options.isFlagged) {
if (!!options.isFlagged) {
if (options.librariesOnly) {
options.scriptListIsEmptyMessage = 'No flagged libraries.';
} else {
Expand All @@ -547,7 +547,7 @@ exports.userScriptListPage = function (aReq, aRes, aNext) {

async.parallel([
function (aCallback) {
if (!options.isFlagged || !options.isAdmin) { // NOTE: Watchpoint
if (!!!options.isFlagged || !options.isAdmin) { // NOTE: Watchpoint
aCallback();
return;
}
Expand Down
50 changes: 42 additions & 8 deletions libs/modelQuery.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,25 +182,59 @@ var applyModelListQueryFlaggedFilter = function (aModelListQuery, aOptions, aFla
if (aOptions.isYou || aOptions.isMod) {
// Mod
if (aFlaggedQuery) {
if (aFlaggedQuery === 'true') {
aOptions.isFlagged = true;
aOptions.searchBarPlaceholder = aOptions.searchBarPlaceholder.replace(/^Search /, 'Search Flagged ');
if (!_.findWhere(aOptions.searchBarFormHiddenVariables, { name: 'flagged' })) {
aOptions.searchBarFormHiddenVariables.push({ name: 'flagged', value: 'true' });
}
aModelListQuery.and({ flags: { $gt: 0 } });

aOptions.isFlagged = aFlaggedQuery;
aOptions.searchBarPlaceholder = aOptions.searchBarPlaceholder.replace(
/^Search /, 'Search Flagged '
);

switch (aOptions.isFlagged) {
case 'none':
if (aOptions.isAdmin) {
// Filter nothing but still show Flagged column
break;
}
// fallthrough
case 'absolute':
if (aOptions.isAdmin) {
aOptions.filterAbsolute = true;
aModelListQuery.and({ flagsAbsolute: { $gt: 0 } }); // TODO: This does not exist yet
break;
}
// fallthrough
default:
// Ensure default depending on role
if (aOptions.isAdmin) {
aOptions.isFlagged = 'critical';
aOptions.filterCritical = true;

} else {
aOptions.isFlagged = 'true';
}

aModelListQuery.and({ flags: { $gt: 0 } });
break;
}

if (!_.findWhere(aOptions.searchBarFormHiddenVariables, { name: 'flagged' })) {
aOptions.searchBarFormHiddenVariables.push({ name: 'flagged', value: aOptions.isFlagged });
}

} else {

// Remove `flagged` form variable if present
aOptions.searchBarFormHiddenVariables = _.without(
aOptions.searchBarFormHiddenVariables,
_.findWhere(aOptions.searchBarFormHiddenVariables, { name: 'flagged', value: 'true' })
_.findWhere(aOptions.searchBarFormHiddenVariables, { name: 'flagged' })
);

}
} else {

// Hide
// Script.flagged is undefined by default.
aModelListQuery.and({ flagged: { $ne: true } });

}
};
exports.applyModelListQueryFlaggedFilter = applyModelListQueryFlaggedFilter;
Expand Down
6 changes: 6 additions & 0 deletions views/includes/flagAdminToolFlaggedFilters.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<h3>Filters</h3>
<div class="list-group">
<a class="list-group-item list-group-item-info" href="?flagged=none{{#searchBarValue}}&q={{searchBarValue}}{{/searchBarValue}}"><i class="fa fa-fw fa-times"></i> Clear Filter</a>
<a class="list-group-item{{#filterCritical}} active{{/filterCritical}}" href="?flagged=critical{{#searchBarValue}}&q={{searchBarValue}}{{/searchBarValue}}"><i class="fa fa-fw fa-flag-o"></i> Critical Flags</a>
<a class="list-group-item{{#filterAbsolute}} active{{/filterAbsolute}}" href="?flagged=absolute{{#searchBarValue}}&q={{searchBarValue}}{{/searchBarValue}}"><i class="fa fa-fw fa-flag"></i> Absolute Flags</a>
</div>
8 changes: 4 additions & 4 deletions views/includes/scriptList.html
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<table class="table table-hover">
<thead>
<tr>
<th class="text-center"><a href="?orderBy=name&orderDir={{orderDir.name}}{{#searchBarValue}}&q={{searchBarValue}}{{/searchBarValue}}{{#librariesOnly}}&library=true{{/librariesOnly}}{{#isFlagged}}&flagged=true{{/isFlagged}}">Name</a></th>
{{^librariesOnly}}<th class="text-center td-fit"><a href="?orderBy=installs&orderDir={{orderDir.install}}{{#searchBarValue}}&q={{searchBarValue}}{{/searchBarValue}}{{#isFlagged}}&flagged=true{{/isFlagged}}">Installs</a></th>{{/librariesOnly}}
<th class="text-center td-fit"><a href="?orderBy=rating&orderDir={{orderDir.rating}}{{#searchBarValue}}&q={{searchBarValue}}{{/searchBarValue}}{{#librariesOnly}}&library=true{{/librariesOnly}}{{#isFlagged}}&flagged=true{{/isFlagged}}">Rating</a></th>
<th class="text-center td-fit"><a href="?orderBy=updated&orderDir={{orderDir.updated}}{{#searchBarValue}}&q={{searchBarValue}}{{/searchBarValue}}{{#librariesOnly}}&library=true{{/librariesOnly}}{{#isFlagged}}&flagged=true{{/isFlagged}}">Last Updated</a></th>
<th class="text-center"><a href="?orderBy=name&orderDir={{orderDir.name}}{{#searchBarValue}}&q={{searchBarValue}}{{/searchBarValue}}{{#librariesOnly}}&library=true{{/librariesOnly}}{{#isFlagged}}&flagged={{isFlagged}}{{/isFlagged}}">Name</a></th>
{{^librariesOnly}}<th class="text-center td-fit"><a href="?orderBy=installs&orderDir={{orderDir.install}}{{#searchBarValue}}&q={{searchBarValue}}{{/searchBarValue}}{{#isFlagged}}&flagged={{isFlagged}}{{/isFlagged}}">Installs</a></th>{{/librariesOnly}}
<th class="text-center td-fit"><a href="?orderBy=rating&orderDir={{orderDir.rating}}{{#searchBarValue}}&q={{searchBarValue}}{{/searchBarValue}}{{#librariesOnly}}&library=true{{/librariesOnly}}{{#isFlagged}}&flagged={{isFlagged}}{{/isFlagged}}">Rating</a></th>
<th class="text-center td-fit"><a href="?orderBy=updated&orderDir={{orderDir.updated}}{{#searchBarValue}}&q={{searchBarValue}}{{/searchBarValue}}{{#librariesOnly}}&library=true{{/librariesOnly}}{{#isFlagged}}&flagged={{isFlagged}}{{/isFlagged}}">Last Updated</a></th>
{{#hasFlagged}}
<th>Flagged</th>
{{/hasFlagged}}
Expand Down
4 changes: 2 additions & 2 deletions views/includes/userList.html
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<table class="table table-hover table-condensed">
<thead>
<tr>
<th><a href="?orderBy=name&orderDir={{orderDir.name}}{{#searchBarValue}}&q={{searchBarValue}}{{/searchBarValue}}{{#isFlagged}}&flagged=true{{/isFlagged}}">Name</a></th>
<th class="td-fit"><a href="?orderBy=role&orderDir={{orderDir.role}}{{#searchBarValue}}&q={{searchBarValue}}{{/searchBarValue}}{{#isFlagged}}&flagged=true{{/isFlagged}}">Rank</a></th>
<th><a href="?orderBy=name&orderDir={{orderDir.name}}{{#searchBarValue}}&q={{searchBarValue}}{{/searchBarValue}}{{#isFlagged}}&flagged={{isFlagged}}{{/isFlagged}}">Name</a></th>
<th class="td-fit"><a href="?orderBy=role&orderDir={{orderDir.role}}{{#searchBarValue}}&q={{searchBarValue}}{{/searchBarValue}}{{#isFlagged}}&flagged={{isFlagged}}{{/isFlagged}}">Rank</a></th>
{{#hasFlagged}}
<th>Flagged</th>
{{/hasFlagged}}
Expand Down
6 changes: 3 additions & 3 deletions views/pages/modPage.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@
<h3>Flagged Items</h3>
<p>These are items over their threshold.</p>
<div class="list-group">
<a href="/?flagged=true" class="list-group-item">
<a href="/?flagged={{#isAdmin}}critical{{/isAdmin}}{{^isAdmin}}true{{/isAdmin}}" class="list-group-item">
<i class="fa fa-fw fa-file-code-o"></i> <i class="fa fa-fw fa-flag"></i> Flagged Scripts
</a>
<a href="/?library=true&flagged=true" class="list-group-item">
<a href="/?library=true&flagged={{#isAdmin}}critical{{/isAdmin}}{{^isAdmin}}true{{/isAdmin}}" class="list-group-item">
<i class="fa fa-fw fa-file-excel-o"></i> <i class="fa fa-fw fa-flag"></i> Flagged Libraries
</a>
<a href="/users?flagged=true" class="list-group-item">
<a href="/users?flagged={{#isAdmin}}critical{{/isAdmin}}{{^isAdmin}}true{{/isAdmin}}" class="list-group-item">
<i class="fa fa-fw fa-user"></i> <i class="fa fa-fw fa-flag"></i> Flagged Users
</a>
</div>
Expand Down
5 changes: 5 additions & 0 deletions views/pages/scriptListPage.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ <h2 class="page-heading">
</div>
<div class="col-sm-4">
{{> includes/searchBarPanel.html }}
{{#isFlagged}}
{{#isAdmin}}
{{> includes/flagAdminToolFlaggedFilters.html }}
{{/isAdmin}}
{{/isFlagged}}
{{> includes/popularGroupsPanel.html }}
{{> includes/announcementsPanel.html }}
</div>
Expand Down
5 changes: 5 additions & 0 deletions views/pages/userListPage.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ <h2 class="page-heading">
</div>
<div class="col-sm-4">
{{> includes/searchBarPanel.html }}
{{#isFlagged}}
{{#isAdmin}}
{{> includes/flagAdminToolFlaggedFilters.html }}
{{/isAdmin}}
{{/isFlagged}}
</div>
</div>
</div>
Expand Down
5 changes: 5 additions & 0 deletions views/pages/userScriptListPage.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@
</div>
<div class="container-fluid col-sm-4">
{{> includes/searchBarPanel.html }}
{{#isFlagged}}
{{#isAdmin}}
{{> includes/flagAdminToolFlaggedFilters.html }}
{{/isAdmin}}
{{/isFlagged}}
{{> includes/userStatsPanel.html }}
</div>
</div>
Expand Down

0 comments on commit b9f1765

Please sign in to comment.