Merge branch 'PR89' into develop

pull/90/head
13621160019@163.com 2021-12-03 19:21:08 +08:00
commit b10cc91a3a
5 changed files with 29 additions and 18 deletions

View File

@ -1,7 +1,7 @@
'use strict';
app.controller('SensorController', function($scope, $translate, $uibModal, SensorService, toaster, SweetAlert) {
app.controller('SensorController', function($scope, $window, $translate, $uibModal, SensorService, toaster, SweetAlert) {
$scope.cur_user = JSON.parse($window.localStorage.getItem("myems_admin_ui_current_user"));
$scope.getAllSensors = function() {
SensorService.getAllSensors(function (response) {
if (angular.isDefined(response.status) && response.status === 200) {
@ -27,7 +27,9 @@ app.controller('SensorController', function($scope, $translate, $uibModal, Sens
}
});
modalInstance.result.then(function(sensor) {
SensorService.addSensor(sensor, function (response) {
let headers = { "User-UUID": $scope.cur_user.uuid, "Token": $scope.cur_user.token };
SensorService.addSensor(sensor, {headers},
function (response) {
if (angular.isDefined(response.status) && response.status === 201) {
toaster.pop({
type: "success",
@ -67,7 +69,8 @@ app.controller('SensorController', function($scope, $translate, $uibModal, Sens
});
modalInstance.result.then(function(modifiedSensor) {
SensorService.editSensor(modifiedSensor, function (response) {
let headers = { "User-UUID": $scope.cur_user.uuid, "Token": $scope.cur_user.token };
SensorService.editSensor(modifiedSensor, {headers}, function (response) {
if (angular.isDefined(response.status) && response.status === 200) {
toaster.pop({
type: "success",
@ -105,7 +108,8 @@ app.controller('SensorController', function($scope, $translate, $uibModal, Sens
},
function(isConfirm) {
if (isConfirm) {
SensorService.deleteSensor(sensor, function (response) {
let headers = { "User-UUID": $scope.cur_user.uuid, "Token": $scope.cur_user.token };
SensorService.deleteSensor(sensor, {headers}, function (response) {
if (angular.isDefined(response.status) && response.status === 204) {
toaster.pop({
type: "success",

View File

@ -80,7 +80,8 @@ app.controller('SensorPointController', function (
$scope.pairPoint = function (dragEl, dropEl) {
var pointid = angular.element('#' + dragEl).scope().point.id;
var sensorid = $scope.currentSensor.id;
SensorPointService.addPair(sensorid, pointid, function (response) {
let headers = { "User-UUID": $scope.cur_user.uuid, "Token": $scope.cur_user.token };
SensorPointService.addPair(sensorid, pointid, {headers}, function (response) {
if (angular.isDefined(response.status) && response.status === 201) {
toaster.pop({
type: "success",
@ -106,7 +107,8 @@ app.controller('SensorPointController', function (
}
var sensorpointid = angular.element('#' + dragEl).scope().sensorpoint.id;
var sensorid = $scope.currentSensor.id;
SensorPointService.deletePair(sensorid, sensorpointid, function (response) {
let headers = { "User-UUID": $scope.cur_user.uuid, "Token": $scope.cur_user.token };
SensorPointService.deletePair(sensorid, sensorpointid, {headers}, function (response) {
if (angular.isDefined(response.status) && response.status === 204) {
toaster.pop({
type: "success",

View File

@ -17,24 +17,24 @@ app.factory('SensorService', function($http) {
callback(response);
});
},
addSensor: function(sensor, callback) {
$http.post(getAPI()+'sensors',{data:sensor})
addSensor: function(sensor, headers, callback) {
$http.post(getAPI()+'sensors',{data:sensor}, {headers})
.then(function (response) {
callback(response);
}, function (response) {
callback(response);
});
},
editSensor: function(sensor, callback) {
$http.put(getAPI()+'sensors/'+sensor.id,{data:sensor})
editSensor: function(sensor, headers, callback) {
$http.put(getAPI()+'sensors/'+sensor.id,{data:sensor}, {headers})
.then(function (response) {
callback(response);
}, function (response) {
callback(response);
});
},
deleteSensor: function(sensor, callback) {
$http.delete(getAPI()+'sensors/'+sensor.id)
deleteSensor: function(sensor, headers, callback) {
$http.delete(getAPI()+'sensors/'+sensor.id, {headers})
.then(function (response) {
callback(response);
}, function (response) {

View File

@ -1,8 +1,8 @@
'use strict';
app.factory('SensorPointService', function($http) {
return {
addPair: function(sensorID,pointID,callback) {
$http.post(getAPI()+'sensors/'+sensorID+'/points',{data:{'point_id':pointID}})
addPair: function(sensorID,pointID, headers, callback) {
$http.post(getAPI()+'sensors/'+sensorID+'/points',{data:{'point_id':pointID}}, {headers})
.then(function (response) {
callback(response);
}, function (response) {
@ -10,8 +10,8 @@ app.factory('SensorPointService', function($http) {
});
},
deletePair: function(sensorID,pointID, callback) {
$http.delete(getAPI()+'sensors/'+sensorID+'/points/'+pointID)
deletePair: function(sensorID,pointID, headers, callback) {
$http.delete(getAPI()+'sensors/'+sensorID+'/points/'+pointID, {headers})
.then(function (response) {
callback(response);
}, function (response) {

View File

@ -3,7 +3,7 @@ import simplejson as json
import mysql.connector
import config
import uuid
from core.useractivity import user_logger
from core.useractivity import user_logger, access_control
class SensorCollection:
@ -44,6 +44,7 @@ class SensorCollection:
@user_logger
def on_post(req, resp):
"""Handles POST requests"""
access_control(req)
try:
raw_json = req.stream.read().decode('utf-8')
except Exception as ex:
@ -133,6 +134,7 @@ class SensorItem:
@staticmethod
@user_logger
def on_delete(req, resp, id_):
access_control(req)
if not id_.isdigit() or int(id_) <= 0:
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST',
description='API.INVALID_SENSOR_ID')
@ -209,6 +211,7 @@ class SensorItem:
@user_logger
def on_put(req, resp, id_):
"""Handles PUT requests"""
access_control(req)
try:
raw_json = req.stream.read().decode('utf-8')
except Exception as ex:
@ -320,6 +323,7 @@ class SensorPointCollection:
@user_logger
def on_post(req, resp, id_):
"""Handles POST requests"""
access_control(req)
try:
raw_json = req.stream.read().decode('utf-8')
except Exception as ex:
@ -387,6 +391,7 @@ class SensorPointItem:
@staticmethod
@user_logger
def on_delete(req, resp, id_, pid):
access_control(req)
if not id_.isdigit() or int(id_) <= 0:
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST',
description='API.INVALID_SENSOR_ID')