From a463959a365a5d618a79c96a26f6506e700d6ea3 Mon Sep 17 00:00:00 2001
From: Henry Jameson <me@hjkos.com>
Date: Thu, 1 Oct 2020 01:43:07 +0300
Subject: Initial work on highlighting changed settings. Some refactoring to
 simplify addition of new settings

---
 .../settings_modal/helpers/boolean_setting.vue     | 57 ++++++++++++++++++++++
 1 file changed, 57 insertions(+)
 create mode 100644 src/components/settings_modal/helpers/boolean_setting.vue

(limited to 'src/components/settings_modal/helpers/boolean_setting.vue')

diff --git a/src/components/settings_modal/helpers/boolean_setting.vue b/src/components/settings_modal/helpers/boolean_setting.vue
new file mode 100644
index 00000000..11b354ed
--- /dev/null
+++ b/src/components/settings_modal/helpers/boolean_setting.vue
@@ -0,0 +1,57 @@
+<template>
+  <label
+    class="BooleanSetting"
+  >
+    <Checkbox
+      :checked="state"
+      @change="update"
+      :disabled="disabled"
+      >
+      <span
+        v-if="!!$slots.default"
+        class="label"
+        >
+        <slot />
+      </span>
+    </Checkbox>
+    <span v-if="isChanged">
+      <strong>CHANGED</strong>
+    </span>
+  </label>
+</template>
+
+<script>
+import { get, set } from 'lodash'
+import Checkbox from 'src/components/checkbox/checkbox.vue'
+export default {
+  props: [
+    'path',
+    'disabled'
+  ],
+  components: {
+    Checkbox
+  },
+  computed: {
+    pathDefault () {
+      const [firstSegment, ...rest] = this.path.split('.')
+      return [firstSegment + 'DefaultValue', ...rest].join('.')
+    },
+    state () {
+      return get(this.$parent, this.path)
+    },
+    isChanged () {
+      return get(this.$parent, this.path) !== get(this.$parent, this.pathDefault)
+    }
+  },
+  methods: {
+    update (e) {
+      set(this.$parent, this.path, e)
+    }
+  }
+}
+</script>
+
+<style lang="scss">
+.BooleanSetting {
+}
+</style>
-- 
cgit v1.2.3-70-g09d2

