Continuing work on POCONSOLE-75. Restore function written, but not tested.
This commit is contained in:
@@ -9,8 +9,8 @@ from datetime import datetime
|
||||
from app import app, db
|
||||
from app.datalogger.models import *
|
||||
from app.datalogger.getDailyTotals import getTotals
|
||||
from pycomm_helper.utils import readTag
|
||||
|
||||
from pycomm_helper.utils import readTag, writeTag
|
||||
from random import random
|
||||
|
||||
ALLOWED_EXTENSIONS = set(['txt', 'pdf', 'png', 'jpg', 'jpeg', 'gif', 'doc', 'docx', 'xls', 'xlsx', 'zip'])
|
||||
|
||||
@@ -206,13 +206,13 @@ def get_csv_for_stroke(stroke_number):
|
||||
"attachment; filename=card_{}.csv".format(res._id)})
|
||||
|
||||
|
||||
@app.route('/api/backup_restore_update_all')
|
||||
def update_backup_restore_all():
|
||||
@app.route('/api/backup_all')
|
||||
def backup_all():
|
||||
all_br = [i.serialize for i in BackupRestore.query.all()]
|
||||
for i in range(0, len(all_br)):
|
||||
try:
|
||||
# read_value = readTag(all_br[i]['device']['address'], all_br[i]['tag'])
|
||||
read_value = (1.234, 'REAL')
|
||||
read_value = (random() * 100.0, 'REAL')
|
||||
all_br[i]['value'] = read_value[0]
|
||||
all_br[i]['tag_type'] = read_value[1]
|
||||
BackupRestore.query.filter_by(_id=all_br[i]['_id']).update({"value": str(all_br[i]['value']), "tag_type": all_br[i]['tag_type']})
|
||||
@@ -222,15 +222,56 @@ def update_backup_restore_all():
|
||||
return jsonify(all_br)
|
||||
|
||||
|
||||
@app.route('/api/backup_restore_update/<int:id>')
|
||||
def update_backup_restore(id):
|
||||
@app.route('/api/backup/<int:id>')
|
||||
def backup_single(id):
|
||||
"""
|
||||
Backs up the tag value of the specified database entry
|
||||
"""
|
||||
|
||||
single_br = BackupRestore.query.filter_by(_id=id).one().serialize
|
||||
try:
|
||||
# read_value = readTag(single_br['device']['address'], single_br['tag'])
|
||||
read_value = (1.234, 'REAL')
|
||||
read_value = (random() * 100.0, 'REAL')
|
||||
single_br['value'] = read_value[0]
|
||||
single_br['tag_type'] = read_value[1]
|
||||
BackupRestore.query.filter_by(_id=single_br['_id']).update({"value": str(single_br['value']), "tag_type": single_br['tag_type']})
|
||||
except:
|
||||
print("Error backing up tag value for tag {}".format(single_br['tag']))
|
||||
return jsonify(single_br)
|
||||
|
||||
|
||||
@app.route('/api/restore_all')
|
||||
def restore_all():
|
||||
all_br = [i.serialize for i in BackupRestore.query.all()]
|
||||
for i in range(0, len(all_br)):
|
||||
try:
|
||||
tag_val = 0
|
||||
if all_br[i]['tag_type'] == "REAL":
|
||||
tag_val = float(all_br[i]['value'])
|
||||
else:
|
||||
tag_val = int(all_br[i]['value'])
|
||||
|
||||
write_value = readTag(all_br[i]['device']['address'], all_br[i]['tag'], write_value)
|
||||
except:
|
||||
print("Error backing up tag value for tag {}".format(all_br[i]['tag']))
|
||||
continue
|
||||
return jsonify(all_br)
|
||||
|
||||
|
||||
@app.route('/api/restore/<int:id>')
|
||||
def restore_single(id):
|
||||
"""
|
||||
Writes the value of the specified database entry to the PLC
|
||||
"""
|
||||
|
||||
single_br = BackupRestore.query.filter_by(_id=id).one().serialize
|
||||
try:
|
||||
if single_br['tag_type'] == "REAL":
|
||||
tag_val = float(single_br['value'])
|
||||
else:
|
||||
tag_val = int(single_br['value'])
|
||||
|
||||
write_value = writeTag(single_br['device']['address'], single_br['tag'], tag_val)
|
||||
except:
|
||||
print("Error backing up tag value for tag {}".format(single_br['tag']))
|
||||
return jsonify(single_br)
|
||||
|
||||
92
app/static/js/backup_restore.controller.js
Normal file
92
app/static/js/backup_restore.controller.js
Normal file
@@ -0,0 +1,92 @@
|
||||
poconsole.controller('backupRestoreCtrl', function($scope, $route, $http, $routeParams, Page, $log, BackupRestore, Device) {
|
||||
Page.setTitle('Backup & Restore');
|
||||
Page.setPage('backuprestore');
|
||||
|
||||
$scope.data_types = [ 'REAL', 'INT', 'BOOL'];
|
||||
|
||||
$scope.loadBRTagList = function(){
|
||||
$scope.loading = true;
|
||||
var getBRTagList = BackupRestore.getBRTags();
|
||||
getBRTagList.then(function(data) {
|
||||
$scope.loading = false;
|
||||
$scope.bRTags = data.objects;
|
||||
});
|
||||
};
|
||||
$scope.loadBRTagList();
|
||||
|
||||
var getAllDevices = Device.getAllDevices();
|
||||
getAllDevices.then(function(d){
|
||||
$scope.devices = d.devices;
|
||||
});
|
||||
|
||||
$scope.submitAddBRTag = function(){
|
||||
var createStatus = Tag.createTag($scope.newTag);
|
||||
$scope.createStatus = createStatus.status;
|
||||
$scope.loadTagList();
|
||||
};
|
||||
|
||||
$scope.openDeleteTag = function(id){
|
||||
var getTag = Tag.getTag(id);
|
||||
getTag.then(function(data){
|
||||
$scope.error = false;
|
||||
$scope.dTag = data.tag;
|
||||
$log.info("Thinking about deleting tag with parameters: "+ JSON.stringify($scope.dTag));
|
||||
});
|
||||
};
|
||||
|
||||
$scope.deleteTag = function(id){
|
||||
var deleteTag = Tag.deleteTag(id);
|
||||
deleteTag.then(function(data){
|
||||
$log.info("deleting tag "+ id + " status: " + data.status);
|
||||
$scope.error = false;
|
||||
$scope.loadTagList();
|
||||
});
|
||||
};
|
||||
|
||||
$scope.openClearTagData = function(id){
|
||||
var getTag = Tag.getTag(id);
|
||||
getTag.then(function(data){
|
||||
$scope.error = false;
|
||||
$scope.dTagValues = data.tag;
|
||||
$log.info("Thinking about deleting tag data with parameters: "+ JSON.stringify($scope.dTagValues));
|
||||
});
|
||||
};
|
||||
|
||||
$scope.deleteTagValues = function(id){
|
||||
var clearSingleTagData = Tag.clearSingleTagData(id);
|
||||
clearSingleTagData.then(function(data){
|
||||
$log.info("deleting tag "+ id + " status: " + data.status);
|
||||
$scope.error = false;
|
||||
$scope.loadTagList();
|
||||
});
|
||||
};
|
||||
|
||||
$scope.openEditTag = function(id){
|
||||
var getTag = Tag.getTag(id);
|
||||
getTag.then(function(data){
|
||||
$scope.error = false;
|
||||
$scope.editTag = data.tag;
|
||||
$log.info("Started editing tag with parameters: "+ JSON.stringify($scope.editTag));
|
||||
});
|
||||
};
|
||||
|
||||
$scope.submitEditTag = function(){
|
||||
var editStatus = Tag.updateTag($scope.editTag);
|
||||
$scope.loadTagList();
|
||||
};
|
||||
|
||||
$scope.getPlotTags = function(){
|
||||
var tags_to_plot = [];
|
||||
for(var i =0; i<$scope.tags.length; i ++){
|
||||
if ($scope.tags[i].selectedForPlot){
|
||||
tags_to_plot.push($scope.tags[i]._id);
|
||||
}
|
||||
}
|
||||
$scope.tags_to_plot = tags_to_plot.join();
|
||||
};
|
||||
|
||||
$scope.device_label = function(data_type_obj){
|
||||
return data_type_obj.address + " - " + data_type_obj.device_type.device_type;
|
||||
};
|
||||
|
||||
});
|
||||
@@ -1,6 +1,14 @@
|
||||
poconsole.factory('BackupRestore', function($q, $http, $log){
|
||||
var service = {};
|
||||
|
||||
service.getBRTags = function(){
|
||||
var deferred = $q.defer();
|
||||
$http.get('/api/backup_restore').success(function(data) {
|
||||
deferred.resolve(data);
|
||||
});
|
||||
return deferred.promise;
|
||||
};
|
||||
|
||||
service.getBRTag = function(id){
|
||||
var deferred = $q.defer();
|
||||
$http.get('/api/backup_restore/' + id).success(function(data) {
|
||||
|
||||
Reference in New Issue
Block a user