sugar kills (removed sugar.js)

Relative dates for next airing on posters and list (series)
History time shows real time on tooltip
This commit is contained in:
Mark McDowall 2013-07-16 23:23:44 -07:00
parent 641e01376b
commit 207d9c256d
21 changed files with 296 additions and 9100 deletions

View File

@ -24,7 +24,7 @@ module.exports = function (grunt) {
'UI/JsLibraries/jquery.knob.js' : 'http://raw.github.com/aterrien/jQuery-Knob/master/js/jquery.knob.js', 'UI/JsLibraries/jquery.knob.js' : 'http://raw.github.com/aterrien/jQuery-Knob/master/js/jquery.knob.js',
'UI/JsLibraries/require.js' : 'http://raw.github.com/jrburke/requirejs/master/require.js', 'UI/JsLibraries/require.js' : 'http://raw.github.com/jrburke/requirejs/master/require.js',
'UI/JsLibraries/sugar.js' : 'http://raw.github.com/andrewplummer/Sugar/master/release/sugar-full.development.js', 'UI/JsLibraries/filesize.js' : 'http://cdn.filesizejs.com/filesize.js',
'UI/JsLibraries/lodash.underscore.js' : 'http://raw.github.com/bestiejs/lodash/master/dist/lodash.underscore.js', 'UI/JsLibraries/lodash.underscore.js' : 'http://raw.github.com/bestiejs/lodash/master/dist/lodash.underscore.js',
'UI/JsLibraries/messenger.js' : 'http://raw.github.com/HubSpot/messenger/master/build/js/messenger.js', 'UI/JsLibraries/messenger.js' : 'http://raw.github.com/HubSpot/messenger/master/build/js/messenger.js',

View File

@ -4,10 +4,11 @@ define(
[ [
'app', 'app',
'marionette', 'marionette',
'moment',
'Calendar/Collection', 'Calendar/Collection',
'Episode/Layout', 'Episode/Layout',
'fullcalendar' 'fullcalendar'
], function (App, Marionette, CalendarCollection, EpisodeLayout) { ], function (App, Marionette, Moment, CalendarCollection, EpisodeLayout) {
var _instance; var _instance;
@ -50,8 +51,8 @@ define(
}, },
getEvents: function (start, end, callback) { getEvents: function (start, end, callback) {
var startDate = Date.create(start).format(Date.ISO8601_DATETIME); var startDate = Moment(start).toISOString();
var endDate = Date.create(end).format(Date.ISO8601_DATETIME); var endDate = Moment(end).toISOString();
_instance.collection.fetch({ _instance.collection.fetch({
data : { start: startDate, end: endDate }, data : { start: startDate, end: endDate },
@ -80,11 +81,11 @@ define(
getStatusLevel: function (element) { getStatusLevel: function (element) {
var hasFile = element.get('hasFile'); var hasFile = element.get('hasFile');
var currentTime = Date.create(); var currentTime = Moment();
var start = Date.create(element.get('airDate')); var start = Moment(element.get('airDate'));
var end = Date.create(element.get('end')); var end = Moment(element.get('end'));
if (currentTime.isBetween(start, end)) { if (currentTime.isAfter(start) && currentTime.isBefore(end)) {
return 'warning'; return 'warning';
} }

View File

@ -2,20 +2,21 @@
define( define(
[ [
'backbone', 'backbone',
'moment',
'Series/EpisodeModel' 'Series/EpisodeModel'
], function (Backbone, EpisodeModel) { ], function (Backbone, Moment, EpisodeModel) {
return Backbone.Collection.extend({ return Backbone.Collection.extend({
url : window.ApiRoot + '/calendar', url : window.ApiRoot + '/calendar',
model: EpisodeModel, model: EpisodeModel,
comparator: function (model1, model2) { comparator: function (model1, model2) {
var airDate1 = model1.get('airDate'); var airDate1 = model1.get('airDate');
var date1 = Date.create(airDate1); var date1 = Moment(airDate1);
var time1 = date1.getTime(); var time1 = date1.unix();
var airDate2 = model2.get('airDate'); var airDate2 = model2.get('airDate');
var date2 = Date.create(airDate2); var date2 = Moment(airDate2);
var time2 = date2.getTime(); var time2 = date2.unix();
if (time1 < time2){ if (time1 < time2){
return -1; return -1;

View File

@ -2,16 +2,24 @@
define( define(
[ [
'backgrid', 'backgrid',
'moment',
'Shared/FormatHelpers' 'Shared/FormatHelpers'
], function (Backgrid, FormatHelpers) { ], function (Backgrid, Moment, FormatHelpers) {
return Backgrid.Cell.extend({ return Backgrid.Cell.extend({
className: 'air-date-cell', className: 'air-date-cell',
render: function () { render: function () {
this.$el.empty(); this.$el.empty();
var airDate = this.model.get(this.column.get('name')); var date = this.model.get(this.column.get('name'));
this.$el.html(FormatHelpers.DateHelper(airDate));
if (date) {
this.$el.html(FormatHelpers.DateHelper(date));
//TODO: Figure out why this makes the series grid freak out
//this.$el.attr('title', Moment(date).format('LLLL'));
}
return this; return this;
} }

View File

@ -2,8 +2,9 @@
define( define(
[ [
'Cells/NzbDroneCell' 'Cells/NzbDroneCell',
], function (NzbDroneCell) { 'Shared/FormatHelpers'
], function (NzbDroneCell, FormatHelpers) {
return NzbDroneCell.extend({ return NzbDroneCell.extend({
className: 'episode-number-cell', className: 'episode-number-cell',
@ -30,14 +31,14 @@ define(
if (episodes.constructor === Array) { if (episodes.constructor === Array) {
paddedEpisodes = _.map(episodes,function (episodeNumber) { paddedEpisodes = _.map(episodes,function (episodeNumber) {
return episodeNumber.pad(2); return FormatHelpers.pad(episodeNumber, 2);
}).join(); }).join();
} }
else { else {
paddedEpisodes = episodes.pad(2); paddedEpisodes = FormatHelpers.pad(episodes, 2);
} }
result = 'S{0}-E{1}'.format(seasonNumber.pad(2), paddedEpisodes); result = '{0}x{1}'.format(seasonNumber, paddedEpisodes);
} }
else if (airDate) { else if (airDate) {
result = new Date(airDate).toLocaleDateString(); result = new Date(airDate).toLocaleDateString();

View File

@ -2,8 +2,9 @@
define( define(
[ [
'backgrid' 'backgrid',
], function (Backgrid) { 'moment'
], function (Backgrid, Moment) {
return Backgrid.Cell.extend({ return Backgrid.Cell.extend({
className: 'episode-status-cell', className: 'episode-status-cell',
@ -16,7 +17,7 @@ define(
var icon; var icon;
var tooltip; var tooltip;
var hasAired = Date.create(this.model.get('airDate')).isBefore(Date.create()); var hasAired = Moment(this.model.get('airDate')).isBefore(Moment());
var hasFile = this.model.get('hasFile'); var hasFile = this.model.get('hasFile');
if (hasFile) { if (hasFile) {

View File

@ -1,8 +1,10 @@
'use strict'; 'use strict';
define( define(
[ [
'Cells/NzbDroneCell' 'Cells/NzbDroneCell',
], function (NzbDroneCell) { 'moment',
'Shared/FormatHelpers'
], function (NzbDroneCell, Moment, FormatHelpers) {
return NzbDroneCell.extend({ return NzbDroneCell.extend({
className: 'relative-date-cell', className: 'relative-date-cell',
@ -10,7 +12,11 @@ define(
render: function () { render: function () {
var date = this.model.get(this.column.get('name')); var date = this.model.get(this.column.get('name'));
this.$el.html(Date.create(date).relative());
if (date) {
this.$el.html(FormatHelpers.DateHelper(date));
this.$el.attr('title', Moment(date).format('LLLL'));
}
return this; return this;
} }

View File

@ -8,11 +8,13 @@
} }
.air-date-cell { .air-date-cell {
width : 100px; width : 120px;
cursor: default;
} }
.relative-date-cell { .relative-date-cell {
width : 150px; width : 150px;
cursor: default;
} }
.quality-cell { .quality-cell {

View File

@ -2,15 +2,27 @@
define( define(
[ [
'handlebars', 'handlebars',
'sugar' 'moment',
], function (Handlebars) { 'Shared/FormatHelpers'
], function (Handlebars, Moment, FormatHelpers) {
Handlebars.registerHelper('ShortDate', function (input) { Handlebars.registerHelper('ShortDate', function (input) {
if (!input) { if (!input) {
return ''; return '';
} }
var date = Date.create(input); var date = Moment(input);
var result = '<span title="' + date.full() + '">' + date.short() + '</span>'; var result = '<span title="' + date.format('LLLL') + '">' + date.format('LL') + '</span>';
return new Handlebars.SafeString(result);
});
Handlebars.registerHelper('NextAiring', function (input) {
if (!input) {
return '';
}
var date = Moment(input);
var result = '<span title="' + date.format('LLLL') + '">' + FormatHelpers.DateHelper(input) + '</span>';
return new Handlebars.SafeString(result); return new Handlebars.SafeString(result);
}); });
@ -20,7 +32,7 @@ define(
return ''; return '';
} }
return Date.create(input).format('{dd}'); return Moment(input).format('DD');
}); });
Handlebars.registerHelper('Month', function (input) { Handlebars.registerHelper('Month', function (input) {
@ -28,7 +40,7 @@ define(
return ''; return '';
} }
return Date.create(input).format('{Mon}'); return Moment(input).format('MMM');
}); });
Handlebars.registerHelper('StartTime', function (input) { Handlebars.registerHelper('StartTime', function (input) {
@ -36,11 +48,11 @@ define(
return ''; return '';
} }
var date = Date.create(input); var date = Moment(input);
if (date.format('{mm}') === '00') { if (date.format('mm') === '00') {
return date.format('{h}{tt}'); return date.format('ha');
} }
return date.format('{h}.{mm}{tt}'); return date.format('h.mma');
}); });
}); });

View File

@ -2,8 +2,9 @@
define( define(
[ [
'handlebars', 'handlebars',
'Shared/FormatHelpers' 'Shared/FormatHelpers',
], function (Handlebars, FormatHelpers) { 'moment'
], function (Handlebars, FormatHelpers, Moment) {
Handlebars.registerHelper('EpisodeNumber', function () { Handlebars.registerHelper('EpisodeNumber', function () {
if (this.series.seriesType === 'daily') { if (this.series.seriesType === 'daily') {
@ -19,11 +20,11 @@ define(
Handlebars.registerHelper('StatusLevel', function () { Handlebars.registerHelper('StatusLevel', function () {
var hasFile = this.hasFile; var hasFile = this.hasFile;
var currentTime = Date.create(); var currentTime = Moment();
var start = Date.create(this.airDate); var start = Moment(this.airDate);
var end = Date.create(this.end); var end = Moment(this.end);
if (currentTime.isBetween(start, end)) { if (currentTime.isAfter(start) && currentTime.isBefore(end)) {
return 'warning'; return 'warning';
} }

View File

@ -9,6 +9,7 @@ define(
}); });
Handlebars.registerHelper('Pad2', function (input) { Handlebars.registerHelper('Pad2', function (input) {
return input.pad(2); return FormatHelpers.pad(input, 2);
}); });
}); });

153
UI/JsLibraries/filesize.js Normal file
View File

@ -0,0 +1,153 @@
/**
* filesize
*
* @author Jason Mulligan <jason.mulligan@avoidwork.com>
* @copyright 2013 Jason Mulligan
* @license BSD-3 <https://raw.github.com/avoidwork/filesize.js/master/LICENSE>
* @link http://filesizejs.com
* @module filesize
* @version 1.10.0
*/
( function ( global ) {
"use strict";
var base = 10,
right = /\.(.*)/,
bit = /b$/,
bite = /^B$/,
zero = /^0$/,
options;
options = {
all : {
increments : [["B", 1], ["kb", 125], ["kB", 1000], ["Mb", 125000], ["MB", 1000000], ["Gb", 125000000], ["GB", 1000000000], ["Tb", 125000000000], ["TB", 1000000000000], ["Pb", 125000000000000], ["PB", 1000000000000000]],
nth : 11
},
bitless : {
increments : [["B", 1], ["kB", 1000], ["MB", 1000000], ["GB", 1000000000], ["TB", 1000000000000], ["PB", 1000000000000000]],
nth : 6
}
};
/**
* filesize
*
* @param {Mixed} arg String, Int or Float to transform
* @param {Mixed} pos [Optional] Position to round to, defaults to 2 if shrt is ommitted, or `true` for shrthand output
* @param {Boolean} bits [Optional] Determines if `bit` sizes are used for result calculation, default is true
* @return {String} Readable file size String
*/
function filesize ( arg) {
var result = "",
bits = true,
skip = false,
i, neg, num, pos, shrt, size, sizes, suffix, z;
// Determining arguments
if (arguments[3] !== undefined) {
pos = arguments[1];
shrt = arguments[2];
bits = arguments[3];
}
else {
typeof arguments[1] === "boolean" ? shrt = arguments[1] : pos = arguments[1];
if ( typeof arguments[2] === "boolean" ) {
bits = arguments[2];
}
}
if ( isNaN( arg ) || ( pos !== undefined && isNaN( pos ) ) ) {
throw new Error("Invalid arguments");
}
shrt = ( shrt === true );
bits = ( bits === true );
pos = shrt ? 1 : ( pos === undefined ? 2 : parseInt( pos, base ) );
num = Number( arg );
neg = ( num < 0 );
// Flipping a negative number to determine the size
if ( neg ) {
num = -num;
}
// Zero is now a special case because bytes divide by 1
if ( num === 0 ) {
if ( shrt ) {
result = "0";
}
else {
result = "0 B";
}
}
else {
if ( bits ) {
sizes = options.all.increments;
i = options.all.nth;
}
else {
sizes = options.bitless.increments;
i = options.bitless.nth;
}
while ( i-- ) {
size = sizes[i][1];
suffix = sizes[i][0];
if ( num >= size ) {
// Treating bytes as cardinal
if ( bite.test( suffix ) ) {
skip = true;
pos = 0;
}
result = ( num / size ).toFixed( pos );
if ( !skip && shrt ) {
if ( bits && bit.test( suffix ) ) {
suffix = suffix.toLowerCase();
}
suffix = suffix.charAt( 0 );
z = right.exec( result );
if ( suffix === "k" ) {
suffix = "K";
}
if ( z !== null && z[1] !== undefined && zero.test( z[1] ) ) {
result = parseInt( result, base );
}
result += suffix;
}
else if ( !shrt ) {
result += " " + suffix;
}
break;
}
}
}
// Decorating a 'diff'
if ( neg ) {
result = "-" + result;
}
return result;
}
// CommonJS, AMD, script tag
if ( typeof exports !== "undefined" ) {
module.exports = filesize;
}
else if ( typeof define === "function" ) {
define( function () {
return filesize;
});
}
else {
global.filesize = filesize;
}
})( this );

File diff suppressed because it is too large Load Diff

View File

@ -2,16 +2,17 @@
define( define(
[ [
'backbone', 'backbone',
'moment',
'Series/SeriesModel' 'Series/SeriesModel'
], function (Backbone, SeriesModel) { ], function (Backbone, Moment, SeriesModel) {
return Backbone.Model.extend({ return Backbone.Model.extend({
initialize: function () { initialize: function () {
if (this.has('series')) { if (this.has('series')) {
var start = Date.create(this.get('airDate')); var start = Moment(this.get('airDate'));
var runtime = this.get('series').get('runtime'); var runtime = this.get('series').get('runtime');
this.set('end', start.addMinutes(runtime)); this.set('end', start.add('minutes', runtime));
} }
}, },

View File

@ -31,7 +31,7 @@
<div class="span8"> <div class="span8">
{{#if_eq status compare="continuing"}} {{#if_eq status compare="continuing"}}
{{#if nextAiring}} {{#if nextAiring}}
<span class="label">{{ShortDate nextAiring}}</span> <span class="label">{{NextAiring nextAiring}}</span>
{{/if}} {{/if}}
<span class="label label-info">Season {{seasonCount}}</span> <span class="label label-info">Season {{seasonCount}}</span>
{{else}} {{else}}

View File

@ -20,14 +20,14 @@
<div class="center"> <div class="center">
<div class="labels"> <div class="labels">
{{#if isContinuing}} {{#if_eq status compare="continuing"}}
{{#if nextAiring}} {{#if nextAiring}}
<span class="label label-inverse">{{ShortDate nextAiring}}</span> <span class="label label-inverse">{{NextAiring nextAiring}}</span>
{{/if}} {{/if}}
<span class="label label-info">Season {{seasonCount}}</span> <span class="label label-info">Season {{seasonCount}}</span>
{{else}} {{else}}
<span class="label label-info">{{seasonCount}} Seasons</span> <span class="label label-info">{{seasonCount}} Seasons</span>
{{/if}} {{/if_eq}}
</div> </div>
</div> </div>
</div> </div>

View File

@ -60,7 +60,8 @@ define(
label : 'Episodes', label : 'Episodes',
sortable: false, sortable: false,
template: 'Series/EpisodeProgressTemplate', template: 'Series/EpisodeProgressTemplate',
cell : TemplatedCell cell : TemplatedCell,
className: 'episode-progress-cell'
}, },
{ {
name : 'this', name : 'this',
@ -189,8 +190,7 @@ define(
title : '', title : '',
icon : 'icon-table', icon : 'icon-table',
callback: this._showTable callback: this._showTable
}, }
] ]
}; };

View File

@ -2,37 +2,37 @@
define( define(
[ [
'sugar' 'moment',
], { 'filesize'
Bytes: function (sourceSize) { ], function (Moment, Filesize) {
var size = Number(sourceSize);
return size.bytes(1);
},
DateHelper: function (sourceDate) { return {
if (!sourceDate) {
return '';
}
var date = Date.create(sourceDate); Bytes: function (sourceSize) {
var size = Number(sourceSize);
return Filesize(size, 1, false);
},
if (date.isYesterday()) { DateHelper: function (sourceDate) {
return 'Yesterday'; if (!sourceDate) {
} return '';
if (date.isToday()) { }
return 'Today';
}
if (date.isTomorrow()) {
return 'Tomorrow';
}
if (date.isAfter(Date.create('tomorrow')) && date.isBefore(Date.create().addDays(7))) {
return date.format('{Weekday}');
}
if (date.isAfter(Date.create().addDays(6))) { var date = Moment(sourceDate);
return date.relative().replace(' from now', '');
}
return date.format('{MM}/{dd}/{yyyy}'); if (date.isAfter(Moment().add('days', 6))) {
return date.fromNow(true);
}
//TODO: It would be nice to not have to hack this...
var calendarDate = date.calendar();
return calendarDate.substring(0, calendarDate.indexOf(' at '));
},
pad: function(n, width, z) {
z = z || '0';
n = n + '';
return n.length >= width ? n : new Array(width - n.length + 1).join(z) + n;
}
} }
}); });

View File

@ -0,0 +1,23 @@
'use strict';
define(
[
], function () {
return {
startsWith: function(str, starts){
if (starts === '') return true;
if (str == null || starts == null) return false;
str = String(str); starts = String(starts);
return str.length >= starts.length && str.slice(0, starts.length) === starts;
},
endsWith: function(str, ends){
if (ends === '') return true;
if (str == null || ends == null) return false;
str = String(str); ends = String(ends);
return str.length >= ends.length && str.slice(str.length - ends.length) === ends;
}
}
});

View File

@ -5,8 +5,8 @@ require.config({
paths: { paths: {
'backbone' : 'JsLibraries/backbone', 'backbone' : 'JsLibraries/backbone',
'sugar' : 'JsLibraries/sugar',
'moment' : 'JsLibraries/moment', 'moment' : 'JsLibraries/moment',
'filesize' : 'JsLibraries/filesize',
'handlebars' : 'JsLibraries/handlebars.runtime', 'handlebars' : 'JsLibraries/handlebars.runtime',
'handlebars.helpers' : 'JsLibraries/handlebars.helpers', 'handlebars.helpers' : 'JsLibraries/handlebars.helpers',
'bootstrap' : 'JsLibraries/bootstrap', 'bootstrap' : 'JsLibraries/bootstrap',

View File

@ -1,5 +1,5 @@
'use strict'; 'use strict';
define(function () { define(['Shared/StringHelpers'],function (StringHelpers) {
//This module will automatically route all relative links through backbone router rather than //This module will automatically route all relative links through backbone router rather than
//causing links to reload pages. //causing links to reload pages.
@ -40,7 +40,7 @@ define(function () {
} }
if (!href.startsWith('http')) { if (!StringHelpers.startsWith(href, 'http')) {
router.navigate(href, { trigger: true }); router.navigate(href, { trigger: true });
} }