Commit bb8f499a273d10a270aefb86145abcfc79fa30c3

Authored by ABNER SILVA DE OLIVEIRA
2 parents 8edc8a6f aa9af3a8

Merge branch 'ngforward' of softwarepublico.gov.br:noosfero-themes/angular-theme into ngforward

.gitignore
... ... @@ -6,4 +6,6 @@ coverage/
6 6 .tmp/
7 7 dist/
8 8 src/noosfero.js*
  9 +src/commons.js
  10 +src/noosfero-specs.js
9 11 typings
... ...
package.json
... ... @@ -21,6 +21,7 @@
21 21 "eslint-plugin-angular": "~0.12.0",
22 22 "estraverse": "~4.1.0",
23 23 "expose-loader": "^0.7.1",
  24 + "glob": "^7.0.0",
24 25 "gulp": "~3.9.0",
25 26 "gulp-angular-filesort": "~1.1.1",
26 27 "gulp-angular-templatecache": "~1.8.0",
... ...
src/app/cms/cms.component.ts 0 → 100644
... ... @@ -0,0 +1,36 @@
  1 +import {StateConfig, Component, Inject} from 'ng-forward';
  2 +
  3 +@Component({
  4 + selector: 'cms',
  5 + templateUrl: "app/cms/cms.html"
  6 +})
  7 +@Inject("noosfero", "$stateParams", "$httpParamSerializer", "$state", "SweetAlert")
  8 +export class Cms {
  9 +
  10 + article: any = {};
  11 + profile: any;
  12 +
  13 + constructor(private noosfero, private $stateParams, private $httpParamSerializer, private $state, private SweetAlert) {
  14 +
  15 + }
  16 +
  17 + save() {
  18 + this.noosfero.currentProfile.then((profile) => {
  19 + return this.noosfero.profiles.one(profile.id).customPOST(
  20 + { article: this.article },
  21 + 'articles',
  22 + {},
  23 + { 'Content-Type': 'application/json' }
  24 + )
  25 + }).then((response) => {
  26 + this.$state.transitionTo('main.profile.page', { page: response.data.article.path, profile: response.data.article.profile.identifier });
  27 + this.SweetAlert.swal({
  28 + title: "Good job!",
  29 + text: "Article saved!",
  30 + type: "success",
  31 + timer: 1000
  32 + });
  33 + });
  34 + }
  35 +
  36 +}
... ...
src/app/cms/cms.controller.js
... ... @@ -1,35 +0,0 @@
1   -(function() {
2   - 'use strict';
3   -
4   - angular
5   - .module('noosferoApp')
6   - .controller('CmsController', CmsController);
7   -
8   -
9   - /** @ngInject */
10   - function CmsController(noosfero, $stateParams, $httpParamSerializer, $state, SweetAlert) {
11   - var vm = this;
12   - vm.article = {};
13   - vm.profile = null;
14   -
15   - vm.save = function() {
16   - noosfero.currentProfile.then(function(profile) {
17   - return noosfero.profiles.one(profile.id).customPOST(
18   - {article: vm.article},
19   - 'articles',
20   - {},
21   - {'Content-Type':'application/json'}
22   - )
23   - }).then(function(response) {
24   - $state.transitionTo('main.profile.page', {page: response.data.article.path, profile: response.data.article.profile.identifier});
25   - SweetAlert.swal({
26   - title: "Good job!",
27   - text: "Article saved!",
28   - type: "success",
29   - timer: 1000
30   - });
31   - });
32   - }
33   -
34   - }
35   -})();
src/app/components/noosfero-blocks/block.component.ts 0 → 100644
... ... @@ -0,0 +1,20 @@
  1 +import { Input, Inject, Component } from 'ng-forward';
  2 +
  3 +@Component({
  4 + selector: 'noosfero-block',
  5 + template: '<div></div>'
  6 +})
  7 +@Inject("$element", "$scope", "$injector", "$compile")
  8 +export class Block {
  9 +
  10 + @Input() block: any;
  11 + @Input() owner: any;
  12 +
  13 + ngOnInit() {
  14 + let blockName = this.block.type.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase();
  15 + this.$element.replaceWith(this.$compile('<noosfero-' + blockName + ' block="ctrl.block" owner="ctrl.owner"></noosfero-' + blockName + '>')(this.$scope));
  16 + }
  17 +
  18 + constructor(private $element: any, private $scope: ng.IScope, private $injector: ng.auto.IInjectorService, private $compile: ng.ICompileService) {
  19 + }
  20 +}
