From e71765f10a20f63712cf1c679df3808a7db49a95 Mon Sep 17 00:00:00 2001 From: Damir Mustafin Date: Tue, 20 Sep 2016 02:56:46 +0300 Subject: [PATCH 01/12] Disable "add proxy button" --- proxies/client/proxies.html | 10 +++++++++- proxies/client/proxies.js | 5 ++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/proxies/client/proxies.html b/proxies/client/proxies.html index beb082f0c0..07d0f61f9c 100644 --- a/proxies/client/proxies.html +++ b/proxies/client/proxies.html @@ -6,7 +6,15 @@

- + {{ # if biggerThan proxies.count 1 }} + + {{ else }} + + {{ / if }} {{ _ "proxies_pageHeader" }}


diff --git a/proxies/client/proxies.js b/proxies/client/proxies.js index 4dca5b459c..d96b87a9ed 100644 --- a/proxies/client/proxies.js +++ b/proxies/client/proxies.js @@ -27,5 +27,8 @@ Template.proxies.helpers({ proxies () { const instance = Template.instance(); return instance.proxies.get(); - } + }, + biggerThan (a, b) { + return (a > b); + }, }); From 3424314a357069cdd477a3bc89636bd93627ce72 Mon Sep 17 00:00:00 2001 From: Damir Mustafin Date: Tue, 20 Sep 2016 03:19:16 +0300 Subject: [PATCH 02/12] Fix --- proxies/client/proxies.html | 4 ++-- proxies/client/proxies.js | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/proxies/client/proxies.html b/proxies/client/proxies.html index 07d0f61f9c..409d33de83 100644 --- a/proxies/client/proxies.html +++ b/proxies/client/proxies.html @@ -6,7 +6,7 @@

- {{ # if biggerThan proxies.count 1 }} + {{ # unless biggerThan proxies.count 1 }} @@ -14,7 +14,7 @@

- {{ / if }} + {{ / unless }} {{ _ "proxies_pageHeader" }}


diff --git a/proxies/client/proxies.js b/proxies/client/proxies.js index d96b87a9ed..01c7370e20 100644 --- a/proxies/client/proxies.js +++ b/proxies/client/proxies.js @@ -29,6 +29,6 @@ Template.proxies.helpers({ return instance.proxies.get(); }, biggerThan (a, b) { - return (a > b); + return (a >= b); }, }); From 24cd709d558f1ab3ea9f6b8b543518f816152ad8 Mon Sep 17 00:00:00 2001 From: Damir Mustafin Date: Tue, 20 Sep 2016 03:20:35 +0300 Subject: [PATCH 03/12] Insert rule --- proxies/collection/permissions.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/proxies/collection/permissions.js b/proxies/collection/permissions.js index 84276d0e59..0f1c26c3d1 100644 --- a/proxies/collection/permissions.js +++ b/proxies/collection/permissions.js @@ -2,6 +2,11 @@ import { Proxies } from './'; Proxies.allow({ insert (userId, proxy) { + // Check if proxy is already exist + if (Proxies.find().count() >= 1) { + return false; + } + // Check if user has admin role return Roles.userIsInRole(userId, ['admin']); }, From 52a40027a03ca4917d5db35c38af1309a2b91476 Mon Sep 17 00:00:00 2001 From: Damir Mustafin Date: Tue, 20 Sep 2016 21:21:16 +0300 Subject: [PATCH 04/12] lint --- proxies/client/proxies.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/proxies/client/proxies.js b/proxies/client/proxies.js index 01c7370e20..9c37f5919f 100644 --- a/proxies/client/proxies.js +++ b/proxies/client/proxies.js @@ -2,7 +2,7 @@ import { Proxies } from '../collection'; import { Template } from 'meteor/templating'; import { ReactiveVar } from 'meteor/reactive-var'; -Template.proxies.onCreated(function(){ +Template.proxies.onCreated(function () { const instance = this; instance.proxies = new ReactiveVar(); @@ -20,7 +20,7 @@ Template.proxies.onCreated(function(){ Template.proxies.events({ 'click #add-proxy': function (event, instance) { Modal.show('addProxy', { proxy: {}, isEdit: false }); - } + }, }); Template.proxies.helpers({ From 894581386d1d679e407a9b0edfc4887a1f012a67 Mon Sep 17 00:00:00 2001 From: Damir Mustafin Date: Tue, 20 Sep 2016 21:41:54 +0300 Subject: [PATCH 05/12] i18n label --- core/lib/i18n/en.i18n.json | 1 + 1 file changed, 1 insertion(+) diff --git a/core/lib/i18n/en.i18n.json b/core/lib/i18n/en.i18n.json index 406cae9712..1085073f48 100644 --- a/core/lib/i18n/en.i18n.json +++ b/core/lib/i18n/en.i18n.json @@ -268,6 +268,7 @@ "proxies_pageHeader": "Proxies", "proxies_addProxy": "Add proxy", "proxies_noProxiesFound": "No proxies found.", + "proxies_cannotAddMoreProxies": "You already have a Proxy available to attach your API. Please select the Proxy. You can add a new Proxy only after your have deleted the existing one.", "proxyBackendForm_apiBasePath_helpText": "Base path added to all API requests. Example:", "proxyBackendForm_apiPort_helpText": "Port number on API server", "proxyBackendForm_proxyBasePath_helpText": "Base path added to all Proxy requests. Example:", From 6914c4ab86036158256cea3e215b174828cc2751 Mon Sep 17 00:00:00 2001 From: Damir Mustafin Date: Tue, 20 Sep 2016 21:42:18 +0300 Subject: [PATCH 06/12] Add title attr to button --- proxies/client/proxies.html | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/proxies/client/proxies.html b/proxies/client/proxies.html index 409d33de83..410044aaac 100644 --- a/proxies/client/proxies.html +++ b/proxies/client/proxies.html @@ -11,7 +11,10 @@

{{ _ "proxies_addProxy" }} {{ else }} - {{ / unless }} From 16dbd717b5a5edd79dd1ea98a7c048c2e25ee34d Mon Sep 17 00:00:00 2001 From: Damir Mustafin Date: Tue, 20 Sep 2016 23:52:52 +0300 Subject: [PATCH 07/12] info tooltip --- proxies/client/proxies.html | 11 +++++------ proxies/client/proxies.js | 4 ++++ proxies/client/proxies.less | 3 +++ 3 files changed, 12 insertions(+), 6 deletions(-) create mode 100644 proxies/client/proxies.less diff --git a/proxies/client/proxies.html b/proxies/client/proxies.html index 410044aaac..504cacd0da 100644 --- a/proxies/client/proxies.html +++ b/proxies/client/proxies.html @@ -11,12 +11,11 @@

{{ _ "proxies_addProxy" }} {{ else }} - + + + {{ / unless }} {{ _ "proxies_pageHeader" }}

diff --git a/proxies/client/proxies.js b/proxies/client/proxies.js index 9c37f5919f..cc396fc8b7 100644 --- a/proxies/client/proxies.js +++ b/proxies/client/proxies.js @@ -17,6 +17,10 @@ Template.proxies.onCreated(function () { }); }); +Template.proxies.onRendered(function(){ + $('[data-toggle="tooltip"]').tooltip(); +}); + Template.proxies.events({ 'click #add-proxy': function (event, instance) { Modal.show('addProxy', { proxy: {}, isEdit: false }); diff --git a/proxies/client/proxies.less b/proxies/client/proxies.less new file mode 100644 index 0000000000..415b08104c --- /dev/null +++ b/proxies/client/proxies.less @@ -0,0 +1,3 @@ +span.helper { + display: inline-block; +} From 4174bc96d50db22dc784c65f1c7ad4d2535d6f1e Mon Sep 17 00:00:00 2001 From: Damir Mustafin Date: Wed, 21 Sep 2016 01:57:45 +0300 Subject: [PATCH 08/12] Revert "info tooltip" This reverts commit 16dbd717b5a5edd79dd1ea98a7c048c2e25ee34d. --- proxies/client/proxies.html | 11 ++++++----- proxies/client/proxies.js | 4 ---- proxies/client/proxies.less | 3 --- 3 files changed, 6 insertions(+), 12 deletions(-) delete mode 100644 proxies/client/proxies.less diff --git a/proxies/client/proxies.html b/proxies/client/proxies.html index 504cacd0da..410044aaac 100644 --- a/proxies/client/proxies.html +++ b/proxies/client/proxies.html @@ -11,11 +11,12 @@

{{ _ "proxies_addProxy" }} {{ else }} - - - + {{ / unless }} {{ _ "proxies_pageHeader" }}

diff --git a/proxies/client/proxies.js b/proxies/client/proxies.js index cc396fc8b7..9c37f5919f 100644 --- a/proxies/client/proxies.js +++ b/proxies/client/proxies.js @@ -17,10 +17,6 @@ Template.proxies.onCreated(function () { }); }); -Template.proxies.onRendered(function(){ - $('[data-toggle="tooltip"]').tooltip(); -}); - Template.proxies.events({ 'click #add-proxy': function (event, instance) { Modal.show('addProxy', { proxy: {}, isEdit: false }); diff --git a/proxies/client/proxies.less b/proxies/client/proxies.less deleted file mode 100644 index 415b08104c..0000000000 --- a/proxies/client/proxies.less +++ /dev/null @@ -1,3 +0,0 @@ -span.helper { - display: inline-block; -} From 22149056f9cd76954fd26a6695244c97e677ba20 Mon Sep 17 00:00:00 2001 From: ilya Date: Wed, 21 Sep 2016 12:43:23 +0300 Subject: [PATCH 09/12] cleaned up --- proxies/client/proxies.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/proxies/client/proxies.html b/proxies/client/proxies.html index 410044aaac..a2f3638064 100644 --- a/proxies/client/proxies.html +++ b/proxies/client/proxies.html @@ -21,7 +21,7 @@

{{ _ "proxies_pageHeader" }}


-
+
{{ # if proxies.count }} {{ # each proxy in proxies }} {{ > proxyItem proxy=proxy }} From b21977e2b5c7323bf9cdf7d86599653aac2466b2 Mon Sep 17 00:00:00 2001 From: Damir Mustafin Date: Wed, 21 Sep 2016 13:08:08 +0300 Subject: [PATCH 10/12] Simplify code --- proxies/client/proxies.html | 2 +- proxies/client/proxies.js | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/proxies/client/proxies.html b/proxies/client/proxies.html index a2f3638064..5231fdd376 100644 --- a/proxies/client/proxies.html +++ b/proxies/client/proxies.html @@ -6,7 +6,7 @@

- {{ # unless biggerThan proxies.count 1 }} + {{ # unless isDisabled }} diff --git a/proxies/client/proxies.js b/proxies/client/proxies.js index 9c37f5919f..e4cea1f655 100644 --- a/proxies/client/proxies.js +++ b/proxies/client/proxies.js @@ -6,6 +6,7 @@ Template.proxies.onCreated(function () { const instance = this; instance.proxies = new ReactiveVar(); + instance.isDisabled = new ReactiveVar(); instance.subscribe('allProxies'); @@ -13,6 +14,8 @@ Template.proxies.onCreated(function () { if (instance.subscriptionsReady()) { // Update reactive vatiable with proxies cursor when subscription is ready instance.proxies.set(Proxies.find()); + const proxiesCount = Proxies.find().count(); + instance.isDisabled.set(proxiesCount >= 1); } }); }); @@ -28,7 +31,8 @@ Template.proxies.helpers({ const instance = Template.instance(); return instance.proxies.get(); }, - biggerThan (a, b) { - return (a >= b); + isDisabled () { + const instance = Template.instance(); + return instance.isDisabled.get(); }, }); From 759f8b49ca70589588e14e191b9c8e1c1ce1012c Mon Sep 17 00:00:00 2001 From: Damir Mustafin Date: Wed, 21 Sep 2016 13:09:05 +0300 Subject: [PATCH 11/12] Comments --- proxies/client/proxies.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/proxies/client/proxies.js b/proxies/client/proxies.js index e4cea1f655..54f5026e7b 100644 --- a/proxies/client/proxies.js +++ b/proxies/client/proxies.js @@ -14,7 +14,11 @@ Template.proxies.onCreated(function () { if (instance.subscriptionsReady()) { // Update reactive vatiable with proxies cursor when subscription is ready instance.proxies.set(Proxies.find()); + + // Get proxies count const proxiesCount = Proxies.find().count(); + + // Set button disabled if at least one proxy is already added instance.isDisabled.set(proxiesCount >= 1); } }); From 88bad47acc37e55107141d2b75252e20e62b80f7 Mon Sep 17 00:00:00 2001 From: Damir Mustafin Date: Wed, 21 Sep 2016 14:01:16 +0300 Subject: [PATCH 12/12] Cleanup --- core/lib/i18n/en.i18n.json | 1 - 1 file changed, 1 deletion(-) diff --git a/core/lib/i18n/en.i18n.json b/core/lib/i18n/en.i18n.json index 5221e581ac..e1c1e4bef5 100644 --- a/core/lib/i18n/en.i18n.json +++ b/core/lib/i18n/en.i18n.json @@ -276,7 +276,6 @@ "proxies_pageHeader": "Proxies", "proxies_addProxy": "Add proxy", "proxies_noProxiesFound": "No proxies found.", - "proxies_cannotAddMoreProxies": "You already have a Proxy available to attach your API. Please select the Proxy. You can add a new Proxy only after your have deleted the existing one.", "proxyBackendForm_advancedSettings_title": "Advanced settings", "proxyBackendForm_apiBasePath_helpText": "Base path added to all API requests. Example:", "proxyBackendForm_apiPort_helpText": "Port number on API server",