Added search on backup
This commit is contained in:
@@ -110,6 +110,18 @@ app.get("/api/backup", async (req,res)=>{
|
|||||||
res.send(allBackup)
|
res.send(allBackup)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
app.post("/api/backup/search", async (req,res)=>{
|
||||||
|
const searchTerm = req.body.term;
|
||||||
|
const foundItems = await BackupModel.find({
|
||||||
|
$or: [
|
||||||
|
{ projectName: new RegExp(searchTerm,"i") },
|
||||||
|
{ volumeName: new RegExp(searchTerm, "i") }
|
||||||
|
]
|
||||||
|
})
|
||||||
|
|
||||||
|
res.status(201).send(foundItems);
|
||||||
|
})
|
||||||
|
|
||||||
app.get("/api/update", async (req,res)=>{
|
app.get("/api/update", async (req,res)=>{
|
||||||
const allUpdate = await UpdateModel.find({ deleted: { $ne: true} }).sort({ Date: 'asc' })
|
const allUpdate = await UpdateModel.find({ deleted: { $ne: true} }).sort({ Date: 'asc' })
|
||||||
res.status(200).send(allUpdate);
|
res.status(200).send(allUpdate);
|
||||||
|
|||||||
@@ -2,6 +2,10 @@
|
|||||||
<div class="title">
|
<div class="title">
|
||||||
<h2>Backup List</h2>
|
<h2>Backup List</h2>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="search">
|
||||||
|
<app-search (textChange)="onTextChange($event)"></app-search>
|
||||||
|
</div>
|
||||||
|
<p>{{searchTerm}}</p>
|
||||||
<div class="table">
|
<div class="table">
|
||||||
<table>
|
<table>
|
||||||
<thead>
|
<thead>
|
||||||
|
|||||||
@@ -2,22 +2,31 @@ import { Component, OnDestroy, OnInit } from '@angular/core';
|
|||||||
import { BackupService } from './backup-list.service';
|
import { BackupService } from './backup-list.service';
|
||||||
import { Backup } from '../../../shared/model/backup.model';
|
import { Backup } from '../../../shared/model/backup.model';
|
||||||
import { CommonModule } from '@angular/common';
|
import { CommonModule } from '@angular/common';
|
||||||
import { Subscription } from 'rxjs';
|
import { debounceTime, distinctUntilChanged, Subscription, switchMap } from 'rxjs';
|
||||||
|
import { FormControl, FormsModule, ReactiveFormsModule } from '@angular/forms';
|
||||||
|
import { SearchComponent } from "../../../shared/components/search/search.component";
|
||||||
|
import { searchService } from '../../../shared/components/search/search.service';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-backup-list',
|
selector: 'app-backup-list',
|
||||||
standalone: true,
|
standalone: true,
|
||||||
imports: [CommonModule],
|
imports: [CommonModule, ReactiveFormsModule, SearchComponent],
|
||||||
templateUrl: './backup-list.component.html',
|
templateUrl: './backup-list.component.html',
|
||||||
styleUrl: './backup-list.component.scss',
|
styleUrl: './backup-list.component.scss',
|
||||||
providers: [BackupService]
|
providers: [BackupService]
|
||||||
})
|
})
|
||||||
export class BackupListComponent implements OnInit, OnDestroy{
|
export class BackupListComponent implements OnInit, OnDestroy{
|
||||||
|
|
||||||
|
|
||||||
backupVolumes: Backup[] = []
|
backupVolumes: Backup[] = []
|
||||||
currentDate = new Date();
|
currentDate = new Date();
|
||||||
innerHTML!: string;
|
innerHTML!: string;
|
||||||
backupVolumesSubscription!: Subscription;
|
backupVolumesSubscription!: Subscription;
|
||||||
constructor(private backupService: BackupService) {}
|
searchTerm: FormControl = new FormControl();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
constructor(private backupService: BackupService, private searchService: searchService) {}
|
||||||
|
|
||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
this.backupVolumesSubscription = this.backupService.allBackups().subscribe((volumes)=>{
|
this.backupVolumesSubscription = this.backupService.allBackups().subscribe((volumes)=>{
|
||||||
@@ -38,4 +47,18 @@ export class BackupListComponent implements OnInit, OnDestroy{
|
|||||||
onReset() {
|
onReset() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
searchRequestSubscriptions: Subscription[] = [];
|
||||||
|
|
||||||
|
onTextChange(changedText: string) {
|
||||||
|
this.cancelPendingRequests();
|
||||||
|
this.searchService.search(changedText).subscribe((resp)=>{
|
||||||
|
this.backupVolumes = resp;
|
||||||
|
})
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
cancelPendingRequests() {
|
||||||
|
this.searchRequestSubscriptions.forEach(sub => sub.unsubscribe());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
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