Skip to content

Commit

Permalink
Squashed commit of the following:
Browse files Browse the repository at this point in the history
commit ae97959
Author: Jörg Weber <weber.joerg.h@gmail.com>
Date:   Tue Jul 29 14:32:13 2014 +0200

    * write db content ordered to file system
    * add db lock to avoid circular event handling
      on update db

commit 4bcd657
Author: Jörg Weber <weber.joerg.h@gmail.com>
Date:   Tue Jul 29 14:31:19 2014 +0200

    * add playSong event handling to view
    * update main view on playSong event

commit fa10416
Author: Jörg Weber <weber.joerg.h@gmail.com>
Date:   Tue Jul 29 14:30:15 2014 +0200

    * fix subsonic plugin by referencing to correct method

commit 6a49e53
Author: Jörg Weber <weber.joerg.h@gmail.com>
Date:   Tue Jul 29 14:29:46 2014 +0200

    * add optional successCallback handling to writeFile

commit 116fddf
Author: Jörg Weber <weber.joerg.h@gmail.com>
Date:   Tue Jul 29 14:29:13 2014 +0200

    * remove unnecessary event trigger

commit 5df5f9c
Author: Jörg Weber <weber.joerg.h@gmail.com>
Date:   Tue Jul 29 12:30:43 2014 +0200

    * make jshint happy

commit fb7086c
Author: Jörg Weber <weber.joerg.h@gmail.com>
Date:   Tue Jul 29 12:28:19 2014 +0200

    * add jQuery as argument

commit d4317d1
Author: Jörg Weber <weber.joerg.h@gmail.com>
Date:   Tue Jul 29 12:27:59 2014 +0200

    * remove order from sons db query because we sort
      the db on save

commit 59649cb
Author: Jörg Weber <weber.joerg.h@gmail.com>
Date:   Tue Jul 29 12:27:25 2014 +0200

    * sort db on save

commit 90f80d5
Author: Jörg Weber <weber.joerg.h@gmail.com>
Date:   Tue Jul 29 12:27:07 2014 +0200

    * trigger fillSongBoxEvent instead of query db and
      call fillSongBox manually

commit 3635df2
Author: Jörg Weber <weber.joerg.h@gmail.com>
Date:   Tue Jul 29 12:26:24 2014 +0200

    * adjust jshintrc

commit 8dbce47
Author: Jörg Weber <weber.joerg.h@gmail.com>
Date:   Tue Jul 29 12:26:05 2014 +0200

    * set indent of 4 spaces to js beautifyrc

commit 75e7e39
Author: Jörg Weber <weber.joerg.h@gmail.com>
Date:   Tue Jul 29 11:28:09 2014 +0200

    * remove limit of database query

commit 4e81c4f
Author: Jörg Weber <weber.joerg.h@gmail.com>
Date:   Tue Jul 29 11:27:45 2014 +0200

    * refactor fillSongBox
    * use native Array.forEach instead of ‘for loop’
    * call encodeHtml only once for each entry

commit 3455b50
Author: Jörg Weber <weber.joerg.h@gmail.com>
Date:   Tue Jul 29 11:26:23 2014 +0200

    * refactor setSongAsFirstPlaylistElement
    * use Array.join instead of string concatenation

commit 43c0e22
Author: Jörg Weber <weber.joerg.h@gmail.com>
Date:   Tue Jul 29 11:24:26 2014 +0200

    * code formatting

commit e3e172f
Author: Jörg Weber <weber.joerg.h@gmail.com>
Date:   Tue Jul 29 11:18:43 2014 +0200

    * adjust jshint to use 4 space indent

commit 6e1d965
Author: Jörg Weber <weber.joerg.h@gmail.com>
Date:   Tue Jul 29 11:18:23 2014 +0200

    * update jquery to v2.1.1

commit 369ed1b
Merge: ca68f56 d28fb3f
Author: Jörg Weber <weber.joerg.h@gmail.com>
Date:   Tue Jul 29 09:10:21 2014 +0200

    Merge branch 'refactor/theBigRefactoring' into refactor/view

    Conflicts:
    	app/js/components/lib_core.js
    	app/js/components/lib_view.js

