Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reestablish the model filters #700

Merged
merged 1 commit into from
Aug 5, 2015
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
34 changes: 33 additions & 1 deletion controllers/moderation.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ exports.removedItemListPage = function (aReq, aRes, aNext) {
});
}

//
options.byModel = aReq.query.byModel !== undefined ? aReq.query.byModel : null;

// Page metadata
pageMetadata(options, 'Graveyard');

Expand All @@ -77,8 +80,37 @@ exports.removedItemListPage = function (aReq, aRes, aNext) {
// removedItemListQuery
var removedItemListQuery = Remove.find();

// removedItemListQuery: byModel
if (options.byModel) {
modelQuery.findOrDefaultIfNull(removedItemListQuery, 'model', options.byModel, null);
Copy link
Member Author

Choose a reason for hiding this comment

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

I also didn't know what to put in the parm list where the null is... it does work if I do /.*/ in R70 above however it (always) transfers that to the QSP which is probably undesirable which is why I ended up doing the R84 conditional above to ensure the default to all models. Putting in '{ $in [...] }' (the dot, dot, dot meaning all the model names) doesn't like the findOrDefaultIfNull routine as it puts the single quotes in the condition which can't happen... and of course take them out and the V8 JavaScript debugger throws an exception.

}

// removedItemListQuery: Defaults
modelQuery.applyRemovedItemListQueryDefaults(removedItemListQuery, options, aReq);
switch (options.byModel) {
case 'User':
modelQuery.applyRemovedItemUserListQueryDefaults(removedItemListQuery, options, aReq);
break;
case 'Script':
modelQuery.applyRemovedItemScriptListQueryDefaults(removedItemListQuery, options, aReq);
break;
case 'Comment':
modelQuery.applyRemovedItemCommentListQueryDefaults(removedItemListQuery, options, aReq);
break;
case 'Discussion':
modelQuery.applyRemovedItemDiscussionListQueryDefaults(removedItemListQuery, options, aReq);
break;
case 'Flag':
modelQuery.applyRemovedItemFlagListQueryDefaults(removedItemListQuery, options, aReq);
break;
case 'Group':
modelQuery.applyRemovedItemGroupListQueryDefaults(removedItemListQuery, options, aReq);
break;
case 'Vote':
modelQuery.applyRemovedItemVoteListQueryDefaults(removedItemListQuery, options, aReq);
break;
default:
modelQuery.applyRemovedItemListQueryDefaults(removedItemListQuery, options, aReq);
}

// removedItemListQuery: Pagination
var pagination = options.pagination; // is set in modelQuery.apply___ListQueryDefaults
Expand Down
102 changes: 100 additions & 2 deletions libs/modelQuery.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ var parseUserSearchQuery = function (aUserListQuery, aQuery) {
fullWordMatchFields: []
});
};
exports.parseCommentSearchQuery = parseCommentSearchQuery;
exports.parseUserSearchQuery = parseUserSearchQuery;
Copy link
Member Author

Choose a reason for hiding this comment

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

This is already exported once... so matched it with it's function... this is the bug mentioned.


