Compare commits

...
Sign in to create a new pull request.
Author SHA1 Message Date
Xaver Maierhofer
ed06ff6b09 [!!!][TASK] Refactor Scss, add Sass-lint and adjust styling
Add variables to allow easy modifications to color, font and also extending Style
2017-03-18 20:06:42 +01:00
Xaver Maierhofer
6175d6bb7a [TASK] Update eslint to 2.11.0 2017-03-18 16:30:18 +01:00
Milan Pässler
931ca67fc2 [BUGFIX] bower package name should be lowercase 2017-03-18 16:29:47 +01:00
Milan Pässler
340c1d9a53 [TASK] Add required information into package.json 2017-03-18 16:29:30 +01:00
Xaver Maierhofer
ae59f75594 [TASK] Use strict 2017-03-18 16:26:29 +01:00
Xaver Maierhofer
d57ce0052a [TASK] Add scss to grunt watcher 2017-03-18 16:26:29 +01:00
Xaver Maierhofer
894f32da54 [TASK] Style layer selector 2017-03-18 16:26:29 +01:00
Milan Pässler
a8c19ba44c [!!!][TASK] Use eslint default 2017-03-18 16:26:29 +01:00
Xaver Maierhofer
a627e2febc [TASK] Remove tablesort number
No complex different styled numbers need to be sorted
2017-03-18 16:26:29 +01:00
Xaver Maierhofer
e32fe6648d [TASK] Remove jsHashes 2017-03-18 16:26:29 +01:00
Xaver Maierhofer
a2ab0dce4f [TASK] Simple sort for firmware versions 2017-03-18 16:26:29 +01:00
Xaver Maierhofer
90d2c3e444 [TASK] Replace numeraljs with toFixed vanilla js 2017-03-18 16:26:29 +01:00
Xaver Maierhofer
a56876a10e [TASK] Update npm bower install module 2017-03-18 16:26:29 +01:00
Xaver Maierhofer
2d5e35324a [TASK] Add helper.js to grunt watch 2017-03-18 16:26:29 +01:00
Xaver Maierhofer
28de7c5403 [TASK] Adjust marker style - focus on online nodes 2017-03-18 16:26:29 +01:00
Milan Pässler
2630b6197d fix linting 2017-03-18 16:26:29 +01:00
Nils Schneider
62d64c717c [TASK] remove build.js, it is not needed anymore 2017-03-18 16:26:29 +01:00
Xaver Maierhofer
5691406d09 [TASK] Format load average 2017-03-18 16:26:29 +01:00
Xaver Maierhofer
e80f7d899d [TASK] Only add german language from numeral.js 2017-03-18 16:26:29 +01:00
Xaver Maierhofer
292c5c020c [TASK] Unicode instead of utf8 icons 2017-03-18 16:26:25 +01:00
Xaver Maierhofer
58279ac213 [BUGFIX] Enable build for default 2017-03-17 03:23:28 +01:00
Xaver Maierhofer
6f4b9d6701 [TASK] Replace all specialchars in NODE_NAME in stat urls 2017-03-17 03:23:28 +01:00
Xaver Maierhofer
e9e393e105 [TASK] Seperate dev and default for requirejs 2017-03-17 03:23:28 +01:00
Xaver Maierhofer
5921a5f355 [TASK] Add index option to grunt-conncet server 2017-03-17 03:23:28 +01:00
Xaver Maierhofer
c9458ffcae [TASK] CGL - Optimize returns and unnecessary math 2017-03-17 03:23:28 +01:00
Xaver Maierhofer
c7b58d5743 [TASK] Inline style and icon css and es6-shim 2017-03-17 03:23:28 +01:00
Xaver Maierhofer
7389547e3e [BUGFIX] Correct css path to icon font 2017-03-17 03:23:28 +01:00
Xaver Maierhofer
6aec0b21a8 [TASK] Update bower components 2017-03-17 03:23:28 +01:00
Xaver Maierhofer
04eb8f039b [TASK] Only include additional german locale
English is default
2017-03-17 03:23:28 +01:00
Xaver Maierhofer
0abd4130cf [TASK] Use own iconfont set
Reduce overhead in initial load
2017-03-17 03:23:28 +01:00
Milan Pässler
418b630e02 change code style to ffrgb/meshviewer fork 2017-03-17 03:23:07 +01:00
H4ndl3
59ba0ba29e add loading animation
Create _loader.scss

