Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
nengyuanzhang committed Jun 25, 2024
2 parents 7abb72f + f90080a commit 17daa64
Show file tree
Hide file tree
Showing 6 changed files with 99 additions and 33 deletions.
2 changes: 1 addition & 1 deletion database/install/myems_system_db.sql
Original file line number Diff line number Diff line change
Expand Up @@ -841,7 +841,7 @@ CREATE TABLE IF NOT EXISTS `myems_system_db`.`tbl_microgrids` (
`contact_id` BIGINT NOT NULL,
`cost_center_id` BIGINT NOT NULL,
`serial_number` VARCHAR(255) NOT NULL,
`svg` LONGTEXT NOT NULL,
`svg_id` BIGINT NOT NULL,
`is_cost_data_displayed` BOOL NOT NULL,
`phase_of_lifecycle` VARCHAR(255) NOT NULL,
`description` VARCHAR(255),
Expand Down
3 changes: 3 additions & 0 deletions database/upgrade/upgrade4.7.0RC.sql
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ CREATE INDEX `tbl_svgs_index_1` ON `myems_system_db`.`tbl_svgs` (`name`);
ALTER TABLE myems_system_db.tbl_energy_storage_power_stations ADD `svg_id` BIGINT NOT NULL AFTER `cost_center_id`;
ALTER TABLE myems_system_db.tbl_energy_storage_power_stations DROP COLUMN svg;

ALTER TABLE myems_system_db.tbl_microgrids ADD `svg_id` BIGINT NOT NULL AFTER `serial_number`;
ALTER TABLE myems_system_db.tbl_microgrids DROP COLUMN svg;

-- UPDATE VERSION NUMBER
UPDATE `myems_system_db`.`tbl_versions` SET version='4.7.0RC', release_date='2024-07-07' WHERE id=1;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ app.controller('MicrogridController', function(
$uibModal,
CostCenterService,
ContactService,
SVGService,
MicrogridService,
toaster,
SweetAlert) {
Expand Down Expand Up @@ -37,6 +38,17 @@ app.controller('MicrogridController', function(
});
};

$scope.getAllSVGs = function() {
let headers = { "User-UUID": $scope.cur_user.uuid, "Token": $scope.cur_user.token, "Quickmode": 'true' };
SVGService.getAllSVGs(headers, function (response) {
if (angular.isDefined(response.status) && response.status === 200) {
$scope.svgs = response.data;
} else {
$scope.svgs = [];
}
});
};

$scope.getAllMicrogrids = function() {
let headers = { "User-UUID": $scope.cur_user.uuid, "Token": $scope.cur_user.token };
MicrogridService.getAllMicrogrids(headers, function (response) {
Expand All @@ -58,6 +70,7 @@ app.controller('MicrogridController', function(
return {
costcenters: angular.copy($scope.costcenters),
contacts: angular.copy($scope.contacts),
svgs: angular.copy($scope.svgs),
};
}
}
Expand Down Expand Up @@ -100,7 +113,8 @@ app.controller('MicrogridController', function(
return {
microgrid: angular.copy(microgrid),
costcenters:angular.copy($scope.costcenters),
contacts:angular.copy($scope.contacts)
contacts:angular.copy($scope.contacts),
svgs: angular.copy($scope.svgs),
};
}
}
Expand Down Expand Up @@ -265,6 +279,7 @@ app.controller('MicrogridController', function(
$scope.getAllMicrogrids();
$scope.getAllCostCenters();
$scope.getAllContacts();
$scope.getAllSVGs();
$scope.$on('handleBroadcastMicrogridChanged', function(event) {
$scope.getAllMicrogrids();
});
Expand All @@ -275,6 +290,7 @@ app.controller('ModalAddMicrogridCtrl', function($scope, $uibModalInstance,param
$scope.operation = "SETTING.ADD_MICROGRID";
$scope.costcenters=params.costcenters;
$scope.contacts=params.contacts;
$scope.svgs=params.svgs;
$scope.microgrid = {
is_cost_data_displayed: false
};
Expand All @@ -292,6 +308,7 @@ app.controller('ModalEditMicrogridCtrl', function($scope, $uibModalInstance, par
$scope.microgrid = params.microgrid;
$scope.costcenters=params.costcenters;
$scope.contacts=params.contacts;
$scope.svgs=params.svgs;
$scope.ok = function() {
$uibModalInstance.close($scope.microgrid);
};
Expand Down
15 changes: 8 additions & 7 deletions myems-admin/views/settings/microgrid/microgrid.model.html
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,14 @@ <h4 class="modal-title">{{operation | translate}}(ID:{{microgrid.id}})</h4>
</div>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">{{'MICROGRID.SVG' | translate}}</label>
<div class="col-sm-9">
<textarea ng-model="microgrid.svg" rows="10" cols="50" name="microgridsvg" class="form-control" required="" placeholder="<svg></svg>"></textarea>
<div class="m-t-xs" ng-show="form_microgrid.microgridsvg.$invalid && form_microgrid.microgridsvg.$dirty">
<small class="text-danger" ng-show="form_microgrid.microgridsvg.$error.required">{{'MICROGRID.INPUT_SVG' | translate}}</small>
</div>
<div class="form-group"><label class="col-sm-2 control-label">{{'COMMON.SVG' | translate}}</label>
<div class="col-sm-10">
<ui-select ng-model="energystoragepowerstation.svg.id" theme="bootstrap" required>
<ui-select-match allow-clear="false" placeholder="{{'COMMON.PLACEHOLDER' | translate}}">{{$select.selected.name}}</ui-select-match>
<ui-select-choices repeat="svg.id as svg in svgs | filter: $select.search">
<div ng-bind-html="svg.name | highlight: $select.search"></div>
</ui-select-choices>
</ui-select>
</div>
</div>
<div class="form-group">
Expand Down
10 changes: 5 additions & 5 deletions myems-api/MyEMS.postman_collection.json
Original file line number Diff line number Diff line change
Expand Up @@ -6645,7 +6645,7 @@
],
"body": {
"mode": "raw",
"raw": "{\"data\":{\"name\":\"Beijing Office\", \"address\":\"Wangfujing Street, Dongcheng District, Beijing\", \"postal_code\":\"100000\", \"latitude\":39.909429, \"longitude\":116.416993, \"rated_capacity\":600.000, \"rated_power\":100.000,\"contact_id\":1, \"cost_center_id\":1, \"svg\":\"<svg></svg>\", \"is_cost_data_displayed\":false, \"phase_of_lifecycle\":\"1use\", \"description\":\"Classic\"}}"
"raw": "{\"data\":{\"name\":\"Beijing Office\", \"address\":\"Wangfujing Street, Dongcheng District, Beijing\", \"postal_code\":\"100000\", \"latitude\":39.909429, \"longitude\":116.416993, \"rated_capacity\":600.000, \"rated_power\":100.000,\"contact_id\":1, \"cost_center_id\":1, \"svg_id\":1, \"is_cost_data_displayed\":false, \"phase_of_lifecycle\":\"1use\", \"description\":\"Classic\"}}"
},
"url": {
"raw": "{{base_url}}/energystoragepowerstations",
Expand Down Expand Up @@ -6683,7 +6683,7 @@
],
"body": {
"mode": "raw",
"raw": "{\"data\":{\"name\":\"Beijing Office\", \"address\":\"Wangfujing Street, Dongcheng District, Beijing\", \"postal_code\":\"100000\", \"latitude\":39.909429, \"longitude\":116.416993, \"rated_capacity\":600.000, \"rated_power\":200.000, \"contact_id\":1, \"cost_center_id\":1, \"svg\":\"<svg></svg>\", \"is_cost_data_displayed\":false, \"phase_of_lifecycle\":\"2commissioning\", \"description\":\"Classic\"}}"
"raw": "{\"data\":{\"name\":\"Beijing Office\", \"address\":\"Wangfujing Street, Dongcheng District, Beijing\", \"postal_code\":\"100000\", \"latitude\":39.909429, \"longitude\":116.416993, \"rated_capacity\":600.000, \"rated_power\":200.000, \"contact_id\":1, \"cost_center_id\":1, \"svg_id\":1, \"is_cost_data_displayed\":false, \"phase_of_lifecycle\":\"2commissioning\", \"description\":\"Classic\"}}"
},
"url": {
"raw": "{{base_url}}/energystoragepowerstations/1",
Expand Down Expand Up @@ -9585,7 +9585,7 @@
],
"body": {
"mode": "raw",
"raw": "{\"data\":{\"name\":\"Beijing Office\", \"address\":\"Wangfujing Street, Dongcheng District, Beijing\", \"postal_code\":\"100000\", \"latitude\":39.909429, \"longitude\":116.416993, \"rated_capacity\":600.000, \"rated_power\":100.000, \"contact_id\":1, \"cost_center_id\":1, \"serial_number\": \"S1234567890\", \"svg\":\"<svg></svg>\", \"is_cost_data_displayed\":false, \"phase_of_lifecycle\":\"1use\", \"description\":\"Classic\"}}"
"raw": "{\"data\":{\"name\":\"Beijing Office\", \"address\":\"Wangfujing Street, Dongcheng District, Beijing\", \"postal_code\":\"100000\", \"latitude\":39.909429, \"longitude\":116.416993, \"rated_capacity\":600.000, \"rated_power\":100.000, \"contact_id\":1, \"cost_center_id\":1, \"serial_number\": \"S1234567890\", \"svg_id\":1, \"is_cost_data_displayed\":false, \"phase_of_lifecycle\":\"1use\", \"description\":\"Classic\"}}"
},
"url": {
"raw": "{{base_url}}/microgrids",
Expand Down Expand Up @@ -9623,7 +9623,7 @@
],
"body": {
"mode": "raw",
"raw": "{\"data\":{\"name\":\"Beijing Office\", \"address\":\"Wangfujing Street, Dongcheng District, Beijing\", \"postal_code\":\"100000\", \"latitude\":39.909429, \"longitude\":116.416993, \"rated_capacity\":600.000, \"rated_power\":200.000, \"contact_id\":1, \"cost_center_id\":1, \"serial_number\": \"S1234567890\", \"svg\":\"<svg></svg>\", \"is_cost_data_displayed\":false, \"phase_of_lifecycle\":\"2commissioning\", \"description\":\"Classic\"}}"
"raw": "{\"data\":{\"name\":\"Beijing Office\", \"address\":\"Wangfujing Street, Dongcheng District, Beijing\", \"postal_code\":\"100000\", \"latitude\":39.909429, \"longitude\":116.416993, \"rated_capacity\":600.000, \"rated_power\":200.000, \"contact_id\":1, \"cost_center_id\":1, \"serial_number\": \"S1234567890\", \"svg_id\":1, \"is_cost_data_displayed\":false, \"phase_of_lifecycle\":\"2commissioning\", \"description\":\"Classic\"}}"
},
"url": {
"raw": "{{base_url}}/microgrids/1",
Expand Down Expand Up @@ -18497,7 +18497,7 @@
]
},
{
"name": "SVG",
"name": "SVG",
"item": [
{
"name": "GET All SVGs",
Expand Down
83 changes: 64 additions & 19 deletions myems-api/core/microgrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,22 @@ def on_get(req, resp):
cost_center_dict[row[0]] = {"id": row[0],
"name": row[1],
"uuid": row[2]}
svg_dict = dict()

query = (" SELECT id, name, uuid "
" FROM tbl_svgs ")
cursor.execute(query)
rows_svgs = cursor.fetchall()
if rows_svgs is not None and len(rows_svgs) > 0:
for row in rows_svgs:
svg_dict[row[0]] = {"id": row[0],
"name": row[1],
"uuid": row[2]}

query = (" SELECT id, name, uuid, "
" address, postal_code, latitude, longitude, rated_capacity, rated_power, "
" contact_id, cost_center_id, serial_number, svg, is_cost_data_displayed, phase_of_lifecycle, "
" description "
" contact_id, cost_center_id, serial_number, svg_id, is_cost_data_displayed, "
" phase_of_lifecycle, description "
" FROM tbl_microgrids "
" ORDER BY id ")
cursor.execute(query)
Expand All @@ -70,7 +82,7 @@ def on_get(req, resp):
"contact": contact_dict.get(row[9], None),
"cost_center": cost_center_dict.get(row[10], None),
"serial_number": row[11],
"svg": row[12],
"svg": svg_dict.get(row[12], None),
"is_cost_data_displayed": bool(row[13]),
"phase_of_lifecycle": row[14],
"description": row[15],
Expand Down Expand Up @@ -171,12 +183,12 @@ def on_post(req, resp):
description='API.INVALID_SERIAL_NUMBER')
serial_number = str.strip(new_values['data']['serial_number'])

if 'svg' not in new_values['data'].keys() or \
not isinstance(new_values['data']['svg'], str) or \
len(str.strip(new_values['data']['svg'])) == 0:
if 'svg_id' not in new_values['data'].keys() or \
not isinstance(new_values['data']['svg_id'], int) or \
new_values['data']['svg_id'] <= 0:
raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST',
description='API.INVALID_SVG')
svg = str.strip(new_values['data']['svg'])
description='API.INVALID_SVG_ID')
svg_id = new_values['data']['svg_id']

if 'is_cost_data_displayed' not in new_values['data'].keys() or \
not isinstance(new_values['data']['is_cost_data_displayed'], bool):
Expand Down Expand Up @@ -232,9 +244,20 @@ def on_post(req, resp):
raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND',
description='API.COST_CENTER_NOT_FOUND')

cursor.execute(" SELECT name "
" FROM tbl_svgs "
" WHERE id = %s ",
(svg_id,))
row = cursor.fetchone()
if row is None:
cursor.close()
cnx.close()
raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND',
description='API.SVG_NOT_FOUND')

add_values = (" INSERT INTO tbl_microgrids "
" (name, uuid, address, postal_code, latitude, longitude, rated_capacity, rated_power, "
" contact_id, cost_center_id, serial_number, svg, is_cost_data_displayed, "
" contact_id, cost_center_id, serial_number, svg_id, is_cost_data_displayed, "
" phase_of_lifecycle, description) "
" VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s) ")
cursor.execute(add_values, (name,
Expand All @@ -248,7 +271,7 @@ def on_post(req, resp):
contact_id,
cost_center_id,
serial_number,
svg,
svg_id,
is_cost_data_displayed,
phase_of_lifecycle,
description))
Expand Down Expand Up @@ -304,10 +327,21 @@ def on_get(req, resp, id_):
cost_center_dict[row[0]] = {"id": row[0],
"name": row[1],
"uuid": row[2]}
svg_dict = dict()

query = (" SELECT id, name, uuid "
" FROM tbl_svgs ")
cursor.execute(query)
rows_svgs = cursor.fetchall()
if rows_svgs is not None and len(rows_svgs) > 0:
for row in rows_svgs:
svg_dict[row[0]] = {"id": row[0],
"name": row[1],
"uuid": row[2]}

query = (" SELECT id, name, uuid, "
" address, postal_code, latitude, longitude, rated_capacity, rated_power, "
" contact_id, cost_center_id, serial_number, svg, is_cost_data_displayed, phase_of_lifecycle, "
" contact_id, cost_center_id, serial_number, svg_id, is_cost_data_displayed, phase_of_lifecycle, "
" description "
" FROM tbl_microgrids "
" WHERE id = %s ")
Expand All @@ -332,7 +366,7 @@ def on_get(req, resp, id_):
"contact": contact_dict.get(row[9], None),
"cost_center": cost_center_dict.get(row[10], None),
"serial_number": row[11],
"svg": row[12],
"svg": svg_dict.get(row[12], None),
"is_cost_data_displayed": bool(row[13]),
"phase_of_lifecycle": row[14],
"description": row[15],
Expand Down Expand Up @@ -497,12 +531,12 @@ def on_put(req, resp, id_):
description='API.INVALID_SERIAL_NUMBER')
serial_number = str.strip(new_values['data']['serial_number'])

if 'svg' not in new_values['data'].keys() or \
not isinstance(new_values['data']['svg'], str) or \
len(str.strip(new_values['data']['svg'])) == 0:
if 'svg_id' not in new_values['data'].keys() or \
not isinstance(new_values['data']['svg_id'], int) or \
new_values['data']['svg_id'] <= 0:
raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST',
description='API.INVALID_SVG')
svg = str.strip(new_values['data']['svg'])
description='API.INVALID_SVG_ID')
svg_id = new_values['data']['svg_id']

if 'is_cost_data_displayed' not in new_values['data'].keys() or \
not isinstance(new_values['data']['is_cost_data_displayed'], bool):
Expand Down Expand Up @@ -567,11 +601,22 @@ def on_put(req, resp, id_):
raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND',
description='API.COST_CENTER_NOT_FOUND')

cursor.execute(" SELECT name "
" FROM tbl_svgs "
" WHERE id = %s ",
(new_values['data']['svg_id'],))
row = cursor.fetchone()
if row is None:
cursor.close()
cnx.close()
raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND',
description='API.SVG_NOT_FOUND')

update_row = (" UPDATE tbl_microgrids "
" SET name = %s, address = %s, postal_code = %s, latitude = %s, longitude = %s, "
" rated_capacity = %s, rated_power = %s, "
" contact_id = %s, cost_center_id = %s, "
" serial_number = %s, svg = %s, is_cost_data_displayed = %s, phase_of_lifecycle = %s, "
" serial_number = %s, svg_id = %s, is_cost_data_displayed = %s, phase_of_lifecycle = %s, "
" description = %s "
" WHERE id = %s ")
cursor.execute(update_row, (name,
Expand All @@ -584,7 +629,7 @@ def on_put(req, resp, id_):
contact_id,
cost_center_id,
serial_number,
svg,
svg_id,
is_cost_data_displayed,
phase_of_lifecycle,
description,
Expand Down

0 comments on commit 17daa64

Please sign in to comment.