clean code

This commit is contained in:
Chneemann 2024-04-09 09:58:38 +02:00
parent 9956a31424
commit 484df8e5b9
8 changed files with 47 additions and 27 deletions

View file

@ -228,9 +228,9 @@
</div>
} @else {
<img class="add" src="./../../../assets/img/add.svg" alt="" />
} @if (taskData.subtasks) {
} @if (taskData.subtasksTitle) {
<div class="subtasks">
@for (task of taskData.subtasks.reverse(); track task) {
@for (task of taskData.subtasksTitle.reverse(); track task) {
<div class="single-subtask">
<p>- {{ task }}</p>
<img

View file

@ -4,7 +4,7 @@ import { FormsModule, NgForm, NgModel } from '@angular/forms';
import { AssignedComponent } from './assigned/assigned.component';
import { User } from '../../interfaces/user.interface';
import { FirebaseService } from '../../services/firebase.service';
import { TaskData } from '../../interfaces/task-data.interface';
import { Task } from '../../interfaces/task.interface';
@Component({
selector: 'app-add-task',
@ -25,16 +25,20 @@ export class AddTaskComponent {
searchValue: string = '';
searchInput: boolean = false;
filteredUsers: User[] = [];
constructor(public firebaseService: FirebaseService) {}
taskData: TaskData = {
taskData: Task = {
id: '',
title: '',
description: '',
date: this.currentDate,
priority: 'medium',
category: '',
status: '',
priority: 'medium',
subtasksTitle: [],
subtasksDone: [],
assigned: [],
subtasks: [],
date: '',
};
receiveAssigned(assigned: string[]) {
@ -42,13 +46,13 @@ export class AddTaskComponent {
}
addSubtask(subtaskName: string) {
this.taskData.subtasks.unshift(subtaskName);
this.taskData.subtasksTitle.unshift(subtaskName);
this.saveTaskData();
}
deleteSubtask(subtaskName: string) {
this.taskData.subtasks.splice(
this.taskData.subtasks.indexOf(subtaskName),
this.taskData.subtasksTitle.splice(
this.taskData.subtasksTitle.indexOf(subtaskName),
1
);
this.saveTaskData();
@ -128,12 +132,12 @@ export class AddTaskComponent {
this.taskData.date = this.currentDate;
this.taskData.category = '';
this.taskData.assigned = [];
this.taskData.subtasks = [];
this.taskData.subtasksTitle = [];
}
onSubmit(ngForm: NgForm) {
if (ngForm.submitted && ngForm.form.valid) {
console.log('Send completed');
this.firebaseService.addNewTask(this.taskData);
this.removeTaskData();
}
}

View file

@ -42,7 +42,7 @@ export class TaskComponent {
// Assigned
userBadged(id: number) {
userBadged(id: string) {
const userId = String(id);
const user = this.firebaseService
.getAllUsers()
@ -60,7 +60,7 @@ export class TaskComponent {
}
}
userBadgedColor(id: number) {
userBadgedColor(id: string) {
const userId = String(id);
const user = this.firebaseService
.getAllUsers()

View file

@ -46,7 +46,7 @@
<div class="date">
<div>
@if (displayNumberOfTaskStatusUrgent().length) {
<span>{{ nextUrgentTasks() }}</span>
<span>{{ nextUrgentTask() }}</span>
<p class="spacer">
{{ "summary.upcomingDeadline" | translate }}
</p>

View file

@ -11,6 +11,8 @@ import { FirebaseService } from '../../services/firebase.service';
styleUrl: './summary.component.scss',
})
export class SummaryComponent {
nextUrgendTask: number[] = [];
constructor(
public firebaseService: FirebaseService,
private translateService: TranslateService
@ -33,19 +35,21 @@ export class SummaryComponent {
.filter((task) => task.priority === 'urgent');
}
nextUrgentTasks() {
nextUrgentTask() {
const urgentTasks = this.displayNumberOfTaskStatusUrgent();
if (urgentTasks.length >= 2) {
const timestamps = urgentTasks.map((task) => task.timestamp);
return this.timeConverter(Math.min(...timestamps));
} else if (urgentTasks.length > 0) {
return this.timeConverter(urgentTasks[0].timestamp);
if (urgentTasks.length > 0) {
const nextTask = urgentTasks.reduce((earliest, current) => {
const currentDate = Date.parse(current.date);
const earliestDate = Date.parse(earliest.date);
return currentDate < earliestDate ? current : earliest;
});
return this.timeConverter(nextTask.date);
}
return;
return null;
}
timeConverter(timestamp: number) {
var a = new Date(timestamp * 1000);
timeConverter(dateString: string) {
var a = new Date(dateString);
var months = [
'Jan.',
'Feb.',

View file

@ -5,5 +5,5 @@ export interface TaskData {
priority: string;
category: string;
assigned: string[];
subtasks: string[];
subtasksTitle: string[];
}

View file

@ -7,6 +7,6 @@ export interface Task {
priority: string;
subtasksTitle: string[];
subtasksDone: boolean[];
assigned: number[];
timestamp: number;
assigned: string[];
date: string;
}

View file

@ -1,6 +1,7 @@
import { Injectable, OnDestroy, inject } from '@angular/core';
import {
Firestore,
addDoc,
collection,
deleteDoc,
doc,
@ -9,6 +10,7 @@ import {
} from '@angular/fire/firestore';
import { Task } from '../interfaces/task.interface';
import { User } from '../interfaces/user.interface';
import { TaskData } from '../interfaces/task-data.interface';
@Injectable({
providedIn: 'root',
})
@ -56,6 +58,16 @@ export class FirebaseService implements OnDestroy {
});
}
async addNewTask(task: TaskData) {
await addDoc(collection(this.firestore, 'tasks'), task)
.catch((err) => {
console.error(err);
})
.then((docRef) => {
console.log('Document written with ID: ', docRef?.id);
});
}
// ------------- USERS ------------- //
subUserList() {