Fixed events between components
authorErik Haider Forsén <erikhf@ifi.uio.no>
Thu, 19 Nov 2015 19:48:30 +0000 (20:48 +0100)
committerErik Haider Forsén <erikhf@ifi.uio.no>
Thu, 19 Nov 2015 19:48:30 +0000 (20:48 +0100)
src/components/app.html
src/components/app.ts
src/components/map/map.ts
src/components/navbar/navbar.html
src/components/navbar/navbar.ts
src/components/search/search.ts
src/components/sidebar/sidebar.html [new file with mode: 0644]
src/components/sidebar/sidebar.ts [new file with mode: 0644]

index e524360..1be1056 100644 (file)
@@ -1,6 +1,14 @@
 <div class="container">
-    <mou-navbar></mou-navbar>
-    <mou-map #map></mou-map>
+    <mou-navbar (outevent)="map.update($event)"></mou-navbar>
+
+    <div class="row">
+        <div class="col-md-8">
+            <mou-map (newactive)="sidebar.update($event)" #map></mou-map>
+        </div>
+        <div class="col-md-4">
+            <mou-sidebar #sidebar></mou-sidebar>
+        </div>
+    </div>
 </div>
 
 
index f8bdea7..f8d69d0 100644 (file)
@@ -2,13 +2,14 @@ import {HTTP_PROVIDERS} from 'angular2/http';
 import {Component, View, bootstrap, provide, ELEMENT_PROBE_PROVIDERS} from 'angular2/angular2';
 import {Map} from './map/map';
 import {Navbar} from "./navbar/navbar";
+import {Sidebar} from "./sidebar/sidebar";
 
 declare var System:any;
 
 @Component({
     selector: 'mou-app',
     templateUrl: './components/app.html',
-    directives: [Map, Navbar]
+    directives: [Map, Navbar, Sidebar]
 })
 class App {}
 
index ebf20ba..91cc714 100644 (file)
@@ -1,10 +1,11 @@
-import {Component, CORE_DIRECTIVES,} from 'angular2/angular2';
+import {Component, EventEmitter,CORE_DIRECTIVES,} from 'angular2/angular2';
 import {Headers, Http} from 'angular2/http';
 
 
 @Component({
     selector: 'mou-map',
     directives: [CORE_DIRECTIVES],
+    events: ['newactive'],
     templateUrl: './components/map/map.html'
 })
 
@@ -16,7 +17,7 @@ export class Map {
     http: Http;
 
     constructor(http:Http) {
-
+        this.newactive = new EventEmitter();
         this.map = new google.maps.Map(document.getElementById("map"),{center: {lat:0,lng:0}, zoom:12});
         this.init();
         this.http = http;
@@ -174,7 +175,9 @@ export class Map {
         console.log('you just deleted the marker');
     }
 
-
+    update(event){
+        this.newactive.next(event);
+    }
 }
 
 
index ab8f70f..620df8e 100644 (file)
@@ -1,6 +1,6 @@
 <div id="navdiv" class="navbar navbar-default navbar-fixed-top">
 
-    <mou-search></mou-search>
+    <mou-search (newsearch)="inevent($event)"></mou-search>
 
 </div>
 
index b34ea77..6591410 100644 (file)
@@ -1,19 +1,22 @@
-import {Component,View, CORE_DIRECTIVES} from 'angular2/angular2';
+import {Component,View,EventEmitter, CORE_DIRECTIVES} from 'angular2/angular2';
 import {Search} from "../search/search";
 
 @Component({
     selector: 'mou-navbar',
     directives: [CORE_DIRECTIVES, Search],
     templateUrl: './components/navbar/navbar.html',
+    events:['outevent'],
     styleUrls: ['./components/navbar/navbar.css']
 })
 
 export class Navbar {
+    constructor(){
+        this.outevent = new EventEmitter();
+    }
 
-
-
-
-
+    inevent(e){
+        this.outevent.next(e);
+    }
 }
 
 
index 98e69aa..7039114 100644 (file)
@@ -19,6 +19,7 @@ export class Search {
     }
 
     getMoreInfo(orgunit) {
+        console.log("yolo");
         this.newsearch.next(orgunit.id);
     }
 
diff --git a/src/components/sidebar/sidebar.html b/src/components/sidebar/sidebar.html
new file mode 100644 (file)
index 0000000..875e2c2
--- /dev/null
@@ -0,0 +1,19 @@
+<div>
+    <div *ng-if="activeOrgUnit">
+        <div class="form-group">
+            <label>Name</label>
+            <input class="form-control" type="text" [(ng-model)]="activeOrgUnit.name" [disabled]="!editmode">
+        </div>
+        <div class="form-group">
+            <label>Shortname</label>
+            <input class="form-control" type="text" [(ng-model)]="activeOrgUnit.shortName" [disabled]="!editmode">
+        </div>
+        <fieldset class="form-group">
+            <legend>Group(s)</legend>
+            <div *ng-for="#group of activeOrgUnit.organisationUnitGroups">
+                <input class="form-control" type="text" [(ng-model)]="group.name" [disabled]="!editmode">
+            </div>
+        </fieldset>
+        <button class="btn btn-default" (click)="editmode = !editmode">Edit</button>
+    </div>
+</div>
\ No newline at end of file
diff --git a/src/components/sidebar/sidebar.ts b/src/components/sidebar/sidebar.ts
new file mode 100644 (file)
index 0000000..e023261
--- /dev/null
@@ -0,0 +1,27 @@
+import {Component, NgFor, NgIf, NgModel, CORE_DIRECTIVES,FORM_DIRECTIVES} from 'angular2/angular2';
+import {Http} from 'angular2/http';
+
+
+@Component({
+    selector: 'mou-sidebar',
+    directives: [CORE_DIRECTIVES,FORM_DIRECTIVES,NgFor,NgModel,NgIf],
+    templateUrl: './components/sidebar/sidebar.html'
+})
+export class Sidebar {
+    http: Http;
+    activeOrgUnit: Object;
+    editmode: boolean;
+
+    constructor(http:Http){
+        this.http = http;
+        this.editmode = false;
+    }
+
+    update(orgunitId){
+        console.log(orgunitId);
+        this.http.get(dhisAPI + "/api/organisationUnits/" + orgunitId)
+            .map(res => res.json())
+            .subscribe(res => this.activeOrgUnit = res)
+    }
+}
+