| layout | events | ||
|---|---|---|---|
| permalink | /events/index.html | ||
| title | イベント | ||
| description | |||
| tags | |||
| image |
|
{% raw %}
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.12/angular.min.js"></script>
<script>
var app = angular.module('evtApp', []);
app.controller('EventListCtrl', function($scope, $http) {
var eventURL = 'http://reading.fxos.org/api/events/gcal';
$http({method: 'GET', url: eventURL, responseType: 'json'}).
success(function(data, status) {
var events = [];
if (status == 200) {
data.items.forEach(function(item) {
var from = new Date(item.start.dateTime);
var to = new Date(item.end.dateTime);
var desc = parseDesc(item.description);
events.push({
title: item.summary,
from: from,
to: to,
location: item.location,
isOneDay: isSameDate(from, to),
url: desc.url,
description: desc.description,
});
});
}
$scope.events = events;
});
});
function isSameDate(from, to) {
return (from.getYear() === to.getYear() &&
from.getMonth() === to.getMonth() &&
from.getDate() === to.getDate());
}
function parseDesc(desc) {
var lines = desc.split('\n');
var ret = {};
if (lines.length >=1 && lines[0].match(/^(http|https):\/\//)) {
ret.url = lines[0];
ret.description = lines.slice(1).join(' ');
} else {
ret.url = null;
ret.description = lines.join(' ');
}
return ret;
}
</script>
{{evt.title}}
{% endraw %}
日時:
{{evt.from|date:'yyyy/MM/dd HH:mm'}}
-
{{evt.to|date:'HH:mm'}}
{{evt.to|date:'yyyy/MM/dd HH:mm'}}
場所: {{evt.location}}
{{evt.description}}