use ui-router instead of routeProvider

This commit is contained in:
Athou
2013-03-29 15:09:50 +01:00
parent 60bcb64828
commit fc8bd5c812
14 changed files with 1145 additions and 80 deletions

View File

@@ -5,14 +5,17 @@ module.run(function($rootScope) {
// args.entry - the entry
$rootScope.$broadcast('mark', args);
});
$rootScope.$on('emitReload', function(event, args) {
$rootScope.$broadcast('reload');
});
});
module.controller('CategoryTreeCtrl', function($scope, $routeParams, $location,
$route, SubscriptionService) {
module.controller('CategoryTreeCtrl', function($scope, $stateParams, $location,
$state, $route, SubscriptionService) {
$scope.$on('$routeChangeSuccess', function() {
$scope.selectedType = $routeParams._type;
$scope.selectedId = $routeParams._id;
$scope.$on('$stateChangeSuccess', function() {
$scope.selectedType = $stateParams._type;
$scope.selectedId = $stateParams._id;
});
$scope.SubscriptionService = SubscriptionService;
@@ -52,17 +55,23 @@ module.controller('CategoryTreeCtrl', function($scope, $routeParams, $location,
$scope.feedClicked = function(id) {
if ($scope.selectedType == 'feed' && id == $scope.selectedId) {
$route.reload();
$scope.$emit('emitReload');
} else {
$location.path('/feeds/view/feed/' + id);
$state.transitionTo('feeds.view', {
_type : 'feed',
_id : id
});
}
};
$scope.categoryClicked = function(id) {
if ($scope.selectedType == 'category' && id == $scope.selectedId) {
$route.reload();
$scope.$emit('emitReload');
} else {
$location.path('/feeds/view/category/' + id);
$state.transitionTo('feeds.view', {
_type : 'category',
_id : id
});
}
};
@@ -88,11 +97,11 @@ module.controller('CategoryTreeCtrl', function($scope, $routeParams, $location,
});
});
module.controller('FeedListCtrl', function($scope, $routeParams, $http, $route,
module.controller('FeedListCtrl', function($scope, $stateParams, $http, $route,
$window, EntryService, SettingsService) {
$scope.selectedType = $routeParams._type;
$scope.selectedId = $routeParams._id;
$scope.selectedType = $stateParams._type;
$scope.selectedId = $stateParams._id;
$scope.name = null;
$scope.entries = [];
@@ -101,7 +110,7 @@ module.controller('FeedListCtrl', function($scope, $routeParams, $http, $route,
$scope.$watch('settingsService.settings.readingMode', function(newValue,
oldValue) {
if (newValue && oldValue && newValue != oldValue) {
$route.reload();
$scope.$emit('emitReload');
}
});
@@ -219,7 +228,7 @@ module.controller('FeedListCtrl', function($scope, $routeParams, $http, $route,
openNextEntry(e);
})
});
Mousetrap.bind('shift+space', function(e) {
$scope.$apply(function() {
openPreviousEntry(e);
@@ -230,4 +239,12 @@ module.controller('FeedListCtrl', function($scope, $routeParams, $http, $route,
openPreviousEntry(e);
})
});
$scope.$on('reload', function(event, args) {
$scope.name = null;
$scope.entries = [];
$scope.busy = false;
$scope.hasMore = true;
$scope.loadMoreEntries();
});
});

View File

@@ -122,8 +122,8 @@ module.directive('category', function($compile) {
};
});
module.directive('toolbar', function($routeParams, $route, SettingsService,
EntryService, SubscriptionService) {
module.directive('toolbar', function($stateParams, $route, $location,
SettingsService, EntryService, SubscriptionService) {
return {
scope : {},
restrict : 'E',
@@ -142,19 +142,22 @@ module.directive('toolbar', function($routeParams, $route, SettingsService,
$scope.settingsService = SettingsService;
$scope.refresh = function() {
$route.reload();
$scope.$emit('emitReload');
};
$scope.markAllAsRead = function() {
EntryService.mark({
type : $routeParams._type,
id : $routeParams._id,
type : $stateParams._type,
id : $stateParams._id,
read : true,
}, function() {
SubscriptionService.init(function() {
$route.reload();
$scope.$emit('emitReload');
});
});
}
};
$scope.toAdmin = function() {
$location.path('admin');
};
},
link : function($scope, element) {
element.find('.read-mode button').bind('click', function() {

View File

@@ -1,12 +1,28 @@
var app = angular.module('commafeed', [ 'ui', 'ui.bootstrap',
'commafeed.directives', 'commafeed.controllers', 'commafeed.services',
var app = angular.module('commafeed', [ 'ui', 'ui.bootstrap', 'ui.state',
'commafeed.directives', 'commafeed.controllers', 'commafeed.services',
'ngSanitize', 'ngUpload', 'infinite-scroll' ]);
app.config([ '$routeProvider', function($routeProvider) {
$routeProvider.when('/feeds/view/:_type/:_id', {
templateUrl : 'templates/feeds.html'
app.config(function($urlRouterProvider, $stateProvider) {
$stateProvider.state('feeds', {
abstract: true,
url: '/feeds',
templateUrl: 'templates/feeds.html'
});
$routeProvider.otherwise({
redirectTo : '/feeds/view/category/all'
$stateProvider.state('feeds.view', {
url: '/view/:_type/:_id',
templateUrl : 'templates/feeds.view.html'
});
} ]);
$stateProvider.state('admin', {
abstract: true,
url: '/admin',
templateUrl: 'templates/admin.html'
});
$stateProvider.state('admin.users', {
url: '/users',
templateUrl : 'templates/admin.users.html'
});
$urlRouterProvider.when('/', '/feeds/view/category/all');
$urlRouterProvider.when('/admin', '/admin/users');
});