Przeglądaj źródła

Intermediate work on pulling data from Django JSON response - displaying JSON data on new page

David Leonard 10 lat temu
rodzic
commit
37baf2e7b4

+ 10 - 0
ionic/www/js/app.js

@@ -36,6 +36,16 @@ angular.module('starter', ['ionic', 'starter.controllers'])
     }
   })
 
+  .state('app.githubUser', {
+    url: "/githubUser",
+    views: {
+        'menuContent': {
+            templateUrl: "templates/githubUser.html",
+            controller: 'githubUserCtrl'
+        }
+    }
+  })
+
   // if none of the above states are matched, use this as the fallback
   $urlRouterProvider.otherwise('/app/sessions');
 });

+ 2 - 10
ionic/www/js/controllers.js

@@ -9,16 +9,8 @@ angular.module('starter.controllers', ['starter.services'])
     console.log($scope.sessions);
 })
 
-.controller('SessionCtrl', function($scope, $stateParams, Session) {
-    $scope.session = Session.get({sessionId: $stateParams.sessionId});
-});
-
-
-/* 
-
-.controller('SessionsCtrl', function($scope, Session) {
-    $scope.sessions = Session.get();
+.controller('githubUserCtrl', function($scope, githubUser) {
+    $scope.sessions = githubUser.get();
     console.log($scope.sessions);
 })
 
-*/

+ 5 - 1
ionic/www/js/services.js

@@ -2,4 +2,8 @@ angular.module('starter.services', ['ngResource'])
 
 .factory('Session', function ($resource) {
     return $resource('http://127.0.0.1:8000/hackathon/snippets/');
-});
+})
+
+.factory('githubUser', function ($resource) {
+    return $resource('http://127.0.0.1:8000/hackathon/githubUser/');
+})

+ 11 - 0
ionic/www/templates/githubUser.html

@@ -0,0 +1,11 @@
+<ion-view title="Sessions">
+  <ion-nav-buttons side="left">
+      <button menu-toggle="left" class="button button-icon icon ion-navicon"></button>
+  </ion-nav-buttons>
+  <ion-content class="has-header">
+      <ion-list>
+          <ion-item ng-repeat="session in sessions" 
+                    href="#/app/sessions/{{session.id}}">{{session}}</ion-item>
+      </ion-list>
+  </ion-content>
+</ion-view>

+ 3 - 0
ionic/www/templates/menu.html

@@ -21,6 +21,9 @@
         <ion-item nav-clear menu-close href="#/app/sessions">
             Sessions
         </ion-item>
+        <ion-item nav-clear menu-close href="#/app/githubUser">
+            Github User 
+        </ion-item>
       </ion-list>
     </ion-content>
   </ion-side-menu>