From c9f7a57d9036a5ca20a42601b483012eca787e07 Mon Sep 17 00:00:00 2001 From: Max Lynch Date: Tue, 26 May 2015 16:48:47 -0500 Subject: [PATCH] HN App kind of working --- ionic/components/app/test/hn/hn.js | 2 +- ionic/components/app/test/hn/index.js | 15 ++--- ionic/components/app/test/hn/main.html | 3 - ionic/components/app/test/hn/pages/top.html | 11 ++-- ionic/components/app/test/hn/pages/top.js | 64 ++++++++++----------- scripts/e2e/angular.template.html | 1 + 6 files changed, 44 insertions(+), 52 deletions(-) diff --git a/ionic/components/app/test/hn/hn.js b/ionic/components/app/test/hn/hn.js index ab359bec02..67599b999b 100644 --- a/ionic/components/app/test/hn/hn.js +++ b/ionic/components/app/test/hn/hn.js @@ -1,7 +1,7 @@ import {Promise} from 'angular2/src/facade/async'; -console.log(Promise); var APIUrl = 'https://hacker-news.firebaseio.com/v0/'; + export class HackerNewsClient { constructor() { //this.fb = new Firebase(APIUrl); diff --git a/ionic/components/app/test/hn/index.js b/ionic/components/app/test/hn/index.js index 1a9c734c31..c277fda0d6 100644 --- a/ionic/components/app/test/hn/index.js +++ b/ionic/components/app/test/hn/index.js @@ -1,22 +1,20 @@ -import {NgElement} from 'angular2/angular2'; -import {bootstrap} from 'angular2/angular2' +import {bootstrap, ElementRef} from 'angular2/angular2' import {Component, Directive} from 'angular2/src/core/annotations_impl/annotations'; import {View} from 'angular2/src/core/annotations_impl/view'; -import {bind} from 'angular2/di'; -import {Content, Nav, NavPane} from 'ionic/ionic'; +import {Nav, HeaderTemplate, Toolbar, Content} from 'ionic/ionic'; -import {HackerNews} from 'hn'; -import {HNTopStories} from 'pages/top'; +import {HackerNews} from './hn'; +import {HNTopStories} from './pages/top'; @Component({ selector: 'ion-app' }) @View({ templateUrl: 'main.html', - directives: [Content, Nav, NavPane] + directives: [Nav, Content, HeaderTemplate, Toolbar] }) export class IonicApp { constructor( - @NgElement() element:NgElement + elementRef: ElementRef ) { console.log('IonicApp start: HackerNews', HackerNews) @@ -27,4 +25,3 @@ export class IonicApp { export function main() { bootstrap(IonicApp); } - diff --git a/ionic/components/app/test/hn/main.html b/ionic/components/app/test/hn/main.html index 818de8dc68..834979452d 100644 --- a/ionic/components/app/test/hn/main.html +++ b/ionic/components/app/test/hn/main.html @@ -1,5 +1,2 @@ - diff --git a/ionic/components/app/test/hn/pages/top.html b/ionic/components/app/test/hn/pages/top.html index 7f8445d50e..2cc58d555e 100644 --- a/ionic/components/app/test/hn/pages/top.html +++ b/ionic/components/app/test/hn/pages/top.html @@ -1,12 +1,15 @@ + - - Loaded {{stories.length}} stories + - + + {{story.title}} - + + + diff --git a/ionic/components/app/test/hn/pages/top.js b/ionic/components/app/test/hn/pages/top.js index 354390d3f1..0d6c5672d9 100644 --- a/ionic/components/app/test/hn/pages/top.js +++ b/ionic/components/app/test/hn/pages/top.js @@ -1,23 +1,25 @@ +import {NgFor, ElementRef, bootstrap} from 'angular2/angular2'; -import {For, Ancestor, Descendent, Parent, NgElement, Component, View, bootstrap} from 'angular2/angular2'; -import {PushToNav, Content, Nav, NavPane, List, Item} from 'ionic/ionic'; +import {Ancestor} from 'angular2/src/core/annotations_impl/visibility'; -import {HackerNews} from 'hn' +import {Component, Directive} from 'angular2/src/core/annotations_impl/annotations'; +import {View} from 'angular2/src/core/annotations_impl/view'; -@Component({ selector: 'top-stories' }) +import {Content, Nav, List, Item} from 'ionic/ionic'; + +import {HackerNews} from '../hn' + +console.log('Angular directives', NgFor, Content, List, Item); + +@Component({ + selector: 'top-stories' +}) @View({ templateUrl: 'pages/top.html', - directives: [Content, For, List, Item, PushToNav] + directives: [Content, NgFor, List, Item] }) export class HNTopStories { - constructor(@Ancestor() viewport: Nav) {//, @Ancestor() app: HNApp) { - console.log('TOP STORIES', 'Ancestor', viewport); - - var self = this; - - this.throwMe = function() { - throw new Error('stack test from throwMe'); - }; + constructor() { this.stories = [{ by: "FatalLogic", @@ -31,35 +33,27 @@ export class HNTopStories { type: "story", url: "http://minusbat.livejournal.com/180556.html" }]; + return; - var APIUrl = 'https://hacker-news.firebaseio.com/v0'; - this.fb = new window.Firebase(APIUrl); + var APIUrl = 'https://hacker-news.firebaseio.com/v0'; - this.fb = new window.Firebase(APIUrl); - this.fb.child('topstories').limitToFirst(20).once('value', (snapshot) => { + console.log('FIREBASE', window.Firebase); - let items = snapshot.val(); + this.fb = new window.Firebase(APIUrl); + this.fb.child('topstories').limitToFirst(20).once('value', (snapshot) => { - console.log('Fetched', items.length, 'items'); + let items = snapshot.val(); - for(var itemID of items) { + console.log('Fetched', items.length, 'items'); - this.fb.child("item").child(itemID).on('value', (data) => { - //setTimeout(() => { - //console.log('SUB THIS', this); - //console.log(itemID, data.val()); - //console.log('ADDED'); - //self.stories.push(data.val()); - //throw new Error("stack test"); - debugger; - console.log('GOT ITEM', data.val()); - self.stories.push({title: 'asdf'}); - //}); + for(var itemID of items) { - //console.log(data.val()); - }); - } - }); + this.fb.child("item").child(itemID).on('value', (data) => { + console.log('GOT ITEM', data.val()); + this.stories.push(data.val()); + }); + } + }); //doStuffEnd } diff --git a/scripts/e2e/angular.template.html b/scripts/e2e/angular.template.html index b2b393bc75..54c7d3ab47 100644 --- a/scripts/e2e/angular.template.html +++ b/scripts/e2e/angular.template.html @@ -16,6 +16,7 @@ +