Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding angular2-chat-app example #436

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ some of their dependencies.

If you have any questions just ask on [Slack](http://slack.rethinkdb.com) or [Twitter](https://twitter.com/rethinkdb)!

## Angular2
* [Angular2 Chat App](/examples/angular2-chat-app/)

## CycleJS

* [CycleJS Chat App](/examples/cyclejs-chat-app)
Expand Down
94 changes: 94 additions & 0 deletions examples/angular2-chat-app/.hz/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
# This is a TOML file

###############################################################################
# IP options
# 'bind' controls which local interfaces will be listened on
# 'port' controls which port will be listened on
#------------------------------------------------------------------------------
# bind = [ "localhost" ]
# port = 8181


###############################################################################
# HTTPS Options
# 'secure' will disable HTTPS and use HTTP instead when set to 'false'
# 'key_file' and 'cert_file' are required for serving HTTPS
#------------------------------------------------------------------------------
# secure = false
# key_file = "horizon-key.pem"
# cert_file = "horizon-cert.pem"


###############################################################################
# App Options
# 'project_name' sets the name of the RethinkDB database used to store the
# application state
# 'serve_static' will serve files from the given directory over HTTP/HTTPS
#------------------------------------------------------------------------------
project_name = "angular2_chat_app"
# serve_static = "dist"


###############################################################################
# Data Options
# WARNING: these should probably not be enabled on a publically accessible
# service. Tables and indexes are not lightweight objects, and allowing them
# to be created like this could open the service up to denial-of-service
# attacks.
# 'auto_create_collection' creates a collection when one is needed but does not exist
# 'auto_create_index' creates an index when one is needed but does not exist
#------------------------------------------------------------------------------
# auto_create_collection = true
# auto_create_index = true


###############################################################################
# RethinkDB Options
# These options are mutually exclusive
# 'connect' will connect to an existing RethinkDB instance
# 'start_rethinkdb' will run an internal RethinkDB instance
#------------------------------------------------------------------------------
# connect = "localhost:28015"
# start_rethinkdb = false


###############################################################################
# Debug Options
# 'debug' enables debug log statements
#------------------------------------------------------------------------------
# debug = true


###############################################################################
# Authentication Options
# Each auth subsection will add an endpoint for authenticating through the
# specified provider.
# 'token_secret' is the key used to sign jwts
# 'allow_anonymous' issues new accounts to users without an auth provider
# 'allow_unauthenticated' allows connections that are not tied to a user id
# 'auth_redirect' specifies where users will be redirected to after login
#------------------------------------------------------------------------------
token_secret = "ST3Z1Bw9SVrHjIe/oA0HOEkJ7yVnh+mupIWcqjnt4woo/m5vAc2BFrt+cWfkVQysXiqfmC7NdrKkoFH4B4HKyA=="
# allow_anonymous = true
# allow_unauthenticated = true
# auth_redirect = "/"
#
# [auth.facebook]
# id = "000000000000000"
# secret = "00000000000000000000000000000000"
#
# [auth.google]
# id = "00000000000-00000000000000000000000000000000.apps.googleusercontent.com"
# secret = "000000000000000000000000"
#
# [auth.twitter]
# id = "0000000000000000000000000"
# secret = "00000000000000000000000000000000000000000000000000"
#
# [auth.github]
# id = "00000000000000000000"
# secret = "0000000000000000000000000000000000000000"
#
# [auth.twitch]
# id = "0000000000000000000000000000000"
# secret = "0000000000000000000000000000000"
1 change: 1 addition & 0 deletions examples/angular2-chat-app/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Horizon Chat example using Angular2
19 changes: 19 additions & 0 deletions examples/angular2-chat-app/dist/app/app.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
///<reference path="./horizon.d.ts" />

import {Component} from '@angular/core';
import {ChatComponent} from './components/chat/chat.component'

@Component({
selector: 'my-app',
template: '<chat></chat>',
directives: [ChatComponent],
styles:[` chat{
margin: auto;
max-width: 800px;
width:100%;
display:block;

}
`]
})
export class AppComponent { }
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
import {Component, OnInit} from '@angular/core';
import {ChatService} from './chat.service'

@Component({
selector: '<chat></chat>',
styles: [`
ul {
list-style-type: none;
padding:0;
}

.message {
height: 50px;
padding:5px;
}

.message img {
vertical-align:middle;
}
.message .text {
vertical-align:middle;
margin-left:5px;
font-size:20px;
}
.message .datetime {
color:darkgrey;
float:right;
}
form{

}
input {
width: 90%;
height: 50px;
font-size: 20px;
float: left;
padding: 10px;
}
button{
width:10%;
height: 50px;
}
`],
template: `<h1>Messages</h1>
<form>
<input [(ngModel)]="newMessage">
<button type="submit" (click)="addMessage(newMessage)">Send</button>
</form>
<ul>
<li *ngFor="let message of messages; let i = index" class="message">
<img height="50px" width="50px" src="{{message.url}}" />
<span> {{message.text}} </span>
<span class="datetime u-pull-right">
{{message.datetime}}
</span>
</li>
</ul>`,
providers:[ChatService]
})
export class ChatComponent implements OnInit {
newMessage = '';
messages = [];

constructor(private _chatService: ChatService) {

}
ngOnInit() {
this.getChats()
}

getChats = function () {
this._chatService
.getChats()
.subscribe((newMessages) => {
this.messages = [...newMessages];
});
}

addMessage = function (text) {
if (text) {
this._chatService
.sendChat(text)
.subscribe();
this.newMessage = '';
}
}




}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import {Component, OnInit} from '@angular/core';
import {Observable} from 'rxjs'


export class ChatService {
horizon = Horizon();
chat = this.horizon('chat');
avatar_url = `http://api.adorable.io/avatars/50/${new Date().getMilliseconds()}.png`;


constructor() { }
getChats = function (): Observable<[any]> {
return this.chat
.order('datetime', 'descending')
.limit(8)
.watch()
}

sendChat = function (text: string): Observable<[any]> {
return this.chat.store({
text: text,
datetime: new Date(),
url: this.avatar_url,
})
}
}
1 change: 1 addition & 0 deletions examples/angular2-chat-app/dist/app/horizon.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
declare var Horizon: any
4 changes: 4 additions & 0 deletions examples/angular2-chat-app/dist/app/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { bootstrap } from '@angular/platform-browser-dynamic';
import { AppComponent } from './app.component';

bootstrap(AppComponent);
30 changes: 30 additions & 0 deletions examples/angular2-chat-app/dist/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<html>

<head>
<title>Angular 2 QuickStart</title>
Copy link

@marcusreese marcusreese Jun 3, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might want to change the title so it's no longer 'Angular 2 QuickStart'. And add <!doctype html> to the top?

<meta name="viewport" content="width=device-width, initial-scale=1">
<script type="text/javascript" src="//localhost:8181/horizon/horizon.js"></script>
<script type="text/javascript" src="/horizon/horizon.js"></script>

<!-- 1. Load libraries -->
<!-- IE required polyfills, in this exact order -->
<script src="node_modules/typescript/lib/typescript.js"></script>
<script src="node_modules/es6-shim/es6-shim.min.js"></script>

<script src="node_modules/zone.js/dist/zone.js"></script>
<script src="node_modules/reflect-metadata/Reflect.js"></script>
<script src="node_modules/systemjs/dist/system.src.js"></script>

<!-- 2. Configure SystemJS -->
<script src="systemjs.config.js"></script>
<script>
System.import('app').catch(function(err){ console.error(err); });
</script>
</head>
<!-- 3. Display the application -->

<body>
<my-app>Loading...</my-app>
</body>

</html>
26 changes: 26 additions & 0 deletions examples/angular2-chat-app/dist/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"name": "angular2-chat-app",
"version": "1.0.0",
"scripts": {
"postinstall": "typings install",
"typings": "typings"
},
"license": "ISC",
"dependencies": {
"@angular/common": "2.0.0-rc.1",
"@angular/compiler": "2.0.0-rc.1",
"@angular/core": "2.0.0-rc.1",
"@angular/http": "2.0.0-rc.1",
"@angular/platform-browser": "2.0.0-rc.1",
"@angular/platform-browser-dynamic": "2.0.0-rc.1",
"systemjs": "0.19.27",
"es6-shim": "^0.35.0",
"reflect-metadata": "^0.1.3",
"rxjs": "5.0.0-beta.6",
"zone.js": "^0.6.12",
"typescript": "^1.8.9"
},
"devDependencies": {
"typings":"^0.8.1"
}
}
38 changes: 38 additions & 0 deletions examples/angular2-chat-app/dist/systemjs.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
(function(global) {

// map tells the System loader where to look for things
var map = {
'app': 'app', // 'dist',
'rxjs': 'node_modules/rxjs',
'angular2-in-memory-web-api': 'node_modules/angular2-in-memory-web-api',
'@angular': 'node_modules/@angular'
};
// packages tells the System loader how to load when no filename and/or no extension
var packages = {
'app': { main: 'main.ts', defaultExtension: 'ts' },
'rxjs': { defaultExtension: 'js' },
'angular2-in-memory-web-api': { defaultExtension: 'js' },
};
var packageNames = [
'@angular/common',
'@angular/compiler',
'@angular/core',
'@angular/http',
'@angular/platform-browser',
'@angular/platform-browser-dynamic',
'@angular/testing',
];
// add package entries for angular packages in the form '@angular/common': { main: 'index.js', defaultExtension: 'js' }
packageNames.forEach(function(pkgName) {
packages[pkgName] = { main: 'index.js', defaultExtension: 'js' };
});
var config = {
transpiler: 'typescript',
typescriptOptions: {
emitDecoratorMetadata: true
},
map: map,
packages: packages
}
System.config(config);
})(this);
17 changes: 17 additions & 0 deletions examples/angular2-chat-app/dist/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"compilerOptions": {
"target": "es5",
"module": "system",
"moduleResolution": "node",
"sourceMap": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"removeComments": false,
"noImplicitAny": false
},
"exclude": [
"node_modules",
"typings/main",
"typings/main.d.ts"
]
}
6 changes: 6 additions & 0 deletions examples/angular2-chat-app/dist/typings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"ambientDependencies": {
"es6-shim": "github:DefinitelyTyped/DefinitelyTyped/es6-shim/es6-shim.d.ts#7de6c3dd94feaeb21f20054b9f30d5dabc5efabd",
"jasmine": "github:DefinitelyTyped/DefinitelyTyped/jasmine/jasmine.d.ts#7de6c3dd94feaeb21f20054b9f30d5dabc5efabd"
}
}