... ...
src/app/components/noosfero-blocks/block.directive.js
... ... @@ -1,24 +0,0 @@
1   -(function() {
2   - 'use strict';
3   -
4   - angular
5   - .module('noosferoApp')
6   - .directive('noosferoBlock', noosferoBlock);
7   -
8   - /** @ngInject */
9   - function noosferoBlock($compile) {
10   - var directive = {
11   - restrict: 'E',
12   - scope: {
13   - block: '<',
14   - owner: '<'
15   - },
16   - link: function(scope, element) {
17   - var blockName = scope.block.type.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase();
18   - element.replaceWith($compile('<noosfero-'+blockName+' block="block" owner="owner"></noosfero-'+blockName+'>')(scope));
19   - }
20   - };
21   - return directive;
22   - }
23   -
24   -})();
src/app/components/noosfero-boxes/box.html
... ... @@ -4,7 +4,7 @@
4 4 <h3 class="panel-title">{{block.title}}</h3>
5 5 </div>
6 6 <div class="panel-body">
7   - <noosfero-block block="block" owner="$ctrl.owner"></noosfero-block>
  7 + <noosfero-block [block]="block" [owner]="ctrl.owner"></noosfero-block>
8 8 </div>
9 9 </div>
10 10 </div>
... ...
src/app/components/noosfero-boxes/boxes.component.js
... ... @@ -1,26 +0,0 @@
1   -(function() {
2   - 'use strict';
3   -
4   - angular
5   - .module('noosferoApp')
6   - .component('noosferoBoxes', {
7   - restrict: 'E',
8   - bindings: {
9   - boxes: '<',
10   - owner: '<'
11   - },
12   - templateUrl: 'app/components/noosfero-boxes/boxes.html',
13   - controller: BoxesController
14   - });
15   -
16   - /** @ngInject */
17   - function BoxesController() {
18   - var vm = this;
19   -
20   - vm.boxesOrder = function(box) {
21   - if(box.position==2) return 0;
22   - return box.position;
23   - }
24   - }
25   -
26   -})();
src/app/components/noosfero-boxes/boxes.component.ts 0 → 100644
... ... @@ -0,0 +1,16 @@
  1 +import { Input, Inject, Component } from 'ng-forward';
  2 +
  3 +@Component({
  4 + selector: "noosfero-boxes",
  5 + templateUrl: "app/components/noosfero-boxes/boxes.html"
  6 +})
  7 +export class Boxes {
  8 +
  9 + @Input() boxes: any
  10 + @Input() owner: any
  11 +
  12 + boxesOrder(box) {
  13 + if (box.position == 2) return 0;
  14 + return box.position;
  15 + }
  16 +}
... ...
src/app/components/noosfero-boxes/boxes.html
1   -<ng-include ng-repeat="box in $ctrl.boxes | orderBy: $ctrl.boxesOrder" src="'app/components/noosfero-boxes/box.html'"></ng-include>
  1 +<ng-include ng-repeat="box in ctrl.boxes | orderBy: ctrl.boxesOrder" src="'app/components/noosfero-boxes/box.html'"></ng-include>
... ...
src/app/content-viewer/content-viewer-actions.component.ts 0 → 100644
... ... @@ -0,0 +1,18 @@
  1 +import {Component, Inject} from "ng-forward";
  2 +
  3 +@Component({
  4 + selector: "content-viewer-actions",
  5 + templateUrl: "app/content-viewer/navbar-actions.html",
  6 +})
  7 +@Inject("noosfero")
  8 +export class ContentViewerActions {
  9 +
  10 + article: any;
  11 + profile: any;
  12 +
  13 + constructor(noosfero) {
  14 + noosfero.currentProfile.then((profile) => {
  15 + this.profile = profile;
  16 + });
  17 + }
  18 +}
