refactored tree, no more dropdown for feed editing

This commit is contained in:
Athou
2013-04-30 16:17:34 +02:00
parent bfde9241eb
commit 2d40c4292c
16 changed files with 444 additions and 121 deletions

View File

@@ -169,6 +169,136 @@ function($scope, $timeout, $stateParams, $window, $location, $state, $route, Cat
});
}]);
module.controller('FeedDetailsCtrl', ['$scope', '$state', '$stateParams', 'FeedService', 'CategoryService', '$dialog',
function($scope, $state, $stateParams, FeedService, CategoryService, $dialog) {
$scope.CategoryService = CategoryService;
$scope.sub = FeedService.get({
id : $stateParams._id
});
$scope.back = function() {
$state.transitionTo('feeds.view', {
_id: $stateParams._id,
_type: 'feed'
});
};
$scope.unsubscribe = function() {
var sub = $scope.sub;
var title = 'Unsubscribe';
var msg = 'Unsubscribe from ' + sub.name + ' ?';
var btns = [ {
result : 'cancel',
label : 'Cancel'
}, {
result : 'ok',
label : 'OK',
cssClass : 'btn-primary'
} ];
$dialog.messageBox(title, msg, btns).open().then(
function(result) {
if (result == 'ok') {
var data = {
id : sub.id
};
FeedService.unsubscribe(data,
function() {
CategoryService.init();
});
$state.transitionTo('feeds.view', {
_id: 'all',
_type: 'category'
});
}
});
};
$scope.save = function() {
var sub = $scope.sub;
FeedService.modify({
id : sub.id,
name : sub.name,
categoryId : sub.categoryId
}, function() {
CategoryService.init();
$state.transitionTo('feeds.view', {
_id: 'all',
_type: 'category'
});
});
};
}]);
module.controller('CategoryDetailsCtrl', ['$scope', '$state', '$stateParams', 'FeedService', 'CategoryService', '$dialog',
function($scope, $state, $stateParams, FeedService, CategoryService, $dialog) {
$scope.CategoryService = CategoryService;
CategoryService.get(function() {
for(var i = 0; i < CategoryService.flatCategories.length; i++){
var cat = CategoryService.flatCategories[i];
if (cat.id == $stateParams._id) {
$scope.category = angular.copy(cat);
$scope.category.name = $scope.category.origName;
break;
}
}
});
$scope.back = function() {
$state.transitionTo('feeds.view', {
_id: $stateParams._id,
_type: 'category'
});
};
$scope.deleteCategory = function() {
var category = $scope.category;
var title = 'Delete category';
var msg = 'Delete category ' + category.name + ' ?';
var btns = [ {
result : 'cancel',
label : 'Cancel'
}, {
result : 'ok',
label : 'OK',
cssClass : 'btn-primary'
} ];
$dialog.messageBox(title, msg, btns).open().then(
function(result) {
if (result == 'ok') {
CategoryService.remove({
id : category.id
}, function() {
CategoryService.init();
});
$state.transitionTo('feeds.view', {
_id: 'all',
_type: 'category'
});
}
});
};
$scope.save = function() {
var cat = $scope.category;
CategoryService.modify({
id : cat.id,
name : cat.name,
parentId : cat.parentId
}, function() {
CategoryService.init();
$state.transitionTo('feeds.view', {
_id: 'all',
_type: 'category'
});
});
};
}]);
module.controller('ToolbarCtrl', ['$scope', '$http', '$state', '$stateParams',
'$route', '$location', 'SettingsService', 'EntryService', 'ProfileService', 'AnalyticsService', 'ServerService', 'FeedService',
function($scope, $http, $state, $stateParams, $route, $location,

View File

@@ -112,32 +112,6 @@ module.directive('category', [ function() {
function($scope, $state, $dialog, FeedService, CategoryService,
SettingsService) {
$scope.settingsService = SettingsService;
$scope.unsubscribe = function(subscription) {
var title = 'Unsubscribe';
var msg = 'Unsubscribe from ' + subscription.name
+ ' ?';
var btns = [ {
result : 'cancel',
label : 'Cancel'
}, {
result : 'ok',
label : 'OK',
cssClass : 'btn-primary'
} ];
$dialog.messageBox(title, msg, btns).open().then(
function(result) {
if (result == 'ok') {
var data = {
id : subscription.id
};
FeedService.unsubscribe(data,
function() {
CategoryService.init();
});
}
});
};
$scope.formatCategoryName = function(category) {
var count = $scope.unreadCount({
@@ -181,52 +155,17 @@ module.directive('category', [ function() {
});
}
};
$scope.renameFeed = function(feed) {
var name = window.prompt('Rename feed : ', feed.name);
if (name && name != feed.name) {
feed.name = name;
FeedService.rename({
id : feed.id,
name : name
});
}
$scope.showFeedDetails = function(feed) {
$state.transitionTo('feeds.feed_details', {
_id: feed.id
});
};
$scope.renameCategory = function(category) {
var name = window.prompt('Rename category: ',
category.name);
if (name && name != category.name) {
category.name = name;
CategoryService.rename({
id : category.id,
name : name
});
}
};
$scope.deleteCategory = function(category) {
var title = 'Delete category';
var msg = 'Delete category ' + category.name + ' ?';
var btns = [ {
result : 'cancel',
label : 'Cancel'
}, {
result : 'ok',
label : 'OK',
cssClass : 'btn-primary'
} ];
$dialog.messageBox(title, msg, btns).open().then(
function(result) {
if (result == 'ok') {
CategoryService.remove({
id : category.id
}, function() {
CategoryService.init();
});
}
});
$scope.showCategoryDetails = function(category) {
$state.transitionTo('feeds.category_details', {
_id: category.id
});
};
$scope.toggleCategory = function(category) {

View File

@@ -23,6 +23,16 @@ function($routeProvider, $stateProvider, $urlRouterProvider) {
templateUrl : 'templates/feeds.view.html',
controller : 'FeedListCtrl'
});
$stateProvider.state('feeds.feed_details', {
url : '/details/feed/:_id',
templateUrl : 'templates/feeds.feed_details.html',
controller : 'FeedDetailsCtrl'
});
$stateProvider.state('feeds.category_details', {
url : '/details/category/:_id',
templateUrl : 'templates/feeds.category_details.html',
controller : 'CategoryDetailsCtrl'
});
$stateProvider.state('feeds.help', {
url : '/help',
templateUrl : 'templates/feeds.help.html',

View File

@@ -80,14 +80,15 @@ function($resource, $http) {
_method : 'unsubscribe'
}
},
rename : {
modify : {
method : 'POST',
params : {
_method : 'rename'
_method : 'modify'
}
}
};
var res = $resource('rest/feed/:_method', {}, actions);
res.get = $resource('rest/feed/get/:id').get;
return res;
}]);
@@ -102,7 +103,8 @@ function($resource, $http) {
}
array.push({
id : category.id,
name : name
name : name,
origName: category.name
});
if (category.children) {
for ( var i = 0; i < category.children.length; i++) {
@@ -142,10 +144,10 @@ function($resource, $http) {
_method : 'delete'
}
},
rename : {
modify : {
method : 'POST',
params : {
_method : 'rename'
_method : 'modify'
}
},
collapse : {