Update main.scss

Update _base.scss

Update gui.js

Update index.html

removed trailing spaces

removed trailing white spaces for real
2017-03-17 03:16:41 +01:00
79 changed files with 4541 additions and 3925 deletions

View file

@ -11,6 +11,6 @@ trim_trailing_whitespace = true
end_of_line = lf
insert_final_newline = true
[*.{js,html,scss,json}]
[*.{js,html,scss,json,yml,md}]
indent_size = 2
indent_style = space

2
.gitignore vendored
View file

@ -3,3 +3,5 @@ node_modules/
build/
.sass-cache/
config.json
.idea/
.eslintrc

3
.sass-lint.yml Normal file
View file

@ -0,0 +1,3 @@
rules:
no-color-literals: 0
single-line-per-selector: 0

View file

@ -1,24 +1,11 @@
module.exports = function (grunt) {
grunt.loadNpmTasks("grunt-git-describe")
"use strict";
grunt.initConfig({
"git-describe": {
options: {},
default: {}
}
})
grunt.loadTasks("tasks");
grunt.registerTask("saveRevision", function() {
grunt.event.once("git-describe", function (rev) {
grunt.option("gitRevision", rev)
})
grunt.task.run("git-describe")
})
grunt.loadTasks("tasks")
grunt.registerTask("default", ["bower-install-simple", "lint", "saveRevision", "copy", "sass", "postcss", "requirejs"])
grunt.registerTask("lint", ["eslint"])
grunt.registerTask("dev", ["default", "connect:server", "watch"])
}
grunt.registerTask("default", ["bower-install-simple", "lint", "copy", "sass", "postcss", "requirejs:default", "inline"]);
grunt.registerTask("lint", ["sasslint", "eslint"]);
grunt.registerTask("dev", ["bower-install-simple", "lint", "copy", "sass", "requirejs:dev"]);
grunt.registerTask("serve", ["dev", "connect:server", "watch"]);
};

View file

@ -46,10 +46,19 @@ Just run the following command from the hopglass directory:
This will generate `build/` containing all required files.
## Development
Use `grunt serve` for development.
# Configure
Copy `config.json.example` to `build/config.json` and change it to match your community.
## Customize style
Start your development and edit files in `scss/custom/`. Additional information in comments.
## dataPath (string/array)
`dataPath` can be either a string containing the address of a [HopGlass Server](https://github.com/plumpudding/hopglass-server) or an array containing multiple addresses.

30
app.js
View file

@ -1,3 +1,5 @@
"use strict";
require.config({
baseUrl: "lib",
paths: {
@ -5,32 +7,24 @@ require.config({
"leaflet.label": "../bower_components/Leaflet.label/dist/leaflet.label",
"leaflet.providers": "../bower_components/leaflet-providers/leaflet-providers",
"chroma-js": "../bower_components/chroma-js/chroma.min",
"moment": "../bower_components/moment/min/moment-with-locales.min",
"tablesort": "../bower_components/tablesort/tablesort.min",
"tablesort.numeric": "../bower_components/tablesort/src/sorts/tablesort.numeric",
"moment": "../bower_components/moment/min/moment.min",
"moment.de": "../bower_components/moment/locale/de",
"tablesort": "../bower_components/tablesort/src/tablesort",
"d3": "../bower_components/d3/d3.min",
"numeral": "../bower_components/numeraljs/min/numeral.min",
"numeral-intl": "../bower_components/numeraljs/min/languages.min",
"virtual-dom": "../bower_components/virtual-dom/dist/virtual-dom",
"rbush": "../bower_components/rbush/rbush",
"helper": "../helper",
"jshashes": "../bower_components/jshashes/hashes"
"helper": "utils/helper"
},
shim: {
"leaflet.label": ["leaflet"],
"leaflet.providers": ["leaflet"],
"moment.de": ["moment"],
"tablesort": {
exports: "Tablesort"
},
"numeral-intl": {
deps: ["numeral"],
exports: "numeral"
},
"tablesort.numeric": ["tablesort"],
"helper": ["numeral-intl"]
}
}
})
});
require(["main", "helper"], function (main) {
getJSON("config.json").then(main)
})
require(["main", "helper"], function (main, helper) {
helper.getJSON("config.json").then(main);
});