commit ca68f56
Author: Jörg Weber <weber.joerg.h@gmail.com>
Date:   Mon Jul 28 23:13:48 2014 +0200

    * remove obsolete arguments

commit 02ad9b7
Author: Jörg Weber <weber.joerg.h@gmail.com>
Date:   Mon Jul 28 23:07:34 2014 +0200

    * split view and core
  • Loading branch information
JayGray committed Jul 29, 2014
1 parent d28fb3f commit 3e90c8b
Show file tree
Hide file tree
Showing 9 changed files with 129 additions and 88 deletions.
2 changes: 1 addition & 1 deletion .jsbeautifyrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
"jslint_happy": true,
"max_preserve_newlines": 2,
"format_on_save": true,
"indent_size": 2,
"indent_size": 4,
"indent_with_tabs": false
}
46 changes: 24 additions & 22 deletions .jshintrc
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
{
"esnext": true,
"bitwise": false,
"camelcase": true,
"curly": true,
"eqeqeq": true,
"immed": true,
"indent": 2,
"latedef": true,
"newcap": true,
"noarg": true,
"quotmark": "single",
"regexp": true,
"undef": true,
"unused": true,
"strict": true,
"trailing": true,
"smarttabs": true,
"devel": true,
"browser": true,
"globals" : {
"$": true
}
"maxerr" : 50,
"bitwise" : true,
"camelcase" : true,
"curly" : true,
"eqeqeq" : true,
"forin" : true,
"immed" : true,
"indent" : 4,
"latedef" : true,
"newcap" : true,
"noarg" : true,
"noempty" : true,
"nonew" : true,
"quotmark" : "single",
"plusplus" : false,
"undef" : true,
"unused" : true,
"strict" : true,
"trailing" : true,
"white" : true,
"browser" : true,
"globals" : {
"jQuery" : true
}
}
6 changes: 4 additions & 2 deletions app/js/3rd/jquery.min.js

Large diffs are not rendered by default.

18 changes: 8 additions & 10 deletions app/js/components/lib_core.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*global TAFFY, window*/
(function (window) {
/*global window*/
(function (window, $) {
'use strict';

function AudicaCoreError(message) {
Expand Down Expand Up @@ -94,8 +94,6 @@
'!is': timestamp
}
}).remove();

this.trigger('collectSongs');
};

Audica.prototype.updateSongList = function () {
Expand All @@ -108,8 +106,8 @@
Audica.prototype.backgroundTasks = function () {
this.view.updateProgress();
this.view.updateTimings();
if (this.plugins['scrobbler']) {
this.plugins['scrobbler'].scrobbleSong();
if (this.plugins.scrobbler) {
this.plugins.scrobbler.scrobbleSong();
}
};

Expand All @@ -132,15 +130,15 @@
window.bindKeyEvents(this);

this.on('INFO', function (args) {
console.log(args.message);
window.console.log(args.message);
});

this.on('ERROR', function (error) {
console.error(error.stack);
window.console.error(error.stack);
});

this.on('WARN', function (args) {
console.warn(args.message);
window.console.warn(args.message);
});

this.on('readyCollectingSongs', function (args) {
Expand Down Expand Up @@ -219,4 +217,4 @@

window.Audica = new Audica();

}(window));
}(window, jQuery));
41 changes: 26 additions & 15 deletions app/js/components/lib_db.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
function Db() {
var _dbName = null;
this.query = null;
this.lock = false;

this.setDbName = function (dbName) {
_dbName = dbName;
Expand All @@ -15,15 +16,23 @@
};
}

Db.prototype.save = function (db) {
var serializedDb = JSON.stringify(db),
Db.prototype.save = function () {
var db = this;
this.lock = true;
var dbContent = this.query().order('artist asec, album asec, year asec, track asec, title asec').get();
this.query().remove();
this.query.insert(dbContent);
var serializedDb = JSON.stringify(dbContent),
dbName = this.getDbName();

root.Audica.plugins.fileSystem.writeFile(
dbName,
new Blob([serializedDb], {
type: 'text/plain'
})
}),
function(){
db.lock = false;
}
);
};

