Commit 8fa37152acf2dea5844f2f830f18f24e269a4b12
Exists in
master
and in
34 other branches
Merge branch 'ngforward' of softwarepublico.gov.br:noosfero-themes/angular-theme into ngforward
Showing
11 changed files
with
116 additions
and
98 deletions
Show diff stats
src/app/cms/cms.component.ts
| 1 | 1 | import {StateConfig, Component, Inject} from 'ng-forward'; |
| 2 | 2 | import {Profile} from "./../models/interfaces"; |
| 3 | +import {ArticleService} from "../../lib/ng-noosfero-api/http/article.service"; | |
| 4 | + | |
| 3 | 5 | @Component({ |
| 4 | 6 | selector: 'cms', |
| 5 | 7 | templateUrl: "app/cms/cms.html" |
| 6 | 8 | }) |
| 7 | -@Inject("noosfero", "$stateParams", "$httpParamSerializer", "$state", "SweetAlert") | |
| 9 | +@Inject(ArticleService, "noosfero", "$stateParams", "$httpParamSerializer", "$state", "SweetAlert") | |
| 8 | 10 | export class Cms { |
| 9 | 11 | |
| 10 | 12 | article: any = {}; |
| 11 | 13 | profile: any; |
| 12 | 14 | |
| 13 | - constructor(private noosfero: any/* TODO convert noosferoService */, private $stateParams: ng.ui.IStateParamsService, private $httpParamSerializer: any, private $state: ng.ui.IStateService, private SweetAlert: any) { | |
| 15 | + constructor(private ArticleService: ArticleService, private noosfero: any/* TODO convert noosferoService */, private $stateParams: ng.ui.IStateParamsService, private $httpParamSerializer: any, private $state: ng.ui.IStateService, private SweetAlert: any) { | |
| 14 | 16 | |
| 15 | 17 | } |
| 16 | 18 | |
| 17 | 19 | save() { |
| 18 | 20 | this.noosfero.currentProfile.then((profile: Profile) => { |
| 19 | - return this.noosfero.profiles.one(profile.id).customPOST( | |
| 20 | - { article: this.article }, | |
| 21 | - 'articles', | |
| 22 | - {}, | |
| 23 | - { 'Content-Type': 'application/json' } | |
| 24 | - ) | |
| 21 | + return this.ArticleService.create(profile.id, this.article); | |
| 25 | 22 | }).then((response: restangular.IResponse) => { |
| 26 | 23 | this.$state.transitionTo('main.profile.page', { page: response.data.article.path, profile: response.data.article.profile.identifier }); |
| 27 | 24 | this.SweetAlert.swal({ | ... | ... |
src/app/components/navbar/navbar.spec.ts
| ... | ... | @@ -30,6 +30,43 @@ describe("Components", () => { |
| 30 | 30 | login: "user" |
| 31 | 31 | }; |
| 32 | 32 | |
| 33 | + | |
| 34 | + let scope = { | |
| 35 | + eventCalledHook: () => { }, | |
| 36 | + $on: (eventName: string, func: Function) => { | |
| 37 | + this.eventCalledHook = func; | |
| 38 | + } | |
| 39 | + } | |
| 40 | + | |
| 41 | + let modalInstance = { | |
| 42 | + close: () => { } | |
| 43 | + } | |
| 44 | + | |
| 45 | + let $modal = { | |
| 46 | + open: (args: {}) => { | |
| 47 | + return modalInstance; | |
| 48 | + } | |
| 49 | + } | |
| 50 | + | |
| 51 | + let authService = { | |
| 52 | + logout: () => { } | |
| 53 | + } | |
| 54 | + | |
| 55 | + let stateService = jasmine.createSpyObj("$state", ["go"]); | |
| 56 | + let providers = [ | |
| 57 | + new Provider('moment', { useValue: {} }), | |
| 58 | + new Provider('$modal', { useValue: $modal }), | |
| 59 | + new Provider('AuthService', { useValue: authService }), | |
| 60 | + new Provider('Session', { | |
| 61 | + useValue: { | |
| 62 | + currentUser: () => { return user } | |
| 63 | + } | |
| 64 | + }), | |
| 65 | + new Provider('$scope', { useValue: scope }), | |
| 66 | + new Provider('$state', { useValue: stateService }), | |
| 67 | + new Provider('AUTH_EVENTS', { useValue: { AUTH_EVENTS } }) | |
| 68 | + ]; | |
| 69 | + | |
| 33 | 70 | beforeEach(angular.mock.module("templates")); |
| 34 | 71 | |
| 35 | 72 | // beforeEach(inject((_$rootScope_: ng.IRootScopeService) => { |
| ... | ... | @@ -72,51 +109,14 @@ describe("Components", () => { |
| 72 | 109 | }); |
| 73 | 110 | |
| 74 | 111 | it('It should open on click', (done: Function) => { |
| 75 | - | |
| 76 | - let scope = { | |
| 77 | - eventCalledHook: () => { }, | |
| 78 | - $on: (eventName: string, func: Function) => { | |
| 79 | - console.log("ON Called!"); | |
| 80 | - this.eventCalledHook = func; | |
| 81 | - } | |
| 82 | - } | |
| 83 | - | |
| 84 | - let modalInstance = { | |
| 85 | - close: () => { | |
| 86 | - console.log("CLOSE Called!"); | |
| 87 | - } | |
| 88 | - } | |
| 89 | - | |
| 90 | - let $modal = { | |
| 91 | - open: (args: {}) => { | |
| 92 | - return modalInstance; | |
| 93 | - } | |
| 94 | - } | |
| 95 | - | |
| 96 | - let stateService = jasmine.createSpyObj("$state", ["go"]); | |
| 97 | - let providers = [ | |
| 98 | - new Provider('moment', { useValue: {} }), | |
| 99 | - new Provider('$modal', { useValue: $modal }), | |
| 100 | - new Provider('AuthService', { useValue: {} }), | |
| 101 | - new Provider('Session', { | |
| 102 | - useValue: { | |
| 103 | - currentUser: () => { return user } | |
| 104 | - } | |
| 105 | - }), | |
| 106 | - new Provider('$scope', { useValue: scope }), | |
| 107 | - new Provider('$state', { useValue: stateService }), | |
| 108 | - new Provider('AUTH_EVENTS', { useValue: { AUTH_EVENTS } }) | |
| 109 | - ]; | |
| 110 | 112 | quickCreateComponent({ |
| 111 | 113 | providers: providers, |
| 112 | 114 | template: "<acme-navbar></acme-navbar>", |
| 113 | 115 | directives: [Navbar] |
| 114 | 116 | }) |
| 115 | 117 | .then(fixture => { |
| 116 | - console.log("entrou no .then") | |
| 117 | 118 | let navbarComp: Navbar = <Navbar>fixture.debugElement.componentViewChildren[0].componentInstance; |
| 118 | 119 | spyOn($modal, "open"); |
| 119 | - //navbarComp.activate(); | |
| 120 | 120 | navbarComp.openLogin(); |
| 121 | 121 | expect($modal.open).toHaveBeenCalled(); |
| 122 | 122 | expect($modal.open).toHaveBeenCalledWith({ |
| ... | ... | @@ -129,6 +129,22 @@ describe("Components", () => { |
| 129 | 129 | }) |
| 130 | 130 | }); |
| 131 | 131 | |
| 132 | + it('It should logout', (done: Function) => { | |
| 133 | + quickCreateComponent({ | |
| 134 | + providers: providers, | |
| 135 | + template: "<acme-navbar></acme-navbar>", | |
| 136 | + directives: [Navbar] | |
| 137 | + }) | |
| 138 | + .then(fixture => { | |
| 139 | + let navbarComp: Navbar = <Navbar>fixture.debugElement.componentViewChildren[0].componentInstance; | |
| 140 | + spyOn(authService, "logout"); | |
| 141 | + navbarComp.logout(); | |
| 142 | + expect(authService.logout).toHaveBeenCalled(); | |
| 143 | + done(); | |
| 144 | + }) | |
| 145 | + }); | |
| 146 | + | |
| 147 | + | |
| 132 | 148 | |
| 133 | 149 | // it('closes the modal the login', (done: Function) => { |
| 134 | 150 | // let scope = { | ... | ... |
src/app/components/noosfero/noosfero.service.js
| ... | ... | @@ -6,18 +6,7 @@ |
| 6 | 6 | |
| 7 | 7 | return { |
| 8 | 8 | currentProfile: currentProfile.promise, |
| 9 | - setCurrentProfile: function(profile) { currentProfile.resolve(profile) }, | |
| 10 | - profiles: Restangular.service('profiles'), | |
| 11 | - articles: Restangular.service('articles'), | |
| 12 | - profile: function(profileId) { | |
| 13 | - return Restangular.one('profiles', profileId); | |
| 14 | - }, | |
| 15 | - members: function(profile) { | |
| 16 | - return Restangular.service('members', profile); | |
| 17 | - }, | |
| 18 | - boxes: function(profileId) { | |
| 19 | - return Restangular.service('boxes', Restangular.one('profiles', profileId)) | |
| 20 | - } | |
| 9 | + setCurrentProfile: function(profile) { currentProfile.resolve(profile) } | |
| 21 | 10 | } |
| 22 | 11 | }); |
| 23 | 12 | })(); | ... | ... |
src/app/content-viewer/content-viewer.component.ts
| ... | ... | @@ -5,13 +5,14 @@ import {ArticleView} from "../components/noosfero-articles/article/article_view" |
| 5 | 5 | import {Input, Component, StateConfig, Inject} from "ng-forward"; |
| 6 | 6 | |
| 7 | 7 | import {ArticleBlog} from "./../components/noosfero-articles/blog/blog.component"; |
| 8 | +import {ArticleService} from "../../lib/ng-noosfero-api/http/article.service"; | |
| 8 | 9 | |
| 9 | 10 | @Component({ |
| 10 | 11 | selector: "content-viewer", |
| 11 | 12 | templateUrl: "app/content-viewer/page.html", |
| 12 | 13 | directives: [ArticleBlog, ArticleView] |
| 13 | 14 | }) |
| 14 | -@Inject("noosfero", "$log", "$stateParams") | |
| 15 | +@Inject(ArticleService, "noosfero", "$log", "$stateParams") | |
| 15 | 16 | export class ContentViewer { |
| 16 | 17 | |
| 17 | 18 | @Input() |
| ... | ... | @@ -20,14 +21,14 @@ export class ContentViewer { |
| 20 | 21 | @Input() |
| 21 | 22 | profile: noosfero.Profile = null; |
| 22 | 23 | |
| 23 | - constructor(private noosfero: any, private $log: ng.ILogService, private $stateParams: angular.ui.IStateParamsService) { | |
| 24 | + constructor(private ArticleService: ArticleService, private noosfero: any, private $log: ng.ILogService, private $stateParams: angular.ui.IStateParamsService) { | |
| 24 | 25 | this.activate(); |
| 25 | 26 | } |
| 26 | 27 | |
| 27 | 28 | activate() { |
| 28 | 29 | this.noosfero.currentProfile.then((profile: noosfero.Profile) => { |
| 29 | 30 | this.profile = profile; |
| 30 | - return this.noosfero.profiles.one(this.profile.id).one("articles").get({ path: this.$stateParams["page"] }); | |
| 31 | + return this.ArticleService.getByProfile(this.profile.id, { path: this.$stateParams["page"] }); | |
| 31 | 32 | }).then((response: restangular.IResponse) => { |
| 32 | 33 | this.article = response.data.article; |
| 33 | 34 | }); | ... | ... |
src/app/index.ts
| 1 | - | |
| 2 | - | |
| 3 | 1 | import {NoosferoApp} from "./index.module"; |
| 4 | 2 | import {noosferoModuleConfig} from "./index.config"; |
| 5 | 3 | import {noosferoAngularRunBlock} from "./index.run"; |
| 6 | 4 | import {routeConfig} from "./index.route"; |
| 7 | 5 | |
| 8 | -import {ContentViewer as noosferoContentViewer} from "./content-viewer/content-viewer.component"; | |
| 9 | -import {ContentViewerActions as noosferoContentViewerActions} from "./content-viewer/content-viewer-actions.component"; | |
| 10 | -import {Profile as noosferoProfile} from "./profile/profile.component"; | |
| 11 | -import {ProfileInfo as noosferoProfileInfo} from "./profile-info/profile-info.component"; | |
| 12 | -import {ProfileHome as noosferoProfileHome} from "./profile/profile-home.component"; | |
| 13 | -import {Cms as noosferoCms} from "./cms/cms.component"; | |
| 14 | - | |
| 15 | 6 | import {Main} from "./main/main.component"; |
| 16 | 7 | import {bootstrap, bundle} from "ng-forward"; |
| 17 | 8 | |
| ... | ... | @@ -41,15 +32,7 @@ NoosferoApp.run(noosferoAngularRunBlock); |
| 41 | 32 | // NoosferoApp.addService("AuthService", AuthService); |
| 42 | 33 | NoosferoApp.addController("AuthController", AuthController); |
| 43 | 34 | |
| 44 | - | |
| 45 | 35 | require("./components/noosfero/noosfero.service.js"); |
| 46 | 36 | require("./components/noosfero/profile-image/profile-image.component.js"); |
| 47 | 37 | |
| 48 | -NoosferoApp.addController("ContentViewerController", noosferoContentViewer); | |
| 49 | -NoosferoApp.addController("ContentViewerActionsController", noosferoContentViewerActions); | |
| 50 | -NoosferoApp.addController("ProfileController", noosferoProfile); | |
| 51 | -NoosferoApp.addController("ProfileHomeController", noosferoProfileHome); | |
| 52 | -NoosferoApp.addController("ProfileInfoController", noosferoProfileInfo); | |
| 53 | -NoosferoApp.addController("CmsController", noosferoCms); | |
| 54 | - | |
| 55 | 38 | NoosferoApp.addConfig(routeConfig); | ... | ... |
src/app/main/main.component.ts
src/app/profile-info/profile-info.component.ts
| 1 | 1 | import {StateConfig, Component, Inject} from 'ng-forward'; |
| 2 | 2 | |
| 3 | 3 | import {Profile} from "./../models/interfaces"; |
| 4 | +import {ProfileService} from "../../lib/ng-noosfero-api/http/profile.service"; | |
| 4 | 5 | |
| 5 | 6 | @Component({ |
| 6 | 7 | selector: 'profile', |
| 7 | 8 | templateUrl: "app/profile-info/profile-info.html" |
| 8 | 9 | }) |
| 9 | -@Inject("noosfero") | |
| 10 | +@Inject(ProfileService, "noosfero") | |
| 10 | 11 | export class ProfileInfo { |
| 11 | 12 | |
| 12 | 13 | activities: any |
| 13 | 14 | profile: any |
| 14 | 15 | |
| 15 | - constructor(private noosfero: any) { | |
| 16 | + constructor(private ProfileService: ProfileService, private noosfero: any) { | |
| 16 | 17 | this.activate(); |
| 17 | 18 | } |
| 18 | 19 | |
| 19 | 20 | activate() { |
| 20 | 21 | this.noosfero.currentProfile.then((profile: Profile) => { |
| 21 | 22 | this.profile = profile; |
| 22 | - return this.noosfero.profiles.one(this.profile.id).one('activities').get(); | |
| 23 | + return this.ProfileService.getActivities(this.profile.id); | |
| 23 | 24 | }).then((response: restangular.IResponse) => { |
| 24 | 25 | this.activities = response.data.activities; |
| 25 | 26 | }); | ... | ... |
src/app/profile/profile-home.component.ts
| 1 | 1 | import {StateConfig, Component, Inject} from 'ng-forward'; |
| 2 | 2 | |
| 3 | 3 | import {Profile} from "./../models/interfaces"; |
| 4 | +import {ProfileService} from "../../lib/ng-noosfero-api/http/profile.service"; | |
| 4 | 5 | |
| 5 | 6 | @Component({ |
| 6 | 7 | selector: 'profile-home', |
| 7 | 8 | template: "<div></div>" |
| 8 | 9 | }) |
| 9 | -@Inject("noosfero", "$log", "$stateParams", "$scope", "$state") | |
| 10 | +@Inject(ProfileService, "noosfero", "$log", "$stateParams", "$scope", "$state") | |
| 10 | 11 | export class ProfileHome { |
| 11 | 12 | |
| 12 | 13 | profile: Profile; |
| 13 | 14 | |
| 14 | - constructor(noosfero: any, $log: ng.ILogService, $stateParams: ng.ui.IStateParamsService, $scope: ng.IScope, $state: ng.ui.IStateService) { | |
| 15 | + constructor(ProfileService: ProfileService, noosfero: any, $log: ng.ILogService, $stateParams: ng.ui.IStateParamsService, $scope: ng.IScope, $state: ng.ui.IStateService) { | |
| 15 | 16 | noosfero.currentProfile.then((profile: Profile) => { |
| 16 | 17 | this.profile = profile; |
| 17 | - return noosfero.profile(this.profile.id).customGET('home_page', { fields: 'path' }); | |
| 18 | + return ProfileService.get(this.profile.id).customGET('home_page', { fields: 'path' }); | |
| 18 | 19 | }).then((response: restangular.IResponse) => { |
| 19 | 20 | if (response.data.article) { |
| 20 | 21 | $state.transitionTo('main.profile.page', { page: response.data.article.path, profile: this.profile.identifier }, { location: false }); | ... | ... |
src/app/profile/profile.component.ts
| ... | ... | @@ -3,7 +3,9 @@ import {ProfileInfo} from '../profile-info/profile-info.component'; |
| 3 | 3 | import {ProfileHome} from '../profile/profile-home.component'; |
| 4 | 4 | import {Cms} from '../cms/cms.component'; |
| 5 | 5 | import {ContentViewer} from "../content-viewer/content-viewer.component"; |
| 6 | +import {ContentViewerActions} from "../content-viewer/content-viewer-actions.component"; | |
| 6 | 7 | import {NoosferoActivities} from "../components/noosfero-activities/activities.component"; |
| 8 | +import {ProfileService} from "../../lib/ng-noosfero-api/http/profile.service"; | |
| 7 | 9 | |
| 8 | 10 | import * as noosferoModels from "./../models/interfaces"; |
| 9 | 11 | |
| ... | ... | @@ -20,7 +22,7 @@ import * as noosferoModels from "./../models/interfaces"; |
| 20 | 22 | views: { |
| 21 | 23 | "mainBlockContent": { |
| 22 | 24 | templateUrl: "app/profile-info/profile-info.html", |
| 23 | - controller: "ProfileInfoController", | |
| 25 | + controller: ProfileInfo, | |
| 24 | 26 | controllerAs: "vm" |
| 25 | 27 | } |
| 26 | 28 | } |
| ... | ... | @@ -32,7 +34,7 @@ import * as noosferoModels from "./../models/interfaces"; |
| 32 | 34 | views: { |
| 33 | 35 | "mainBlockContent": { |
| 34 | 36 | templateUrl: "app/cms/cms.html", |
| 35 | - controller: "CmsController", | |
| 37 | + controller: Cms, | |
| 36 | 38 | controllerAs: "vm" |
| 37 | 39 | } |
| 38 | 40 | } |
| ... | ... | @@ -43,7 +45,7 @@ import * as noosferoModels from "./../models/interfaces"; |
| 43 | 45 | component: ProfileHome, |
| 44 | 46 | views: { |
| 45 | 47 | "mainBlockContent": { |
| 46 | - controller: "ProfileHomeController", | |
| 48 | + controller: ProfileHome, | |
| 47 | 49 | controllerAs: "vm" |
| 48 | 50 | } |
| 49 | 51 | } |
| ... | ... | @@ -55,28 +57,28 @@ import * as noosferoModels from "./../models/interfaces"; |
| 55 | 57 | views: { |
| 56 | 58 | "mainBlockContent": { |
| 57 | 59 | templateUrl: "app/content-viewer/page.html", |
| 58 | - controller: "ContentViewerController", | |
| 60 | + controller: ContentViewer, | |
| 59 | 61 | controllerAs: "vm" |
| 60 | 62 | }, |
| 61 | 63 | "actions@main": { |
| 62 | 64 | templateUrl: "app/content-viewer/navbar-actions.html", |
| 63 | - controller: "ContentViewerActionsController", | |
| 65 | + controller: ContentViewerActions, | |
| 64 | 66 | controllerAs: "vm" |
| 65 | 67 | } |
| 66 | 68 | } |
| 67 | 69 | } |
| 68 | 70 | ]) |
| 69 | -@Inject("noosfero", "$log", "$stateParams") | |
| 71 | +@Inject(ProfileService, "noosfero", "$log", "$stateParams") | |
| 70 | 72 | export class Profile { |
| 71 | 73 | |
| 72 | 74 | boxes: noosferoModels.Box[]; |
| 73 | 75 | profile: noosferoModels.Profile; |
| 74 | 76 | |
| 75 | - constructor(noosfero: any, $log: ng.ILogService, $stateParams: ng.ui.IStateParamsService) { | |
| 76 | - noosfero.profiles.one().get({ identifier: $stateParams["profile"] }).then((response: restangular.IResponse) => { | |
| 77 | + constructor(ProfileService: ProfileService, noosfero: any, $log: ng.ILogService, $stateParams: ng.ui.IStateParamsService) { | |
| 78 | + ProfileService.getByIdentifier($stateParams["profile"]).then((response: restangular.IResponse) => { | |
| 77 | 79 | this.profile = response.data[0]; |
| 78 | 80 | noosfero.setCurrentProfile(this.profile); |
| 79 | - return noosfero.boxes(this.profile.id).one().get(); | |
| 81 | + return ProfileService.getBoxes(this.profile.id); | |
| 80 | 82 | }).then((response: restangular.IResponse) => { |
| 81 | 83 | this.boxes = response.data.boxes; |
| 82 | 84 | }); | ... | ... |
src/lib/ng-noosfero-api/http/article.service.ts
| 1 | 1 | import { Injectable, Inject } from "ng-forward"; |
| 2 | +import {Article} from "../../../app/models/interfaces"; | |
| 2 | 3 | |
| 3 | 4 | @Injectable() |
| 4 | 5 | @Inject("Restangular") |
| ... | ... | @@ -6,14 +7,25 @@ export class ArticleService { |
| 6 | 7 | |
| 7 | 8 | constructor(private Restangular: any) { } |
| 8 | 9 | |
| 9 | - getByProfile(profileId: number, filters: any) { | |
| 10 | - return this.Restangular.one('profiles', profileId).customGET('articles', filters); | |
| 10 | + create(profileId: number, article: Article) { | |
| 11 | + return this.Restangular.one('profiles', profileId).customPOST( | |
| 12 | + { article: article }, | |
| 13 | + 'articles', | |
| 14 | + {}, | |
| 15 | + { 'Content-Type': 'application/json' } | |
| 16 | + ); | |
| 11 | 17 | } |
| 12 | 18 | |
| 13 | - getChildren(id: number, filters: any) { | |
| 14 | - return this.Restangular.service('articles').one(id).customGET('children', filters); | |
| 19 | + get(articleId: number) { | |
| 20 | + return this.Restangular.one('articles', articleId); | |
| 15 | 21 | } |
| 16 | 22 | |
| 23 | + getByProfile(profileId: number, filters: any) { | |
| 24 | + return this.Restangular.one('profiles', profileId).customGET('articles', filters); | |
| 25 | + } | |
| 17 | 26 | |
| 27 | + getChildren(articleId: number, options: any = {}) { | |
| 28 | + return this.get(articleId).customGET('children', options); | |
| 29 | + } | |
| 18 | 30 | |
| 19 | 31 | } | ... | ... |
src/lib/ng-noosfero-api/http/profile.service.ts
| ... | ... | @@ -8,8 +8,24 @@ export class ProfileService { |
| 8 | 8 | |
| 9 | 9 | } |
| 10 | 10 | |
| 11 | + getActivities(profileId: number, options: any = {}) { | |
| 12 | + return this.get(profileId).customGET("activities", options); | |
| 13 | + } | |
| 14 | + | |
| 15 | + get(profileId: number) { | |
| 16 | + return this.Restangular.one('profiles', profileId); | |
| 17 | + } | |
| 18 | + | |
| 11 | 19 | getProfileMembers(profileId: number, filters: any) { |
| 12 | - return this.Restangular.service('profiles').one(profileId).customGET("members", filters); | |
| 20 | + return this.get(profileId).customGET("members", filters); | |
| 21 | + } | |
| 22 | + | |
| 23 | + getByIdentifier(identifier: string) { | |
| 24 | + return this.Restangular.one('profiles').get({ identifier: identifier }); | |
| 25 | + } | |
| 26 | + | |
| 27 | + getBoxes(profileId: number) { | |
| 28 | + return this.get(profileId).customGET('boxes'); | |
| 13 | 29 | } |
| 14 | 30 | |
| 15 | 31 | } | ... | ... |