Fix settings search (#10777)
restore dynamic menu building... data manipulation in js is yuck
This commit is contained in:
parent
dfb4317d38
commit
55750cebb4
|
@ -5,7 +5,9 @@ namespace App\Http\Controllers;
|
|||
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Collection;
|
||||
use LibreNMS\Util\DynamicConfig;
|
||||
use LibreNMS\Util\DynamicConfigItem;
|
||||
|
||||
class SettingsController extends Controller
|
||||
{
|
||||
|
@ -22,7 +24,10 @@ class SettingsController extends Controller
|
|||
$data = [
|
||||
'active_tab' => $tab,
|
||||
'active_section' => $section,
|
||||
'groups' => $dynamicConfig->getGrouped()->forget('global'),
|
||||
'groups' => $dynamicConfig->getGroups()->reduce(function ($groups, $group) {
|
||||
/** @var Collection $groups */
|
||||
return $groups->put($group, []);
|
||||
}, new Collection())->forget('global'),
|
||||
];
|
||||
|
||||
return view('settings.index', $data);
|
||||
|
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -1,5 +1,5 @@
|
|||
{
|
||||
"/js/app.js": "/js/app.js?id=5c0876339a6786677dfe",
|
||||
"/js/app.js": "/js/app.js?id=d466ed778e5c8dc360d8",
|
||||
"/css/app.css": "/css/app.css?id=17e56994706c74ee9663",
|
||||
"/js/manifest.js": "/js/manifest.js?id=3c768977c2574a34506e",
|
||||
"/js/vendor.js": "/js/vendor.js?id=dc98201378abb0b1bb08"
|
||||
|
|
|
@ -61,7 +61,7 @@
|
|||
prefix: String,
|
||||
initialTab: {type: String, default: 'alerting'},
|
||||
initialSection: String,
|
||||
groups: {type: Object}
|
||||
tabs: {type: Object}
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
|
@ -100,9 +100,6 @@
|
|||
handleBack(event) {
|
||||
[this.tab, this.section] = event.state.split('/');
|
||||
},
|
||||
loadData(response) {
|
||||
this.settings = response.data;
|
||||
},
|
||||
updateSetting(name, value) {
|
||||
this.$set(this.settings[name], 'value', value)
|
||||
},
|
||||
|
@ -126,6 +123,46 @@
|
|||
mounted() {
|
||||
window.onpopstate = this.handleBack; // handle back button
|
||||
axios.get(route('settings.list')).then((response) => this.settings = response.data)
|
||||
},
|
||||
computed: {
|
||||
groups() {
|
||||
if (_.isEmpty(this.settings)) {
|
||||
return this.tabs;
|
||||
}
|
||||
|
||||
// group data
|
||||
let groups = {};
|
||||
for (const key of Object.keys(this.settings)) {
|
||||
let setting = this.settings[key];
|
||||
// filter
|
||||
if (!setting.name.includes(this.search_phrase)) {
|
||||
continue
|
||||
}
|
||||
if (setting.group) {
|
||||
if (!(setting.group in groups)) {
|
||||
groups[setting.group] = {};
|
||||
}
|
||||
if (setting.section) {
|
||||
if (!(setting.section in groups[setting.group])) {
|
||||
groups[setting.group][setting.section] = [];
|
||||
}
|
||||
|
||||
groups[setting.group][setting.section].push(setting);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// sort groups
|
||||
let sorted = {};
|
||||
for (const group_key of Object.keys(groups).sort()) {
|
||||
sorted[group_key] = {};
|
||||
for (const section_key of Object.keys(groups[group_key]).sort()) {
|
||||
sorted[group_key][section_key] = _.sortBy(groups[group_key][section_key], 'order').map(a => a.name);
|
||||
}
|
||||
}
|
||||
|
||||
return sorted;
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
prefix="{{ url('settings') }}"
|
||||
initial-tab="{{ $active_tab }}"
|
||||
initial-section="{{ $active_section }}"
|
||||
:groups="{{ $groups }}"
|
||||
:tabs="{{ $groups }}"
|
||||
></librenms-settings>
|
||||
</div>
|
||||
</div>
|
||||
|
|
Loading…
Reference in New Issue