sbd-npm 1.4.8 → 1.4.10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. package/package.json +1 -1
  2. package/status.js +82 -4
  3. package/util.js +38 -27
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sbd-npm",
3
- "version": "1.4.8",
3
+ "version": "1.4.10",
4
4
  "description": "Stock Big Data",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/status.js CHANGED
@@ -38,6 +38,9 @@ $(function () {
38
38
  case "task":
39
39
  Status.handle_task();
40
40
  break;
41
+ case "worker":
42
+ Status.handle_worker();
43
+ break;
41
44
  case "tool":
42
45
  Status.handle_tool();
43
46
  break;
@@ -161,15 +164,21 @@ $(function () {
161
164
 
162
165
  handle_process: function () {
163
166
  if (!document.getElementById("process_div_body")) {
167
+ let prefix_caption = "";
168
+ if (Util.is_mobile()) {
169
+ prefix_caption = "<caption>&nbsp;&nbsp;&nbsp;";
170
+ } else {
171
+ prefix_caption = '<caption class="text-right">';
172
+ }
164
173
  Util.init_table_skeleton({
165
174
  "element_id": "process_div",
166
- "caption": '<caption class="text-right">共 <span class="label label-info" id="process_num"></span> 进程,<input checked type="checkbox" id="is_py_process"> 只显示Python进程</caption>',
175
+ "caption": prefix_caption + ' <span class="label label-info" id="process_num"></span> 进程,&nbsp;&nbsp;<input checked type="checkbox" id="is_py_process"> 只显示 Python 进程</caption>',
167
176
  "head_cols": [
168
177
  {"name": "进程ID", "table_sort": 1},
169
178
  {"name": "进程名", "table_sort": 1},
170
179
  {"name": "用户名", "table_sort": 1},
171
180
  {"name": "状态", "table_sort": 1},
172
- {"name": "实际内存", "table_sort": 1, "title": "resident set size"},
181
+ {"name": "实际内存", "class": "info", "table_sort": 1, "title": "resident set size"},
173
182
  {"name": "虚拟内存", "table_sort": 1},
174
183
  {"name": "启动命令"},
175
184
  {"name": "创建时间", "table_sort": 1},
@@ -197,7 +206,7 @@ $(function () {
197
206
  html.push("<td>", Util.seconds_to_format(item["create_time"]), "</td>");
198
207
  html.push("</tr>");
199
208
  });
200
- $("#process_div_body").html(html.join(""));
209
+ Util.render_table_html("process_div_body", html);
201
210
  $("#process_num").html(process_num);
202
211
  Util.hide_tips();
203
212
  });
@@ -398,7 +407,7 @@ $(function () {
398
407
 
399
408
  handle_task: function () {
400
409
  if (!document.getElementById("task_content")) {
401
- let ht_html =[];
410
+ let ht_html = [];
402
411
  ht_html.push('<div class="page-header" style="margin-top: 15px; text-align: center;">');
403
412
  ht_html.push('<div class="form-inline">');
404
413
  ht_html.push('<div class="form-group">');
@@ -510,6 +519,75 @@ $(function () {
510
519
  });
511
520
  },
512
521
 
522
+ handle_worker: function () {
523
+ let is_init = 0;
524
+ if (!document.getElementById("workers")) {
525
+ is_init = 1;
526
+ let hw_html = [];
527
+ hw_html.push('<form class="form-inline">');
528
+ hw_html.push('<div class="form-group">');
529
+ hw_html.push('<select id="workers" class="form-control">');
530
+ hw_html.push('<option value="">Loading...</option>');
531
+ hw_html.push('</select>');
532
+ hw_html.push('</div>');
533
+ hw_html.push('</form>');
534
+ hw_html.push('<div id="worker_process_div"></div>');
535
+ $("#worker_div").html(hw_html.join(""));
536
+ }
537
+ Util.post(location.pathname, {active_div: localStorage[Status.tab_token], is_init: is_init, key: $("#workers").val()}, function (j) {
538
+ if (j["workers"]) {
539
+ let select_html = [];
540
+ select_html.push("<option value=''>共 ", j["workers"].length, " 个Worker</option>");
541
+ j["workers"].forEach(function (w) {
542
+ select_html.push("<option value='", w["key"], "'>", w["ip"], "</option>");
543
+ });
544
+ $("#workers").html(select_html.join(""));
545
+ if (j["workers"].length > 0) {
546
+ $("#workers").change(function() {
547
+ let worker_key = $(this).val();
548
+ if (worker_key) {
549
+ Util.show_loading();
550
+ Util.set_table_loading("worker_process_div_body");
551
+ Status.handle_worker();
552
+ }
553
+ });
554
+ }
555
+ } else if (j["process"]) {
556
+ if (!document.getElementById("worker_process_div_body")) {
557
+ let prefix_caption = "";
558
+ if (Util.is_mobile()) {
559
+ prefix_caption = "<caption id='worker_process_tip'>&nbsp;&nbsp;&nbsp;";
560
+ } else {
561
+ prefix_caption = '<caption id="worker_process_tip" class="text-right">';
562
+ }
563
+ Util.init_table_skeleton({
564
+ "element_id": "worker_process_div",
565
+ "caption": prefix_caption + '</caption>',
566
+ "head_cols": [
567
+ {"name": "进程ID", "table_sort": 1},
568
+ {"name": "状态", "table_sort": 1},
569
+ {"name": "启动命令"},
570
+ {"name": "创建时间", "class": "info", "table_sort": 1},
571
+ ]
572
+ });
573
+ }
574
+ let html = [], process_num = 0;
575
+ j["process"].forEach(function (item) {
576
+ process_num++;
577
+ html.push("<tr>");
578
+ html.push("<td>", item["pid"], "</td>");
579
+ html.push("<td>", item["status"], "</td>");
580
+ html.push("<td title='", item["cmdline"], "'>", Util.sub_str(item["cmdline"], 100), "</td>");
581
+ html.push("<td>", Util.seconds_to_format(item["create_time"]), "</td>");
582
+ html.push("</tr>");
583
+ });
584
+ Util.render_table_html("worker_process_div_body", html);
585
+ $("#worker_process_tip").html('共 <span class="label label-info">' + process_num + '</span> 进程,最后更新时间:' + Util.seconds_to_format(j["date"]));
586
+ }
587
+ Util.hide_tips();
588
+ });
589
+ },
590
+
513
591
  handle_tool: function () {
514
592
  let t_obj = $("#timestamp");
515
593
  let t_val = t_obj.val();
package/util.js CHANGED
@@ -96,40 +96,16 @@ const Util = {
96
96
  });
97
97
 
98
98
  $('#stock').keyup(function () {
99
- let st_obj = $("#search-tips");
100
99
  let key_word = $(this).val();
101
100
  if (key_word) {
102
101
  if (Util.is_has_chinese(key_word) || (Util.is_alpha(key_word) && key_word.length >= 2) || ($.isNumeric(key_word) && key_word.length >= 3)) {
103
102
  Util.hide_tips();
104
103
  clearTimeout(Util.stock_timer_id);
105
- st_obj.css("display", "none");
106
- Util.stock_timer_id = setTimeout(function () {
107
- Util.show_loading();
108
- Util.post("/action", {action: "search", key_word: key_word}, function (j) {
109
- let key_word = $("#stock").val();
110
- if (key_word) {
111
- let _html = [];
112
- _html.push('<div class="list-group">');
113
- if (j.data.length > 0) {
114
- $.each(j.data, function (index, item) {
115
- let upper_code = item["code"].toUpperCase();
116
- _html.push('<a target="_blank" rel="noopener noreferrer nofollow" class="list-group-item" href="/stock/', upper_code, '">', (item["name"] ? item["name"] : upper_code), '(', upper_code, ')</a>');
117
- });
118
- } else {
119
- _html.push('<a href="#" class="list-group-item disabled">无数据</a>');
120
- }
121
- _html.push('</div>');
122
- st_obj.html(_html.join(""));
123
- st_obj.css("display", "block");
124
- } else {
125
- st_obj.css("display", "none");
126
- }
127
- Util.hide_tips();
128
- });
129
- }, 500);
104
+ $("#search-tips").css("display", "none");
105
+ Util.stock_timer_id = setTimeout(Util.request_search, 500);
130
106
  }
131
107
  } else {
132
- st_obj.css("display", "none");
108
+ $("#search-tips").css("display", "none");
133
109
  }
134
110
  });
135
111
 
@@ -175,6 +151,41 @@ const Util = {
175
151
  $("#sidebar-menu").html(_html.join(""));
176
152
  },
177
153
 
154
+ /**
155
+ * 查询请求
156
+ */
157
+ request_search: function() {
158
+ Util.show_loading();
159
+ Util.post("/action", {action: "search", key_word: $("#stock").val()}, function (j) {
160
+ let key_word = $("#stock").val();
161
+ if (key_word) {
162
+ if (key_word === j["key_word"]) {
163
+ let html = [];
164
+ html.push('<div class="list-group">');
165
+ if (j["data"] && j["data"].length > 0) {
166
+ j["data"].forEach(function (item) {
167
+ let upper_code = item["code"].toUpperCase();
168
+ html.push('<a target="_blank" rel="noopener noreferrer nofollow" class="list-group-item" href="/stock/', upper_code, '">', (item["name"] ? item["name"] : upper_code), '(', upper_code, ')</a>');
169
+ });
170
+ } else {
171
+ html.push('<a href="#" class="list-group-item disabled">无数据</a>');
172
+ }
173
+ html.push('</div>');
174
+ let st_obj = $("#search-tips");
175
+ st_obj.html(html.join(""));
176
+ st_obj.css("display", "block");
177
+ Util.hide_tips();
178
+ } else {
179
+ Util.hide_tips();
180
+ Util.request_search();
181
+ }
182
+ } else {
183
+ $("#search-tips").css("display", "none");
184
+ Util.hide_tips();
185
+ }
186
+ });
187
+ },
188
+
178
189
  /**
179
190
  * 获取链接 URL 地址
180
191
  * @param key