rjs optimize the app.

This commit is contained in:
kayone 2013-11-20 22:04:15 -08:00
parent 6b418276b6
commit 3311357df0
12 changed files with 135 additions and 129 deletions

View File

@ -163,7 +163,7 @@ module.exports = function (grunt) {
keepBuildDir : true,
modules: [{
name: 'app',
exclude: ['JsLibraries/jquery', 'templates.js']
exclude: ['templates.js']
}],
}

View File

@ -22,7 +22,7 @@ namespace NzbDrone.Api.Frontend
if (context.Request.Path.StartsWith("/api", StringComparison.CurrentCultureIgnoreCase)) return false;
if (context.Request.Path.StartsWith("/signalr", StringComparison.CurrentCultureIgnoreCase)) return false;
if (context.Request.Path.EndsWith("app.js")) return false;
if (context.Request.Path.EndsWith("main.js")) return false;
if (context.Request.Path.StartsWith("/log", StringComparison.CurrentCultureIgnoreCase) &&
context.Request.Path.EndsWith(".txt", StringComparison.CurrentCultureIgnoreCase))

View File

@ -55,6 +55,7 @@ namespace NzbDrone.Api.Frontend.Mappers
text = text.Replace(".css", ".css?v=" + BuildInfo.Version);
text = text.Replace(".js", ".js?v=" + BuildInfo.Version);
text = text.Replace("API_KEY", _configFileProvider.ApiKey);
text = text.Replace("APP_VERSION", BuildInfo.Version.ToString());
return text;
}

View File

