Skip to content
Merged
1 change: 1 addition & 0 deletions core/lib/i18n/en.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,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.",
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This help text is unnecessary, if we simply hide the Add Proxy button.

"proxyBackendForm_advancedSettings_title": "Advanced settings",
"proxyBackendForm_apiBasePath_helpText": "Base path added to all API requests. Example:",
"proxyBackendForm_apiPort_helpText": "Port number on API server",
Expand Down
15 changes: 13 additions & 2 deletions proxies/client/proxies.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,22 @@
</div>
<div class="col-md-6">
<h2>
<button class="btn btn-default btn-sm pull-right" id="add-proxy">{{ _ "proxies_addProxy" }}</button>
{{ # unless isDisabled }}
<button class="btn btn-default btn-sm pull-right" id="add-proxy">
{{ _ "proxies_addProxy" }}
</button>
{{ else }}
<button
class="btn btn-default btn-sm pull-right"
title="{{ _ 'proxies_cannotAddMoreProxies' }}"
disabled="true">
{{ _ "proxies_addProxy" }}
</button>
{{ / unless }}
{{ _ "proxies_pageHeader" }}
</h2>
<hr>
<div class="">
<div>
{{ # if proxies.count }}
{{ # each proxy in proxies }}
{{ > proxyItem proxy=proxy }}
Expand Down
17 changes: 14 additions & 3 deletions proxies/client/proxies.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,41 @@ 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();
instance.isDisabled = new ReactiveVar();

instance.subscribe('allProxies');

instance.autorun(() => {
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);
}
});
});

Template.proxies.events({
'click #add-proxy': function (event, instance) {
Modal.show('addProxy', { proxy: {}, isEdit: false });
Copy link
Copy Markdown
Contributor

@brylie brylie Sep 21, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Be aware of changes to the addProxy form. Specifically, the template has been renamed proxyForm and used for both adding and editing proxies.

#1597

}
},
});

Template.proxies.helpers({
proxies () {
const instance = Template.instance();
return instance.proxies.get();
}
},
isDisabled () {
const instance = Template.instance();
return instance.isDisabled.get();
},
});
5 changes: 5 additions & 0 deletions proxies/collection/permissions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
},
Expand Down