Browse Source

repo.php/addCategories: repositoryUrl and categoryUrl

master
Stephan Bösch-Plepelits 7 years ago
parent
commit
ca51637002
  1. 7
      conf.php-dist
  2. 21
      repo.php
  3. 35
      src/addCategories.js
  4. 2
      src/repositories.php

7
conf.php-dist

@ -1,9 +1,16 @@
<?php
// Repositories from which to read the categories.
// 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(
'default' => 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',
),
);

21
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");

35
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 = '<img src="img/edit.png"/>'
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 = '<img src="img/edit.png"/>'
li.appendChild(editLink)
}
ul.appendChild(li)
}

2
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',
);
}
}

Loading…
Cancel
Save