From f06fa207eb5ce8ed380eb263c58c7933249e80e5 Mon Sep 17 00:00:00 2001 From: Victor Costa Date: Fri, 8 Jan 2016 10:47:22 -0300 Subject: [PATCH] Migrate to ui-router --- bower.json | 2 +- src/app/components/noosfero-blocks/main-block/main-block.directive.js | 6 +++--- src/app/content-viewer/content-viewer.controller.js | 8 ++++---- src/app/content-viewer/page.html | 13 +++++++++++++ src/app/index.module.js | 2 +- src/app/index.route.js | 26 +++++++++++++++++++++++--- src/app/profile/profile.controller.js | 4 ++-- src/index.html | 2 +- 8 files changed, 48 insertions(+), 15 deletions(-) create mode 100644 src/app/content-viewer/page.html diff --git a/bower.json b/bower.json index e8ad744..27865f4 100644 --- a/bower.json +++ b/bower.json @@ -9,7 +9,7 @@ "angular-messages": "~1.4.2", "angular-aria": "~1.4.2", "angular-resource": "~1.4.2", - "angular-route": "~1.4.2", + "angular-ui-router": "~0.2.15", "bootstrap-sass": "~3.3.5", "angular-bootstrap": "~0.13.4", "malarkey": "yuanqing/malarkey#~1.3.1", diff --git a/src/app/components/noosfero-blocks/main-block/main-block.directive.js b/src/app/components/noosfero-blocks/main-block/main-block.directive.js index cb67faa..5bb4d15 100644 --- a/src/app/components/noosfero-blocks/main-block/main-block.directive.js +++ b/src/app/components/noosfero-blocks/main-block/main-block.directive.js @@ -6,7 +6,7 @@ .directive('noosferoMainBlock', noosferoMainBlock); /** @ngInject */ - function noosferoMainBlock($log, $routeParams, noosfero) { + function noosferoMainBlock($log, $stateParams, noosfero) { var directive = { restrict: 'E', templateUrl: 'app/components/noosfero-blocks/main-block/main-block.html', @@ -24,8 +24,8 @@ /** @ngInject */ function MainBlockController() { var vm = this; - $log.log($routeParams.page); - noosfero.articles().get({path: $routeParams.page, private_token: '1b00325e5f769a0c38550bd35b3f1d64'}).$promise.then(function (article) { + $log.log($stateParams.page); + noosfero.articles().get({path: $stateParams.page, private_token: '1b00325e5f769a0c38550bd35b3f1d64'}).$promise.then(function (article) { //FIXME vm.article = article.articles[0]; $log.log(vm.article); diff --git a/src/app/content-viewer/content-viewer.controller.js b/src/app/content-viewer/content-viewer.controller.js index fc07ebd..882f0d7 100644 --- a/src/app/content-viewer/content-viewer.controller.js +++ b/src/app/content-viewer/content-viewer.controller.js @@ -7,16 +7,16 @@ /** @ngInject */ - function ContentViewerController($timeout, noosfero, $log, $routeParams) { + function ContentViewerController(noosfero, $log, $stateParams) { var vm = this; vm.article = null; activate(); function activate() { - $log.log($routeParams.page); - noosfero.articles().get({path: $routeParams.page, private_token: '1b00325e5f769a0c38550bd35b3f1d64'}).$promise.then(function (article) { + $log.log($stateParams.page); + noosfero.articles().get({path: $stateParams.page, private_token: '1b00325e5f769a0c38550bd35b3f1d64'}).$promise.then(function (article) { //FIXME - vm.article = article.articles[0]; + vm.content = article.articles[0]; }); } } diff --git a/src/app/content-viewer/page.html b/src/app/content-viewer/page.html new file mode 100644 index 0000000..1164a76 --- /dev/null +++ b/src/app/content-viewer/page.html @@ -0,0 +1,13 @@ +
+ +
+ +
+ +
+ +
+ +
+ +{{vm.article}} diff --git a/src/app/index.module.js b/src/app/index.module.js index 39ed460..4eeada8 100644 --- a/src/app/index.module.js +++ b/src/app/index.module.js @@ -2,6 +2,6 @@ 'use strict'; angular - .module('angular', ['ngAnimate', 'ngCookies', 'ngTouch', 'ngSanitize', 'ngMessages', 'ngAria', 'ngResource', 'ngRoute', 'ui.bootstrap', 'toastr']); + .module('angular', ['ngAnimate', 'ngCookies', 'ngTouch', 'ngSanitize', 'ngMessages', 'ngAria', 'ngResource', 'ui.router', 'ui.bootstrap', 'toastr']); })(); diff --git a/src/app/index.route.js b/src/app/index.route.js index 5930cd9..7ede5d0 100644 --- a/src/app/index.route.js +++ b/src/app/index.route.js @@ -5,7 +5,18 @@ .module('angular') .config(routeConfig); - function routeConfig($routeProvider) { + function routeConfig($stateProvider, $urlRouterProvider) { + $stateProvider + .state('profile', { + url: '/:profile', + templateUrl: 'app/profile/profile.html', + controller: 'ProfileController', + controllerAs: 'vm' + }); + + $urlRouterProvider.otherwise('/'); + + /* var profileController = { templateUrl: 'app/profile/profile.html', controller: 'ProfileController', @@ -15,11 +26,20 @@ .when('/profile/:profile', { redirectTo: '/:profile' }) - .when('/:profile', profileController) - .when('/:profile/:page*', profileController) + .when('/:profile', { + templateUrl: 'app/profile/profile.html', + controller: 'ProfileController', + controllerAs: 'vm' + }) + .when('/:profile/:page*', { + templateUrl: 'app/content-viewer/page.html', + controller: 'ContentViewerController', + controllerAs: 'vm' + }) .otherwise({ redirectTo: '/' }); + */ } })(); diff --git a/src/app/profile/profile.controller.js b/src/app/profile/profile.controller.js index b5f4af6..8daa1f4 100644 --- a/src/app/profile/profile.controller.js +++ b/src/app/profile/profile.controller.js @@ -7,13 +7,13 @@ /** @ngInject */ - function ProfileController($timeout, noosfero, $log, $routeParams) { + function ProfileController(noosfero, $log, $stateParams) { var vm = this; vm.boxes = []; activate(); function activate() { - noosfero.communities().get({identifier: $routeParams.profile, private_token: '1b00325e5f769a0c38550bd35b3f1d64'}).$promise.then(function (profile) { + noosfero.communities().get({identifier: $stateParams.profile, private_token: '1b00325e5f769a0c38550bd35b3f1d64'}).$promise.then(function (profile) { $log.log(profile); vm.owner = profile.communities[0]; }); diff --git a/src/index.html b/src/index.html index 637e4a1..d347022 100644 --- a/src/index.html +++ b/src/index.html @@ -25,7 +25,7 @@

You are using an outdated browser. Please upgrade your browser to improve your experience.

-
+
-- libgit2 0.21.2