Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Manuel83 committed Mar 28, 2016
1 parent 2dc419e commit c46ec6b
Show file tree
Hide file tree
Showing 18 changed files with 87 additions and 917 deletions.
3 changes: 3 additions & 0 deletions .bowerrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"directory": "brewapp/static/addon/"
}
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ __pycache__/
env/
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
Expand Down Expand Up @@ -57,4 +56,4 @@ docs/_build/
target/

#sqllitefiles
*.db
*.db
16 changes: 14 additions & 2 deletions brewapp/base/hardwareswitch.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,26 @@ def init():
'POST': [post_post],
'PATCH_SINGLE': [post_post],
})
initHardware()
initHardware(False)

def initHardware(cleanup = True):
if(cleanup):
app.brewapp_hardware.cleanup()

def initHardware():
app.brewapp_switch_state = {}
hw = Hardware.query.all()
for h in hw:
if(h.switch != None):
app.brewapp_switch_state[h.switch] = False

kettles = Kettle.query.all()
for v in kettles:
if(v.agitator != None):
app.brewapp_switch_state[v.agitator] = False
if(v.heater != None):
app.brewapp_switch_state[v.heater] = False


@app.route('/api/switch', methods=['GET'])
def switchstate():
return json.dumps(app.brewapp_switch_state)
Expand Down
12 changes: 3 additions & 9 deletions brewapp/base/kettle.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from w1_thermometer import *
from brewapp import manager
from brewapp.base.pid.pidbase import *
from brewapp.base.hardwareswitch import *


@app.route('/api/kettle/state', methods=['GET'])
Expand Down Expand Up @@ -64,9 +65,7 @@ def setTargetTemp(vid, temp):
def post_post(result=None, **kw):
result["automatic"] = json.loads(result["automatic"])
if(result != None):
app.brewapp_hardware.cleanup()
initKettle()
app.brewapp_hardware.init()
initHardware()

def pre_post(data, **kw):
data["automatic"] = json.dumps(data.get("automatic", None))
Expand All @@ -93,8 +92,6 @@ def init():
'PATCH_SINGLE': [pre_post]})
initKettle()



def initKettle():

kettles = Kettle.query.all()
Expand All @@ -108,10 +105,7 @@ def initKettle():
app.brewapp_kettle_state[v.id]["automatic"] = False
app.brewapp_kettle_state[v.id]["agitator"] = v.agitator
app.brewapp_kettle_state[v.id]["heater"] = v.heater
if(v.agitator != None):
app.brewapp_switch_state[v.agitator] = False
if(v.heater != None):
app.brewapp_switch_state[v.heater] = False

## JOBS
@brewjob(key="readtemp", interval=5)
def readKettleTemp():
Expand Down
8 changes: 6 additions & 2 deletions brewapp/base/static/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
<link rel="stylesheet" type="text/css" href="/base/static/addon/css/font-awesome.min.css">
<link rel="stylesheet" type="text/css" href="/base/static/addon/css/angular-wizard.min.css">





<!-- Charting lib -->
<script src="/base/static/addon/js/d3.min.js" charset="utf-8"></script>
<script src="/base/static/addon/js/c3.min.js"></script>
Expand Down Expand Up @@ -43,10 +47,10 @@
<script src="static/js/setup/controller.js"></script>
<script src="static/js/hardware/controller.js"></script>
</head>
<body>
<body id="skin-blur-violate">
<div ng-app="craftberpi">
<navigation></navigation>

