Hello,
since I am really missing the possibility of dynamically generating sitemap subitems (e.g. receive a JSON with items, and generate them on-the-fly within a sitemap based on how many items the JSON returns) I’ve coded a static HTML page myself.
Actually, I wanted to show my Wunderlist tasks as sitemap entries in my OpenHAB instance.
To do that, I’ve coded this simple AngularJS1-based webpage that gets my Wunderlist tasks from an API developed by me (it serves tasks as JSON), and I then just generate them as OpenHAB-like tiles using the Angular binding (ng-repeat).
The code is quite simple:
<style type="text/css">
.wunderlist-item
{
width: calc(50% - 16px);
display: inline-block;
margin: 0 8px;
padding: 4px 0;
min-height: 48px;
font-family: "Helvetica", "Arial", sans-serif;
font-size: 14px;
font-weight: 400;
line-height: 20px;
color: #616161;
border-bottom: 1px solid #cccccc;
}
.wunderlist-item img
{
margin-right: 12px;
position: relative;
top: 10px;
}
@media only screen and (max-width: 839px)
{
.wunderlist-item
{
width: calc(100% - 16px);
}
}
</style>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.2/angular.min.js"></script>
<script type="text/javascript">
var wunderlistApp = angular.module("wunderlistApp", []);
wunderlistApp.controller("wunderlistCtrl", function($scope, $http) {
// get "list" parameter value
name= "list";
name = name.replace(/[\[\]]/g, "\\$&");
var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)");
var results = regex.exec(document.location.href);
if (!results) return null;
if (!results[2]) return '';
listId = decodeURIComponent(results[2].replace(/\+/g, " "));
// grab data
$scope.wunderlistInterval = null;
$scope.wunderlistRefresh = function()
{
$http({
method: 'GET',
url: "myAPIsource/?command=wunderlist&list=" + listId,
timeout: 2000
}).then(function(response) {
$scope.wunderlistTasks = response.data.data.tasks;
});
$scope.wunderlistInterval = setTimeout($scope.wunderlistRefresh, 3000);
}
$scope.wunderlistRefresh();
});
</script>
<section ng-app="wunderlistApp" ng-controller="wunderlistCtrl">
<div class="wunderlist-item" ng-repeat="task in wunderlistTasks">
<img src="../icon/keyring?format=svg" width="32">
{{task.title}}
</div>
</section>
And my CSS makes it look like native OpenHAB sitemap items as well:
So I now have my shopping list from Wunderlist within OpenHAB to be shared with my family. Unfortunately, this site only renders in browser and not in the Android app. Any ideas why?
Best,
Denis