Added search on backup
This commit is contained in:
8
src/app/shared/components/search/search.component.html
Normal file
8
src/app/shared/components/search/search.component.html
Normal file
@@ -0,0 +1,8 @@
|
||||
<div class="container">
|
||||
<input
|
||||
type="text"
|
||||
placeholder="Enter your search term..."
|
||||
[value]="initialValue"
|
||||
(input)="onInput($event)"
|
||||
/>
|
||||
</div>
|
||||
23
src/app/shared/components/search/search.component.spec.ts
Normal file
23
src/app/shared/components/search/search.component.spec.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
|
||||
import { SearchComponent } from './search.component';
|
||||
|
||||
describe('SearchComponent', () => {
|
||||
let component: SearchComponent;
|
||||
let fixture: ComponentFixture<SearchComponent>;
|
||||
|
||||
beforeEach(async () => {
|
||||
await TestBed.configureTestingModule({
|
||||
imports: [SearchComponent]
|
||||
})
|
||||
.compileComponents();
|
||||
|
||||
fixture = TestBed.createComponent(SearchComponent);
|
||||
component = fixture.componentInstance;
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should create', () => {
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
});
|
||||
43
src/app/shared/components/search/search.component.ts
Normal file
43
src/app/shared/components/search/search.component.ts
Normal file
@@ -0,0 +1,43 @@
|
||||
import { Component, EventEmitter, Input, OnDestroy, OnInit, Output } from '@angular/core';
|
||||
import { FormsModule } from '@angular/forms';
|
||||
import { Subject, debounceTime, distinctUntilChanged, Subscription } from 'rxjs';
|
||||
|
||||
@Component({
|
||||
selector: 'app-search',
|
||||
standalone: true,
|
||||
imports: [FormsModule],
|
||||
templateUrl: './search.component.html',
|
||||
styleUrl: './search.component.scss'
|
||||
})
|
||||
export class SearchComponent implements OnInit, OnDestroy {
|
||||
@Input() initialValue: string = "";
|
||||
@Input() debounceTime = 300;
|
||||
|
||||
@Output() textChange = new EventEmitter<string>();
|
||||
|
||||
inputValue = new Subject<string>();
|
||||
trigger = this.inputValue.pipe(
|
||||
debounceTime(this.debounceTime),
|
||||
distinctUntilChanged()
|
||||
);
|
||||
|
||||
subscriptions: Subscription[] = [];
|
||||
|
||||
constructor() {}
|
||||
|
||||
ngOnInit() {
|
||||
const subscription = this.trigger.subscribe(currentValue => {
|
||||
this.textChange.emit(currentValue);
|
||||
});
|
||||
this.subscriptions.push(subscription);
|
||||
}
|
||||
|
||||
ngOnDestroy() {
|
||||
this.subscriptions.forEach(sub => sub.unsubscribe());
|
||||
}
|
||||
|
||||
onInput(e: any) {
|
||||
this.inputValue.next(e.target.value);
|
||||
}
|
||||
}
|
||||
|
||||
18
src/app/shared/components/search/search.service.ts
Normal file
18
src/app/shared/components/search/search.service.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
import { HttpClient, HttpParams } from "@angular/common/http";
|
||||
import { Injectable } from "@angular/core";
|
||||
import { BACKUP_GET_URL } from "../../constants/backend";
|
||||
import { Backup } from "../../model/backup.model";
|
||||
|
||||
@Injectable({providedIn:'root'})
|
||||
|
||||
export class searchService {
|
||||
|
||||
constructor(private httpClient: HttpClient){}
|
||||
|
||||
search(term: string){
|
||||
console.log(term)
|
||||
let params = new HttpParams().set('term',term)
|
||||
|
||||
return this.httpClient.post<Backup[]>(BACKUP_GET_URL+"/search",{term})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user