View file

@ -0,0 +1,7 @@
@mixin icon($name, $code, $prefix: 'ion-') {
.#{$prefix}#{$name} {
&:before {
content: '#{$code}';
}
}
}

BIN
assets/icons/fonts/icon.ttf Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

45
assets/icons/icon.scss Normal file
View file

@ -0,0 +1,45 @@
// Needed for standalone scss
// @import 'icon-mixin';
@font-face {
font-family: 'ionicons';
font-style: normal;
font-weight: normal;
src: url('fonts/icon.woff2') format('woff2'),
url('fonts/icon.woff') format('woff'),
url('fonts/icon.ttf') format('truetype');
}
[class^='ion-'], [class*=' ion-'] {
&:before {
display: inline-block;
font-family: $font-family-icons;
font-style: normal;
font-variant: normal;
font-weight: normal;
line-height: 1;
speak: none;
text-rendering: auto;
text-transform: none;
vertical-align: 0;
}
}
@include icon('android-add', '\f2c7');
@include icon('chevron-left', '\f124');
@include icon('chevron-right', '\f125');
@include icon('pin', '\f3a3');
@include icon('wifi', '\f25c');
@include icon('eye', '\f133');
@include icon('ios-arrow-thin-left', '\f3d5');
@include icon('ios-arrow-thin-right', '\f3d6');
@include icon('arrow-up-b', '\f10d');
@include icon('arrow-down-b', '\f104');
@include icon('android-locate', '\f2e9');
@include icon('android-close', '\f2d7');
@include icon('android-lock', '\f392');
@include icon('ios-copy', '\f41c');
@include icon('location', '\f456');
@include icon('android-remove', '\f2f4');
@include icon('ios-person', '\f47e');
@include icon('layer', '\f229');

View file