Expand All @@ -46,27 +55,29 @@
_db.query.settings({
cacheSize: 10000,
onDBChange: function () {
var dbContent = this;
if (null !== _timeout) {
clearTimeout(_timeout);
if(false === _db.lock){
if (null !== _timeout) {
clearTimeout(_timeout);
}
_timeout = window.setTimeout(function () {
_db.save();
}, 1000);
}
_timeout = window.setTimeout(function () {
_db.save(dbContent);
}, 1000);
}
});
}, function () {
_db.query = TAFFY();
_db.query.settings({
cacheSize: 10000,
onDBChange: function () {
var dbContent = this;
if (null !== _timeout) {
clearTimeout(_timeout);
if(false === _db.lock){
if (null !== _timeout) {
clearTimeout(_timeout);
}
_timeout = window.setTimeout(function () {
_db.save();
}, 1000);
}
_timeout = window.setTimeout(function () {
_db.save(dbContent);
}, 1000);
}
});
});
Expand Down
4 changes: 1 addition & 3 deletions app/js/components/lib_keys.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@
if (bindKeysToView[args.to]) {
bindKeysToView[args.to].call(this);
if (args.to === 'search' && dom.songBox.find('li').length === 0) {
var currentSongList = Audica.songDb.query().order('artist asec, album asec, year asec, track asec, title asec').get();
// TODO listen for event in seperate plugin
Audica.view.fillSongBox(currentSongList);
Audica.trigger('fillSongBox');
}
}
});
Expand Down
81 changes: 54 additions & 27 deletions app/js/components/lib_view.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
/*global Audica:true, XMLHttpRequest:true, console:true, window, chrome*/
(function(window, Audica) {
/*global Audica*/
(function (window, Audica, $) {
'use strict';

function AudicaViewError(message) {
this.message = (message || '');
}

AudicaViewError.prototype = new Error();

//private
Expand All @@ -29,7 +30,7 @@


//module
function View(){
function View() {
this.closePlayerControlViewTimerId = null;
this.resizeEventTimeoutId = null;

Expand Down Expand Up @@ -90,7 +91,7 @@
preferencesView: null
};

View.prototype.init = function(){
View.prototype.init = function () {
Audica.on('registerEvents', this.bindEvents.bind(this));
for (var selector in this.Dom) {
if (this.Dom.hasOwnProperty(selector)) {
Expand Down Expand Up @@ -121,8 +122,27 @@
};

View.prototype.setSongAsFirstPlaylistElement = function (song) {
var li = $('<li data-song="' + escape(JSON.stringify(song)) + '"><span>' + song.artist + '</span>g / <span>' + song.album + '</span> / <span>' + song.track + '.</span> <span>' + song.title + '</span></li>');
this.setFirstPlaylistElement(li);
var li = [
'<li data-song-id="',
song.___id,
'">',
'<span>',
this.encodeHtml(song.artist),
'</span> / ',
'<span>',
this.encodeHtml(song.album),
'</span> / ',
'<span>',
this.encodeHtml(song.track),
'.</span> ',
'<span>',
this.encodeHtml(song.title),
'</span>',
'</li>'
];

var $li = $(li.join(''));
this.setFirstPlaylistElement($li);
};

View.prototype.clearPlaylist = function () {
Expand Down Expand Up @@ -155,30 +175,36 @@
Audica.trigger('firstPlayListElementRemoved');
};

View.prototype.updateMainView = function (artist, album, title) {
View.prototype.updateMainView = function (song) {
var title = song.title,
album = song.album,
artist = song.artist;

this.Dom.title.text(title);
this.Dom.album.text(album);
this.Dom.artist.text(artist);
Audica.trigger('updateMainView');
};

View.prototype.fillSongBox = function (songs) {
var lis = [],
i = 0,
length = songs.length,
song;
for (i; i < length; i++) {
song = songs[i];
var li = [];
li.push('<li data-song-id="' + escape(song.___id) + '">');
li.push('<span class="artist" data-value="' + escape(song.artist) + '">' + this.encodeHtml(song.artist) + '</span> / ');
li.push('<span class="album" data-value="' + escape(song.album) + '">' + this.encodeHtml(song.album) + '</span> / ');
li.push('<span class="track" data-value="' + escape(song.track) + '">' + this.encodeHtml(song.track) + '.</span>');
li.push('<span class="title" data-value="' + escape(song.title) + '">' + this.encodeHtml(song.title) + '</span>');
var _this = this,
lis = [];
songs.forEach(function(song, index){
var li = [],
artist = _this.encodeHtml(song.artist),
album = _this.encodeHtml(song.album),
track = _this.encodeHtml(song.track),
title = _this.encodeHtml(song.title);

li.push('<li data-song-id="' + song.___id + '">');
li.push('<span class="artist" data-value="' + artist + '">' + artist + '</span> / ');
li.push('<span class="album" data-value="' + album + '">' + album + '</span> / ');
li.push('<span class="track" data-value="' + track + '">' + track + '.</span>');
li.push('<span class="title" data-value="' + title + '">' + title + '</span>');
li.push('</li>');
lis[i] = li.join('');
}
this.Dom.songBox[0].innerHTML = lis.join('');
lis[index] = li.join('');
});
this.Dom.songBox.html(lis.join(''));
this.bindSongBoxEvents();
};

Expand Down Expand Up @@ -244,7 +270,7 @@
selectedElems.find(currentXClass).attr('positionX', true);
};

View.prototype.bindEvents = function(){
View.prototype.bindEvents = function () {
var _this = this;
$(document).mousemove(function () {
var playerControlView = _this.Dom.playerControlView;
Expand Down Expand Up @@ -391,21 +417,21 @@
});

Audica.on('fillSongBox', function () {
var currentSongList = Audica.songDb.query().order('artist logical, album logical, year logical, track logical, title logical').limit(15).get();
var currentSongList = Audica.songDb.query().get();
_this.fillSongBox(currentSongList);
});

Audica.on('domElementsSet', this.applyCoverArtStyle.bind(this));
Audica.on('nextSong', this.applyCoverArtStyle.bind(this));
Audica.on('previousSong', this.applyCoverArtStyle.bind(this));
Audica.on('playSong', this.updateMainView.bind(this));

$(window).on('resize', function () {
window.clearTimeout(self.resizeEventTimeoutId);
window.clearTimeout(_this.resizeEventTimeoutId);
_this.resizeEventTimeoutId = window.setTimeout(_this.applyCoverArtStyle.bind(_this), 250);
});
};

var encodeDecodeElement = $('<div />');
View.prototype.encodeHtml = function (string) {
if (typeof string === 'string') {
return string.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
Expand All @@ -414,6 +440,7 @@
}
};

var encodeDecodeElement = $('<div />');
View.prototype.decodeHtml = function (string) {
if (typeof string === 'string') {
return encodeDecodeElement.html(string).text();
Expand All @@ -423,4 +450,4 @@
};

Audica.view = new View();
}(window, Audica));
}(window, Audica, jQuery));
11 changes: 7 additions & 4 deletions app/js/plugins/lib_fileSystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,12 +125,15 @@
}
};

function writeFileInDirectory(directory, filePath, fileBlob) {
function writeFileInDirectory(directory, filePath, fileBlob, successCallback) {
directory.getFile(filePath, {
create: true
}, function(fileEntry) {
fileEntry.createWriter(function(fileWriter) {
fileWriter.onwriteend = function() {
if(typeof successCallback === 'function'){
successCallback();
}
Audica.trigger('INFO', {
message: 'Writing file ' + filePath + ' completed.'
});
Expand All @@ -153,17 +156,17 @@
});
}

this.writeFile = function(filePath, fileBlob) {
this.writeFile = function(filePath, fileBlob, successCallback) {
if (_isCordova) {
window.resolveLocalFileSystemURL(cordova.file.dataDirectory, function(directory) {
writeFileInDirectory(directory, filePath, fileBlob);
writeFileInDirectory(directory, filePath, fileBlob, successCallback);
}, function(error) {
Audica.trigger('ERROR', {
message: error
});
});
} else {
writeFileInDirectory(fileSystem.root, filePath, fileBlob);
writeFileInDirectory(fileSystem.root, filePath, fileBlob, successCallback);
}
};

Expand Down
Loading

0 comments on commit 3e90c8b

Please sign in to comment.