forked from 1337programming/angular2.0-Wepack-App
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
570 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
src/app/components/example-modules/hn-module/components/hn-item/hn-item.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import { Component, View, For, If, Switch, SwitchWhen, SwitchDefault } from 'angular2/angular2'; | ||
import { HNApi } from '../../services/hn-api'; | ||
import { timeAgo } from '../../../../../services/time'; | ||
import { DomainPipe } from './pipes/domain.pipe'; | ||
|
||
let view = require('./views/hn-item.html'); | ||
let styles = require('./styles/hn-item.less'); | ||
|
||
var hnApi; | ||
|
||
@Component({ | ||
selector: 'hn-item', | ||
viewBindings: [HNApi], | ||
properties: { | ||
newItemId: 'itemId', | ||
newLoadChildren: 'loadChildren', | ||
newTopLevel: 'topLevel' | ||
} | ||
}) | ||
@View({ | ||
template: view, | ||
styles: [ styles ], | ||
directives: [ | ||
For, | ||
If, | ||
Switch, | ||
SwitchWhen, | ||
SwitchDefault | ||
] | ||
}) | ||
export class HNItem { | ||
data: Object; | ||
domainPipe: Object; | ||
loadChildren: boolean; | ||
topLevel: boolean; | ||
itemId; | ||
timeAgo; | ||
|
||
|
||
constructor(hnApiInstance: HNApi) { | ||
this.domainPipe = DomainPipe.transform; | ||
|
||
// Default value. | ||
this.loadChildren = true; | ||
|
||
// Make accessible in other methods. | ||
hnApi = hnApiInstance; | ||
|
||
this.timeAgo = timeAgo; | ||
} | ||
|
||
set newItemId(itemId) { | ||
this.itemId = itemId; | ||
this.fetchData(); | ||
} | ||
|
||
set newLoadChildren(loadChildren) { | ||
this.loadChildren = loadChildren === 'true'; | ||
} | ||
|
||
set newTopLevel(topLevel) { | ||
this.topLevel = topLevel === 'true'; | ||
} | ||
|
||
fetchData() { | ||
hnApi.fetchItem(this.itemId).then(data => { | ||
this.data = data; | ||
}); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
src/app/components/example-modules/hn-module/components/hn-item/pipes/domain.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { Pipes } from 'angular2/angular2'; | ||
|
||
export class DomainPipe extends Pipes { | ||
static transform(input) { | ||
if (!input) { | ||
return ''; | ||
} | ||
var domain = input.split('/')[2]; | ||
return domain ? domain.replace('www.', '') : domain; | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
src/app/components/example-modules/hn-module/components/hn-item/styles/hn-item.less
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
hn-item { | ||
display: block; | ||
margin: 10px 0; | ||
} | ||
|
||
.hnItem-title { | ||
font-size: 10pt; | ||
color: #828282; | ||
} | ||
|
||
.hnItem > section { | ||
font-size: 7pt; | ||
&, | ||
a:link, | ||
a:visited { | ||
color: #828282; | ||
} | ||
a:hover { | ||
text-decoration: underline; | ||
} | ||
} | ||
|
||
.hnItem--comment { | ||
margin: 15px 0; | ||
} | ||
|
||
.hnItem--coment-content { | ||
margin-top: 5px; | ||
} | ||
|
||
.hnItem--comment-children { | ||
margin-left: 50px; | ||
} |
69 changes: 69 additions & 0 deletions
69
src/app/components/example-modules/hn-module/components/hn-item/views/hn-item.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
<div class="hnItem-loading spinner" *if="!data"> | ||
<div class="rect1"></div> | ||
<div class="rect2"></div> | ||
<div class="rect3"></div> | ||
<div class="rect4"></div> | ||
<div class="rect5"></div> | ||
</div> | ||
<div class="hnItem-container" *if="data"> | ||
<div [switch]="data.type"> | ||
<template [switch-when]="'comment'"> | ||
<div class="hnItem--comment"> | ||
<header> | ||
<span class="u-pointer" (click)="collapsed = !collapsed" *if="!topLevel"> | ||
[{{collapsed ? '+' : '-'}}] | ||
</span> | ||
<a [href]="urlForUser(data.by)" class="hnItem-author">{{data.by}}</a> | ||
<span>{{timeAgo(data.time)}}</span> | | ||
<a [href]="urlForItem(data.id)">link</a> | ||
</header> | ||
<section class="hnItem--coment-content" [hidden]="!data || collapsed">{{data.text}}</section> | ||
<div class="hnItem--comment-children" *if="loadChildren && data.kids" [hidden]="collapsed"> | ||
<div *for="#kidId of data.kids"> | ||
child id: {{kidId}} | ||
<hn-item item-id="{{kidId}}"></hn-item> | ||
</div> | ||
</div> | ||
</div> | ||
</template> | ||
<template [switch-when]="'job'"> | ||
<div class="hnItem--story"> | ||
<header> | ||
<a class="hnItem-title" [href]="data.url">{{data.title}}</a> | ||
<span class="comhead" [hidden]="!data.url">({{domainPipe(data.url)}})</span> | ||
</header> | ||
<section [hidden]="!data"> | ||
<span>{{timeAgo(data.time)}}</span> | ||
</section> | ||
</div> | ||
</template> | ||
<template [switch-when]="'poll'"> | ||
<div class="hnItem--story"> | ||
<header> | ||
<a class="hnItem-title" [href]="data.url">{{data.title}}</a> | ||
<span class="comhead" [hidden]="!data.url">({{domainPipe(data.url)}})</span> | ||
</header> | ||
<section [hidden]="!data"> | ||
<span>{{data.score}} points</span> by | ||
<a [href]="urlForUser(data.by)">{{data.by}}</a> | ||
<span>{{timeAgo(data.time)}}</span> | | ||
<a [href]="urlForItem(data.id)">comments</a> | ||
</section> | ||
</div> | ||
</template> | ||
<template [switch-default]> | ||
<div class="hnItem--story"> | ||
<header> | ||
<a class="hnItem-title" [href]="data.url">{{data.title}}</a> | ||
<span class="comhead" [hidden]="!data.url">({{domainPipe(data.url)}})</span> | ||
</header> | ||
<section [hidden]="!data"> | ||
<span>{{data.score}} points</span> by | ||
<a [href]="urlForUser(data.by)">{{data.by}}</a> | ||
<span>{{timeAgo(data.time)}}</span> | | ||
<a [href]="urlForItem(data.id)">comments</a> | ||
</section> | ||
</div> | ||
</template> | ||
</div> | ||
</div> |
28 changes: 28 additions & 0 deletions
28
src/app/components/example-modules/hn-module/directives/home.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { Component, View, For } from 'angular2/angular2'; | ||
import { HNApi } from '../services/hn-api'; | ||
import { HNItem } from '../components/hn-item/hn-item'; | ||
|
||
let view = require('../views/home.html'); | ||
let styles = require('../styles/hn.less'); | ||
|
||
@Component({ | ||
selector: 'page-home', | ||
viewBindings: HNApi | ||
}) | ||
@View({ | ||
directives: [ | ||
For, | ||
HNItem | ||
], | ||
styles: [ styles ], | ||
template: view | ||
}) | ||
export class HomePage { | ||
topStories: Array<HNItem>; | ||
|
||
constructor(public hnApi: HNApi) { | ||
hnApi.fetchTopStories().then(() => { | ||
this.topStories = hnApi.topStories; | ||
}); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
src/app/components/example-modules/hn-module/directives/item.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { Component, View, For } from 'angular2/angular2'; | ||
import { HNApi } from '../services/hn-api'; | ||
import { HNItem } from '../../components/hn-item'; | ||
|
||
let view = require('../views/item.html'); | ||
let styles = require('../styles/hn.less'); | ||
|
||
@Component({ | ||
selector: 'page-item', | ||
viewBindings: HNApi | ||
}) | ||
@View({ | ||
directives: [ | ||
For, | ||
HNItem | ||
], | ||
template: view, | ||
styles: [ styles ] | ||
}) | ||
export class ItemPage { | ||
childrenIds: Array; | ||
itemId; | ||
|
||
constructor(public hnApi: HNApi, id) { | ||
this.itemId = id; | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
src/app/components/example-modules/hn-module/directives/user.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { Component, View, For, If } from 'angular2/angular2'; | ||
import { HNApi } from '../services/hn-api'; | ||
import { timeAgo } from '../../../../../services/time'; | ||
import { HNItem } from '../components/hn-item/hn-item'; | ||
|
||
let view = require('../views/user.html'); | ||
let styles = require('../styles/hn.less'); | ||
|
||
@Component({ | ||
selector: 'page-user', | ||
viewBindings: HNApi | ||
}) | ||
@View({ | ||
directives: [ | ||
For, | ||
If, | ||
HNItem | ||
], | ||
styles: [ styles ], | ||
template: view | ||
}) | ||
export class UserPage { | ||
showSubmissions: boolean; | ||
timeAgo; | ||
|
||
constructor(hnApi: HNApi) { | ||
this.timeAgo = timeAgo; | ||
this.showSubmissions = false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
//import {zone} from 'zone.js'; | ||
//window.zone = window.Zone = zone; | ||
|
||
let styles = require('./styles/hn.less'); | ||
let view = require('/.views/hn.html'); | ||
|
||
import {RouteConfig} from 'angular2/router'; | ||
import {Component, View} from 'angular2/angular2'; | ||
import {HomePage} from './directives/home' | ||
import {ItemPage} from './directives/item' | ||
import {UserPage} from './directives/user' | ||
import {HNItem} from './components/hn-item/hn-item'; | ||
|
||
|
||
@Component({ | ||
selector: 'hacker-news' | ||
}) | ||
@RouteConfig([ | ||
{ path: '/', redirectTo: '/hn' }, | ||
{ path: '/hn', as: 'hn', component: HackerNews }, | ||
{ path: '/hn-item', as: 'hn-item', component: HNItem }, | ||
]) | ||
@View({ | ||
template: view, | ||
styles: [ styles ], | ||
directives: [ | ||
HomePage, | ||
ItemPage, | ||
UserPage | ||
] | ||
}) | ||
export class HackerNews { | ||
|
||
} | ||
|
Oops, something went wrong.