From 10c7ced0b7f54d9fb3b4fbf26504539146ceabe5 Mon Sep 17 00:00:00 2001 From: MattIPv4 Date: Tue, 28 Apr 2020 12:03:11 +0100 Subject: [PATCH] Delegate data around the app --- src/nginxconfig/templates/app.vue | 29 +++++---- src/nginxconfig/templates/domain.vue | 62 +++++++------------ .../templates/domain_sections/python.vue | 51 +++++++-------- .../util/computed_from_defaults.js | 14 +++++ .../util/delegated_from_defaults.js | 10 +++ 5 files changed, 89 insertions(+), 77 deletions(-) create mode 100644 src/nginxconfig/util/computed_from_defaults.js create mode 100644 src/nginxconfig/util/delegated_from_defaults.js diff --git a/src/nginxconfig/templates/app.vue b/src/nginxconfig/templates/app.vue index 8d7d77d..ce0c72f 100644 --- a/src/nginxconfig/templates/app.vue +++ b/src/nginxconfig/templates/app.vue @@ -29,15 +29,15 @@ limitations under the License.
- @@ -63,16 +63,21 @@ limitations under the License. data() { return { i18n, - domains: 1, - active: 1, + domains: [ + Domain.delegated, + ], + active: 0, }; }, methods: { - domainTitle(index) { - if (this.$refs.domains) { - const data = this.$refs.domains[index-1].export(); - return data.Server.domain; - } + changes(index) { + const data = this.$data.domains[index]; + const changes = Object.values(data).reduce((prev, current) => { + prev += Object.values(current).filter(d => d.default !== d.computed).length; + return prev; + }, 0); + if (changes) return ` (${changes.toLocaleString()})`; + return ''; }, }, }; diff --git a/src/nginxconfig/templates/domain.vue b/src/nginxconfig/templates/domain.vue index 420a3ff..6133608 100644 --- a/src/nginxconfig/templates/domain.vue +++ b/src/nginxconfig/templates/domain.vue @@ -18,62 +18,48 @@ limitations under the License.
- - Log export data to console
diff --git a/src/nginxconfig/templates/domain_sections/python.vue b/src/nginxconfig/templates/domain_sections/python.vue index d6e9575..fefcb27 100644 --- a/src/nginxconfig/templates/domain_sections/python.vue +++ b/src/nginxconfig/templates/domain_sections/python.vue @@ -1,46 +1,43 @@ diff --git a/src/nginxconfig/util/computed_from_defaults.js b/src/nginxconfig/util/computed_from_defaults.js new file mode 100644 index 0000000..3db4a33 --- /dev/null +++ b/src/nginxconfig/util/computed_from_defaults.js @@ -0,0 +1,14 @@ +export default (defaults) => { + return Object.keys(defaults).reduce((prev, key) => { + prev[key] = { + get() { + return this.$props.data[key].value; + }, + set (value) { + this.$props.data[key].value = value; + this.$props.data[key].computed = value; + }, + }; + return prev; + }, {}); +}; diff --git a/src/nginxconfig/util/delegated_from_defaults.js b/src/nginxconfig/util/delegated_from_defaults.js new file mode 100644 index 0000000..27c7a57 --- /dev/null +++ b/src/nginxconfig/util/delegated_from_defaults.js @@ -0,0 +1,10 @@ +export default (defaults) => { + return Object.keys(defaults).reduce((prev, key) => { + prev[key] = { + value: defaults[key].default, + computed: defaults[key].default, + ...defaults[key], + }; + return prev; + }, {}); +};