From b21cda248f687f88b9bd5b6fbc51ffe638f05a2b Mon Sep 17 00:00:00 2001 From: Thomas Rudin Date: Sun, 1 Sep 2019 12:06:47 +0200 Subject: [PATCH] jshint + cleanup --- Makefile | 2 +- static/js/compat.js | 4 +- static/js/components/Map.js | 7 +- static/js/components/Search.js | 7 +- static/js/components/SearchInput.js | 2 +- static/js/config.js | 2 +- static/js/map/CustomOverlay.js | 2 +- static/js/map/SearchControl.js | 2 +- static/js/old/SearchInput.js | 35 ------- static/js/old/SearchMenu.js | 36 ------- static/js/old/SearchResult.js | 157 ---------------------------- static/js/old/SearchService.js | 28 ----- static/js/old/SearchStore.js | 7 -- static/js/routes.js | 6 +- 14 files changed, 16 insertions(+), 281 deletions(-) delete mode 100644 static/js/old/SearchInput.js delete mode 100644 static/js/old/SearchMenu.js delete mode 100644 static/js/old/SearchResult.js delete mode 100644 static/js/old/SearchService.js delete mode 100644 static/js/old/SearchStore.js diff --git a/Makefile b/Makefile index d7f2c00..529bf21 100644 --- a/Makefile +++ b/Makefile @@ -36,7 +36,7 @@ clean: rm -rf $(OUT_DIR) jshint: - jshint static/js/*.js static/js/util static/js/overlays static/js/search + jshint static/js/*.js static/js/components static/js/map static/js/util $(STATIC_VFS): go generate diff --git a/static/js/compat.js b/static/js/compat.js index 00bf0ea..ad4c44b 100644 --- a/static/js/compat.js +++ b/static/js/compat.js @@ -4,12 +4,12 @@ export function hashCompat(){ if (window.location.hash) { let match = window.location.hash.match(/^#\/(\d*)\/(\d*)\/(\d*)$/m); if (match) { - window.location.hash = `#!/map/0/${match[1]}/${match[2]}/${match[3]}` + window.location.hash = `#!/map/0/${match[1]}/${match[2]}/${match[3]}`; } match = window.location.hash.match(/^#\/(\d*)\/(\d*)\/(\d*)\/(\d*)$/m); if (match) { - window.location.hash = `#!/map/${match[1]}/${match[2]}/${match[3]}/${match[4]}` + window.location.hash = `#!/map/${match[1]}/${match[2]}/${match[3]}/${match[4]}`; } } } diff --git a/static/js/components/Map.js b/static/js/components/Map.js index f175ec4..6329b0c 100644 --- a/static/js/components/Map.js +++ b/static/js/components/Map.js @@ -1,9 +1,8 @@ -import wsChannel from '../WebSocketChannel.js'; import layerManager from '../map/LayerManager.js'; import { createMap } from '../map/MapFactory.js'; export default { - view(vnode){ + view(){ return m("div", { class: "full-screen" }); }, @@ -31,7 +30,7 @@ export default { map.on('baselayerchange', updateHash); }, - onbeforeupdate(newVnode, oldVnode) { + onbeforeupdate(newVnode) { const center = newVnode.state.map.getCenter(); const newAattrs = newVnode.attrs; @@ -49,4 +48,4 @@ export default { onremove(vnode){ vnode.state.map.remove(); } -} +}; diff --git a/static/js/components/Search.js b/static/js/components/Search.js index 83dbd6b..668db86 100644 --- a/static/js/components/Search.js +++ b/static/js/components/Search.js @@ -4,7 +4,7 @@ import { getMapObjects } from '../api.js'; const state = { busy: false, result: [] -} +}; function searchFor(type, key, valuelike){ return getMapObjects({ @@ -49,7 +49,6 @@ function search(query){ export default { oncreate(vnode){ - console.log("oncreate", vnode); search(vnode.attrs.query); }, @@ -57,7 +56,7 @@ export default { if (state.result.length == 0) { return m("div", vnode.attrs.query); } else { - return m(SearchResult, { result: state.result }) + return m(SearchResult, { result: state.result }); } } -} +}; diff --git a/static/js/components/SearchInput.js b/static/js/components/SearchInput.js index 0f4a320..be43df3 100644 --- a/static/js/components/SearchInput.js +++ b/static/js/components/SearchInput.js @@ -1,7 +1,7 @@ const state = { query: "" -} +}; function doSearch(){ m.route.set(`/search/${state.query}`); diff --git a/static/js/config.js b/static/js/config.js index 16cc3d5..b348712 100644 --- a/static/js/config.js +++ b/static/js/config.js @@ -9,4 +9,4 @@ export default { set(cfg){ config = cfg; } -} +}; diff --git a/static/js/map/CustomOverlay.js b/static/js/map/CustomOverlay.js index 494b577..b59a95f 100644 --- a/static/js/map/CustomOverlay.js +++ b/static/js/map/CustomOverlay.js @@ -2,7 +2,7 @@ var customOverlays = {}; try { - customOverlays = JSON.parse(localStorage["mapserver-customOverlays"]) + customOverlays = JSON.parse(localStorage["mapserver-customOverlays"]); } catch (e){} function save(){ diff --git a/static/js/map/SearchControl.js b/static/js/map/SearchControl.js index 701cbf7..34a5fcf 100644 --- a/static/js/map/SearchControl.js +++ b/static/js/map/SearchControl.js @@ -5,7 +5,7 @@ export default L.Control.extend({ L.Control.prototype.initialize.call(this, opts); }, - onAdd: function(map) { + onAdd: function() { var div = L.DomUtil.create('div'); m.mount(div, SearchInput); return div; diff --git a/static/js/old/SearchInput.js b/static/js/old/SearchInput.js deleted file mode 100644 index b584f03..0000000 --- a/static/js/old/SearchInput.js +++ /dev/null @@ -1,35 +0,0 @@ -import SearchStore from './SearchStore.js'; -import SearchService from './SearchService.js'; - -export default { - view: function(){ - function handleInput(e){ - SearchStore.query = e.target.value; - } - - function handleKeyDown(e){ - if (e.keyCode == 13){ - SearchService.search(); - } - } - - function handleDoSearch(){ - SearchService.search(); - } - - return m("div", { class: "input-group mb-3" }, [ - m("input[type=text]", { - placeholder: "Search", - class: "form-control", - oninput: handleInput, - onkeydown: handleKeyDown, - value: SearchStore.query - }), - m("div", { class: "input-group-append", onclick: handleDoSearch }, [ - m("span", { class: "input-group-text" }, [ - m("i", { class: "fa fa-search"}) - ]) - ]) - ]); - } -}; diff --git a/static/js/old/SearchMenu.js b/static/js/old/SearchMenu.js deleted file mode 100644 index 66dcc21..0000000 --- a/static/js/old/SearchMenu.js +++ /dev/null @@ -1,36 +0,0 @@ - -import SearchService from './SearchService.js'; -import SearchStore from './SearchStore.js'; -import SearchResult from './SearchResult.js'; - -export default { - view: function(vnode){ - - var style = {}; - - if (!SearchStore.show) { - style.display = "none"; - } - - function close(){ - SearchService.clear(); - } - - function getContent(){ - if (SearchStore.busy){ - return m("div", m("i", { class: "fa fa-spinner"})); - } else { - return m(SearchResult, { map: vnode.attrs.map }); - } - } - - return m("div", { class: "card", id: "search-menu", style: style }, [ - m("div", { class: "card-header" }, [ - m("i", { class: "fa fa-search"}), - "Search", - m("i", { class: "fa fa-times float-right", onclick: close }), - ]), - m("div", { class: "card-body", style: {overflow: "auto"} }, getContent()) - ]); - } -}; diff --git a/static/js/old/SearchResult.js b/static/js/old/SearchResult.js deleted file mode 100644 index 8364668..0000000 --- a/static/js/old/SearchResult.js +++ /dev/null @@ -1,157 +0,0 @@ -import SearchStore from './SearchStore.js'; -import layerMgr from '../map/LayerManager.js'; - -export default { - view: function(vnode){ - var map = vnode.attrs.map; - - function getLayer(obj){ - var layer = layerMgr.getLayerByY(obj.y); - return layer ? layer.name : ""; - } - - function getPos(obj){ - var text = obj.x + "/" + obj.y + "/" + obj.z; - - return m("span", {class:"badge badge-success"}, text); - } - - var rows = SearchStore.result.map(function(obj){ - - var row_classes = ""; - var description = obj.type; - var type = obj.type; - - // train-line result - if (obj.type == "train"){ - description = [ - m("span", obj.attributes.station), - " ", - m("span", {class:"badge badge-info"}, obj.attributes.line) - ]; - - type = m("i", { class: "fa fa-subway" }); - } - - // travelnet - if (obj.type == "travelnet"){ - description = m("span", obj.attributes.station_name); - type = m("img", { src: "pics/travelnet_inv.png" }); - } - - // bones - if (obj.type == "bones"){ - description = m("span", obj.attributes.owner); - type = m("img", { src: "pics/bones_top.png" }); - } - - // label - if (obj.type == "label"){ - description = m("span", obj.attributes.text); - type = m("img", { src: "pics/mapserver_label.png" }); - } - - // digiterm - if (obj.type == "digiterm"){ - description = m("span", obj.attributes.display_text); - type = m("img", { src: "pics/digiterms_beige_front.png" }); - } - - // digiline lcd - if (obj.type == "digilinelcd"){ - description = m("span", obj.attributes.text); - type = m("img", { src: "pics/lcd_lcd.png" }); - } - - // locator - if (obj.type == "locator"){ - description = m("span", obj.attributes.name); - - var img = "pics/locator_beacon_level1.png"; - - if (obj.attributes.level == "2") - img = "pics/locator_beacon_level2.png"; - else if (obj.attributes.level == "3") - img = "pics/locator_beacon_level3.png"; - - type = m("img", { src: img }); - } - - // poi marker - if (obj.type == "poi"){ - description = m("span", obj.attributes.name); - - var color = obj.attributes.color || "blue"; - var icon = obj.attributes.icon || "home"; - - type = m("div", { style: "position: relative", class: "awesome-marker awesome-marker-icon-" + color }, [ - m("i", { class: "fa fa-" + icon }) - ]); - } - - //shop - 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("i", {class:"fa fa-cart-arrow-down"}) - ), - m("span", {class:"badge badge-info"}, obj.attributes.out_item), - " for ", - m("span", {class:"badge badge-primary"}, - obj.attributes.in_count, - "x", - m("i", {class:"fa fa-money-bill"}) - ), - m("span", {class:"badge badge-info"}, obj.attributes.in_item), - " Stock: ", - m("span", {class:"badge badge-info"}, obj.attributes.stock) - ]); - } - - function onclick(){ - var layer = layerMgr.getLayerByY(obj.y); - - layerMgr.switchLayer(layer.id); - - map.setView([obj.z, obj.x], 12); - SearchStore.show = false; - } - - return m("tr", {"class": row_classes}, [ - m("td", type), - m("td", obj.attributes.owner), - m("td", getLayer(obj)), - m("td", getPos(obj)), - 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 table-striped"}, [ - m("thead", [ - m("tr", [ - m("th", "Type"), - m("th", "Owner"), - m("th", "Layer"), - m("th", "Position"), - m("th", "Description"), - m("th", "Action") - ]) - ]), - m("tbody", rows) - ]); - } -}; diff --git a/static/js/old/SearchService.js b/static/js/old/SearchService.js deleted file mode 100644 index bc19717..0000000 --- a/static/js/old/SearchService.js +++ /dev/null @@ -1,28 +0,0 @@ -import SearchStore from './SearchStore.js'; -import { getMapObjects } from '../api.js'; - -export default { - - search: function(){ - SearchStore.show = true; - this.fetchData(); - }, - - fetchData: function(){ - SearchStore.result = []; - - if (!SearchStore.query){ - return; - } - - SearchStore.busy = true; - - - - }, - - clear: function(){ - SearchStore.result = []; - SearchStore.show = false; - } -}; diff --git a/static/js/old/SearchStore.js b/static/js/old/SearchStore.js deleted file mode 100644 index a154484..0000000 --- a/static/js/old/SearchStore.js +++ /dev/null @@ -1,7 +0,0 @@ - -export default { - query: "", - show: false, - busy: false, - result: [] -}; diff --git a/static/js/routes.js b/static/js/routes.js index 6ae3f1a..b715183 100644 --- a/static/js/routes.js +++ b/static/js/routes.js @@ -4,12 +4,12 @@ import Search from './components/Search.js'; var Home = { view: function() { - return "Home" + return "Home"; } -} +}; export default { "/": Home, "/map/:layerId/:zoom/:lon/:lat": Map, "/search/:query": Search -} +};