mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 16:46:12 +01:00
feat: closes #11902, ability to clear search history
This commit is contained in:
@@ -92,5 +92,7 @@
|
|||||||
"end": "End",
|
"end": "End",
|
||||||
"filter": "Filter",
|
"filter": "Filter",
|
||||||
"view-as-json": "View as JSON",
|
"view-as-json": "View as JSON",
|
||||||
"expand-analytics": "Expand analytics"
|
"expand-analytics": "Expand analytics",
|
||||||
|
"clear-search-history": "Clear Search History",
|
||||||
|
"clear-search-history-confirm": "Are you sure you want to clear entire search history?"
|
||||||
}
|
}
|
||||||
|
|||||||
22
public/src/admin/dashboard/searches.js
Normal file
22
public/src/admin/dashboard/searches.js
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
define('admin/dashboard/searches', ['alerts', 'bootbox'], (alerts, bootbox) => {
|
||||||
|
const ACP = {};
|
||||||
|
|
||||||
|
ACP.init = () => {
|
||||||
|
$('#clear-search-history').on('click', () => {
|
||||||
|
bootbox.confirm('[[admin/dashboard:clear-search-history-confirm]]', function (ok) {
|
||||||
|
if (ok) {
|
||||||
|
socket.emit('admin.clearSearchHistory', function (err) {
|
||||||
|
if (err) {
|
||||||
|
return alerts.error(err);
|
||||||
|
}
|
||||||
|
ajaxify.refresh();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
return ACP;
|
||||||
|
});
|
||||||
@@ -26,7 +26,7 @@ module.exports = function (module) {
|
|||||||
module.scan = async function (params) {
|
module.scan = async function (params) {
|
||||||
let cursor = '0';
|
let cursor = '0';
|
||||||
let returnData = [];
|
let returnData = [];
|
||||||
const seen = {};
|
const seen = Object.create(null);
|
||||||
do {
|
do {
|
||||||
/* eslint-disable no-await-in-loop */
|
/* eslint-disable no-await-in-loop */
|
||||||
const res = await module.client.scan(cursor, 'MATCH', params.match, 'COUNT', 10000);
|
const res = await module.client.scan(cursor, 'MATCH', params.match, 'COUNT', 10000);
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ const events = require('../events');
|
|||||||
const db = require('../database');
|
const db = require('../database');
|
||||||
const privileges = require('../privileges');
|
const privileges = require('../privileges');
|
||||||
const websockets = require('./index');
|
const websockets = require('./index');
|
||||||
|
const batch = require('../batch');
|
||||||
const index = require('./index');
|
const index = require('./index');
|
||||||
const getAdminSearchDict = require('../admin/search').getDictionary;
|
const getAdminSearchDict = require('../admin/search').getDictionary;
|
||||||
|
|
||||||
@@ -117,4 +118,12 @@ SocketAdmin.getServerTime = function (socket, data, callback) {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
SocketAdmin.clearSearchHistory = async function () {
|
||||||
|
const keys = await db.scan({ match: 'searches:*' });
|
||||||
|
await batch.processArray(keys, db.deleteAll, {
|
||||||
|
batch: 500,
|
||||||
|
interval: 0,
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
require('../promisify')(SocketAdmin);
|
require('../promisify')(SocketAdmin);
|
||||||
|
|||||||
@@ -1,20 +1,21 @@
|
|||||||
<div class="row dashboard px-lg-4">
|
<div class="row dashboard px-lg-4">
|
||||||
<div class="col-12">
|
<div class="col-12">
|
||||||
|
<div class="d-flex justify-content-between align-items-center mb-3">
|
||||||
<form class="d-flex flex-wrap gap-3 align-sm-items-center mb-3" method="GET">
|
<form class="d-flex flex-wrap gap-3 align-sm-items-center" method="GET">
|
||||||
<div class="d-flex align-items-center gap-2">
|
<div class="d-flex align-items-center gap-2">
|
||||||
<label class="form-label mb-0" for="start">[[admin/dashboard:start]]</label>
|
<label class="form-label mb-0" for="start">[[admin/dashboard:start]]</label>
|
||||||
<input type="date" class="form-control form-control-sm w-auto" id="start" name="start" value="{startDate}">
|
<input type="date" class="form-control form-control-sm w-auto" id="start" name="start" value="{startDate}">
|
||||||
</div>
|
</div>
|
||||||
<div class="d-flex align-items-center gap-2">
|
<div class="d-flex align-items-center gap-2">
|
||||||
<label class="form-label mb-0" for="end">[[admin/dashboard:end]]</label>
|
<label class="form-label mb-0" for="end">[[admin/dashboard:end]]</label>
|
||||||
<input type="date" class="form-control form-control-sm w-auto" id="end" name="end" value="{endDate}">
|
<input type="date" class="form-control form-control-sm w-auto" id="end" name="end" value="{endDate}">
|
||||||
</div>
|
</div>
|
||||||
<div class="">
|
<div class="">
|
||||||
<button onclick="$('form').submit();return false;"class="btn btn-primary btn-sm" type="submit">[[admin/dashboard:filter]]</button>
|
<button onclick="$('form').submit();return false;"class="btn btn-primary btn-sm" type="submit">[[admin/dashboard:filter]]</button>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
|
<button id="clear-search-history" class="btn btn-sm btn-light"><i class="fa fa-trash text-danger"></i> [[admin/dashboard:clear-search-history]]</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
<table class="table table-sm text-sm search-list">
|
<table class="table table-sm text-sm search-list">
|
||||||
<thead>
|
<thead>
|
||||||
|
|||||||
Reference in New Issue
Block a user