adding keyword and position to autocomplete
This commit is contained in:
parent
e7fb834418
commit
b96d083f4b
@ -13,27 +13,57 @@ export class MongoSearchManager implements ISearchManager {
|
|||||||
|
|
||||||
console.log("autocomplete: " + text);
|
console.log("autocomplete: " + text);
|
||||||
let items:Array<AutoCompleteItem> = [];
|
let items:Array<AutoCompleteItem> = [];
|
||||||
PhotoModel.find({name: {$regex: text, $options: "i"}}).limit(10).select('name').exec((err, res:Array<any>) => {
|
let promises = [];
|
||||||
if (err || !res) {
|
|
||||||
return cb(err, null);
|
|
||||||
}
|
|
||||||
items = items.concat(this.encapsulateAutoComplete(res.map(r => r.name), AutoCompeleteTypes.image));
|
|
||||||
|
|
||||||
|
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({
|
DirectoryModel.find({
|
||||||
name: {
|
name: {$regex: text, $options: "i"}
|
||||||
$regex: text,
|
}).limit(10).select('name').exec().then((res:Array<any>)=> {
|
||||||
$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.directory));
|
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) {
|
search(text, cb:(error:any, result:SearchResult) => void) {
|
||||||
@ -108,5 +138,17 @@ export class MongoSearchManager implements ISearchManager {
|
|||||||
return res;
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -61,7 +61,7 @@ export class GalleryRouter {
|
|||||||
|
|
||||||
private addAutoComplete() {
|
private addAutoComplete() {
|
||||||
this.app.get("/api/gallery/autocomplete/:text",
|
this.app.get("/api/gallery/autocomplete/:text",
|
||||||
AuthenticationMWs.authenticate,
|
// AuthenticationMWs.authenticate,
|
||||||
GalleryMWs.autocomplete,
|
GalleryMWs.autocomplete,
|
||||||
RenderingMWs.renderResult
|
RenderingMWs.renderResult
|
||||||
);
|
);
|
||||||
|
|||||||
@ -1,11 +1,16 @@
|
|||||||
export enum AutoCompeleteTypes {
|
export enum AutoCompeleteTypes {
|
||||||
image,
|
image,
|
||||||
directory,
|
directory,
|
||||||
imageTag
|
keyword,
|
||||||
|
position
|
||||||
}
|
}
|
||||||
|
|
||||||
export class AutoCompleteItem {
|
export class AutoCompleteItem {
|
||||||
constructor(public text:string, public type:AutoCompeleteTypes) {
|
constructor(public text:string, public type:AutoCompeleteTypes) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
equals(other:AutoCompleteItem) {
|
||||||
|
return this.text === other.text && this.type === other.type;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
<div class="photo-container" (mouseover)="hover()" (mouseout)="mouseOut()">
|
<div class="photo-container" (mouseover)="hover()" (mouseout)="mouseOut()">
|
||||||
<img #image [src]="gridPhoto.getThumbnailPath()">
|
<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-name">{{gridPhoto.photo.name}}</div>
|
||||||
|
|
||||||
<div class="photo-position" *ngIf="gridPhoto.photo.metadata.positionData">
|
<div class="photo-position" *ngIf="gridPhoto.photo.metadata.positionData">
|
||||||
|
|||||||
@ -1,7 +1,6 @@
|
|||||||
///<reference path="../../../../browser.d.ts"/>
|
///<reference path="../../../../browser.d.ts"/>
|
||||||
|
|
||||||
import {Component, Input, ElementRef, ViewChild} from "@angular/core";
|
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 {IRenderable, Dimension} from "../../../model/IRenderable";
|
||||||
import {GridPhoto} from "../GridPhoto";
|
import {GridPhoto} from "../GridPhoto";
|
||||||
|
|
||||||
@ -14,23 +13,25 @@ export class GalleryPhotoComponent implements IRenderable {
|
|||||||
@Input() gridPhoto:GridPhoto;
|
@Input() gridPhoto:GridPhoto;
|
||||||
@ViewChild("image") imageRef:ElementRef;
|
@ViewChild("image") imageRef:ElementRef;
|
||||||
@ViewChild("info") infoDiv:ElementRef;
|
@ViewChild("info") infoDiv:ElementRef;
|
||||||
infoHeight:number = 0;
|
|
||||||
infobackground = "";
|
|
||||||
|
|
||||||
|
infoStyle = {
|
||||||
|
height: 0,
|
||||||
|
background: ""
|
||||||
|
};
|
||||||
|
|
||||||
constructor(private animBuilder:AnimationBuilder) {
|
constructor() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
hover() {
|
hover() {
|
||||||
this.infoHeight = this.infoDiv.nativeElement.clientHeight;
|
this.infoStyle.height = this.infoDiv.nativeElement.clientHeight;
|
||||||
this.infobackground = "rgba(0,0,0,0.8)";
|
this.infoStyle.background = "rgba(0,0,0,0.8)";
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
mouseOut() {
|
mouseOut() {
|
||||||
this.infoHeight = 0;
|
this.infoStyle.height = 0;
|
||||||
this.infobackground = "rgba(0,0,0,0.0)";
|
this.infoStyle.background = "rgba(0,0,0,0.0)";
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user