From ba0499a1d36673234eca2838734eec3bd184fd84 Mon Sep 17 00:00:00 2001 From: Angelina Filippova Date: Fri, 15 Nov 2019 17:06:47 +0900 Subject: [PATCH] Render RateLimiters using data from API --- src/views/settings/components/Inputs.vue | 56 +++ .../settings/components/RateLimiters.vue | 364 +----------------- 2 files changed, 65 insertions(+), 355 deletions(-) diff --git a/src/views/settings/components/Inputs.vue b/src/views/settings/components/Inputs.vue index 4fe634eb..2f582cd7 100644 --- a/src/views/settings/components/Inputs.vue +++ b/src/views/settings/components/Inputs.vue @@ -99,6 +99,30 @@ @change="updateSetting($event, settingGroup.key, setting.key)"/> +
+
+ : + +
+ +

Set different limits for unauthenticated and authenticated users

+
+
+
+ + : + + + + : + + +
+ +

Set limit for all users

+
+
+

{{ setting.description }}

@@ -153,6 +177,19 @@ export default { return this.data[this.setting.key] === ':disabled' ? ':disabled' : Object.keys(this.data[this.setting.key])[0] + }, + rateLimitAllUsers() { + return this.data[this.setting.key] ? Object.entries(this.data[this.setting.key])[0] : [null, null] + }, + rateLimitAuthUsers() { + return Array.isArray(this.data[this.setting.key]) + ? Object.entries(this.data[this.setting.key][1])[0] + : false + }, + rateLimitUnauthUsers() { + return Array.isArray(this.data[this.setting.key]) + ? Object.entries(this.data[this.setting.key][0])[0] + : false } }, methods: { @@ -194,6 +231,22 @@ export default { console.log(updatedValue) this.updateSetting(updatedValue, this.settingGroup.key, this.setting.key) }, + parseRateLimiter(value, input, typeOfInput, typeOfLimit, currentValue) { + if (typeOfLimit === 'oneLimit') { + const valueToSend = typeOfInput === 'scale' ? { 'tuple': [value, currentValue[1]] } : { 'tuple': [currentValue[0], value] } + this.updateSetting(valueToSend, 'rate_limit', input) + } else if (typeOfLimit === 'authUserslimit') { + const valueToSend = typeOfInput === 'scale' + ? [{ 'tuple': [currentValue[0][0], currentValue[0][1]] }, { 'tuple': [value, currentValue[1][1]] }] + : [{ 'tuple': [currentValue[0][0], currentValue[0][1]] }, { 'tuple': [currentValue[1][0], value] }] + this.updateSetting(valueToSend, 'rate_limit', input) + } else if (typeOfLimit === 'unauthUsersLimit') { + const valueToSend = typeOfInput === 'scale' + ? [{ 'tuple': [value, currentValue[0][1]] }, { 'tuple': [currentValue[1][0], currentValue[1][1]] }] + : [{ 'tuple': [currentValue[0][0], value] }, { 'tuple': [currentValue[1][0], currentValue[1][1]] }] + this.updateSetting(valueToSend, 'rate_limit', input) + } + }, processNestedData(value, tab, inputName, childName) { const updatedValue = { ...this.$store.state.settings.settings[tab][inputName], ...{ [childName]: value }} this.updateSetting(updatedValue, tab, inputName) @@ -209,6 +262,9 @@ export default { toggleAtomTuple(value, tab, input) { console.log(value) }, + toggleLimits(value, input) { + this.updateSetting(value, 'rate_limit', input) + }, updateSetting(value, tab, input) { this.$store.dispatch('UpdateSettings', { tab, data: { [input]: value }}) } diff --git a/src/views/settings/components/RateLimiters.vue b/src/views/settings/components/RateLimiters.vue index f0381846..5c079b83 100644 --- a/src/views/settings/components/RateLimiters.vue +++ b/src/views/settings/components/RateLimiters.vue @@ -1,221 +1,6 @@