@ -4,8 +4,8 @@ namespace NzbDrone.Api.Notifications
{
public class IndexerModule : ProviderModuleBase<NotificationResource, INotification, NotificationDefinition>
{
public IndexerModule(NotificationFactory notificationrFactory)
: base(notificationrFactory, "notification")
public IndexerModule(NotificationFactory notificationFactory)
: base(notificationFactory, "notification")
{
}

View File

@ -1,17 +0,0 @@
using NzbDrone.Core.ThingiProvider;
namespace NzbDrone.Core.Notifications
{
public class Notification
{
public int Id { get; set; }
public string Name { get; set; }
public string ImplementationName { get; set; }
public string Link { get; set; }
public bool OnGrab { get; set; }
public bool OnDownload { get; set; }
public IProviderConfig Settings { get; set; }
public INotification Instance { get; set; }
public string Implementation { get; set; }
}
}

View File

@ -354,7 +354,6 @@
<Compile Include="Notifications\Growl\GrowlSettings.cs" />
<Compile Include="Notifications\Growl\TestGrowlCommand.cs" />
<Compile Include="Notifications\INotification.cs" />
<Compile Include="Notifications\Notification.cs" />
<Compile Include="Notifications\NotificationRepository.cs" />
<Compile Include="Fluent.cs" />
<Compile Include="History\HistoryRepository.cs" />

View File

@ -1,88 +1,92 @@
'use strict';
(function () {
window.alert = function (message) {
window.Messenger().post(message);
};
define(
[
'jquery',
'messenger'
], function ($, Messenger) {
'use strict';
var addError = function(message){
window.$('#errors').append('<div>' + message + '</div>');
};
window.alert = function (message) {
new Messenger().post(message);
};
window.onerror = function (msg, url, line) {
var addError = function (message) {
$('#errors').append('<div>' + message + '</div>');
};
try {
window.onerror = function (msg, url, line) {
var a = document.createElement('a');
a.href = url;
var filename = a.pathname.split('/').pop();
try {
//Suppress Firefox debug errors when console window is closed
if (filename.toLowerCase() === 'markupview.jsm' || filename.toLowerCase() === 'markup-view.js') {
return false;
var a = document.createElement('a');
a.href = url;
var filename = a.pathname.split('/').pop();
//Suppress Firefox debug errors when console window is closed
if (filename.toLowerCase() === 'markupview.jsm' || filename.toLowerCase() === 'markup-view.js') {
return false;
}
var messageText = filename + ' : ' + line + '</br>' + msg;
var message = {
message : messageText,
type : 'error',
hideAfter : 1000,
showCloseButton: true
};
new Messenger().post(message);
addError(message.message);
}
catch (error) {
console.log('An error occurred while reporting error. ' + error);
console.log(msg);
new Messenger().post('Couldn\'t report JS error. ' + msg);
}
var messageText = filename + ' : ' + line + '</br>' + msg;
return false; //don't suppress default alerts and logs.
};
$(document).ajaxError(function (event, xmlHttpRequest, ajaxOptions) {
//don't report 200 error codes
if (xmlHttpRequest.status >= 200 && xmlHttpRequest.status <= 300) {
return undefined;
}
//don't report aborted requests
if (xmlHttpRequest.statusText === 'abort') {
return undefined;
}
var message = {
message : messageText,
type : 'error',
hideAfter : 1000,
showCloseButton: true
};
window.Messenger().post(message);
if (xmlHttpRequest.status === 0 && xmlHttpRequest.readyState === 0) {
return false;
}
if (xmlHttpRequest.status === 400 && ajaxOptions.isValidatedCall) {
return false;
}
if (xmlHttpRequest.status === 503) {
message.message = xmlHttpRequest.responseJSON.message;
}
else {
message.message = '[{0}] {1} : {2}'.format(ajaxOptions.type, xmlHttpRequest.statusText, ajaxOptions.url);
}
new Messenger().post(message);
addError(message.message);
}
catch (error) {
console.log('An error occurred while reporting error. ' + error);
console.log(msg);
window.alert('Couldn\'t report JS error. ' + msg);
}
return false; //don't suppress default alerts and logs.
};
window.$(document).ajaxError(function (event, xmlHttpRequest, ajaxOptions) {
//don't report 200 error codes
if (xmlHttpRequest.status >= 200 && xmlHttpRequest.status <= 300) {
return undefined;
}
//don't report aborted requests
if (xmlHttpRequest.statusText === 'abort') {
return undefined;
}
var message = {
type : 'error',
hideAfter : 1000,
showCloseButton: true
};
if (xmlHttpRequest.status === 0 && xmlHttpRequest.readyState === 0) {
return false;
}
if (xmlHttpRequest.status === 400 && ajaxOptions.isValidatedCall) {
return false;
}
if (xmlHttpRequest.status === 503) {
message.message = xmlHttpRequest.responseJSON.message;
}
else {
message.message = '[{0}] {1} : {2}'.format(ajaxOptions.type, xmlHttpRequest.statusText, ajaxOptions.url);
}
window.Messenger().post(message);
addError(message.message);
return false;
});
});
})();

View File

@ -1,7 +1,4 @@
define(
[
'jquery'
], function ($) {
define([], function () {
'use strict';
return {
load: function (name, parentRequire, onload, config) {
@ -13,7 +10,7 @@ define(
var resource = name.split('!')[0];
var url = window.NzbDrone.ApiRoot + '/' + resource;
$.ajax({
window.$.ajax({
url: url
}).done(function (data) {
onload(data);

View File

@ -1,6 +1,6 @@
'use strict';
require.config({
urlArgs: 'v=' + window.NzbDrone.Version,
paths: {
'backbone' : 'JsLibraries/backbone',
'moment' : 'JsLibraries/moment',
@ -22,23 +22,39 @@ require.config({
'signalR' : 'JsLibraries/jquery.signalR',
'jquery.knob' : 'JsLibraries/jquery.knob',
'jquery.dotdotdot' : 'JsLibraries/jquery.dotdotdot',
'jquery' : 'jQuery/jquery.shim',
'messenger' : 'JsLibraries/messenger',
'jquery' : 'JsLibraries/jquery',
'libs' : 'JsLibraries/',
'api': 'Require/require.api'
},
shim: {
jquery :{
exports: '$'
},
signalR: {
api: {
deps:
[
'jquery'
]
},
bootstrap: {
jquery : {
exports: '$'
},
messenger : {
deps :
[
'jquery'
],
exports: 'Messenger'
},
signalR : {
deps:
[
'jquery'
]
},
bootstrap : {
deps:
[
'jquery'
@ -49,23 +65,24 @@ require.config({
});
}
},
backstrech: {
backstrech : {
deps:
[
'jquery'
]
},
underscore: {
underscore : {
deps :
[
'jquery'
],
exports: '_'
},
backbone: {
backbone : {
deps:
[
'jquery',
'Instrumentation/ErrorHandler',
'underscore',
'Mixins/jquery.ajax',
'jQuery/ToTheTop'
@ -73,7 +90,7 @@ require.config({
exports: 'Backbone'
},
marionette: {
marionette : {
deps:
[
'backbone',
@ -88,45 +105,45 @@ require.config({
}
},
'jquery.knob': {
'jquery.knob' : {
deps:
[
'jquery'
]
},
'jquery.dotdotdot': {
'jquery.dotdotdot' : {
deps:
[
'jquery'
]
},
'backbone.pageable': {
'backbone.pageable' : {
deps:
[
'backbone'
]
},
'backbone.deepmodel': {
'backbone.deepmodel' : {
deps:
[
'backbone',
'underscore'
]
},
'backbone.validation': {
'backbone.validation' : {
deps :
[
'backbone'
],
exports: 'Backbone.Validation'
},
'backbone.modelbinder':{
deps :
'backbone.modelbinder': {
deps:
[
'backbone'
]
},
backgrid : {
backgrid : {
deps:
[
'backbone'
@ -154,7 +171,7 @@ require.config({
});
}
},
'backgrid.paginator': {
'backgrid.paginator' : {
exports: 'Backgrid.Extension.Paginator',
@ -163,7 +180,7 @@ require.config({
'backgrid'
]
},
'backgrid.selectall': {
'backgrid.selectall' : {
exports: 'Backgrid.Extension.SelectAll',
@ -175,6 +192,11 @@ require.config({
}
});
require.config({
urlArgs: 'v=' + window.NzbDrone.Version
});
define(
[
'jquery',
@ -224,5 +246,5 @@ define(
$('#footer-region .version').html(footerText);
});
app.start();
return app;
});

View File

@ -71,10 +71,6 @@
</script>
<script src="/polyfills.js"></script>
<script src="/JsLibraries/jquery.js"></script>
<script src="/JsLibraries/messenger.js"></script>
<script src="/Instrumentation/ErrorHandler.js"></script>
<script data-main="/app" src="/JsLibraries/require.js"></script>
<script data-main="main" src="/JsLibraries/require.js"></script>
<script src="/JsLibraries/xrayquire.js"></script>
</html>

View File

@ -1,7 +0,0 @@
'use strict';
define(
[
], function () {
return window.$;
});

11
src/UI/main.js Normal file
View File

@ -0,0 +1,11 @@
require.config({
urlArgs: 'v=' + window.NzbDrone.Version
});
define(
[
'app'
], function (app) {
'use strict';
app.start();
});