environment.component.ts
2.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
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";
import {SearchComponent} from "../search/search.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"
}
}
},
{
url: '^/search?query',
component: SearchComponent,
name: 'main.environment.search',
views: {
"mainBlockContent": {
templateUrl: "app/search/search.html",
controller: SearchComponent,
controllerAs: "ctrl"
}
}
}
])
@Inject(EnvironmentService, "$state", "currentEnvironment")
export class EnvironmentComponent {
boxes: noosfero.Box[];
environment: noosfero.Environment;
constructor(private environmentService: EnvironmentService, private $state: ng.ui.IStateService, private notificationService: NotificationService, currentEnvironment: noosfero.Environment) {
this.environment = currentEnvironment;
this.environmentService.getBoxes(this.environment.id)
.then((boxes: noosfero.Box[]) => {
this.boxes = boxes;
}).catch(() => {
this.$state.transitionTo('main');
this.notificationService.error({ message: "notification.environment.not_found" });
});
}
}