@ -1,5 +1,5 @@
{
"name": "HopGlass",
"name": "hopglass",
"ignore": [
"node_modules",
"bower_components",
@ -9,23 +9,19 @@
],
"dependencies": {
"Leaflet.label": "~0.2.1",
"chroma-js": "~0.6.1",
"leaflet": "~0.7.3",
"ionicons": "~2.0.1",
"moment": "~2.9.0",
"requirejs": "~2.1.16",
"tablesort": "https://github.com/tristen/tablesort.git#v3.0.2",
"chroma-js": "~1.1.1",
"leaflet": "~0.7.7",
"moment": "~2.13.0",
"requirejs": "~2.2.0",
"tablesort": "https://github.com/tristen/tablesort.git#v4.0.1",
"roboto-slab-fontface": "*",
"es6-shim": "~0.27.1",
"almond": "~0.3.1",
"r.js": "~2.1.16",
"d3": "~3.5.5",
"numeraljs": "~1.5.3",
"roboto-fontface": "~0.3.0",
"virtual-dom": "~2.0.1",
"leaflet-providers": "~1.0.27",
"rbush": "https://github.com/mourner/rbush.git#~1.3.5",
"jshashes": "~1.0.5"
"es6-shim": "~0.35.1",
"almond": "~0.3.2",
"d3": "~3.5.17",
"roboto-fontface": "~0.4.5",
"virtual-dom": "~2.1.1",
"leaflet-providers": "~1.1.10",
"rbush": "https://github.com/mourner/rbush.git#~1.4.3"
},
"authors": [
"Milan Pässler <me@petabyteboy.de>",

View file

@ -1,9 +0,0 @@
({
baseUrl: "lib",
name: "../bower_components/almond/almond",
mainConfigFile: "app.js",
include: "../app",
wrap: true,
optimize: "uglify",
out: "app-combined.js"
})

249
helper.js
View file

@ -1,228 +1,241 @@
function get(url) {
return new Promise(function(resolve, reject) {
var req = new XMLHttpRequest()
req.open('GET', url)
return new Promise(function (resolve, reject) {
var req = new XMLHttpRequest();
req.open('GET', url);
req.onload = function() {
req.onload = function () {
if (req.status == 200) {
resolve(req.response)
resolve(req.response);
}
else {
reject(Error(req.statusText))
reject(Error(req.statusText));
}
}
};
req.onerror = function() {
reject(Error("Network Error"))
}
req.onerror = function () {
reject(Error("Network Error"));
};
req.send()
})
req.send();
});
}
function getJSON(url) {
return get(url).then(JSON.parse)
return get(url).then(JSON.parse);
}
function sortByKey(key, d) {
return d.slice().sort( function (a, b) {
return a[key] - b[key]
}).reverse()
return d.slice().sort(function (a, b) {
return a[key] - b[key];
}).reverse();
}
function limit(key, m, d) {
return d.filter( function (d) {
return d[key].isAfter(m)
})
return d.filter(function (d) {
return d[key].isAfter(m);
});
}
function sum(a) {
return a.reduce( function (a, b) {
return a + b
}, 0)
return a.reduce(function (a, b) {
return a + b;
}, 0);
}
function one() {
return 1
return 1;
}
function trueDefault(d) {
return d === undefined ? true : d
return d === undefined ? true : d;
}
function dictGet(dict, key) {
var k = key.shift()
var k = key.shift();
if (!(k in dict))
return null
if (!(k in dict)) {
return null;
}
if (key.length == 0)
return dict[k]
if (key.length == 0) {
return dict[k];
}
return dictGet(dict[k], key)
return dictGet(dict[k], key);
}
function localStorageTest() {
var test = 'test'
var test = 'test';
try {
localStorage.setItem(test, test)
localStorage.removeItem(test)
return true
} catch(e) {
return false
localStorage.setItem(test, test);
localStorage.removeItem(test);
return true;
} catch (e) {
return false;
}
}
function listReplace(s, subst) {
for (key in subst) {
var re = new RegExp(key, 'g')
s = s.replace(re, subst[key])
var re = new RegExp(key, 'g');
s = s.replace(re, subst[key]);
}
return s
return s;
}
/* Helpers working with nodes */
function offline(d) {
return !d.flags.online
return !d.flags.online;
}
function online(d) {
return d.flags.online
return d.flags.online;
}
function has_location(d) {
return "location" in d.nodeinfo &&
Math.abs(d.nodeinfo.location.latitude) < 90 &&
Math.abs(d.nodeinfo.location.longitude) < 180
Math.abs(d.nodeinfo.location.latitude) < 90 &&
Math.abs(d.nodeinfo.location.longitude) < 180;
}
function subtract(a, b) {
var ids = {}
var ids = {};
b.forEach( function (d) {
ids[d.nodeinfo.node_id] = true
})
b.forEach(function (d) {
ids[d.nodeinfo.node_id] = true;
});
return a.filter( function (d) {
return !(d.nodeinfo.node_id in ids)
})
return a.filter(function (d) {
return !(d.nodeinfo.node_id in ids);
});
}
/* Helpers working with links */
function showDistance(d) {
if (isNaN(d.distance))
return
if (isNaN(d.distance)) {
return;
}
return numeral(d.distance).format("0,0") + " m"
return d.distance.toFixed(0) + " m"
}
function showTq(d) {
return numeral(1/d.tq).format("0%")
return (1 / d.tq * 100).toFixed(0) + "%"
}
/* Infobox stuff (XXX: move to module) */
function attributeEntry(el, label, value) {
if (value === null || value == undefined)
return
var tr = document.createElement("tr")
var th = document.createElement("th")
if (typeof label === "string")
th.textContent = label
else {
th.appendChild(label)
tr.className = "routerpic"
if (value === null || value == undefined) {
return;
}
tr.appendChild(th)
var tr = document.createElement("tr");
var th = document.createElement("th");
if (typeof label === "string") {
th.textContent = label;
} else {
th.appendChild(label);
tr.className = "routerpic";
}
var td = document.createElement("td")
tr.appendChild(th);
if (typeof value == "function")
value(td)
else
td.appendChild(document.createTextNode(value))
var td = document.createElement("td");
tr.appendChild(td)
if (typeof value == "function") {
value(td);
} else {
td.appendChild(document.createTextNode(value));
}
el.appendChild(tr)
tr.appendChild(td);
return td
el.appendChild(tr);
return td;
}
function createIframe(opt, width, height) {
el = document.createElement("iframe")
width = typeof width !== 'undefined' ? width : '100%'
height = typeof height !== 'undefined' ? height : '350px'
el = document.createElement("iframe");
width = typeof width !== 'undefined' ? width : '100%';
height = typeof height !== 'undefined' ? height : '350px';
if (opt.src)
el.src = opt.src
else
el.src = opt
if (opt.src) {
el.src = opt.src;
} else {
el.src = opt;
}
if (opt.frameBorder)
el.frameBorder = opt.frameBorder
else
el.frameBorder = 1
if (opt.frameBorder) {
el.frameBorder = opt.frameBorder;
} else {
el.frameBorder = 1;
}
if (opt.width)
el.width = opt.width
else
el.width = width
if (opt.width) {
el.width = opt.width;
} else {
el.width = width;
}
if (opt.height)
el.height = opt.height
else
el.height = height
if (opt.height) {
el.height = opt.height;
} else {
el.height = height;
}
el.scrolling = "no"
el.seamless = "seamless"
el.scrolling = "no";
el.seamless = "seamless";
return el
return el;
}
function showStat(o, subst) {
var content, caption
subst = typeof subst !== 'undefined' ? subst : {}
var content, caption;
subst = typeof subst !== 'undefined' ? subst : {};
if (o.thumbnail) {
content = document.createElement("img")
content.src = listReplace(o.thumbnail, subst)
content = document.createElement("img");
content.src = listReplace(o.thumbnail, subst);
}
if (o.caption) {
caption = listReplace(o.caption, subst)
caption = listReplace(o.caption, subst);
if (!content)
content = document.createTextNode(caption)
if (!content) {
content = document.createTextNode(caption);
}
}
if (o.iframe) {
content = createIframe(o.iframe, o.width, o.height)
if (o.iframe.src)
content.src = listReplace(o.iframe.src, subst)
else
content.src = listReplace(o.iframe, subst)
content = createIframe(o.iframe, o.width, o.height);
if (o.iframe.src) {
content.src = listReplace(o.iframe.src, subst);
} else {
content.src = listReplace(o.iframe, subst);
}
}
var p = document.createElement("p")
var p = document.createElement("p");
if (o.href) {
var link = document.createElement("a")
link.target = "_blank"
link.href = listReplace(o.href, subst)
link.appendChild(content)
var link = document.createElement("a");
link.target = "_blank";
link.href = listReplace(o.href, subst);
link.appendChild(content);
if (caption && o.thumbnail)
link.title = caption
if (caption && o.thumbnail) {
link.title = caption;
}
p.appendChild(link)
} else
p.appendChild(content)
p.appendChild(link);
} else {
p.appendChild(content);
}
return p
return p;
}

View file

@ -1,18 +1,27 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, user-scalable=no">
<link rel="stylesheet" href="css/ionicons.min.css">
<link rel="stylesheet" href="roboto-slab-fontface.css">
<link rel="stylesheet" href="roboto-fontface.css">
<link rel="stylesheet" href="style.css">
<script src="vendor/es6-shim/es6-shim.min.js"></script>
<script src="app.js"></script>
<script>
console.log("Version: #revision#")
</script>
</head>
<body>
</body>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, user-scalable=no">
<link rel="stylesheet" href="roboto-slab-fontface.css">
<link rel="stylesheet" href="roboto-fontface.css">
<link rel="stylesheet" href="style.css?__inline=true">
<script src="vendor/es6-shim/es6-shim.min.js?__inline=true"></script>
<script src="app.js"></script>
<script>
console.log("Version: #revision#");
</script>
</head>
<body>
<div class="loader">
<p>
Lade<br/>
<span class="spinner"></span><br/>
Karte &amp; Knoten...
</p>
<noscript>
<strong>JavaScript required</strong>
</noscript>
</div>
</body>
</html>

View file

@ -1,17 +1,27 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, user-scalable=no">
<link rel="stylesheet" href="bower_components/roboto-slab-fontface/roboto-slab-fontface.css">
<link rel="stylesheet" href="bower_components/roboto-fontface/roboto-fontface.css">
<link rel="stylesheet" href="bower_components/leaflet/dist/leaflet.css">
<link rel="stylesheet" href="bower_components/Leaflet.label/dist/leaflet.label.css">
<link rel="stylesheet" href="bower_components/ionicons/css/ionicons.min.css">
<link rel="stylesheet" href="style.css">
<script src="bower_components/es6-shim/es6-shim.min.js"></script>
<script src="bower_components/requirejs/require.js" data-main="app"></script>
</head>
<body>
</body>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, user-scalable=no">
<link rel="stylesheet" href="bower_components/roboto-slab-fontface/roboto-slab-fontface.css">
<link rel="stylesheet" href="bower_components/roboto-fontface/roboto-fontface.css">
<link rel="stylesheet" href="bower_components/leaflet/dist/leaflet.css">
<link rel="stylesheet" href="bower_components/Leaflet.label/dist/leaflet.label.css">
<link rel="stylesheet" href="assets/icons/hopglass-icons.css">
<link rel="stylesheet" href="style.css">
<script src="bower_components/es6-shim/es6-shim.min.js"></script>
<script src="bower_components/requirejs/require.js" data-main="app"></script>
</head>
<body>
<div class="loader">
<p>
Lade<br/>
<span class="spinner"></span><br \>
Karte &amp; Knoten...
</p>
<noscript>
<strong>JavaScript required</strong>
</noscript>
</div>
</body>
</html>

View file

@ -1,38 +1,38 @@
define(function () {
return function() {
"use strict";
return function () {
this.render = function (d) {
var el = document.createElement("div")
d.appendChild(el)
var s = "<h2>Über HopGlass</h2>"
var s = "<h2>Über HopGlass</h2>";
s += "<p>Mit Doppelklick und Shift+Doppelklick kann man in der Karte "
s += "auch zoomen.</p>"
s += "<p>Mit Doppelklick und Shift+Doppelklick kann man in der Karte ";
s += "auch zoomen.</p>";
s += "<h3>AGPL 3</h3>"
s += "<h3>AGPL 3</h3>";
s += "<p>Copyright (C) Milan Pässler</p>"
s += "<p>Copyright (C) Nils Schneider</p>"
s += "<p>Copyright (C) Milan Pässler</p>";
s += "<p>Copyright (C) Nils Schneider</p>";
s += "<p>This program is free software: you can redistribute it and/or "
s += "modify it under the terms of the GNU Affero General Public "
s += "License as published by the Free Software Foundation, either "
s += "version 3 of the License, or (at your option) any later version.</p>"
s += "<p>This program is free software: you can redistribute it and/or ";
s += "modify it under the terms of the GNU Affero General Public ";
s += "License as published by the Free Software Foundation, either ";
s += "version 3 of the License, or (at your option) any later version.</p>";
s += "<p>This program is distributed in the hope that it will be useful, "
s += "but WITHOUT ANY WARRANTY; without even the implied warranty of "
s += "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the "
s += "GNU Affero General Public License for more details.</p>"
s += "<p>This program is distributed in the hope that it will be useful, ";
s += "but WITHOUT ANY WARRANTY; without even the implied warranty of ";
s += "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ";
s += "GNU Affero General Public License for more details.</p>";
s += "<p>You should have received a copy of the GNU Affero General "
s += "Public License along with this program. If not, see "
s += "<a href=\"https://www.gnu.org/licenses/\">"
s += "https://www.gnu.org/licenses/</a>.</p>"
s += "<p>You should have received a copy of the GNU Affero General ";
s += "Public License along with this program. If not, see ";
s += "<a href=\"https://www.gnu.org/licenses/\">";
s += "https://www.gnu.org/licenses/</a>.</p>";
s += "<p>The source code is available at "
s += "<a href=\"https://github.com/plumpudding/hopglass\">"
s += "https://github.com/plumpudding/hopglass</a>."
s += "<p>The source code is available at ";
s += "<a href=\"https://github.com/plumpudding/hopglass\">";
s += "https://github.com/plumpudding/hopglass</a>.";
el.innerHTML = s
}
}
})
d.innerHTML = s;
};
};
});

