clean code
This commit is contained in:
parent
9956a31424
commit
484df8e5b9
8 changed files with 47 additions and 27 deletions
|
|
@ -228,9 +228,9 @@
|
||||||
</div>
|
</div>
|
||||||
} @else {
|
} @else {
|
||||||
<img class="add" src="./../../../assets/img/add.svg" alt="" />
|
<img class="add" src="./../../../assets/img/add.svg" alt="" />
|
||||||
} @if (taskData.subtasks) {
|
} @if (taskData.subtasksTitle) {
|
||||||
<div class="subtasks">
|
<div class="subtasks">
|
||||||
@for (task of taskData.subtasks.reverse(); track task) {
|
@for (task of taskData.subtasksTitle.reverse(); track task) {
|
||||||
<div class="single-subtask">
|
<div class="single-subtask">
|
||||||
<p>- {{ task }}</p>
|
<p>- {{ task }}</p>
|
||||||
<img
|
<img
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ import { FormsModule, NgForm, NgModel } from '@angular/forms';
|
||||||
import { AssignedComponent } from './assigned/assigned.component';
|
import { AssignedComponent } from './assigned/assigned.component';
|
||||||
import { User } from '../../interfaces/user.interface';
|
import { User } from '../../interfaces/user.interface';
|
||||||
import { FirebaseService } from '../../services/firebase.service';
|
import { FirebaseService } from '../../services/firebase.service';
|
||||||
import { TaskData } from '../../interfaces/task-data.interface';
|
import { Task } from '../../interfaces/task.interface';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-add-task',
|
selector: 'app-add-task',
|
||||||
|
|
@ -25,16 +25,20 @@ export class AddTaskComponent {
|
||||||
searchValue: string = '';
|
searchValue: string = '';
|
||||||
searchInput: boolean = false;
|
searchInput: boolean = false;
|
||||||
filteredUsers: User[] = [];
|
filteredUsers: User[] = [];
|
||||||
|
|
||||||
constructor(public firebaseService: FirebaseService) {}
|
constructor(public firebaseService: FirebaseService) {}
|
||||||
|
|
||||||
taskData: TaskData = {
|
taskData: Task = {
|
||||||
|
id: '',
|
||||||
title: '',
|
title: '',
|
||||||
description: '',
|
description: '',
|
||||||
date: this.currentDate,
|
|
||||||
priority: 'medium',
|
|
||||||
category: '',
|
category: '',
|
||||||
|
status: '',
|
||||||
|
priority: 'medium',
|
||||||
|
subtasksTitle: [],
|
||||||
|
subtasksDone: [],
|
||||||
assigned: [],
|
assigned: [],
|
||||||
subtasks: [],
|
date: '',
|
||||||
};
|
};
|
||||||
|
|
||||||
receiveAssigned(assigned: string[]) {
|
receiveAssigned(assigned: string[]) {
|
||||||
|
|
@ -42,13 +46,13 @@ export class AddTaskComponent {
|
||||||
}
|
}
|
||||||
|
|
||||||
addSubtask(subtaskName: string) {
|
addSubtask(subtaskName: string) {
|
||||||
this.taskData.subtasks.unshift(subtaskName);
|
this.taskData.subtasksTitle.unshift(subtaskName);
|
||||||
this.saveTaskData();
|
this.saveTaskData();
|
||||||
}
|
}
|
||||||
|
|
||||||
deleteSubtask(subtaskName: string) {
|
deleteSubtask(subtaskName: string) {
|
||||||
this.taskData.subtasks.splice(
|
this.taskData.subtasksTitle.splice(
|
||||||
this.taskData.subtasks.indexOf(subtaskName),
|
this.taskData.subtasksTitle.indexOf(subtaskName),
|
||||||
1
|
1
|
||||||
);
|
);
|
||||||
this.saveTaskData();
|
this.saveTaskData();
|
||||||
|
|
@ -128,12 +132,12 @@ export class AddTaskComponent {
|
||||||
this.taskData.date = this.currentDate;
|
this.taskData.date = this.currentDate;
|
||||||
this.taskData.category = '';
|
this.taskData.category = '';
|
||||||
this.taskData.assigned = [];
|
this.taskData.assigned = [];
|
||||||
this.taskData.subtasks = [];
|
this.taskData.subtasksTitle = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
onSubmit(ngForm: NgForm) {
|
onSubmit(ngForm: NgForm) {
|
||||||
if (ngForm.submitted && ngForm.form.valid) {
|
if (ngForm.submitted && ngForm.form.valid) {
|
||||||
console.log('Send completed');
|
this.firebaseService.addNewTask(this.taskData);
|
||||||
this.removeTaskData();
|
this.removeTaskData();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -42,7 +42,7 @@ export class TaskComponent {
|
||||||
|
|
||||||
// Assigned
|
// Assigned
|
||||||
|
|
||||||
userBadged(id: number) {
|
userBadged(id: string) {
|
||||||
const userId = String(id);
|
const userId = String(id);
|
||||||
const user = this.firebaseService
|
const user = this.firebaseService
|
||||||
.getAllUsers()
|
.getAllUsers()
|
||||||
|
|
@ -60,7 +60,7 @@ export class TaskComponent {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
userBadgedColor(id: number) {
|
userBadgedColor(id: string) {
|
||||||
const userId = String(id);
|
const userId = String(id);
|
||||||
const user = this.firebaseService
|
const user = this.firebaseService
|
||||||
.getAllUsers()
|
.getAllUsers()
|
||||||
|
|
|
||||||
|
|
@ -46,7 +46,7 @@
|
||||||
<div class="date">
|
<div class="date">
|
||||||
<div>
|
<div>
|
||||||
@if (displayNumberOfTaskStatusUrgent().length) {
|
@if (displayNumberOfTaskStatusUrgent().length) {
|
||||||
<span>{{ nextUrgentTasks() }}</span>
|
<span>{{ nextUrgentTask() }}</span>
|
||||||
<p class="spacer">
|
<p class="spacer">
|
||||||
{{ "summary.upcomingDeadline" | translate }}
|
{{ "summary.upcomingDeadline" | translate }}
|
||||||
</p>
|
</p>
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,8 @@ import { FirebaseService } from '../../services/firebase.service';
|
||||||
styleUrl: './summary.component.scss',
|
styleUrl: './summary.component.scss',
|
||||||
})
|
})
|
||||||
export class SummaryComponent {
|
export class SummaryComponent {
|
||||||
|
nextUrgendTask: number[] = [];
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
public firebaseService: FirebaseService,
|
public firebaseService: FirebaseService,
|
||||||
private translateService: TranslateService
|
private translateService: TranslateService
|
||||||
|
|
@ -33,19 +35,21 @@ export class SummaryComponent {
|
||||||
.filter((task) => task.priority === 'urgent');
|
.filter((task) => task.priority === 'urgent');
|
||||||
}
|
}
|
||||||
|
|
||||||
nextUrgentTasks() {
|
nextUrgentTask() {
|
||||||
const urgentTasks = this.displayNumberOfTaskStatusUrgent();
|
const urgentTasks = this.displayNumberOfTaskStatusUrgent();
|
||||||
if (urgentTasks.length >= 2) {
|
if (urgentTasks.length > 0) {
|
||||||
const timestamps = urgentTasks.map((task) => task.timestamp);
|
const nextTask = urgentTasks.reduce((earliest, current) => {
|
||||||
return this.timeConverter(Math.min(...timestamps));
|
const currentDate = Date.parse(current.date);
|
||||||
} else if (urgentTasks.length > 0) {
|
const earliestDate = Date.parse(earliest.date);
|
||||||
return this.timeConverter(urgentTasks[0].timestamp);
|
return currentDate < earliestDate ? current : earliest;
|
||||||
|
});
|
||||||
|
return this.timeConverter(nextTask.date);
|
||||||
}
|
}
|
||||||
return;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
timeConverter(timestamp: number) {
|
timeConverter(dateString: string) {
|
||||||
var a = new Date(timestamp * 1000);
|
var a = new Date(dateString);
|
||||||
var months = [
|
var months = [
|
||||||
'Jan.',
|
'Jan.',
|
||||||
'Feb.',
|
'Feb.',
|
||||||
|
|
|
||||||
|
|
@ -5,5 +5,5 @@ export interface TaskData {
|
||||||
priority: string;
|
priority: string;
|
||||||
category: string;
|
category: string;
|
||||||
assigned: string[];
|
assigned: string[];
|
||||||
subtasks: string[];
|
subtasksTitle: string[];
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,6 @@ export interface Task {
|
||||||
priority: string;
|
priority: string;
|
||||||
subtasksTitle: string[];
|
subtasksTitle: string[];
|
||||||
subtasksDone: boolean[];
|
subtasksDone: boolean[];
|
||||||
assigned: number[];
|
assigned: string[];
|
||||||
timestamp: number;
|
date: string;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
import { Injectable, OnDestroy, inject } from '@angular/core';
|
import { Injectable, OnDestroy, inject } from '@angular/core';
|
||||||
import {
|
import {
|
||||||
Firestore,
|
Firestore,
|
||||||
|
addDoc,
|
||||||
collection,
|
collection,
|
||||||
deleteDoc,
|
deleteDoc,
|
||||||
doc,
|
doc,
|
||||||
|
|
@ -9,6 +10,7 @@ import {
|
||||||
} from '@angular/fire/firestore';
|
} from '@angular/fire/firestore';
|
||||||
import { Task } from '../interfaces/task.interface';
|
import { Task } from '../interfaces/task.interface';
|
||||||
import { User } from '../interfaces/user.interface';
|
import { User } from '../interfaces/user.interface';
|
||||||
|
import { TaskData } from '../interfaces/task-data.interface';
|
||||||
@Injectable({
|
@Injectable({
|
||||||
providedIn: 'root',
|
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 ------------- //
|
// ------------- USERS ------------- //
|
||||||
|
|
||||||
subUserList() {
|
subUserList() {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue