rewrote abbjobs to use json apin provided by old sikweb

This commit is contained in:
okalintu
2016-12-02 20:12:05 +02:00
parent c2322cb103
commit 4d548f0767
7 changed files with 6425 additions and 4 deletions
+1 -1
View File
@@ -6,6 +6,6 @@
<div class="row" ng-repeat="job in jobs" style="height:280px;;border:2px solid black;color:#33333">
<div class="col-xs-7 col-xs-offset-1" style="font-size:72px;padding-top:30px">{{ job.title }}</div>
<div class="col-xs-3"><img ng-src="{{ job.QR }}" style="height:250px;"></div>
<div class="col-xs-3 col-xs-offset-1"><qrcode data="http://sahkoinsinoorikilta.fi/fi/news/{{ job.id }}" size="278"></qrcode></div>
</div>
</div>
+190
View File
@@ -0,0 +1,190 @@
/*
* angular-qrcode v6.2.1
* (c) 2013 Monospaced http://monospaced.com
* License: MIT
*/
angular.module('monospaced.qrcode', [])
.directive('qrcode', ['$window', function($window) {
var canvas2D = !!$window.CanvasRenderingContext2D,
levels = {
'L': 'Low',
'M': 'Medium',
'Q': 'Quartile',
'H': 'High'
},
draw = function(context, qr, modules, tile) {
for (var row = 0; row < modules; row++) {
for (var col = 0; col < modules; col++) {
var w = (Math.ceil((col + 1) * tile) - Math.floor(col * tile)),
h = (Math.ceil((row + 1) * tile) - Math.floor(row * tile));
context.fillStyle = qr.isDark(row, col) ? '#000' : '#fff';
context.fillRect(Math.round(col * tile),
Math.round(row * tile), w, h);
}
}
};
return {
restrict: 'E',
template: '<canvas class="qrcode"></canvas>',
link: function(scope, element, attrs) {
var domElement = element[0],
$canvas = element.find('canvas'),
canvas = $canvas[0],
context = canvas2D ? canvas.getContext('2d') : null,
download = 'download' in attrs,
href = attrs.href,
link = download || href ? document.createElement('a') : '',
trim = /^\s+|\s+$/g,
error,
version,
errorCorrectionLevel,
data,
size,
modules,
tile,
qr,
$img,
setVersion = function(value) {
version = Math.max(1, Math.min(parseInt(value, 10), 40)) || 5;
},
setErrorCorrectionLevel = function(value) {
errorCorrectionLevel = value in levels ? value : 'M';
},
setData = function(value) {
if (!value) {
return;
}
data = value.replace(trim, '');
qr = qrcode(version, errorCorrectionLevel);
qr.addData(data);
try {
qr.make();
} catch(e) {
error = e.message;
return;
}
error = false;
modules = qr.getModuleCount();
},
setSize = function(value) {
size = parseInt(value, 10) || modules * 2;
tile = size / modules;
canvas.width = canvas.height = size;
},
render = function() {
if (!qr) {
return;
}
if (error) {
if (link) {
link.removeAttribute('download');
link.title = '';
link.href = '#_';
}
if (!canvas2D) {
domElement.innerHTML = '<img src width="' + size + '"' +
'height="' + size + '"' +
'class="qrcode">';
}
scope.$emit('qrcode:error', error);
return;
}
if (download) {
domElement.download = 'qrcode.png';
domElement.title = 'Download QR code';
}
if (canvas2D) {
draw(context, qr, modules, tile);
if (download) {
domElement.href = canvas.toDataURL('image/png');
return;
}
} else {
domElement.innerHTML = qr.createImgTag(tile, 0);
$img = element.find('img');
$img.addClass('qrcode');
if (download) {
domElement.href = $img[0].src;
return;
}
}
if (href) {
domElement.href = href;
}
};
if (link) {
link.className = 'qrcode-link';
$canvas.wrap(link);
domElement = domElement.firstChild;
}
setVersion(attrs.version);
setErrorCorrectionLevel(attrs.errorCorrectionLevel);
setSize(attrs.size);
attrs.$observe('version', function(value) {
if (!value) {
return;
}
setVersion(value);
setData(data);
setSize(size);
render();
});
attrs.$observe('errorCorrectionLevel', function(value) {
if (!value) {
return;
}
setErrorCorrectionLevel(value);
setData(data);
setSize(size);
render();
});
attrs.$observe('data', function(value) {
if (!value) {
return;
}
setData(value);
setSize(size);
render();
});
attrs.$observe('size', function(value) {
if (!value) {
return;
}
setSize(value);
render();
});
attrs.$observe('href', function(value) {
if (!value) {
return;
}
href = value;
render();
});
}
};
}]);
+13 -3
View File
@@ -1,5 +1,5 @@
var app = angular.module('infoApp', ['ngAnimate', 'ngRoute']);
var app = angular.module('infoApp', ['ngAnimate', 'ngRoute', 'monospaced.qrcode']);
app.controller('infoscreen_main', function($scope,$http,$timeout){
var templates = [];
$scope.init = function(rot){
@@ -35,8 +35,18 @@ app.controller('infoscreen_main', function($scope,$http,$timeout){
});
app.controller('ABBController', function($scope, $http){
$scope.jobs = [];
$http.get("/infoscreen/abbjobs").then(function(response){
$scope.jobs = response.data;
var min_date = moment().subtract(30,'days').format("YYYY-MM-DD%20HH:mm:ss");
var url = "http://sahkoinsinoorikilta.fi/api/news.php";
var params = "?type=11&lang=fi&title_search=ABB&min_date="+min_date
$http.get(url+params).then(function(response){
$scope.jobs = _.filter(response.data, function(job){
if (job.autohide_enabled == 1){
if (moment(job.autohide) < moment()){
return false;
}
}
return true;
})
})
});
app.controller('SossoController', function($scope, $http){
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
+59
View File
@@ -0,0 +1,59 @@
//---------------------------------------------------------------------
//
// QR Code Generator for JavaScript UTF8 Support (optional)
//
// Copyright (c) 2011 Kazuhiko Arase
//
// URL: http://www.d-project.com/
//
// Licensed under the MIT license:
// http://www.opensource.org/licenses/mit-license.php
//
// The word 'QR Code' is registered trademark of
// DENSO WAVE INCORPORATED
// http://www.denso-wave.com/qrcode/faqpatent-e.html
//
//---------------------------------------------------------------------
!function(qrcode) {
//---------------------------------------------------------------------
// overwrite qrcode.stringToBytes
//---------------------------------------------------------------------
qrcode.stringToBytes = function(s) {
// http://stackoverflow.com/questions/18729405/how-to-convert-utf8-string-to-byte-array
function toUTF8Array(str) {
var utf8 = [];
for (var i=0; i < str.length; i++) {
var charcode = str.charCodeAt(i);
if (charcode < 0x80) utf8.push(charcode);
else if (charcode < 0x800) {
utf8.push(0xc0 | (charcode >> 6),
0x80 | (charcode & 0x3f));
}
else if (charcode < 0xd800 || charcode >= 0xe000) {
utf8.push(0xe0 | (charcode >> 12),
0x80 | ((charcode>>6) & 0x3f),
0x80 | (charcode & 0x3f));
}
// surrogate pair
else {
i++;
// UTF-16 encodes 0x10000-0x10FFFF by
// subtracting 0x10000 and splitting the
// 20 bits of 0x0-0xFFFFF into two halves
charcode = 0x10000 + (((charcode & 0x3ff)<<10)
| (str.charCodeAt(i) & 0x3ff));
utf8.push(0xf0 | (charcode >>18),
0x80 | ((charcode>>12) & 0x3f),
0x80 | ((charcode>>6) & 0x3f),
0x80 | (charcode & 0x3f));
}
}
return utf8;
}
return toUTF8Array(s);
};
}(qrcode);
@@ -5,12 +5,16 @@
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Infoscreen</title>
<script src="/static/js/moment.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.5.8/angular.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.8/angular-route.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.5.8/angular-animate.js"></script>
<script src="https://code.jquery.com/jquery-3.1.0.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.8.3/underscore-min.js"></script>
<script src="/static/js/qrcode.js"></script>
<script src="/static/js/qrcode_UTF8.js"></script>
<script src="/static/js/angular-qrcode.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"></link>
<link rel="stylesheet" href="/static/css/infoscreen.css">
<script src="/static/js/infoscreen_controllers.js"></script>