Skip to content

Commit

Permalink
Sort Settings by translated names (librenms#11280)
Browse files Browse the repository at this point in the history
If browser language is different from the language set in LibreNMS, it might sort slightly incorrectly.
  • Loading branch information
murrant authored Mar 12, 2020
1 parent 36e2dc4 commit 82eddfc
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 10 deletions.
9 changes: 4 additions & 5 deletions app/Http/Controllers/SettingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,16 @@ class SettingsController extends Controller
* @param DynamicConfig $dynamicConfig
* @param string $tab
* @param string $section
* @return \Illuminate\Http\Response
* @return \Illuminate\Http\Response|\Illuminate\View\View
*/
public function index(DynamicConfig $dynamicConfig, $tab = 'global', $section = '')
{
$data = [
'active_tab' => $tab,
'active_section' => $section,
'groups' => $dynamicConfig->getGroups()->reduce(function ($groups, $group) {
/** @var Collection $groups */
return $groups->put($group, []);
}, new Collection())->forget('global'),
'groups' => $dynamicConfig->getGroups()->reject(function ($group) {
return $group == 'global';
}),
];

return view('settings.index', $data);
Expand Down
2 changes: 1 addition & 1 deletion html/js/app.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion html/mix-manifest.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"/js/app.js": "/js/app.js?id=d074dd82ac08dba78c44",
"/js/app.js": "/js/app.js?id=1416a11a53d67bf51725",
"/css/app.css": "/css/app.css?id=2a88c6515df894dc6f36",
"/js/manifest.js": "/js/manifest.js?id=3c768977c2574a34506e",
"/js/vendor.js": "/js/vendor.js?id=58c8fc0774b5843ec004",
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
"development": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
"watch": "npm run development -- --watch",
"watch-poll": "npm run watch -- --watch-poll",
"watch-production": "npm run production -- --watch --progress",
"watch-prod": "npm run watch-production",
"hot": "cross-env NODE_ENV=development node_modules/webpack-dev-server/bin/webpack-dev-server.js --inline --hot --config=node_modules/laravel-mix/setup/webpack.config.js",
"prod": "npm run production",
"production": "cross-env NODE_ENV=production node_modules/webpack/bin/webpack.js --no-progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js"
Expand Down
14 changes: 11 additions & 3 deletions resources/js/components/LibrenmsSettings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,9 @@

return this.checkLogic(setting.when);
},
translatedCompare(prefix, a, b) {
return this.$t(prefix + a).localeCompare(this.$t(prefix + b))
},
checkLogic(logic) {
switch (logic.operator) {
case 'equals':
Expand All @@ -136,7 +139,12 @@
computed: {
groups() {
if (_.isEmpty(this.settings)) {
return this.tabs;
let sorted_tabs = {};
this.tabs.sort((a, b) => this.translatedCompare('settings.groups.', a, b)).forEach(function (tab) {
sorted_tabs[tab] = [];
});

return sorted_tabs;
}

// group data
Expand All @@ -163,9 +171,9 @@

// sort groups
let sorted = {};
Object.keys(groups).sort().forEach(group_key => {
Object.keys(groups).sort((a, b) => this.translatedCompare('settings.groups.', a, b)).forEach(group_key => {
sorted[group_key] = {};
Object.keys(groups[group_key]).sort().forEach(section_key => {
Object.keys(groups[group_key]).sort((a, b) => this.translatedCompare('settings.sections.', a , b)).forEach(section_key => {
sorted[group_key][section_key] = _.sortBy(groups[group_key][section_key], 'order').map(a => a.name);
});
});
Expand Down

0 comments on commit 82eddfc

Please sign in to comment.