Skip to content

Commit f5e032e

Browse files
committed
- Added disabledMessage and disabledTitle property to services.js
- Alerts are cleared before every new selection - disabledMessage triggers alert and TryIt disabled state - A few bugfixes, including issue running grunt after running grunt build-prod
1 parent 30be272 commit f5e032e

19 files changed

+135
-54
lines changed

Gruntfile.js

+8-3
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ module.exports = function (grunt) {
2929
'<%- path.dist %>',
3030
'<%- path.temp %>',
3131
'<%- path.bower %>'
32+
],
33+
34+
dist: [
35+
'<%- path.dist %>'
3236
]
3337
},
3438

@@ -113,8 +117,8 @@ module.exports = function (grunt) {
113117
'cd <%- path.app %>',
114118
'rsync . $cwd/<%- path.dist %> ' +
115119
'--update --delete --verbose --recursive ' +
116-
'--exclude ./less --exclude ./style'
117-
].join('&&')
120+
'--exclude less --exclude style'
121+
].join('&&')
118122
},
119123

120124
sourcemap_links: {
@@ -209,6 +213,7 @@ module.exports = function (grunt) {
209213
});
210214

211215
grunt.registerTask('build-dev', [
216+
'clean:dist',
212217
'bower',
213218
'shell:sync_dev',
214219
'less',
@@ -217,7 +222,7 @@ module.exports = function (grunt) {
217222

218223
grunt.registerTask('build-prod', [
219224
'set-prod',
220-
'clean',
225+
'clean:all',
221226
'bower',
222227
'copy',
223228
'less',

app/app-js/app-start.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ define(function (require) {
77
var Marionette = require('marionette'),
88
app = require('app'),
99

10-
api = require('entities/api/api.module'),
11-
service = require('entities/service/service.module'),
12-
alert = require('entities/alert/alert.module'),
10+
apiEntity = require('entities/api/api.module'),
11+
serviceEntity = require('entities/service/service.module'),
12+
alertEntity = require('entities/alert/alert.module'),
1313

1414
header = require('modules/header/header.module'),
1515
menu = require('modules/menu/menu.module'),
@@ -26,9 +26,9 @@ define(function (require) {
2626
};
2727

2828
// start entity modules
29-
api.start();
30-
service.start();
31-
alert.start();
29+
apiEntity.start();
30+
serviceEntity.start();
31+
alertEntity.start();
3232

3333
// start rendering modules
3434
header.start();

app/app-js/entities/alert/alert.controller.js

+6-3
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,14 @@ define(function (require) {
5050
},
5151

5252
removeAlert: function (alert) {
53-
this.alerts.remove(alert);
54-
this.alertRegistry[alert.hash()] = false;
53+
var alert = this.alertRegistry[alert.hash()];
54+
if (alert) {
55+
this.alerts.remove(alert);
56+
delete this.alertRegistry[alert.hash()];
57+
}
5558
},
5659

57-
clearAlerts: function (alert) {
60+
clearAlerts: function () {
5861
this.alertRegistry = {};
5962
this.alerts.reset();
6063
},

app/app-js/entities/alert/alert.model.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ define(function (require) {
77
defaults: {
88
title: 'Alert Title',
99
message: 'Alert message',
10-
state: 'danger' // {danger|warn|info|success}
10+
state: 'danger', // {danger|warn|info|success}
11+
uniqueGroup: null,
12+
uniqueValue: null
1113
},
1214

1315
hash: function () {

app/app-js/entities/api/call/genericOutput.model.js

+5
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,13 @@ define(function (require) {
1313
},
1414

1515
fetch: function (options) {
16+
var self = this;
17+
1618
options = options || {};
1719
options.url = this.urlRoot + '/' + this.get('serviceKey') + '/' + this.get('endpointKey');
20+
options.error = function () {
21+
self.set('output', null);
22+
};
1823

1924
return GenericOutputModel.__super__.fetch.call(this, options);
2025
},

app/app-js/entities/api/call/genericUri.model.js

+5
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,13 @@ define(function (require) {
1313
},
1414

1515
fetch: function (options) {
16+
var self = this;
17+
1618
options = options || {};
1719
options.url = this.urlRoot + '/' + this.get('serviceKey') + '/' + this.get('endpointKey');
20+
options.error = function () {
21+
self.set('uri', null);
22+
};
1823

1924
return GenericUriModel.__super__.fetch.call(this, options);
2025
}

app/app-js/entities/api/call/sampleUri.model.js

+6-15
Original file line numberDiff line numberDiff line change
@@ -14,23 +14,14 @@ define(function (require) {
1414
},
1515

1616
fetch: function (options) {
17-
var serviceName = appChannel.reqres.request('lookup:serviceName', this.get('serviceKey'));
17+
var self = this;
18+
serviceName = appChannel.reqres.request('lookup:serviceName', this.get('serviceKey'));
1819

1920
options = options || {};
20-
21-
_.extend(options, {
22-
url: this.urlRoot + '/' + this.get('serviceKey') + '/' + this.get('endpointKey'),
23-
24-
error: function () {
25-
var alert = {
26-
title: 'You haven\'t authenticated with the ' + serviceName + ' API.',
27-
message: 'Connect with a data source on the left to begin',
28-
state: 'danger'
29-
};
30-
31-
appChannel.commands.execute('add:alert', alert);
32-
}
33-
});
21+
options.url = this.urlRoot + '/' + this.get('serviceKey') + '/' + this.get('endpointKey');
22+
options.error = function () {
23+
self.set('uri', null);
24+
};
3425

3526
return SampleUriModel.__super__.fetch.call(this, options);
3627
}

app/app-js/entities/api/call/tryUri.model.js

+11
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,17 @@ define(function (require) {
1010
output: null
1111
},
1212

13+
fetch: function (options) {
14+
var self = this;
15+
16+
options = options || {};
17+
options.error = function () {
18+
self.set('output', null);
19+
};
20+
21+
TryUriModel.__super__.fetch.apply(this, arguments);
22+
},
23+
1324
parse: function (response) {
1425
return {
1526
output: JSON.stringify(response, null, 2)

app/app-js/entities/service/endpoint/endpoint.model.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ define(function (require) {
66

77
defaults: {
88
endpointName: null,
9-
endpointKey: null
9+
endpointKey: null,
10+
disabledMessage: null
1011
}
1112
});
1213

app/app-js/entities/service/service.controller.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ define(function (require) {
1313
reqres: {
1414
'get:serviceCollection': 'getServiceCollection',
1515
'lookup:serviceName': 'lookupServiceName',
16-
'lookup:endpointName': 'lookupEndpointName'
16+
'lookup:endpointName': 'lookupEndpointName',
17+
'is:endpointDisabled': 'isEndpointDisabled'
1718
},
1819

1920
commands: {
@@ -56,6 +57,10 @@ define(function (require) {
5657

5758
lookupEndpointName: function (serviceKey, endpointKey) {
5859
return services.lookupEndpointName(serviceKey, endpointKey);
60+
},
61+
62+
isEndpointDisabled: function (serviceKey, endpointKey) {
63+
return services.isEndpointDisabled(serviceKey, endpointKey);
5964
}
6065
});
6166

app/app-js/entities/service/services.js

+16-2
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,18 @@ define(function (require) {
99
'endpointKey': 'userprofile'
1010
}, {
1111
'endpointName': 'User\'s friends list',
12-
'endpointKey': 'ownerfriends'
12+
'endpointKey': 'ownerfriends',
13+
'disabledTitle': 'Our Apologies!',
14+
'disabledMessage':
15+
'Live demonstration of some Facebook features is currently disabled, ' +
16+
'pending approval from Facebook.'
1317
}, {
1418
'endpointName': 'User\'s news feed',
15-
'endpointKey': 'ownernews'
19+
'endpointKey': 'ownernews',
20+
'disabledTitle': 'Our Apologies!',
21+
'disabledMessage':
22+
'Live demonstration of some Facebook features is currently disabled, ' +
23+
'pending approval from Facebook.'
1624
}, {
1725
'endpointName': 'User\'s status feed',
1826
'endpointKey': 'ownerstatus'
@@ -133,6 +141,12 @@ define(function (require) {
133141
return endpoint.length && endpoint[0].endpointName;
134142
};
135143

144+
services.isEndpointDisabled = function (serviceKey, endpointKey) {
145+
var service = _.where(this, { serviceKey: serviceKey }),
146+
endpoint = service.length && _.where(service[0].endpoints, { endpointKey: endpointKey });
147+
return endpoint.length && endpoint[0].disabledMessage;
148+
};
149+
136150
services.clone = function () {
137151
var _services = _.clone(this);
138152

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
2-
{{#title}}<p><strong>{{title}}</strong>&nbsp;{{message}}</p>{{/title}}
2+
{{#title}}<p><strong>{{title}}&nbsp;</strong>{{/title}}{{message}}</p>

app/app-js/modules/alert/alert.view.js

+5-10
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ define(function (require) {
66

77
AlertView = Marionette.ItemView.extend({
88
template: template,
9-
className: 'alert alert-danger fade',
9+
className: 'alert fade',
1010

1111
events: {
1212
'click .close': 'closeClicked'
@@ -16,21 +16,16 @@ define(function (require) {
1616
moduleChannel.vent.trigger('close:alert', this.model);
1717
},
1818

19+
onRender: function () {
20+
this.$el.addClass('alert-' + this.model.get('state'));
21+
},
22+
1923
onShow: function () {
2024
var self = this;
2125

2226
_.delay(function () {
2327
self.$el.addClass('in');
2428
}, 100);
25-
},
26-
27-
remove: function () {
28-
var self = this,
29-
args = arguments;
30-
31-
_.delay(function () {
32-
AlertView.__super__.remove.apply(self, args);
33-
}, 500);
3429
}
3530
});
3631

app/app-js/modules/menu/menu.controller.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ define(function (require) {
2424
},
2525

2626
showMenu: function (serviceKey, endpointKey) {
27+
// Clear all alerts before each selection
28+
appChannel.commands.execute('clear:alerts');
29+
2730
if (!this.menuView || this.menuView.isClosed) {
2831
this.menuView = new MenuView({
2932
collection: this.services
@@ -37,7 +40,7 @@ define(function (require) {
3740
}
3841

3942
if (endpointKey) {
40-
moduleChannel.vent.trigger('select:endpoint', serviceKey, endpointKey);
43+
moduleChannel.vent.trigger('select:endpoint', serviceKey, endpointKey);
4144
}
4245
}
4346
});

app/app-js/modules/menu/menuItem/menuItem.view.js

+14
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
define(function (require) {
22
var Marionette = require('marionette'),
33
template = require('hgn!modules/menu/menuItem/menuItem.view'),
4+
appChannel = require('app.channel'),
45
MenuItemView;
56

67
MenuItemView = Marionette.ItemView.extend({
@@ -23,7 +24,20 @@ define(function (require) {
2324
},
2425

2526
onSelect: function () {
27+
var disabledMessage;
2628
this.ui.link.addClass('types-selected');
29+
30+
if (disabledMessage = this.model.get('disabledMessage')) {
31+
var alert = {
32+
title: this.model.get('disabledTitle'),
33+
message: disabledMessage,
34+
state: 'info',
35+
uniqueGroup: 'endpoint',
36+
uniqueValue: this.model.get('endpointKey')
37+
};
38+
39+
appChannel.commands.execute('add:alert', alert);
40+
}
2741
}
2842
});
2943

app/app-js/modules/tryUri/tryUri.controller.js

+5
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ define(function (require) {
3131
authorizedServices: null,
3232

3333
showTryUri: function (serviceKey, endpointKey) {
34+
var endpointDisabled;
35+
3436
this.currentService = serviceKey;
3537
appChannel.vent.trigger('show:menu', serviceKey, endpointKey);
3638

@@ -48,6 +50,9 @@ define(function (require) {
4850
});
4951
}
5052

53+
endpointDisabled = appChannel.reqres.request('is:endpointDisabled', serviceKey, endpointKey);
54+
this.tryUriView.triggerMethod('endpointDisabled', endpointDisabled);
55+
5156
this.api.fetchSampleUri();
5257
this.api.fetchGenericUri();
5358
this.api.fetchGenericOutput();

app/app-js/modules/tryUri/tryUri.view.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@ <h3>URI Format: <code class="js-generic-uri tryuri-generic-uri">{{genericUri.uri
1515
</div>
1616

1717
<h3>Sample Output:</h3>
18-
<pre>
19-
<code class="js-output tryuri-output">{{tryUri.output}}{{^tryUri.output}}{{genericOutput.output}}{{/tryUri.output}}</code>
18+
<pre class="tryuri-output">
19+
<code class="js-output">{{tryUri.output}}{{^tryUri.output}}{{genericOutput.output}}{{/tryUri.output}}</code>
2020
</pre>

0 commit comments

Comments
 (0)