From 1f4c2df3aed2b9091575b6910955145bbe0d4841 Mon Sep 17 00:00:00 2001 From: Samuel Elliott Date: Mon, 12 Feb 2018 19:01:07 +0000 Subject: [PATCH] Add functions to get a set, category and setting value --- client/src/modules/settings.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/client/src/modules/settings.js b/client/src/modules/settings.js index e00fefe8..77f87c6b 100644 --- a/client/src/modules/settings.js +++ b/client/src/modules/settings.js @@ -77,6 +77,27 @@ export default class { } } + static getSet(set_id) { + return this.getSettings.find(s => s.id === set_id); + } + + static getCategory(set_id, category_id) { + const set = this.getSet(set_id); + if (!set) return; + + return set.settings.find(c => c.category === category_id); + } + + static getSetting(set_id, category_id, setting_id) { + const category = this.getCategory(set_id, category_id); + if (!category) return; + + const setting = category.settings.find(s => s.id === setting_id); + if (!setting) return; + + return setting.value; + } + static setSetting(set_id, category_id, setting_id, value) { for (let set of this.getSettings) { if (set.id !== set_id) continue;