From 399b8681c2b05868b6230d3291c96fc212d95ee2 Mon Sep 17 00:00:00 2001 From: olefebvre Date: Thu, 1 Sep 2016 09:26:52 +0200 Subject: [PATCH] implements contacts component --- src/chatle/Views/Home/Index.cshtml | 15 +++++------ src/chatle/app/app.component.spec.ts | 26 ++++++++++++++++--- src/chatle/app/app.component.ts | 3 ++- src/chatle/app/app.module.ts | 6 +++-- src/chatle/app/contacts/contact.component.ts | 15 ++++++++--- .../contact.component.ts~RF6cae1c9.TMP | 0 src/chatle/app/contacts/contact.html | 1 + src/chatle/app/contacts/contacts.component.ts | 4 +-- src/chatle/app/contacts/contacts.html | 6 +++++ src/chatle/app/main.ts | 1 + src/chatle/app/shared/chat.service.spec.ts | 8 +++--- src/chatle/app/shared/chat.service.ts | 5 ++-- src/chatle/gulpfile.js | 6 +++-- src/chatle/wwwroot/_references.js | 6 +++-- 14 files changed, 72 insertions(+), 30 deletions(-) create mode 100644 src/chatle/app/contacts/contact.component.ts~RF6cae1c9.TMP create mode 100644 src/chatle/app/contacts/contact.html create mode 100644 src/chatle/app/contacts/contacts.html diff --git a/src/chatle/Views/Home/Index.cshtml b/src/chatle/Views/Home/Index.cshtml index 041c7139..8c9de689 100644 --- a/src/chatle/Views/Home/Index.cshtml +++ b/src/chatle/Views/Home/Index.cshtml @@ -80,13 +80,12 @@ } diff --git a/src/chatle/app/app.component.spec.ts b/src/chatle/app/app.component.spec.ts index 4c9c3136..a912db7b 100644 --- a/src/chatle/app/app.component.spec.ts +++ b/src/chatle/app/app.component.spec.ts @@ -1,8 +1,26 @@ -import { AppComponent } from "./app.component"; +import { Injector } from '@angular/core'; +import { TestBed, inject } from '@angular/core/testing'; +import { HttpModule, Http, XHRBackend } from '@angular/http'; +import { MockBackend } from '@angular/http/testing'; + +import { AppComponent } from './app.component'; +import { ChatService } from './shared/chat.service'; +import { Settings } from './shared/settings'; describe('AppComponent', () => { - it("app component should exist", () => { - let component = new AppComponent(); - expect(component).toBeDefined(); + + beforeEach(() => { + TestBed.configureTestingModule({ + imports: [HttpModule], + providers: [ + { provide: XHRBackend, useClass: MockBackend }, + { provide: Settings, useClass: Settings } + ] + }); }); + + it("app component should exist", inject([ChatService], (service: ChatService) => { + let component = new AppComponent(service); + expect(component).toBeDefined(); + })); }); \ No newline at end of file diff --git a/src/chatle/app/app.component.ts b/src/chatle/app/app.component.ts index ac17d294..661b1dec 100644 --- a/src/chatle/app/app.component.ts +++ b/src/chatle/app/app.component.ts @@ -1,6 +1,7 @@ import { Component, OnInit } from '@angular/core'; -import { ChatService, ConnectionState} from './shared/chat.service' +import { ChatService, ConnectionState } from './shared/chat.service' +import { Settings } from './shared/settings' @Component({ selector: 'chatle', diff --git a/src/chatle/app/app.module.ts b/src/chatle/app/app.module.ts index 26d863ae..10222f46 100644 --- a/src/chatle/app/app.module.ts +++ b/src/chatle/app/app.module.ts @@ -1,4 +1,4 @@ -import { NgModule } from '@angular/core'; +import { NgModule, provide } from '@angular/core'; import { BrowserModule } from '@angular/platform-browser'; import { FormsModule } from '@angular/forms'; import { HttpModule } from '@angular/http'; @@ -6,10 +6,12 @@ import { HttpModule } from '@angular/http'; import { AppComponent } from './app.component'; import { ContactComponent } from './contacts/contact.component'; import { ContactsComponent } from './contacts/contacts.component'; +import { Settings } from './shared/settings'; @NgModule({ imports: [ BrowserModule, FormsModule, HttpModule ], declarations: [ AppComponent, ContactComponent, ContactsComponent ], - bootstrap: [ AppComponent ] + bootstrap: [AppComponent], + providers: [{ provide: Settings, useFactory: () => window['chatleSetting'] }] }) export class AppModule { } diff --git a/src/chatle/app/contacts/contact.component.ts b/src/chatle/app/contacts/contact.component.ts index f8bd5409..1e498068 100644 --- a/src/chatle/app/contacts/contact.component.ts +++ b/src/chatle/app/contacts/contact.component.ts @@ -1,8 +1,17 @@ -import { Component } from '@angular/core'; +import { Component, Input } from '@angular/core'; + +import { User } from '../shared/user'; @Component({ selector: 'contact', - template: '

Contact

' + templateUrl: 'contact.html' }) -export class ContactComponent { } +export class ContactComponent { + @Input() + user: User; + + onClick() { + + } +} diff --git a/src/chatle/app/contacts/contact.component.ts~RF6cae1c9.TMP b/src/chatle/app/contacts/contact.component.ts~RF6cae1c9.TMP new file mode 100644 index 00000000..e69de29b diff --git a/src/chatle/app/contacts/contact.html b/src/chatle/app/contacts/contact.html new file mode 100644 index 00000000..5b5a0277 --- /dev/null +++ b/src/chatle/app/contacts/contact.html @@ -0,0 +1 @@ +{{user.Id}} \ No newline at end of file diff --git a/src/chatle/app/contacts/contacts.component.ts b/src/chatle/app/contacts/contacts.component.ts index d0de43a2..30c68697 100644 --- a/src/chatle/app/contacts/contacts.component.ts +++ b/src/chatle/app/contacts/contacts.component.ts @@ -5,10 +5,10 @@ import { User } from '../shared/user' @Component({ selector: 'contacts', - template: `

Contacts

+ template: `
CONNECTED
` }) diff --git a/src/chatle/app/contacts/contacts.html b/src/chatle/app/contacts/contacts.html new file mode 100644 index 00000000..c05b5e53 --- /dev/null +++ b/src/chatle/app/contacts/contacts.html @@ -0,0 +1,6 @@ +
CONNECTED
+ \ No newline at end of file diff --git a/src/chatle/app/main.ts b/src/chatle/app/main.ts index 5b2f55c6..eeda6e45 100644 --- a/src/chatle/app/main.ts +++ b/src/chatle/app/main.ts @@ -1,3 +1,4 @@ import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; + import { AppModule } from './app.module'; platformBrowserDynamic().bootstrapModule(AppModule); diff --git a/src/chatle/app/shared/chat.service.spec.ts b/src/chatle/app/shared/chat.service.spec.ts index 8abb648d..5fd57ced 100644 --- a/src/chatle/app/shared/chat.service.spec.ts +++ b/src/chatle/app/shared/chat.service.spec.ts @@ -11,18 +11,20 @@ import { Message } from './message'; import { Conversation } from './conversation'; describe('ChatService', () => { + TestBed.resetTestEnvironment(); beforeEach(() => { TestBed.configureTestingModule({ imports: [HttpModule], providers: [ - { provide: XHRBackend, useClass: MockBackend } + { provide: XHRBackend, useClass: MockBackend }, + { provide: Settings, useClass: Settings } ] }); }); - it("start should return connectionState observable", inject([Settings, Http], (settings: Settings, http: Http) => { - let service = new ChatService(settings, http); + it("start should return connectionState observable", inject([Http, Settings], (http: Http, settings: Settings) => { + let service = new ChatService(http, settings); let connectionState: ConnectionState; service.start(true) diff --git a/src/chatle/app/shared/chat.service.ts b/src/chatle/app/shared/chat.service.ts index 2038c68b..2170f06c 100644 --- a/src/chatle/app/shared/chat.service.ts +++ b/src/chatle/app/shared/chat.service.ts @@ -1,4 +1,4 @@ -import { Injectable } from '@angular/core'; +import { Injectable, Inject } from '@angular/core'; import { Http } from '@angular/http'; import 'rxjs/add/operator/toPromise'; @@ -46,9 +46,8 @@ export class ChatService { private userDisconnectedSubject = new Subject(); private messageReceivedSubject = new Subject(); private joinConversationSubject = new Subject(); - private settings = new Settings(); - constructor(private http: Http) { + constructor(private http: Http, private settings: Settings) { this.connectionState = this.connectionStateSubject.asObservable(); this.messageReceived = this.messageReceivedSubject.asObservable(); this.userConnected = this.userConnectedSubject.asObservable(); diff --git a/src/chatle/gulpfile.js b/src/chatle/gulpfile.js index ffb404ef..27e215db 100644 --- a/src/chatle/gulpfile.js +++ b/src/chatle/gulpfile.js @@ -35,6 +35,8 @@ paths.rxjs = paths.node_modules + "rxjs/**/*.js"; paths.jasminejs = paths.node_modules + "jasmine-core/lib/jasmine-core/*.*"; paths.app = "app/**/*.js"; +paths.appTemplates = "app/**/*.html" +paths.appmaps = "app/**/*.map" paths.appDest = paths.webroot + "js/app"; gulp.task("clean:js", function (cb) { return rimraf(paths.concatJsDest, cb); @@ -104,7 +106,7 @@ gulp.task("copy:rxjs", function () { }); gulp.task("copy:app", function () { - return gulp.src(paths.app + "*") + return gulp.src([paths.app, paths.appmaps, paths.appTemplates]) .pipe(gulp.dest(paths.appDest)); }); @@ -125,7 +127,7 @@ gulp.task("dependencies", [ "copy:angular", "copy:app" ]); gulp.task("watch", function() { - return watch(paths.app + "*") + return watch(paths.app) .pipe(gulp.dest(paths.appDest)) }); diff --git a/src/chatle/wwwroot/_references.js b/src/chatle/wwwroot/_references.js index c7da0039..a68655fb 100644 --- a/src/chatle/wwwroot/_references.js +++ b/src/chatle/wwwroot/_references.js @@ -5,10 +5,9 @@ /// /// /// -/// /// +/// /// -/// /// /// /// @@ -19,6 +18,9 @@ /// /// /// +/// +/// +/// /// /// ///