forked from MTSR/mapserver
js cleanup / jshint
This commit is contained in:
parent
dfcb4241f3
commit
16d691abf0
@ -32,7 +32,7 @@ clean:
|
|||||||
rm -rf $(OUT_DIR)
|
rm -rf $(OUT_DIR)
|
||||||
|
|
||||||
jshint:
|
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):
|
$(STATIC_VFS):
|
||||||
go generate
|
go generate
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
/* exported SearchControl */
|
/* exported SearchControl */
|
||||||
|
/* globals SearchInput: true */
|
||||||
|
/* globals SearchMenu: true */
|
||||||
|
|
||||||
var SearchControl = L.Control.extend({
|
var SearchControl = L.Control.extend({
|
||||||
initialize: function(wsChannel, opts) {
|
initialize: function(wsChannel, opts) {
|
||||||
|
@ -49,5 +49,5 @@ var LabelOverlay = AbstractIconOverlay.extend({
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
createPopup: function(lbl){}
|
createPopup: function(){}
|
||||||
});
|
});
|
||||||
|
@ -33,7 +33,6 @@ var ShopOverlay = AbstractIconOverlay.extend({
|
|||||||
},
|
},
|
||||||
|
|
||||||
createPopup: function(obj){
|
createPopup: function(obj){
|
||||||
console.log(obj)
|
|
||||||
return "<h4>" + obj.attributes.type + "</h4><hr>" +
|
return "<h4>" + obj.attributes.type + "</h4><hr>" +
|
||||||
"<b>Owner: </b> " + obj.attributes.owner + "<br>" +
|
"<b>Owner: </b> " + obj.attributes.owner + "<br>" +
|
||||||
"<b>Input: </b> " + obj.attributes.in_count + " x " + obj.attributes.in_item + "<br>" +
|
"<b>Input: </b> " + obj.attributes.in_count + " x " + obj.attributes.in_item + "<br>" +
|
||||||
|
@ -1,8 +1,11 @@
|
|||||||
|
/* exported SearchInput */
|
||||||
|
/* globals SearchService: true */
|
||||||
|
/* globals SearchStore: true */
|
||||||
|
|
||||||
var SearchInput = {
|
var SearchInput = {
|
||||||
view: function(){
|
view: function(){
|
||||||
function handleInput(e){
|
function handleInput(e){
|
||||||
SearchStore.search(e.target.value);
|
SearchService.search(e.target.value);
|
||||||
}
|
}
|
||||||
|
|
||||||
return m("div", { class: "input-group mb-3" }, [
|
return m("div", { class: "input-group mb-3" }, [
|
||||||
@ -11,7 +14,12 @@ var SearchInput = {
|
|||||||
m("i", { class: "fa fa-search"})
|
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
|
||||||
|
})
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
@ -1,44 +1,7 @@
|
|||||||
|
/* exported SearchMenu */
|
||||||
var SearchResult = {
|
/* globals SearchResult: true */
|
||||||
view: function(vnode){
|
/* globals SearchService: true */
|
||||||
|
/* globals SearchStore: true */
|
||||||
function getLayer(obj){
|
|
||||||
var layer = layerMgr.getLayerByY(obj.y);
|
|
||||||
return layer ? layer.name : "<unknown>";
|
|
||||||
}
|
|
||||||
|
|
||||||
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)
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var SearchMenu = {
|
var SearchMenu = {
|
||||||
view: function(){
|
view: function(){
|
||||||
@ -49,7 +12,7 @@ var SearchMenu = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function close(){
|
function close(){
|
||||||
SearchStore.clear();
|
SearchService.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
return m("div", { class: "card", id: "search-menu", style: style }, [
|
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))
|
m("div", { class: "card-body", style: {overflow: "auto"} }, m(SearchResult))
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
44
server/static/js/search/SearchResult.js
Normal file
44
server/static/js/search/SearchResult.js
Normal file
@ -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 : "<unknown>";
|
||||||
|
}
|
||||||
|
|
||||||
|
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)
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
};
|
39
server/static/js/search/SearchService.js
Normal file
39
server/static/js/search/SearchService.js
Normal file
@ -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 = [];
|
||||||
|
}
|
||||||
|
};
|
@ -1,40 +1,6 @@
|
|||||||
|
/* exported SearchStore */
|
||||||
|
|
||||||
var SearchStore = {
|
var SearchStore = {
|
||||||
query: "",
|
query: "",
|
||||||
result: [],
|
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 = [];
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
@ -13,6 +13,8 @@
|
|||||||
"/js/CoordinatesDisplay.js",
|
"/js/CoordinatesDisplay.js",
|
||||||
"/js/WorldInfoDisplay.js",
|
"/js/WorldInfoDisplay.js",
|
||||||
"/js/search/SearchStore.js",
|
"/js/search/SearchStore.js",
|
||||||
|
"/js/search/SearchService.js",
|
||||||
|
"/js/search/SearchResults.js",
|
||||||
"/js/search/SearchMenu.js",
|
"/js/search/SearchMenu.js",
|
||||||
"/js/search/SearchInput.js",
|
"/js/search/SearchInput.js",
|
||||||
"/js/overlays/AbstractIconOverlay.js",
|
"/js/overlays/AbstractIconOverlay.js",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user