Files
commafeed/src/main/webapp/js/services.js

201 lines
3.8 KiB
JavaScript
Raw Normal View History

2013-03-22 09:29:30 +01:00
var module = angular.module('commafeed.services', [ 'ngResource' ]);
module.service('AnalyticsService', [ '$state', function($state) {
this.track = function(path) {
path = path || $state.$current.url.prefix;
if (!ga) {
return;
}
ga('send', 'pageview', {
page : path
});
};
} ]);
2013-04-22 20:58:18 -05:00
module.factory('ProfileService', ['$resource', function($resource) {
2013-04-18 12:50:44 +02:00
return $resource('rest/user/profile/');
2013-04-22 20:58:18 -05:00
}]);
2013-03-31 08:17:28 +02:00
2013-04-22 20:58:18 -05:00
module.factory('SettingsService', ['$resource', function($resource) {
2013-04-18 12:50:44 +02:00
var res = $resource('rest/user/settings');
2013-03-27 12:13:56 +01:00
2013-04-18 12:50:44 +02:00
var s = {};
s.settings = {};
s.save = function(callback) {
res.save(s.settings, function(data) {
if (callback) {
callback(data);
}
2013-03-31 11:30:52 +02:00
});
2013-04-18 12:50:44 +02:00
};
s.init = function(callback) {
res.get(function(data) {
s.settings = data;
if (callback) {
callback(data);
2013-03-24 13:11:05 +01:00
}
2013-04-18 12:50:44 +02:00
});
2013-03-31 11:30:52 +02:00
};
2013-04-18 12:50:44 +02:00
s.init();
return s;
2013-04-22 20:58:18 -05:00
}]);
2013-04-18 12:50:44 +02:00
2013-04-22 20:58:18 -05:00
module.factory('FeedService', ['$resource', '$http',
function($resource, $http) {
2013-03-31 11:30:52 +02:00
var actions = {
2013-04-18 12:50:44 +02:00
entries : {
method : 'GET',
params : {
_method : 'entries'
}
},
2013-03-31 11:30:52 +02:00
fetch : {
method : 'GET',
params : {
2013-04-16 12:36:36 +02:00
_method : 'fetch'
2013-03-31 11:30:52 +02:00
}
},
2013-04-18 12:50:44 +02:00
mark : {
method : 'POST',
params : {
_method : 'mark'
}
},
2013-03-31 11:30:52 +02:00
subscribe : {
method : 'POST',
params : {
2013-04-16 12:36:36 +02:00
_method : 'subscribe'
2013-03-31 11:30:52 +02:00
}
},
unsubscribe : {
method : 'POST',
2013-03-31 11:30:52 +02:00
params : {
2013-04-16 12:36:36 +02:00
_method : 'unsubscribe'
2013-03-31 11:30:52 +02:00
}
},
2013-04-01 14:30:40 +02:00
rename : {
method : 'POST',
2013-04-01 14:30:40 +02:00
params : {
2013-04-16 12:36:36 +02:00
_method : 'rename'
2013-04-01 14:30:40 +02:00
}
2013-04-18 12:50:44 +02:00
}
};
var res = $resource('rest/feed/:_method', {}, actions);
return res;
2013-04-22 20:58:18 -05:00
}]);
2013-04-18 12:50:44 +02:00
2013-04-22 20:58:18 -05:00
module.factory('CategoryService', ['$resource', '$http',
function($resource, $http) {
2013-04-18 12:50:44 +02:00
var flatten = function(category, parentName, array) {
if (!array)
array = [];
var name = category.name;
if (parentName) {
name += (' (in ' + parentName + ')');
}
array.push({
id : category.id,
name : name
});
if (category.children) {
for ( var i = 0; i < category.children.length; i++) {
flatten(category.children[i], category.name, array);
}
}
return array;
};
var actions = {
get : {
method : 'GET',
params : {
_method : 'get'
}
2013-04-01 14:30:40 +02:00
},
2013-04-18 12:50:44 +02:00
entries : {
method : 'GET',
params : {
_method : 'entries'
}
},
mark : {
method : 'POST',
2013-03-31 11:30:52 +02:00
params : {
2013-04-18 12:50:44 +02:00
_method : 'mark'
2013-03-31 11:30:52 +02:00
}
},
2013-04-18 12:50:44 +02:00
add : {
method : 'POST',
2013-03-31 11:30:52 +02:00
params : {
2013-04-16 12:36:36 +02:00
_method : 'add'
2013-03-31 11:30:52 +02:00
}
},
2013-04-18 12:50:44 +02:00
remove : {
method : 'POST',
2013-03-31 11:30:52 +02:00
params : {
2013-04-16 12:36:36 +02:00
_method : 'delete'
2013-04-16 12:36:18 +02:00
}
},
2013-04-18 12:50:44 +02:00
rename : {
method : 'POST',
2013-04-16 12:36:18 +02:00
params : {
2013-04-16 12:36:36 +02:00
_method : 'rename'
2013-03-31 11:30:52 +02:00
}
2013-04-18 12:50:44 +02:00
},
collapse : {
method : 'POST',
params : {
_method : 'collapse'
}
2013-03-31 11:30:52 +02:00
}
};
2013-04-18 12:50:44 +02:00
var res = $resource('rest/category/:_method', {}, actions);
res.subscriptions = {};
res.flatCategories = {};
2013-03-27 12:13:56 +01:00
2013-04-18 12:50:44 +02:00
res.init = function(callback) {
res.get(function(data) {
res.subscriptions = data;
res.flatCategories = flatten(data);
2013-03-31 11:30:52 +02:00
if (callback)
callback(data);
});
};
2013-04-18 12:50:44 +02:00
res.init();
return res;
2013-04-22 20:58:18 -05:00
}]);
2013-03-22 20:51:22 +01:00
2013-04-22 20:58:18 -05:00
module.factory('EntryService', ['$resource', '$http',
function($resource, $http) {
2013-03-31 11:30:52 +02:00
var actions = {
2013-04-18 12:50:44 +02:00
search : {
2013-03-31 11:30:52 +02:00
method : 'GET',
params : {
2013-04-18 12:50:44 +02:00
_method : 'search'
2013-03-31 11:30:52 +02:00
}
},
mark : {
method : 'POST',
2013-03-31 11:30:52 +02:00
params : {
_method : 'mark'
}
}
};
2013-04-18 12:50:44 +02:00
var res = $resource('rest/entry/:_method', {}, actions);
2013-03-31 11:30:52 +02:00
return res;
2013-04-22 20:58:18 -05:00
}]);
2013-03-23 23:14:14 +01:00
2013-04-22 20:58:18 -05:00
module.factory('AdminUsersService', ['$resource', function($resource) {
2013-04-18 12:50:44 +02:00
var res = {};
res.get = $resource('rest/admin/user/get/:id').get;
res.getAll = $resource('rest/admin/user/getAll').query;
res.save = $resource('rest/admin/user/save').save;
res.remove = $resource('rest/admin/user/delete').save;
2013-03-29 17:17:36 +01:00
return res;
2013-04-22 20:58:18 -05:00
}]);
2013-04-05 16:31:42 +02:00
2013-04-22 20:58:18 -05:00
module.factory('AdminSettingsService', ['$resource', function($resource) {
2013-04-18 12:50:44 +02:00
var res = $resource('rest/admin/settings/');
2013-04-05 16:31:42 +02:00
return res;
2013-04-22 20:58:18 -05:00
}]);