diff --git a/backend/model/mongoose/MongoSearchManager.ts b/backend/model/mongoose/MongoSearchManager.ts index 92d38f2b..cdd11a02 100644 --- a/backend/model/mongoose/MongoSearchManager.ts +++ b/backend/model/mongoose/MongoSearchManager.ts @@ -13,27 +13,57 @@ export class MongoSearchManager implements ISearchManager { console.log("autocomplete: " + text); let items:Array = []; - PhotoModel.find({name: {$regex: text, $options: "i"}}).limit(10).select('name').exec((err, res:Array) => { - 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)=> { + 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)=> { + 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)=> { + 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)=> { + 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)=> { + 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) => { - if (err || !res) { - return cb(err, null); - } + name: {$regex: text, $options: "i"} + }).limit(10).select('name').exec().then((res:Array)=> { 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) { + 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; + } + } \ No newline at end of file diff --git a/backend/routes/GalleryRouter.ts b/backend/routes/GalleryRouter.ts index 2124463e..f36ae89d 100644 --- a/backend/routes/GalleryRouter.ts +++ b/backend/routes/GalleryRouter.ts @@ -61,7 +61,7 @@ export class GalleryRouter { private addAutoComplete() { this.app.get("/api/gallery/autocomplete/:text", - AuthenticationMWs.authenticate, + // AuthenticationMWs.authenticate, GalleryMWs.autocomplete, RenderingMWs.renderResult ); diff --git a/common/entities/AutoCompleteItem.ts b/common/entities/AutoCompleteItem.ts index 79a001f5..0b36f9ca 100644 --- a/common/entities/AutoCompleteItem.ts +++ b/common/entities/AutoCompleteItem.ts @@ -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; + } } diff --git a/frontend/app/gallery/grid/photo/photo.grid.gallery.component.html b/frontend/app/gallery/grid/photo/photo.grid.gallery.component.html index 0aee9866..d96e1b6e 100644 --- a/frontend/app/gallery/grid/photo/photo.grid.gallery.component.html +++ b/frontend/app/gallery/grid/photo/photo.grid.gallery.component.html @@ -1,6 +1,6 @@
-
+
{{gridPhoto.photo.name}}
diff --git a/frontend/app/gallery/grid/photo/photo.grid.gallery.component.ts b/frontend/app/gallery/grid/photo/photo.grid.gallery.component.ts index 05f777cf..0e09a02d 100644 --- a/frontend/app/gallery/grid/photo/photo.grid.gallery.component.ts +++ b/frontend/app/gallery/grid/photo/photo.grid.gallery.component.ts @@ -1,7 +1,6 @@ /// 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)"; }