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

Filter by usernote tag #546

Merged
merged 2 commits into from
Dec 15, 2021
Merged
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
23 changes: 21 additions & 2 deletions extension/data/modules/usernotes.js
Original file line number Diff line number Diff line change
Expand Up @@ -1045,6 +1045,10 @@ function usernotes () {
<div class="tb-un-info">
<span class="tb-info">There are ${userCount} users with ${noteCount} notes.</span>
<br> <input id="tb-unote-user-search" type="text" class="tb-input" placeholder="search for user"> <input id="tb-unote-contents-search" type="text" class="tb-input" placeholder="search for note contents">
<select name="tb-un-filter" id="tb-un-filter" class="selector tb-action-button">
<option value="all" default>All</option>
${colors.map(op => `<option value=${TBHelpers.htmlEncode(op.key)}>${TBHelpers.htmlEncode(op.text)}</option>`).join('')}
</select>
<br><br>
<button id="tb-un-prune-sb" class="tb-general-button">Prune deleted/suspended profiles</button>
</div></br></br>
Expand Down Expand Up @@ -1082,6 +1086,7 @@ function usernotes () {
// Variables to store the filter text
let userText = '';
let contentText = '';
let filterKey = 'all';

// Creates a new pager with the correct filtered items and replace
// the current one with the new one, debounced because typing delay
Expand All @@ -1090,8 +1095,18 @@ function usernotes () {
// notes based on `userText` and `contentText`
const filteredData = allUsers.map(user => ({
name: user.name,
// Filter out notes not matching `contentText`
notes: user.notes.filter(note => note.note.toLowerCase().includes(contentText.toLowerCase())),
// Filter out notes not matching `contentText` as well as filtering out keys
notes: user.notes.filter(note => {
if (!note.note.toLowerCase().includes(contentText.toLowerCase())) {
return false;
}

if (filterKey !== 'all' && filterKey !== note.type) {
return false;
}

return true;
}),
})).filter(user => {
// Filter out users not matching `userText`
if (userText && !user.name.toLowerCase().includes(userText.toLowerCase())) {
Expand Down Expand Up @@ -1128,6 +1143,10 @@ function usernotes () {
contentText = $(this).val();
refreshPager();
});
$body.find('#tb-un-filter').change(function () {
filterKey = $(this).val();
refreshPager();
});

// Process done
self.endProfile('manager-render');
Expand Down