(front) Suggester with ng-bootstrap
Really "complex" search method, but yea, it's work :s (cherry picked from commit 0789a92b0a9153b6112ad39b1f61090bdbeab197)
This commit is contained in:
662
dashboard/package-lock.json
generated
662
dashboard/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -19,15 +19,17 @@
|
|||||||
"@angular/platform-browser": "~11.0.4",
|
"@angular/platform-browser": "~11.0.4",
|
||||||
"@angular/platform-browser-dynamic": "~11.0.4",
|
"@angular/platform-browser-dynamic": "~11.0.4",
|
||||||
"@angular/router": "~11.0.4",
|
"@angular/router": "~11.0.4",
|
||||||
"rxjs": "~6.6.0",
|
"@ng-bootstrap/ng-bootstrap": "^9.1.3",
|
||||||
"zone.js": "~0.10.2",
|
|
||||||
"bootstrap": "^3.3.7",
|
"bootstrap": "^3.3.7",
|
||||||
"tslib": "^2.0.0"
|
"rxjs": "~6.6.0",
|
||||||
|
"tslib": "^2.0.0",
|
||||||
|
"zone.js": "~0.10.2"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@angular-devkit/build-angular": "~0.1100.4",
|
"@angular-devkit/build-angular": "~0.1100.4",
|
||||||
"@angular/cli": "~11.0.4",
|
"@angular/cli": "~11.0.4",
|
||||||
"@angular/compiler-cli": "~11.0.4",
|
"@angular/compiler-cli": "~11.0.4",
|
||||||
|
"@angular/localize": "^11.0.4",
|
||||||
"@types/jasmine": "~3.6.0",
|
"@types/jasmine": "~3.6.0",
|
||||||
"@types/node": "^12.11.1",
|
"@types/node": "^12.11.1",
|
||||||
"codelyzer": "^6.0.0",
|
"codelyzer": "^6.0.0",
|
||||||
|
|||||||
@@ -23,12 +23,15 @@ import { ConvertSizeToStringPipe } from './pipes/convert-size-to-string.pipe';
|
|||||||
import { RoundPipe } from './pipes/round.pipe';
|
import { RoundPipe } from './pipes/round.pipe';
|
||||||
import { AlbumsComponent } from './albums/albums.component';
|
import { AlbumsComponent } from './albums/albums.component';
|
||||||
|
|
||||||
|
import {NgbModule} from '@ng-bootstrap/ng-bootstrap';
|
||||||
|
|
||||||
@NgModule({
|
@NgModule({
|
||||||
imports: [
|
imports: [
|
||||||
BrowserModule,
|
BrowserModule,
|
||||||
HttpClientModule,
|
HttpClientModule,
|
||||||
FormsModule,
|
FormsModule,
|
||||||
AppRoutingModule
|
AppRoutingModule,
|
||||||
|
NgbModule
|
||||||
],
|
],
|
||||||
declarations: [
|
declarations: [
|
||||||
AppComponent,
|
AppComponent,
|
||||||
|
|||||||
@@ -85,13 +85,9 @@
|
|||||||
</span>
|
</span>
|
||||||
<input class="form-control" type="text" name="search" placeholder="Search Here" autocomplete="off" autofocus="autofocus"
|
<input class="form-control" type="text" name="search" placeholder="Search Here" autocomplete="off" autofocus="autofocus"
|
||||||
id="searchSuggest"
|
id="searchSuggest"
|
||||||
list="dynmicUserIds"
|
|
||||||
[(ngModel)]="searchTerm"
|
[(ngModel)]="searchTerm"
|
||||||
(keyup)="onSearchChange()"
|
[ngbTypeahead]="search"
|
||||||
(change)="onSearchSelected($event)">
|
(selectItem)="onSelectSearch($event)">
|
||||||
<datalist id="dynmicUserIds">
|
|
||||||
<option *ngFor="let item of suggested" [value]="item.name" [label]="item.type" [id]="item">{{item}}</option>
|
|
||||||
</datalist>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
|
|||||||
@@ -4,16 +4,16 @@ import { Router } from '@angular/router';
|
|||||||
import { ElsService } from './../els.service';
|
import { ElsService } from './../els.service';
|
||||||
import { Song } from './../model/song';
|
import { Song } from './../model/song';
|
||||||
import { Bucket } from './../model/bucket';
|
import { Bucket } from './../model/bucket';
|
||||||
import { Album } from './../model/album';
|
|
||||||
import { Artist } from './../model/artist';
|
|
||||||
import { Suggested } from '../model/suggested';
|
import { Suggested } from '../model/suggested';
|
||||||
|
|
||||||
|
import {Observable, of, OperatorFunction} from 'rxjs';
|
||||||
|
import {catchError, debounceTime, distinctUntilChanged, map, tap, switchMap} from 'rxjs/operators';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-dashboard',
|
selector: 'app-dashboard',
|
||||||
templateUrl: './dashboard.component.html',
|
templateUrl: './dashboard.component.html',
|
||||||
styleUrls: [ './dashboard.component.css' ]
|
styleUrls: [ './dashboard.component.css' ]
|
||||||
})
|
})
|
||||||
|
|
||||||
export class DashboardComponent implements OnInit {
|
export class DashboardComponent implements OnInit {
|
||||||
totalTime = 0;
|
totalTime = 0;
|
||||||
totalSize = 0;
|
totalSize = 0;
|
||||||
@@ -119,18 +119,26 @@ export class DashboardComponent implements OnInit {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
onSearchChange() {
|
onSelectSearch($event) {
|
||||||
this.elsService.getSuggest(this.searchTerm).subscribe(result => this.suggested = result);
|
this.route.navigate(['/' + $event.item.type + '/' + $event.item.name])
|
||||||
}
|
}
|
||||||
|
|
||||||
onSearchSelected($event) {
|
searching = false;
|
||||||
let selected = $event.target.value
|
searchFailed = false;
|
||||||
// FIXME Not possible to get good element (just value)
|
|
||||||
// Need to use a plugin to do this correctly
|
search: OperatorFunction<string, readonly string[]> = (text$: Observable<string>) =>
|
||||||
this.suggested.forEach(element => {
|
text$.pipe(
|
||||||
if (element.name == selected) {
|
debounceTime(300),
|
||||||
this.route.navigate(['/' + element.type + '/' + element.name])
|
distinctUntilChanged(),
|
||||||
}
|
tap(() => this.searching = true),
|
||||||
});
|
switchMap(term =>
|
||||||
}
|
this.elsService.getSuggest(term).pipe(
|
||||||
|
tap(() => this.searchFailed = false),
|
||||||
|
catchError(() => {
|
||||||
|
this.searchFailed = true;
|
||||||
|
return of([]);
|
||||||
|
}))
|
||||||
|
),
|
||||||
|
tap(() => this.searching = false)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,7 @@
|
|||||||
|
/***************************************************************************************************
|
||||||
|
* Load `$localize` onto the global scope - used if i18n tags appear in Angular templates.
|
||||||
|
*/
|
||||||
|
import '@angular/localize/init';
|
||||||
/**
|
/**
|
||||||
* This file includes polyfills needed by Angular and is loaded before the app.
|
* This file includes polyfills needed by Angular and is loaded before the app.
|
||||||
* You can add your own extra polyfills to this file.
|
* You can add your own extra polyfills to this file.
|
||||||
|
|||||||
Reference in New Issue
Block a user