fix for admin api

This commit is contained in:
Athou
2013-04-18 12:50:44 +02:00
parent 9bd825d786
commit af109ccf5c
30 changed files with 1000 additions and 861 deletions

View File

@@ -30,7 +30,7 @@
apiKey:"",
dom_id:"swagger-ui-container",
supportHeaderParams: false,
supportedSubmitMethods: ['get', 'post', 'put'],
supportedSubmitMethods: ['get', 'post', 'put', 'delete'],
onComplete: function(swaggerApi, swaggerUi){
if(console) {
console.log("Loaded SwaggerUI")

View File

@@ -16,7 +16,8 @@ module.run(function($rootScope) {
});
});
module.controller('SubscribeCtrl', function($scope, SubscriptionService) {
module.controller('SubscribeCtrl', function($scope, FeedService,
CategoryService) {
$scope.opts = {
backdropFade : true,
@@ -27,7 +28,7 @@ module.controller('SubscribeCtrl', function($scope, SubscriptionService) {
$scope.isOpenImport = false;
$scope.sub = {};
$scope.SubscriptionService = SubscriptionService;
$scope.CategoryService = CategoryService;
$scope.open = function() {
$scope.sub = {};
@@ -42,7 +43,7 @@ module.controller('SubscribeCtrl', function($scope, SubscriptionService) {
var msg = 'Loading...';
if ($scope.sub.url && (!$scope.sub.title || $scope.sub.title == msg)) {
$scope.sub.title = msg;
SubscriptionService.fetch({
FeedService.fetch({
url : $scope.sub.url
}, function(data) {
$scope.sub.title = data.title;
@@ -52,7 +53,9 @@ module.controller('SubscribeCtrl', function($scope, SubscriptionService) {
};
$scope.save = function() {
SubscriptionService.subscribe($scope.sub);
FeedService.subscribe($scope.sub, function() {
CategoryService.init();
});
$scope.close();
};
@@ -65,7 +68,7 @@ module.controller('SubscribeCtrl', function($scope, SubscriptionService) {
};
$scope.uploadComplete = function(contents, completed) {
SubscriptionService.init();
CategoryService.init();
$scope.closeImport();
};
@@ -81,13 +84,13 @@ module.controller('SubscribeCtrl', function($scope, SubscriptionService) {
};
$scope.saveCategory = function() {
SubscriptionService.addCategory($scope.cat);
CategoryService.add($scope.cat);
$scope.closeCategory();
};
});
module.controller('CategoryTreeCtrl', function($scope, $timeout, $stateParams,
$window, $location, $state, $route, SubscriptionService) {
$window, $location, $state, $route, CategoryService) {
$scope.selectedType = $stateParams._type;
$scope.selectedId = $stateParams._id;
@@ -98,12 +101,12 @@ module.controller('CategoryTreeCtrl', function($scope, $timeout, $stateParams,
});
$timeout(function refreshTree() {
SubscriptionService.init(function() {
CategoryService.init(function() {
$timeout(refreshTree, 15000);
});
}, 15000);
$scope.SubscriptionService = SubscriptionService;
$scope.CategoryService = CategoryService;
$scope.unreadCount = function(category) {
var count = 0;
@@ -123,7 +126,7 @@ module.controller('CategoryTreeCtrl', function($scope, $timeout, $stateParams,
};
var rootUnreadCount = function() {
return $scope.unreadCount($scope.SubscriptionService.subscriptions);
return $scope.unreadCount($scope.CategoryService.subscriptions);
};
$scope.$watch(rootUnreadCount, function(value) {
@@ -192,20 +195,19 @@ module.controller('CategoryTreeCtrl', function($scope, $timeout, $stateParams,
};
$scope.$on('mark', function(event, args) {
mark($scope.SubscriptionService.subscriptions, args.entry);
mark($scope.CategoryService.subscriptions, args.entry);
});
});
module.controller('ToolbarCtrl',
function($scope, $http, $state, $stateParams, $route, $location,
SettingsService, EntryService, SubscriptionService,
SessionService) {
SettingsService, EntryService, ProfileService) {
function totalActiveAjaxRequests() {
return ($http.pendingRequests.length + $.active);
}
$scope.session = SessionService.get();
$scope.session = ProfileService.get();
$scope.loading = true;
$scope.$watch(totalActiveAjaxRequests, function() {
@@ -271,7 +273,7 @@ module.controller('ToolbarCtrl',
});
module.controller('FeedListCtrl', function($scope, $stateParams, $http, $route,
$window, EntryService, SettingsService, SubscriptionService) {
$window, EntryService, SettingsService, FeedService, CategoryService) {
$scope.selectedType = $stateParams._type;
$scope.selectedId = $stateParams._id;
@@ -327,8 +329,9 @@ module.controller('FeedListCtrl', function($scope, $stateParams, $http, $route,
$scope.hasMore = data.entries.length == limit;
};
if (!$scope.keywords) {
EntryService.get({
type : $scope.selectedType,
var service = $scope.selectedType == 'feed' ? FeedService
: CategoryService;
service.entries({
id : $scope.selectedId,
readType : $scope.settingsService.settings.readingMode,
order : $scope.settingsService.settings.readingOrder,
@@ -351,7 +354,6 @@ module.controller('FeedListCtrl', function($scope, $stateParams, $http, $route,
entry : entry
});
EntryService.mark({
type : 'entry',
id : entry.id,
read : read
});
@@ -442,13 +444,14 @@ module.controller('FeedListCtrl', function($scope, $stateParams, $http, $route,
});
$scope.$on('markAll', function(event, args) {
EntryService.mark({
type : $scope.selectedType,
var service = $scope.selectedType == 'feed' ? FeedService
: CategoryService;
service.mark({
id : $scope.selectedId,
olderThan : $scope.timestamp,
read : true
}, function() {
SubscriptionService.init(function() {
CategoryService.init(function() {
$scope.$emit('emitReload');
});
});
@@ -559,8 +562,8 @@ module.controller('SettingsCtrl', function($scope, $location, SettingsService) {
};
});
module.controller('ProfileCtrl', function($scope, $location, SessionService) {
$scope.user = SessionService.get();
module.controller('ProfileCtrl', function($scope, $location, ProfileService) {
$scope.user = ProfileService.get();
$scope.cancel = function() {
$location.path('/');
@@ -574,7 +577,7 @@ module.controller('ProfileCtrl', function($scope, $location, SessionService) {
password : $scope.user.password
};
SessionService.save(o, function() {
ProfileService.save(o, function() {
$location.path('/');
});

View File

@@ -86,7 +86,7 @@ module.directive('category', function($compile) {
restrict : 'E',
replace : true,
templateUrl : 'directives/category.html',
controller : function($scope, $dialog, SubscriptionService,
controller : function($scope, $dialog, FeedService, CategoryService,
SettingsService) {
$scope.settingsService = SettingsService;
$scope.unsubscribe = function(subscription) {
@@ -104,8 +104,12 @@ module.directive('category', function($compile) {
$dialog.messageBox(title, msg, btns).open().then(
function(result) {
if (result == 'ok') {
SubscriptionService
.unsubscribe(subscription.id);
var data = {
id : subscription.id
};
FeedService.unsubscribe(data, function() {
CategoryService.init();
});
}
});
};
@@ -114,7 +118,7 @@ module.directive('category', function($compile) {
var name = window.prompt('Rename feed : ', feed.name);
if (name && name != feed.name) {
feed.name = name;
SubscriptionService.rename({
FeedService.rename({
id : feed.id,
name : name
});
@@ -125,7 +129,7 @@ module.directive('category', function($compile) {
var name = window.prompt('Rename category: ', category.name);
if (name && name != category.name) {
category.name = name;
SubscriptionService.renameCategory({
CategoryService.rename({
id : category.id,
name : name
});
@@ -147,10 +151,10 @@ module.directive('category', function($compile) {
$dialog.messageBox(title, msg, btns).open().then(
function(result) {
if (result == 'ok') {
SubscriptionService.deleteCategory({
CategoryService.remove({
id : category.id
}, function() {
SubscriptionService.init();
CategoryService.init();
});
}
});
@@ -158,7 +162,10 @@ module.directive('category', function($compile) {
$scope.toggleCategory = function(category) {
category.expanded = !category.expanded;
SubscriptionService.collapse({
if (category.id == 'all') {
return;
}
CategoryService.collapse({
id : category.id,
collapse : !category.expanded
});

View File

@@ -1,24 +1,78 @@
var module = angular.module('commafeed.services', [ 'ngResource' ]);
module.factory('SessionService', function($resource) {
var actions = {
get : {
method : 'GET',
params : {
_method : 'get'
}
},
save : {
method : 'POST',
params : {
_method : 'save'
}
}
};
return $resource('rest/session/:_method', {}, actions);
module.factory('ProfileService', function($resource) {
return $resource('rest/user/profile/');
});
module.factory('SubscriptionService', function($resource, $http) {
module.factory('SettingsService', function($resource) {
var res = $resource('rest/user/settings');
var s = {};
s.settings = {};
s.save = function(callback) {
res.save(s.settings, function(data) {
if (callback) {
callback(data);
}
});
};
s.init = function(callback) {
res.get(function(data) {
s.settings = data;
if (callback) {
callback(data);
}
});
};
s.init();
return s;
});
module.factory('FeedService', function($resource, $http) {
var actions = {
entries : {
method : 'GET',
params : {
_method : 'entries'
}
},
fetch : {
method : 'GET',
params : {
_method : 'fetch'
}
},
mark : {
method : 'POST',
params : {
_method : 'mark'
}
},
subscribe : {
method : 'POST',
params : {
_method : 'subscribe'
}
},
unsubscribe : {
method : 'POST',
params : {
_method : 'unsubscribe'
}
},
rename : {
method : 'POST',
params : {
_method : 'rename'
}
}
};
var res = $resource('rest/feed/:_method', {}, actions);
return res;
});
module.factory('CategoryService', function($resource, $http) {
var flatten = function(category, parentName, array) {
if (!array)
@@ -39,131 +93,72 @@ module.factory('SubscriptionService', function($resource, $http) {
return array;
};
var actions = {
fetch : {
get : {
method : 'GET',
params : {
_type : 'feed',
_method : 'fetch'
_method : 'get'
}
},
subscribe : {
method : 'POST',
entries : {
method : 'GET',
params : {
_type : 'feed',
_method : 'subscribe'
_method : 'entries'
}
},
unsubscribe : {
mark : {
method : 'POST',
params : {
_type : 'feed',
_method : 'unsubscribe'
_method : 'mark'
}
},
add : {
method : 'POST',
params : {
_method : 'add'
}
},
remove : {
method : 'POST',
params : {
_method : 'delete'
}
},
rename : {
method : 'POST',
params : {
_type : 'feed',
_method : 'rename'
}
},
collapse : {
method : 'POST',
params : {
_type : 'category',
_method : 'collapse'
}
},
addCategory : {
method : 'POST',
params : {
_type : 'category',
_method : 'add'
}
},
deleteCategory : {
method : 'POST',
params : {
_type : 'category',
_method : 'delete'
}
},
renameCategory : {
method : 'POST',
params : {
_type : 'category',
_method : 'rename'
}
}
};
var s = {};
s.get = $resource('rest/subscriptions/get').get;
s.subscriptions = {};
s.flatCategories = {};
var res = $resource('rest/category/:_method', {}, actions);
res.subscriptions = {};
res.flatCategories = {};
var res = $resource('rest/subscriptions/:_type/:_method', {}, actions);
s.init = function(callback) {
s.get(function(data) {
s.subscriptions = data;
s.flatCategories = flatten(s.subscriptions);
if (callback)
callback(data);
});
};
s.fetch = res.fetch;
s.rename = res.rename;
s.subscribe = function(sub, callback) {
res.subscribe(sub, function(data) {
s.init();
res.init = function(callback) {
res.get(function(data) {
res.subscriptions = data;
res.flatCategories = flatten(data);
if (callback)
callback(data);
});
};
var removeSubscription = function(node, subId) {
if (node.children) {
$.each(node.children, function(k, v) {
removeSubscription(v, subId);
});
}
if (node.feeds) {
var foundAtIndex = -1;
$.each(node.feeds, function(k, v) {
if (v.id == subId) {
foundAtIndex = k;
}
});
if (foundAtIndex > -1) {
node.feeds.splice(foundAtIndex, 1);
}
}
};
s.unsubscribe = function(id) {
removeSubscription(s.subscriptions, id);
res.unsubscribe({
id : id
});
};
s.addCategory = function(cat, callback) {
res.addCategory(cat, function(data) {
s.init();
if (callback)
callback(data);
});
};
s.deleteCategory = res.deleteCategory;
s.collapse = res.collapse;
s.init();
return s;
res.init();
return res;
});
module.factory('EntryService', function($resource, $http) {
var actions = {
get : {
search : {
method : 'GET',
params : {
_method : 'get'
_method : 'search'
}
},
mark : {
@@ -173,80 +168,20 @@ module.factory('EntryService', function($resource, $http) {
}
}
};
var res = $resource('rest/entries/:type/:_method', {}, actions);
res.search = $resource('rest/entries/search', {}, actions).get;
var res = $resource('rest/entry/:_method', {}, actions);
return res;
});
module.factory('SettingsService', function($resource) {
var s = {};
s.settings = {};
s.save = function(callback) {
$resource('rest/settings/save').save(s.settings, function(data) {
if (callback) {
callback(data);
}
});
};
s.init = function(callback) {
$resource('rest/settings/get').get(function(data) {
s.settings = data;
if (callback) {
callback(data);
}
});
};
s.init();
return s;
});
module.factory('AdminUsersService', function($resource) {
var actions = {
get : {
method : 'GET',
params : {
_method : 'get'
}
},
getAll : {
method : 'GET',
params : {
_method : 'getAll'
},
isArray : true
},
save : {
method : 'POST',
params : {
_method : 'save'
}
},
remove : {
method : 'POST',
params : {
_method : 'delete'
}
}
};
var res = $resource('rest/admin/user/:_method', {}, actions);
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;
return res;
});
module.factory('AdminSettingsService', function($resource) {
var actions = {
get : {
method : 'GET',
params : {
_method : 'get'
}
},
save : {
method : 'POST',
params : {
_method : 'save'
}
}
};
var res = $resource('rest/admin/settings/:_method', {}, actions);
var res = $resource('rest/admin/settings/');
return res;
});

View File

@@ -34,7 +34,7 @@
<label class="control-label">Category</label>
<div class="controls">
<select name="category" ng-model="sub.categoryId" class="input-block-level" required>
<option ng-repeat="cat in SubscriptionService.flatCategories" value="{{cat.id}}">{{cat.name}}</option>
<option ng-repeat="cat in CategoryService.flatCategories" value="{{cat.id}}">{{cat.name}}</option>
</select>
<span class="help-block" ng-show="!subscribeForm.category.$valid">Required</span>
</div>
@@ -51,7 +51,7 @@
<button type="button" class="close" ng-click="closeImport()">&times;</button>
<h4>Import</h4>
</div>
<form ng-upload class="form-horizontal" action="rest/subscriptions/import">
<form ng-upload class="form-horizontal" action="rest/feed/import">
<div class="modal-body">
<div class="control-group">
<div>Let me import your feeds from your
@@ -93,7 +93,7 @@
<label class="control-label">Parent</label>
<div class="controls">
<select name="category" ng-model="cat.parentId" class="input-block-level" required>
<option ng-repeat="cat in SubscriptionService.flatCategories" value="{{cat.id}}">{{cat.name}}</option>
<option ng-repeat="cat in CategoryService.flatCategories" value="{{cat.id}}">{{cat.name}}</option>
</select>
<span class="help-block" ng-show="!categoryForm.category.$valid">Required</span>
</div>

View File

@@ -1,6 +1,6 @@
<div class="css-treeview" ng-controller="CategoryTreeCtrl">
<ul>
<category node="SubscriptionService.subscriptions"
<category node="CategoryService.subscriptions"
feed-click="feedClicked(id)" category-click="categoryClicked(id)"
selected-type="selectedType" selected-id="selectedId"
format-category-name="formatCategoryName(category)"