1
0
mirror of https://github.com/xuthus83/pigallery2.git synced 2025-01-14 14:43:17 +08:00

adding keyword and position to autocomplete

This commit is contained in:
Braun Patrik 2016-05-15 19:36:23 +02:00
parent e7fb834418
commit b96d083f4b
5 changed files with 74 additions and 26 deletions

View File

@ -13,27 +13,57 @@ export class MongoSearchManager implements ISearchManager {
console.log("autocomplete: " + text);
let items:Array<AutoCompleteItem> = [];
PhotoModel.find({name: {$regex: text, $options: "i"}}).limit(10).select('name').exec((err, res:Array<any>) => {
if (err || !res) {
return cb(err, null);
}
items = items.concat(this.encapsulateAutoComplete(res.map(r => r.name), AutoCompeleteTypes.image));
let promises = [];
promises.push(
PhotoModel.find({name: {$regex: text, $options: "i"}})
.limit(10).select('name').exec().then((res:Array<any>)=> {
items = items.concat(this.encapsulateAutoComplete(res.map(r => r.name), AutoCompeleteTypes.image));
}));
promises.push(
PhotoModel.find({"metadata.positionData.city": {$regex: text, $options: "i"}})
.limit(10).select('metadata.positionData.city').exec().then((res:Array<any>)=> {
items = items.concat(this.encapsulateAutoComplete(res.map(r => r.metadata.positionData.city), AutoCompeleteTypes.position));
}));
promises.push(
PhotoModel.find({"metadata.positionData.state": {$regex: text, $options: "i"}})
.limit(10).select('metadata.positionData.state').exec().then((res:Array<any>)=> {
items = items.concat(this.encapsulateAutoComplete(res.map(r => r.metadata.positionData.state), AutoCompeleteTypes.position));
}));
promises.push(
PhotoModel.find({"metadata.positionData.country": {$regex: text, $options: "i"}})
.limit(10).select('metadata.positionData.country').exec().then((res:Array<any>)=> {
items = items.concat(this.encapsulateAutoComplete(res.map(r => r.metadata.positionData.country), AutoCompeleteTypes.position));
}));
//TODO: fix caseinsensitivity
promises.push(
PhotoModel.find({"metadata.keywords": {$regex: text, $options: "i"}})
.limit(10).select('metadata.keywords').exec().then((res:Array<any>)=> {
res.forEach((photo)=> {
items = items.concat(this.encapsulateAutoComplete(photo.metadata.keywords.filter(k => k.indexOf(text) != -1), AutoCompeleteTypes.keyword));
});
}));
promises.push(
DirectoryModel.find({
name: {
$regex: text,
$options: "i"
}
}).limit(10).select('name').exec((err, res:Array<any>) => {
if (err || !res) {
return cb(err, null);
}
name: {$regex: text, $options: "i"}
}).limit(10).select('name').exec().then((res:Array<any>)=> {
items = items.concat(this.encapsulateAutoComplete(res.map(r => r.name), AutoCompeleteTypes.directory));
return cb(null, items);
});
}));
Promise.all(promises).then(()=> {
return cb(null, this.autoCompleteItemsUnique(items));
}).catch((err)=> {
console.error(err);
return cb(err, null);
});
}
search(text, cb:(error:any, result:SearchResult) => void) {
@ -108,5 +138,17 @@ export class MongoSearchManager implements ISearchManager {
return res;
}
private autoCompleteItemsUnique(array:Array<AutoCompleteItem>) {
var a = array.concat();
for (var i = 0; i < a.length; ++i) {
for (var j = i + 1; j < a.length; ++j) {
if (a[i].equals(a[j]))
a.splice(j--, 1);
}
}
return a;
}
}

View File

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

View File

@ -1,11 +1,16 @@
export enum AutoCompeleteTypes {
image,
directory,
imageTag
keyword,
position
}
export class AutoCompleteItem {
constructor(public text:string, public type:AutoCompeleteTypes) {
}
equals(other:AutoCompleteItem) {
return this.text === other.text && this.type === other.type;
}
}

View File

@ -1,6 +1,6 @@
<div class="photo-container" (mouseover)="hover()" (mouseout)="mouseOut()">
<img #image [src]="gridPhoto.getThumbnailPath()">
<div class="info" #info [style.margin-top.px]="-infoHeight" [style.background]="infobackground">
<div class="info" #info [style.margin-top.px]="-infoStyle.height" [style.background]="infoStyle.background">
<div class="photo-name">{{gridPhoto.photo.name}}</div>
<div class="photo-position" *ngIf="gridPhoto.photo.metadata.positionData">

View File

@ -1,7 +1,6 @@
///<reference path="../../../../browser.d.ts"/>
import {Component, Input, ElementRef, ViewChild} from "@angular/core";
import {AnimationBuilder} from "@angular/platform-browser/src/animate/animation_builder";
import {IRenderable, Dimension} from "../../../model/IRenderable";
import {GridPhoto} from "../GridPhoto";
@ -14,23 +13,25 @@ export class GalleryPhotoComponent implements IRenderable {
@Input() gridPhoto:GridPhoto;
@ViewChild("image") imageRef:ElementRef;
@ViewChild("info") infoDiv:ElementRef;
infoHeight:number = 0;
infobackground = "";
infoStyle = {
height: 0,
background: ""
};
constructor(private animBuilder:AnimationBuilder) {
constructor() {
}
hover() {
this.infoHeight = this.infoDiv.nativeElement.clientHeight;
this.infobackground = "rgba(0,0,0,0.8)";
this.infoStyle.height = this.infoDiv.nativeElement.clientHeight;
this.infoStyle.background = "rgba(0,0,0,0.8)";
}
mouseOut() {
this.infoHeight = 0;
this.infobackground = "rgba(0,0,0,0.0)";
this.infoStyle.height = 0;
this.infoStyle.background = "rgba(0,0,0,0.0)";
}