Skip to content

Commit

Permalink
modularize / add description field
Browse files Browse the repository at this point in the history
  • Loading branch information
aboudard committed May 11, 2018
1 parent 7e37992 commit 290ed04
Show file tree
Hide file tree
Showing 17 changed files with 232 additions and 71 deletions.
8 changes: 8 additions & 0 deletions src/angular/server.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,41 @@
"todos": [
{
"id": 0,
"description": "pop pop opopopo popo po",
"title": "Bonjour les chats"
},
{
"id": 1,
"description": "rere rerere rere rerer ererer",
"title": "Angular best practices"
},
{
"id": 2,
"description": "ytyt ytyty tytyty tytyty tyttyt yty",
"title": "Java avec les pingouins"
},
{
"description": "nbn bnb nbnbnnbn bnnbnbnb nbnbnb nbb nb nb nbnb",
"title": "Spring Boot for my crocodile",
"id": 3
},
{
"description": "bebebbebbb be be b be bbbebbebeb b ebebebebeb b eb",
"title": "Beer is not my first name",
"id": 4
},
{
"description": "chhchc ch ch hh ch hchchch ch chchch hc hc",
"title": "PHP pour mon chat",
"id": 5
},
{
"description": "tdtd tdt ddddt dtdt dtdtddtdtd tdtd",
"title": "That's barealy a Todo List right ?",
"id": 7
},
{
"description": "ititit ititit it it it it it ititit itit ",
"title": "Do something about it",
"id": 8
}
Expand Down
62 changes: 11 additions & 51 deletions src/angular/src/app/app.component.html
Original file line number Diff line number Diff line change
@@ -1,42 +1,24 @@
<nav class="navbar navbar-expand-lg navbar-dark bg-primary mb-1">
<a class="navbar-brand py-0 px-3" href="#" style=""><img height="50px" src="assets/img/logo-ngrx.png"/></a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarsExampleDefault"
aria-controls="navbarsExampleDefault" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>

<div class="collapse navbar-collapse" id="navbarsExampleDefault">
<ul class="navbar-nav mr-auto">
<li class="nav-item active">
<a class="nav-link" href="#">NgRx Data / SpringBoot</a>
</li>

</ul>
<div class="float-right pr-3">
<span class="navbar-text text-white">

<span class="badge badge-secondary">
<span>Alain Boudard</span>
</span>
<span class="small"> | <a href="#">Déconnexion</a></span>
</span>
</div>
</div>
</nav>

<app-navbar></app-navbar>
<div class="container">

<div class="row">
<div class="col-3">
<h5>Add a Todo : </h5>
<form (submit)="addTodo($event, newTodo.value)">
<form (submit)="addTodo($event)">
<div class="form-group">
<label for="title">Todo title</label>
<app-fa-input [icon]="'burn'" class="form-control" (value)="onNewValue($event)">
<input appInputRef type="text" placeholder="Enter todo title" id="title" #newTodo required aria-describedby="titleHelp">
<input appInputRef type="text" placeholder="Enter todo title" id="title" name="title" [(ngModel)]="todo.title" required aria-describedby="titleHelp">
</app-fa-input>
<small id="titleHelp" class="form-text text-muted">This is the sound of C.</small>
</div>
<div class="form-group">
<label for="title">Todo description</label>
<app-fa-input [icon]="'comment-alt'" class="form-control" (value)="onNewValue($event)">
<input appInputRef type="text" placeholder="Enter todo title" id="description" name="description" [(ngModel)]="todo.description" required aria-describedby="titleHelp">
</app-fa-input>
<small id="descriptionHelp" class="form-text text-muted">This is the new style of Music.</small>
</div>
<button type="submit" class="btn btn-primary"><i class="fas fa-check"></i> Submit</button>
</form>
<hr>
Expand All @@ -52,29 +34,8 @@ <h5 class="card-title">Welcome to {{ title }}</h5>
Todo List with SpringBoot backend and Rest API, NgRx Data store solution for CRUD operations
</p>
</div>
<table class="table table-hover table-bordered">
<thead class="thead-light">
<tr>
<th scope="col">#</th>
<th scope="col">Title</th>
<th>&nbsp;</th>
</tr>
</thead>
<tbody>
<tr *ngFor="let todo of todos$ | async; let i = index">
<th scope="row"><span [innerText]="todo.id"></span></th>
<td><span [innerText]="todo.title"></span></td>
<td>
<app-todos></app-todos>

<i class="fas fa-trash float-right text-danger" (click)="deleteTodo(todo.id)"></i>
<span *ngIf="todo.active"><i class="float-right far fa-check-square fa-lg text-info mr-2" (click)="updateTodo(todo)"></i></span>
<span *ngIf="!todo.active"><i class="float-right far fa-square fa-lg text-secondary mr-2" (click)="updateTodo(todo)"></i></span>

</td>
</tr>

</tbody>
</table>
</div>

<div class="alert alert-info mt-2">
Expand All @@ -87,7 +48,6 @@ <h5 class="card-title">Welcome to {{ title }}</h5>

</div>


<footer class="footer">
<div class="container">
&copy; <span [innerText]="yearNow"></span>&nbsp;<span> Coco </span>
Expand Down
26 changes: 9 additions & 17 deletions src/angular/src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,38 +15,30 @@ import {ToastService} from "./services/toast.service";
export class AppComponent implements OnInit {

title = 'NgRx Data & SpringBoot together';
todos$: Observable<Todo[]>;

todo: Todo;
yearNow: string;
appVersion: string;
user = { name: 'Bill' };

constructor(
private todosService: TodosService,
private toastService: ToastService
private toastService: ToastService // create an instance of the service that intercepts $entities actions
) {
this.todos$ = todosService.entities$;
}
getTodos() {
this.todosService.getAll();

}


ngOnInit() {
this.yearNow = new Date().getFullYear().toString();
this.appVersion = 'V X.X.X';
this.getTodos();
}

addTodo(event: Event, todoTitre: string) {
event.preventDefault();
this.todosService.add({title: todoTitre, active: true});
}
deleteTodo(todoId: number) {
this.todosService.delete(todoId);
this.todo = {title: '', description: '', active: true};
}

updateTodo(todo: Todo) {
todo.active = !todo.active;
this.todosService.update(todo);
addTodo(event: Event) {
event.preventDefault();
this.todosService.add(this.todo);
}

onClick() {
Expand Down
2 changes: 2 additions & 0 deletions src/angular/src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {BrowserAnimationsModule} from "@angular/platform-browser/animations";
import {CompModule} from "./comp/comp.module";
import {DirectivesModule} from "./directives/directives.module";
import {ToastrModule} from "ngx-toastr";
import {TodoModule} from "./todo/todo.module";


@NgModule({
Expand All @@ -24,6 +25,7 @@ import {ToastrModule} from "ngx-toastr";
imports: [
DirectivesModule,
CompModule,
TodoModule,
FormsModule,
ReactiveFormsModule,
HttpClientModule,
Expand Down
5 changes: 3 additions & 2 deletions src/angular/src/app/comp/comp.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { FaInputComponent } from './fa-input/fa-input.component';
import {HelloComponent} from "./hello/hello.component";
import { NavbarComponent } from './navbar/navbar.component';

@NgModule({
imports: [
CommonModule
],
declarations: [FaInputComponent, HelloComponent],
exports: [FaInputComponent, HelloComponent]
declarations: [FaInputComponent, HelloComponent, NavbarComponent],
exports: [FaInputComponent, HelloComponent, NavbarComponent]
})
export class CompModule { }
25 changes: 25 additions & 0 deletions src/angular/src/app/comp/navbar/navbar.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<nav class="navbar navbar-expand-lg navbar-dark bg-primary mb-1">
<a class="navbar-brand py-0 px-3" href="#" style=""><img height="50px" src="assets/img/logo-ngrx.png"/></a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarsExampleDefault"
aria-controls="navbarsExampleDefault" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>

<div class="collapse navbar-collapse" id="navbarsExampleDefault">
<ul class="navbar-nav mr-auto">
<li class="nav-item active">
<a class="nav-link" href="#">NgRx Data / SpringBoot</a>
</li>

</ul>
<div class="float-right pr-3">
<span class="navbar-text text-white">

<span class="badge badge-secondary">
<span>Alain Boudard</span>
</span>
<span class="small"> | <a href="#">Déconnexion</a></span>
</span>
</div>
</div>
</nav>
Empty file.
25 changes: 25 additions & 0 deletions src/angular/src/app/comp/navbar/navbar.component.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';

import { NavbarComponent } from './navbar.component';

describe('NavbarComponent', () => {
let component: NavbarComponent;
let fixture: ComponentFixture<NavbarComponent>;

beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ NavbarComponent ]
})
.compileComponents();
}));

beforeEach(() => {
fixture = TestBed.createComponent(NavbarComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it('should create', () => {
expect(component).toBeTruthy();
});
});
15 changes: 15 additions & 0 deletions src/angular/src/app/comp/navbar/navbar.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { Component, OnInit } from '@angular/core';

@Component({
selector: 'app-navbar',
templateUrl: './navbar.component.html',
styleUrls: ['./navbar.component.scss']
})
export class NavbarComponent implements OnInit {

constructor() { }

ngOnInit() {
}

}
1 change: 1 addition & 0 deletions src/angular/src/app/dto/todo.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export interface Todo {
id?: number;
title: string;
description: string;
active: boolean;
}
16 changes: 15 additions & 1 deletion src/angular/src/app/store/entity-store.module.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,25 @@
// entity-store.module.ts
import { NgModule } from '@angular/core';
import { EntityMetadataMap, NgrxDataModule } from 'ngrx-data';
import { EntityMetadataMap, NgrxDataModule, PropsFilterFnFactory } from 'ngrx-data';

export function activeFilter(entities: {active: boolean}[], search: boolean) {
return entities.filter(e => e.active === search);
}

/**
* Filter for entities whose name matches the case-insensitive pattern
* The filter works on ALL properties
* @param {T[]} entities
* @param {string} pattern
* @return {any[]}
*/
export function textFilter<T extends { title: string; description: string }>(
entities: T[],
pattern: string
) {
return PropsFilterFnFactory(['title', 'description'])(entities, pattern);
}

export function sortByTitle(a: { title: string }, b: { title: string }): number {
return a.title.localeCompare(b.title);
}
Expand Down
12 changes: 12 additions & 0 deletions src/angular/src/app/todo/todo.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { TodosComponent } from './todos/todos.component';

@NgModule({
imports: [
CommonModule
],
declarations: [TodosComponent],
exports: [TodosComponent]
})
export class TodoModule { }
35 changes: 35 additions & 0 deletions src/angular/src/app/todo/todos/todos.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<table class="table table-hover table-bordered">
<thead class="thead-light">
<tr>
<th scope="col">#</th>
<th scope="col">Title</th>
<th scope="col">Description</th>
<th>&nbsp;</th>
</tr>
<tr>
<th></th>
<th>
<div class="input-group input-group-sm">
<input class="form-control" type="text">
</div>
</th>
<th></th>
<th></th>
</tr>
</thead>
<tbody>
<tr *ngFor="let todo of todos$ | async; let i = index">
<th scope="row"><span [innerText]="todo.id"></span></th>
<td><span [innerText]="todo.title"></span></td>
<td><span [innerText]="todo.description"></span></td>
<td>

<i class="fas fa-trash float-right text-danger" (click)="deleteTodo(todo.id)"></i>
<span *ngIf="todo.active"><i class="float-right far fa-check-square fa-lg text-info mr-2" (click)="updateTodo(todo)"></i></span>
<span *ngIf="!todo.active"><i class="float-right far fa-square fa-lg text-secondary mr-2" (click)="updateTodo(todo)"></i></span>

</td>
</tr>

</tbody>
</table>
Empty file.
25 changes: 25 additions & 0 deletions src/angular/src/app/todo/todos/todos.component.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';

import { TodosComponent } from './todos.component';

describe('TodosComponent', () => {
let component: TodosComponent;
let fixture: ComponentFixture<TodosComponent>;

beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ TodosComponent ]
})
.compileComponents();
}));

beforeEach(() => {
fixture = TestBed.createComponent(TodosComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it('should create', () => {
expect(component).toBeTruthy();
});
});
Loading

0 comments on commit 290ed04

Please sign in to comment.