diff --git a/server/app/config.go b/server/app/config.go index f4f2806..9a4b84c 100644 --- a/server/app/config.go +++ b/server/app/config.go @@ -165,7 +165,7 @@ func ParseConfig(filename string) (*Config, error) { Port: 8080, EnableRendering: true, EnablePrometheus: true, - EnableSearch: false, + EnableSearch: true, EnableInitialRendering: true, EnableTransparency: false, Webdev: false, diff --git a/server/static/js/SearchControl.js b/server/static/js/SearchControl.js index 424dbec..7ec2e36 100644 --- a/server/static/js/SearchControl.js +++ b/server/static/js/SearchControl.js @@ -7,11 +7,14 @@ var SearchControl = L.Control.extend({ L.Control.prototype.initialize.call(this, opts); }, - onAdd: function() { + onAdd: function(map) { var div = L.DomUtil.create('div'); - m.mount(div, SearchInput); - m.mount(document.getElementById("search-content"), SearchMenu); + m.mount(document.getElementById("search-content"), { + view: function () { + return m(SearchMenu, {map: map}); + } + }); return div; } diff --git a/server/static/js/overlays/ShopOverlay.js b/server/static/js/overlays/ShopOverlay.js index b4b7d15..cce844e 100644 --- a/server/static/js/overlays/ShopOverlay.js +++ b/server/static/js/overlays/ShopOverlay.js @@ -22,7 +22,7 @@ var ShopOverlay = AbstractIconOverlay.extend({ }, getMaxDisplayedZoom: function(){ - return 5; + return 10; }, getIcon: function(obj){ diff --git a/server/static/js/search/SearchMenu.js b/server/static/js/search/SearchMenu.js index cd35755..a493832 100644 --- a/server/static/js/search/SearchMenu.js +++ b/server/static/js/search/SearchMenu.js @@ -4,7 +4,8 @@ /* globals SearchStore: true */ var SearchMenu = { - view: function(){ + view: function(vnode){ + var style = {}; if (!SearchStore.query) { @@ -21,7 +22,7 @@ var SearchMenu = { "Search", m("i", { class: "fa fa-times float-right", onclick: close }), ]), - m("div", { class: "card-body", style: {overflow: "auto"} }, m(SearchResult)) + m("div", { class: "card-body", style: {overflow: "auto"} }, m(SearchResult, { map: vnode.attrs.map })) ]); } }; diff --git a/server/static/js/search/SearchResult.js b/server/static/js/search/SearchResult.js index e34cece..48223a7 100644 --- a/server/static/js/search/SearchResult.js +++ b/server/static/js/search/SearchResult.js @@ -3,7 +3,8 @@ /* globals layerMgr: true */ var SearchResult = { - view: function(){ + view: function(vnode){ + var map = vnode.attrs.map; function getLayer(obj){ var layer = layerMgr.getLayerByY(obj.y); @@ -12,30 +13,68 @@ var SearchResult = { function getPos(obj){ var layer = layerMgr.getLayerByY(obj.y); - var link = (layer ? layer.id : "0") + "/" + obj.x + "/" + obj.z + "/" + 12; var text = obj.x + "/" + obj.y + "/" + obj.z; - return m("a", { href: "#" + link }, text); + return m("span", {class:"badge badge-success"}, text); } var rows = SearchStore.result.map(function(obj){ - return m("tr", [ - m("td", obj.type), + + var row_classes = ""; + var description = obj.type; + var type = obj.type; + + if (obj.type == "poi"){ + description = m("span", obj.attributes.name); + type = m("img", { src: "css/images/marker-icon.png" }); + } + + if (obj.type == "shop") { + if (obj.attributes.stock == 0){ + row_classes += "table-warning"; + type = m("img", { src: "pics/shop_empty.png" }); + } else { + type = m("img", { src: "pics/shop.png" }); + } + + description = m("span", [ + "Shop, trading ", + m("span", {class:"badge badge-primary"}, obj.attributes.out_count + "x"), + m("span", {class:"badge badge-info"}, obj.attributes.out_item), + " for ", + m("span", {class:"badge badge-primary"}, obj.attributes.in_count + "x"), + m("span", {class:"badge badge-info"}, obj.attributes.in_item), + " Stock: ", + m("span", {class:"badge badge-info"}, obj.attributes.stock) + ]); + } + + function onclick(){ + map.setView([obj.z, obj.x], 12); + } + + return m("tr", {"class": row_classes}, [ + m("td", type), m("td", obj.attributes.owner), m("td", getLayer(obj)), m("td", getPos(obj)), - m("td", "stuff") + m("td", description), + m("button[type=button]", {class: "btn btn-secondary", onclick: onclick }, [ + "Goto ", + m("i", { class: "fas fa-play" }) + ]) ]); }); - return m("table", {class:"table"}, [ + return m("table", {class:"table table-striped"}, [ m("thead", [ m("tr", [ m("th", "Type"), m("th", "Owner"), m("th", "Layer"), m("th", "Position"), - m("th", "Description") + m("th", "Description"), + m("th", "Action") ]) ]), m("tbody", rows) diff --git a/server/static/js/search/SearchService.js b/server/static/js/search/SearchService.js index 32a4415..18f8e14 100644 --- a/server/static/js/search/SearchService.js +++ b/server/static/js/search/SearchService.js @@ -16,18 +16,30 @@ var SearchService = { return; } - api.getMapObjects({ - pos1: { x:-2048, y:-2048, z:-2048 }, - pos2: { x:2048, y:2048, z:2048 }, + function searchFor(q){ + q.pos1 = { x:-2048, y:-2048, z:-2048 }; + q.pos2 = { x:2048, y:2048, z:2048 }; + return api.getMapObjects(q); + } + + var shop_prom = searchFor({ type: "shop", attributelike: { key: "out_item", value: "%" + SearchStore.query + "%" } - }) - .then(function(result){ - SearchStore.result = result; - //console.log(result); //XXX + }); + + var poi_prom = searchFor({ + type: "poi", + attributelike: { + key: "name", + value: "%" + SearchStore.query + "%" + } + }); + + Promise.all([shop_prom, poi_prom]).then(function(results){ + SearchStore.result = results[1].concat(results[0]); }); }, 400),