- Created model for timetable-data management

- Updated infoscreen hsl command
- Fixed all depending code
This commit is contained in:
Juuso Käenmäki
2017-01-18 17:26:47 +02:00
parent 869de82c5c
commit 892e2b5252
7 changed files with 87 additions and 35 deletions
+10
View File
@@ -0,0 +1,10 @@
<div ng-controller="infoadmin_hslitem_create" style="margin-top:20px;">
<div>
Create new item to show hsl ttimetables. Name is used only as identifier
</div>
<div class="form-group">
<label>Name:</label>
<input type="text" ng-model="item.name"></input>
</div>
<input type="button" class="btn btn-success" ng-click="send()" value="create"></input>
</div>
@@ -136,6 +136,12 @@ app.controller('infoadmin_sossoitem_create', function($scope, $http,ItemList){
$http.post("/infoscreen/create_sossoitem", $scope.item).then(ItemList.loadItems)
}
});
app.controller('infoadmin_hslitem_create', function($scope, $http,ItemList){
$scope.item = {}
$scope.send = function(){
$http.post("/infoscreen/create_hslitem", $scope.item).then(ItemList.loadItems)
}
});
app.controller('infoadmin_image_create', ['$scope', 'Upload', '$timeout',"ItemList", function ($scope, Upload, $timeout,ItemList) {
$scope.send = function(file) {
+44 -30
View File
@@ -1,4 +1,4 @@
var activescope;
var app = angular.module('infoApp', ['ngAnimate', 'ngRoute', 'monospaced.qrcode']);
app.controller('infoscreen_main', function($scope,$http,$timeout){
var templates = [];
@@ -66,56 +66,69 @@ app.controller('SossoController', function($scope, $http) {
$scope.data = response.data;
})
});
app.controller('timetableCtrl',
function($scope, $http, $interval) {
function load(){
$http.get('/static/js/hsl.json')
$http.get('/infoscreen/hsl_data')
.then(function(data, status, headers, config) {
$scope.arr=[];
parse(data);
});
};
var obj;
$scope.$on('$destroy', function() {
$interval.cancel(inter1);
$interval.cancel(inter2);
});
var objects;
$scope.arr=[];
var dict=[];
function parse(data){
obj=data['data'];
for(var a in obj){
for(var b in obj[a]['lines']){
var elem=obj[a]['lines'][b].split(":");
objects=data['data'];
for(var objectIndex in objects){
var stop = objects[objectIndex];
for(var lineIndex in stop['lines']){
var elem=stop['lines'][lineIndex].split(":");
dict[elem[0]]=elem[1];
}
for(var b in obj[a]['departures']){
var e=true;
var time=obj[a]['departures'][b]['time'];
date=obj[a]['departures'][b]['date'];
for(var lineIndex in stop['departures']){
var line = stop['departures'][lineIndex];
var time=line['time'];
date=line['date'];
if(time<1000)
var unit = 1;
else
var unit = 2;
var hh= Math.floor(obj[a]['departures'][b]['time']/100);
if(hh>=24){
hh-=24;
var hours= Math.floor(line['time']/100);
if(hours>=24){
hours-=24;
date++;
}
var mm= obj[a]['departures'][b]['time']%100;
var c= obj[a]['departures'][b]['code'].substring(1,5);
if(c.charAt(0)=='0')
c=c.substring(1,4);
z={"stop":obj[a]['name'].split(",")[0],"dist":obj[a]['dist'],"bus":c,"date":date,"time":pad(hh,2)+":"+pad(mm,2),"laststop":dict[obj[a]['departures'][b]['code']].split(",")[0].split(" ")[0]};
for(var i= $scope.arr.length-1;i>=0;i--)
if( $scope.arr[i]['bus']==z['bus'] && $scope.arr[i]['laststop']==z['laststop']){
if( $scope.arr[i]['dist']==z['dist']){
var minutes= line['time']%100;
var code= line['code'].substring(1,5);
if(code.charAt(0)=='0')
code=code.substring(1,4);
temp={"stop":stop['name'].split(",")[0],
"dist":stop['dist'],
"bus":code,
"date":date,
"time":pad(hours,2)+":"+pad(minutes,2),
"laststop":dict[line['code']].split(",")[0].split(" ")[0]
};
var trigger=true;
for(var objectIndex= $scope.arr.length-1;objectIndex>=0;objectIndex--)
if( $scope.arr[objectIndex]['bus']==temp['bus'] && $scope.arr[objectIndex]['laststop']==temp['laststop']){
if( $scope.arr[objectIndex]['dist']==temp['dist']){
break;
}
else if( $scope.arr[i]['dist'] > z['dist']){
$scope.arr.splice(i,1);
else if( $scope.arr[objectIndex]['dist'] > temp['dist']){
$scope.arr.splice(objectIndex,1);
}
else
e=false;
}
if(e){
$scope.arr.push(z);
trigger=false;
}
if(trigger){
$scope.arr.push(temp);
}
}
@@ -146,7 +159,8 @@ app.controller('timetableCtrl',
}
}
load();
var t=$interval(delOld,2000);
var z=$interval(load,60000);
var inter1=$interval(delOld,2000);
var inter2=$interval(load,10000);
}
);