Merge branch 'PR81' into develop
commit
8e0bb54616
|
@ -27,7 +27,8 @@ app.controller('EnergyCategoryController', function($scope, $translate,$uibModal
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
modalInstance.result.then(function(category) {
|
modalInstance.result.then(function(category) {
|
||||||
CategoryService.addCategory(category, function (response) {
|
let headers = { "User-UUID": $scope.cur_user.uuid, "Token": $scope.cur_user.token };
|
||||||
|
CategoryService.addCategory(category, headers, function (response) {
|
||||||
if (angular.isDefined(response.status) && response.status === 201) {
|
if (angular.isDefined(response.status) && response.status === 201) {
|
||||||
toaster.pop({
|
toaster.pop({
|
||||||
type: "success",
|
type: "success",
|
||||||
|
@ -68,7 +69,8 @@ app.controller('EnergyCategoryController', function($scope, $translate,$uibModal
|
||||||
});
|
});
|
||||||
|
|
||||||
modalInstance.result.then(function (modifiedCategory) {
|
modalInstance.result.then(function (modifiedCategory) {
|
||||||
CategoryService.editCategory(modifiedCategory, function (response) {
|
let headers = { "User-UUID": $scope.cur_user.uuid, "Token": $scope.cur_user.token };
|
||||||
|
CategoryService.editCategory(modifiedCategory, headers, function (response) {
|
||||||
if(angular.isDefined(response.status) && response.status === 200){
|
if(angular.isDefined(response.status) && response.status === 200){
|
||||||
toaster.pop({
|
toaster.pop({
|
||||||
type: "success",
|
type: "success",
|
||||||
|
@ -106,7 +108,8 @@ app.controller('EnergyCategoryController', function($scope, $translate,$uibModal
|
||||||
closeOnCancel: true },
|
closeOnCancel: true },
|
||||||
function (isConfirm) {
|
function (isConfirm) {
|
||||||
if (isConfirm) {
|
if (isConfirm) {
|
||||||
CategoryService.deleteCategory(category, function (response) {
|
let headers = { "User-UUID": $scope.cur_user.uuid, "Token": $scope.cur_user.token };
|
||||||
|
CategoryService.deleteCategory(category, headers, function (response) {
|
||||||
if (angular.isDefined(response.status) && response.status === 204) {
|
if (angular.isDefined(response.status) && response.status === 204) {
|
||||||
toaster.pop({
|
toaster.pop({
|
||||||
type: "success",
|
type: "success",
|
||||||
|
|
|
@ -2,47 +2,47 @@
|
||||||
app.factory('CategoryService', function($http) {
|
app.factory('CategoryService', function($http) {
|
||||||
return {
|
return {
|
||||||
getAllCategories:function(callback){
|
getAllCategories:function(callback){
|
||||||
$http.get(getAPI()+'energycategories')
|
$http.get(getAPI()+'energycategories')
|
||||||
.then(function (response) {
|
.then(function (response) {
|
||||||
callback(response);
|
callback(response);
|
||||||
}, function (response) {
|
}, function (response) {
|
||||||
callback(response);
|
callback(response);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
searchCategories: function(query, callback) {
|
searchCategories: function(query, headers, callback) {
|
||||||
$http.get(getAPI()+'energycategories', { params: { q: query } })
|
$http.get(getAPI()+'energycategories', { params: { q: query } }, {headers})
|
||||||
.then(function (response) {
|
.then(function (response) {
|
||||||
callback(response);
|
callback(response);
|
||||||
}, function (response) {
|
}, function (response) {
|
||||||
callback(response);
|
callback(response);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
addCategory: function(category, callback) {
|
addCategory: function(category, headers, callback) {
|
||||||
$http.post(getAPI()+'energycategories',{data:category})
|
$http.post(getAPI()+'energycategories',{data:category}, {headers})
|
||||||
.then(function (response) {
|
.then(function (response) {
|
||||||
callback(response);
|
callback(response);
|
||||||
}, function (response) {
|
}, function (response) {
|
||||||
callback(response);
|
callback(response);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
editCategory: function(category, callback) {
|
editCategory: function(category, headers, callback) {
|
||||||
$http.put(getAPI()+'energycategories/'+category.id,{data:category})
|
$http.put(getAPI()+'energycategories/'+category.id,{data:category}, {headers})
|
||||||
.then(function (response) {
|
.then(function (response) {
|
||||||
callback(response);
|
callback(response);
|
||||||
}, function (response) {
|
}, function (response) {
|
||||||
callback(response);
|
callback(response);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
deleteCategory: function(category, callback) {
|
deleteCategory: function(category, headers, callback) {
|
||||||
$http.delete(getAPI()+'energycategories/'+category.id)
|
$http.delete(getAPI()+'energycategories/'+category.id, {headers})
|
||||||
.then(function (response) {
|
.then(function (response) {
|
||||||
callback(response);
|
callback(response);
|
||||||
}, function (response) {
|
}, function (response) {
|
||||||
callback(response);
|
callback(response);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
getCategory: function(id, callback) {
|
getCategory: function(id, headers, callback) {
|
||||||
$http.get(getAPI()+'energycategories/'+id)
|
$http.get(getAPI()+'energycategories/'+id, {headers})
|
||||||
.then(function (response) {
|
.then(function (response) {
|
||||||
callback(response);
|
callback(response);
|
||||||
}, function (response) {
|
}, function (response) {
|
||||||
|
|
|
@ -3,7 +3,7 @@ import simplejson as json
|
||||||
import mysql.connector
|
import mysql.connector
|
||||||
import config
|
import config
|
||||||
import uuid
|
import uuid
|
||||||
from core.useractivity import user_logger
|
from core.useractivity import user_logger, access_control
|
||||||
|
|
||||||
|
|
||||||
class EnergyCategoryCollection:
|
class EnergyCategoryCollection:
|
||||||
|
@ -42,6 +42,7 @@ class EnergyCategoryCollection:
|
||||||
@user_logger
|
@user_logger
|
||||||
def on_post(req, resp):
|
def on_post(req, resp):
|
||||||
"""Handles POST requests"""
|
"""Handles POST requests"""
|
||||||
|
access_control(req)
|
||||||
try:
|
try:
|
||||||
raw_json = req.stream.read().decode('utf-8')
|
raw_json = req.stream.read().decode('utf-8')
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
|
@ -149,6 +150,7 @@ class EnergyCategoryItem:
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@user_logger
|
@user_logger
|
||||||
def on_delete(req, resp, id_):
|
def on_delete(req, resp, id_):
|
||||||
|
access_control(req)
|
||||||
if not id_.isdigit() or int(id_) <= 0:
|
if not id_.isdigit() or int(id_) <= 0:
|
||||||
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST',
|
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST',
|
||||||
description='API.INVALID_ENERGY_CATEGORY_ID')
|
description='API.INVALID_ENERGY_CATEGORY_ID')
|
||||||
|
@ -231,6 +233,7 @@ class EnergyCategoryItem:
|
||||||
@user_logger
|
@user_logger
|
||||||
def on_put(req, resp, id_):
|
def on_put(req, resp, id_):
|
||||||
"""Handles PUT requests"""
|
"""Handles PUT requests"""
|
||||||
|
access_control(req)
|
||||||
try:
|
try:
|
||||||
raw_json = req.stream.read().decode('utf-8')
|
raw_json = req.stream.read().decode('utf-8')
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
|
@ -304,4 +307,3 @@ class EnergyCategoryItem:
|
||||||
cursor.close()
|
cursor.close()
|
||||||
cnx.disconnect()
|
cnx.disconnect()
|
||||||
resp.status = falcon.HTTP_200
|
resp.status = falcon.HTTP_200
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue