diff --git a/infoscreen/admin.py b/infoscreen/admin.py
index 8c38f3f..da0268b 100644
--- a/infoscreen/admin.py
+++ b/infoscreen/admin.py
@@ -1,3 +1,9 @@
from django.contrib import admin
+from infoscreen.models import Rotation, InfoItem, InfoInstance, InfoOption
# Register your models here.
+
+admin.site.register(Rotation)
+admin.site.register(InfoItem)
+admin.site.register(InfoInstance)
+admin.site.register(InfoOption)
diff --git a/infoscreen/migrations/0003_auto_20160914_1543.py b/infoscreen/migrations/0003_auto_20160914_1543.py
new file mode 100644
index 0000000..9c1c8ba
--- /dev/null
+++ b/infoscreen/migrations/0003_auto_20160914_1543.py
@@ -0,0 +1,58 @@
+# -*- coding: utf-8 -*-
+# Generated by Django 1.9 on 2016-09-14 15:43
+from __future__ import unicode_literals
+
+from django.db import migrations, models
+import django.db.models.deletion
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('infoscreen', '0002_auto_20160831_1757'),
+ ]
+
+ operations = [
+ migrations.CreateModel(
+ name='InfoInstance',
+ fields=[
+ ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
+ ('duration', models.FloatField(default=15.0)),
+ ],
+ ),
+ migrations.CreateModel(
+ name='InfoItem',
+ fields=[
+ ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
+ ('name', models.CharField(max_length=255)),
+ ('template_url', models.CharField(max_length=512)),
+ ('expire_date', models.DateTimeField()),
+ ],
+ ),
+ migrations.CreateModel(
+ name='InfoOption',
+ fields=[
+ ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
+ ('key', models.CharField(max_length=255)),
+ ('value', models.CharField(max_length=255)),
+ ('item', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='options', to='infoscreen.InfoItem')),
+ ],
+ ),
+ migrations.CreateModel(
+ name='Rotation',
+ fields=[
+ ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
+ ('name', models.CharField(max_length=255)),
+ ],
+ ),
+ migrations.AddField(
+ model_name='infoinstance',
+ name='item',
+ field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='infoscreen.InfoItem'),
+ ),
+ migrations.AddField(
+ model_name='infoinstance',
+ name='rotation',
+ field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='instances', to='infoscreen.Rotation'),
+ ),
+ ]
diff --git a/infoscreen/models.py b/infoscreen/models.py
index 2d4d93a..d7c49e6 100644
--- a/infoscreen/models.py
+++ b/infoscreen/models.py
@@ -1,6 +1,64 @@
from django.db import models
from django.utils import timezone
+class InfoItem(models.Model):
+ name = models.CharField(max_length=255)
+ template_url = models.CharField(max_length=512)
+ expire_date = models.DateTimeField() # None means never expiring item
+
+ def get_dict(self):
+ # fetch options
+ opts = {}
+ for o in self.options.all():
+ opts[o.key] = o.value
+ # parse dict
+ return {
+ 'name': self.name,
+ 'template_url': self.template_url,
+ 'options': opts
+ }
+ def __str__(self):
+ return self.name
+class InfoInstance(models.Model):
+ rotation = models.ForeignKey('Rotation', related_name='instances')
+ item = models.ForeignKey('InfoItem')
+ duration = models.FloatField(default=15.0) # seconds
+
+ def get_dict(self):
+ return {
+ 'item': self.item.get_dict(),
+ 'duration': self.duration,
+ }
+ def __str__(self):
+ return "{}: {} ({}s)".format(self.rotation.name, self.item.name, self.duration)
+
+class InfoOption(models.Model):
+ class __meta__:
+ unique_together = ("item", "key")
+
+ item = models.ForeignKey('InfoItem', related_name='options')
+ key = models.CharField(max_length=255)
+ value = models.CharField(max_length=255)
+
+ def __str__(self):
+ return "{}: {} -> {}".format(self.item.name, self.key, self.value)
+
+class Rotation(models.Model):
+ name = models.CharField(max_length=255)
+
+ def get_dict(self):
+ # exclude expired items from rotation (note: using filter would exclude items with no expide_date)
+ instances = self.instances.exclude(item__expire_date__lt=timezone.now())
+ instance_list = list(map(lambda i:i.get_dict(), instances))
+
+ return {
+ 'name': self.name,
+ 'instances': instance_list,
+ }
+
+ def __str__(self):
+ return self.name
+
class ABBJob(models.Model):
sw_id = models.IntegerField(default=-1)
title = models.CharField(max_length=255)
@@ -12,3 +70,6 @@ class ABBJob(models.Model):
"title": self.title,
"QR": self.QR,
}
+
+ def __str__(self):
+ return self.title
diff --git a/infoscreen/static/html/genericimage.html b/infoscreen/static/html/genericimage.html
new file mode 100644
index 0000000..3113d80
--- /dev/null
+++ b/infoscreen/static/html/genericimage.html
@@ -0,0 +1 @@
+
diff --git a/infoscreen/static/html/test1.html b/infoscreen/static/html/test1.html
deleted file mode 100644
index 8f0ce55..0000000
--- a/infoscreen/static/html/test1.html
+++ /dev/null
@@ -1 +0,0 @@
-
\ No newline at end of file
diff --git a/infoscreen/static/js/infoscreen_controllers.js b/infoscreen/static/js/infoscreen_controllers.js
index 16c5370..0d67766 100644
--- a/infoscreen/static/js/infoscreen_controllers.js
+++ b/infoscreen/static/js/infoscreen_controllers.js
@@ -1,32 +1,35 @@
-var app = angular.module('infoApp', ['ngAnimate']);
+var app = angular.module('infoApp', ['ngAnimate', 'ngRoute']);
-
-
-app.controller('infoscreen_main', function($scope,$timeout){
- $scope.index = -1;
- var templates = [
- {
- template: "/static/html/test1.html?img=otatarha",
- onload: function(){$scope.imagepath = "/static/img/otaajot16fb.png";}
- },{
- template: "/static/html/abb.html"
- },{
- template: "/static/html/test1.html?img=otaolut",
- onload: function(){$scope.imagepath = "/static/img/otaolutbanner.jpg";}
- },{
- template: "/static/html/test1.html?img=asw",
- onload: function(){$scope.imagepath = "/static/img/asw.png";}
- },{
- template: "/static/html/test1.html?img=fujitsu",
- onload: function(){$scope.imagepath = "/static/img/fujitsu.png";}
- },
- ];
- $scope.next = function(){
- $scope.index = ($scope.index + 1) % templates.length;
- $scope.active = templates[$scope.index];
- $timeout($scope.next,15000);
+app.controller('infoscreen_main', function($scope,$http,$timeout){
+ var templates = [];
+ $scope.init = function(rot){
+ $scope.rotation = rot;
+ get_rotation();
+ }
+ var get_rotation = function(){
+ $scope.index = -1;
+ $http.get('/infoscreen/rotation/'+$scope.rotation).then(function(response){
+ templates = response.data.instances;
+ $scope.next();
+ });
+ }
+
+ $scope.next = function(){
+ $scope.index++;
+ if ($scope.index >= templates.length){
+ return get_rotation();
+ }
+ var temp = templates[$scope.index];
+ $scope.active = {
+ template: temp.item.template_url,
+ onload: function(){
+ for (key in temp.item.options){
+ $scope[key] = temp.item.options[key]
+ }
+ }
+ };
+ $timeout($scope.next, temp.duration * 1000);
}
- $scope.next()
});
app.controller('ABBController', function($scope, $http){
$scope.jobs = [];
diff --git a/infoscreen/templates/infoscreen_index.html b/infoscreen/templates/infoscreen_index.html
index ae55891..850f72b 100644
--- a/infoscreen/templates/infoscreen_index.html
+++ b/infoscreen/templates/infoscreen_index.html
@@ -16,7 +16,7 @@