diff --git a/doc/nginx.conf b/doc/nginx.conf
index 889f184..ca53af6 100644
--- a/doc/nginx.conf
+++ b/doc/nginx.conf
@@ -48,6 +48,7 @@ server {
rewrite ^/embed/(.*)$ /paste.php?embed&id=$1 last;
rewrite ^/report /report.php last;
rewrite ^/event /event.php last;
+ rewrite ^/rules /rules.php last;
location ~* \.(jpg|jpeg|png|gif|ico|css|js) {
add_header "Cache-Control" "public";
@@ -66,7 +67,7 @@ server {
}
# Deny directories that should not be publicly accessible.
- location ~ (/doc|/tmp|/includes|/config|/.git|/.ht|/js|/node_modules).* {
+ location ~ (/doc|/tmp|/includes|/config|/.git|/.ht|/js|/node_modules|/composer).* {
deny all;
}
diff --git a/js/archive.js b/js/archive.js
index 3241ce8..d05f003 100644
--- a/js/archive.js
+++ b/js/archive.js
@@ -7,7 +7,7 @@ whenReady(() => {
const urlParams = new URLSearchParams(window.location.search);
const myParam = urlParams.get('q');
- const apiUrl = myParam !== null ? '/api/ajax_pastes.php?q=' + myParam : '/api/ajax_pastes.php';
+ const apiUrl = /* myParam !== null ? '/api/ajax_pastes.php?q=' + myParam : */ '/api/ajax_pastes.php';
const table = new DataTable(document.getElementById('archive'), {
ajaxCallback: (resolve) => {
@@ -28,7 +28,7 @@ whenReady(() => {
tagColorClass = 'is-info';
}
- return `
+ return `
${escape(tagData.name)}
`;
}).join('');
@@ -38,7 +38,22 @@ whenReady(() => {
${escape(rowData.author)} |
${tags} |
`;
- }
+ },
+ filterCallback: (datum, query) => {
+ if (datum.title.indexOf(query) !== -1) {
+ return true;
+ }
+
+ /* this is inefficient */
+ for (const tag of datum.tags) {
+ if (tag.name.toLowerCase() === query.toLowerCase()) {
+ return true;
+ }
+ }
+
+ return false;
+ },
+ preFilter: myParam
});
table.attach();
});
\ No newline at end of file
diff --git a/js/data_tables.js b/js/data_tables.js
index 5a41d5b..9eca460 100644
--- a/js/data_tables.js
+++ b/js/data_tables.js
@@ -1,6 +1,5 @@
import { makeEl, clearEl } from "./dom";
-
class SimplePaginator {
constructor(element) {
this.element = element;
@@ -78,6 +77,7 @@ class DataTable {
this.ajaxCallback = options.ajaxCallback;
this.data = [];
+ this.unfilteredData = [];
this.totalRecords = -1;
this.perPage = 20;
@@ -85,9 +85,23 @@ class DataTable {
this.paginator = new SimplePaginator(this.container.querySelector('.paginator'));
+ this.filterCallback = options.filterCallback;
}
attach() {
+ this.filterField = this.container.querySelector('input.search');
+ if (this.filterField && this.filterCallback) {
+ this.filterField.addEventListener('keyup', evt => {
+ if (evt.target) {
+ this._updateFilter(evt.target.value);
+ }
+ });
+
+ if (this.options.preFilter) {
+ this.filterField.value = this.options.preFilter;
+ }
+ }
+
this.paginator.attach(this._updatePage.bind(this));
this._loadEntries();
}
@@ -95,12 +109,15 @@ class DataTable {
/* Load the requested data from the server, and when done, update the DOM. */
_loadEntries() {
new Promise(this.ajaxCallback)
- .then(this._updateEntries.bind(this));
+ .then(data => {
+ this.unfilteredData = data.data;
+ this._updateFilter(this.options.preFilter);
+ });
}
/* Update the DOM to reflect the current state of the data we have loaded */
_updateEntries(data) {
- this.data = data.data;
+ this.data = data;
this.totalRecords = this.data.length;
const bodyElement = this.element.querySelector('tbody');
@@ -123,7 +140,25 @@ class DataTable {
_updatePage(n) {
this.currentPage = n;
this.paginator.update(this.totalRecords, this.perPage, this.currentPage);
- this._updateEntries({data: this.data});
+ this._updateEntries(this.data);
+ }
+
+ _updateFilter(query) {
+ /* clearing the query */
+ if (query === null || query === '') {
+ this._updateEntries(this.unfilteredData);
+ return;
+ }
+
+ let data = [];
+ for (const datum of this.unfilteredData) {
+ if (this.filterCallback(datum, query)) {
+ data.push(datum);
+ }
+ }
+
+ this._updatePage(0)
+ this._updateEntries(data);
}
_updateSort(field, direction) {
diff --git a/theme/bulma/archive.php b/theme/bulma/archive.php
index 0fc2b53..2c90e98 100644
--- a/theme/bulma/archive.php
+++ b/theme/bulma/archive.php
@@ -1,27 +1,3 @@
-
-