... ...
src/app/content-viewer/content-viewer-actions.controller.js
... ... @@ -1,22 +0,0 @@
1   -(function() {
2   - 'use strict';
3   -
4   - angular
5   - .module('noosferoApp')
6   - .controller('ContentViewerActionsController', ContentViewerActionsController);
7   -
8   -
9   - /** @ngInject */
10   - function ContentViewerActionsController(noosfero) {
11   - var vm = this;
12   - vm.article = null;
13   - vm.profile = null;
14   - activate();
15   -
16   - function activate() {
17   - noosfero.currentProfile.then(function(profile) {
18   - vm.profile = profile;
19   - });
20   - }
21   - }
22   -})();
src/app/content-viewer/content-viewer.component.ts
1   -
2 1 import * as noosfero from "../models/interfaces";
3 2  
4 3 import {ArticleDirective, ArticleView} from "../components/noosfero-articles/article/article.directive";
5   -import {Input, Component, StateConfig} from "ng-forward";
  4 +import {Input, Component, StateConfig, Inject} from "ng-forward";
6 5  
7 6 import {NoosferoArticleBlog} from "./../components/noosfero-articles/blog/blog.component";
8 7  
9 8 @Component({
10 9 selector: "content-viewer",
11 10 templateUrl: "app/content-viewer/page.html",
12   - providers: [
13   - "noosferoService", "$log", "$stateParams"
14   - ],
15 11 directives: [NoosferoArticleBlog, ArticleView, ArticleDirective]
16 12 })
  13 +@Inject("noosfero", "$log", "$stateParams")
