1
0
mirror of https://github.com/bpatrik/pigallery2.git synced 2025-01-12 04:23:09 +02:00

bugfixing aoutocomplete

This commit is contained in:
Braun Patrik 2016-05-04 18:57:31 +02:00
parent 67af4e5ed9
commit 9f793851ce
10 changed files with 28 additions and 19 deletions

View File

@ -52,7 +52,7 @@ export class GalleryRouter{
private addAutoComplete() {
this.app.get("/api/gallery/autocomplete/:text",
// AuthenticationMWs.authenticate,
AuthenticationMWs.authenticate,
GalleryMWs.autocomplete,
RenderingMWs.renderResult
);

View File

@ -1,10 +1,10 @@
import {Photo} from "./Photo";
export class Directory{
constructor(public id:number,
public name:string,
public path:string,
public lastUpdate:Date,
public directories:Array<Directory>,
public photos:Array<Photo>){}
constructor(public id?:string,
public name?:string,
public path?:string,
public lastUpdate?:Date,
public directories:Array<Directory> = [],
public photos:Array<Photo> = []){}
}

View File

@ -1,7 +1,7 @@
import {Utils} from "../Utils";
import {Directory} from "./Directory";
export class Photo {
constructor(public id:number, public name:string, public width:number, public height:number) {
constructor(public id:string, public name:string, public width:number, public height:number) {
}
public static getThumbnailPath(directory:Directory,photo:Photo){

View File

@ -8,5 +8,5 @@ export enum UserRoles{
}
export class User {
constructor(public id?:number,public name?:string, public password?:string, public role:UserRoles = UserRoles.User){}
constructor(public id?:string,public name?:string, public password?:string, public role:UserRoles = UserRoles.User){}
}

View File

@ -3,8 +3,8 @@
<div navbar>
<gallery-search></gallery-search>
</div>
<div body class="container" style="width: 100%; padding:0">
<div *ngIf="currentDirectory" *ngFor="let directory of currentDirectory.directories">
<div body class="container" style="width: 100%; padding:0" *ngIf="currentDirectory">
<div *ngFor="let directory of currentDirectory.directories">
<gallery-directory *ngIf="directory" [directory]="directory"></gallery-directory>
</div>
<gallery-grid [directory]="currentDirectory" [lightbox]="lightbox"></gallery-grid>

View File

@ -24,7 +24,7 @@ import {GallerySearchComponent} from "./search/search.gallery.component";
})
export class GalleryComponent implements OnInit{
currentDirectory:Directory = new Directory(-1,"","/",new Date(),[],[]);
currentDirectory:Directory = new Directory();
constructor(private _galleryService:GalleryService,

View File

@ -3,7 +3,6 @@
import {Component, Input, ElementRef, ViewChild} from '@angular/core';
import {Photo} from "../../../../common/entities/Photo";
import {Directory} from "../../../../common/entities/Directory";
import {Utils} from "../../../../common/Utils";
import {IRenderable, Dimension} from "../../model/IRenderable";
@Component({

View File

@ -1,7 +1,7 @@
<div class="col-sm-4 col-md-5 pull-right">
<form class="navbar-form" role="search">
<div class="input-group">
<input type="text" class="form-control" placeholder="Search" (keyup)="getSuggestions($event)"
<input type="text" class="form-control" placeholder="Search" (keyup)="getSuggestions($event)" (blur)="onFocusLost($event)"
name="srch-term" id="srch-term" autocomplete="off" >
<div class="autocomplete-list" *ngIf="autoCompleteItems.length > 0" >

View File

@ -19,7 +19,7 @@ export class GallerySearchComponent {
getSuggestions(event:KeyboardEvent){
let searchText = (<HTMLInputElement>event.target).value;
if(searchText.length > 0) {
if(searchText.trim().length > 0) {
this._autoCompleteService.autoComplete(searchText).then((message:Message<Array<AutoCompleteItem>>) =>{
if(message.error){
//TODO: implement
@ -28,11 +28,13 @@ export class GallerySearchComponent {
}
this.showSuggestions(message.result,searchText);
});
}else{
this.emptyAutoComplete();
}
}
private showSuggestions(suggestions:Array<AutoCompleteItem>,searchText:string){
this.autoCompleteItems = [];
this.emptyAutoComplete();
suggestions.forEach((item)=>{
let preIndex = item.text.toLowerCase().indexOf(searchText.toLowerCase());
let renderItem = new AutoCompleteRenderItem();
@ -47,6 +49,14 @@ export class GallerySearchComponent {
});
}
public onFocusLost(event){
this.autoCompleteItems = [];
}
private emptyAutoComplete(){
this.autoCompleteItems = [];
}