Code refactoring and few bug fixes
This commit is contained in:
parent
95e3e7cad6
commit
a2ba79205a
5 changed files with 404 additions and 416 deletions
|
@ -18,10 +18,9 @@ Rectangle{
|
|||
property int absoluteHour: parseInt(dialog.absoluteHour, 10)
|
||||
property int absoluteMinute: parseInt(dialog.absoluteMinute, 10)
|
||||
property alias triggerstate: trigger.state
|
||||
property variant parentPoint
|
||||
property variant parentPoint: undefined
|
||||
property variant pointId
|
||||
property variant lastRun: 0;
|
||||
//property int parentPointAbsoluteHour //TEST changed from int, want "undefined"
|
||||
property alias deviceRow: pointRect.parent
|
||||
property variant selectedDate: (deviceRow == null || deviceRow == undefined) ? new Date() : deviceRow.selectedDate
|
||||
|
||||
|
@ -32,7 +31,6 @@ Rectangle{
|
|||
var dynamicBar = actionBar.createObject(pointRect)
|
||||
dynamicBar.hangOnToPoint = pointRect
|
||||
dynamicBar.state = "pointLoaded"
|
||||
//pointRect.hangOnToBar = dynamicBar
|
||||
}
|
||||
|
||||
//use item instead of rectangle (no border then though) to make it invisible (opacity: 0)
|
||||
|
@ -418,6 +416,7 @@ Rectangle{
|
|||
function remove(keepDialogOpen, ignoreParent){
|
||||
if(keepDialogOpen == undefined && ignoreParent == undefined && pointRect.parentPoint != undefined){
|
||||
//remove from parent instead
|
||||
print(pointRect.parentPoint);
|
||||
pointRect.parentPoint.remove();
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -95,24 +95,25 @@ function updateParentsInChildList(newParentPoint){
|
|||
function updateChildPoints(){
|
||||
|
||||
var children;
|
||||
var localParentPoint;
|
||||
if(pointRect.parentPoint != undefined){
|
||||
children = pointRect.parentPoint.getChildPoints();
|
||||
parentPoint = pointRect.parentPoint;
|
||||
localParentPoint = pointRect.parentPoint;
|
||||
}
|
||||
else{
|
||||
children = getChildPoints();
|
||||
parentPoint = pointRect;
|
||||
localParentPoint = pointRect;
|
||||
}
|
||||
|
||||
for(var point in children){
|
||||
children[point].absoluteHour = parentPoint.absoluteHour;
|
||||
children[point].absoluteMinute = parentPoint.absoluteMinute;
|
||||
children[point].fuzzyBefore = parentPoint.fuzzyBefore;
|
||||
children[point].fuzzyAfter = parentPoint.fuzzyAfter;
|
||||
children[point].offset = parentPoint.offset;
|
||||
children[point].triggerstate = parentPoint.triggerstate;
|
||||
children[point].dimvalue = parentPoint.dimvalue;
|
||||
children[point].state = parentPoint.state;
|
||||
children[point].absoluteHour = localParentPoint.absoluteHour;
|
||||
children[point].absoluteMinute = localParentPoint.absoluteMinute;
|
||||
children[point].fuzzyBefore = localParentPoint.fuzzyBefore;
|
||||
children[point].fuzzyAfter = localParentPoint.fuzzyAfter;
|
||||
children[point].offset = localParentPoint.offset;
|
||||
children[point].triggerstate = localParentPoint.triggerstate;
|
||||
children[point].dimvalue = localParentPoint.dimvalue;
|
||||
children[point].state = localParentPoint.state;
|
||||
if(children[point].triggerstate == "absolute"){
|
||||
children[point].x = children[point].getAbsoluteXValue();
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@ import "mainscripts.js" as MainScripts
|
|||
width: mainWidth
|
||||
height: mainHeight
|
||||
property int dayListHeaderHeight: 15
|
||||
property variant selectedDate: Scripts.getCurrentDate(); //Maybe just today
|
||||
property variant selectedDate: MainScripts.getCurrentDate(); //Maybe just today
|
||||
property variant sunData: MainScripts.getSunData();
|
||||
|
||||
Component.onCompleted: {
|
||||
|
@ -22,17 +22,17 @@ import "mainscripts.js" as MainScripts
|
|||
var currentDay = new Date(startday);
|
||||
currentDay.setDate(startday.getDate() + i);
|
||||
dynamicDay.daydate = currentDay;
|
||||
Scripts.addDay(dynamicDay);
|
||||
MainScripts.addDay(dynamicDay);
|
||||
}
|
||||
dynamicDay.state = "visible" //set last day (today) as visible
|
||||
weekDayText.text = Scripts.getCurrentDayName()
|
||||
Scripts.updateDeviceIndex();
|
||||
Scripts.setLoading();
|
||||
weekDayText.text = MainScripts.getCurrentDayName()
|
||||
MainScripts.updateDeviceIndex();
|
||||
MainScripts.setLoading();
|
||||
var updateLastRunFunc = updateLastRun;
|
||||
restoreJobs.callWith(updateLastRunFunc);
|
||||
Scripts.initiateStoredPointsInGUI();
|
||||
Scripts.endLoading();
|
||||
Scripts.updateEndsWith();
|
||||
MainScripts.initiateStoredPointsInGUI();
|
||||
MainScripts.endLoading();
|
||||
MainScripts.updateEndsWith();
|
||||
}
|
||||
|
||||
Rectangle{
|
||||
|
@ -47,7 +47,7 @@ import "mainscripts.js" as MainScripts
|
|||
anchors.verticalCenter: weekDayText.verticalCenter
|
||||
arrowText: "<-"
|
||||
onClicked: {
|
||||
Scripts.decrementCurrentDay();
|
||||
MainScripts.decrementCurrentDay();
|
||||
}
|
||||
}
|
||||
Text{
|
||||
|
@ -60,7 +60,7 @@ import "mainscripts.js" as MainScripts
|
|||
anchors.verticalCenter: weekDayText.verticalCenter
|
||||
arrowText: "->"
|
||||
onClicked: {
|
||||
Scripts.incrementCurrentDay();
|
||||
MainScripts.incrementCurrentDay();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -194,7 +194,7 @@ import "mainscripts.js" as MainScripts
|
|||
property int deviceId: modelData.id;
|
||||
property alias continuingBar: continuingBar
|
||||
property variant selectedDate: main.selectedDate
|
||||
property int currentDayIndex: Scripts.getCurrentDayIndex(main.selectedDate)
|
||||
property int currentDayIndex: MainScripts.getCurrentDayIndex(main.selectedDate)
|
||||
|
||||
state: "enabled"
|
||||
|
||||
|
@ -230,9 +230,9 @@ import "mainscripts.js" as MainScripts
|
|||
dynamicPoint.addActiveState("bell");
|
||||
dynamicPoint.setFirstState();
|
||||
dynamicPoint.pointId = new Date().getTime(); //just needed for storage update
|
||||
|
||||
deviceRow.updateContinuingBars();
|
||||
dialog.show(dynamicPoint)
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -251,11 +251,11 @@ import "mainscripts.js" as MainScripts
|
|||
|
||||
//device functions:
|
||||
function createChildPoint(index, pointRect, deviceId){
|
||||
return Scripts.createChildPoint(index, pointRect, deviceId);
|
||||
return MainScripts.createChildPoint(index, pointRect, deviceId);
|
||||
}
|
||||
|
||||
function getDeviceRow(dayIndex, deviceId){
|
||||
return Scripts.getDeviceRow(dayIndex, deviceId);
|
||||
return MainScripts.getDeviceRow(dayIndex, deviceId);
|
||||
}
|
||||
|
||||
function hasPoints(){
|
||||
|
@ -263,7 +263,7 @@ import "mainscripts.js" as MainScripts
|
|||
}
|
||||
|
||||
function isLoading(){
|
||||
return Scripts.isLoading();
|
||||
return MainScripts.isLoading();
|
||||
}
|
||||
|
||||
function setChanged(){
|
||||
|
@ -271,7 +271,7 @@ import "mainscripts.js" as MainScripts
|
|||
}
|
||||
|
||||
function updateContinuingBars(){
|
||||
Scripts.updateEndsWith();
|
||||
MainScripts.updateEndsWith();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -367,7 +367,7 @@ import "mainscripts.js" as MainScripts
|
|||
}
|
||||
|
||||
function saveAll(){
|
||||
var days = Scripts.getDays();
|
||||
var days = MainScripts.getDays();
|
||||
if(dialog.dialogOpacity == 1){
|
||||
MainScripts.setChanged(dialog.actionPoint.deviceRow.deviceId, true); //set the devicerow that the currently visible dialog is connected to as dirty
|
||||
}
|
||||
|
@ -380,9 +380,9 @@ import "mainscripts.js" as MainScripts
|
|||
}
|
||||
MainScripts.setChanged(deviceId, false); //reset hasChanged-status
|
||||
|
||||
if(Scripts.deviceIsEnabled(deviceId)){ //if device is disabled, don't add any points to schedule (but remove current)
|
||||
if(MainScripts.deviceIsEnabled(deviceId)){ //if device is disabled, don't add any points to schedule (but remove current)
|
||||
for(var j=0;j<days.length;j++){
|
||||
var row = Scripts.getDeviceRow(days[j].daydate.getDay(), deviceId);
|
||||
var row = MainScripts.getDeviceRow(days[j].daydate.getDay(), deviceId);
|
||||
for(var k=0;k<row.children.length;k++){
|
||||
var point = row.children[k];
|
||||
if(point.isPoint && point.parentPoint == undefined){ //and not disabled
|
||||
|
@ -400,17 +400,17 @@ import "mainscripts.js" as MainScripts
|
|||
}
|
||||
|
||||
function updateCurrentDay(){
|
||||
main.selectedDate = Scripts.getCurrentDate();
|
||||
main.selectedDate = MainScripts.getCurrentDate();
|
||||
main.sunData = updateSunData.callWith(main.selectedDate);
|
||||
MainScripts.updateSunData(main.sunData);
|
||||
weekDayText.text = Scripts.getCurrentDayName();
|
||||
weekDayText.text = MainScripts.getCurrentDayName();
|
||||
}
|
||||
|
||||
function updateEndsWith(){
|
||||
Scripts.updateEndsWith();
|
||||
MainScripts.updateEndsWith();
|
||||
}
|
||||
|
||||
function updateLastRun(deviceId, day, pointId, lastRun){
|
||||
Scripts.updateLastRun(deviceId, day, pointId, lastRun);
|
||||
MainScripts.updateLastRun(deviceId, day, pointId, lastRun);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -129,6 +129,84 @@ function willSunSet(){
|
|||
}
|
||||
|
||||
|
||||
//INIT:
|
||||
function initiateStoredPointsInGUI(){
|
||||
for(var devicekey in storedPoints){
|
||||
for(var i=0;i<storedPoints[devicekey].length;i++){
|
||||
addPointToGUI(devicekey, storedPoints[devicekey][i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function addPointToGUI(key, job){
|
||||
if(job == undefined){
|
||||
return;
|
||||
}
|
||||
var deviceId = key;
|
||||
var jobdata = job.v;
|
||||
var state = getStateFromMethod.callWith(jobdata.method);
|
||||
var activeStates = new Array("on", "off", "dim", "bell"); //TODO get dynamically, depending on device...
|
||||
var dimvalue = jobdata.value;
|
||||
var absoluteTime = jobdata.absoluteTime;
|
||||
var pointId = jobdata.id;
|
||||
print("POINTID: " + jobdata.id);
|
||||
var lastRun = jobdata.lastRun;
|
||||
print("Adding point to GUI with lastrun: " + lastRun);
|
||||
var events = jobdata.events;
|
||||
var parentPoint;
|
||||
|
||||
for(var key in events){
|
||||
var eventdata = events[key].d;
|
||||
var dayIndex = eventdata.value;
|
||||
var dayOfWeek = getDayIndexForDayOfWeek(dayIndex); //set dayOfWeek to correct index in the days-table
|
||||
|
||||
print("Inserting point at: " + weekday_name_array[days[dayOfWeek].daydate.getDay()] + " (" + dayOfWeek + ")" + ", id: " + deviceId);
|
||||
|
||||
var pointParentDevice = getDeviceRow(dayOfWeek, deviceId);
|
||||
|
||||
var component = Qt.createComponent("ActionPoint.qml");
|
||||
var dynamicPoint = component.createObject(pointParentDevice);
|
||||
|
||||
if(parentPoint == undefined){
|
||||
//set common values
|
||||
var time = getTimeFromSeconds(absoluteTime); //eventdata.time);
|
||||
dynamicPoint.absoluteHour = time[0]; //same time for all
|
||||
dynamicPoint.absoluteMinute = time[1]; //same time for all
|
||||
dynamicPoint.triggerstate = getTriggerstateFromType.callWith(eventdata.type);
|
||||
dynamicPoint.fuzzyBefore = eventdata.fuzzinessBefore/60;
|
||||
dynamicPoint.fuzzyAfter = eventdata.fuzzinessAfter/60;
|
||||
dynamicPoint.offset = eventdata.offset/60;
|
||||
dynamicPoint.lastRun = lastRun;
|
||||
if(dynamicPoint.triggerstate == "absolute"){
|
||||
dynamicPoint.x = dynamicPoint.getAbsoluteXValue();
|
||||
}
|
||||
dynamicPoint.setActiveStates(activeStates); //TODO: active states depending on the device (get this from __init__ etc)
|
||||
dynamicPoint.setFirstState(state);
|
||||
dynamicPoint.dimvalue = dimvalue * (100/255);
|
||||
dynamicPoint.pointId = pointId;
|
||||
parentPoint = dynamicPoint;
|
||||
}
|
||||
else{
|
||||
dynamicPoint.parentPoint = parentPoint;
|
||||
dynamicPoint.setActiveStates(parentPoint.getActiveStates());
|
||||
parentPoint.addChildPoint(dayIndex, dynamicPoint);
|
||||
}
|
||||
|
||||
dynamicPoint.border.color = "blue"; //default blue at the moment
|
||||
|
||||
}
|
||||
|
||||
parentPoint.updateChildPoints(); //if any child points exists, update them with parent values
|
||||
}
|
||||
|
||||
function getTimeFromSeconds(seconds){
|
||||
var totalMinutes = seconds/60;
|
||||
var minutes = totalMinutes%60;
|
||||
var hours = Math.floor(totalMinutes/60);
|
||||
return [hours, minutes];
|
||||
}
|
||||
|
||||
|
||||
//DEVICE PROPERTIES:
|
||||
|
||||
var deviceProperties = {};
|
||||
|
@ -142,6 +220,10 @@ function deviceEnabled(deviceId, enabled){
|
|||
setChanged(deviceId, true);
|
||||
}
|
||||
|
||||
function deviceIsEnabled(deviceId){
|
||||
return days[0].children[0].children[deviceIndex[deviceId]].state == "enabled";
|
||||
}
|
||||
|
||||
function getDeviceTimerKeys(deviceId){
|
||||
var device = deviceProperties[deviceId];
|
||||
return device == undefined ? {} : device["timerkeys"];
|
||||
|
@ -165,4 +247,266 @@ function setChanged(deviceId, change){
|
|||
deviceProperties[deviceId] = {};
|
||||
}
|
||||
deviceProperties[deviceId]["hasChanged"] = change;
|
||||
}
|
||||
|
||||
|
||||
//DEVICE INDEX:
|
||||
|
||||
var deviceIndex = [];
|
||||
|
||||
function assignContinuingBarProperties(deviceRow, previousEndPoint, dayIndex, firstRow){
|
||||
|
||||
if(previousEndPoint == undefined){ //the first has no point to bind to
|
||||
deviceRow.continuingBar.prevDayColor = "white";
|
||||
deviceRow.continuingBar.prevDayOpacity = 0;
|
||||
deviceRow.continuingBar.prevDayWidth = 0;
|
||||
}
|
||||
else{
|
||||
deviceRow.continuingBar.prevDayColor = previousEndPoint.actionTypeColor;
|
||||
if(previousEndPoint.state == "dim"){
|
||||
deviceRow.continuingBar.prevDayOpacity = previousEndPoint.dimvalue/100;
|
||||
}
|
||||
else{
|
||||
deviceRow.continuingBar.prevDayOpacity = previousEndPoint.actionTypeOpacity;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if(deviceRow.hasPoints()){
|
||||
deviceRow.endPoint = getEndsWith(deviceRow.children, days[dayIndex].daydate.getDay(), deviceRow.deviceId);
|
||||
previousEndPoint = deviceRow.endPoint;
|
||||
deviceRow.continuingBar.prevDayWidth = 0;
|
||||
deviceRow.continuingBar.state = "continuingWithLimitedWidth";
|
||||
}
|
||||
else{
|
||||
deviceRow.continuingBar.state = "continuing";
|
||||
deviceRow.endPoint = previousEndPoint;
|
||||
deviceRow.continuingBar.prevDayWidth = deviceRow.width;
|
||||
}
|
||||
|
||||
return previousEndPoint;
|
||||
}
|
||||
|
||||
function getEndsWith(pointList, dayIndex, deviceId){
|
||||
var prevPoint = null;
|
||||
for(var i=0;i<pointList.length;i++){
|
||||
if(pointList[i].isPoint != undefined && pointList[i].isPoint == "true"){
|
||||
if((prevPoint == null || pointList[i].x > prevPoint.x) && pointList[i].state != "bell"){ //TODO when more than "bell", make dynamic
|
||||
prevPoint = pointList[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(prevPoint == null){
|
||||
dayIndex = dayIndex - 1;
|
||||
if(dayIndex == -1){ //too far, begin from end again
|
||||
dayIndex = days.length - 1;
|
||||
}
|
||||
|
||||
var prevDayDevice = getDeviceRow(dayIndex, deviceId);
|
||||
if(prevDayDevice == undefined){
|
||||
return null;
|
||||
}
|
||||
return prevDayDevice.endPoint;
|
||||
}
|
||||
if(prevPoint.state == "off"){
|
||||
return null;
|
||||
}
|
||||
return prevPoint; //only on or dim
|
||||
}
|
||||
|
||||
function updateDeviceIndex(){ //TODO, better way, please...
|
||||
deviceIndex = []; //empty list
|
||||
var startIndex = 0;
|
||||
for(var i=0;i<days[0].children[0].children.length;i++){
|
||||
var deviceListItem = days[0].children[0].children[i];
|
||||
if(deviceListItem.deviceId != undefined){
|
||||
startIndex = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
for(var i=0;i<deviceModel.length;i++){
|
||||
deviceIndex[deviceModel.get(i).id] = i + startIndex;
|
||||
}
|
||||
}
|
||||
|
||||
function updateEndsWith(){
|
||||
updateDeviceIndex(); //TODO needed?
|
||||
for(var device in deviceIndex){
|
||||
//for each device, order doesn't matter
|
||||
var previousEndPoint = undefined;
|
||||
//loop through days, beginning with oldest, in search for the first Point
|
||||
var startIndex = 0;
|
||||
for(var dayIndex=0;dayIndex<days.length;dayIndex++){
|
||||
var deviceRow = days[dayIndex].children[0].children[(parseInt(deviceIndex[device]))]; //+1 TODO property somehow? Or function...
|
||||
|
||||
if(deviceRow.hasPoints()){
|
||||
startIndex = dayIndex;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//Second loop, start from first point
|
||||
for(var i=0;i<days.length;i++){
|
||||
var dayIndex = i + startIndex;
|
||||
if(dayIndex > days.length-1){
|
||||
dayIndex = dayIndex - days.length;
|
||||
}
|
||||
|
||||
var deviceRow = days[dayIndex].children[0].children[parseInt(deviceIndex[device])];
|
||||
|
||||
previousEndPoint = assignContinuingBarProperties(deviceRow, previousEndPoint, dayIndex, i==0);
|
||||
|
||||
if(i == days.length-1){
|
||||
//last one, bind the first one too then
|
||||
deviceRow = days[startIndex].children[0].children[parseInt(deviceIndex[device])];
|
||||
assignContinuingBarProperties(deviceRow, previousEndPoint, dayIndex, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//DAYS:
|
||||
|
||||
var weekday_name_array = new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");
|
||||
var currentDayIndex = 6; //Today...
|
||||
var days = new Array();
|
||||
|
||||
function addDay(day){
|
||||
days.push(day);
|
||||
}
|
||||
|
||||
function decrementCurrentDay(){
|
||||
days[currentDayIndex].state = "hiddenRight";
|
||||
var workDate = days[currentDayIndex].daydate;
|
||||
workDate.setDate(workDate.getDate() - 7);
|
||||
days[currentDayIndex].daydate = workDate;
|
||||
if(currentDayIndex == 0){
|
||||
currentDayIndex = days.length - 1;
|
||||
}
|
||||
else{
|
||||
currentDayIndex--;
|
||||
}
|
||||
days[currentDayIndex].state = "hiddenLeft"; //place on right side of center, for correct slid
|
||||
days[currentDayIndex].state = "visible";
|
||||
}
|
||||
|
||||
function getCurrentDay(){
|
||||
return days[currentDayIndex];
|
||||
}
|
||||
|
||||
function getCurrentDayIndex(dummyvalue){
|
||||
//by sending in this dummyvalue, this function will be evaluated when that value is changed...
|
||||
return currentDayIndex;
|
||||
}
|
||||
|
||||
function getCurrentDate(){
|
||||
if(days.length < 7){
|
||||
//not initiated yet
|
||||
return new Date(); //now
|
||||
}
|
||||
var date = new Date(days[currentDayIndex].daydate);
|
||||
return date;
|
||||
}
|
||||
|
||||
function getCurrentDayName(){
|
||||
var day = getCurrentDay().daydate;
|
||||
return weekday_name_array[day.getDay()] + " " + day.getDate();
|
||||
}
|
||||
|
||||
function getDayIndexForDayOfWeek(dayOfWeek){
|
||||
var offset = days[0].daydate.getDay();
|
||||
dayOfWeek = days.length - offset + parseInt(dayOfWeek);
|
||||
if(dayOfWeek == -1){
|
||||
dayOfWeek = days.length - 1;
|
||||
}
|
||||
if(dayOfWeek > days.length-1){
|
||||
dayOfWeek = dayOfWeek - days.length;
|
||||
}
|
||||
return dayOfWeek;
|
||||
}
|
||||
|
||||
function getDays(){
|
||||
return days;
|
||||
}
|
||||
|
||||
function incrementCurrentDay(){
|
||||
days[currentDayIndex].state = "hiddenLeft";
|
||||
var workDate = days[currentDayIndex].daydate;
|
||||
workDate.setDate(workDate.getDate() + 1);
|
||||
if(currentDayIndex == (days.length - 1)){
|
||||
currentDayIndex = 0;
|
||||
}
|
||||
else{
|
||||
currentDayIndex++;
|
||||
}
|
||||
days[currentDayIndex].daydate = workDate;
|
||||
days[currentDayIndex].state = "hiddenRight"; //place on right side of center, for correct slide
|
||||
days[currentDayIndex].state = "visible";
|
||||
}
|
||||
|
||||
function updateLastRun(deviceId, day, pointId, lastRun){
|
||||
day = getDayIndexForDayOfWeek(day);
|
||||
var row = getDeviceRow(day,deviceId);
|
||||
for(var k=0;k<row.children.length;k++){
|
||||
var point = row.children[k];
|
||||
if(point.isPoint && point.parentPoint == undefined && point.pointId == pointId){ //and not disabled
|
||||
point.lastRun = lastRun;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//OTHER:
|
||||
|
||||
function getDeviceRow(dayOfWeek, deviceId){
|
||||
var dayListViewComp = days[dayOfWeek];
|
||||
if(dayListViewComp == undefined){
|
||||
print("DayListViewComp undefined");
|
||||
return null;
|
||||
}
|
||||
var currentDeviceIndex = deviceIndex[deviceId];
|
||||
if(dayListViewComp.children.length == undefined){
|
||||
return null;
|
||||
}
|
||||
var pointParent = dayListViewComp.children[0].children[currentDeviceIndex];
|
||||
return pointParent;
|
||||
}
|
||||
|
||||
function createChildPoint(index, pointRect, deviceId){
|
||||
index = getDayIndexForDayOfWeek(index);
|
||||
var deviceRow = getDeviceRow(index, deviceId);
|
||||
var component = Qt.createComponent("ActionPoint.qml");
|
||||
var dynamicPoint = component.createObject(deviceRow);
|
||||
dynamicPoint.absoluteHour = pointRect.absoluteHour;
|
||||
dynamicPoint.absoluteMinute = pointRect.absoluteMinute;
|
||||
dynamicPoint.fuzzyBefore = pointRect.fuzzyBefore;
|
||||
dynamicPoint.fuzzyAfter = pointRect.fuzzyAfter;
|
||||
dynamicPoint.offset = pointRect.offset;
|
||||
dynamicPoint.dimvalue = pointRect.dimvalue;
|
||||
|
||||
dynamicPoint.parentPoint = pointRect
|
||||
dynamicPoint.x = dynamicPoint.getAbsoluteXValue();
|
||||
dynamicPoint.triggerstate = pointRect.triggerstate;
|
||||
dynamicPoint.border.color = "blue"
|
||||
dynamicPoint.setActiveStates(pointRect.getActiveStates());
|
||||
|
||||
dynamicPoint.setFirstState(pointRect.state);
|
||||
return dynamicPoint;
|
||||
}
|
||||
|
||||
|
||||
//LOADING:
|
||||
var loading = false;
|
||||
function setLoading(){
|
||||
loading = true;
|
||||
}
|
||||
|
||||
function endLoading(){
|
||||
loading = false;
|
||||
}
|
||||
|
||||
function isLoading(){
|
||||
return loading;
|
||||
}
|
|
@ -1,323 +1,6 @@
|
|||
var deviceIndex = [];
|
||||
|
||||
//from main:
|
||||
var weekday_name_array = new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"); //TODO share this with mainscripts.js
|
||||
|
||||
|
||||
//Days:
|
||||
var weekday_name_array = new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday")
|
||||
var currentDayIndex = 6; //Today...
|
||||
var days = new Array();
|
||||
|
||||
function addDay(day){
|
||||
days.push(day);
|
||||
}
|
||||
|
||||
function decrementCurrentDay(){
|
||||
print("Currentdayindex: " + currentDayIndex);
|
||||
days[currentDayIndex].state = "hiddenRight";
|
||||
var workDate = days[currentDayIndex].daydate;
|
||||
workDate.setDate(workDate.getDate() - 7);
|
||||
days[currentDayIndex].daydate = workDate;
|
||||
if(currentDayIndex == 0){
|
||||
currentDayIndex = days.length - 1;
|
||||
}
|
||||
else{
|
||||
currentDayIndex--;
|
||||
}
|
||||
days[currentDayIndex].state = "hiddenLeft"; //place on right side of center, for correct slid
|
||||
days[currentDayIndex].state = "visible";
|
||||
}
|
||||
|
||||
function getCurrentDay(){
|
||||
return days[currentDayIndex];
|
||||
}
|
||||
|
||||
function getCurrentDayIndex(dummyvalue){
|
||||
//by sending in this dummyvalue, this function will be evaluated when that value is changed...
|
||||
return currentDayIndex;
|
||||
}
|
||||
|
||||
function getCurrentDate(){
|
||||
if(days.length < 7){
|
||||
//not initiated yet
|
||||
return new Date(); //now
|
||||
}
|
||||
var date = new Date(days[currentDayIndex].daydate);
|
||||
return date;
|
||||
}
|
||||
|
||||
function getCurrentDayName(){
|
||||
var day = getCurrentDay().daydate;
|
||||
return weekday_name_array[day.getDay()] + " " + day.getDate();
|
||||
}
|
||||
|
||||
function getDays(){
|
||||
return days;
|
||||
}
|
||||
|
||||
function incrementCurrentDay(){
|
||||
days[currentDayIndex].state = "hiddenLeft";
|
||||
var workDate = days[currentDayIndex].daydate;
|
||||
workDate.setDate(workDate.getDate() + 1);
|
||||
if(currentDayIndex == (days.length - 1)){
|
||||
currentDayIndex = 0;
|
||||
}
|
||||
else{
|
||||
currentDayIndex++;
|
||||
}
|
||||
days[currentDayIndex].daydate = workDate;
|
||||
days[currentDayIndex].state = "hiddenRight"; //place on right side of center, for correct slide
|
||||
days[currentDayIndex].state = "visible";
|
||||
}
|
||||
|
||||
//Other:
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function updateDeviceIndex(){ //TODO, better way, please...
|
||||
deviceIndex = []; //empty list
|
||||
var startIndex = 0;
|
||||
for(var i=0;i<days[0].children[0].children.length;i++){
|
||||
var deviceListItem = days[0].children[0].children[i];
|
||||
if(deviceListItem.deviceId != undefined){
|
||||
startIndex = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
for(var i=0;i<deviceModel.length;i++){
|
||||
deviceIndex[deviceModel.get(i).id] = i + startIndex;
|
||||
}
|
||||
}
|
||||
|
||||
function updateEndsWith(){
|
||||
updateDeviceIndex(); //TODO needed?
|
||||
for(var device in deviceIndex){
|
||||
//for each device, order doesn't matter
|
||||
var previousEndPoint = undefined;
|
||||
//loop through days, beginning with oldest, in search for the first Point
|
||||
var startIndex = 0;
|
||||
for(var dayIndex=0;dayIndex<days.length;dayIndex++){
|
||||
var deviceRow = days[dayIndex].children[0].children[(parseInt(deviceIndex[device]))]; //+1 TODO property somehow? Or function...
|
||||
|
||||
if(deviceRow.hasPoints()){
|
||||
startIndex = dayIndex;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//Second loop, start from first point
|
||||
for(var i=0;i<days.length;i++){
|
||||
var dayIndex = i + startIndex;
|
||||
if(dayIndex > days.length-1){
|
||||
dayIndex = dayIndex - days.length;
|
||||
}
|
||||
|
||||
var deviceRow = days[dayIndex].children[0].children[parseInt(deviceIndex[device])];
|
||||
|
||||
previousEndPoint = assignContinuingBarProperties(deviceRow, previousEndPoint, dayIndex, i==0);
|
||||
|
||||
if(i == days.length-1){
|
||||
//last one, bind the first one too then
|
||||
deviceRow = days[startIndex].children[0].children[parseInt(deviceIndex[device])];
|
||||
assignContinuingBarProperties(deviceRow, previousEndPoint, dayIndex, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function assignContinuingBarProperties(deviceRow, previousEndPoint, dayIndex, firstRow){
|
||||
|
||||
if(previousEndPoint == undefined){ //the first has no point to bind to
|
||||
deviceRow.continuingBar.prevDayColor = "white";
|
||||
deviceRow.continuingBar.prevDayOpacity = 0;
|
||||
deviceRow.continuingBar.prevDayWidth = 0;
|
||||
}
|
||||
else{
|
||||
deviceRow.continuingBar.prevDayColor = previousEndPoint.actionTypeColor;
|
||||
if(previousEndPoint.state == "dim"){
|
||||
deviceRow.continuingBar.prevDayOpacity = previousEndPoint.dimvalue/100;
|
||||
}
|
||||
else{
|
||||
deviceRow.continuingBar.prevDayOpacity = previousEndPoint.actionTypeOpacity;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if(deviceRow.hasPoints()){
|
||||
deviceRow.endPoint = getEndsWith(deviceRow.children, days[dayIndex].daydate.getDay(), deviceRow.deviceId);
|
||||
previousEndPoint = deviceRow.endPoint;
|
||||
deviceRow.continuingBar.prevDayWidth = 0;
|
||||
deviceRow.continuingBar.state = "continuingWithLimitedWidth";
|
||||
}
|
||||
else{
|
||||
deviceRow.continuingBar.state = "continuing";
|
||||
deviceRow.endPoint = previousEndPoint;
|
||||
deviceRow.continuingBar.prevDayWidth = deviceRow.width;
|
||||
}
|
||||
|
||||
return previousEndPoint;
|
||||
}
|
||||
|
||||
//Init:
|
||||
function initiateStoredPointsInGUI(){
|
||||
for(var devicekey in storedPoints){
|
||||
for(var i=0;i<storedPoints[devicekey].length;i++){
|
||||
addPointToGUI(devicekey, storedPoints[devicekey][i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function addPointToGUI(key, job){
|
||||
if(job == undefined){
|
||||
return;
|
||||
}
|
||||
var deviceId = key;
|
||||
var jobdata = job.v;
|
||||
var state = getStateFromMethod.callWith(jobdata.method);
|
||||
var activeStates = new Array("on", "off", "dim", "bell"); //TODO get dynamically, depending on device...
|
||||
var dimvalue = jobdata.value;
|
||||
var absoluteTime = jobdata.absoluteTime;
|
||||
var pointId = jobdata.id;
|
||||
print("POINTID: " + jobdata.id);
|
||||
var lastRun = jobdata.lastRun;
|
||||
print("Adding point to GUI with lastrun: " + lastRun);
|
||||
var events = jobdata.events;
|
||||
var parentPoint;
|
||||
|
||||
for(var key in events){
|
||||
var eventdata = events[key].d;
|
||||
var dayIndex = eventdata.value;
|
||||
var dayOfWeek = getDayIndexForDayOfWeek(dayIndex); //set dayOfWeek to correct index in the days-table
|
||||
|
||||
print("Inserting point at: " + weekday_name_array[days[dayOfWeek].daydate.getDay()] + " (" + dayOfWeek + ")" + ", id: " + deviceId);
|
||||
|
||||
var pointParentDevice = getDeviceRow(dayOfWeek, deviceId);
|
||||
|
||||
var component = Qt.createComponent("ActionPoint.qml");
|
||||
var dynamicPoint = component.createObject(pointParentDevice);
|
||||
|
||||
if(parentPoint == undefined){
|
||||
//set common values
|
||||
var time = getTimeFromSeconds(absoluteTime); //eventdata.time);
|
||||
dynamicPoint.absoluteHour = time[0]; //same time for all
|
||||
dynamicPoint.absoluteMinute = time[1]; //same time for all
|
||||
dynamicPoint.triggerstate = getTriggerstateFromType.callWith(eventdata.type);
|
||||
dynamicPoint.fuzzyBefore = eventdata.fuzzinessBefore/60;
|
||||
dynamicPoint.fuzzyAfter = eventdata.fuzzinessAfter/60;
|
||||
dynamicPoint.offset = eventdata.offset/60;
|
||||
dynamicPoint.lastRun = lastRun;
|
||||
if(dynamicPoint.triggerstate == "absolute"){
|
||||
dynamicPoint.x = dynamicPoint.getAbsoluteXValue();
|
||||
}
|
||||
dynamicPoint.setActiveStates(activeStates); //TODO: active states depending on the device (get this from __init__ etc)
|
||||
dynamicPoint.setFirstState(state);
|
||||
dynamicPoint.dimvalue = dimvalue * (100/255);
|
||||
dynamicPoint.pointId = pointId;
|
||||
parentPoint = dynamicPoint;
|
||||
}
|
||||
else{
|
||||
dynamicPoint.parentPoint = parentPoint;
|
||||
dynamicPoint.setActiveStates(parentPoint.getActiveStates());
|
||||
parentPoint.addChildPoint(dayIndex, dynamicPoint);
|
||||
}
|
||||
|
||||
dynamicPoint.border.color = "blue"; //default blue at the moment
|
||||
|
||||
}
|
||||
|
||||
parentPoint.updateChildPoints(); //if any child points exists, update them with parent values
|
||||
}
|
||||
|
||||
|
||||
//End init
|
||||
|
||||
//must be run in "main"
|
||||
function getDeviceRow(dayOfWeek, deviceId){
|
||||
var dayListViewComp = days[dayOfWeek];
|
||||
if(dayListViewComp == undefined){
|
||||
print("DayListViewComp undefined");
|
||||
return null;
|
||||
}
|
||||
var currentDeviceIndex = deviceIndex[deviceId];
|
||||
if(dayListViewComp.children.length == undefined){
|
||||
return null;
|
||||
}
|
||||
//print("DeviceIndex: " + currentDeviceIndex + " och " + deviceId + ", och sedan " + days.length);
|
||||
var pointParent = dayListViewComp.children[0].children[currentDeviceIndex];
|
||||
return pointParent;
|
||||
}
|
||||
|
||||
function createChildPoint(index, pointRect, deviceId){
|
||||
index = getDayIndexForDayOfWeek(index);
|
||||
var deviceRow = getDeviceRow(index, deviceId);
|
||||
var component = Qt.createComponent("ActionPoint.qml");
|
||||
var dynamicPoint = component.createObject(deviceRow);
|
||||
dynamicPoint.absoluteHour = pointRect.absoluteHour;
|
||||
dynamicPoint.absoluteMinute = pointRect.absoluteMinute;
|
||||
dynamicPoint.fuzzyBefore = pointRect.fuzzyBefore;
|
||||
dynamicPoint.fuzzyAfter = pointRect.fuzzyAfter;
|
||||
dynamicPoint.offset = pointRect.offset;
|
||||
dynamicPoint.dimvalue = pointRect.dimvalue;
|
||||
|
||||
dynamicPoint.parentPoint = pointRect
|
||||
dynamicPoint.x = dynamicPoint.getAbsoluteXValue();
|
||||
dynamicPoint.triggerstate = pointRect.triggerstate;
|
||||
dynamicPoint.border.color = "blue"
|
||||
dynamicPoint.setActiveStates(pointRect.getActiveStates());
|
||||
|
||||
/*
|
||||
dynamicPoint.addActiveState("on"); //TODO, add same states as in pointRect
|
||||
dynamicPoint.addActiveState("off");
|
||||
dynamicPoint.addActiveState("dim");
|
||||
dynamicPoint.addActiveState("bell");
|
||||
*/
|
||||
dynamicPoint.setFirstState(pointRect.state);
|
||||
//print("RETURNING " + dynamicPoint);
|
||||
return dynamicPoint;
|
||||
}
|
||||
|
||||
var loading = false;
|
||||
function setLoading(){
|
||||
loading = true;
|
||||
}
|
||||
|
||||
function endLoading(){
|
||||
loading = false;
|
||||
}
|
||||
|
||||
function isLoading(){
|
||||
return loading;
|
||||
}
|
||||
|
||||
function getDayIndexForDayOfWeek(dayOfWeek){
|
||||
var offset = days[0].daydate.getDay();
|
||||
dayOfWeek = days.length - offset + parseInt(dayOfWeek);
|
||||
if(dayOfWeek == -1){
|
||||
dayOfWeek = days.length - 1;
|
||||
}
|
||||
if(dayOfWeek > days.length-1){
|
||||
dayOfWeek = dayOfWeek - days.length;
|
||||
}
|
||||
return dayOfWeek;
|
||||
}
|
||||
|
||||
function updateLastRun(deviceId, day, pointId, lastRun){
|
||||
day = getDayIndexForDayOfWeek(day);
|
||||
var row = getDeviceRow(day,deviceId);
|
||||
for(var k=0;k<row.children.length;k++){
|
||||
var point = row.children[k];
|
||||
if(point.isPoint && point.parentPoint == undefined && point.pointId == pointId){ //and not disabled
|
||||
point.lastRun = lastRun;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//can be used from any file:
|
||||
function getBarWidth(currentBar, currentPointRect, pointList){
|
||||
|
||||
var maxWidth = currentPointRect.parent.width;
|
||||
|
@ -332,51 +15,6 @@ function getBarWidth(currentBar, currentPointRect, pointList){
|
|||
return (nextX - currentPointRect.x);
|
||||
}
|
||||
|
||||
function hasBarChangingPoints(pointList){
|
||||
|
||||
for(var i=0;i<pointList.length;i++){
|
||||
if (pointList[i].isPoint != undefined && pointList[i].isPoint == "true" && pointList[i].state != "bell") { //TODO make "bell" dynamic?
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function getEndsWith(pointList, dayIndex, deviceId){
|
||||
var prevPoint = null;
|
||||
for(var i=0;i<pointList.length;i++){
|
||||
if(pointList[i].isPoint != undefined && pointList[i].isPoint == "true"){
|
||||
if((prevPoint == null || pointList[i].x > prevPoint.x) && pointList[i].state != "bell"){ //TODO when more than "bell", make dynamic
|
||||
prevPoint = pointList[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(prevPoint == null){
|
||||
dayIndex = dayIndex - 1;
|
||||
if(dayIndex == -1){ //too far, begin from end again
|
||||
dayIndex = days.length - 1;
|
||||
}
|
||||
|
||||
var prevDayDevice = getDeviceRow(dayIndex, deviceId);
|
||||
if(prevDayDevice == undefined){
|
||||
return null;
|
||||
}
|
||||
return prevDayDevice.endPoint;
|
||||
}
|
||||
if(prevPoint.state == "off"){
|
||||
return null;
|
||||
}
|
||||
return prevPoint; //only on or dim
|
||||
}
|
||||
|
||||
function getTimeFromSeconds(seconds){
|
||||
var totalMinutes = seconds/60;
|
||||
var minutes = totalMinutes%60;
|
||||
var hours = Math.floor(totalMinutes/60);
|
||||
return [hours, minutes];
|
||||
}
|
||||
|
||||
function getFirstPointWidth(deviceRow){
|
||||
var pointList = deviceRow.children; //TODO should really try to avoid using "children"... make own list instead?
|
||||
var firstX = deviceRow.width;
|
||||
|
@ -392,21 +30,6 @@ function getFirstPointWidth(deviceRow){
|
|||
return firstX + pointWidth/2;
|
||||
}
|
||||
|
||||
function pad(number, length) {
|
||||
|
||||
var str = '' + number;
|
||||
while (str.length < length) {
|
||||
str = '0' + str;
|
||||
}
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
function getOffsetWeekdayName(index){
|
||||
index = getOffsetWeekday(index);
|
||||
return weekday_name_array[index];
|
||||
}
|
||||
|
||||
function getOffsetWeekday(index){
|
||||
//TODO this can be modified based on locale, not adding 1 if week should start with sunday
|
||||
index = parseInt(index);
|
||||
|
@ -417,7 +40,28 @@ function getOffsetWeekday(index){
|
|||
return index;
|
||||
}
|
||||
|
||||
function deviceIsEnabled(deviceId){
|
||||
return days[0].children[0].children[deviceIndex[deviceId]].state == "enabled";
|
||||
function getOffsetWeekdayName(index){
|
||||
index = getOffsetWeekday(index);
|
||||
return weekday_name_array[index];
|
||||
}
|
||||
|
||||
function hasBarChangingPoints(pointList){
|
||||
|
||||
for(var i=0;i<pointList.length;i++){
|
||||
if (pointList[i].isPoint != undefined && pointList[i].isPoint == "true" && pointList[i].state != "bell") { //TODO make "bell" dynamic?
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function pad(number, length) {
|
||||
|
||||
var str = '' + number;
|
||||
while (str.length < length) {
|
||||
str = '0' + str;
|
||||
}
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue