added search
This commit is contained in:
parent
71867c1738
commit
0aba24ada5
6 changed files with 54 additions and 10 deletions
|
|
@ -58,13 +58,21 @@
|
||||||
<div class="assigned">
|
<div class="assigned">
|
||||||
<p>Assigned to</p>
|
<p>Assigned to</p>
|
||||||
<input
|
<input
|
||||||
class="searchfield"
|
#searchField
|
||||||
|
id="search-assigned"
|
||||||
|
class="search-assigned"
|
||||||
|
name="search"
|
||||||
type="text"
|
type="text"
|
||||||
|
[(ngModel)]="searchValue"
|
||||||
|
(input)="searchTask()"
|
||||||
autocomplete="off"
|
autocomplete="off"
|
||||||
(click)="toggleAssignedMenu()"
|
(click)="toggleAssignedMenu()"
|
||||||
/>
|
/>
|
||||||
@if (isAssignedOpen) {
|
@if (isAssignedOpen) {
|
||||||
<app-assigned></app-assigned>
|
<app-assigned
|
||||||
|
[filteredUsers]="filteredUsers"
|
||||||
|
[searchInput]="searchInput"
|
||||||
|
></app-assigned>
|
||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -37,7 +37,7 @@ p {
|
||||||
padding: 6px;
|
padding: 6px;
|
||||||
p {
|
p {
|
||||||
color: var(--red);
|
color: var(--red);
|
||||||
font-size: 16px;
|
font-size: 12px;
|
||||||
font-weight: 400;
|
font-weight: 400;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,8 @@ import { CommonModule } from '@angular/common';
|
||||||
import { Component, HostListener, ViewChild } from '@angular/core';
|
import { Component, HostListener, ViewChild } from '@angular/core';
|
||||||
import { FormsModule, NgForm, NgModel } from '@angular/forms';
|
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 { FirebaseService } from '../../services/firebase.service';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-add-task',
|
selector: 'app-add-task',
|
||||||
|
|
@ -17,7 +19,12 @@ export class AddTaskComponent {
|
||||||
|
|
||||||
currentDate: string = new Date().toISOString().split('T')[0];
|
currentDate: string = new Date().toISOString().split('T')[0];
|
||||||
dateInPast: boolean = false;
|
dateInPast: boolean = false;
|
||||||
isAssignedOpen: boolean = true;
|
isAssignedOpen: boolean = false;
|
||||||
|
searchValue: string = '';
|
||||||
|
searchInput: boolean = false;
|
||||||
|
filteredUsers: User[] = [];
|
||||||
|
|
||||||
|
constructor(public firebaseService: FirebaseService) {}
|
||||||
|
|
||||||
taskData = {
|
taskData = {
|
||||||
title: '',
|
title: '',
|
||||||
|
|
@ -37,6 +44,27 @@ export class AddTaskComponent {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
updateSearchInput() {
|
||||||
|
if (this.searchValue) {
|
||||||
|
this.searchInput = this.searchValue.toLowerCase().length > 0;
|
||||||
|
} else {
|
||||||
|
this.searchInput = false;
|
||||||
|
}
|
||||||
|
return this.searchInput;
|
||||||
|
}
|
||||||
|
|
||||||
|
searchTask(): void {
|
||||||
|
this.updateSearchInput();
|
||||||
|
this.filteredUsers = this.firebaseService
|
||||||
|
.getAllUserWithoutGuest()
|
||||||
|
.filter(
|
||||||
|
(user) =>
|
||||||
|
user.firstName.toLowerCase().includes(this.searchValue) ||
|
||||||
|
user.lastName.toLowerCase().includes(this.searchValue) ||
|
||||||
|
user.initials.toLowerCase().includes(this.searchValue)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
toggleAssignedMenu() {
|
toggleAssignedMenu() {
|
||||||
this.isAssignedOpen = !this.isAssignedOpen;
|
this.isAssignedOpen = !this.isAssignedOpen;
|
||||||
}
|
}
|
||||||
|
|
@ -93,7 +121,7 @@ export class AddTaskComponent {
|
||||||
@HostListener('document:click', ['$event'])
|
@HostListener('document:click', ['$event'])
|
||||||
checkOpenNavbar(event: MouseEvent) {
|
checkOpenNavbar(event: MouseEvent) {
|
||||||
const targetElement = event.target as HTMLElement;
|
const targetElement = event.target as HTMLElement;
|
||||||
if (!targetElement.closest('.assigned')) {
|
if (!targetElement.closest('.search-assigned')) {
|
||||||
this.isAssignedOpen = false;
|
this.isAssignedOpen = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
<section>
|
<section>
|
||||||
@for (user of loadAllUserWithoutGuest(); track user; let index = $index) {
|
@for (user of displayAssigned(); track user; let index = $index) {
|
||||||
<div
|
<div
|
||||||
class="content"
|
class="content"
|
||||||
(click)="addAssignedToTask(user.id)"
|
(click)="addAssignedToTask(user.id)"
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,8 @@ import { User } from '../../../interfaces/user.interface';
|
||||||
styleUrl: './assigned.component.scss',
|
styleUrl: './assigned.component.scss',
|
||||||
})
|
})
|
||||||
export class AssignedComponent {
|
export class AssignedComponent {
|
||||||
|
@Input() filteredUsers: User[] = [];
|
||||||
|
@Input() searchInput: boolean = false;
|
||||||
assigned: string[] = [];
|
assigned: string[] = [];
|
||||||
|
|
||||||
constructor(public firebaseService: FirebaseService) {
|
constructor(public firebaseService: FirebaseService) {
|
||||||
|
|
@ -45,9 +47,11 @@ export class AssignedComponent {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
loadAllUserWithoutGuest(): User[] {
|
displayAssigned() {
|
||||||
return this.firebaseService
|
if (this.searchInput) {
|
||||||
.getAllUsers()
|
return this.filteredUsers;
|
||||||
.filter((user) => user.initials !== 'G');
|
} else {
|
||||||
|
return this.firebaseService.getAllUserWithoutGuest();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -72,6 +72,10 @@ export class FirebaseService implements OnDestroy {
|
||||||
return this.allUsers;
|
return this.allUsers;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getAllUserWithoutGuest(): User[] {
|
||||||
|
return this.getAllUsers().filter((user) => user.initials !== 'G');
|
||||||
|
}
|
||||||
|
|
||||||
getCurrentUserId() {
|
getCurrentUserId() {
|
||||||
let currentUser = localStorage.getItem('currentUser');
|
let currentUser = localStorage.getItem('currentUser');
|
||||||
if (currentUser !== null) {
|
if (currentUser !== null) {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue