-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathtareas.component.ts
69 lines (59 loc) · 1.98 KB
/
tareas.component.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import { CommonModule } from '@angular/common'
import { Component, OnInit } from '@angular/core'
import { FormsModule } from '@angular/forms'
import { Router, RouterModule } from '@angular/router'
import { IconsModule } from 'app/icons.module'
import { Tarea } from 'domain/tarea'
import { FilterTareas } from 'pipes/filterTareas.pipe'
import { OrderTareas } from 'pipes/orderTareas.pipe'
import { TareasService } from 'services/tareas.service'
import { mostrarError } from 'util/errorHandler'
@Component({
selector: 'app-tareas',
standalone: true,
imports: [CommonModule, FormsModule, RouterModule, FilterTareas, OrderTareas, IconsModule],
templateUrl: './tareas.component.html',
styleUrl: './tareas.component.css'
})
export class TareasComponent implements OnInit {
tareaBuscada = ''
tareas: Array<Tarea> = []
errors = []
constructor(public tareasService: TareasService, private router: Router) { }
async ngOnInit() {
await this.obtenerTodasLasTareas()
}
async actualizarTarea(callbackActualizacion: (tarea: Tarea) => void, tarea: Tarea) {
callbackActualizacion(tarea)
try {
await this.tareasService.actualizarTarea(tarea)
} catch (e) {
await errorHandler(this, e as unknown as Error)
}
}
async cumplir(tarea: Tarea) {
await this.actualizarTarea((tarea: Tarea) => { tarea.cumplir() }, tarea)
}
async desasignar(tarea: Tarea) {
await this.actualizarTarea((tarea: Tarea) => { tarea.desasignar() }, tarea)
}
crearNuevaTarea() {
this.router.navigateByUrl('/nuevaTarea')
}
asignar(tarea: Tarea) {
this.router.navigate(['/asignarTarea', tarea.id])
}
async obtenerTodasLasTareas() {
try {
this.tareas = await this.tareasService.todasLasTareas()
} catch (error) {
mostrarError(this, error)
}
}
}
export const errorHandler = async (component: TareasComponent, error: Error) => {
try {
component.tareas = await component.tareasService.todasLasTareas()
} catch (e) {}
mostrarError(component, error)
}