17 14 export class ContentViewer {
18 15  
19 16 @Input()
... ...
src/app/index.route.ts
... ... @@ -3,42 +3,8 @@
3 3 /** @ngInject */
4 4 export function routeConfig($stateProvider, $urlRouterProvider) {
5 5 $stateProvider
6   - .state("main.profile.cms", {
7   - url: "^/myprofile/:profile/cms",
8   - views: {
9   - "mainBlockContent": {
10   - templateUrl: "app/cms/cms.html",
11   - controller: "CmsController",
12   - controllerAs: "vm"
13   - }
14   - }
15   - })
16 6 .state("main.profile.settings", {
17 7 url: "^/myprofile/:profile"
18   - })
19   - .state("main.profile.home", {
20   - url: "",
21   - views: {
22   - "mainBlockContent": {
23   - controller: "ProfileHomeController",
24   - controllerAs: "vm"
25   - }
26   - }
27   - })
28   - .state("main.profile.page", {
29   - url: "/{page:any}",
30   - views: {
31   - "mainBlockContent": {
32   - templateUrl: "app/content-viewer/page.html",
33   - controller: "ContentViewerController",
34   - controllerAs: "vm"
35   - },
36   - "actions@main": {
37   - templateUrl: "app/content-viewer/navbar-actions.html",
38   - controller: "ContentViewerActionsController",
39   - controllerAs: "vm"
40   - }
41   - }
42 8 });
43 9  
44 10 $urlRouterProvider.otherwise("/");
... ...
src/app/index.ts
... ... @@ -7,15 +7,18 @@ import {noosferoAngularRunBlock} from &quot;./index.run&quot;;
7 7 import {routeConfig} from "./index.route";
8 8  
9 9 import {ContentViewer as noosferoContentViewer} from "./content-viewer/content-viewer.component";
  10 +import {ContentViewerActions as noosferoContentViewerActions} from "./content-viewer/content-viewer-actions.component";
10 11 import {Profile as noosferoProfile} from "./profile/profile.component";
11 12 import {ProfileInfo as noosferoProfileInfo} from "./profile-info/profile-info.component";
  13 +import {ProfileHome as noosferoProfileHome} from "./profile/profile-home.component";
  14 +import {Cms as noosferoCms} from "./cms/cms.component";
12 15  
13 16 import {Main} from "./main/main.component";
14 17 import {bootstrap, bundle} from "ng-forward";
15 18  
16 19  
17 20  
18   -declare var moment: any;
  21 +declare var moment: any;
19 22  
20 23 let noosferoApp: any = bundle("noosferoApp", Main, ["ngAnimate", "ngCookies", "ngStorage", "ngTouch",
21 24 "ngSanitize", "ngMessages", "ngAria", "restangular",
... ... @@ -35,32 +38,25 @@ NoosferoApp.addConstants(&quot;AUTH_EVENTS&quot;, {
35 38 NoosferoApp.addConfig(noosferoModuleConfig);
36 39 NoosferoApp.run(noosferoAngularRunBlock);
37 40  
38   -require("./cms/cms.controller.js");
39 41 require("./components/auth/auth.controller.js");
40 42 require("./components/auth/auth.service.js");
41 43 require("./components/navbar/navbar.directive.js");
42 44 require("./components/noosfero-activities/activities.component.js");
43 45 require("./components/noosfero-activities/activity/activity.component.js");
44   -
45   -// require("./components/noosfero-articles/blog/blog.component.js");
46   -
47   -
48   -require("./components/noosfero-blocks/block.directive.js");
49 46 require("./components/noosfero-blocks/link-list/link-list.component.js");
50 47 require("./components/noosfero-blocks/main-block/main-block.component.js");
51 48 require("./components/noosfero-blocks/members-block/members-block.component.js");
52 49 require("./components/noosfero-blocks/profile-image/profile-image.component.js");
53 50 require("./components/noosfero-blocks/recent-documents/recent-documents.component.js");
54   -require("./components/noosfero-boxes/boxes.component.js");
55 51 require("./components/noosfero/noosfero-template.filter.js");
56 52 require("./components/noosfero/noosfero.service.js");
57 53 require("./components/noosfero/profile-image/profile-image.component.js");
58   -require("./content-viewer/content-viewer-actions.controller.js");
59   -// require("./content-viewer/content-viewer.controller.js");
60   -require("./profile/profile-home.controller.js");
61 54  
62 55 NoosferoApp.addController("ContentViewerController", noosferoContentViewer);
  56 +NoosferoApp.addController("ContentViewerActionsController", noosferoContentViewerActions);
63 57 NoosferoApp.addController("ProfileController", noosferoProfile);
  58 +NoosferoApp.addController("ProfileHomeController", noosferoProfileHome);
64 59 NoosferoApp.addController("ProfileInfoController", noosferoProfileInfo);
  60 +NoosferoApp.addController("CmsController", noosferoCms);
65 61  
66 62 NoosferoApp.addConfig(routeConfig);
... ...
src/app/main/main.component.ts
1 1 import {bundle, Component, StateConfig} from "ng-forward";
2 2 import {NoosferoArticleBlog} from "./../components/noosfero-articles/blog/blog.component.ts";
3   -
4 3 import {ArticleDirective} from "../components/noosfero-articles/article/article.directive.ts";
5   -
6 4 import {Profile} from "../profile/profile.component";
  5 +import {Boxes} from "../components/noosfero-boxes/boxes.component";
  6 +import {Block} from "../components/noosfero-blocks/block.component";
7 7  
8 8 @Component({
9 9 selector: 'main-content',
... ... @@ -16,7 +16,7 @@ export class MainContent {
16 16 @Component({
17 17 selector: 'main',
18 18 template: '<div ng-view></div>',
19   - directives: [NoosferoArticleBlog, ArticleDirective]
  19 + directives: [NoosferoArticleBlog, ArticleDirective, Boxes, Block]
20 20 })
21 21 @StateConfig([
22 22 {
... ...
src/app/profile/profile-home.component.ts 0 → 100644
... ... @@ -0,0 +1,24 @@
  1 +import {StateConfig, Component, Inject} from 'ng-forward';
  2 +
  3 +@Component({
  4 + selector: 'profile-home',
  5 + template: "<div></div>"
  6 +})
  7 +@Inject("noosfero", "$log", "$stateParams", "$scope", "$state")
  8 +export class ProfileHome {
  9 +
  10 + profile: any;
  11 +
  12 + constructor(noosfero, $log, $stateParams, $scope, $state) {
  13 + noosfero.currentProfile.then((profile) => {
  14 + this.profile = profile;
  15 + return noosfero.profile(this.profile.id).customGET('home_page', { fields: 'path' });
  16 + }).then((response) => {
  17 + if (response.data.article) {
  18 + $state.transitionTo('main.profile.page', { page: response.data.article.path, profile: this.profile.identifier }, { location: false });
  19 + } else {
  20 + $state.transitionTo('main.profile.info', { profile: this.profile.identifier }, { location: false });
  21 + }
  22 + });
  23 + }
  24 +}
... ...
src/app/profile/profile-home.controller.js
... ... @@ -1,27 +0,0 @@
1   -(function() {
2   - 'use strict';
3   -
4   - angular
5   - .module('noosferoApp')
6   - .controller('ProfileHomeController', ProfileHomeController);
7   -
8   -
9   - /** @ngInject */
10   - function ProfileHomeController(noosfero, $log, $stateParams, $scope, $state) {
11   - var vm = this;
12   - activate();
13   -
14   - function activate() {
15   - noosfero.currentProfile.then(function(profile) {
16   - vm.profile = profile;
17   - return noosfero.profile(vm.profile.id).customGET('home_page', {fields: 'path'});
18   - }).then(function(response) {
19   - if(response.data.article) {
20   - $state.transitionTo('main.profile.page', {page: response.data.article.path, profile: vm.profile.identifier}, {location: false});
21   - } else {
22   - $state.transitionTo('main.profile.info', {profile: vm.profile.identifier}, {location: false});
23   - }
24   - });
25   - }
26   - }
27   -})();
src/app/profile/profile.component.ts
1 1 import {StateConfig, Component, Inject} from 'ng-forward';
2 2 import {ProfileInfo} from '../profile-info/profile-info.component'
  3 +import {ProfileHome} from '../profile/profile-home.component'
  4 +import {Cms} from '../cms/cms.component'
  5 +import {ContentViewer} from "../content-viewer/content-viewer.component";
3 6  
4 7 @Component({
5 8 selector: 'profile',
... ... @@ -7,9 +10,9 @@ import {ProfileInfo} from &#39;../profile-info/profile-info.component&#39;
7 10 })
8 11 @StateConfig([
9 12 {
  13 + name: 'main.profile.info',
10 14 url: "^/profile/:profile",
11 15 component: ProfileInfo,
12   - name: 'main.profile.info',
13 16 views: {
14 17 "mainBlockContent": {
15 18 templateUrl: "app/profile-info/profile-info.html",
... ... @@ -17,6 +20,46 @@ import {ProfileInfo} from &#39;../profile-info/profile-info.component&#39;
17 20 controllerAs: "vm"
18 21 }
19 22 }
  23 + },
  24 + {
  25 + name: 'main.profile.cms',
  26 + url: "^/myprofile/:profile/cms",
  27 + component: Cms,
  28 + views: {
  29 + "mainBlockContent": {
  30 + templateUrl: "app/cms/cms.html",
  31 + controller: "CmsController",
  32 + controllerAs: "vm"
  33 + }
  34 + }
  35 + },
  36 + {
  37 + name: 'main.profile.home',
  38 + url: "",
  39 + component: ProfileHome,
  40 + views: {
  41 + "mainBlockContent": {
  42 + controller: "ProfileHomeController",
  43 + controllerAs: "vm"
  44 + }
  45 + }
  46 + },
  47 + {
  48 + name: 'main.profile.page',
  49 + url: "/{page:any}",
  50 + component: ContentViewer,
  51 + views: {
  52 + "mainBlockContent": {
  53 + templateUrl: "app/content-viewer/page.html",
  54 + controller: "ContentViewerController",
  55 + controllerAs: "vm"
  56 + },
  57 + "actions@main": {
  58 + templateUrl: "app/content-viewer/navbar-actions.html",
  59 + controller: "ContentViewerActionsController",
  60 + controllerAs: "vm"
  61 + }
  62 + }
20 63 }
21 64 ])
22 65 @Inject("noosfero", "$log", "$stateParams")
... ...
src/app/profile/profile.html
1 1 <div class="profile-container">
2 2 <div class="row">
3   - <noosfero-boxes boxes="vm.boxes" owner="vm.profile"></noosfero-boxes>
  3 + <noosfero-boxes [boxes]="vm.boxes" [owner]="vm.profile"></noosfero-boxes>
4 4 </div>
5 5 </div>
... ...
src/index.html
... ... @@ -35,7 +35,8 @@
35 35  
36 36  
37 37  
38   - <script src="noosfero.js"></script>
  38 + <script src="commons.js"></script>
  39 + <script src="noosfero.js"></script>
39 40 <!-- inject:partials -->
40 41 <!-- angular templates will be automatically converted in js and inserted here -->
41 42 <!-- endinject -->
... ...