<div class="container" ng-view></div>
</div>
</body>
Expand Down
47 changes: 22 additions & 25 deletions brewapp/base/static/js/dashboard/controller.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
angular.module('craftberpi.controllers2', []).controller('DashBoardController', function($scope, $location, CBPSteps, CBPKettle, CBPPump,ChartFactory, CBPSwitch, $uibModal, ws, $timeout) {
angular.module('craftberpi.controllers2', []).controller('DashBoardController', function($scope, $location, CBPSteps, CBPKettle, CBPHardware, ChartFactory, CBPSwitch, $uibModal, ws, $timeout) {


$scope.percent = 65;
$scope.options = {
animate:{
duration:500,
enabled:true
},
barColor:'green',
scaleColor:false,
lineWidth:20,
lineCap:'butt',
$scope.percent = 65;
$scope.options = {
animate: {
duration: 500,
enabled: true
},
barColor: 'green',
scaleColor: false,
lineWidth: 20,
lineCap: 'butt',

};
};

$scope.switch_state = {}
$scope.kettle_state = {}
Expand All @@ -29,11 +29,11 @@ angular.module('craftberpi.controllers2', []).controller('DashBoardController',

})

CBPPump.query(function(data) {
$scope.pumps = data.objects;
CBPHardware.query(function(data) {
$scope.hardware = data.objects;
});

CBPPump.getstate(function(data) {
CBPHardware.getstate(function(data) {
$scope.pumps_state = data;
});

Expand All @@ -55,13 +55,12 @@ angular.module('craftberpi.controllers2', []).controller('DashBoardController',

$scope.automiticState = function(item) {

if($scope.kettle_state[item.id] == undefined) {
if ($scope.kettle_state[item.id] == undefined) {
return "btn-default"
}
if ($scope.kettle_state[item.id]['automatic'] == true) {
if ($scope.kettle_state[item.id]['automatic'] == true) {
return "btn-success"
}
else {
} else {
return "btn-default"
}
}
Expand All @@ -73,10 +72,9 @@ angular.module('craftberpi.controllers2', []).controller('DashBoardController',
return "btn-default"
}

if($scope.switch_state[s] == true) {
if ($scope.switch_state[s] == true) {
return "btn-success"
}
else {
} else {
return "btn-default"
}
}
Expand All @@ -98,9 +96,8 @@ angular.module('craftberpi.controllers2', []).controller('DashBoardController',
num_of_kettles = 1;
if (item.state == "D") {
return "info";
}
else if (item.type == "M" && item.state == "A" && num_of_kettles > 0 && $scope.kettle_temps != undefined && $scope.kettle_temps[item["kettleid"]][1] >= item.temp) {
return "active"
} else if (item.type == "M" && item.state == "A" && num_of_kettles > 0 && $scope.kettle_temps != undefined && $scope.kettle_temps[item["kettleid"]][1] >= item.temp) {
return "active"
} else if (item.state == "A" && item.timer_start != null) {
return "active"
} else if (item.state == "A" && item.timer_start == null) {
Expand Down
30 changes: 20 additions & 10 deletions brewapp/base/static/js/hardware/controller.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
angular.module('craftberpi.hardware', []).controller('PumpOverviewController', function($scope, $location, CBPPump, ConfirmMessage, CBPKettle, CBPConfig) {
angular.module('craftberpi.hardware', []).controller('PumpOverviewController', function($scope, $location, CBPHardware, ConfirmMessage, CBPKettle, CBPConfig) {


$scope.pump = {
Expand All @@ -18,27 +18,27 @@ angular.module('craftberpi.hardware', []).controller('PumpOverviewController', f
})
});

CBPPump.query(function(response) {
CBPHardware.query(function(response) {
$scope.pumps = response.objects;
});
$scope.save = function() {

if ($scope.pump.name.length == 0) {
return;
}
CBPPump.save($scope.pump, function(data) {
CBPPump.query(function(response) {
CBPHardware.save($scope.pump, function(data) {
CBPHardware.query(function(response) {
$scope.pumps = response.objects;
});
});

}

}).controller('PumpEditController', function($scope, $location, $routeParams, CBPPump, ConfirmMessage, CBPKettle, CBPConfig) {
}).controller('PumpEditController', function($scope, $location, $routeParams, CBPHardware, ConfirmMessage, CBPKettle, CBPConfig) {

$scope.vid = $routeParams.vid

CBPPump.get({
CBPHardware.get({
"id": $scope.vid
}, function(response) {
$scope.pump = response;
Expand All @@ -56,18 +56,28 @@ angular.module('craftberpi.hardware', []).controller('PumpOverviewController', f
});

$scope.save = function() {
CBPPump.update({
CBPHardware.update({
"id": $scope.pump.id
}, $scope.pump, function() {
history.back();
});
}
$scope.delete = function() {
CBPPump.delete({
"id": $scope.pump.id

ConfirmMessage.open("Delete Hardware","Do you really want to delete the hardware?", function() {
CBPHardware.delete({
"id": $scope.pump.id
}, function() {
history.back();
});

}, function() {
history.back();

});




}

});
18 changes: 13 additions & 5 deletions brewapp/base/static/js/kettle/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ angular.module('craftberpi.controllers5', []).controller('KettleOverviewControll

});
}, function() {
// cancel do nothing

});
}

Expand Down Expand Up @@ -82,7 +82,7 @@ angular.module('craftberpi.controllers5', []).controller('KettleOverviewControll
});
}

}).controller('KettleEditController', function($scope, CBPKettle, $routeParams, CBPConfig) {
}).controller('KettleEditController', function($scope, CBPKettle, $routeParams, CBPConfig, ConfirmMessage) {
// Do something with myService
$scope.vid = $routeParams.vid

Expand Down Expand Up @@ -126,10 +126,18 @@ angular.module('craftberpi.controllers5', []).controller('KettleOverviewControll
});
}
$scope.delete = function() {
CBPKettle.delete({
"id": $scope.kettle.id

ConfirmMessage.open("Delete Kettle","Do you really want to delete the kettle?", function() {
CBPKettle.delete({
"id": $scope.kettle.id
}, function() {
history.back();
});

}, function() {
history.back();

});


}
});
4 changes: 2 additions & 2 deletions brewapp/base/static/js/service.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ factory("CBPConfig", function($resource) {
}
});
}).
factory("CBPPump", function($resource) {
factory("CBPHardware", function($resource) {
return $resource("/api/hardware/:id", {}, {
query: {
method: 'GET',
Expand Down Expand Up @@ -259,7 +259,7 @@ factory('ConfirmMessage', function($route, $location, $uibModal) {
modalInstance.result.then(function(data) {
confirm()
}, function() {
confirm(cancel)
cancel()
})
}
}
Expand Down
2 changes: 1 addition & 1 deletion brewapp/base/static/partials/dashboard/overview.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

</div>
</div>
<div class="row" >
<div class="row" ng-if="hardware.length > 0" >
<div class="col-sm-6" ng-include="'/base/static/partials/dashboard/pump.html'"/>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion brewapp/base/static/partials/dashboard/pump.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
</div>
<div class="panel-body">

<button class="btn btn-default" role="group" ng-class="buttonState(p.switch)" ng-click="switchGPIO(p.switch)" ng-repeat="p in pumps">
<button class="btn btn-default" role="group" ng-class="buttonState(p.switch)" ng-click="switchGPIO(p.switch)" ng-repeat="p in hardware">
{{p.name}}
</button>
</div>
Expand Down
1 change: 1 addition & 0 deletions brewapp/base/static/partials/navigation.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
<a href="#{{ route.path }}">{{ route.name }}</a>
</li>


</ul>
</div>
</div>
Expand Down
1 change: 0 additions & 1 deletion node_modules/.bin/bower

This file was deleted.

Loading

0 comments on commit c46ec6b

Please sign in to comment.