FRM PR

From mn/ifi/inf5750
Revision as of 13:58, 14 November 2015 by Erikhf@uio.no (talk | contribs) (Created page with "== #1 == ===Status=== MERGET ===PQ=== The following changes since commit 1e6ce2f50c69ca191a07aaad996f4deb464880f8: Fixed map (pair programming) (2015-11-12 14:11:13 +01...")

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

#1

Status

MERGET

PQ

The following changes since commit 1e6ce2f50c69ca191a07aaad996f4deb464880f8:

  Fixed map  (pair programming) (2015-11-12 14:11:13 +0100) 
 
are available in the git repository at:

  gitolite@git.uio.no:u/erikhf/frm.git apiService

for you to fetch changes up to aca80f6a97807505358ebe0d62d58e3de67252c3:

  [apiService] created a service for getting the API URL (2015-11-14 13:43:58 +0100)

----------------------------------------------------------------
Erik Haider Forsén (1):
      [apiService] created a service for getting the API URL

src/components/app.ts                    | 11 +++++++++--
src/components/dhisapi/dhisapiService.ts | 18 ++++++++++++++++++
src/components/filter/filter.ts          | 16 +++++++++++++++-
src/index.html                           |  8 +-------
4 files changed, 43 insertions(+), 10 deletions(-)
create mode 100644 src/components/dhisapi/dhisapiService.ts

diff --git a/src/components/app.ts b/src/components/app.ts
index cb9479e..a3d4fd3 100644 
--- a/src/components/app.ts
+++ b/src/components/app.ts
@@ -3,6 +3,7 @@ import {Component, View, bootstrap, provide} from 'angular2/angular2';
import {Map} from './map/map';
import {Search} from "./search/search";
import {Filter} from "./filter/filter";
+import {DhisapiService} from "./dhisapi/dhisapiService";

declare var System:any;

@@ -10,12 +11,18 @@ declare var System:any;
    {
        selector: 'mou-app',
        templateUrl: './components/app.html',
-        directives:[Filter, Map, Search]
+        directives:[Filter, Map, Search],
+        providers: [DhisapiService]
     })


class App {
+    construector(dhis: DhisapiService){
+        dhis.getApiURL(function(uri){
+            console.log(uri);
+        })
+    }

}

-bootstrap(App,[HTTP_PROVIDERS]);
\ No newline at end of file
+bootstrap(App,[HTTP_PROVIDERS,DhisapiService]);
diff --git a/src/components/dhisapi/dhisapiService.ts b/src/components/dhisapi/dhisapiService.ts
new file mode 100644
index 0000000..38f9c4b
--- /dev/null
+++ b/src/components/dhisapi/dhisapiService.ts
@@ -0,0 +1,18 @@
+import {Injectable} from 'angular2/angular2';
+import {Http} from 'angular2/http';
+
+@Injectable()
+export class DhisapiService {
+    private http: Http;
+
+    constructor(http: Http){
+        this.http = http;
+    }
+
+    getApiURL = function(callback){
+        this.http.get('../manifest.webapp')
+            .map(res => res.json())
+            .map(res => res.activities.dhis.href)
+            .subscribe( res => callback(res));
+    }
+}
diff --git a/src/components/filter/filter.ts b/src/components/filter/filter.ts
index a3a63b7..9181b79 100644
--- a/src/components/filter/filter.ts
+++ b/src/components/filter/filter.ts
@@ -1,15 +1,18 @@
import {Component, View, CORE_DIRECTIVES} from 'angular2/angular2';
import {Headers, Http} from 'angular2/http';
+import {DhisapiService} from "../dhisapi/dhisapiService";

@Component({
    selector: 'mou-filter',
    directives: [CORE_DIRECTIVES],
-    templateUrl: './components/filter/filter.html'
+    templateUrl: './components/filter/filter.html',
+    providers: [DhisapiService]
})

export class Filter {
    result: Object;

+    dhis: DhisapiService;
    // Example HTTP request

    /*
@@ -31,4 +34,15 @@ export class Filter {
    }

    */
+
+    constructor(dhis: DhisapiService){
+        this.dhis = dhis;
+    }
+
+    onInit(){
+        this.dhis.getApiURL(function(uri){
+            console.log("Dette er uri: " + uri);
+        })
+    }
+
 }
diff --git a/src/index.html b/src/index.html
index c712323..3b1e667 100644
--- a/src/index.html
+++ b/src/index.html
@@ -3,13 +3,7 @@
<head>
    <meta charset="UTF-8">
    <title>Sample App</title>
-    <script>
-        var xhReq = new XMLHttpRequest();
-        xhReq.open("GET", "../manifest.webapp", false);
-        xhReq.send(null);
-        var serverResponse = JSON.parse(xhReq.responseText);
-        var dhisAPI = serverResponse.activities.dhis.href;
-    </script>
 +
    <script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyDlgw6kZAQvD8ex_md-6wb_NcnVlZWkbE4"></script>
    <script src="../node_modules/systemjs/dist/system.src.js"></script>
    <script src="../node_modules/angular2/bundles/angular2.dev.js"></script>