Skip to content

Commit 0475cc3

Browse files
author
Curtis Lacy
committed
2 parents 6c0abae + 7fdd04a commit 0475cc3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+459
-263
lines changed

app/app-js/app-require.js

+5-29
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,14 @@ require.config({
1010
'marionette': '../vendor/marionette/backbone.marionette',
1111
'bootstrap': '../vendor/bootstrap/bootstrap',
1212
'parsley': '../vendor/parsleyjs/parsley',
13+
'spinner': '../vendor/spin.js/spin',
1314
'hogan': '../vendor/requirejs-hogan-plugin/hogan',
1415
'hgn': '../vendor/requirejs-hogan-plugin/hgn',
1516
'text': '../vendor/requirejs-hogan-plugin/text',
1617

17-
// change to logger-prod for production (disables logging)
18-
'lib/logger': 'lib/logger-dev'
18+
// change to -prod for production
19+
'lib/logger': 'lib/logger-dev',
20+
'lib/eventDebugger': 'lib/eventDebugger-dev'
1921
},
2022

2123
shim: {
@@ -38,30 +40,4 @@ require.config({
3840
}
3941
});
4042

41-
require([
42-
'marionette',
43-
'app',
44-
'bootstrap',
45-
'entities/api/api.module',
46-
'entities/service/service.module',
47-
'entities/alert/alert.module',
48-
'debug/event.debugger'
49-
],
50-
function (Marionette, app) {
51-
require([
52-
'modules/header/header.module',
53-
'modules/menu/menu.module',
54-
'modules/welcome/welcome.module',
55-
'modules/footer/footer.module',
56-
'modules/static/static.module',
57-
'modules/tryUri/tryUri.module',
58-
'modules/alert/alert.module',
59-
], function () {
60-
// Override templating method to use hgn templates
61-
Marionette.Renderer.render = function (template, data) {
62-
return template(data);
63-
};
64-
65-
app.start();
66-
});
67-
});
43+
require(['app-start']);

app/app-js/app-start.js

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
define(function (require) {
2+
require('marionette');
3+
require('bootstrap');
4+
require('backbone.computedfields');
5+
require('lib/eventDebugger');
6+
7+
var Marionette = require('marionette'),
8+
app = require('app'),
9+
10+
api = require('entities/api/api.module'),
11+
service = require('entities/service/service.module'),
12+
alert = require('entities/alert/alert.module'),
13+
14+
header = require('modules/header/header.module'),
15+
menu = require('modules/menu/menu.module'),
16+
welcome = require('modules/welcome/welcome.module'),
17+
footer = require('modules/footer/footer.module'),
18+
static_ = require('modules/static/static.module'),
19+
tryUri = require('modules/tryUri/tryUri.module'),
20+
alert = require('modules/alert/alert.module'),
21+
loading = require('modules/loading/loading.module');
22+
23+
// Override templating method to use hgn templates
24+
Marionette.Renderer.render = function (template, data) {
25+
return template(data);
26+
};
27+
28+
// start entity modules
29+
api.start();
30+
service.start();
31+
alert.start();
32+
33+
// start rendering modules
34+
header.start();
35+
menu.start();
36+
welcome.start();
37+
footer.start();
38+
static_.start();
39+
tryUri.start();
40+
alert.start();
41+
loading.start();
42+
43+
// start app
44+
app.start();
45+
46+
});

app/app-js/app.controller.js

+23-13
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
define(function (require) {
22
var AppContentLayout = require('app.content.layout'),
33
ModuleController = require('lib/module.controller'),
4+
history = require('lib/history'),
45
AppController;
56

67
AppController = ModuleController.extend({
@@ -10,29 +11,38 @@ define(function (require) {
1011
},
1112

1213
appEvents: {
13-
1414
commands: {
15-
'showin:header': 'showInHeader',
16-
'showin:footer': 'showInFooter',
17-
'showin:content': 'showInContent',
18-
'showin:alert': 'showInAlert',
19-
'showin:menu': 'showInMenu',
20-
'showin:main': 'showInMain'
15+
'showin:headerRegion': 'showInHeaderRegion',
16+
'showin:footerRegion': 'showInFooterRegion',
17+
'showin:contentRegion': 'showInContentRegion',
18+
'showin:alertRegion': 'showInAlertRegion',
19+
'showin:menuRegion': 'showInMenuRegion',
20+
'showin:mainRegion': 'showInMainRegion',
21+
'showin:loadingRegion': 'showInLoadingRegion',
22+
'close:loadingRegion': 'closeLoadingRegion'
2123
}
2224
},
2325

2426
appLayout: null,
2527
appLayoutShown: false,
2628

27-
showInHeader: function (view) {
29+
showInLoadingRegion: function (view) {
30+
this.app.loadingRegion.show(view);
31+
},
32+
33+
closeLoadingRegion: function () {
34+
this.app.loadingRegion.close();
35+
},
36+
37+
showInHeaderRegion: function (view) {
2838
this.app.headerRegion.show(view);
2939
},
3040

31-
showInFooter: function (view) {
41+
showInFooterRegion: function (view) {
3242
this.app.footerRegion.show(view);
3343
},
3444

35-
showInContent: function (view) {
45+
showInContentRegion: function (view) {
3646
this.app.contentRegion.show(view);
3747

3848
// showing a view in the contentRegion will destroy the appLayout
@@ -56,23 +66,23 @@ define(function (require) {
5666
this.appLayoutShown = true;
5767
},
5868

59-
showInAlert: function (view) {
69+
showInAlertRegion: function (view) {
6070
var self = this;
6171

6272
this._showInContentRegion(function () {
6373
self.appLayout.alertRegion.show(view);
6474
});
6575
},
6676

67-
showInMenu: function (view) {
77+
showInMenuRegion: function (view) {
6878
var self = this;
6979

7080
this._showInContentRegion(function () {
7181
self.appLayout.menuRegion.show(view);
7282
});
7383
},
7484

75-
showInMain: function (view) {
85+
showInMainRegion: function (view) {
7686
var self = this;
7787

7888
this._showInContentRegion(function () {

app/app-js/app.js

+11-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,17 @@ define(function (require) {
77
app.addRegions({
88
headerRegion: '#header-region',
99
contentRegion: '#content-region',
10-
footerRegion: '#footer-region'
10+
footerRegion: '#footer-region',
11+
loadingRegion: '#loading-region'
12+
});
13+
14+
// Hacky fix for stupid Facebook oauth redirect hash
15+
app.on('initialize:before', function () {
16+
if (window.location.hash == '#_=_') {
17+
history.replaceState
18+
? history.replaceState(null, null, window.location.href.split('#')[0])
19+
: window.location.hash = '';
20+
}
1121
});
1222

1323
app.on('initialize:after', function () {

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

-2
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,12 @@ define(function (require) {
4646
if (!this.alertRegistry[hash]) {
4747
this.alerts.add(alert);
4848
this.alertRegistry[hash] = true;
49-
console.log('>>> add', this.alerts.models);
5049
}
5150
},
5251

5352
removeAlert: function (alert) {
5453
this.alerts.remove(alert);
5554
this.alertRegistry[alert.hash()] = false;
56-
console.log('>>> rem', this.alerts.models);
5755
},
5856

5957
clearAlerts: function (alert) {

app/app-js/entities/alert/alert.module.js

-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ define(function (require) {
1111
});
1212

1313
alertEntities = app.module('alertEntities', AlertModule);
14-
alertEntities.start();
1514

1615
return alertEntities;
1716
});

app/app-js/entities/api/api.controller.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ define(function (require) {
77

88
appEvents: {
99
reqres: {
10-
'get:api': 'getApi'
10+
'get:apiModel': 'getApiModel'
1111
}
1212
},
1313

14-
getApi: function (serviceKey, endpointKey) {
14+
getApiModel: function (serviceKey, endpointKey) {
1515
return new ApiModel({
1616
serviceKey: serviceKey,
1717
endpointKey: endpointKey

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

+45-36
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ define(function (require) {
44
GenericUriModel = require('entities/api/call/genericUri.model'),
55
SampleUriModel = require('entities/api/call/sampleUri.model'),
66
GetUriModel = require('entities/api/call/tryUri.model'),
7-
HasNestedModel = require('lib/hasNestedModel.mixin'),
7+
HasNestedModel = require('lib/hasNestedModel'),
88
appChannel = require('app.channel'),
99
ApiModel;
1010

@@ -20,59 +20,64 @@ define(function (require) {
2020
tryUri: null
2121
},
2222

23-
constructor: function (attrs, options) {
24-
var apiAttributes = _.pick(attrs, ['serviceKey', 'endpointKey']);
25-
26-
_.extend(attrs, {
27-
genericOutput: new GenericOutputModel(apiAttributes),
28-
genericUri: new GenericUriModel(apiAttributes),
29-
sampleUri: new SampleUriModel(apiAttributes),
30-
tryUri: new GetUriModel()
31-
});
23+
computed: {
24+
apiName: {
25+
depends: ['serviceKey', 'endpointKey'],
26+
get: function () {
27+
var serviceName = appChannel.reqres.request(
28+
'lookup:serviceName', this.get('serviceKey')),
29+
endpointName = appChannel.reqres.request(
30+
'lookup:endpointName', this.get('serviceKey'), this.get('endpointKey')),
31+
apiName = serviceName + ' ' + endpointName;
32+
return apiName;
33+
}
34+
}
35+
},
3236

37+
constructor: function () {
38+
// Attach nested model functionality
3339
new HasNestedModel(this);
3440

35-
ApiModel.__super__.constructor.call(this, attrs, options);
41+
// Attach computed field functionality
42+
new Backbone.ComputedFields(this);
43+
44+
ApiModel.__super__.constructor.apply(this, arguments);
3645
},
3746

3847
initialize: function () {
39-
var self = this;
48+
var self = this,
49+
apiAttributes = {
50+
serviceKey: this.get('serviceKey'),
51+
endpointKey: this.get('endpointKey')
52+
};
53+
54+
// Initialize submodels
55+
this.set({
56+
genericOutput: new GenericOutputModel(apiAttributes),
57+
genericUri: new GenericUriModel(apiAttributes),
58+
sampleUri: new SampleUriModel(apiAttributes),
59+
tryUri: new GetUriModel()
60+
});
4061

4162
this.on('change', function () {
42-
var serviceKey,
43-
endpointKey;
44-
63+
var apiAttributes;
64+
65+
// When serviceKey or endpointKey are changed, pass them down to submodels
4566
if (self.hasChanged('serviceKey') || self.hasChanged('endpointKey')) {
46-
serviceKey = self.get('serviceKey');
47-
endpointKey = self.get('endpointKey');
67+
apiAttributes = {
68+
serviceKey: self.get('serviceKey'),
69+
endpointKey: self.get('endpointKey')
70+
};
4871

4972
_.invoke([
5073
self.get('genericOutput'),
5174
self.get('genericUri'),
5275
self.get('sampleUri')
53-
], 'set', { serviceKey: serviceKey, endpointKey: endpointKey });
54-
55-
self.trigger('change:apiName', self, self.get('apiName'));
76+
], 'set', apiAttributes);
5677
}
5778
});
5879
},
5980

60-
get: function (key) {
61-
var serviceName,
62-
endpointName,
63-
apiName;
64-
65-
if (key === 'apiName') {
66-
serviceName = appChannel.reqres.request('lookup:serviceName', this.get('serviceKey'));
67-
endpointName = appChannel.reqres.request('lookup:endpointName',
68-
this.get('serviceKey'), this.get('endpointKey'));
69-
apiName = serviceName + ' ' + endpointName;
70-
return apiName;
71-
} else {
72-
return ApiModel.__super__.get.apply(this, arguments);
73-
}
74-
},
75-
7681
clear: function () {
7782
this.set({
7883
apiName: null,
@@ -101,6 +106,10 @@ define(function (require) {
101106

102107
fetchTryUri: function (options) {
103108
this.get('tryUri').fetch({ data: $.param(options) });
109+
},
110+
111+
toJSON: function () {
112+
return _.clone(this.attributes);
104113
}
105114
});
106115

app/app-js/entities/api/api.module.js

-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ define(function (require) {
1111
});
1212

1313
apiEntities = app.module('apiEntities', AlertModule);
14-
apiEntities.start();
1514

1615
return apiEntities;
1716
});

0 commit comments

Comments
 (0)