forked from avatsaev/angular-ngrx-socket-frontend
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: initial full version without ngrx
- Loading branch information
Aslan Vatsaev
committed
Aug 21, 2017
1 parent
6fcc47f
commit e3d8633
Showing
21 changed files
with
352 additions
and
965 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +0,0 @@ | ||
.card{ | ||
margin-bottom: 15px; | ||
} | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,11 @@ | ||
import { Component } from '@angular/core'; | ||
import {SocketService} from './core/services/socket.service'; | ||
import {Note} from './core/models/note'; | ||
import {Observable} from 'rxjs/Observable'; | ||
|
||
|
||
@Component({ | ||
selector: 'app-root', | ||
templateUrl: './app.component.html', | ||
styleUrls: ['./app.component.css'] | ||
}) | ||
export class AppComponent { | ||
notes$: Observable<Note[]>; | ||
|
||
constructor(private socket: SocketService) { | ||
this.notes$ = socket.listen('[Notes] Listed').map(notes => Object.values(notes)); | ||
|
||
socket.join('notes'); | ||
|
||
} | ||
|
||
addNote(note: Note) { | ||
this.socket.emit('[Notes] Add', note); | ||
} | ||
|
||
deleteNote(note) { | ||
this.socket.emit('[Notes] Delete', note); | ||
} | ||
|
||
updateNote(note){ | ||
this.socket.emit('[Notes] Update', {...note, body: '----'}); | ||
} | ||
} |
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 |
---|---|---|
@@ -1,19 +1,23 @@ | ||
import { BrowserModule } from '@angular/platform-browser'; | ||
|
||
import { NgModule } from '@angular/core'; | ||
|
||
import { AppRoutingModule } from './app-routing.module'; | ||
import { AppComponent } from './app.component'; | ||
import {SocketService} from './core/services/socket.service'; | ||
import {SharedModule} from './core/modules/shared.module'; | ||
import {BrowserModule} from '@angular/platform-browser'; | ||
import {CommonModule} from '@angular/common'; | ||
|
||
|
||
@NgModule({ | ||
declarations: [ | ||
AppComponent | ||
], | ||
imports: [ | ||
BrowserModule, | ||
AppRoutingModule | ||
AppRoutingModule, | ||
SharedModule | ||
], | ||
providers: [SocketService], | ||
providers: [], | ||
bootstrap: [AppComponent] | ||
}) | ||
export class AppModule { } |
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,4 @@ | ||
.card{ | ||
margin-bottom: 15px; | ||
} | ||
|
25 changes: 25 additions & 0 deletions
25
src/app/core/components/note-item/note-item.component.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,25 @@ | ||
<div class="card"> | ||
<div class="card-header"> | ||
<p class="card-header-title"> | ||
@{{note.username}} | ||
</p> | ||
|
||
</div> | ||
<div class="card-content"> | ||
<span *ngIf="!editMode" class="note-body"> | ||
{{note.body}} | ||
</span> | ||
|
||
<textarea class="textarea" *ngIf="editMode" [(ngModel)]="newNoteBody" > | ||
</textarea> | ||
|
||
</div> | ||
<footer *ngIf="!editMode" class="card-footer"> | ||
<a class="card-footer-item" (click)="toggleEditMode()">Edit</a> | ||
<a class="card-footer-item" (click)="deleteNote()">Delete</a> | ||
</footer> | ||
<footer *ngIf="editMode" class="card-footer"> | ||
<a class="card-footer-item" (click)="toggleEditMode()">Cancel</a> | ||
<a class="card-footer-item" (click)="updateNote()">Save</a> | ||
</footer> | ||
</div> |
25 changes: 25 additions & 0 deletions
25
src/app/core/components/note-item/note-item.component.spec.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,25 @@ | ||
import { async, ComponentFixture, TestBed } from '@angular/core/testing'; | ||
|
||
import { NoteItemComponent } from './note-item.component'; | ||
|
||
describe('NoteItemComponent', () => { | ||
let component: NoteItemComponent; | ||
let fixture: ComponentFixture<NoteItemComponent>; | ||
|
||
beforeEach(async(() => { | ||
TestBed.configureTestingModule({ | ||
declarations: [ NoteItemComponent ] | ||
}) | ||
.compileComponents(); | ||
})); | ||
|
||
beforeEach(() => { | ||
fixture = TestBed.createComponent(NoteItemComponent); | ||
component = fixture.componentInstance; | ||
fixture.detectChanges(); | ||
}); | ||
|
||
it('should be created', () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
}); |
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,47 @@ | ||
import {Component, EventEmitter, Input, OnChanges, OnInit, Output} from '@angular/core'; | ||
import {Note} from '../../models/note'; | ||
|
||
@Component({ | ||
selector: 'app-note-item', | ||
templateUrl: './note-item.component.html', | ||
styleUrls: ['./note-item.component.css'] | ||
}) | ||
export class NoteItemComponent implements OnInit, OnChanges { | ||
|
||
@Input() note: Note; | ||
newNoteBody: string; | ||
|
||
@Output() onNoteUpdated = new EventEmitter<Note>(); | ||
@Output() onNoteDeleted = new EventEmitter<Note>(); | ||
|
||
editMode = false; | ||
|
||
constructor() { } | ||
|
||
ngOnInit() { | ||
} | ||
|
||
ngOnChanges() { | ||
this.newNoteBody = this.note.body; | ||
} | ||
|
||
toggleEditMode() { | ||
this.editMode = !this.editMode; | ||
if (!this.editMode) { | ||
// reset new body value on edit cancel | ||
this.newNoteBody = this.note.body; | ||
} | ||
} | ||
|
||
updateNote() { | ||
this.note.body = this.newNoteBody; | ||
this.onNoteUpdated.emit(this.note); | ||
this.toggleEditMode(); | ||
} | ||
|
||
deleteNote() { | ||
this.onNoteDeleted.emit(this.note); | ||
} | ||
|
||
|
||
} |
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,20 @@ | ||
import { NgModule } from '@angular/core'; | ||
import { CommonModule } from '@angular/common'; | ||
import {NoteItemComponent} from '../components/note-item/note-item.component'; | ||
import {FormsModule} from '@angular/forms'; | ||
|
||
|
||
@NgModule({ | ||
imports: [ | ||
FormsModule, | ||
CommonModule | ||
], | ||
declarations: [ | ||
NoteItemComponent | ||
], | ||
exports: [ | ||
NoteItemComponent, | ||
FormsModule, | ||
] | ||
}) | ||
export class SharedModule { } |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
.card{ | ||
margin-bottom: 15px; | ||
} | ||
|
||
.connected { | ||
color: green; | ||
|
||
} | ||
|
||
.connected:after { | ||
content: 'CONNECTED'; | ||
} | ||
|
||
.disconnected { | ||
color: red; | ||
} | ||
|
||
.disconnected:after { | ||
content: 'DISONNECTED'; | ||
} |
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,16 @@ | ||
<a class="button is-success" (click)="addNote({username: 'username', body: 'Lorem dolor ipsum'})"> | ||
<span class="fa fa-plus"></span> | ||
ADD | ||
</a> | ||
<p class="has-text-centered">List of notes</p> | ||
|
||
|
||
|
||
<app-note-item | ||
*ngFor=" let note of notes$ | async" | ||
[note]="note" | ||
(onNoteUpdated)="updateNote($event)" | ||
(onNoteDeleted)="deleteNote($event)" | ||
> | ||
</app-note-item> | ||
|
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,25 @@ | ||
import { async, ComponentFixture, TestBed } from '@angular/core/testing'; | ||
|
||
import { NoteListComponent } from './note-list.component'; | ||
|
||
describe('NoteListComponent', () => { | ||
let component: NoteListComponent; | ||
let fixture: ComponentFixture<NoteListComponent>; | ||
|
||
beforeEach(async(() => { | ||
TestBed.configureTestingModule({ | ||
declarations: [ NoteListComponent ] | ||
}) | ||
.compileComponents(); | ||
})); | ||
|
||
beforeEach(() => { | ||
fixture = TestBed.createComponent(NoteListComponent); | ||
component = fixture.componentInstance; | ||
fixture.detectChanges(); | ||
}); | ||
|
||
it('should be created', () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
}); |
Oops, something went wrong.