diff --git a/src/app/environment/environment-home.component.ts b/src/app/environment/environment-home.component.ts
new file mode 100644
index 0000000..baffb31
--- /dev/null
+++ b/src/app/environment/environment-home.component.ts
@@ -0,0 +1,41 @@
+import {Component, Inject, provide} from 'ng-forward';
+import {EnvironmentService} from "../../lib/ng-noosfero-api/http/environment.service";
+import {NotificationService} from "../shared/services/notification.service";
+
+/**
+ * @ngdoc controller
+ * @name environment.Environment
+ * @description
+ * This is the environment controller.
+ */
+@Component({
+ selector: 'environment-home',
+ templateUrl: "app/environment/environment-home.html",
+ providers: [
+ provide('environmentService', { useClass: EnvironmentService }),
+ provide('notificationService', { useClass: NotificationService })
+ ]
+})
+@Inject(EnvironmentService, "$log", "$sce")
+export class EnvironmentHomeComponent {
+
+ environment: noosfero.Environment;
+
+ constructor(private environmentService: EnvironmentService, private $sce: ng.ISCEService) {
+ console.debug("Constructor from EnvironmentHomeComponent");
+
+ environmentService.getByIdentifier("default").then((result: noosfero.Environment) => {
+ this.environment = result;
+ console.debug("Environment ::", result);
+ })
+ }
+
+ getEnvironmentDescription() {
+ if(this.environment && this.environment.settings && this.environment.settings.description){
+ return this.$sce.trustAsHtml(this.environment.settings.description);
+ }
+ else {
+ return "";
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/app/environment/environment-home.html b/src/app/environment/environment-home.html
new file mode 100644
index 0000000..4aa1685
--- /dev/null
+++ b/src/app/environment/environment-home.html
@@ -0,0 +1,2 @@
+
+
\ No newline at end of file
diff --git a/src/app/environment/environment.component.ts b/src/app/environment/environment.component.ts
new file mode 100644
index 0000000..fee1d30
--- /dev/null
+++ b/src/app/environment/environment.component.ts
@@ -0,0 +1,54 @@
+import {StateConfig, Component, Inject, provide} from 'ng-forward';
+import {EnvironmentService} from "../../lib/ng-noosfero-api/http/environment.service";
+import {NotificationService} from "../shared/services/notification.service";
+import {EnvironmentHomeComponent} from "./environment-home.component";
+
+/**
+ * @ngdoc controller
+ * @name environment.Environment
+ * @description
+ * This is the environment controller.
+ */
+@Component({
+ selector: 'environment',
+ templateUrl: "app/environment/environment.html",
+ providers: [
+ provide('environmentService', { useClass: EnvironmentService }),
+ provide('notificationService', { useClass: NotificationService })
+ ]
+})
+@StateConfig([
+ {
+ name: 'main.environment.home',
+ url: "",
+ component: EnvironmentHomeComponent,
+ views: {
+ "mainBlockContent": {
+ templateUrl: "app/environment/environment-home.html",
+ controller: EnvironmentHomeComponent,
+ controllerAs: "vm"
+ }
+ }
+ }
+])
+@Inject(EnvironmentService, "$state")
+export class EnvironmentComponent {
+
+ boxes: noosfero.Box[];
+ environment: noosfero.Environment;
+
+ constructor(environmentService: EnvironmentService, $state: ng.ui.IStateService, notificationService: NotificationService) {
+ //console.debug("Creating EnvironmentComponent...");
+ let boxesPromisse = environmentService.getByIdentifier("default").then((environment: noosfero.Environment) => {
+ //console.debug("Set current environment by identifier callback.: ", environment);
+ this.environment = environment;
+ return environmentService.getBoxes(this.environment.id);
+ }).then((boxes: noosfero.Box[]) => {
+ //console.debug("Set environment boxes in callback: ", boxes);
+ this.boxes = boxes;
+ }).catch(() => {
+ $state.transitionTo('main');
+ notificationService.error({ message: "notification.environment.not_found" });
+ });
+ }
+}
diff --git a/src/app/environment/environment.html b/src/app/environment/environment.html
new file mode 100644
index 0000000..fb560ba
--- /dev/null
+++ b/src/app/environment/environment.html
@@ -0,0 +1,5 @@
+
diff --git a/src/app/main/main.component.ts b/src/app/main/main.component.ts
index 837c567..07f111b 100644
--- a/src/app/main/main.component.ts
+++ b/src/app/main/main.component.ts
@@ -6,12 +6,16 @@ import {ArticleViewComponent} from "./../article/article-default-view.component"
import {ProfileComponent} from "../profile/profile.component";
import {BoxesComponent} from "../layout/boxes/boxes.component";
import {BlockComponent} from "../layout/blocks/block.component";
+import {EnvironmentComponent} from "../environment/environment.component";
+import {EnvironmentHomeComponent} from "../environment/environment-home.component";
+
import {LinkListBlockComponent} from "./../layout/blocks/link-list/link-list.component";
import {RecentDocumentsBlockComponent} from "../layout/blocks/recent-documents/recent-documents.component";
import {ProfileImageBlockComponent} from "../layout/blocks/profile-image-block/profile-image-block.component";
import {RawHTMLBlockComponent} from "../layout/blocks/raw-html/raw-html.component";
import {MembersBlockComponent} from "./../layout/blocks/members-block/members-block.component";
+import {PeopleBlockComponent} from "./../layout/blocks/people-block/people-block.component";
import {NoosferoTemplate} from "../shared/pipes/noosfero-template.filter";
import {DateFormat} from "../shared/pipes/date-format.filter";
@@ -34,7 +38,7 @@ import {MainBlockComponent} from "../layout/blocks/main-block/main-block.compone
* This controller actually contains the main content of Noosfero Angular Theme:
* - the navbar
* - the {@link Main} view content
- *
+ *
*/
@Component({
selector: 'main-content',
@@ -45,6 +49,15 @@ export class MainContentComponent {
}
+@Component({
+ selector: 'environment-content',
+ templateUrl: "app/main/main.html",
+ providers: [AuthService, SessionService]
+})
+export class EnvironmentContent {
+
+}
+
/**
* @ngdoc controller
* @name main.Main
@@ -63,19 +76,35 @@ export class MainContentComponent {
selector: 'main',
template: '',
directives: [
- ArticleBlogComponent, ArticleViewComponent, BoxesComponent, BlockComponent, LinkListBlockComponent,
+ ArticleBlogComponent, ArticleViewComponent, BoxesComponent, BlockComponent,
+ EnvironmentComponent,
+ LinkListBlockComponent,
MainBlockComponent, RecentDocumentsBlockComponent, Navbar, ProfileImageBlockComponent,
- MembersBlockComponent, NoosferoTemplate, DateFormat, RawHTMLBlockComponent
+ MembersBlockComponent, PeopleBlockComponent, NoosferoTemplate, DateFormat, RawHTMLBlockComponent
],
providers: [AuthService, SessionService, NotificationService]
})
@StateConfig([
{
- url: '/',
- component: MainContentComponent,
+ url: '',
+ component: MainContentComponent,
+ abstract: true,
name: 'main',
},
{
+ url: '/',
+ component: EnvironmentComponent,
+ name: 'main.environment',
+ abstract: true,
+ views: {
+ "content": {
+ templateUrl: "app/environment/environment.html",
+ controller: EnvironmentComponent,
+ controllerAs: "vm"
+ }
+ }
+ },
+ {
url: "^/:profile",
abstract: true,
component: ProfileComponent,
diff --git a/src/lib/ng-noosfero-api/http/environment.service.ts b/src/lib/ng-noosfero-api/http/environment.service.ts
new file mode 100644
index 0000000..8ec6250
--- /dev/null
+++ b/src/lib/ng-noosfero-api/http/environment.service.ts
@@ -0,0 +1,98 @@
+import { Injectable, Inject } from "ng-forward";
+
+@Injectable()
+@Inject("Restangular", "$q")
+export class EnvironmentService {
+
+ private _currentEnvironmentPromise: ng.IDeferred;
+
+ constructor(private restangular: restangular.IService, private $q: ng.IQService) {
+
+ }
+
+ getEnvironmentPeople(params: any) : ng.IPromise {
+ let p = this.restangular.one('people').get(params);
+ let deferred = this.$q.defer();
+ p.then(this.getHandleSuccessFunctionKeyArray("people", deferred));
+ p.catch(this.getHandleErrorFunction(deferred));
+ return deferred.promise;
+ }
+
+ getByIdentifier(identifier: string): ng.IPromise {
+ console.debug("Getting the current environment by identifier in service: " + identifier);
+ let p = this.restangular.one('environment').customGET(identifier);
+ console.debug("Return promise: ", p);
+
+ let deferred = this.$q.defer();
+ p.then(this.getHandleSuccessFunction(deferred));
+ p.catch(this.getHandleErrorFunction(deferred));
+ return deferred.promise;
+ }
+
+ getBoxes(id: number) {
+ console.debug("Getting the environment [${id}] boxes in service", id);
+ let p = this.restangular.one('environments', id).customGET("boxes");
+ console.debug("Return boxes promise in service: ", p);
+
+ let deferred = this.$q.defer();
+ p.then(this.getHandleSuccessFunctionKeyArray("boxes", deferred));
+ p.catch(this.getHandleErrorFunction(deferred));
+ return deferred.promise;
+ }
+
+ /** TODO - Please, use the base class RestangularService
+ * (description)
+ *
+ * @template T
+ * @param {ng.IDeferred} deferred (description)
+ * @returns {(response: restangular.IResponse) => void} (description)
+ */
+ getHandleErrorFunction(deferred: ng.IDeferred): (response: restangular.IResponse) => void {
+ let self = this;
+ /**
+ * (description)
+ *
+ * @param {restangular.IResponse} response (description)
+ */
+ let errorFunction = (response: restangular.IResponse): void => {
+ deferred.reject(response);
+ };
+ return errorFunction;
+ }
+
+ /**
+ * TODO - use restangular service as base class, and this will not be necessary here anymore
+ */
+ protected getHandleSuccessFunction(deferred: ng.IDeferred, responseKey?: string): (response: restangular.IResponse) => void {
+ let self = this;
+
+ /**
+ * (description)
+ *
+ * @param {restangular.IResponse} response (description)
+ */
+ let successFunction = (response: restangular.IResponse): void => {
+ let data = this.restangular.stripRestangular(response.data)
+ deferred.resolve(data);
+ };
+ return successFunction;
+ }
+
+ /**
+ * TODO - use restangular service as base class, and this will not be necessary here anymore
+ */
+ protected getHandleSuccessFunctionKeyArray(key: string, deferred: ng.IDeferred, responseKey?: string): (response: restangular.IResponse) => void {
+ let self = this;
+
+ /**
+ * (description)
+ *
+ * @param {restangular.IResponse} response (description)
+ */
+ let successFunction = (response: restangular.IResponse): void => {
+ let data = this.restangular.stripRestangular(response.data[key]);
+ deferred.resolve(data);
+ };
+ return successFunction;
+ }
+}
diff --git a/src/lib/ng-noosfero-api/interfaces/environment.ts b/src/lib/ng-noosfero-api/interfaces/environment.ts
index a9c0220..14a8585 100644
--- a/src/lib/ng-noosfero-api/interfaces/environment.ts
+++ b/src/lib/ng-noosfero-api/interfaces/environment.ts
@@ -1,5 +1,19 @@
namespace noosfero {
+ /**
+ * @ngdoc interface
+ * @name noofero.Environment
+ * @description
+ * A representation of a Noosfero Environment.
+ */
export interface Environment extends RestModel {
+ /**
+ * @ngdoc property
+ * @name id
+ * @propertyOf noofero.Environment
+ * @returns {number} The Environment id
+ */
+ id: number;
+ settings: any
}
}
\ No newline at end of file
--
libgit2 0.21.2