1
0
forked from MTSR/mapserver

js cleanup / jshint

This commit is contained in:
NatureFreshMilk 2019-04-15 07:54:11 +02:00
parent dfcb4241f3
commit 16d691abf0
10 changed files with 108 additions and 85 deletions

View File

@ -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

View File

@ -1,4 +1,6 @@
/* exported SearchControl */
/* globals SearchInput: true */
/* globals SearchMenu: true */
var SearchControl = L.Control.extend({
initialize: function(wsChannel, opts) {

View File

@ -49,5 +49,5 @@ var LabelOverlay = AbstractIconOverlay.extend({
});
},
createPopup: function(lbl){}
createPopup: function(){}
});

View File

@ -33,7 +33,6 @@ var ShopOverlay = AbstractIconOverlay.extend({
},
createPopup: function(obj){
console.log(obj)
return "<h4>" + obj.attributes.type + "</h4><hr>" +
"<b>Owner: </b> " + obj.attributes.owner + "<br>" +
"<b>Input: </b> " + obj.attributes.in_count + " x " + obj.attributes.in_item + "<br>" +

View File

@ -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
})
]);
}
}
};

View File

@ -1,44 +1,7 @@
var SearchResult = {
view: function(vnode){
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)
]);
}
}
/* 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))
]);
}
}
};

View 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)
]);
}
};

View 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 = [];
}
};

View File

@ -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: []
};

View File

@ -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",