Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
nengyuanzhang committed Feb 2, 2024
2 parents 0cac603 + 0fbc662 commit e2ddad5
Show file tree
Hide file tree
Showing 5 changed files with 128 additions and 3 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- added offline meter export, import and clone functions to myems-api, myems-admin
- added virtual meter export, import and clone functions to myems-api, myems-admin
- added space export, import and clone functions to myems-api, myems-admin
- added command export, import and clone functions to myems-api
- added command export, import and clone functions to myems-api, myems-admin
- added energy flow diagram export, import and clone functions to myems-api
- added tariff export, import and clone functions to myems-api
- added working calendar export, import and clone functions to myems-api
Expand Down
95 changes: 95 additions & 0 deletions myems-admin/app/controllers/settings/command/command.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ app.controller('CommandController', function(
toaster,
SweetAlert) {
$scope.cur_user = JSON.parse($window.localStorage.getItem("myems_admin_ui_current_user"));
$scope.exportdata = '';
$scope.importdata = '';

$scope.getAllCommands = function() {
let headers = { "User-UUID": $scope.cur_user.uuid, "Token": $scope.cur_user.token };
CommandService.getAllCommands(headers, function (response) {
Expand Down Expand Up @@ -154,6 +157,98 @@ app.controller('CommandController', function(
}
});
};

$scope.exportCommand = function(command) {
let headers = { "User-UUID": $scope.cur_user.uuid, "Token": $scope.cur_user.token };
CommandService.exportCommand(command, headers, function(response) {
if (angular.isDefined(response.status) && response.status === 200) {
$scope.exportdata = JSON.stringify(response.data);
var modalInstance = $uibModal.open({
windowClass: "animated fadeIn",
templateUrl: 'views/common/export.html',
controller: 'ModalExportCtrl',
resolve: {
params: function() {
return {
exportdata: angular.copy($scope.exportdata)
};
}
}
});
modalInstance.result.then(function() {
//do nothing;
}, function() {
//do nothing;
});
$rootScope.modalInstance = modalInstance;
} else {
$scope.exportdata = null;
}
});
};

$scope.cloneCommand = function(command){
let headers = { "User-UUID": $scope.cur_user.uuid, "Token": $scope.cur_user.token };
CommandService.cloneCommand(command, headers, function(response) {
if (angular.isDefined(response.status) && response.status === 201) {
toaster.pop({
type: "success",
title: $translate.instant("TOASTER.SUCCESS_TITLE"),
body: $translate.instant("TOASTER.SUCCESS_ADD_BODY", {template: $translate.instant("COMMON.DATA_SOURCE")}),
showCloseButton: true,
});
$scope.getAllCommands();
$scope.$emit('handleEmitCommandChanged');
}else {
toaster.pop({
type: "error",
title: $translate.instant("TOASTER.ERROR_ADD_BODY", {template: $translate.instant("COMMON.DATA_SOURCE")}),
body: $translate.instant(response.data.description),
showCloseButton: true,
});
}
});
};

$scope.importCommand = function() {
var modalInstance = $uibModal.open({
templateUrl: 'views/common/import.html',
controller: 'ModalImportCtrl',
windowClass: "animated fadeIn",
resolve: {
params: function() {
return {
};
}
}
});
modalInstance.result.then(function(importdata) {
let headers = { "User-UUID": $scope.cur_user.uuid, "Token": $scope.cur_user.token };
CommandService.importCommand(importdata, headers, function(response) {
if (angular.isDefined(response.status) && response.status === 201) {
toaster.pop({
type: "success",
title: $translate.instant("TOASTER.SUCCESS_TITLE"),
body: $translate.instant("TOASTER.SUCCESS_ADD_BODY", {template: $translate.instant("COMMON.DATA_SOURCE")}),
showCloseButton: true,
});
$scope.getAllCommands();
$scope.$emit('handleEmitCommandChanged');
} else {
toaster.pop({
type: "error",
title: $translate.instant("TOASTER.ERROR_ADD_BODY", { template: $translate.instant("COMMON.DATA_SOURCE") }),
body: $translate.instant(response.data.description),
showCloseButton: true,
});
}
});
}, function() {

});
$rootScope.modalInstance = modalInstance;
};

$scope.getAllCommands();

});
Expand Down
24 changes: 24 additions & 0 deletions myems-admin/app/services/settings/command/command.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,29 @@ app.factory('CommandService', function($http) {
callback(response);
});
},
exportCommand: function(command, headers, callback) {
$http.get(getAPI()+'commands/'+command.id+'/export', {headers})
.then(function (response) {
callback(response);
}, function (response) {
callback(response);
});
},
importCommand: function(importdata, headers, callback) {
$http.post(getAPI()+'commands/import', JSON.parse(importdata), {headers})
.then(function (response) {
callback(response);
}, function (response) {
callback(response);
});
},
cloneCommand: function(command, headers, callback) {
$http.post(getAPI()+'commands/'+command.id+'/clone', {data:null}, {headers})
.then(function (response) {
callback(response);
}, function (response) {
callback(response);
});
},
};
});
8 changes: 7 additions & 1 deletion myems-admin/views/settings/command/command.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@
<uib-tab heading="{{'SETTING.COMMAND' | translate}}">
<div class="panel-body" ng-controller="CommandController">
<a ng-click="addCommand()" class="btn btn-primary btn-rounded btn-outline" href="">
<i class="fa fa-plus-circle"></i> {{'SETTING.ADD_COMMAND' | translate}}</a>
<i class="fa fa-plus-circle"></i> {{'SETTING.ADD_COMMAND' | translate}}
</a>
<a ng-click="importCommand()" class="btn btn-primary btn-rounded btn-outline" href="">
<i class="fa fa-plus-circle"></i> {{'SETTING.IMPORT' | translate}}
</a>
<table class="footable table table-bordered table-hover" data-sort="true" data-page-size="15">
<thead>
<tr>
Expand Down Expand Up @@ -35,6 +39,8 @@
class="btn btn-danger btn-rounded btn-xs">{{'SETTING.DELETE' | translate}}</a>
<a ng-click="sendCommand(command)"
class="btn btn-danger btn-rounded btn-xs">{{'COMMAND.SEND' | translate}}</a>
<a ng-click="exportCommand(command)" class="btn btn-danger btn-rounded btn-xs" >{{'SETTING.EXPORT' | translate}}</a>
<a ng-click="cloneCommand(command)" class="btn btn-danger btn-rounded btn-xs" >{{'SETTING.CLONE' | translate}}</a>
</td>
</tr>
</tbody>
Expand Down
2 changes: 1 addition & 1 deletion myems-api/core/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,7 @@ def on_post(req, resp):
description='API.INVALID_PAYLOAD')
payload = str.strip(new_values['payload'])

if 'set_value' not in new_values.keys():
if 'set_value' not in new_values.keys() or new_values['set_value'] is None:
set_value = None
elif isinstance(new_values['set_value'], float) or \
isinstance(new_values['set_value'], int):
Expand Down

0 comments on commit e2ddad5

Please sign in to comment.