View file

@ -1,20 +1,23 @@
define([], function () {
"use strict";
return function (tag) {
if (!tag)
tag = "div"
if (!tag) {
tag = "div";
}
var self = this
var self = this;
var container = document.createElement(tag)
var container = document.createElement(tag);
self.add = function (d) {
d.render(container)
}
d.render(container);
};
self.render = function (el) {
el.appendChild(container)
}
el.appendChild(container);
};
return self
}
})
return self;
};
});

View file

@ -1,80 +1,93 @@
define(["filters/nodefilter"], function (NodeFilter) {
"use strict";
return function () {
var targets = []
var filterObservers = []
var filters = []
var filteredData
var data
var targets = [];
var filterObservers = [];
var filters = [];
var filteredData;
var data;
function remove(d) {
targets = targets.filter( function (e) { return d !== e } )
targets = targets.filter(function (e) {
return d !== e;
});
}
function add(d) {
targets.push(d)
targets.push(d);
if (filteredData !== undefined)
d.setData(filteredData)
}
function setData(d) {
data = d
refresh()
}
function refresh() {
if (data === undefined)
return
var filter = filters.reduce( function (a, f) {
return function (d) {
return a(d) && f.run(d)
}
}, function () { return true })
filteredData = new NodeFilter(filter)(data)
targets.forEach( function (t) {
t.setData(filteredData)
})
}
function notifyObservers() {
filterObservers.forEach( function (d) {
d.filtersChanged(filters)
})
}
function addFilter(d) {
filters.push(d)
notifyObservers()
d.setRefresh(refresh)
refresh()
}
function removeFilter(d) {
filters = filters.filter( function (e) { return d !== e } )
notifyObservers()
refresh()
}
function watchFilters(d) {
filterObservers.push(d)
d.filtersChanged(filters)
return function () {
filterObservers = filterObservers.filter( function (e) { return d !== e })
if (filteredData !== undefined) {
d.setData(filteredData);
}
}
return { add: add,
remove: remove,
setData: setData,
addFilter: addFilter,
removeFilter: removeFilter,
watchFilters: watchFilters,
refresh: refresh
}
}
})
function setData(d) {
data = d;
refresh();
}
function refresh() {
if (data === undefined) {
return;
}
var filter = filters.reduce(function (a, f) {
return function (d) {
return a(d) && f.run(d);
};
}, function () {
return true;
});
filteredData = new NodeFilter(filter)(data);
targets.forEach(function (t) {
t.setData(filteredData);
});
}
function notifyObservers() {
filterObservers.forEach(function (d) {
d.filtersChanged(filters);
});
}
function addFilter(d) {
filters.push(d);
notifyObservers();
d.setRefresh(refresh);
refresh();
}
function removeFilter(d) {
filters = filters.filter(function (e) {
return d !== e;
});
notifyObservers();
refresh();
}
function watchFilters(d) {
filterObservers.push(d);
d.filtersChanged(filters);
return function () {
filterObservers = filterObservers.filter(function (e) {
return d !== e;
});
};
}
return {
add: add,
remove: remove,
setData: setData,
addFilter: addFilter,
removeFilter: removeFilter,
watchFilters: watchFilters,
refresh: refresh
};
};
});

