diff --git a/server/Makefile b/server/Makefile
index 288e987..a1194f1 100644
--- a/server/Makefile
+++ b/server/Makefile
@@ -32,7 +32,7 @@ clean:
rm -rf $(OUT_DIR)
jshint:
- jshint static/js/*.js static/js/util static/js/overlays
+ jshint static/js/*.js static/js/util static/js/overlays static/js/search
$(STATIC_VFS):
go generate
diff --git a/server/static/js/SearchControl.js b/server/static/js/SearchControl.js
index 07c36d3..424dbec 100644
--- a/server/static/js/SearchControl.js
+++ b/server/static/js/SearchControl.js
@@ -1,4 +1,6 @@
/* exported SearchControl */
+/* globals SearchInput: true */
+/* globals SearchMenu: true */
var SearchControl = L.Control.extend({
initialize: function(wsChannel, opts) {
diff --git a/server/static/js/overlays/LabelOverlay.js b/server/static/js/overlays/LabelOverlay.js
index b8d6167..97414dd 100644
--- a/server/static/js/overlays/LabelOverlay.js
+++ b/server/static/js/overlays/LabelOverlay.js
@@ -49,5 +49,5 @@ var LabelOverlay = AbstractIconOverlay.extend({
});
},
- createPopup: function(lbl){}
+ createPopup: function(){}
});
diff --git a/server/static/js/overlays/ShopOverlay.js b/server/static/js/overlays/ShopOverlay.js
index 340cedb..b4b7d15 100644
--- a/server/static/js/overlays/ShopOverlay.js
+++ b/server/static/js/overlays/ShopOverlay.js
@@ -33,7 +33,6 @@ var ShopOverlay = AbstractIconOverlay.extend({
},
createPopup: function(obj){
- console.log(obj)
return "
" + obj.attributes.type + "
" +
"Owner: " + obj.attributes.owner + "
" +
"Input: " + obj.attributes.in_count + " x " + obj.attributes.in_item + "
" +
diff --git a/server/static/js/search/SearchInput.js b/server/static/js/search/SearchInput.js
index 4419ebb..8a1817b 100644
--- a/server/static/js/search/SearchInput.js
+++ b/server/static/js/search/SearchInput.js
@@ -1,8 +1,11 @@
+/* exported SearchInput */
+/* globals SearchService: true */
+/* globals SearchStore: true */
var SearchInput = {
view: function(){
function handleInput(e){
- SearchStore.search(e.target.value);
+ SearchService.search(e.target.value);
}
return m("div", { class: "input-group mb-3" }, [
@@ -11,7 +14,12 @@ var SearchInput = {
m("i", { class: "fa fa-search"})
])
]),
- m("input[type=text]", { placeholder: "Search", class: "form-control", oninput: handleInput, value: SearchStore.query })
+ m("input[type=text]", {
+ placeholder: "Search",
+ class: "form-control",
+ oninput: handleInput,
+ value: SearchStore.query
+ })
]);
}
-}
+};
diff --git a/server/static/js/search/SearchMenu.js b/server/static/js/search/SearchMenu.js
index 9ca4caa..cd35755 100644
--- a/server/static/js/search/SearchMenu.js
+++ b/server/static/js/search/SearchMenu.js
@@ -1,44 +1,7 @@
-
-var SearchResult = {
- view: function(vnode){
-
- function getLayer(obj){
- var layer = layerMgr.getLayerByY(obj.y);
- return layer ? layer.name : "";
- }
-
- 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);
- }
-
- var rows = SearchStore.result.map(function(obj){
- return m("tr", [
- m("td", obj.type),
- m("td", obj.attributes.owner),
- m("td", getLayer(obj)),
- m("td", getPos(obj)),
- m("td", "stuff")
- ]);
- });
-
- return m("table", {class:"table"}, [
- m("thead", [
- m("tr", [
- m("th", "Type"),
- m("th", "Owner"),
- m("th", "Layer"),
- m("th", "Position"),
- m("th", "Description")
- ])
- ]),
- m("tbody", rows)
- ]);
- }
-}
+/* exported SearchMenu */
+/* globals SearchResult: true */
+/* globals SearchService: true */
+/* globals SearchStore: true */
var SearchMenu = {
view: function(){
@@ -49,7 +12,7 @@ var SearchMenu = {
}
function close(){
- SearchStore.clear();
+ SearchService.clear();
}
return m("div", { class: "card", id: "search-menu", style: style }, [
@@ -61,4 +24,4 @@ var SearchMenu = {
m("div", { class: "card-body", style: {overflow: "auto"} }, m(SearchResult))
]);
}
-}
+};
diff --git a/server/static/js/search/SearchResult.js b/server/static/js/search/SearchResult.js
new file mode 100644
index 0000000..e34cece
--- /dev/null
+++ b/server/static/js/search/SearchResult.js
@@ -0,0 +1,44 @@
+/* exported SearchResult */
+/* globals SearchStore: true */
+/* globals layerMgr: true */
+
+var SearchResult = {
+ view: function(){
+
+ function getLayer(obj){
+ var layer = layerMgr.getLayerByY(obj.y);
+ return layer ? layer.name : "";
+ }
+
+ 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);
+ }
+
+ var rows = SearchStore.result.map(function(obj){
+ return m("tr", [
+ m("td", obj.type),
+ m("td", obj.attributes.owner),
+ m("td", getLayer(obj)),
+ m("td", getPos(obj)),
+ m("td", "stuff")
+ ]);
+ });
+
+ return m("table", {class:"table"}, [
+ m("thead", [
+ m("tr", [
+ m("th", "Type"),
+ m("th", "Owner"),
+ m("th", "Layer"),
+ m("th", "Position"),
+ m("th", "Description")
+ ])
+ ]),
+ m("tbody", rows)
+ ]);
+ }
+};
diff --git a/server/static/js/search/SearchService.js b/server/static/js/search/SearchService.js
new file mode 100644
index 0000000..32a4415
--- /dev/null
+++ b/server/static/js/search/SearchService.js
@@ -0,0 +1,39 @@
+/* exported SearchService */
+/* globals SearchStore: true */
+
+var SearchService = {
+
+ search: function(q){
+ SearchStore.query = q;
+
+ this.fetchData();
+ },
+
+ fetchData: debounce(function(){
+ SearchStore.result = [];
+
+ if (!SearchStore.query){
+ return;
+ }
+
+ api.getMapObjects({
+ pos1: { x:-2048, y:-2048, z:-2048 },
+ pos2: { x:2048, y:2048, z:2048 },
+ type: "shop",
+ attributelike: {
+ key: "out_item",
+ value: "%" + SearchStore.query + "%"
+ }
+ })
+ .then(function(result){
+ SearchStore.result = result;
+ //console.log(result); //XXX
+ });
+
+ }, 400),
+
+ clear: function(){
+ SearchStore.query = "";
+ SearchStore.result = [];
+ }
+};
diff --git a/server/static/js/search/SearchStore.js b/server/static/js/search/SearchStore.js
index 1308425..656d4e6 100644
--- a/server/static/js/search/SearchStore.js
+++ b/server/static/js/search/SearchStore.js
@@ -1,40 +1,6 @@
+/* exported SearchStore */
var SearchStore = {
query: "",
- result: [],
-
- search: function(q){
- this.query = q;
-
- this.fetchData();
- },
-
- fetchData: debounce(function(){
- var self = this;
- this.result = [];
-
- if (!this.query){
- return;
- }
-
- api.getMapObjects({
- pos1: { x:-2048, y:-2048, z:-2048 },
- pos2: { x:2048, y:2048, z:2048 },
- type: "shop",
- attributelike: {
- key: "out_item",
- value: "%" + this.query + "%"
- }
- })
- .then(function(result){
- self.result = result;
- console.log(result); //XXX
- });
-
- }, 400),
-
- clear: function(){
- this.query = "";
- this.result = [];
- }
+ result: []
};
diff --git a/server/static/manifest.js b/server/static/manifest.js
index aded117..8f7d697 100644
--- a/server/static/manifest.js
+++ b/server/static/manifest.js
@@ -13,6 +13,8 @@
"/js/CoordinatesDisplay.js",
"/js/WorldInfoDisplay.js",
"/js/search/SearchStore.js",
+ "/js/search/SearchService.js",
+ "/js/search/SearchResults.js",
"/js/search/SearchMenu.js",
"/js/search/SearchInput.js",
"/js/overlays/AbstractIconOverlay.js",