var parseRemovedItemSearchQuery = function (aRemovedItemListQuery, aQuery) {
parseModelListSearchQuery(aRemovedItemListQuery, aQuery, {
Expand All @@ -140,7 +140,7 @@ var parseRemovedItemSearchQuery = function (aRemovedItemListQuery, aQuery) {
fullWordMatchFields: ['model']
});
};
exports.parseCommentSearchQuery = parseCommentSearchQuery;
exports.parseRemovedItemSearchQuery = parseRemovedItemSearchQuery;
Copy link
Member Author

Choose a reason for hiding this comment

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

This is already exported twice... so matched it with it's function... this is the bug mentioned.


exports.applyDiscussionCategoryFilter = function (aDiscussionListQuery, aOptions, aCatergorySlug) {
if (aCatergorySlug === 'all') {
Expand Down Expand Up @@ -281,6 +281,104 @@ exports.applyUserListQueryDefaults = function (aUserListQuery, aOptions, aReq) {
});
};

var removedItemUserListQueryDefaults = {
defaultSort: '-removed',
parseSearchQueryFn: parseRemovedItemSearchQuery,
searchBarPlaceholder: 'Search Removed Items in Users',
searchBarFormHiddenVariables: [
{ name: 'byModel', value: 'User' }
],
filterFlaggedItems: false
}
exports.removedItemUserListQueryDefaults = removedItemUserListQueryDefaults;
exports.applyRemovedItemUserListQueryDefaults = function (aRemovedItemUserListQuery, aOptions, aReq) {
applyModelListQueryDefaults(aRemovedItemUserListQuery, aOptions, aReq, removedItemUserListQueryDefaults);
};

var removedItemScriptListQueryDefaults = {
defaultSort: '-removed',
parseSearchQueryFn: parseRemovedItemSearchQuery,
searchBarPlaceholder: 'Search Removed Items in Scripts',
searchBarFormHiddenVariables: [
{ name: 'byModel', value: 'Script' }
],
filterFlaggedItems: false
}
exports.removedItemScriptListQueryDefaults = removedItemScriptListQueryDefaults;
exports.applyRemovedItemScriptListQueryDefaults = function (aRemovedItemScriptListQuery, aOptions, aReq) {
applyModelListQueryDefaults(aRemovedItemScriptListQuery, aOptions, aReq, removedItemScriptListQueryDefaults);
};

var removedItemCommentListQueryDefaults = {
defaultSort: '-removed',
parseSearchQueryFn: parseRemovedItemSearchQuery,
searchBarPlaceholder: 'Search Removed Items in Comments',
searchBarFormHiddenVariables: [
{ name: 'byModel', value: 'Comment' }
],
filterFlaggedItems: false
}
exports.removedItemCommentListQueryDefaults = removedItemCommentListQueryDefaults;
exports.applyRemovedItemCommentListQueryDefaults = function (aRemovedItemCommentListQuery, aOptions, aReq) {
applyModelListQueryDefaults(aRemovedItemCommentListQuery, aOptions, aReq, removedItemCommentListQueryDefaults);
};

var removedItemDiscussionListQueryDefaults = {
defaultSort: '-removed',
parseSearchQueryFn: parseRemovedItemSearchQuery,
searchBarPlaceholder: 'Search Removed Items in Discussions',
searchBarFormHiddenVariables: [
{ name: 'byModel', value: 'Discussion' }
],
filterFlaggedItems: false
}
exports.removedItemDiscussionListQueryDefaults = removedItemDiscussionListQueryDefaults;
exports.applyRemovedItemDiscussionListQueryDefaults = function (aRemovedItemDiscussionListQuery, aOptions, aReq) {
applyModelListQueryDefaults(aRemovedItemDiscussionListQuery, aOptions, aReq, removedItemDiscussionListQueryDefaults);
};

var removedItemFlagListQueryDefaults = {
defaultSort: '-removed',
parseSearchQueryFn: parseRemovedItemSearchQuery,
searchBarPlaceholder: 'Search Removed Items in Flags',
searchBarFormHiddenVariables: [
{ name: 'byModel', value: 'Flag' }
],
filterFlaggedItems: false
}
exports.removedItemFlagListQueryDefaults = removedItemFlagListQueryDefaults;
exports.applyRemovedItemFlagListQueryDefaults = function (aRemovedItemFlagListQuery, aOptions, aReq) {
applyModelListQueryDefaults(aRemovedItemFlagListQuery, aOptions, aReq, removedItemFlagListQueryDefaults);
};

var removedItemGroupListQueryDefaults = {
defaultSort: '-removed',
parseSearchQueryFn: parseRemovedItemSearchQuery,
searchBarPlaceholder: 'Search Removed Items in Groups',
searchBarFormHiddenVariables: [
{ name: 'byModel', value: 'Group' }
],
filterFlaggedItems: false
}
exports.removedItemGroupListQueryDefaults = removedItemGroupListQueryDefaults;
exports.applyRemovedItemGroupListQueryDefaults = function (aRemovedItemGroupListQuery, aOptions, aReq) {
applyModelListQueryDefaults(aRemovedItemGroupListQuery, aOptions, aReq, removedItemGroupListQueryDefaults);
};

var removedItemVoteListQueryDefaults = {
defaultSort: '-removed',
parseSearchQueryFn: parseRemovedItemSearchQuery,
searchBarPlaceholder: 'Search Removed Items in Votes',
searchBarFormHiddenVariables: [
{ name: 'byModel', value: 'Vote' }
],
filterFlaggedItems: false
}
exports.removedItemVoteListQueryDefaults = removedItemVoteListQueryDefaults;
exports.applyRemovedItemVoteListQueryDefaults = function (aRemovedItemVoteListQuery, aOptions, aReq) {
applyModelListQueryDefaults(aRemovedItemVoteListQuery, aOptions, aReq, removedItemVoteListQueryDefaults);
};

exports.applyRemovedItemListQueryDefaults = function (aRemovedItemListQuery, aOptions, aReq) {
applyModelListQueryDefaults(aRemovedItemListQuery, aOptions, aReq, {
defaultSort: '-removed',
Expand Down
6 changes: 3 additions & 3 deletions views/includes/removedItemList.html
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<table class="table table-hover table-condensed">
<thead>
<tr>
<th class="text-center td-fit"><a href="?orderBy=model&orderDir={{orderDir.model}}{{#searchBarValue}}&q={{searchBarValue}}{{/searchBarValue}}">Type</a></th>
<th class="text-center td-fit"><a href="?orderBy=model&orderDir={{orderDir.model}}{{#byModel}}&byModel={{byModel}}{{/byModel}}{{#searchBarValue}}&q={{searchBarValue}}{{/searchBarValue}}">Model</a></th>
<th>Item</th>
<th>Reason</th>
<th class="text-center td-fit"><a href="?orderBy=removerName&orderDir={{orderDir.removerName}}{{#searchBarValue}}&q={{searchBarValue}}{{/searchBarValue}}">Removed By</a></th>
<th class="text-center td-fit"><a href="?orderBy=removed&orderDir={{orderDir.removed}}{{#searchBarValue}}&q={{searchBarValue}}{{/searchBarValue}}">Date</a></th>
<th class="text-center td-fit"><a href="?orderBy=removerName&orderDir={{orderDir.removerName}}{{#byModel}}&byModel={{byModel}}{{/byModel}}{{#searchBarValue}}&q={{searchBarValue}}{{/searchBarValue}}">Removed By</a></th>
<th class="text-center td-fit"><a href="?orderBy=removed&orderDir={{orderDir.removed}}{{#byModel}}&byModel={{byModel}}{{/byModel}}{{#searchBarValue}}&q={{searchBarValue}}{{/searchBarValue}}">Date</a></th>
</tr>
</thead>
<tbody>
Expand Down
17 changes: 9 additions & 8 deletions views/pages/removedItemListPage.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,16 @@ <h2 class="page-heading">
{{> includes/searchBarPanel.html }}
<h3>Filters</h3>
<div class="list-group">
<a href="./removed" class="list-group-item"><i class="fa fa-fw fa-times"></i> Clear search</a>
<a href="?q=User" class="list-group-item"><i class="fa fa-fw fa-search"></i> Users</a>
<a href="?q=Script" class="list-group-item"><i class="fa fa-fw fa-search"></i> Scripts</a>
<a href="?q=Comment" class="list-group-item"><i class="fa fa-fw fa-search"></i> Comments</a>
<a href="?q=Discussion" class="list-group-item"><i class="fa fa-fw fa-search"></i> Discussion</a>
<a href="?q=Flag" class="list-group-item"><i class="fa fa-fw fa-search"></i> Flags</a>
<a href="?q=Group" class="list-group-item"><i class="fa fa-fw fa-search"></i> Groups</a>
<a href="?q=Vote" class="list-group-item"><i class="fa fa-fw fa-search"></i> Votes</a>
<a href="./removed{{#searchBarValue}}?q={{searchBarValue}}{{/searchBarValue}}" class="list-group-item"><i class="fa fa-fw fa-times"></i> Clear Filter</a>
<a href="?byModel=User{{#searchBarValue}}&q={{searchBarValue}}{{/searchBarValue}}" class="list-group-item"><i class="fa fa-fw fa-user"></i> User</a>
<a href="?byModel=Script{{#searchBarValue}}&q={{searchBarValue}}{{/searchBarValue}}" class="list-group-item"><i class="fa fa-fw fa-file"></i> Script</a>
<a href="?byModel=Comment{{#searchBarValue}}&q={{searchBarValue}}{{/searchBarValue}}" class="list-group-item"><i class="fa fa-fw fa-comment"></i> Comment</a>
<a href="?byModel=Discussion{{#searchBarValue}}&q={{searchBarValue}}{{/searchBarValue}}" class="list-group-item"><i class="fa fa-fw fa-commenting"></i> Discussion</a>
<a href="?byModel=Flag{{#searchBarValue}}&q={{searchBarValue}}{{/searchBarValue}}" class="list-group-item"><i class="fa fa-fw fa-flag"></i> Flag</a>
<a href="?byModel=Group{{#searchBarValue}}&q={{searchBarValue}}{{/searchBarValue}}" class="list-group-item"><i class="fa fa-fw fa-tag"></i> Group</a>
<a href="?byModel=Vote{{#searchBarValue}}&q={{searchBarValue}}{{/searchBarValue}}" class="list-group-item"><i class="fa fa-fw fa-signal"></i> Vote</a>
</div>

</div>
</div>
</div>
Expand Down