View file

@ -1,40 +1,43 @@
define([], function () {
define(function () {
"use strict";
return function (distributor) {
var container = document.createElement("ul")
container.classList.add("filters")
var div = document.createElement("div")
var container = document.createElement("ul");
container.classList.add("filters");
var div = document.createElement("div");
function render(el) {
el.appendChild(div)
el.appendChild(div);
}
function filtersChanged(filters) {
while (container.firstChild)
container.removeChild(container.firstChild)
while (container.firstChild) {
container.removeChild(container.firstChild);
}
filters.forEach( function (d) {
var li = document.createElement("li")
var div = document.createElement("div")
container.appendChild(li)
li.appendChild(div)
d.render(div)
filters.forEach(function (d) {
var li = document.createElement("li");
container.appendChild(li);
d.render(li);
var button = document.createElement("button")
button.textContent = ""
var button = document.createElement("button");
button.classList.add("ion-android-close");
button.onclick = function () {
distributor.removeFilter(d)
}
li.appendChild(button)
})
distributor.removeFilter(d);
};
li.appendChild(button);
});
if (container.parentNode === div && filters.length === 0)
div.removeChild(container)
else if (filters.length > 0)
div.appendChild(container)
if (container.parentNode === div && filters.length === 0) {
div.removeChild(container);
} else if (filters.length > 0) {
div.appendChild(container);
}
}
return { render: render,
filtersChanged: filtersChanged
}
}
})
return {
render: render,
filtersChanged: filtersChanged
};
};
});

Some files were not shown because too many files have changed in this diff Show more