From ce8a1c2a5dfc58e4992b8912592347df1e5d12ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20B=C3=B6sch-Plepelits?= Date: Wed, 6 Dec 2017 21:45:38 +0100 Subject: [PATCH 01/54] OpenStreetBrowserLoader: avoid duplicate categories --- src/OpenStreetBrowserLoader.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/OpenStreetBrowserLoader.js b/src/OpenStreetBrowserLoader.js index 6889dbac..0aff3dfa 100644 --- a/src/OpenStreetBrowserLoader.js +++ b/src/OpenStreetBrowserLoader.js @@ -89,6 +89,11 @@ OpenStreetBrowserLoader.prototype.getTemplate = function (id, callback) { } OpenStreetBrowserLoader.prototype.getCategoryFromData = function (id, data, callback) { + if (id in this.categories) { + callback(null, this.categories[id]) + return + } + if (!data.type) { return callback(new Error('no type defined'), null) } From 1cec6a9240e51b4d12fa1b8b26def4e27c70c2ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20B=C3=B6sch-Plepelits?= Date: Mon, 4 Dec 2017 20:45:11 +0100 Subject: [PATCH 02/54] OpenStreetBrowserLoader: load repository in one http request --- repo.php | 55 ++++++++++++++++++++++++++++++++++ src/OpenStreetBrowserLoader.js | 50 +++++++++++++++++++++---------- 2 files changed, 90 insertions(+), 15 deletions(-) create mode 100644 repo.php diff --git a/repo.php b/repo.php new file mode 100644 index 00000000..570b8106 --- /dev/null +++ b/repo.php @@ -0,0 +1,55 @@ + + + + + + + $ts) { + $ts = $t; + } + } + closedir($d); + + return $ts; +} + +$cacheDir = null; +$ts = newestTimestamp($path); +if (isset($config['cache'])) { + $cacheDir = "{$config['cache']}/repo"; + @mkdir($cacheDir); + $cacheTs = filemtime("{$cacheDir}/{$repo}.json"); + if ($cacheTs === $ts) { + Header("Content-Type: application/json; charset=utf-8"); + readfile("{$cacheDir}/{$repo}.json"); + exit(0); + } +} + +$data = array(); + +$d = opendir($path); +while ($f = readdir($d)) { + if (preg_match("/^([0-9a-zA-Z_\-]+)\.json$/", $f, $m) && $f !== 'package.json') { + $d1 = json_decode(file_get_contents("{$path}/{$f}"), true); + $data[$m[1]] = jsonMultilineStringsJoin($d1, array('exclude' => array(array('const')))); + } +} +closedir($d); + +$ret = json_encode($data, JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES); + +Header("Content-Type: application/json; charset=utf-8"); +print $ret; + +file_put_contents("{$cacheDir}/{$repo}.json", $ret); +touch("{$cacheDir}/{$repo}.json", $ts); diff --git a/src/OpenStreetBrowserLoader.js b/src/OpenStreetBrowserLoader.js index 0aff3dfa..230cd073 100644 --- a/src/OpenStreetBrowserLoader.js +++ b/src/OpenStreetBrowserLoader.js @@ -4,6 +4,7 @@ var jsonMultilineStrings = require('json-multiline-strings') function OpenStreetBrowserLoader () { this.types = {} this.categories = {} + this.repoCache = {} this.templates = {} this._loadClash = {} // if a category is being loaded multiple times, collect callbacks } @@ -18,12 +19,25 @@ OpenStreetBrowserLoader.prototype.getCategory = function (id, callback) { return } - if (id in this._loadClash) { - this._loadClash[id].push(callback) + var repo = 'default' + + if (repo in this.repoCache) { + this.getCategoryFromData(id, this.repoCache[repo][id], function (err, category) { + if (category) { + category.setMap(this.map) + } + + callback(err, category) + }) return } - this._loadClash[id] = [] + if (repo in this._loadClash) { + this._loadClash[repo].push([ id, callback ]) + return + } + + this._loadClash[repo] = [ [ id, callback ] ] function reqListener (req) { if (req.status !== 200) { @@ -31,26 +45,32 @@ OpenStreetBrowserLoader.prototype.getCategory = function (id, callback) { return callback(req.statusText, null) } - var data = JSON.parse(req.responseText) - data = jsonMultilineStrings.join(data, { exclude: [ [ 'const' ] ] }) + this.repoCache[repo] = JSON.parse(req.responseText) - this.getCategoryFromData(id, data, function (err, category) { - if (category) { - category.setMap(this.map) - } + var todo = this._loadClash[repo] + delete this._loadClash[repo] - callback(err, category) + todo.forEach(function (c) { + var id = c[0] + var callback = c[1] - this._loadClash[id].forEach(function (c) { - c(err, category) - }) - delete this._loadClash[id] + if (id in this.categories) { + callback(null, this.categories[id]) + } else { + this.getCategoryFromData(id, this.repoCache[repo][id], function (err, category) { + if (category) { + category.setMap(this.map) + } + + callback(err, category) + }) + } }.bind(this)) } var req = new XMLHttpRequest() req.addEventListener('load', reqListener.bind(this, req)) - req.open('GET', config.categoriesDir + '/' + id + '.json?' + config.categoriesRev) + req.open('GET', 'repo.php?repo=' + repo + '&' + config.categoriesRev) req.send() } From 92b39f59e20a2d966df50f387b523bb753c769d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20B=C3=B6sch-Plepelits?= Date: Thu, 7 Dec 2017 06:52:24 +0100 Subject: [PATCH 03/54] OpenStreetBrowserLoader: optional parameters 'options' - getCategory() - getTemplate() --- src/OpenStreetBrowserLoader.js | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/src/OpenStreetBrowserLoader.js b/src/OpenStreetBrowserLoader.js index 230cd073..f6a63f1d 100644 --- a/src/OpenStreetBrowserLoader.js +++ b/src/OpenStreetBrowserLoader.js @@ -13,7 +13,17 @@ OpenStreetBrowserLoader.prototype.setMap = function (map) { this.map = map } -OpenStreetBrowserLoader.prototype.getCategory = function (id, callback) { +/** + * @param string id ID of the category + * @parapm [object] options Options. + * @param function callback Callback which will be called with (err, category) + */ +OpenStreetBrowserLoader.prototype.getCategory = function (id, options, callback) { + if (typeof options === 'function') { + callback = options + options = {} + } + if (id in this.categories) { callback(null, this.categories[id]) return @@ -74,7 +84,17 @@ OpenStreetBrowserLoader.prototype.getCategory = function (id, callback) { req.send() } -OpenStreetBrowserLoader.prototype.getTemplate = function (id, callback) { +/** + * @param string id ID of the template + * @parapm [object] options Options. + * @param function callback Callback which will be called with (err, template) + */ +OpenStreetBrowserLoader.prototype.getTemplate = function (id, options, callback) { + if (typeof options === 'function') { + callback = options + options = {} + } + if (id in this.templates) { callback.apply(this, this.templates[id]) return From 35a01460fe44ad30e380b813c62ad41c849d0c11 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20B=C3=B6sch-Plepelits?= Date: Thu, 7 Dec 2017 07:09:21 +0100 Subject: [PATCH 04/54] OpenStreetBrowserLoader: split getRepo() from getCategory() --- src/OpenStreetBrowserLoader.js | 55 +++++++++++++++++++--------------- 1 file changed, 31 insertions(+), 24 deletions(-) diff --git a/src/OpenStreetBrowserLoader.js b/src/OpenStreetBrowserLoader.js index f6a63f1d..f192d345 100644 --- a/src/OpenStreetBrowserLoader.js +++ b/src/OpenStreetBrowserLoader.js @@ -25,29 +25,49 @@ OpenStreetBrowserLoader.prototype.getCategory = function (id, options, callback) } if (id in this.categories) { - callback(null, this.categories[id]) - return + return callback(null, this.categories[id]) } - var repo = 'default' + this.getRepo(repo, options, function (err, repoData) { + // maybe loaded in the meantime? + if (id in this.categories) { + return callback(null, this.categories[id]) + } - if (repo in this.repoCache) { - this.getCategoryFromData(id, this.repoCache[repo][id], function (err, category) { + if (err) { + return callback(err, null) + } + + if (!(id in repoData)) { + return callback(new Error('category not defined'), null) + } + + this.getCategoryFromData(id, repoData[id], function (err, category) { if (category) { category.setMap(this.map) } callback(err, category) - }) - return + }.bind(this)) + }.bind(this)) +} + +/** + * @param string repo ID of the repository + * @parapm [object] options Options. + * @param function callback Callback which will be called with (err, repoData) + */ +OpenStreetBrowserLoader.prototype.getRepo = function (repo, options, callback) { + if (repo in this.repoCache) { + return callback(null, this.repoCache[repo]) } if (repo in this._loadClash) { - this._loadClash[repo].push([ id, callback ]) + this._loadClash[repo].push(callback) return } - this._loadClash[repo] = [ [ id, callback ] ] + this._loadClash[repo] = [ callback ] function reqListener (req) { if (req.status !== 200) { @@ -60,21 +80,8 @@ OpenStreetBrowserLoader.prototype.getCategory = function (id, options, callback) var todo = this._loadClash[repo] delete this._loadClash[repo] - todo.forEach(function (c) { - var id = c[0] - var callback = c[1] - - if (id in this.categories) { - callback(null, this.categories[id]) - } else { - this.getCategoryFromData(id, this.repoCache[repo][id], function (err, category) { - if (category) { - category.setMap(this.map) - } - - callback(err, category) - }) - } + todo.forEach(function (callback) { + callback(null, this.repoCache[repo]) }.bind(this)) } From 73dee9e5e696c7631843e7b6ac4a477bea5a699e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20B=C3=B6sch-Plepelits?= Date: Thu, 7 Dec 2017 09:47:01 +0100 Subject: [PATCH 05/54] OpenStreetBrowserLoader/repo.php: load alternative repositories --- src/CategoryBase.js | 6 ++++++ src/OpenStreetBrowserLoader.js | 15 +++++++++++++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/CategoryBase.js b/src/CategoryBase.js index 4e9fb3eb..f63bd14c 100644 --- a/src/CategoryBase.js +++ b/src/CategoryBase.js @@ -13,6 +13,12 @@ function CategoryBase (id, data) { var name var a + this.repoId = null + var m + if (m = this.id.match(/^(.+)\.([^\.]+)$/)) { + this.repoId = m[1] + } + if (this.id !== 'index') { var domHeader = document.createElement('header') this.dom.appendChild(domHeader) diff --git a/src/OpenStreetBrowserLoader.js b/src/OpenStreetBrowserLoader.js index f192d345..b9115606 100644 --- a/src/OpenStreetBrowserLoader.js +++ b/src/OpenStreetBrowserLoader.js @@ -24,6 +24,17 @@ OpenStreetBrowserLoader.prototype.getCategory = function (id, options, callback) options = {} } + var repo + var categoryId + var m + if (m = id.match(/^(.*)\.([^\.]*)/)) { + repo = m[1] + categoryId = m[2] + } else { + repo = 'default' + categoryId = id + } + if (id in this.categories) { return callback(null, this.categories[id]) } @@ -38,11 +49,11 @@ OpenStreetBrowserLoader.prototype.getCategory = function (id, options, callback) return callback(err, null) } - if (!(id in repoData)) { + if (!(categoryId in repoData)) { return callback(new Error('category not defined'), null) } - this.getCategoryFromData(id, repoData[id], function (err, category) { + this.getCategoryFromData(id, repoData[categoryId], function (err, category) { if (category) { category.setMap(this.map) } From 9b7bf93f4410ab026d340bbbbdde96a2c715951e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20B=C3=B6sch-Plepelits?= Date: Thu, 7 Dec 2017 12:49:33 +0100 Subject: [PATCH 06/54] Categories: if cat. is from alternative repo, print repo name --- src/CategoryBase.js | 7 +++++++ src/category.css | 6 ++++++ 2 files changed, 13 insertions(+) diff --git a/src/CategoryBase.js b/src/CategoryBase.js index f63bd14c..b437ad47 100644 --- a/src/CategoryBase.js +++ b/src/CategoryBase.js @@ -41,6 +41,13 @@ function CategoryBase (id, data) { a.onclick = this.toggle.bind(this) domHeader.appendChild(a) + if (this.repoId) { + a = document.createElement('span') + a.className = 'repoId' + a.appendChild(document.createTextNode(this.repoId)) + domHeader.appendChild(a) + } + if (options.debug) { a = document.createElement('a') a.appendChild(document.createTextNode('⟳')) diff --git a/src/category.css b/src/category.css index 65dc2cff..5cfb4c1a 100644 --- a/src/category.css +++ b/src/category.css @@ -69,6 +69,12 @@ user-select: none; font-size: 15px; } +.category header > span.repoId { + margin-left: 0.2em; + font-size: 10px; + line-height: 10px; + color: #7f7f7f; +} .category header > a { text-decoration: none; color: black; From ab2e9ab4a5195c29fd929f55054314c6cf2d521a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20B=C3=B6sch-Plepelits?= Date: Thu, 7 Dec 2017 12:50:48 +0100 Subject: [PATCH 07/54] Add Categories: show list of categories in repo --- lang/ast.json | 1 + lang/ca.json | 1 + lang/cs.json | 1 + lang/da.json | 1 + lang/de.json | 1 + lang/el.json | 1 + lang/en.json | 1 + lang/es.json | 1 + lang/et.json | 1 + lang/fr.json | 1 + lang/hu.json | 1 + lang/it.json | 1 + lang/ja.json | 1 + lang/nl.json | 1 + lang/pl.json | 1 + lang/ro.json | 1 + lang/ru.json | 1 + lang/sr.json | 1 + lang/template.json | 1 + lang/uk.json | 1 + src/addCategories.css | 3 +++ src/addCategories.js | 39 +++++++++++++++++++++++++++++++++++++++ src/index.js | 1 + 23 files changed, 63 insertions(+) create mode 100644 src/addCategories.css create mode 100644 src/addCategories.js diff --git a/lang/ast.json b/lang/ast.json index d6d91532..6e2dfef4 100644 --- a/lang/ast.json +++ b/lang/ast.json @@ -1,6 +1,7 @@ { "main:options": "Opciones", "more": "más", + "more_categories": "Más categoríes", "options:data_lang": "Llingua de los datos", "options:data_lang:local": "Llingua llocal", "options:ui_lang": "Llingua de la interfaz", diff --git a/lang/ca.json b/lang/ca.json index 125c6797..9d4776cc 100644 --- a/lang/ca.json +++ b/lang/ca.json @@ -1,5 +1,6 @@ { "main:options": "Opcions", "more": "més", + "more_categories": "Més categories", "save": "Guardar" } \ No newline at end of file diff --git a/lang/cs.json b/lang/cs.json index 9ee96b8f..7c670980 100644 --- a/lang/cs.json +++ b/lang/cs.json @@ -1,6 +1,7 @@ { "main:options": "Nastavení", "more": "více", + "more_categories": "Více kategorií", "options:data_lang": "Jazyk dat", "options:data_lang:local": "Místní jazyk", "options:ui_lang": "Jazyk rozhraní", diff --git a/lang/da.json b/lang/da.json index 8145e1e2..ba4c1059 100644 --- a/lang/da.json +++ b/lang/da.json @@ -1,6 +1,7 @@ { "main:options": "Indstillinger", "more": "mere", + "more_categories": "Flere kategorier", "options:data_lang": "Data sprog", "options:data_lang:local": "Lokalt sprog", "options:ui_lang": "Brugerfladesprog", diff --git a/lang/de.json b/lang/de.json index 07e2b059..77fda9d9 100644 --- a/lang/de.json +++ b/lang/de.json @@ -10,6 +10,7 @@ "images": "Bilder", "main:options": "Optionen", "more": "mehr", + "more_categories": "Mehr Kategorien", "open": "geöffnet", "options:data_lang": "Datensprache", "options:data_lang:local": "Lokale Sprache", diff --git a/lang/el.json b/lang/el.json index c909aa30..d1fffd22 100644 --- a/lang/el.json +++ b/lang/el.json @@ -1,6 +1,7 @@ { "main:options": "Επιλογές", "more": "περισσότερα", + "more_categories": "Περισσότερες κατηγορίες", "options:data_lang": "Γλωσσα δεδομένων", "options:data_lang:local": "Τοπική γλώσσα", "options:ui_lang": "Γλώσσα διεπαφής", diff --git a/lang/en.json b/lang/en.json index db92c67c..1ad3b85b 100644 --- a/lang/en.json +++ b/lang/en.json @@ -10,6 +10,7 @@ "images": "Images", "main:options": "Options", "more": "more", + "more_categories": "More categories", "open": "open", "options:data_lang": "Data language", "options:data_lang:desc": "Many map features have their name (and other tags) translated to different languages (e.g. with 'name:en', 'name:de'). Specify which language should be used for displaying, or 'Local language' so that always the untranslated value (e.g. 'name') will be used", diff --git a/lang/es.json b/lang/es.json index 0f4a7c32..310b5aab 100644 --- a/lang/es.json +++ b/lang/es.json @@ -1,6 +1,7 @@ { "main:options": "Opciones", "more": "más", + "more_categories": "Más categorías", "options:data_lang": "Idioma de datos", "options:data_lang:local": "Idioma local", "options:ui_lang": "Idioma de interfaz", diff --git a/lang/et.json b/lang/et.json index 7028b216..4b6a190d 100644 --- a/lang/et.json +++ b/lang/et.json @@ -1,6 +1,7 @@ { "main:options": "Valikud", "more": "lisaks", + "more_categories": "Rohkem kategooriaid", "options:data_lang": "Andmete keel", "options:data_lang:local": "Kohalik keel", "options:ui_lang": "Kasutajaliidese keel", diff --git a/lang/fr.json b/lang/fr.json index e9c15df0..4cbf03d4 100644 --- a/lang/fr.json +++ b/lang/fr.json @@ -1,6 +1,7 @@ { "main:options": "Options", "more": "plus", + "more_categories": "Plus de catégories", "options:data_lang": "Langue des données", "options:data_lang:local": "Langue locale", "options:ui_lang": "Langue de l'interface", diff --git a/lang/hu.json b/lang/hu.json index 0d5c91da..b8422d91 100644 --- a/lang/hu.json +++ b/lang/hu.json @@ -1,6 +1,7 @@ { "main:options": "Beállítások", "more": "több", + "more_categories": "Több kategória", "options:data_lang": "Adatnyelv", "options:data_lang:local": "Helyi nyelv", "options:ui_lang": "Menünyelv", diff --git a/lang/it.json b/lang/it.json index 3746ee15..9830f55a 100644 --- a/lang/it.json +++ b/lang/it.json @@ -1,6 +1,7 @@ { "main:options": "Opzioni", "more": "altri", + "more_categories": "Altre categorie", "options:data_lang": "Lingua dei dati", "options:data_lang:local": "Lingua del tuo browser", "options:ui_lang": "Lingua dell'interfaccia", diff --git a/lang/ja.json b/lang/ja.json index 7c37bd2f..677dd258 100644 --- a/lang/ja.json +++ b/lang/ja.json @@ -1,6 +1,7 @@ { "main:options": "オプション設定", "more": "もっと", + "more_categories": "カテゴリを一覧から追加", "options:data_lang": "データ表示", "options:data_lang:local": "ブラウザの設定言語", "options:ui_lang": "インタフェース表示", diff --git a/lang/nl.json b/lang/nl.json index 7bdb8e7b..812f5d23 100644 --- a/lang/nl.json +++ b/lang/nl.json @@ -1,6 +1,7 @@ { "main:options": "Opties", "more": "meer", + "more_categories": "Meer categorieën", "options:data_lang": "Taal voor data", "options:data_lang:local": "Lokale taal", "options:ui_lang": "Interfacetaal", diff --git a/lang/pl.json b/lang/pl.json index 1b281fb5..108ffafb 100644 --- a/lang/pl.json +++ b/lang/pl.json @@ -1,6 +1,7 @@ { "main:options": "Opcje", "more": "więcej", + "more_categories": "Więcej kategorii", "options:data_lang": "Język danych", "options:data_lang:local": "Język lokalny", "options:ui_lang": "Język interfejsu", diff --git a/lang/ro.json b/lang/ro.json index b2faa188..93199b31 100644 --- a/lang/ro.json +++ b/lang/ro.json @@ -1,6 +1,7 @@ { "main:options": "Optiuni", "more": "Mai mult", + "more_categories": "Mai multe categorii", "options:data_lang": "Limba date", "options:data_lang:local": "Limba locala", "options:ui_lang": "Limba interfata", diff --git a/lang/ru.json b/lang/ru.json index 66dac2a2..29cb888f 100644 --- a/lang/ru.json +++ b/lang/ru.json @@ -1,6 +1,7 @@ { "main:options": "Настройки", "more": "Ещё", + "more_categories": "Больше категорий", "options:data_lang": "Язык информации на карте", "options:data_lang:local": "Определить язык автоматически", "options:ui_lang": "Язык интерфейса", diff --git a/lang/sr.json b/lang/sr.json index 4a52d62d..c462a670 100644 --- a/lang/sr.json +++ b/lang/sr.json @@ -1,6 +1,7 @@ { "main:options": "Опције", "more": "још", + "more_categories": "Више категорија", "options:data_lang": "Језик подетака", "options:data_lang:local": "Локални језик", "options:ui_lang": "Језик интерфејса", diff --git a/lang/template.json b/lang/template.json index 8bdbd5bf..e127a61a 100644 --- a/lang/template.json +++ b/lang/template.json @@ -2,6 +2,7 @@ "default": "", "main:options": "", "more": "", + "more_categories": "", "options:data_lang": "", "options:data_lang:desc": "", "options:data_lang:local": "", diff --git a/lang/uk.json b/lang/uk.json index 93ab3b75..bbe22f2d 100644 --- a/lang/uk.json +++ b/lang/uk.json @@ -1,6 +1,7 @@ { "main:options": "Налаштування", "more": "Ще", + "more_categories": "Більше категорій", "options:data_lang": "Мова мапи", "options:data_lang:local": "Місцева мова", "options:ui_lang": "Мова інтерфейсу", diff --git a/src/addCategories.css b/src/addCategories.css new file mode 100644 index 00000000..4a72bd97 --- /dev/null +++ b/src/addCategories.css @@ -0,0 +1,3 @@ +#content.addCategories > #contentAddCategories { + display: block; +} diff --git a/src/addCategories.js b/src/addCategories.js new file mode 100644 index 00000000..17ac343f --- /dev/null +++ b/src/addCategories.js @@ -0,0 +1,39 @@ +var OpenStreetBrowserLoader = require('./OpenStreetBrowserLoader') +require('./addCategories.css') + +var content +var template = ` +{% for id, data in repoData %} +{{ id }}
+{% endfor %} +` + +function addCategoriesShow () { + if (!content) { + content = document.createElement('div') + content.id = 'contentAddCategories' + document.getElementById('content').appendChild(content) + + template = OverpassLayer.twig.twig({ data: template, autoescape: true }) + } + + content.innerHTML = 'Loading ...' + document.getElementById('content').className = 'addCategories' + + OpenStreetBrowserLoader.getRepo('default', {}, function (err, repoData) { + content.innerHTML = template.render({ repoData: repoData }) + }) +} + +register_hook('init', function (callback) { + var link = document.createElement('a') + link.className = 'addCategories' + link.href = '#' + link.onclick = function () { + addCategoriesShow() + return false + } + link.innerHTML = lang('more_categories') + + document.getElementById('contentList').appendChild(link) +}) diff --git a/src/index.js b/src/index.js index 2d57c399..e1bb5a9f 100644 --- a/src/index.js +++ b/src/index.js @@ -30,6 +30,7 @@ require('./markers') require('./categories') require('./wikipedia') require('./image') +require('./addCategories') window.onload = function () { initState = config.defaultView From 13a4424ab8b1e162d35b666f44832f788ff03ce2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20B=C3=B6sch-Plepelits?= Date: Thu, 7 Dec 2017 18:49:38 +0100 Subject: [PATCH 08/54] repo.php: select repo to list --- repo.php | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/repo.php b/repo.php index 570b8106..d970f916 100644 --- a/repo.php +++ b/repo.php @@ -5,8 +5,24 @@ array( + 'path' => $config['categoriesDir'], + ), + ); +} + +if (isset($_REQUEST['repo'])) { + $repo = $_REQUEST['repo']; +} + +if (!array_key_exists($repo, $repositories)) { + Header("HTTP/1.1 404 Repository not found"); + exit(0); +} + +$path = $repositories[$repo]['path']; function newestTimestamp ($path) { $ts = 0; From b66553765b04eb94f84dc96a73b14d369ec9b6f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20B=C3=B6sch-Plepelits?= Date: Thu, 7 Dec 2017 20:40:13 +0100 Subject: [PATCH 09/54] repo.php: if no repo parameter is given, list repositories --- repo.php | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/repo.php b/repo.php index d970f916..f876f794 100644 --- a/repo.php +++ b/repo.php @@ -13,10 +13,30 @@ if (!isset($repositories)) { ); } -if (isset($_REQUEST['repo'])) { - $repo = $_REQUEST['repo']; +if (!isset($_REQUEST['repo'])) { + Header("Content-Type: application/json; charset=utf-8"); + print '{'; + + $c = 0; + foreach ($repositories as $repoId => $repoData) { + print $c++ ? ',' : ''; + $d = array(); + foreach (array('name') as $k) { + if (array_key_exists($k, $repoData)) { + $d[$k] = $repoData[$k]; + } + } + + print json_encode($repoId) . ':'; + print json_encode($d, JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES|JSON_FORCE_OBJECT); + } + + print '}'; + exit(0); } +$repo = $_REQUEST['repo']; + if (!array_key_exists($repo, $repositories)) { Header("HTTP/1.1 404 Repository not found"); exit(0); From d13385c085954a505105021f44ee5dd9b3b5477d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20B=C3=B6sch-Plepelits?= Date: Thu, 7 Dec 2017 21:56:38 +0100 Subject: [PATCH 10/54] OpenStreetBrowserLoader.getRepo(): no id -> load list of repos --- src/OpenStreetBrowserLoader.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/OpenStreetBrowserLoader.js b/src/OpenStreetBrowserLoader.js index b9115606..f9b0e83a 100644 --- a/src/OpenStreetBrowserLoader.js +++ b/src/OpenStreetBrowserLoader.js @@ -96,9 +96,16 @@ OpenStreetBrowserLoader.prototype.getRepo = function (repo, options, callback) { }.bind(this)) } + var param = [] + if (repo) { + param.push('repo=' + encodeURIComponent(repo)) + } + param.push(config.categoriesRev) + param = param.length ? '?' + param.join('&') : '' + var req = new XMLHttpRequest() req.addEventListener('load', reqListener.bind(this, req)) - req.open('GET', 'repo.php?repo=' + repo + '&' + config.categoriesRev) + req.open('GET', 'repo.php' + param) req.send() } From 10fe71268ccd6f71ebc6db988d69222d11209e1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20B=C3=B6sch-Plepelits?= Date: Thu, 7 Dec 2017 21:59:04 +0100 Subject: [PATCH 11/54] addCategories: list repos or categories --- src/addCategories.js | 48 +++++++++++++++++++++++++++++++++++--------- 1 file changed, 38 insertions(+), 10 deletions(-) diff --git a/src/addCategories.js b/src/addCategories.js index 17ac343f..ab5c340f 100644 --- a/src/addCategories.js +++ b/src/addCategories.js @@ -2,29 +2,57 @@ var OpenStreetBrowserLoader = require('./OpenStreetBrowserLoader') require('./addCategories.css') var content -var template = ` -{% for id, data in repoData %} -{{ id }}
-{% endfor %} -` -function addCategoriesShow () { +function addCategoriesShow (repo) { if (!content) { content = document.createElement('div') content.id = 'contentAddCategories' document.getElementById('content').appendChild(content) - - template = OverpassLayer.twig.twig({ data: template, autoescape: true }) } content.innerHTML = 'Loading ...' document.getElementById('content').className = 'addCategories' - OpenStreetBrowserLoader.getRepo('default', {}, function (err, repoData) { - content.innerHTML = template.render({ repoData: repoData }) + OpenStreetBrowserLoader.getRepo(repo, {}, function (err, repoData) { + var ul = document.createElement('ul') + + for (var id in repoData) { + var data = repoData[id] + + var li = document.createElement('li') + + var a = document.createElement('a') + if (repo) { + a.href = '#categories=' + repo + '.' + id + a.onclick = function () { + addCategoriesHide() + } + } else { + a.href = '#' + a.onclick = function (id) { + addCategoriesShow(id) + return false + }.bind(this, id) + } + + li.appendChild(a) + a.appendChild(document.createTextNode('name' in data ? lang(data.name) : id)) + li.appendChild(a) + + ul.appendChild(li) + } + + while(content.firstChild) + content.removeChild(content.firstChild) + + content.appendChild(ul) }) } +function addCategoriesHide () { + document.getElementById('content').className = 'list' +} + register_hook('init', function (callback) { var link = document.createElement('a') link.className = 'addCategories' From 1d51c1f3ff29f8371022aa5eb02d70d8c0899f3f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20B=C3=B6sch-Plepelits?= Date: Thu, 7 Dec 2017 22:24:31 +0100 Subject: [PATCH 12/54] addCategories: back links & headings --- lang/de.json | 1 + lang/en.json | 1 + src/addCategories.js | 33 ++++++++++++++++++++++++++++++--- 3 files changed, 32 insertions(+), 3 deletions(-) diff --git a/lang/de.json b/lang/de.json index 77fda9d9..50d314cd 100644 --- a/lang/de.json +++ b/lang/de.json @@ -1,4 +1,5 @@ { + "back": "zurück", "category-info-tooltip": "Info & Legende", "closed": "geschlossen", "default": "Standard", diff --git a/lang/en.json b/lang/en.json index 1ad3b85b..08e8bf46 100644 --- a/lang/en.json +++ b/lang/en.json @@ -1,4 +1,5 @@ { + "back": "back", "category-info-tooltip": "Info & Map key", "closed": "closed", "default": "default", diff --git a/src/addCategories.js b/src/addCategories.js index ab5c340f..4998a3b8 100644 --- a/src/addCategories.js +++ b/src/addCategories.js @@ -14,6 +14,36 @@ function addCategoriesShow (repo) { document.getElementById('content').className = 'addCategories' OpenStreetBrowserLoader.getRepo(repo, {}, function (err, repoData) { + while(content.firstChild) + content.removeChild(content.firstChild) + + var backLink = document.createElement('a') + backLink.className = 'back' + backLink.href = '#' + backLink.appendChild(document.createTextNode(lang('back'))) + + if (repo) { + backLink.onclick = function () { + addCategoriesShow() + return false + } + content.appendChild(backLink) + + var h = document.createElement('h2') + h.appendChild(document.createTextNode(repo)) + content.appendChild(h) + } else { + backLink.onclick = function () { + addCategoriesHide() + return false + } + content.appendChild(backLink) + + var h = document.createElement('h2') + h.innerHTML = lang('more_categories') + content.appendChild(h) + } + var ul = document.createElement('ul') for (var id in repoData) { @@ -42,9 +72,6 @@ function addCategoriesShow (repo) { ul.appendChild(li) } - while(content.firstChild) - content.removeChild(content.firstChild) - content.appendChild(ul) }) } From 28db34cf9386bdca9f987cea967843c6acf4cbbd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20B=C3=B6sch-Plepelits?= Date: Fri, 8 Dec 2017 20:43:03 +0100 Subject: [PATCH 13/54] addCategories: add edit link --- conf.php-dist | 3 +++ src/addCategories.js | 13 ++++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/conf.php-dist b/conf.php-dist index caa529f2..600dd113 100644 --- a/conf.php-dist +++ b/conf.php-dist @@ -5,6 +5,9 @@ $config['categoriesDir'] = 'node_modules/openstreetbrowser-categories-main'; // Set to true to reload categories on every page visit. $config['categoriesAlwaysReload'] = true; +// (optional) URL, which points to the OpenStreetBrowser Editor +#$config['urlCategoriesEditor'] = 'editor/'; + // URL of the Overpass API $config['overpassUrl'] = array( '//overpass-api.de/api/interpreter', diff --git a/src/addCategories.js b/src/addCategories.js index 4998a3b8..aa1fca98 100644 --- a/src/addCategories.js +++ b/src/addCategories.js @@ -67,7 +67,18 @@ function addCategoriesShow (repo) { li.appendChild(a) a.appendChild(document.createTextNode('name' in data ? lang(data.name) : id)) - li.appendChild(a) + + if (config.urlCategoriesEditor) { + a = document.createElement('a') + if (repo) { + a.href = config.urlCategoriesEditor + '?id=' + repo + '.' + id + } else { + a.href = config.urlCategoriesEditor + '?repo=' + id + } + a.target = '_blank' + a.innerHTML = '' + li.appendChild(a) + } ul.appendChild(li) } From aaba36ebc983f37b844b4cbcbd92ffdfc4f71753 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20B=C3=B6sch-Plepelits?= Date: Sat, 23 Dec 2017 21:10:58 +0100 Subject: [PATCH 14/54] repo.php: split code into class RepositoryDir --- modulekit.php | 1 + repo.php | 53 ++++++++++--------------------------------- src/RepositoryDir.php | 48 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 61 insertions(+), 41 deletions(-) create mode 100644 src/RepositoryDir.php diff --git a/modulekit.php b/modulekit.php index 20c6354b..3dfe3a26 100644 --- a/modulekit.php +++ b/modulekit.php @@ -16,6 +16,7 @@ $include = array( 'src/ip-location.php', 'src/wikipedia.php', 'src/ImageLoader.php', + 'src/RepositoryDir.php', ), 'css' => array( 'style.css', diff --git a/repo.php b/repo.php index f876f794..bcc9aa99 100644 --- a/repo.php +++ b/repo.php @@ -19,73 +19,44 @@ if (!isset($_REQUEST['repo'])) { $c = 0; foreach ($repositories as $repoId => $repoData) { - print $c++ ? ',' : ''; - $d = array(); - foreach (array('name') as $k) { - if (array_key_exists($k, $repoData)) { - $d[$k] = $repoData[$k]; - } - } + $repo = new RepositoryDir($repoId, $repoData); + print $c++ ? ',' : ''; print json_encode($repoId) . ':'; - print json_encode($d, JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES|JSON_FORCE_OBJECT); + print json_encode($repo->info(), JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES|JSON_FORCE_OBJECT); } print '}'; exit(0); } -$repo = $_REQUEST['repo']; - -if (!array_key_exists($repo, $repositories)) { +$repoId = $_REQUEST['repo']; +if (!array_key_exists($repoId, $repositories)) { Header("HTTP/1.1 404 Repository not found"); exit(0); } -$path = $repositories[$repo]['path']; - -function newestTimestamp ($path) { - $ts = 0; - $d = opendir($path); - while ($f = readdir($d)) { - $t = filemtime("{$path}/{$f}"); - if ($t > $ts) { - $ts = $t; - } - } - closedir($d); - - return $ts; -} +$repo = new RepositoryDir($repoId, $repositories[$repoId]); $cacheDir = null; -$ts = newestTimestamp($path); +$ts = $repo->newestTimestamp($path); if (isset($config['cache'])) { $cacheDir = "{$config['cache']}/repo"; @mkdir($cacheDir); - $cacheTs = filemtime("{$cacheDir}/{$repo}.json"); + $cacheTs = filemtime("{$cacheDir}/{$repoId}.json"); if ($cacheTs === $ts) { Header("Content-Type: application/json; charset=utf-8"); - readfile("{$cacheDir}/{$repo}.json"); + readfile("{$cacheDir}/{$repoId}.json"); exit(0); } } -$data = array(); - -$d = opendir($path); -while ($f = readdir($d)) { - if (preg_match("/^([0-9a-zA-Z_\-]+)\.json$/", $f, $m) && $f !== 'package.json') { - $d1 = json_decode(file_get_contents("{$path}/{$f}"), true); - $data[$m[1]] = jsonMultilineStringsJoin($d1, array('exclude' => array(array('const')))); - } -} -closedir($d); +$data = $repo->data(); $ret = json_encode($data, JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES); Header("Content-Type: application/json; charset=utf-8"); print $ret; -file_put_contents("{$cacheDir}/{$repo}.json", $ret); -touch("{$cacheDir}/{$repo}.json", $ts); +file_put_contents("{$cacheDir}/{$repoId}.json", $ret); +touch("{$cacheDir}/{$repoId}.json", $ts); diff --git a/src/RepositoryDir.php b/src/RepositoryDir.php new file mode 100644 index 00000000..bbf74918 --- /dev/null +++ b/src/RepositoryDir.php @@ -0,0 +1,48 @@ +def = $def; + $this->path = $def['path']; + } + + function info () { + $ret = array(); + + foreach (array('name') as $k) { + if (array_key_exists($k, $this->def)) { + $ret[$k] = $this->def[$k]; + } + } + + return $ret; + } + + function newestTimestamp () { + $ts = 0; + $d = opendir($this->path); + while ($f = readdir($d)) { + $t = filemtime("{$this->path}/{$f}"); + if ($t > $ts) { + $ts = $t; + } + } + closedir($d); + + return $ts; + } + + function data () { + $data = array(); + + $d = opendir($this->path); + while ($f = readdir($d)) { + if (preg_match("/^([0-9a-zA-Z_\-]+)\.json$/", $f, $m) && $f !== 'package.json') { + $d1 = json_decode(file_get_contents("{$this->path}/{$f}"), true); + $data[$m[1]] = jsonMultilineStringsJoin($d1, array('exclude' => array(array('const')))); + } + } + closedir($d); + + return $data; + } +} From 1b030293d003a373ca19cf773ad4e5a16606ae62 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20B=C3=B6sch-Plepelits?= Date: Sat, 23 Dec 2017 22:24:31 +0100 Subject: [PATCH 15/54] repo.php: getRepo() to load repository class --- repo.php | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/repo.php b/repo.php index bcc9aa99..9eafb511 100644 --- a/repo.php +++ b/repo.php @@ -13,13 +13,22 @@ if (!isset($repositories)) { ); } +function getRepo ($repoId, $repoData) { + switch (array_key_exists('type', $repoData) ? $repoData['type'] : 'dir') { + default: + $repo = new RepositoryDir($repoId, $repoData); + } + + return $repo; +} + if (!isset($_REQUEST['repo'])) { Header("Content-Type: application/json; charset=utf-8"); print '{'; $c = 0; foreach ($repositories as $repoId => $repoData) { - $repo = new RepositoryDir($repoId, $repoData); + $repo = getRepo($repoId, $repoData); print $c++ ? ',' : ''; print json_encode($repoId) . ':'; @@ -36,7 +45,7 @@ if (!array_key_exists($repoId, $repositories)) { exit(0); } -$repo = new RepositoryDir($repoId, $repositories[$repoId]); +$repo = getRepo($repoId, $repositories[$repoId]); $cacheDir = null; $ts = $repo->newestTimestamp($path); From fd349d1d5f06a050ded97f6424446b5c902e0347 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20B=C3=B6sch-Plepelits?= Date: Sat, 23 Dec 2017 22:25:50 +0100 Subject: [PATCH 16/54] repo.php: new repository type 'git' --- modulekit.php | 1 + repo.php | 3 +++ src/RepositoryGit.php | 47 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 51 insertions(+) create mode 100644 src/RepositoryGit.php diff --git a/modulekit.php b/modulekit.php index 3dfe3a26..28a9b88a 100644 --- a/modulekit.php +++ b/modulekit.php @@ -17,6 +17,7 @@ $include = array( 'src/wikipedia.php', 'src/ImageLoader.php', 'src/RepositoryDir.php', + 'src/RepositoryGit.php', ), 'css' => array( 'style.css', diff --git a/repo.php b/repo.php index 9eafb511..74231247 100644 --- a/repo.php +++ b/repo.php @@ -15,6 +15,9 @@ if (!isset($repositories)) { function getRepo ($repoId, $repoData) { switch (array_key_exists('type', $repoData) ? $repoData['type'] : 'dir') { + case 'git': + $repo = new RepositoryGit($repoId, $repoData); + break; default: $repo = new RepositoryDir($repoId, $repoData); } diff --git a/src/RepositoryGit.php b/src/RepositoryGit.php new file mode 100644 index 00000000..fa22857b --- /dev/null +++ b/src/RepositoryGit.php @@ -0,0 +1,47 @@ +def = $def; + $this->path = $def['path']; + } + + function info () { + $ret = array(); + + foreach (array('name') as $k) { + if (array_key_exists($k, $this->def)) { + $ret[$k] = $this->def[$k]; + } + } + + return $ret; + } + + function newestTimestamp () { + $ts = (int)shell_exec("cd " . escapeShellArg($this->path) . "; git log -1 --pretty=format:%ct"); + + return $ts; + } + + function data () { + $data = array(); + + $d = popen("cd " . escapeShellArg($this->path) . "; git ls-tree HEAD", "r"); + while ($r = fgets($d)) { + if (preg_match("/^[0-9]{6} blob [0-9a-f]{40}\t(([0-9a-zA-Z_\-]+)\.json)$/", $r, $m)) { + $f = $m[1]; + $id = $m[2]; + + if ($f === 'package.json') { + continue; + } + + $d1 = json_decode(shell_exec("cd " . escapeShellArg($this->path) . "; git show HEAD:" . escapeShellArg($f)), true); + $data[$id] = jsonMultilineStringsJoin($d1, array('exclude' => array(array('const')))); + } + } + pclose($d); + + return $data; + } +} From 14d44c80c1af752bce8b25a4d3592a2649057231 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20B=C3=B6sch-Plepelits?= Date: Mon, 25 Dec 2017 18:48:02 +0100 Subject: [PATCH 17/54] Repositories: move code to src/repositories.php; configure $config['repositories'] --- conf.php-dist | 9 +++++++-- modulekit.php | 1 + repo.php | 26 ++++---------------------- src/repositories.php | 30 ++++++++++++++++++++++++++++++ 4 files changed, 42 insertions(+), 24 deletions(-) create mode 100644 src/repositories.php diff --git a/conf.php-dist b/conf.php-dist index 600dd113..aedbd643 100644 --- a/conf.php-dist +++ b/conf.php-dist @@ -1,6 +1,11 @@ array( + 'path' => 'node_modules/openstreetbrowser-categories-main', + 'type' => 'dir', + ), +); // Set to true to reload categories on every page visit. $config['categoriesAlwaysReload'] = true; diff --git a/modulekit.php b/modulekit.php index 28a9b88a..52af002a 100644 --- a/modulekit.php +++ b/modulekit.php @@ -18,6 +18,7 @@ $include = array( 'src/ImageLoader.php', 'src/RepositoryDir.php', 'src/RepositoryGit.php', + 'src/repositories.php', ), 'css' => array( 'style.css', diff --git a/repo.php b/repo.php index 74231247..ca51897d 100644 --- a/repo.php +++ b/repo.php @@ -5,32 +5,14 @@ array( - 'path' => $config['categoriesDir'], - ), - ); -} - -function getRepo ($repoId, $repoData) { - switch (array_key_exists('type', $repoData) ? $repoData['type'] : 'dir') { - case 'git': - $repo = new RepositoryGit($repoId, $repoData); - break; - default: - $repo = new RepositoryDir($repoId, $repoData); - } - - return $repo; -} +$allRepositories = getRepositories(); if (!isset($_REQUEST['repo'])) { Header("Content-Type: application/json; charset=utf-8"); print '{'; $c = 0; - foreach ($repositories as $repoId => $repoData) { + foreach (getRepositories() as $repoId => $repoData) { $repo = getRepo($repoId, $repoData); print $c++ ? ',' : ''; @@ -43,12 +25,12 @@ if (!isset($_REQUEST['repo'])) { } $repoId = $_REQUEST['repo']; -if (!array_key_exists($repoId, $repositories)) { +if (!array_key_exists($repoId, $allRepositories)) { Header("HTTP/1.1 404 Repository not found"); exit(0); } -$repo = getRepo($repoId, $repositories[$repoId]); +$repo = getRepo($repoId, $allRepositories[$repoId]); $cacheDir = null; $ts = $repo->newestTimestamp($path); diff --git a/src/repositories.php b/src/repositories.php new file mode 100644 index 00000000..50989f9d --- /dev/null +++ b/src/repositories.php @@ -0,0 +1,30 @@ + array( + 'path' => $config['categoriesDir'], + ), + ); + } + + return $repositories; +} + +function getRepo ($repoId, $repoData) { + switch (array_key_exists('type', $repoData) ? $repoData['type'] : 'dir') { + case 'git': + $repo = new RepositoryGit($repoId, $repoData); + break; + default: + $repo = new RepositoryDir($repoId, $repoData); + } + + return $repo; +} From f26ead7c8eee4a79f145c506f4b2e56914b0c969 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20B=C3=B6sch-Plepelits?= Date: Mon, 25 Dec 2017 18:54:03 +0100 Subject: [PATCH 18/54] Repositories: include repositories from gitea (via $config['repositories_gitea']) --- conf.php-dist | 3 +++ src/repositories.php | 21 +++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/conf.php-dist b/conf.php-dist index aedbd643..3d59670c 100644 --- a/conf.php-dist +++ b/conf.php-dist @@ -7,6 +7,9 @@ $config['repositories'] = array( ), ); +// Repositories which should be included from gitea +$config['repositories_gitea'] = "/home/gitea/gitea-repositories"; + // Set to true to reload categories on every page visit. $config['categoriesAlwaysReload'] = true; diff --git a/src/repositories.php b/src/repositories.php index 50989f9d..7ce2cc8b 100644 --- a/src/repositories.php +++ b/src/repositories.php @@ -14,6 +14,27 @@ function getRepositories () { ); } + if (isset($config['repositories_gitea'])) { + $d1 = opendir($config['repositories_gitea']); + while ($f1 = readdir($d1)) { + if (substr($f1, 0, 1) !== '.') { + $d2 = opendir("{$config['repositories_gitea']}/{$f1}"); + while ($f2 = readdir($d2)) { + if (substr($f2, 0, 1) !== '.') { + $f2id = substr($f2, 0, -4); + + $repositories["{$f1}.{$f2id}"] = array( + 'path' => "{$p}/{$f1}/{$f2}", + 'type' => 'git', + ); + } + } + closedir($d2); + } + } + closedir($d1); + } + return $repositories; } From f0f7478d4ecbf147d7b0d1e29ca86d957241ed2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20B=C3=B6sch-Plepelits?= Date: Mon, 25 Dec 2017 19:09:29 +0100 Subject: [PATCH 19/54] Repositories: separate repo/category parts by '/' --- repo.php | 2 +- src/CategoryBase.js | 2 +- src/OpenStreetBrowserLoader.js | 2 +- src/addCategories.js | 4 ++-- src/index.js | 16 +++++++++------- src/repositories.php | 4 ++-- 6 files changed, 16 insertions(+), 14 deletions(-) diff --git a/repo.php b/repo.php index ca51897d..7231a38e 100644 --- a/repo.php +++ b/repo.php @@ -16,7 +16,7 @@ if (!isset($_REQUEST['repo'])) { $repo = getRepo($repoId, $repoData); print $c++ ? ',' : ''; - print json_encode($repoId) . ':'; + print json_encode($repoId, JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES) . ':'; print json_encode($repo->info(), JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES|JSON_FORCE_OBJECT); } diff --git a/src/CategoryBase.js b/src/CategoryBase.js index b437ad47..da6639e3 100644 --- a/src/CategoryBase.js +++ b/src/CategoryBase.js @@ -15,7 +15,7 @@ function CategoryBase (id, data) { this.repoId = null var m - if (m = this.id.match(/^(.+)\.([^\.]+)$/)) { + if (m = this.id.match(/^(.+)\/([^\/]+)$/)) { this.repoId = m[1] } diff --git a/src/OpenStreetBrowserLoader.js b/src/OpenStreetBrowserLoader.js index f9b0e83a..1e1301f1 100644 --- a/src/OpenStreetBrowserLoader.js +++ b/src/OpenStreetBrowserLoader.js @@ -27,7 +27,7 @@ OpenStreetBrowserLoader.prototype.getCategory = function (id, options, callback) var repo var categoryId var m - if (m = id.match(/^(.*)\.([^\.]*)/)) { + if (m = id.match(/^(.*)\/([^\/]*)/)) { repo = m[1] categoryId = m[2] } else { diff --git a/src/addCategories.js b/src/addCategories.js index aa1fca98..f5882c60 100644 --- a/src/addCategories.js +++ b/src/addCategories.js @@ -53,7 +53,7 @@ function addCategoriesShow (repo) { var a = document.createElement('a') if (repo) { - a.href = '#categories=' + repo + '.' + id + a.href = '#categories=' + repo + '/' + id a.onclick = function () { addCategoriesHide() } @@ -71,7 +71,7 @@ function addCategoriesShow (repo) { if (config.urlCategoriesEditor) { a = document.createElement('a') if (repo) { - a.href = config.urlCategoriesEditor + '?id=' + repo + '.' + id + a.href = config.urlCategoriesEditor + '?id=' + repo + '/' + id } else { a.href = config.urlCategoriesEditor + '?repo=' + id } diff --git a/src/index.js b/src/index.js index e1bb5a9f..78047fb8 100644 --- a/src/index.js +++ b/src/index.js @@ -173,15 +173,17 @@ function show (id, options, callback) { document.getElementById('contentDetails').innerHTML = 'Loading ...' } - id = id.split('/') - - if (id.length < 2) { + var m = id.match(/^(.*)\/([nwr]\d+)(\/details)?$/) + if (!m) { return callback(new Error('unknown request')) } - OpenStreetBrowserLoader.getCategory(id[0], function (err, category) { + var categoryId = m[1] + var featureId = m[2] + + OpenStreetBrowserLoader.getCategory(categoryId, function (err, category) { if (err) { - return callback(new Error('error loading category "' + id[0] + '": ' + err)) + return callback(new Error('error loading category "' + categoryId + '": ' + err)) } if (!category.parentDom) { @@ -189,12 +191,12 @@ function show (id, options, callback) { } category.show( - id[1], + featureId, { }, function (err, data) { if (err) { - return callback(new Error('error loading object "' + id[0] + '/' + id[1] + '": ' + err)) + return callback(new Error('error loading object "' + categoryId + '/' + featureId + '": ' + err)) } if (!map._popup || map._popup !== data.popup) { diff --git a/src/repositories.php b/src/repositories.php index 7ce2cc8b..aea8c1c4 100644 --- a/src/repositories.php +++ b/src/repositories.php @@ -23,8 +23,8 @@ function getRepositories () { if (substr($f2, 0, 1) !== '.') { $f2id = substr($f2, 0, -4); - $repositories["{$f1}.{$f2id}"] = array( - 'path' => "{$p}/{$f1}/{$f2}", + $repositories["{$f1}/{$f2id}"] = array( + 'path' => "{$config['repositories_gitea']}/{$f1}/{$f2}", 'type' => 'git', ); } From e7e29197d5663209d5f464f861ea7052709a2b08 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20B=C3=B6sch-Plepelits?= Date: Thu, 28 Dec 2017 10:29:33 +0100 Subject: [PATCH 20/54] repo.php: rename newestTimestamp(), info() includes timestamp --- repo.php | 2 +- src/RepositoryDir.php | 4 +++- src/RepositoryGit.php | 4 +++- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/repo.php b/repo.php index 7231a38e..18e1d46a 100644 --- a/repo.php +++ b/repo.php @@ -33,7 +33,7 @@ if (!array_key_exists($repoId, $allRepositories)) { $repo = getRepo($repoId, $allRepositories[$repoId]); $cacheDir = null; -$ts = $repo->newestTimestamp($path); +$ts = $repo->timestamp($path); if (isset($config['cache'])) { $cacheDir = "{$config['cache']}/repo"; @mkdir($cacheDir); diff --git a/src/RepositoryDir.php b/src/RepositoryDir.php index bbf74918..e0d19208 100644 --- a/src/RepositoryDir.php +++ b/src/RepositoryDir.php @@ -14,10 +14,12 @@ class RepositoryDir { } } + $ret['timestamp'] = Date(DATE_ISO8601, $this->timestamp()); + return $ret; } - function newestTimestamp () { + function timestamp () { $ts = 0; $d = opendir($this->path); while ($f = readdir($d)) { diff --git a/src/RepositoryGit.php b/src/RepositoryGit.php index fa22857b..07130acf 100644 --- a/src/RepositoryGit.php +++ b/src/RepositoryGit.php @@ -14,10 +14,12 @@ class RepositoryGit { } } + $ret['timestamp'] = Date(DATE_ISO8601, $this->timestamp()); + return $ret; } - function newestTimestamp () { + function timestamp () { $ts = (int)shell_exec("cd " . escapeShellArg($this->path) . "; git log -1 --pretty=format:%ct"); return $ts; From 5814643141ace7d2bd87d63b3b775e44ef76febd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20B=C3=B6sch-Plepelits?= Date: Thu, 28 Dec 2017 10:36:20 +0100 Subject: [PATCH 21/54] repo.php: structure repository result { "timestamp": rfcdate, "categories": { "id": ... } } --- src/OpenStreetBrowserLoader.js | 4 ++-- src/RepositoryDir.php | 7 +++++-- src/RepositoryGit.php | 7 +++++-- src/addCategories.js | 10 ++++++++-- 4 files changed, 20 insertions(+), 8 deletions(-) diff --git a/src/OpenStreetBrowserLoader.js b/src/OpenStreetBrowserLoader.js index 1e1301f1..b8a95db6 100644 --- a/src/OpenStreetBrowserLoader.js +++ b/src/OpenStreetBrowserLoader.js @@ -49,11 +49,11 @@ OpenStreetBrowserLoader.prototype.getCategory = function (id, options, callback) return callback(err, null) } - if (!(categoryId in repoData)) { + if (!(categoryId in repoData.categories)) { return callback(new Error('category not defined'), null) } - this.getCategoryFromData(id, repoData[categoryId], function (err, category) { + this.getCategoryFromData(id, repoData.categories[categoryId], function (err, category) { if (category) { category.setMap(this.map) } diff --git a/src/RepositoryDir.php b/src/RepositoryDir.php index e0d19208..1e436718 100644 --- a/src/RepositoryDir.php +++ b/src/RepositoryDir.php @@ -34,13 +34,16 @@ class RepositoryDir { } function data () { - $data = array(); + $data = array( + 'categories' => array(), + 'timestamp' => Date(DATE_ISO8601, $this->timestamp()), + ); $d = opendir($this->path); while ($f = readdir($d)) { if (preg_match("/^([0-9a-zA-Z_\-]+)\.json$/", $f, $m) && $f !== 'package.json') { $d1 = json_decode(file_get_contents("{$this->path}/{$f}"), true); - $data[$m[1]] = jsonMultilineStringsJoin($d1, array('exclude' => array(array('const')))); + $data['categories'][$m[1]] = jsonMultilineStringsJoin($d1, array('exclude' => array(array('const')))); } } closedir($d); diff --git a/src/RepositoryGit.php b/src/RepositoryGit.php index 07130acf..10f67eac 100644 --- a/src/RepositoryGit.php +++ b/src/RepositoryGit.php @@ -26,7 +26,10 @@ class RepositoryGit { } function data () { - $data = array(); + $data = array( + 'categories' => array(), + 'timestamp' => Date(DATE_ISO8601, $this->timestamp()), + ); $d = popen("cd " . escapeShellArg($this->path) . "; git ls-tree HEAD", "r"); while ($r = fgets($d)) { @@ -39,7 +42,7 @@ class RepositoryGit { } $d1 = json_decode(shell_exec("cd " . escapeShellArg($this->path) . "; git show HEAD:" . escapeShellArg($f)), true); - $data[$id] = jsonMultilineStringsJoin($d1, array('exclude' => array(array('const')))); + $data['categories'][$id] = jsonMultilineStringsJoin($d1, array('exclude' => array(array('const')))); } } pclose($d); diff --git a/src/addCategories.js b/src/addCategories.js index f5882c60..e96b2cb8 100644 --- a/src/addCategories.js +++ b/src/addCategories.js @@ -22,6 +22,8 @@ function addCategoriesShow (repo) { backLink.href = '#' backLink.appendChild(document.createTextNode(lang('back'))) + var list = {} + if (repo) { backLink.onclick = function () { addCategoriesShow() @@ -32,6 +34,8 @@ function addCategoriesShow (repo) { var h = document.createElement('h2') h.appendChild(document.createTextNode(repo)) content.appendChild(h) + + list = repoData.categories } else { backLink.onclick = function () { addCategoriesHide() @@ -42,12 +46,14 @@ function addCategoriesShow (repo) { var h = document.createElement('h2') h.innerHTML = lang('more_categories') content.appendChild(h) + + list = repoData } var ul = document.createElement('ul') - for (var id in repoData) { - var data = repoData[id] + for (var id in list) { + var data = list[id] var li = document.createElement('li') From 8e48595194623dd1a8a3084eeb86cc3ec19ca51e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20B=C3=B6sch-Plepelits?= Date: Thu, 28 Dec 2017 21:07:38 +0100 Subject: [PATCH 22/54] repo.php: don't call getRepositories() twice --- repo.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/repo.php b/repo.php index 18e1d46a..c4079d3a 100644 --- a/repo.php +++ b/repo.php @@ -12,7 +12,7 @@ if (!isset($_REQUEST['repo'])) { print '{'; $c = 0; - foreach (getRepositories() as $repoId => $repoData) { + foreach ($allRepositories as $repoId => $repoData) { $repo = getRepo($repoId, $repoData); print $c++ ? ',' : ''; From ca51637002449a650ff8e78bd801bce80ae3f4ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20B=C3=B6sch-Plepelits?= Date: Thu, 28 Dec 2017 21:08:14 +0100 Subject: [PATCH 23/54] repo.php/addCategories: repositoryUrl and categoryUrl --- conf.php-dist | 7 +++++++ repo.php | 21 +++++++++++++++++++-- src/addCategories.js | 35 ++++++++++++++++++++++++----------- src/repositories.php | 2 ++ 4 files changed, 52 insertions(+), 13 deletions(-) diff --git a/conf.php-dist b/conf.php-dist index 3d59670c..0e28a591 100644 --- a/conf.php-dist +++ b/conf.php-dist @@ -1,9 +1,16 @@ array( 'path' => 'node_modules/openstreetbrowser-categories-main', 'type' => 'dir', + // public URL of repository + 'repositoryUrl' => 'https://github.com/example/categories', + // public URL of source of a category in repository + 'categoryUrl' => 'https://github.com/example/categories/tree/master/{{ categoryId }}.json', ), ); diff --git a/repo.php b/repo.php index c4079d3a..2bbec439 100644 --- a/repo.php +++ b/repo.php @@ -17,7 +17,16 @@ if (!isset($_REQUEST['repo'])) { print $c++ ? ',' : ''; print json_encode($repoId, JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES) . ':'; - print json_encode($repo->info(), JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES|JSON_FORCE_OBJECT); + $info = $repo->info(); + + if (isset($repoData['repositoryUrl'])) { + $info['repositoryUrl'] = $repoData['repositoryUrl']; + } + if (isset($repoData['categoryUrl'])) { + $info['categoryUrl'] = $repoData['categoryUrl']; + } + + print json_encode($info, JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES|JSON_FORCE_OBJECT); } print '}'; @@ -30,7 +39,8 @@ if (!array_key_exists($repoId, $allRepositories)) { exit(0); } -$repo = getRepo($repoId, $allRepositories[$repoId]); +$repoData = $allRepositories[$repoId]; +$repo = getRepo($repoId, $repoData); $cacheDir = null; $ts = $repo->timestamp($path); @@ -47,6 +57,13 @@ if (isset($config['cache'])) { $data = $repo->data(); +if (isset($repoData['repositoryUrl'])) { + $data['repositoryUrl'] = $repoData['repositoryUrl']; +} +if (isset($repoData['categoryUrl'])) { + $data['categoryUrl'] = $repoData['categoryUrl']; +} + $ret = json_encode($data, JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES); Header("Content-Type: application/json; charset=utf-8"); diff --git a/src/addCategories.js b/src/addCategories.js index e96b2cb8..14509979 100644 --- a/src/addCategories.js +++ b/src/addCategories.js @@ -22,6 +22,11 @@ function addCategoriesShow (repo) { backLink.href = '#' backLink.appendChild(document.createTextNode(lang('back'))) + var categoryUrl = null + if (repoData.categoryUrl) { + categoryUrl = OverpassLayer.twig.twig({ data: repoData.categoryUrl, autoescape: true }) + } + var list = {} if (repo) { @@ -55,6 +60,11 @@ function addCategoriesShow (repo) { for (var id in list) { var data = list[id] + var repositoryUrl = null + if (data.repositoryUrl) { + repositoryUrl = OverpassLayer.twig.twig({ data: data.repositoryUrl, autoescape: true }) + } + var li = document.createElement('li') var a = document.createElement('a') @@ -74,17 +84,20 @@ function addCategoriesShow (repo) { li.appendChild(a) a.appendChild(document.createTextNode('name' in data ? lang(data.name) : id)) - if (config.urlCategoriesEditor) { - a = document.createElement('a') - if (repo) { - a.href = config.urlCategoriesEditor + '?id=' + repo + '/' + id - } else { - a.href = config.urlCategoriesEditor + '?repo=' + id - } - a.target = '_blank' - a.innerHTML = '' - li.appendChild(a) - } + var editLink = null + if (repo && categoryUrl) { + editLink = document.createElement('a') + editLink.href = categoryUrl.render({ repositoryId: repo, categoryId: id }) + } + if (!repo && repositoryUrl) { + editLink = document.createElement('a') + editLink.href = repositoryUrl.render({ repositoryId: id }) + } + if (editLink) { + editLink.target = '_blank' + editLink.innerHTML = '' + li.appendChild(editLink) + } ul.appendChild(li) } diff --git a/src/repositories.php b/src/repositories.php index aea8c1c4..b9a8ffa8 100644 --- a/src/repositories.php +++ b/src/repositories.php @@ -26,6 +26,8 @@ function getRepositories () { $repositories["{$f1}/{$f2id}"] = array( 'path' => "{$config['repositories_gitea']}/{$f1}/{$f2}", 'type' => 'git', + 'repositoryUrl' => 'https://www.openstreetbrowser.org/dev/{{ repositoryId }}', + 'categoryUrl' => 'https://www.openstreetbrowser.org/dev/{{ repositoryId }}/src/{{ categoryId }}.json', ); } } From 4997dd55de495b33a131f1c47236278dc418aea3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20B=C3=B6sch-Plepelits?= Date: Thu, 28 Dec 2017 21:26:28 +0100 Subject: [PATCH 24/54] Repository: split common code to RepositoryBase --- modulekit.php | 1 + src/RepositoryBase.php | 32 ++++++++++++++++++++++++++++++++ src/RepositoryDir.php | 26 ++------------------------ src/RepositoryGit.php | 26 ++------------------------ 4 files changed, 37 insertions(+), 48 deletions(-) create mode 100644 src/RepositoryBase.php diff --git a/modulekit.php b/modulekit.php index 52af002a..168eb2e7 100644 --- a/modulekit.php +++ b/modulekit.php @@ -16,6 +16,7 @@ $include = array( 'src/ip-location.php', 'src/wikipedia.php', 'src/ImageLoader.php', + 'src/RepositoryBase.php', 'src/RepositoryDir.php', 'src/RepositoryGit.php', 'src/repositories.php', diff --git a/src/RepositoryBase.php b/src/RepositoryBase.php new file mode 100644 index 00000000..1ec18876 --- /dev/null +++ b/src/RepositoryBase.php @@ -0,0 +1,32 @@ +def = $def; + $this->path = $def['path']; + } + + function timestamp () { + return null; + } + + function info () { + $ret = array(); + + foreach (array('name') as $k) { + if (array_key_exists($k, $this->def)) { + $ret[$k] = $this->def[$k]; + } + } + + $ret['timestamp'] = Date(DATE_ISO8601, $this->timestamp()); + + return $ret; + } + + function data () { + $data = array( + 'categories' => array(), + 'timestamp' => Date(DATE_ISO8601, $this->timestamp()), + ); + } +} diff --git a/src/RepositoryDir.php b/src/RepositoryDir.php index 1e436718..afda1937 100644 --- a/src/RepositoryDir.php +++ b/src/RepositoryDir.php @@ -1,24 +1,5 @@ def = $def; - $this->path = $def['path']; - } - - function info () { - $ret = array(); - - foreach (array('name') as $k) { - if (array_key_exists($k, $this->def)) { - $ret[$k] = $this->def[$k]; - } - } - - $ret['timestamp'] = Date(DATE_ISO8601, $this->timestamp()); - - return $ret; - } - +class RepositoryDir extends RepositoryBase { function timestamp () { $ts = 0; $d = opendir($this->path); @@ -34,10 +15,7 @@ class RepositoryDir { } function data () { - $data = array( - 'categories' => array(), - 'timestamp' => Date(DATE_ISO8601, $this->timestamp()), - ); + $data = parent::data(); $d = opendir($this->path); while ($f = readdir($d)) { diff --git a/src/RepositoryGit.php b/src/RepositoryGit.php index 10f67eac..3d4f0f70 100644 --- a/src/RepositoryGit.php +++ b/src/RepositoryGit.php @@ -1,24 +1,5 @@ def = $def; - $this->path = $def['path']; - } - - function info () { - $ret = array(); - - foreach (array('name') as $k) { - if (array_key_exists($k, $this->def)) { - $ret[$k] = $this->def[$k]; - } - } - - $ret['timestamp'] = Date(DATE_ISO8601, $this->timestamp()); - - return $ret; - } - +class RepositoryGit extends RepositoryBase { function timestamp () { $ts = (int)shell_exec("cd " . escapeShellArg($this->path) . "; git log -1 --pretty=format:%ct"); @@ -26,10 +7,7 @@ class RepositoryGit { } function data () { - $data = array( - 'categories' => array(), - 'timestamp' => Date(DATE_ISO8601, $this->timestamp()), - ); + $data = parent::data(); $d = popen("cd " . escapeShellArg($this->path) . "; git ls-tree HEAD", "r"); while ($r = fgets($d)) { From 746e1093d9956f12a706e1e2402688e23d4fd578 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20B=C3=B6sch-Plepelits?= Date: Thu, 28 Dec 2017 21:31:17 +0100 Subject: [PATCH 25/54] Repository: exclude json files which are not categories --- src/RepositoryBase.php | 8 ++++++++ src/RepositoryDir.php | 5 +++++ src/RepositoryGit.php | 5 +++++ 3 files changed, 18 insertions(+) diff --git a/src/RepositoryBase.php b/src/RepositoryBase.php index 1ec18876..39236088 100644 --- a/src/RepositoryBase.php +++ b/src/RepositoryBase.php @@ -29,4 +29,12 @@ class RepositoryBase { 'timestamp' => Date(DATE_ISO8601, $this->timestamp()), ); } + + function isCategory ($data) { + if (!array_key_exists('type', $data)) { + return false; + } + + return in_array($data['type'], array('index', 'overpass')); + } } diff --git a/src/RepositoryDir.php b/src/RepositoryDir.php index afda1937..057cfc2b 100644 --- a/src/RepositoryDir.php +++ b/src/RepositoryDir.php @@ -21,6 +21,11 @@ class RepositoryDir extends RepositoryBase { while ($f = readdir($d)) { if (preg_match("/^([0-9a-zA-Z_\-]+)\.json$/", $f, $m) && $f !== 'package.json') { $d1 = json_decode(file_get_contents("{$this->path}/{$f}"), true); + + if (!$this->isCategory($d1)) { + continue; + } + $data['categories'][$m[1]] = jsonMultilineStringsJoin($d1, array('exclude' => array(array('const')))); } } diff --git a/src/RepositoryGit.php b/src/RepositoryGit.php index 3d4f0f70..d6095449 100644 --- a/src/RepositoryGit.php +++ b/src/RepositoryGit.php @@ -20,6 +20,11 @@ class RepositoryGit extends RepositoryBase { } $d1 = json_decode(shell_exec("cd " . escapeShellArg($this->path) . "; git show HEAD:" . escapeShellArg($f)), true); + + if (!$this->isCategory($d1)) { + continue; + } + $data['categories'][$id] = jsonMultilineStringsJoin($d1, array('exclude' => array(array('const')))); } } From 7a5dd983960172948de93630386456d4a763fad7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20B=C3=B6sch-Plepelits?= Date: Thu, 28 Dec 2017 21:39:42 +0100 Subject: [PATCH 26/54] fix --- src/RepositoryBase.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/RepositoryBase.php b/src/RepositoryBase.php index 39236088..f5ed87b7 100644 --- a/src/RepositoryBase.php +++ b/src/RepositoryBase.php @@ -28,6 +28,8 @@ class RepositoryBase { 'categories' => array(), 'timestamp' => Date(DATE_ISO8601, $this->timestamp()), ); + + return $data; } function isCategory ($data) { From ceba05da229600cd2f04f40cac11f855c29988d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20B=C3=B6sch-Plepelits?= Date: Thu, 28 Dec 2017 21:39:53 +0100 Subject: [PATCH 27/54] Repositories: include templates --- src/RepositoryBase.php | 1 + src/RepositoryDir.php | 4 ++++ src/RepositoryGit.php | 4 ++++ 3 files changed, 9 insertions(+) diff --git a/src/RepositoryBase.php b/src/RepositoryBase.php index f5ed87b7..f5f666f5 100644 --- a/src/RepositoryBase.php +++ b/src/RepositoryBase.php @@ -26,6 +26,7 @@ class RepositoryBase { function data () { $data = array( 'categories' => array(), + 'templates' => array(), 'timestamp' => Date(DATE_ISO8601, $this->timestamp()), ); diff --git a/src/RepositoryDir.php b/src/RepositoryDir.php index 057cfc2b..c0d6c313 100644 --- a/src/RepositoryDir.php +++ b/src/RepositoryDir.php @@ -28,6 +28,10 @@ class RepositoryDir extends RepositoryBase { $data['categories'][$m[1]] = jsonMultilineStringsJoin($d1, array('exclude' => array(array('const')))); } + + if (preg_match("/^(detailsBody|popupBody).html$/", $f, $m)) { + $data['templates'][$m[1]] = file_get_contents("{$this->path}/{$f}"); + } } closedir($d); diff --git a/src/RepositoryGit.php b/src/RepositoryGit.php index d6095449..45dc463a 100644 --- a/src/RepositoryGit.php +++ b/src/RepositoryGit.php @@ -27,6 +27,10 @@ class RepositoryGit extends RepositoryBase { $data['categories'][$id] = jsonMultilineStringsJoin($d1, array('exclude' => array(array('const')))); } + + if (preg_match("/^[0-9]{6} blob [0-9a-f]{40}\t((detailsBody|popupBody)\.html)$/", $r, $m)) { + $data['templates'][$m[2]] = shell_exec("cd " . escapeShellArg($this->path) . "; git show HEAD:" . escapeShellArg($m[1])); + } } pclose($d); From 5dd387921d35c796eee2fec2379d57ce6b910469 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20B=C3=B6sch-Plepelits?= Date: Thu, 28 Dec 2017 21:52:39 +0100 Subject: [PATCH 28/54] OpenStreetBrowserLoader: load templates from repositories --- src/OpenStreetBrowserLoader.js | 45 ++++++++++++++++++---------------- 1 file changed, 24 insertions(+), 21 deletions(-) diff --git a/src/OpenStreetBrowserLoader.js b/src/OpenStreetBrowserLoader.js index b8a95db6..b6be4f9b 100644 --- a/src/OpenStreetBrowserLoader.js +++ b/src/OpenStreetBrowserLoader.js @@ -120,37 +120,40 @@ OpenStreetBrowserLoader.prototype.getTemplate = function (id, options, callback) options = {} } - if (id in this.templates) { - callback.apply(this, this.templates[id]) - return + var repo + var templateId + var m + if (m = id.match(/^(.*)\/([^\/]*)/)) { + repo = m[1] + templateId = m[2] + } else { + repo = 'default' + templateId = id } - if (id in this._loadClash) { - this._loadClash[id].push(callback) + if (id in this.templates) { + callback.apply(this, this.templates[id]) return } - this._loadClash[id] = [] + this.getRepo(repo, options, function (err, repoData) { + // maybe loaded in the meantime? + if (id in this.templates) { + return callback(null, this.templates[id]) + } - function reqListener (req) { - if (req.status !== 200) { - console.log(req) - this.templates[id] = [ req.statusText, null ] - } else { - this.templates[id] = [ null, OverpassLayer.twig.twig({ data: req.responseText, autoescape: true }) ] + if (err) { + return callback(err, null) } - callback.apply(this, this.templates[id]) + if (!repoData.templates || !(templateId in repoData.templates)) { + return callback(new Error('template not defined'), null) + } - this._loadClash[id].forEach(function (c) { - c.apply(this, this.templates[id]) - }.bind(this)) - } + this.templates[id] = OverpassLayer.twig.twig({ data: repoData.templates[templateId], autoescape: true }) - var req = new XMLHttpRequest() - req.addEventListener('load', reqListener.bind(this, req)) - req.open('GET', config.categoriesDir + '/' + id + '.html?' + config.categoriesRev) - req.send() + callback(null, this.templates[id]) + }.bind(this)) } OpenStreetBrowserLoader.prototype.getCategoryFromData = function (id, data, callback) { From 2b3bfb0af728edd7c569f10c494c035a9085d670 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20B=C3=B6sch-Plepelits?= Date: Thu, 28 Dec 2017 22:09:45 +0100 Subject: [PATCH 29/54] Prepare passing options to Categories --- src/CategoryBase.js | 11 +++++++-- src/CategoryIndex.js | 8 +++---- src/CategoryOverpass.js | 8 +++---- src/OpenStreetBrowserLoader.js | 43 +++++++++++++++++++++------------- 4 files changed, 44 insertions(+), 26 deletions(-) diff --git a/src/CategoryBase.js b/src/CategoryBase.js index da6639e3..2c34d64b 100644 --- a/src/CategoryBase.js +++ b/src/CategoryBase.js @@ -2,8 +2,15 @@ var OpenStreetBrowserLoader = require('./OpenStreetBrowserLoader') var tabs = require('modulekit-tabs') -function CategoryBase (id, data) { - this.id = id +function CategoryBase (options, data) { + if (typeof options === 'string') { + this.id = options + this.options = {} + } + else { + this.id = options.id + this.options = options + } this.parentCategory = null this.childrenLoadingCount = 0 this.data = data diff --git a/src/CategoryIndex.js b/src/CategoryIndex.js index 47f7d712..dce04d03 100644 --- a/src/CategoryIndex.js +++ b/src/CategoryIndex.js @@ -5,8 +5,8 @@ var CategoryBase = require('./CategoryBase') CategoryIndex.prototype = Object.create(CategoryBase.prototype) CategoryIndex.prototype.constructor = CategoryIndex -function CategoryIndex (id, data) { - CategoryBase.call(this, id, data) +function CategoryIndex (options, data) { + CategoryBase.call(this, options, data) this.childrenDoms = {} this.childrenCategories = null @@ -51,9 +51,9 @@ CategoryIndex.prototype._loadChildrenCategories = function (callback) { this.childrenCategories[data.id] = null if ('type' in data) { - OpenStreetBrowserLoader.getCategoryFromData(data.id, data, this._loadChildCategory.bind(this, callback)) + OpenStreetBrowserLoader.getCategoryFromData(data.id, this.options, data, this._loadChildCategory.bind(this, callback)) } else { - OpenStreetBrowserLoader.getCategory(data.id, this._loadChildCategory.bind(this, callback)) + OpenStreetBrowserLoader.getCategory(data.id, this.options, this._loadChildCategory.bind(this, callback)) } }.bind(this), function (err) { diff --git a/src/CategoryOverpass.js b/src/CategoryOverpass.js index 86c8f8fa..9d8a8800 100644 --- a/src/CategoryOverpass.js +++ b/src/CategoryOverpass.js @@ -26,10 +26,10 @@ var defaultValues = { CategoryOverpass.prototype = Object.create(CategoryBase.prototype) CategoryOverpass.prototype.constructor = CategoryOverpass -function CategoryOverpass (id, data) { +function CategoryOverpass (options, data) { var p - CategoryBase.call(this, id, data) + CategoryBase.call(this, options, data) data.id = this.id @@ -155,7 +155,7 @@ function CategoryOverpass (id, data) { } CategoryOverpass.prototype.load = function (callback) { - OpenStreetBrowserLoader.getTemplate('popupBody', function (err, template) { + OpenStreetBrowserLoader.getTemplate('popupBody', this.options, function (err, template) { if (err) { console.log("can't load popupBody.html") } else { @@ -323,7 +323,7 @@ CategoryOverpass.prototype.updatePopupContent = function (object, popup) { } CategoryOverpass.prototype.renderTemplate = function (object, templateId, callback) { - OpenStreetBrowserLoader.getTemplate(templateId, function (err, template) { + OpenStreetBrowserLoader.getTemplate(templateId, this.options, function (err, template) { if (err) { err = "can't load " + templateId + ': ' + err return callback(err, null) diff --git a/src/OpenStreetBrowserLoader.js b/src/OpenStreetBrowserLoader.js index b6be4f9b..43ad8393 100644 --- a/src/OpenStreetBrowserLoader.js +++ b/src/OpenStreetBrowserLoader.js @@ -31,18 +31,23 @@ OpenStreetBrowserLoader.prototype.getCategory = function (id, options, callback) repo = m[1] categoryId = m[2] } else { - repo = 'default' + repo = options.repositoryId || 'default' categoryId = id } + var fullId = repo + '/' + categoryId - if (id in this.categories) { - return callback(null, this.categories[id]) + if (fullId in this.categories) { + return callback(null, this.categories[fullId]) } - this.getRepo(repo, options, function (err, repoData) { + var opt = JSON.parse(JSON.stringify(options)) + opt.categoryId = categoryId + opt.repositoryId = repo + + this.getRepo(repo, opt, function (err, repoData) { // maybe loaded in the meantime? - if (id in this.categories) { - return callback(null, this.categories[id]) + if (fullId in this.categories) { + return callback(null, this.categories[fullId]) } if (err) { @@ -53,7 +58,7 @@ OpenStreetBrowserLoader.prototype.getCategory = function (id, options, callback) return callback(new Error('category not defined'), null) } - this.getCategoryFromData(id, repoData.categories[categoryId], function (err, category) { + this.getCategoryFromData(id, opt, repoData.categories[categoryId], function (err, category) { if (category) { category.setMap(this.map) } @@ -127,19 +132,23 @@ OpenStreetBrowserLoader.prototype.getTemplate = function (id, options, callback) repo = m[1] templateId = m[2] } else { - repo = 'default' + repo = options.repositoryId || 'default' templateId = id } + var fullId = repo + '/' + templateId - if (id in this.templates) { - callback.apply(this, this.templates[id]) - return + if (fullId in this.templates) { + return callback(null, this.templates[fullId]) } - this.getRepo(repo, options, function (err, repoData) { + var opt = JSON.parse(JSON.stringify(options)) + opt.templateId = templateId + opt.repositoryId = repo + + this.getRepo(repo, opt, function (err, repoData) { // maybe loaded in the meantime? - if (id in this.templates) { - return callback(null, this.templates[id]) + if (fullId in this.templates) { + return callback(null, this.templates[fullId]) } if (err) { @@ -156,7 +165,7 @@ OpenStreetBrowserLoader.prototype.getTemplate = function (id, options, callback) }.bind(this)) } -OpenStreetBrowserLoader.prototype.getCategoryFromData = function (id, data, callback) { +OpenStreetBrowserLoader.prototype.getCategoryFromData = function (id, options, data, callback) { if (id in this.categories) { callback(null, this.categories[id]) return @@ -170,7 +179,9 @@ OpenStreetBrowserLoader.prototype.getCategoryFromData = function (id, data, call return callback(new Error('unknown type'), null) } - var layer = new this.types[data.type](id, data) + var opt = JSON.parse(JSON.stringify(options)) + opt.id = id + var layer = new this.types[data.type](opt, data) layer.setMap(this.map) From 8b9f9f06b302e4111d1d8c5cefb20d99b7b65f07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20B=C3=B6sch-Plepelits?= Date: Thu, 28 Dec 2017 22:40:09 +0100 Subject: [PATCH 30/54] OpenStreetBrowserLoader: read repository from options, if set --- src/OpenStreetBrowserLoader.js | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/src/OpenStreetBrowserLoader.js b/src/OpenStreetBrowserLoader.js index 43ad8393..9852dad5 100644 --- a/src/OpenStreetBrowserLoader.js +++ b/src/OpenStreetBrowserLoader.js @@ -30,8 +30,12 @@ OpenStreetBrowserLoader.prototype.getCategory = function (id, options, callback) if (m = id.match(/^(.*)\/([^\/]*)/)) { repo = m[1] categoryId = m[2] + } else if (options.repositoryId && options.repositoryId !== 'default') { + repo = options.repositoryId + categoryId = id + id = repo + '/' + id } else { - repo = options.repositoryId || 'default' + repo = 'default' categoryId = id } var fullId = repo + '/' + categoryId @@ -131,6 +135,10 @@ OpenStreetBrowserLoader.prototype.getTemplate = function (id, options, callback) if (m = id.match(/^(.*)\/([^\/]*)/)) { repo = m[1] templateId = m[2] + } else if (options.repositoryId && options.repositoryId !== 'default') { + repo = options.repositoryId + templateId = id + id = repo + '/' + id } else { repo = options.repositoryId || 'default' templateId = id @@ -166,9 +174,24 @@ OpenStreetBrowserLoader.prototype.getTemplate = function (id, options, callback) } OpenStreetBrowserLoader.prototype.getCategoryFromData = function (id, options, data, callback) { - if (id in this.categories) { - callback(null, this.categories[id]) - return + var repo + var categoryId + var m + if (m = id.match(/^(.*)\/([^\/]*)/)) { + repo = m[1] + categoryId = m[2] + } else if (options.repositoryId && options.repositoryId !== 'default') { + repo = options.repositoryId + categoryId = id + id = repo + '/' + id + } else { + repo = 'default' + categoryId = id + } + var fullId = repo + '/' + categoryId + + if (fullId in this.categories) { + return callback(null, this.categories[fullId]) } if (!data.type) { From c8a79a9724654ca0f26ad0eae0897b8f5d24591a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20B=C3=B6sch-Plepelits?= Date: Thu, 28 Dec 2017 22:40:52 +0100 Subject: [PATCH 31/54] fix base --- src/CategoryBase.js | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/src/CategoryBase.js b/src/CategoryBase.js index 2c34d64b..7f9b591f 100644 --- a/src/CategoryBase.js +++ b/src/CategoryBase.js @@ -20,12 +20,6 @@ function CategoryBase (options, data) { var name var a - this.repoId = null - var m - if (m = this.id.match(/^(.+)\/([^\/]+)$/)) { - this.repoId = m[1] - } - if (this.id !== 'index') { var domHeader = document.createElement('header') this.dom.appendChild(domHeader) @@ -48,10 +42,10 @@ function CategoryBase (options, data) { a.onclick = this.toggle.bind(this) domHeader.appendChild(a) - if (this.repoId) { + if (this.options.repositoryId !== 'default') { a = document.createElement('span') a.className = 'repoId' - a.appendChild(document.createTextNode(this.repoId)) + a.appendChild(document.createTextNode(this.options.repositoryId)) domHeader.appendChild(a) } From 91f958ae02b671a789b85dc30e3b041a31de5f35 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20B=C3=B6sch-Plepelits?= Date: Thu, 28 Dec 2017 22:41:09 +0100 Subject: [PATCH 32/54] CategoryIndex: load sub categories from same repository --- src/CategoryIndex.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/CategoryIndex.js b/src/CategoryIndex.js index dce04d03..dc2d0828 100644 --- a/src/CategoryIndex.js +++ b/src/CategoryIndex.js @@ -51,9 +51,9 @@ CategoryIndex.prototype._loadChildrenCategories = function (callback) { this.childrenCategories[data.id] = null if ('type' in data) { - OpenStreetBrowserLoader.getCategoryFromData(data.id, this.options, data, this._loadChildCategory.bind(this, callback)) + OpenStreetBrowserLoader.getCategoryFromData(data.id, this.options, data, this._loadChildCategory.bind(this, data.id, callback)) } else { - OpenStreetBrowserLoader.getCategory(data.id, this.options, this._loadChildCategory.bind(this, callback)) + OpenStreetBrowserLoader.getCategory(data.id, this.options, this._loadChildCategory.bind(this, data.id, callback)) } }.bind(this), function (err) { @@ -64,15 +64,15 @@ CategoryIndex.prototype._loadChildrenCategories = function (callback) { ) } -CategoryIndex.prototype._loadChildCategory = function (callback, err, category) { +CategoryIndex.prototype._loadChildCategory = function (id, callback, err, category) { if (err) { return callback(err) } - this.childrenCategories[category.id] = category + this.childrenCategories[id] = category category.setParent(this) - category.setParentDom(this.childrenDoms[category.id]) + category.setParentDom(this.childrenDoms[id]) callback(err, category) } From 923580378d4927d955f1e56b4a44eccc7dc549d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20B=C3=B6sch-Plepelits?= Date: Sat, 30 Dec 2017 11:45:52 +0100 Subject: [PATCH 33/54] OpenStreetBrowserLoader: fix cache --- src/OpenStreetBrowserLoader.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/OpenStreetBrowserLoader.js b/src/OpenStreetBrowserLoader.js index 9852dad5..a44f676a 100644 --- a/src/OpenStreetBrowserLoader.js +++ b/src/OpenStreetBrowserLoader.js @@ -167,9 +167,9 @@ OpenStreetBrowserLoader.prototype.getTemplate = function (id, options, callback) return callback(new Error('template not defined'), null) } - this.templates[id] = OverpassLayer.twig.twig({ data: repoData.templates[templateId], autoescape: true }) + this.templates[fullId] = OverpassLayer.twig.twig({ data: repoData.templates[templateId], autoescape: true }) - callback(null, this.templates[id]) + callback(null, this.templates[fullId]) }.bind(this)) } @@ -208,7 +208,7 @@ OpenStreetBrowserLoader.prototype.getCategoryFromData = function (id, options, d layer.setMap(this.map) - this.categories[id] = layer + this.categories[fullId] = layer if ('load' in layer) { layer.load(function (err) { From 9d7d2d305339982cc992b40e71793ef30e3b46ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20B=C3=B6sch-Plepelits?= Date: Sat, 30 Dec 2017 11:58:32 +0100 Subject: [PATCH 34/54] OpenStreetBrowserLoader: unify code for id resolving --- src/OpenStreetBrowserLoader.js | 117 ++++++++++++++------------------- 1 file changed, 49 insertions(+), 68 deletions(-) diff --git a/src/OpenStreetBrowserLoader.js b/src/OpenStreetBrowserLoader.js index a44f676a..a803b442 100644 --- a/src/OpenStreetBrowserLoader.js +++ b/src/OpenStreetBrowserLoader.js @@ -24,45 +24,31 @@ OpenStreetBrowserLoader.prototype.getCategory = function (id, options, callback) options = {} } - var repo - var categoryId - var m - if (m = id.match(/^(.*)\/([^\/]*)/)) { - repo = m[1] - categoryId = m[2] - } else if (options.repositoryId && options.repositoryId !== 'default') { - repo = options.repositoryId - categoryId = id - id = repo + '/' + id - } else { - repo = 'default' - categoryId = id - } - var fullId = repo + '/' + categoryId + var ids = this.getFullId(id, options) - if (fullId in this.categories) { - return callback(null, this.categories[fullId]) + if (ids.fullId in this.categories) { + return callback(null, this.categories[ids.fullId]) } var opt = JSON.parse(JSON.stringify(options)) - opt.categoryId = categoryId - opt.repositoryId = repo + opt.categoryId = ids.entityId + opt.repositoryId = ids.repositoryId - this.getRepo(repo, opt, function (err, repoData) { + this.getRepo(ids.repositoryId, opt, function (err, repoData) { // maybe loaded in the meantime? - if (fullId in this.categories) { - return callback(null, this.categories[fullId]) + if (ids.fullId in this.categories) { + return callback(null, this.categories[ids.fullId]) } if (err) { return callback(err, null) } - if (!(categoryId in repoData.categories)) { + if (!(ids.entityId in repoData.categories)) { return callback(new Error('category not defined'), null) } - this.getCategoryFromData(id, opt, repoData.categories[categoryId], function (err, category) { + this.getCategoryFromData(ids.id, opt, repoData.categories[ids.entityId], function (err, category) { if (category) { category.setMap(this.map) } @@ -129,69 +115,41 @@ OpenStreetBrowserLoader.prototype.getTemplate = function (id, options, callback) options = {} } - var repo - var templateId - var m - if (m = id.match(/^(.*)\/([^\/]*)/)) { - repo = m[1] - templateId = m[2] - } else if (options.repositoryId && options.repositoryId !== 'default') { - repo = options.repositoryId - templateId = id - id = repo + '/' + id - } else { - repo = options.repositoryId || 'default' - templateId = id - } - var fullId = repo + '/' + templateId + var ids = this.getFullId(id, options) - if (fullId in this.templates) { - return callback(null, this.templates[fullId]) + if (ids.fullId in this.templates) { + return callback(null, this.templates[ids.fullId]) } var opt = JSON.parse(JSON.stringify(options)) - opt.templateId = templateId - opt.repositoryId = repo + opt.templateId = ids.entityId + opt.repositoryId = ids.repositoryId - this.getRepo(repo, opt, function (err, repoData) { + this.getRepo(ids.repositoryId, opt, function (err, repoData) { // maybe loaded in the meantime? - if (fullId in this.templates) { - return callback(null, this.templates[fullId]) + if (ids.fullId in this.templates) { + return callback(null, this.templates[ids.fullId]) } if (err) { return callback(err, null) } - if (!repoData.templates || !(templateId in repoData.templates)) { + if (!repoData.templates || !(ids.entityId in repoData.templates)) { return callback(new Error('template not defined'), null) } - this.templates[fullId] = OverpassLayer.twig.twig({ data: repoData.templates[templateId], autoescape: true }) + this.templates[ids.fullId] = OverpassLayer.twig.twig({ data: repoData.templates[ids.entityId], autoescape: true }) - callback(null, this.templates[fullId]) + callback(null, this.templates[ids.fullId]) }.bind(this)) } OpenStreetBrowserLoader.prototype.getCategoryFromData = function (id, options, data, callback) { - var repo - var categoryId - var m - if (m = id.match(/^(.*)\/([^\/]*)/)) { - repo = m[1] - categoryId = m[2] - } else if (options.repositoryId && options.repositoryId !== 'default') { - repo = options.repositoryId - categoryId = id - id = repo + '/' + id - } else { - repo = 'default' - categoryId = id - } - var fullId = repo + '/' + categoryId + var ids = this.getFullId(id, options) - if (fullId in this.categories) { - return callback(null, this.categories[fullId]) + if (ids.fullId in this.categories) { + return callback(null, this.categories[ids.fullId]) } if (!data.type) { @@ -203,12 +161,12 @@ OpenStreetBrowserLoader.prototype.getCategoryFromData = function (id, options, d } var opt = JSON.parse(JSON.stringify(options)) - opt.id = id + opt.id = ids.id var layer = new this.types[data.type](opt, data) layer.setMap(this.map) - this.categories[fullId] = layer + this.categories[ids.fullId] = layer if ('load' in layer) { layer.load(function (err) { @@ -219,6 +177,29 @@ OpenStreetBrowserLoader.prototype.getCategoryFromData = function (id, options, d } } +OpenStreetBrowserLoader.prototype.getFullId = function (id, options) { + var result = {} + + var m + if (m = id.match(/^(.*)\/([^\/]*)/)) { + result.id = id + result.repositoryId = m[1] + result.entityId = m[2] + } else if (options.repositoryId && options.repositoryId !== 'default') { + result.repositoryId = options.repositoryId + result.entityId = id + result.id = result.repositoryId + '/' + id + } else { + result.id = id + result.repositoryId = 'default' + result.entityId = id + } + + result.fullId = result.repositoryId + '/' + result.entityId + + return result +} + OpenStreetBrowserLoader.prototype.forget = function (id) { this.categories[id].remove() delete this.categories[id] From ae1da77812bf44cb107241beb84b78508090ad22 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20B=C3=B6sch-Plepelits?= Date: Sat, 30 Dec 2017 15:07:27 +0100 Subject: [PATCH 35/54] Unify link style --- src/category.css | 8 -------- style.css | 15 ++++++++------- 2 files changed, 8 insertions(+), 15 deletions(-) diff --git a/src/category.css b/src/category.css index 5cfb4c1a..ff922678 100644 --- a/src/category.css +++ b/src/category.css @@ -75,14 +75,6 @@ line-height: 10px; color: #7f7f7f; } -.category header > a { - text-decoration: none; - color: black; -} -.category header > a:active, -.category header > a:hover { - text-decoration: underline; -} .category header > a.reload { float: right; } diff --git a/style.css b/style.css index 0b806643..3fab58f5 100644 --- a/style.css +++ b/style.css @@ -8,6 +8,14 @@ body { font-size: 11px; color:#333; } +a { + text-decoration: none; + color: black; +} +a:hover, +a:active { + text-decoration: underline; +} #sidebar { top: 0px; @@ -116,13 +124,6 @@ a.showDetails { #menu li { display: inline-block; } -#menu a { - text-decoration: none; - color: black; -} -#menu a:hover { - text-decoration: underline; -} #menu li::after { content: ' |'; } From a62837bae4873c4b71920a9b15cd315114a2b314 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20B=C3=B6sch-Plepelits?= Date: Sat, 30 Dec 2017 15:13:30 +0100 Subject: [PATCH 36/54] addCategories: improve styling --- src/addCategories.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/addCategories.js b/src/addCategories.js index 14509979..8573d573 100644 --- a/src/addCategories.js +++ b/src/addCategories.js @@ -20,6 +20,7 @@ function addCategoriesShow (repo) { var backLink = document.createElement('a') backLink.className = 'back' backLink.href = '#' + backLink.innerHTML = ' ' backLink.appendChild(document.createTextNode(lang('back'))) var categoryUrl = null @@ -94,8 +95,11 @@ function addCategoriesShow (repo) { editLink.href = repositoryUrl.render({ repositoryId: id }) } if (editLink) { + editLink.className = 'source-code' + editLink.title = 'Show source code' editLink.target = '_blank' - editLink.innerHTML = '' + editLink.innerHTML = '' + li.appendChild(document.createTextNode(' ')) li.appendChild(editLink) } @@ -118,7 +122,7 @@ register_hook('init', function (callback) { addCategoriesShow() return false } - link.innerHTML = lang('more_categories') + link.innerHTML = ' ' + lang('more_categories') document.getElementById('contentList').appendChild(link) }) From 66a91b1f44cd683f7af5ea7578418b4b352f0947 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20B=C3=B6sch-Plepelits?= Date: Tue, 2 Jan 2018 09:13:57 +0100 Subject: [PATCH 37/54] OpenStreetBrowserLoader: improve error handling --- src/OpenStreetBrowserLoader.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/OpenStreetBrowserLoader.js b/src/OpenStreetBrowserLoader.js index a803b442..4b2a89b0 100644 --- a/src/OpenStreetBrowserLoader.js +++ b/src/OpenStreetBrowserLoader.js @@ -77,11 +77,16 @@ OpenStreetBrowserLoader.prototype.getRepo = function (repo, options, callback) { function reqListener (req) { if (req.status !== 200) { - console.log(req) + console.log('http error when loading repository', req) return callback(req.statusText, null) } - this.repoCache[repo] = JSON.parse(req.responseText) + try { + this.repoCache[repo] = JSON.parse(req.responseText) + } catch (err) { + console.log('couldn\'t parse repository', req.responseText) + return callback('couldn\t parse repository', null) + } var todo = this._loadClash[repo] delete this._loadClash[repo] From 7339a6ce9c945a9092429ba8bf73e914bf22913c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20B=C3=B6sch-Plepelits?= Date: Tue, 2 Jan 2018 09:33:36 +0100 Subject: [PATCH 38/54] OpenStreetBrowserLoader.getRepo: remember request result, always call callback --- src/OpenStreetBrowserLoader.js | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/OpenStreetBrowserLoader.js b/src/OpenStreetBrowserLoader.js index 4b2a89b0..99072f4a 100644 --- a/src/OpenStreetBrowserLoader.js +++ b/src/OpenStreetBrowserLoader.js @@ -65,7 +65,7 @@ OpenStreetBrowserLoader.prototype.getCategory = function (id, options, callback) */ OpenStreetBrowserLoader.prototype.getRepo = function (repo, options, callback) { if (repo in this.repoCache) { - return callback(null, this.repoCache[repo]) + return callback.apply(this, this.repoCache[repo]) } if (repo in this._loadClash) { @@ -78,21 +78,21 @@ OpenStreetBrowserLoader.prototype.getRepo = function (repo, options, callback) { function reqListener (req) { if (req.status !== 200) { console.log('http error when loading repository', req) - return callback(req.statusText, null) - } - - try { - this.repoCache[repo] = JSON.parse(req.responseText) - } catch (err) { - console.log('couldn\'t parse repository', req.responseText) - return callback('couldn\t parse repository', null) + this.repoCache[repo] = [ req.statusText, null ] + } else { + try { + this.repoCache[repo] = [ null, JSON.parse(req.responseText) ] + } catch (err) { + console.log('couldn\'t parse repository', req.responseText) + this.repoCache[repo] = [ 'couldn\t parse repository', null ] + } } var todo = this._loadClash[repo] delete this._loadClash[repo] todo.forEach(function (callback) { - callback(null, this.repoCache[repo]) + callback.apply(this, this.repoCache[repo]) }.bind(this)) } From e9f19b122f49a057e3841e8160185a660baa42de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20B=C3=B6sch-Plepelits?= Date: Wed, 3 Jan 2018 10:41:22 +0100 Subject: [PATCH 39/54] Category: don't show repositoryId if not set --- src/CategoryBase.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/CategoryBase.js b/src/CategoryBase.js index 7f9b591f..072638bf 100644 --- a/src/CategoryBase.js +++ b/src/CategoryBase.js @@ -42,7 +42,7 @@ function CategoryBase (options, data) { a.onclick = this.toggle.bind(this) domHeader.appendChild(a) - if (this.options.repositoryId !== 'default') { + if (this.options.repositoryId && this.options.repositoryId !== 'default') { a = document.createElement('span') a.className = 'repoId' a.appendChild(document.createTextNode(this.options.repositoryId)) From 8304df8c84ba5b89f8896fa449101358ea327e9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20B=C3=B6sch-Plepelits?= Date: Sun, 7 Jan 2018 06:33:45 +0100 Subject: [PATCH 40/54] Repositories: scan_dir, file_get_contents, file_put_contents --- src/RepositoryDir.php | 12 ++++++++++++ src/RepositoryGit.php | 19 +++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/src/RepositoryDir.php b/src/RepositoryDir.php index c0d6c313..5ec2d7ee 100644 --- a/src/RepositoryDir.php +++ b/src/RepositoryDir.php @@ -37,4 +37,16 @@ class RepositoryDir extends RepositoryBase { return $data; } + + function scandir($path="") { + return scandir("{$this->path}/{$path}"); + } + + function file_get_contents ($file) { + return file_get_contents("{$this->path}/{$file}"); + } + + function file_put_contents ($file, $content) { + return file_put_contents("{$this->path}/{$file}", $content); + } } diff --git a/src/RepositoryGit.php b/src/RepositoryGit.php index 45dc463a..7058c592 100644 --- a/src/RepositoryGit.php +++ b/src/RepositoryGit.php @@ -36,4 +36,23 @@ class RepositoryGit extends RepositoryBase { return $data; } + + function scandir($path="") { + if ($path !== '' && substr($path, -1) !== '/') { + $path .= '/'; + } + + $d = popen("cd " . escapeShellArg($this->path) . "; git ls-tree HEAD " . escapeShellArg($path), "r"); + $ret = array(); + while ($r = fgets($d)) { + $ret[] = substr($r, 53); + } + pclose($d); + + return $ret; + } + + function file_get_contents ($file) { + return shell_exec("cd " . escapeShellArg($this->path) . "; git show HEAD:" . escapeShellArg($file)); + } } From 572d3b4f8aec243b680088f24b59a82f9d6dae87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20B=C3=B6sch-Plepelits?= Date: Sun, 7 Jan 2018 06:42:42 +0100 Subject: [PATCH 41/54] CategoryOverpass: limit data which is available to rendering info --- src/CategoryOverpass.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/CategoryOverpass.js b/src/CategoryOverpass.js index 9d8a8800..4d9dc6da 100644 --- a/src/CategoryOverpass.js +++ b/src/CategoryOverpass.js @@ -255,8 +255,13 @@ CategoryOverpass.prototype.updateInfo = function () { } global.currentCategory = this - var data = JSON.parse(JSON.stringify(this.data)) - data.map = { zoom: map.getZoom() } + var data = { + layer_id: this.id, + 'const': this.data.const, + } + if (this.map) { + data.map = { zoom: map.getZoom() } + } this.domInfo.innerHTML = this.templateInfo.render(data) global.currentCategory = null } From d609b8498cbb064121efa8bb12132bc5b51ea07c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20B=C3=B6sch-Plepelits?= Date: Sun, 7 Jan 2018 06:34:06 +0100 Subject: [PATCH 42/54] Improve TwigJS documentation --- doc/TwigJS.md | 64 ++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 51 insertions(+), 13 deletions(-) diff --git a/doc/TwigJS.md b/doc/TwigJS.md index bc740b14..2a86392b 100644 --- a/doc/TwigJS.md +++ b/doc/TwigJS.md @@ -1,17 +1,55 @@ +#### Examples +Twig resp. TwigJS is a template language. Example: +```twig +Value of property "test": {{ test }}. +``` + +If-condition: +```twig +{% if test == "foo" %} +It's foo! +{% elseif test == "bar" %} +It's bar! +{% else %} +Other value: {{ test }} +{% endif %} +``` + +For-loop: +```twig +{% for k, v in tags %} +Tag {{ k }} has value {{ v }} +{% endfor %} +``` + +Assign value to variable: +```twig +{% set k = "foo" %} +``` + +For more information, please visit: +* [https://twig.symfony.com/](Page of the original Twig template language) +* [https://github.com/twigjs/twig.js/wiki](Wiki of the TwigJS template language which is almost identical to Twig) + #### TwigJS templates -The following properties are available: -* id (the id of the object is always available, prefixed 'n' for nodes, 'w' for ways and 'r' for relations; e.g. 'n1234') -* osm_id (the numerical id of the object) -* layer_id (the id of the category) -* type ('node', 'way' or 'relation') -* tags.* (all tags are available with the prefix tags., e.g. tags.amenity) -* meta.timestamp (timestamp of last modification) -* meta.version (version of the object) -* meta.changeset (ID of the changeset, the object was last modified in) -* meta.user (Username of the user, who changed the object last) -* meta.uid (UID of the user, who changed the object last) -* map.zoom (Current zoom level) -* const.* (Values from the 'const' option) +When rendering map features, the following properties are available: +* `id` (the id of the object is always available, prefixed 'n' for nodes, 'w' for ways and 'r' for relations; e.g. 'n1234') +* `osm_id` (the numerical id of the object) +* `layer_id` (the id of the category) +* `type` ('node', 'way' or 'relation') +* `tags.*` (all tags are available with the prefix tags., e.g. tags.amenity) +* `meta.timestamp` (timestamp of last modification) +* `meta.version` (version of the object) +* `meta.changeset` (ID of the changeset, the object was last modified in) +* `meta.user` (Username of the user, who changed the object last) +* `meta.uid` (UID of the user, who changed the object last) +* `map.zoom` (Current zoom level) +* `const.*` (Values from the 'const' option) + +For the info-section of a category the following properties are available: +* `layer_id` (the id of the category) +* `map.zoom` (Current zoom level) +* `const.*` (Values from the 'const' option) There are several extra functions defined for the TwigJS language: * function `keyTrans`: return the translation of the given key. Parameters: key (required, e.g. 'amenity'). From 2060a4a435f1a52cfba6c8aa27f718fb693e518c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20B=C3=B6sch-Plepelits?= Date: Sun, 7 Jan 2018 06:53:34 +0100 Subject: [PATCH 43/54] OpenStreetBrowserLoader: handle invalid id --- src/OpenStreetBrowserLoader.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/OpenStreetBrowserLoader.js b/src/OpenStreetBrowserLoader.js index 99072f4a..33b11e31 100644 --- a/src/OpenStreetBrowserLoader.js +++ b/src/OpenStreetBrowserLoader.js @@ -25,6 +25,9 @@ OpenStreetBrowserLoader.prototype.getCategory = function (id, options, callback) } var ids = this.getFullId(id, options) + if (ids === null) { + return callback('invalid id', null) + } if (ids.fullId in this.categories) { return callback(null, this.categories[ids.fullId]) @@ -185,6 +188,10 @@ OpenStreetBrowserLoader.prototype.getCategoryFromData = function (id, options, d OpenStreetBrowserLoader.prototype.getFullId = function (id, options) { var result = {} + if (!id) { + return null + } + var m if (m = id.match(/^(.*)\/([^\/]*)/)) { result.id = id From 21486ede2eccbf5f66692f327174315a881b348f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20B=C3=B6sch-Plepelits?= Date: Sun, 7 Jan 2018 06:55:00 +0100 Subject: [PATCH 44/54] Every category type should have a load() method --- src/CategoryBase.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/CategoryBase.js b/src/CategoryBase.js index 072638bf..8a79c6c2 100644 --- a/src/CategoryBase.js +++ b/src/CategoryBase.js @@ -80,6 +80,10 @@ function CategoryBase (options, data) { this.dom.appendChild(this.domContent) } +CategoryBase.prototype.load = function (callback) { + callback() +} + CategoryBase.prototype.setMap = function (map) { this.map = map } From aa9132a8576eb469d5d4bf5fd10e00e820ec5e05 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20B=C3=B6sch-Plepelits?= Date: Sun, 7 Jan 2018 21:53:00 +0100 Subject: [PATCH 45/54] CategoryBase: new function shallShowReload() --- src/CategoryBase.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/CategoryBase.js b/src/CategoryBase.js index 8a79c6c2..765d80d7 100644 --- a/src/CategoryBase.js +++ b/src/CategoryBase.js @@ -49,7 +49,7 @@ function CategoryBase (options, data) { domHeader.appendChild(a) } - if (options.debug) { + if (this.shallShowReload()) { a = document.createElement('a') a.appendChild(document.createTextNode('⟳')) a.title = lang('reload') @@ -84,6 +84,10 @@ CategoryBase.prototype.load = function (callback) { callback() } +CategoryBase.prototype.shallShowReload = function () { + return options.debug +} + CategoryBase.prototype.setMap = function (map) { this.map = map } From a4e94e6a7d1f86989bb18349628a10085f2dcd91 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20B=C3=B6sch-Plepelits?= Date: Sun, 7 Jan 2018 22:03:27 +0100 Subject: [PATCH 46/54] OpenStreetBrowserLoader.forget(): adapt to new full ids --- src/OpenStreetBrowserLoader.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/OpenStreetBrowserLoader.js b/src/OpenStreetBrowserLoader.js index 33b11e31..991b5cc0 100644 --- a/src/OpenStreetBrowserLoader.js +++ b/src/OpenStreetBrowserLoader.js @@ -213,8 +213,10 @@ OpenStreetBrowserLoader.prototype.getFullId = function (id, options) { } OpenStreetBrowserLoader.prototype.forget = function (id) { - this.categories[id].remove() - delete this.categories[id] + var ids = this.getFullId(id, options) + + this.categories[ids.fullId].remove() + delete this.categories[ids.fullId] } OpenStreetBrowserLoader.prototype.registerType = function (type, classObject) { From 95ddee9526e015f6691996f9f364c5080c93a42f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20B=C3=B6sch-Plepelits?= Date: Sun, 7 Jan 2018 22:08:19 +0100 Subject: [PATCH 47/54] OpenStreetBrowserLoader: option force=true reloads repository --- src/CategoryBase.js | 2 +- src/OpenStreetBrowserLoader.js | 17 ++++++++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/CategoryBase.js b/src/CategoryBase.js index 765d80d7..8d648156 100644 --- a/src/CategoryBase.js +++ b/src/CategoryBase.js @@ -159,7 +159,7 @@ CategoryBase.prototype.reload = function (callback) { OpenStreetBrowserLoader.forget(this.id) - OpenStreetBrowserLoader.getCategory(this.id, function (err, category) { + OpenStreetBrowserLoader.getCategory(this.id, { force: true }, function (err, category) { if (err) { return callback(err) } diff --git a/src/OpenStreetBrowserLoader.js b/src/OpenStreetBrowserLoader.js index 991b5cc0..070310a2 100644 --- a/src/OpenStreetBrowserLoader.js +++ b/src/OpenStreetBrowserLoader.js @@ -15,7 +15,8 @@ OpenStreetBrowserLoader.prototype.setMap = function (map) { /** * @param string id ID of the category - * @parapm [object] options Options. + * @param [object] options Options. + * @waram {boolean} [options.force=false] Whether repository should be reload or not. * @param function callback Callback which will be called with (err, category) */ OpenStreetBrowserLoader.prototype.getCategory = function (id, options, callback) { @@ -29,6 +30,10 @@ OpenStreetBrowserLoader.prototype.getCategory = function (id, options, callback) return callback('invalid id', null) } + if (options.force) { + delete this.categories[ids.fullId] + } + if (ids.fullId in this.categories) { return callback(null, this.categories[ids.fullId]) } @@ -64,9 +69,14 @@ OpenStreetBrowserLoader.prototype.getCategory = function (id, options, callback) /** * @param string repo ID of the repository * @parapm [object] options Options. + * @waram {boolean} [options.force=false] Whether repository should be reload or not. * @param function callback Callback which will be called with (err, repoData) */ OpenStreetBrowserLoader.prototype.getRepo = function (repo, options, callback) { + if (options.force) { + delete this.repoCache[repo] + } + if (repo in this.repoCache) { return callback.apply(this, this.repoCache[repo]) } @@ -115,6 +125,7 @@ OpenStreetBrowserLoader.prototype.getRepo = function (repo, options, callback) { /** * @param string id ID of the template * @parapm [object] options Options. + * @waram {boolean} [options.force=false] Whether repository should be reload or not. * @param function callback Callback which will be called with (err, template) */ OpenStreetBrowserLoader.prototype.getTemplate = function (id, options, callback) { @@ -125,6 +136,10 @@ OpenStreetBrowserLoader.prototype.getTemplate = function (id, options, callback) var ids = this.getFullId(id, options) + if (options.force) { + delete this.templates[ids.fullId] + } + if (ids.fullId in this.templates) { return callback(null, this.templates[ids.fullId]) } From 1702c71a7fa3e100b0bcffb1401d60fdc4599347 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20B=C3=B6sch-Plepelits?= Date: Mon, 8 Jan 2018 22:55:59 +0100 Subject: [PATCH 48/54] Set stylesNoAutoShow option --- src/CategoryOverpass.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/CategoryOverpass.js b/src/CategoryOverpass.js index 4d9dc6da..a459d62e 100644 --- a/src/CategoryOverpass.js +++ b/src/CategoryOverpass.js @@ -63,6 +63,7 @@ function CategoryOverpass (options, data) { data.feature.appUrl = '#' + this.id + '/{{ id }}' data.styleNoBindPopup = [ 'hover' ] + data.stylesNoAutoShow = [ 'hover' ] this.layer = new OverpassLayer(data) From 18bbee96bae9b018cd7006741caeb0bb1b69433f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20B=C3=B6sch-Plepelits?= Date: Tue, 9 Jan 2018 21:17:34 +0100 Subject: [PATCH 49/54] Rename style 'weight' in 'width' --- README.md | 2 +- src/CategoryOverpass.js | 2 +- src/markers.js | 12 +++++------- 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 4455a892..a06c76e9 100644 --- a/README.md +++ b/README.md @@ -90,7 +90,7 @@ The following values are possible for categories (the only mandatory value is qu * feature: an object describing how the feature will be formated resp. styled. * style: a Leaflet style. * stroke: Whether to draw stroke along the path. Set it to false or empty string to disable borders on polygons or circles. (boolean, true) - * weight: Stroke width in pixels (number, 3) + * width: Stroke width in pixels (number, 3) * color: Stroke color (string, '#3388ff') * opacity: Stroke opacity (number, 1.0) * lineCap: shape at end of the stroke (string, 'round') diff --git a/src/CategoryOverpass.js b/src/CategoryOverpass.js index a459d62e..ada7d88a 100644 --- a/src/CategoryOverpass.js +++ b/src/CategoryOverpass.js @@ -11,7 +11,7 @@ var defaultValues = { markerSign: '', 'style:hover': { color: 'black', - weight: 3, + width: 3, opacity: 1, radius: 12, fill: false diff --git a/src/markers.js b/src/markers.js index b2c9447f..9e5c6e96 100644 --- a/src/markers.js +++ b/src/markers.js @@ -5,9 +5,7 @@ function cssStyle (style) { if ('color' in style) { ret += 'stroke: ' + style.color + ';' } - if ('weight' in style) { - ret += 'stroke-width: ' + style.weight + ';' - } + ret += 'stroke-width: ' + ('width' in style ? style.width : '3') + ';' if ('dashArray' in style) { ret += 'stroke-dasharray: ' + style.dashArray + ';' } @@ -80,17 +78,17 @@ function markerPolygon (data) { function markerCircle (style) { var fillColor = 'fillColor' in style ? style.fillColor : '#f2756a' var color = 'color' in style ? style.color : '#000000' - var weight = 'weight' in style ? style.weight : 1 + var width = 'width' in style ? style.width : 1 - return '' + return '' } function markerPointer (style) { var fillColor = 'fillColor' in style ? style.fillColor : '#f2756a' var color = 'color' in style ? style.color : '#000000' - var weight = 'weight' in style ? style.weight : 1 + var width = 'width' in style ? style.width : 1 - return '' + return '' } OverpassLayer.twig.extendFunction('markerLine', markerLine) From 3860882d878975b976a27100890c0945ee445f12 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20B=C3=B6sch-Plepelits?= Date: Tue, 9 Jan 2018 22:52:38 +0100 Subject: [PATCH 50/54] addCategories: sort repository list - newest first --- package.json | 3 ++- src/addCategories.js | 6 +++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 40b06373..49e813dd 100644 --- a/package.json +++ b/package.json @@ -26,7 +26,8 @@ "openstreetmap-tag-translations": "https://github.com/plepe/openstreetmap-tag-translations", "overpass-layer": "https://github.com/plepe/overpass-layer", "query-string": "^5.0.0", - "sheet-router": "^4.2.3" + "sheet-router": "^4.2.3", + "weight-sort": "^1.3.0" }, "scripts": { "test": "echo \"Error: no test specified\" && exit 1", diff --git a/src/addCategories.js b/src/addCategories.js index 8573d573..f478005f 100644 --- a/src/addCategories.js +++ b/src/addCategories.js @@ -1,5 +1,6 @@ var OpenStreetBrowserLoader = require('./OpenStreetBrowserLoader') require('./addCategories.css') +var weightSort = require('weight-sort') var content @@ -53,7 +54,10 @@ function addCategoriesShow (repo) { h.innerHTML = lang('more_categories') content.appendChild(h) - list = repoData + list = weightSort(repoData, { + key: 'timestamp', + reverse: true + }) } var ul = document.createElement('ul') From ed5ac1d46b60a1b76d8e680711acf7492c8144c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20B=C3=B6sch-Plepelits?= Date: Tue, 9 Jan 2018 22:54:53 +0100 Subject: [PATCH 51/54] Update submodules --- lib/modulekit/form | 2 +- lib/modulekit/lang | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/modulekit/form b/lib/modulekit/form index 819380c6..4a94f64c 160000 --- a/lib/modulekit/form +++ b/lib/modulekit/form @@ -1 +1 @@ -Subproject commit 819380c621e2ec79d5ca22db6af44d0eaf1c158c +Subproject commit 4a94f64c11d3f16b01a5aec6afd5cfb4b7257572 diff --git a/lib/modulekit/lang b/lib/modulekit/lang index 1013930a..80118dbc 160000 --- a/lib/modulekit/lang +++ b/lib/modulekit/lang @@ -1 +1 @@ -Subproject commit 1013930aafa47f214f6e9d4b68c684acf4922efc +Subproject commit 80118dbcaafa9ab95298be95548126071efc069f From 46542d2173f698474c18187fd55954ec2d396b2c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20B=C3=B6sch-Plepelits?= Date: Thu, 11 Jan 2018 20:53:10 +0100 Subject: [PATCH 52/54] Repositories: change config - do not include in $config --- conf.php-dist | 4 ++-- src/repositories.php | 23 ++++++++++++----------- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/conf.php-dist b/conf.php-dist index 0e28a591..d053c2f2 100644 --- a/conf.php-dist +++ b/conf.php-dist @@ -3,7 +3,7 @@ // repositoryUrl and categoryUrl are twig templates, which take the following input values: // {{ repositoryId }} id of the repository // {{ categoryId }} id of the category (not for repositoryUrl) -$config['repositories'] = array( +$repositories = array( 'default' => array( 'path' => 'node_modules/openstreetbrowser-categories-main', 'type' => 'dir', @@ -15,7 +15,7 @@ $config['repositories'] = array( ); // Repositories which should be included from gitea -$config['repositories_gitea'] = "/home/gitea/gitea-repositories"; +$repositoriesGitea = "/home/gitea/gitea-repositories"; // Set to true to reload categories on every page visit. $config['categoriesAlwaysReload'] = true; diff --git a/src/repositories.php b/src/repositories.php index b9a8ffa8..4bf761f3 100644 --- a/src/repositories.php +++ b/src/repositories.php @@ -1,30 +1,31 @@ array( 'path' => $config['categoriesDir'], ), ); } - if (isset($config['repositories_gitea'])) { - $d1 = opendir($config['repositories_gitea']); + if (isset($repositoriesGitea)) { + $d1 = opendir($repositoriesGitea); while ($f1 = readdir($d1)) { if (substr($f1, 0, 1) !== '.') { - $d2 = opendir("{$config['repositories_gitea']}/{$f1}"); + $d2 = opendir("{$repositoriesGitea}/{$f1}"); while ($f2 = readdir($d2)) { if (substr($f2, 0, 1) !== '.') { $f2id = substr($f2, 0, -4); - $repositories["{$f1}/{$f2id}"] = array( - 'path' => "{$config['repositories_gitea']}/{$f1}/{$f2}", + $result["{$f1}/{$f2id}"] = array( + 'path' => "{$repositoriesGitea}/{$f1}/{$f2}", 'type' => 'git', 'repositoryUrl' => 'https://www.openstreetbrowser.org/dev/{{ repositoryId }}', 'categoryUrl' => 'https://www.openstreetbrowser.org/dev/{{ repositoryId }}/src/{{ categoryId }}.json', @@ -37,7 +38,7 @@ function getRepositories () { closedir($d1); } - return $repositories; + return $result; } function getRepo ($repoId, $repoData) { From f19906ab27500dc0fb18539f38aa72d255ba76c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20B=C3=B6sch-Plepelits?= Date: Thu, 11 Jan 2018 20:57:01 +0100 Subject: [PATCH 53/54] Repositories: improve configuration of gitea - declare path and url --- conf.php-dist | 5 ++++- src/repositories.php | 17 +++++++++++------ 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/conf.php-dist b/conf.php-dist index d053c2f2..d0339532 100644 --- a/conf.php-dist +++ b/conf.php-dist @@ -15,7 +15,10 @@ $repositories = array( ); // Repositories which should be included from gitea -$repositoriesGitea = "/home/gitea/gitea-repositories"; +$repositoriesGitea = array( + 'path' => "/home/gitea/gitea-repositories", + 'url' => "https://www.openstreetbrowser.org/dev", +); // Set to true to reload categories on every page visit. $config['categoriesAlwaysReload'] = true; diff --git a/src/repositories.php b/src/repositories.php index 4bf761f3..07a47532 100644 --- a/src/repositories.php +++ b/src/repositories.php @@ -16,20 +16,25 @@ function getRepositories () { } if (isset($repositoriesGitea)) { - $d1 = opendir($repositoriesGitea); + $d1 = opendir($repositoriesGitea['path']); while ($f1 = readdir($d1)) { if (substr($f1, 0, 1) !== '.') { - $d2 = opendir("{$repositoriesGitea}/{$f1}"); + $d2 = opendir("{$repositoriesGitea['path']}/{$f1}"); while ($f2 = readdir($d2)) { if (substr($f2, 0, 1) !== '.') { $f2id = substr($f2, 0, -4); - $result["{$f1}/{$f2id}"] = array( - 'path' => "{$repositoriesGitea}/{$f1}/{$f2}", + $r = array( + 'path' => "{$repositoriesGitea['path']}/{$f1}/{$f2}", 'type' => 'git', - 'repositoryUrl' => 'https://www.openstreetbrowser.org/dev/{{ repositoryId }}', - 'categoryUrl' => 'https://www.openstreetbrowser.org/dev/{{ repositoryId }}/src/{{ categoryId }}.json', ); + + if (array_key_exists('url', $repositoriesGitea)) { + $r['repositoryUrl'] = "{$repositoriesGitea['url']}/{{ repositoryId }}"; + $r['categoryUrl'] = "{$repositoriesGitea['url']}/{{ repositoryId }}/src/{{ categoryId }}.json"; + } + + $result["{$f1}/{$f2id}"] = $r; } } closedir($d2); From 875b5e29d05d9ff347ba2dc044d172425f1ba0c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20B=C3=B6sch-Plepelits?= Date: Thu, 11 Jan 2018 21:20:36 +0100 Subject: [PATCH 54/54] Repositories: Advertise gitea env in addCategories --- lang/de.json | 1 + lang/en.json | 1 + src/addCategories.js | 8 ++++++++ src/repositories.php | 11 +++++++++++ 4 files changed, 21 insertions(+) diff --git a/lang/de.json b/lang/de.json index 50d314cd..c52e8f57 100644 --- a/lang/de.json +++ b/lang/de.json @@ -12,6 +12,7 @@ "main:options": "Optionen", "more": "mehr", "more_categories": "Mehr Kategorien", + "more_categories_gitea": "Erstelle und verbessere Kategorien hier!", "open": "geöffnet", "options:data_lang": "Datensprache", "options:data_lang:local": "Lokale Sprache", diff --git a/lang/en.json b/lang/en.json index 08e8bf46..8bb7dfe5 100644 --- a/lang/en.json +++ b/lang/en.json @@ -12,6 +12,7 @@ "main:options": "Options", "more": "more", "more_categories": "More categories", + "more_categories_gitea": "Create & improve categories yourself!", "open": "open", "options:data_lang": "Data language", "options:data_lang:desc": "Many map features have their name (and other tags) translated to different languages (e.g. with 'name:en', 'name:de'). Specify which language should be used for displaying, or 'Local language' so that always the untranslated value (e.g. 'name') will be used", diff --git a/src/addCategories.js b/src/addCategories.js index f478005f..261351a6 100644 --- a/src/addCategories.js +++ b/src/addCategories.js @@ -54,6 +54,14 @@ function addCategoriesShow (repo) { h.innerHTML = lang('more_categories') content.appendChild(h) + if (typeof repositoriesGitea === 'object' && repositoriesGitea.url) { + var a = document.createElement('a') + a.href = repositoriesGitea.url + a.target = '_blank' + a.innerHTML = lang('more_categories_gitea') + content.appendChild(a) + } + list = weightSort(repoData, { key: 'timestamp', reverse: true diff --git a/src/repositories.php b/src/repositories.php index 07a47532..b14b12f4 100644 --- a/src/repositories.php +++ b/src/repositories.php @@ -57,3 +57,14 @@ function getRepo ($repoId, $repoData) { return $repo; } + +register_hook('init', function () { + global $repositoriesGitea; + + if (isset($repositoriesGitea) && array_key_exists('url', $repositoriesGitea)) { + $d = array('repositoriesGitea' => array( + 'url' => $repositoriesGitea['url'], + )); + html_export_var($d); + } +});