2 Commits

Author SHA1 Message Date
f37ce410eb (front) Improve search result stype
Template to show results with glyphicon

(cherry picked from commit 550d8e7b343dc262be87182ae13f231ccc995b55)

Improve style
Stealing CSS from the demo site

(cherry picked from commit 75bebac0ac6080a0210d2b156a14f8a0f70067db)
2021-08-22 17:34:56 +02:00
124a30ad8c (front) Suggester with ng-bootstrap
Really "complex" search method, but yea, it's work :s

(cherry picked from commit 0789a92b0a9153b6112ad39b1f61090bdbeab197)
2021-08-22 17:33:33 +02:00
8 changed files with 474 additions and 305 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -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",

View File

@@ -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,

View File

@@ -34,5 +34,44 @@
border-radius: 50%; border-radius: 50%;
background-color: #9b59b6; background-color: #9b59b6;
margin: 0 auto; margin: 0 auto;
}
/* Style for autocompletion */
/* Stolen from https://ng-bootstrap.github.io/#/components/typeahead/examples */
::ng-deep .dropdown-item {
display: block;
width: 100%;
padding: .25rem 1.5rem;
clear: both;
font-weight: 400;
color: #212529;
text-align: inherit;
white-space: nowrap;
background-color: transparent;
border: 0
}
::ng-deep .dropdown-item:focus,
::ng-deep .dropdown-item:hover {
color: #16181b;
text-decoration: none;
background-color: #f8f9fa
}
::ng-deep .dropdown-item.active,
::ng-deep .dropdown-item:active {
color: #fff;
text-decoration: none;
background-color: #007bff
}
::ng-deep .dropdown-item.disabled,
::ng-deep .dropdown-item:disabled {
color: #6c757d;
pointer-events: none;
background-color: transparent
}
::ng-deep .dropdown-menu.show {
display: block
} }

View File

@@ -77,6 +77,14 @@
</div> </div>
</div> </div>
<ng-template #rt let-r="result" let-t="term">
<!-- glyphicon glyphicon-cd -->
<span *ngIf="r.type == 'artist'" class="glyphicon glyphicon-user"></span>
<span *ngIf="r.type == 'album'" class="glyphicon glyphicon-cd"></span>
&nbsp; <ngb-highlight [result]="r.name" [term]="t"></ngb-highlight>
</ng-template>
<form class="navbar-form"> <form class="navbar-form">
<div class="form-group" style="display:inline;"> <div class="form-group" style="display:inline;">
<div class="input-group" style="display:table;"> <div class="input-group" style="display:table;">
@@ -85,13 +93,10 @@
</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)"> [resultTemplate]="rt"
<datalist id="dynmicUserIds"> (selectItem)="onSelectSearch($event)">
<option *ngFor="let item of suggested" [value]="item.name" [label]="item.type" [id]="item">{{item}}</option>
</datalist>
</div> </div>
</div> </div>
</form> </form>

View File

@@ -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)
)
} }

View File

@@ -1,8 +1,4 @@
export class Suggested { export class Suggested {
name: string; name: string;
type: string; type: string;
public toString() : string {
return `${this.name} (${this.type})`;
}
} }

View File

@@ -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.