Commit 60acdbeefdb163dbadbc39cac19467d8996fa399
Exists in
master
and in
30 other branches
Merge branch 'master' of softwarepublico.gov.br:noosfero-themes/angular-theme
Conflicts: src/app/main/main.component.ts
Showing
7 changed files
with
248 additions
and
5 deletions
Show diff stats
@@ -0,0 +1,41 @@ | @@ -0,0 +1,41 @@ | ||
1 | +import {Component, Inject, provide} from 'ng-forward'; | ||
2 | +import {EnvironmentService} from "../../lib/ng-noosfero-api/http/environment.service"; | ||
3 | +import {NotificationService} from "../shared/services/notification.service"; | ||
4 | + | ||
5 | +/** | ||
6 | + * @ngdoc controller | ||
7 | + * @name environment.Environment | ||
8 | + * @description | ||
9 | + * This is the environment controller. | ||
10 | + */ | ||
11 | +@Component({ | ||
12 | + selector: 'environment-home', | ||
13 | + templateUrl: "app/environment/environment-home.html", | ||
14 | + providers: [ | ||
15 | + provide('environmentService', { useClass: EnvironmentService }), | ||
16 | + provide('notificationService', { useClass: NotificationService }) | ||
17 | + ] | ||
18 | +}) | ||
19 | +@Inject(EnvironmentService, "$log", "$sce") | ||
20 | +export class EnvironmentHomeComponent { | ||
21 | + | ||
22 | + environment: noosfero.Environment; | ||
23 | + | ||
24 | + constructor(private environmentService: EnvironmentService, private $sce: ng.ISCEService) { | ||
25 | + console.debug("Constructor from EnvironmentHomeComponent"); | ||
26 | + | ||
27 | + environmentService.getByIdentifier("default").then((result: noosfero.Environment) => { | ||
28 | + this.environment = result; | ||
29 | + console.debug("Environment ::", result); | ||
30 | + }) | ||
31 | + } | ||
32 | + | ||
33 | + getEnvironmentDescription() { | ||
34 | + if(this.environment && this.environment.settings && this.environment.settings.description){ | ||
35 | + return this.$sce.trustAsHtml(this.environment.settings.description); | ||
36 | + } | ||
37 | + else { | ||
38 | + return ""; | ||
39 | + } | ||
40 | + } | ||
41 | +} | ||
0 | \ No newline at end of file | 42 | \ No newline at end of file |
@@ -0,0 +1,54 @@ | @@ -0,0 +1,54 @@ | ||
1 | +import {StateConfig, Component, Inject, provide} from 'ng-forward'; | ||
2 | +import {EnvironmentService} from "../../lib/ng-noosfero-api/http/environment.service"; | ||
3 | +import {NotificationService} from "../shared/services/notification.service"; | ||
4 | +import {EnvironmentHomeComponent} from "./environment-home.component"; | ||
5 | + | ||
6 | +/** | ||
7 | + * @ngdoc controller | ||
8 | + * @name environment.Environment | ||
9 | + * @description | ||
10 | + * This is the environment controller. | ||
11 | + */ | ||
12 | +@Component({ | ||
13 | + selector: 'environment', | ||
14 | + templateUrl: "app/environment/environment.html", | ||
15 | + providers: [ | ||
16 | + provide('environmentService', { useClass: EnvironmentService }), | ||
17 | + provide('notificationService', { useClass: NotificationService }) | ||
18 | + ] | ||
19 | +}) | ||
20 | +@StateConfig([ | ||
21 | + { | ||
22 | + name: 'main.environment.home', | ||
23 | + url: "", | ||
24 | + component: EnvironmentHomeComponent, | ||
25 | + views: { | ||
26 | + "mainBlockContent": { | ||
27 | + templateUrl: "app/environment/environment-home.html", | ||
28 | + controller: EnvironmentHomeComponent, | ||
29 | + controllerAs: "vm" | ||
30 | + } | ||
31 | + } | ||
32 | + } | ||
33 | +]) | ||
34 | +@Inject(EnvironmentService, "$state") | ||
35 | +export class EnvironmentComponent { | ||
36 | + | ||
37 | + boxes: noosfero.Box[]; | ||
38 | + environment: noosfero.Environment; | ||
39 | + | ||
40 | + constructor(environmentService: EnvironmentService, $state: ng.ui.IStateService, notificationService: NotificationService) { | ||
41 | + //console.debug("Creating EnvironmentComponent..."); | ||
42 | + let boxesPromisse = environmentService.getByIdentifier("default").then((environment: noosfero.Environment) => { | ||
43 | + //console.debug("Set current environment by identifier callback.: ", environment); | ||
44 | + this.environment = environment; | ||
45 | + return environmentService.getBoxes(this.environment.id); | ||
46 | + }).then((boxes: noosfero.Box[]) => { | ||
47 | + //console.debug("Set environment boxes in callback: ", boxes); | ||
48 | + this.boxes = boxes; | ||
49 | + }).catch(() => { | ||
50 | + $state.transitionTo('main'); | ||
51 | + notificationService.error({ message: "notification.environment.not_found" }); | ||
52 | + }); | ||
53 | + } | ||
54 | +} |
src/app/main/main.component.ts
@@ -6,12 +6,16 @@ import {ArticleViewComponent} from "./../article/article-default-view.component" | @@ -6,12 +6,16 @@ import {ArticleViewComponent} from "./../article/article-default-view.component" | ||
6 | import {ProfileComponent} from "../profile/profile.component"; | 6 | import {ProfileComponent} from "../profile/profile.component"; |
7 | import {BoxesComponent} from "../layout/boxes/boxes.component"; | 7 | import {BoxesComponent} from "../layout/boxes/boxes.component"; |
8 | import {BlockComponent} from "../layout/blocks/block.component"; | 8 | import {BlockComponent} from "../layout/blocks/block.component"; |
9 | +import {EnvironmentComponent} from "../environment/environment.component"; | ||
10 | +import {EnvironmentHomeComponent} from "../environment/environment-home.component"; | ||
11 | + | ||
9 | import {LinkListBlockComponent} from "./../layout/blocks/link-list/link-list.component"; | 12 | import {LinkListBlockComponent} from "./../layout/blocks/link-list/link-list.component"; |
10 | import {RecentDocumentsBlockComponent} from "../layout/blocks/recent-documents/recent-documents.component"; | 13 | import {RecentDocumentsBlockComponent} from "../layout/blocks/recent-documents/recent-documents.component"; |
11 | import {ProfileImageBlockComponent} from "../layout/blocks/profile-image-block/profile-image-block.component"; | 14 | import {ProfileImageBlockComponent} from "../layout/blocks/profile-image-block/profile-image-block.component"; |
12 | import {RawHTMLBlockComponent} from "../layout/blocks/raw-html/raw-html.component"; | 15 | import {RawHTMLBlockComponent} from "../layout/blocks/raw-html/raw-html.component"; |
13 | 16 | ||
14 | import {MembersBlockComponent} from "./../layout/blocks/members-block/members-block.component"; | 17 | import {MembersBlockComponent} from "./../layout/blocks/members-block/members-block.component"; |
18 | +import {PeopleBlockComponent} from "./../layout/blocks/people-block/people-block.component"; | ||
15 | import {CommunitiesBlockComponent} from "./../layout/blocks/communities-block/communities-block.component"; | 19 | import {CommunitiesBlockComponent} from "./../layout/blocks/communities-block/communities-block.component"; |
16 | import {NoosferoTemplate} from "../shared/pipes/noosfero-template.filter"; | 20 | import {NoosferoTemplate} from "../shared/pipes/noosfero-template.filter"; |
17 | import {DateFormat} from "../shared/pipes/date-format.filter"; | 21 | import {DateFormat} from "../shared/pipes/date-format.filter"; |
@@ -36,7 +40,7 @@ import {MainBlockComponent} from "../layout/blocks/main-block/main-block.compone | @@ -36,7 +40,7 @@ import {MainBlockComponent} from "../layout/blocks/main-block/main-block.compone | ||
36 | * This controller actually contains the main content of Noosfero Angular Theme: | 40 | * This controller actually contains the main content of Noosfero Angular Theme: |
37 | * - the navbar | 41 | * - the navbar |
38 | * - the {@link Main} view content | 42 | * - the {@link Main} view content |
39 | - * | 43 | + * |
40 | */ | 44 | */ |
41 | @Component({ | 45 | @Component({ |
42 | selector: 'main-content', | 46 | selector: 'main-content', |
@@ -50,6 +54,15 @@ export class MainContentComponent { | @@ -50,6 +54,15 @@ export class MainContentComponent { | ||
50 | } | 54 | } |
51 | } | 55 | } |
52 | 56 | ||
57 | +@Component({ | ||
58 | + selector: 'environment-content', | ||
59 | + templateUrl: "app/main/main.html", | ||
60 | + providers: [AuthService, SessionService] | ||
61 | +}) | ||
62 | +export class EnvironmentContent { | ||
63 | + | ||
64 | +} | ||
65 | + | ||
53 | /** | 66 | /** |
54 | * @ngdoc controller | 67 | * @ngdoc controller |
55 | * @name main.Main | 68 | * @name main.Main |
@@ -68,19 +81,35 @@ export class MainContentComponent { | @@ -68,19 +81,35 @@ export class MainContentComponent { | ||
68 | selector: 'main', | 81 | selector: 'main', |
69 | template: '<div ng-view></div>', | 82 | template: '<div ng-view></div>', |
70 | directives: [ | 83 | directives: [ |
71 | - ArticleBlogComponent, ArticleViewComponent, BoxesComponent, BlockComponent, LinkListBlockComponent, | 84 | + ArticleBlogComponent, ArticleViewComponent, BoxesComponent, BlockComponent, |
85 | + EnvironmentComponent, | ||
86 | + LinkListBlockComponent, CommunitiesBlockComponent | ||
72 | MainBlockComponent, RecentDocumentsBlockComponent, Navbar, ProfileImageBlockComponent, | 87 | MainBlockComponent, RecentDocumentsBlockComponent, Navbar, ProfileImageBlockComponent, |
73 | - MembersBlockComponent, NoosferoTemplate, DateFormat, RawHTMLBlockComponent, CommunitiesBlockComponent | 88 | + MembersBlockComponent, PeopleBlockComponent, NoosferoTemplate, DateFormat, RawHTMLBlockComponent |
74 | ], | 89 | ], |
75 | providers: [AuthService, SessionService, NotificationService, BodyStateClassesService] | 90 | providers: [AuthService, SessionService, NotificationService, BodyStateClassesService] |
76 | }) | 91 | }) |
77 | @StateConfig([ | 92 | @StateConfig([ |
78 | { | 93 | { |
79 | - url: '/', | ||
80 | - component: MainContentComponent, | 94 | + url: '', |
95 | + component: MainContentComponent, | ||
96 | + abstract: true, | ||
81 | name: 'main', | 97 | name: 'main', |
82 | }, | 98 | }, |
83 | { | 99 | { |
100 | + url: '/', | ||
101 | + component: EnvironmentComponent, | ||
102 | + name: 'main.environment', | ||
103 | + abstract: true, | ||
104 | + views: { | ||
105 | + "content": { | ||
106 | + templateUrl: "app/environment/environment.html", | ||
107 | + controller: EnvironmentComponent, | ||
108 | + controllerAs: "vm" | ||
109 | + } | ||
110 | + } | ||
111 | + }, | ||
112 | + { | ||
84 | url: "^/:profile", | 113 | url: "^/:profile", |
85 | abstract: true, | 114 | abstract: true, |
86 | component: ProfileComponent, | 115 | component: ProfileComponent, |
@@ -0,0 +1,98 @@ | @@ -0,0 +1,98 @@ | ||
1 | +import { Injectable, Inject } from "ng-forward"; | ||
2 | + | ||
3 | +@Injectable() | ||
4 | +@Inject("Restangular", "$q") | ||
5 | +export class EnvironmentService { | ||
6 | + | ||
7 | + private _currentEnvironmentPromise: ng.IDeferred<noosfero.Environment>; | ||
8 | + | ||
9 | + constructor(private restangular: restangular.IService, private $q: ng.IQService) { | ||
10 | + | ||
11 | + } | ||
12 | + | ||
13 | + getEnvironmentPeople(params: any) : ng.IPromise<noosfero.Person[]> { | ||
14 | + let p = this.restangular.one('people').get(params); | ||
15 | + let deferred = this.$q.defer<noosfero.Person[]>(); | ||
16 | + p.then(this.getHandleSuccessFunctionKeyArray<noosfero.Person[]>("people", deferred)); | ||
17 | + p.catch(this.getHandleErrorFunction<noosfero.Person[]>(deferred)); | ||
18 | + return deferred.promise; | ||
19 | + } | ||
20 | + | ||
21 | + getByIdentifier(identifier: string): ng.IPromise<noosfero.Environment> { | ||
22 | + console.debug("Getting the current environment by identifier in service: " + identifier); | ||
23 | + let p = this.restangular.one('environment').customGET(identifier); | ||
24 | + console.debug("Return promise: ", p); | ||
25 | + | ||
26 | + let deferred = this.$q.defer<noosfero.Environment>(); | ||
27 | + p.then(this.getHandleSuccessFunction<noosfero.Environment>(deferred)); | ||
28 | + p.catch(this.getHandleErrorFunction<noosfero.Environment>(deferred)); | ||
29 | + return deferred.promise; | ||
30 | + } | ||
31 | + | ||
32 | + getBoxes(id: number) { | ||
33 | + console.debug("Getting the environment [${id}] boxes in service", id); | ||
34 | + let p = this.restangular.one('environments', id).customGET("boxes"); | ||
35 | + console.debug("Return boxes promise in service: ", p); | ||
36 | + | ||
37 | + let deferred = this.$q.defer<noosfero.Box[]>(); | ||
38 | + p.then(this.getHandleSuccessFunctionKeyArray<noosfero.Box[]>("boxes", deferred)); | ||
39 | + p.catch(this.getHandleErrorFunction<noosfero.Box[]>(deferred)); | ||
40 | + return deferred.promise; | ||
41 | + } | ||
42 | + | ||
43 | + /** TODO - Please, use the base class RestangularService | ||
44 | + * (description) | ||
45 | + * | ||
46 | + * @template T | ||
47 | + * @param {ng.IDeferred<T>} deferred (description) | ||
48 | + * @returns {(response: restangular.IResponse) => void} (description) | ||
49 | + */ | ||
50 | + getHandleErrorFunction<T>(deferred: ng.IDeferred<T>): (response: restangular.IResponse) => void { | ||
51 | + let self = this; | ||
52 | + /** | ||
53 | + * (description) | ||
54 | + * | ||
55 | + * @param {restangular.IResponse} response (description) | ||
56 | + */ | ||
57 | + let errorFunction = (response: restangular.IResponse): void => { | ||
58 | + deferred.reject(response); | ||
59 | + }; | ||
60 | + return errorFunction; | ||
61 | + } | ||
62 | + | ||
63 | + /** | ||
64 | + * TODO - use restangular service as base class, and this will not be necessary here anymore | ||
65 | + */ | ||
66 | + protected getHandleSuccessFunction<C>(deferred: ng.IDeferred<C>, responseKey?: string): (response: restangular.IResponse) => void { | ||
67 | + let self = this; | ||
68 | + | ||
69 | + /** | ||
70 | + * (description) | ||
71 | + * | ||
72 | + * @param {restangular.IResponse} response (description) | ||
73 | + */ | ||
74 | + let successFunction = (response: restangular.IResponse): void => { | ||
75 | + let data = this.restangular.stripRestangular(response.data) | ||
76 | + deferred.resolve(data); | ||
77 | + }; | ||
78 | + return successFunction; | ||
79 | + } | ||
80 | + | ||
81 | + /** | ||
82 | + * TODO - use restangular service as base class, and this will not be necessary here anymore | ||
83 | + */ | ||
84 | + protected getHandleSuccessFunctionKeyArray<C>(key: string, deferred: ng.IDeferred<C>, responseKey?: string): (response: restangular.IResponse) => void { | ||
85 | + let self = this; | ||
86 | + | ||
87 | + /** | ||
88 | + * (description) | ||
89 | + * | ||
90 | + * @param {restangular.IResponse} response (description) | ||
91 | + */ | ||
92 | + let successFunction = (response: restangular.IResponse): void => { | ||
93 | + let data = this.restangular.stripRestangular(response.data[key]); | ||
94 | + deferred.resolve(data); | ||
95 | + }; | ||
96 | + return successFunction; | ||
97 | + } | ||
98 | +} |
src/lib/ng-noosfero-api/interfaces/environment.ts
1 | 1 | ||
2 | namespace noosfero { | 2 | namespace noosfero { |
3 | + /** | ||
4 | + * @ngdoc interface | ||
5 | + * @name noofero.Environment | ||
6 | + * @description | ||
7 | + * A representation of a Noosfero Environment. | ||
8 | + */ | ||
3 | export interface Environment extends RestModel { | 9 | export interface Environment extends RestModel { |
10 | + /** | ||
11 | + * @ngdoc property | ||
12 | + * @name id | ||
13 | + * @propertyOf noofero.Environment | ||
14 | + * @returns {number} The Environment id | ||
15 | + */ | ||
16 | + id: number; | ||
17 | + settings: any | ||
4 | } | 18 | } |
5 | } | 19 | } |
6 | \ No newline at end of file | 20 | \ No newline at end of file |