ACP search and title improvements

- Search uses translated titles if available
- Use `advanced` for `development` route titles
- Remove route title from showing up in results
- Highlight matching part of result title
- Don't show empty result contents when only title is matched
v1.18.x
Peter Jaszkowiak 8 years ago committed by Julian Lam
parent 3008794797
commit 862908d0eb

@ -58,6 +58,7 @@
"advanced/errors": "Errors",
"advanced/cache": "Cache",
"development/logger": "Logger",
"development/info": "Info",
"reload-forum": "Reload Forum",
"restart-forum": "Restart Forum",

@ -116,13 +116,14 @@
});
});
var title;
if (/admin\/general\/dashboard$/.test(url)) {
var title = url;
if (/admin\/general\/dashboard$/.test(title)) {
title = '[[admin/menu:general/dashboard]]';
} else {
title = url.match(/admin\/(.+?)\/(.+?)$/);
title = '[[admin/menu:section-' + title[1] + ']]' +
(title[2] ? (' > [[admin/menu:' +
title = title.match(/admin\/(.+?)\/(.+?)$/);
title = '[[admin/menu:section-' +
(title[1] === 'development' ? 'advanced' : title[1]) +
']]' + (title[2] ? (' > [[admin/menu:' +
title[1] + '/' + title[2] + ']]') : '');
}

@ -4,39 +4,41 @@
define('admin/modules/search', ['mousetrap'], function (mousetrap) {
var search = {};
function nsToTitle(namespace) {
return namespace.replace('admin/', '').split('/').map(function (str) {
return str[0].toUpperCase() + str.slice(1);
}).join(' > ');
}
function find(dict, term) {
var html = dict.filter(function (elem) {
return elem.translations.toLowerCase().includes(term);
}).map(function (params) {
var namespace = params.namespace;
var translations = params.translations;
var title = params.title == null ? nsToTitle(namespace) : params.title;
var title = params.title;
var results = translations
// remove all lines without a match
.replace(new RegExp('^(?:(?!' + term + ').)*$', 'gmi'), '')
// get up to 25 characaters of context on both sides of the match
// remove lines that only match the title
.replace(new RegExp('(^|\\n).*?' + title + '.*?(\\n|$)', 'g'), '')
// get up to 25 characters of context on both sides of the match
// and wrap the match in a `.search-match` element
.replace(
new RegExp('^[\\s\\S]*?(.{0,25})(' + term + ')(.{0,25})[\\s\\S]*?$', 'gmi'),
'...$1<span class="search-match">$2</span>$3...<br>'
)
// collapse whitespace
.replace(/(?:\n ?)+/g, '\n');
.replace(/(?:\n ?)+/g, '\n')
.trim();
title = title.replace(
new RegExp('(^.*?)(' + term + ')(.*?$)', 'gi'),
'$1<span class="search-match">$2</span>$3'
);
return '<li role="presentation" class="result">' +
'<a role= "menuitem" href= "' + config.relative_path + '/' + namespace + '" >' +
title +
'<br>' +
'<small><code>' +
'<br>' + (!results ? '' :
('<small><code>' +
results +
'</small></code>' +
'</small></code>')) +
'</a>' +
'</li>';
}).join('');

@ -54,7 +54,7 @@ function simplify(translations) {
function nsToTitle(namespace) {
return namespace.replace('admin/', '').split('/').map(function (str) {
return str[0].toUpperCase() + str.slice(1);
}).join(' > ');
}).join(' > ').replace(/[^a-zA-Z> ]/g, ' ');
}
var fallbackCacheInProgress = {};
@ -67,15 +67,17 @@ function initFallback(namespace, callback) {
}
var template = file.toString();
var title = nsToTitle(namespace);
var translations = sanitize(template);
translations = Translator.removePatterns(translations);
translations = simplify(translations);
translations += '\n' + nsToTitle(namespace);
translations += '\n' + title;
callback(null, {
namespace: namespace,
translations: translations,
title: title,
});
});
}
@ -124,17 +126,32 @@ function initDict(language, callback) {
var str = Object.keys(translations).map(function (key) {
return translations[key];
}).join('\n');
str = sanitize(str);
var title = namespace;
if (/admin\/general\/dashboard$/.test(title)) {
title = '[[admin/menu:general/dashboard]]';
} else {
title = title.match(/admin\/(.+?)\/(.+?)$/);
title = '[[admin/menu:section-' +
(title[1] === 'development' ? 'advanced' : title[1]) +
']]' + (title[2] ? (' > [[admin/menu:' +
title[1] + '/' + title[2] + ']]') : '');
}
next(null, {
namespace: namespace,
translations: str,
});
}
Translator.create(language).translate(title).then(function (title) {
next(null, {
namespace: namespace,
translations: str + '\n' + title,
title: title,
});
}).catch(err);
},
], function (err, params) {
if (err) {
return fallback(namespace, function (err, params) {
if (err) {
return cb({
return cb(null, {
namespace: namespace,
translations: '',
});

Loading…
Cancel
Save