Skip to content

Commit a07db5d

Browse files
committed
Merge branch 'PR' into develop
2 parents 369db7b + 17715f9 commit a07db5d

File tree

4 files changed

+71
-14
lines changed

4 files changed

+71
-14
lines changed

myems-admin/app/controllers/settings/svg/svg.controller.js

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ app.controller('SVGController', function(
1313
$scope.exportdata = '';
1414
$scope.importdata = '';
1515
$scope.current_svg = null;
16-
16+
$scope.searchKeyword = '';
1717
$scope.getAllSVGs = function() {
1818
let headers = { "User-UUID": $scope.cur_user.uuid, "Token": $scope.cur_user.token, "QUICKMODE": true };
1919
SVGService.getAllSVGs(headers, function(response) {
@@ -241,6 +241,39 @@ app.controller('SVGController', function(
241241
$rootScope.modalInstance = modalInstance;
242242
};
243243

244+
let searchDebounceTimer = null;
245+
function safeApply(scope) {
246+
if (!scope.$$phase && !scope.$root.$$phase) {
247+
scope.$apply();
248+
}
249+
}
250+
$scope.searchSVGs = function() {
251+
const headers = {
252+
"User-UUID": $scope.cur_user?.uuid,
253+
"Token": $scope.cur_user?.token
254+
};
255+
256+
const rawKeyword = $scope.searchKeyword || "";
257+
const trimmedKeyword = rawKeyword.trim();
258+
259+
if (searchDebounceTimer) {
260+
clearTimeout(searchDebounceTimer);
261+
}
262+
263+
searchDebounceTimer = setTimeout(() => {
264+
if (!trimmedKeyword) {
265+
$scope.getAllSVGs();
266+
safeApply($scope);
267+
return;
268+
}
269+
270+
SVGService.searchSVGs(trimmedKeyword, headers, (response) => {
271+
$scope.svgs = (response.status === 200) ? response.data : [];
272+
$scope.parentmeters = [...$scope.svgs];
273+
});
274+
}, 300);
275+
};
276+
244277
$scope.getAllSVGs();
245278
});
246279

myems-admin/app/services/settings/svg/svg.service.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@ app.factory('SVGService', function($http) {
1818
});
1919
},
2020
searchSVGs: function(query, headers, callback) {
21-
$http.get(getAPI()+'svgs', { params: { q: query } }, {headers})
21+
$http.get(getAPI()+'svgs', {
22+
params: {q: query},
23+
headers: headers
24+
})
2225
.then(function (response) {
2326
callback(response);
2427
}, function (response) {

myems-admin/views/settings/svg/svg.html

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,16 @@
55
<uib-tabset>
66
<uib-tab heading="{{'COMMON.SVG' | translate}}">
77
<div class="panel-body" ng-controller="SVGController">
8-
<a ng-click="addSVG()" class="btn btn-primary btn-rounded btn-outline" href=""><i class="fa fa-plus-circle"></i> {{'SVG.ADD_SVG' | translate}}</a>
9-
<a ng-click="importSVG()" class="btn btn-primary btn-rounded btn-outline" href=""><i class="fa fa-plus-circle"></i> {{'SETTING.IMPORT' | translate}}</a>
10-
<br>
11-
<br>
8+
<div class="col-md-3">
9+
<a ng-click="addSVG()" class="btn btn-primary btn-rounded btn-outline" href=""><i class="fa fa-plus-circle"></i> {{'SVG.ADD_SVG' | translate}}</a>
10+
<a ng-click="importSVG()" class="btn btn-primary btn-rounded btn-outline" href=""><i class="fa fa-plus-circle"></i> {{'SETTING.IMPORT' | translate}}</a>
11+
</div>
12+
<div class="col-md-9">
13+
<input type="text" class="form-control m-b-xs"
14+
placeholder="{{'SETTING.SEARCH' | translate}}"
15+
ng-model="searchKeyword"
16+
ng-keyup="searchSVGs()">
17+
</div>
1218
<table class="footable table table-bordered table-hover" data-sort="true" data-page-size="15">
1319
<thead>
1420
<tr>

myems-api/core/svg.py

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ class SVGCollection:
1515
It provides endpoints for listing all SVGs and creating new SVGs.
1616
SVGs are used for displaying graphical representations in the energy management system.
1717
"""
18+
1819
def __init__(self):
1920
"""Initialize SVGCollection"""
2021
pass
@@ -33,10 +34,17 @@ def on_get(req, resp):
3334
access_control(req)
3435
else:
3536
api_key_control(req)
37+
38+
search_query = req.get_param('q', default=None)
39+
if search_query is not None:
40+
search_query = search_query.strip()
41+
else:
42+
search_query = ''
43+
3644
# if turn quick mode on, do not return source code
3745
is_quick_mode = False
3846
if 'QUICKMODE' in req.headers and \
39-
isinstance(req.headers['QUICKMODE'], str) and \
47+
isinstance(req.headers['QUICKMODE'], str) and \
4048
len(str.strip(req.headers['QUICKMODE'])) > 0 and \
4149
str.lower(req.headers['QUICKMODE']) in ('true', 't', 'on', 'yes', 'y'):
4250
is_quick_mode = True
@@ -45,25 +53,32 @@ def on_get(req, resp):
4553
cursor = cnx.cursor()
4654
if is_quick_mode:
4755
query = (" SELECT id, name, uuid, description "
48-
" FROM tbl_svgs "
49-
" ORDER BY id ")
50-
cursor.execute(query)
56+
" FROM tbl_svgs ")
57+
params = []
58+
if search_query:
59+
query += " WHERE name LIKE %s OR description LIKE %s "
60+
params = [f'%{search_query}%', f'%{search_query}%']
61+
query += " ORDER BY id "
62+
cursor.execute(query, params)
5163
rows_svgs = cursor.fetchall()
5264

5365
result = list()
5466
if rows_svgs is not None and len(rows_svgs) > 0:
5567
for row in rows_svgs:
56-
5768
meta_result = {"id": row[0],
5869
"name": row[1],
5970
"uuid": row[2],
6071
"description": row[3]}
6172
result.append(meta_result)
6273
else:
6374
query = (" SELECT id, name, uuid, source_code, description "
64-
" FROM tbl_svgs "
65-
" ORDER BY id ")
66-
cursor.execute(query)
75+
" FROM tbl_svgs ")
76+
params = []
77+
if search_query:
78+
query += " WHERE name LIKE %s OR description LIKE %s "
79+
params = [f'%{search_query}%', f'%{search_query}%']
80+
query += " ORDER BY id "
81+
cursor.execute(query, params)
6782
rows_svgs = cursor.fetchall()
6883

6984
result = list()

0 commit comments

Comments
 (0)