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:
parent
a00ca9e12b
commit
1a830d6cef
9 changed files with 74 additions and 40 deletions
|
@ -1,7 +1,8 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
/* Declare app level module */
|
/* 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) {
|
jamstash.config(function ($routeProvider) {
|
||||||
$routeProvider
|
$routeProvider
|
||||||
|
|
|
@ -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 = [
|
this.SearchTypes = [
|
||||||
{ id: "song", name: "Song" },
|
{ id: "song", name: "Song" },
|
||||||
{ id: "album", name: "Album" },
|
{ id: "album", name: "Album" },
|
||||||
|
@ -62,9 +67,11 @@ jamstash.service('globals', function () {
|
||||||
|
|
||||||
this.BaseURL = function () { return this.settings.Server + '/rest'; };
|
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; };
|
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 {
|
return {
|
||||||
getCollections: function (callback) {
|
getCollections: function (callback) {
|
||||||
$http.get('js/json_collections.js').success(callback);
|
$http.get('js/json_collections.js').success(callback);
|
||||||
|
|
|
@ -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.Index = function (name, artist) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.artist = artist;
|
this.artist = artist;
|
||||||
|
@ -49,9 +55,11 @@ jamstash.service('model', function (utils) {
|
||||||
this.description = description;
|
this.description = description;
|
||||||
this.displayName = this.name + " - " + this.album + " - " + this.artist;
|
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) {
|
this.mapArtist = function (data) {
|
||||||
var name = '';
|
var name = '';
|
||||||
var artist = data.artist;
|
var artist = data.artist;
|
||||||
|
|
|
@ -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;
|
var msgIndex = 1;
|
||||||
this.updateMessage = function (msg, autohide) {
|
this.updateMessage = function (msg, autohide) {
|
||||||
if (msg != '') {
|
if (msg !== '') {
|
||||||
var id = msgIndex;
|
var id = msgIndex;
|
||||||
$('#messages').append('<span id=\"msg_' + id + '\" class="message">' + msg + '</span>');
|
$('#messages').append('<span id=\"msg_' + id + '\" class="message">' + msg + '</span>');
|
||||||
$('#messages').fadeIn();
|
$('#messages').fadeIn();
|
||||||
|
@ -23,34 +27,34 @@ jamstash.service('notifications', function ($rootScope, globals) {
|
||||||
}
|
}
|
||||||
msgIndex++;
|
msgIndex++;
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
this.requestPermissionIfRequired = function () {
|
this.requestPermissionIfRequired = function () {
|
||||||
if (window.Notify.isSupported() && window.Notify.needsPermission()) {
|
if (window.Notify.isSupported() && window.Notify.needsPermission()) {
|
||||||
window.Notify.requestPermission();
|
window.Notify.requestPermission();
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
this.hasNotificationPermission = function () {
|
this.hasNotificationPermission = function () {
|
||||||
return (window.Notify.needsPermission() === false);
|
return (window.Notify.needsPermission() === false);
|
||||||
}
|
};
|
||||||
this.hasNotificationSupport = function () {
|
this.hasNotificationSupport = function () {
|
||||||
return window.Notify.isSupported();
|
return window.Notify.isSupported();
|
||||||
}
|
};
|
||||||
var notifications = new Array();
|
var notifications = [];
|
||||||
|
|
||||||
this.showNotification = function (pic, title, text, type, bind) {
|
this.showNotification = function (pic, title, text, type, bind) {
|
||||||
if (this.hasNotificationPermission()) {
|
if (this.hasNotificationPermission()) {
|
||||||
//closeAllNotifications()
|
//closeAllNotifications()
|
||||||
var settings = {}
|
var settings = {};
|
||||||
if (bind = '#NextTrack') {
|
if (bind = '#NextTrack') {
|
||||||
settings.notifyClick = function () {
|
settings.notifyClick = function () {
|
||||||
$rootScope.nextTrack();
|
$rootScope.nextTrack();
|
||||||
this.close();
|
this.close();
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
if (type == 'text') {
|
if (type === 'text') {
|
||||||
settings.body = text;
|
settings.body = text;
|
||||||
settings.icon = pic;
|
settings.icon = pic;
|
||||||
} else if (type == 'html') {
|
} else if (type === 'html') {
|
||||||
settings.body = text;
|
settings.body = text;
|
||||||
}
|
}
|
||||||
var notification = new Notify(title, settings);
|
var notification = new Notify(title, settings);
|
||||||
|
@ -62,10 +66,10 @@ jamstash.service('notifications', function ($rootScope, globals) {
|
||||||
} else {
|
} else {
|
||||||
console.log("showNotification: No Permission");
|
console.log("showNotification: No Permission");
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
this.closeAllNotifications = function () {
|
this.closeAllNotifications = function () {
|
||||||
for (notification in notifications) {
|
for (var notification in notifications) {
|
||||||
notifications[notification].close();
|
notifications[notification].close();
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
});
|
});
|
|
@ -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 index = { shortcuts: [], artists: [] };
|
||||||
var content = {
|
var content = {
|
||||||
album: [],
|
album: [],
|
||||||
|
|
|
@ -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) {
|
this.safeApply = function (fn) {
|
||||||
var phase = $rootScope.$root.$$phase;
|
var phase = $rootScope.$root.$$phase;
|
||||||
if (phase === '$apply' || phase === '$digest') {
|
if (phase === '$apply' || phase === '$digest') {
|
||||||
|
|
|
@ -3,7 +3,7 @@ describe("globals service", function() {
|
||||||
|
|
||||||
var globals;
|
var globals;
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
module('JamStash');
|
module('jamstash.globals');
|
||||||
inject(function (_globals_) {
|
inject(function (_globals_) {
|
||||||
globals = _globals_;
|
globals = _globals_;
|
||||||
});
|
});
|
||||||
|
|
|
@ -2,10 +2,12 @@ describe("model service", function() {
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var model;
|
var model;
|
||||||
beforeEach(module('JamStash'));
|
beforeEach(function() {
|
||||||
beforeEach(inject(function(_model_) {
|
module('jamstash.model');
|
||||||
model = _model_;
|
inject(function (_model_) {
|
||||||
}));
|
model = _model_;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
it("given a name and artist, when calling Index() then the model name and artist are changed", function() {
|
it("given a name and artist, when calling Index() then the model name and artist are changed", function() {
|
||||||
model.Index("CoolAlbum", "HipArtist");
|
model.Index("CoolAlbum", "HipArtist");
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
describe("subsonic service -", function() {
|
describe("Subsonic service -", function() {
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var subsonic, mockBackend, mockGlobals;
|
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);
|
$provide.value('globals', mockGlobals);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue