Splits all the services into different jamstash.* modules.

That way dependencies are actually visible and can be managed
e.g. Jamstash doesn't depend upon underscore directly anymore, it's just the subsonic service that needs it.
This commit is contained in:
Hyzual 2014-11-06 22:19:55 +01:00
parent a00ca9e12b
commit 1a830d6cef
9 changed files with 74 additions and 40 deletions

View file

@ -1,7 +1,8 @@
'use strict';
/* Declare app level module */
var jamstash = angular.module('JamStash', ['ngCookies', 'ngRoute', 'ngSanitize', 'angular-underscore/utils']);
var jamstash = angular.module('JamStash', ['ngCookies', 'ngRoute', 'ngSanitize',
'jamstash.subsonicService']);
jamstash.config(function ($routeProvider) {
$routeProvider

View file

@ -1,8 +1,13 @@
'use strict';
/**
* jamstash.globals Module
*
* Houses Jamstash's global settings and a few utility functions.
*/
angular.module('jamstash.globals', [])
var jamstash = angular.module('JamStash');
.service('globals', function () {
'use strict';
jamstash.service('globals', function () {
this.SearchTypes = [
{ id: "song", name: "Song" },
{ id: "album", name: "Album" },
@ -62,9 +67,11 @@ jamstash.service('globals', function () {
this.BaseURL = function () { return this.settings.Server + '/rest'; };
this.BaseParams = function () { return 'u=' + this.settings.Username + '&p=' + this.settings.Password + '&f=' + this.settings.Protocol + '&v=' + this.settings.ApiVersion + '&c=' + this.settings.ApplicationName; };
});
})
.factory('json', function ($http) { // Deferred loading
'use strict';
jamstash.factory('json', function ($http) { // Deferred loading
return {
getCollections: function (callback) {
$http.get('js/json_collections.js').success(callback);

View file

@ -1,8 +1,14 @@
'use strict';
/**
* jamstash.model Module
*
* Stores the Index, Artist, Album and Song model. Provides a mapping service that converts between subsonic's
* representation and ours.
*/
angular.module('jamstash.model', ['jamstash.utils'])
var jamstash = angular.module('JamStash');
.service('model', function (utils) {
'use strict';
jamstash.service('model', function (utils) {
this.Index = function (name, artist) {
this.name = name;
this.artist = artist;
@ -49,9 +55,11 @@ jamstash.service('model', function (utils) {
this.description = description;
this.displayName = this.name + " - " + this.album + " - " + this.artist;
};
});
})
.service('map', function ($http, globals, utils, model) {
'use strict';
jamstash.service('map', function ($http, globals, utils, model) {
this.mapArtist = function (data) {
var name = '';
var artist = data.artist;

View file

@ -1,11 +1,15 @@
'use strict';
/**
* jamstash.notifications Module
*
* Provides access to the notification UI.
*/
angular.module('jamstash.notifications', [])
.service('notifications', function ($rootScope, globals) {
'use strict';
var jamstash = angular.module('JamStash');
jamstash.service('notifications', function ($rootScope, globals) {
var msgIndex = 1;
this.updateMessage = function (msg, autohide) {
if (msg != '') {
if (msg !== '') {
var id = msgIndex;
$('#messages').append('<span id=\"msg_' + id + '\" class="message">' + msg + '</span>');
$('#messages').fadeIn();
@ -23,34 +27,34 @@ jamstash.service('notifications', function ($rootScope, globals) {
}
msgIndex++;
}
}
};
this.requestPermissionIfRequired = function () {
if (window.Notify.isSupported() && window.Notify.needsPermission()) {
window.Notify.requestPermission();
}
}
};
this.hasNotificationPermission = function () {
return (window.Notify.needsPermission() === false);
}
};
this.hasNotificationSupport = function () {
return window.Notify.isSupported();
}
var notifications = new Array();
};
var notifications = [];
this.showNotification = function (pic, title, text, type, bind) {
if (this.hasNotificationPermission()) {
//closeAllNotifications()
var settings = {}
var settings = {};
if (bind = '#NextTrack') {
settings.notifyClick = function () {
$rootScope.nextTrack();
this.close();
};
}
if (type == 'text') {
if (type === 'text') {
settings.body = text;
settings.icon = pic;
} else if (type == 'html') {
} else if (type === 'html') {
settings.body = text;
}
var notification = new Notify(title, settings);
@ -62,10 +66,10 @@ jamstash.service('notifications', function ($rootScope, globals) {
} else {
console.log("showNotification: No Permission");
}
}
};
this.closeAllNotifications = function () {
for (notification in notifications) {
for (var notification in notifications) {
notifications[notification].close();
}
}
};
});

View file

@ -1,8 +1,15 @@
'use strict';
/**
* jamstash.subsonicService Module
*
* Provides access through $http to the Subsonic server's API.
* Also offers more fine-grained functionality that is not part of Subsonic's API.
*/
angular.module('jamstash.subsonicService', ['jamstash.globals', 'jamstash.utils', 'jamstash.model',
'jamstash.notifications', 'angular-underscore/utils'])
var Jamstash = angular.module('JamStash');
.factory('subsonic', function ($rootScope, $http, $q, globals, utils, map, notifications) {
'use strict';
Jamstash.factory('subsonic', function ($rootScope, $http, $q, globals, utils, map, notifications) {
var index = { shortcuts: [], artists: [] };
var content = {
album: [],

View file

@ -1,8 +1,13 @@
'use strict';
/**
* jamstash.utils Module
*
* Provides generally useful functions, like sorts, date-related functions, localStorage access, etc.
*/
angular.module('jamstash.utils', ['jamstash.globals'])
var jamstash = angular.module('JamStash');
.service('utils', function ($rootScope, globals) {
'use strict';
jamstash.service('utils', function ($rootScope, $cookieStore, globals) {
this.safeApply = function (fn) {
var phase = $rootScope.$root.$$phase;
if (phase === '$apply' || phase === '$digest') {

View file

@ -3,7 +3,7 @@ describe("globals service", function() {
var globals;
beforeEach(function() {
module('JamStash');
module('jamstash.globals');
inject(function (_globals_) {
globals = _globals_;
});

View file

@ -2,10 +2,12 @@ describe("model service", function() {
'use strict';
var model;
beforeEach(module('JamStash'));
beforeEach(inject(function(_model_) {
model = _model_;
}));
beforeEach(function() {
module('jamstash.model');
inject(function (_model_) {
model = _model_;
});
});
it("given a name and artist, when calling Index() then the model name and artist are changed", function() {
model.Index("CoolAlbum", "HipArtist");

View file

@ -1,4 +1,4 @@
describe("subsonic service -", function() {
describe("Subsonic service -", function() {
'use strict';
var subsonic, mockBackend, mockGlobals;
@ -24,7 +24,7 @@ describe("subsonic service -", function() {
}
};
module('JamStash', function ($provide) {
module('jamstash.subsonicService', function ($provide) {
$provide.value('globals', mockGlobals);
});