27
loading...
This website collects cookies to deliver better user experience
@Component({
selector: 'app-todo-list',
templateUrl: './todo-list.component.html',
styleUrls: ['./todo-list.component.scss'],
changeDetection: ChangeDetectionStrategy.OnPush
})
export class TodoListComponent implements OnInit {}
<xml><div class="mx-auto col-10"><h5>{{'todo-list' | translate}}</h5>
<hr><app-cards-list></app-cards-list></div>
<hr><app-add-todo></app-add-todo>
</xml>
"schematics": {
"@schematics/angular:component": {
"styleext": "scss",
"changeDetection": "OnPush"
}
}
public getDuedateTodayCount(todoItems: TODOItem[]) {
console.log('Called getDuedateTodayCount');
return todoItems.filter((todo) => this.isToday(new Date(todo.dueDate))).length;
}
private isToday(someDate) {
const today = new Date();
return (
someDate.getDate() == today.getDate() &&
someDate.getMonth() == today.getMonth() &&
someDate.getFullYear() == today.getFullYear()
);
}
public getDuedateTodayCount(todoItems: TODOItem[]) {
console.log('Called getDuedateTodayCount');
return todoItems.filter((todo) => this.isToday(new Date(todo.dueDate))).length;
}
private isToday(someDate) {
const today = new Date();
return (
someDate.getDate() == today.getDate() &&
someDate.getMonth() == today.getMonth() &&
someDate.getFullYear() == today.getFullYear()
);
}
import { Pipe, PipeTransform } from '@angular/core';
import { TODOItem } from '@app/shared/models/todo-item';
@Pipe({
name: 'duedateTodayCount'
})
export class DuedateTodayCountPipe implements PipeTransform {
transform(todoItems: TODOItem[], args?: any): any {
console.log('Called getDuedateTodayCount');
return todoItems.filter((todo) => this.isToday(new Date(todo.dueDate))).length;
}
private isToday(someDate) {
const today = new Date();
return (
someDate.getDate() == today.getDate() &&
someDate.getMonth() == today.getMonth() &&
someDate.getFullYear() == today.getFullYear()
);
}
public trackByFn(index, item) {
return item.id;
}
@Component({
selector: 'app-todo-item-list-row',
templateUrl: './todo-item-list-row.component.html',
styleUrls: ['./todo-item-list-row.component.scss'],
changeDetection: ChangeDetectionStrategy.OnPush
})
export class TodoItemListRowComponent implements OnInit {
private _todoItem : TODOItem;
public get todoItem() : TODOItem {
return this._todoItem;
}
@Input()
public set todoItem(v : TODOItem) {
this._todoItem = v;
this.cdr.detectChanges();
}
@Input() public readOnlyTODO: boolean;
@Output() public todoDelete = new EventEmitter();
@Output() public todoEdit = new EventEmitter();
@Output() public todoComplete = new EventEmitter<todoitem>();
constructor(private cdr: ChangeDetectorRef) {}
public ngOnInit() {
this.cdr.detach();
}
public completeClick() {
const newTodo = {
...this.todoItem,
completed: !this.todoItem.completed
};
this.todoComplete.emit(newTodo);
}
public deleteClick() {
this.todoDelete.emit(this.todoItem.id);
}
public editClick() {
this.todoEdit.emit(this.todoItem);
}
}
</todoitem>
const routes: Routes = [
{
path: '',
component: TodoListCompletedComponent
}
];
export const TodoListCompletedRoutes = RouterModule.forChild(routes);
@NgModule({
imports: [FormsModule, CommonModule, SharedModule, TodoListCompletedRoutes],
declarations: [TodoListCompletedComponent]
})
export class TodoListCompletedModule {}
const appRoutes: Routes = [
{
path: rootPath,
component: TodoListComponent,
pathMatch: 'full'
},
{
path: completedTodoPath,
loadChildren: './todo-list-completed/todo-list-completed.module#TodoListCompletedModule'
}
];
export const appRouterModule = RouterModule.forRoot(appRoutes);
RouterModule.forRoot(routes, {
preloadingStrategy: PreloadAllModules
})