Commit 4b131cec4c59abefe42fa419f70a38d645e5443d

Authored by Victor Costa
1 parent af7485cb

Refactor profile controller name

src/app/index.route.js
@@ -8,9 +8,9 @@ @@ -8,9 +8,9 @@
8 function routeConfig($routeProvider) { 8 function routeConfig($routeProvider) {
9 $routeProvider 9 $routeProvider
10 .when('/:profile', { 10 .when('/:profile', {
11 - templateUrl: 'app/main/main.html',  
12 - controller: 'MainController',  
13 - controllerAs: 'main' 11 + templateUrl: 'app/profile/profile.html',
  12 + controller: 'ProfileController',
  13 + controllerAs: 'vm'
14 }) 14 })
15 .when('/profile/:profile', { 15 .when('/profile/:profile', {
16 redirectTo: '/:profile' 16 redirectTo: '/:profile'
src/app/main/main.controller.js
@@ -1,27 +0,0 @@ @@ -1,27 +0,0 @@
1 -(function() {  
2 - 'use strict';  
3 -  
4 - angular  
5 - .module('angular')  
6 - .controller('MainController', MainController);  
7 -  
8 -  
9 - /** @ngInject */  
10 - function MainController($timeout, noosfero, $log, $routeParams) {  
11 - var vm = this;  
12 - vm.boxes = [];  
13 - activate();  
14 -  
15 - function activate() {  
16 - noosfero.communities().get({identifier: $routeParams.profile, private_token: '1b00325e5f769a0c38550bd35b3f1d64'}).$promise.then(function (profile) {  
17 - $log.log(profile);  
18 - vm.owner = profile.communities[0];  
19 - });  
20 - }  
21 -  
22 - vm.boxesOrder = function(box) {  
23 - if(box.position==2) return 0;  
24 - return box.position;  
25 - }  
26 - }  
27 -})();  
src/app/main/main.controller.spec.js
@@ -1,38 +0,0 @@ @@ -1,38 +0,0 @@
1 -(function() {  
2 - 'use strict';  
3 -  
4 - describe('controllers', function(){  
5 - var vm;  
6 - var $timeout;  
7 - var toastr;  
8 -  
9 - beforeEach(module('angular'));  
10 - beforeEach(inject(function(_$controller_, _$timeout_, _toastr_) {  
11 - spyOn(_toastr_, 'info').and.callThrough();  
12 -  
13 - vm = _$controller_('MainController');  
14 - $timeout = _$timeout_;  
15 - toastr = _toastr_;  
16 - }));  
17 -  
18 - it('should have a timestamp creation date', function() {  
19 - expect(vm.creationDate).toEqual(jasmine.any(Number));  
20 - });  
21 -  
22 - it('should define animate class after delaying timeout ', function() {  
23 - $timeout.flush();  
24 - expect(vm.classAnimation).toEqual('rubberBand');  
25 - });  
26 -  
27 - it('should show a Toastr info and stop animation when invoke showToastr()', function() {  
28 - vm.showToastr();  
29 - expect(toastr.info).toHaveBeenCalled();  
30 - expect(vm.classAnimation).toEqual('');  
31 - });  
32 -  
33 - it('should define more than 5 awesome things', function() {  
34 - expect(angular.isArray(vm.awesomeThings)).toBeTruthy();  
35 - expect(vm.awesomeThings.length === 5).toBeTruthy();  
36 - });  
37 - });  
38 -})();  
src/app/main/main.html
@@ -1,11 +0,0 @@ @@ -1,11 +0,0 @@
1 -<div class="container">  
2 -  
3 - <div>  
4 - <acme-navbar></acme-navbar>  
5 - </div>  
6 -  
7 - <div class="row">  
8 - <ng-include ng-repeat="box in main.owner.boxes | orderBy: main.boxesOrder" src="'app/views/profile/box.html'"></ng-include>  
9 - </div>  
10 -  
11 -</div>  
src/app/pages/profile/box.html
@@ -1,4 +0,0 @@ @@ -1,4 +0,0 @@
1 -<div class="col-sm-6 col-md-4" ng-repeat="box in main.boxes | orderBy: 'position'">  
2 - Box {{box.id}}->{{box.position}}  
3 - <ng-include ng-repeat="block in box.blocks | orderBy: 'position'" src="'app/views/profile/block.html'"></ng-include>  
4 -</div>  
src/app/profile/profile.controller.js 0 → 100644
@@ -0,0 +1,27 @@ @@ -0,0 +1,27 @@
  1 +(function() {
  2 + 'use strict';
  3 +
  4 + angular
  5 + .module('angular')
  6 + .controller('ProfileController', ProfileController);
  7 +
  8 +
  9 + /** @ngInject */
  10 + function ProfileController($timeout, noosfero, $log, $routeParams) {
  11 + var vm = this;
  12 + vm.boxes = [];
  13 + activate();
  14 +
  15 + function activate() {
  16 + noosfero.communities().get({identifier: $routeParams.profile, private_token: '1b00325e5f769a0c38550bd35b3f1d64'}).$promise.then(function (profile) {
  17 + $log.log(profile);
  18 + vm.owner = profile.communities[0];
  19 + });
  20 + }
  21 +
  22 + vm.boxesOrder = function(box) {
  23 + if(box.position==2) return 0;
  24 + return box.position;
  25 + }
  26 + }
  27 +})();
src/app/profile/profile.controller.spec.js 0 → 100644
@@ -0,0 +1,38 @@ @@ -0,0 +1,38 @@
  1 +(function() {
  2 + 'use strict';
  3 +
  4 + describe('controllers', function(){
  5 + var vm;
  6 + var $timeout;
  7 + var toastr;
  8 +
  9 + beforeEach(module('angular'));
  10 + beforeEach(inject(function(_$controller_, _$timeout_, _toastr_) {
  11 + spyOn(_toastr_, 'info').and.callThrough();
  12 +
  13 + vm = _$controller_('MainController');
  14 + $timeout = _$timeout_;
  15 + toastr = _toastr_;
  16 + }));
  17 +
  18 + it('should have a timestamp creation date', function() {
  19 + expect(vm.creationDate).toEqual(jasmine.any(Number));
  20 + });
  21 +
  22 + it('should define animate class after delaying timeout ', function() {
  23 + $timeout.flush();
  24 + expect(vm.classAnimation).toEqual('rubberBand');
  25 + });
  26 +
  27 + it('should show a Toastr info and stop animation when invoke showToastr()', function() {
  28 + vm.showToastr();
  29 + expect(toastr.info).toHaveBeenCalled();
  30 + expect(vm.classAnimation).toEqual('');
  31 + });
  32 +
  33 + it('should define more than 5 awesome things', function() {
  34 + expect(angular.isArray(vm.awesomeThings)).toBeTruthy();
  35 + expect(vm.awesomeThings.length === 5).toBeTruthy();
  36 + });
  37 + });
  38 +})();
src/app/profile/profile.html 0 → 100644
@@ -0,0 +1,11 @@ @@ -0,0 +1,11 @@
  1 +<div class="container">
  2 +
  3 + <div>
  4 + <acme-navbar></acme-navbar>
  5 + </div>
  6 +
  7 + <div class="row">
  8 + <ng-include ng-repeat="box in vm.owner.boxes | orderBy: vm.boxesOrder" src="'app/views/profile/box.html'"></ng-include>
  9 + </div>
  10 +
  11 +</div>
src/app/views/profile/block.html
@@ -3,6 +3,6 @@ @@ -3,6 +3,6 @@
3 <h3 class="panel-title">{{block.title}}</h3> 3 <h3 class="panel-title">{{block.title}}</h3>
4 </div> 4 </div>
5 <div class="panel-body"> 5 <div class="panel-body">
6 - <noosfero-block block="block" owner="main.owner"></noosfero-block> 6 + <noosfero-block block="block" owner="vm.owner"></noosfero-block>
7 </div> 7 </div>
8 </div> 8 </div>