list.html 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. {% extends 'base.html' %}
  2. {% macro sel(col, vals) %}
  3. <label class="f">{{ cn.get(col, col) }}
  4. <select name="{{ col }}" onchange="this.form.submit()">
  5. <option value="">全部</option>
  6. {% for o in vals %}<option value="{{ o.v }}" {{ 'selected' if filters.get(col) == o.v|string }}>{{ o.l }}</option>{% endfor %}
  7. </select>
  8. </label>
  9. {% endmacro %}
  10. {% block title %}{{ meta.cn }}台账{% endblock %}
  11. {% block body %}
  12. <div class="page-head">
  13. <div>
  14. <h1>{{ meta.cn }}台账</h1>
  15. <div class="sub">
  16. 共 <b>{{ total|num }}</b> 条记录 · 主键 {{ meta.pk|join(' + ') }}{% if table == 'signal' %} · 最新值日期 {{ day }}{% endif %}
  17. </div>
  18. </div>
  19. <div class="acts">
  20. <a href="/db/{{ table }}/new"><button type="button" class="gray">新增一条</button></a>
  21. <a href="/db/{{ table }}/import"><button type="button" class="gray">导入 CSV</button></a>
  22. <a href="{{ export_url }}" class="loadable" data-ld="正在导出 {{ total }} 条…"
  23. data-ld-sub="{{ '导出要把 ' ~ day ~ ' 的原始 CSV 尾部扫一遍取最新值,比列表页还慢,下载没弹出来就是还在扫。' if table == 'signal' else '' }}"><button type="button" class="gray">导出 CSV</button></a>
  24. </div>
  25. </div>
  26. {% if ok %}<div class="flash">{{ ok }}</div>{% endif %}
  27. {% set ld_msg = ('正在查测点:' ~ day ~ ' 那天的原始 CSV 要现扫一遍尾部才能带出最新值,'
  28. ~ '按风场/端口筛一下能少扫几个文件、快很多…')
  29. if table == 'signal' else '正在查询…' %}
  30. {% set ld_sub = '期间别重复点查询、别关页面(每点一次就重扫一遍,一起跑更慢);转完这一页自己就出来了。'
  31. if table == 'signal' else '' %}
  32. <div class="card">
  33. <form method="get" action="/db/{{ table }}" class="loadable" data-ld="{{ ld_msg }}" data-ld-sub="{{ ld_sub }}">
  34. <div class="frow">
  35. <input name="q" value="{{ q }}" placeholder="关键字(搜所有列)">
  36. <span class="casc" title="这一组是级联的:选一个,其余几个就只列这条筛选下还有的值">
  37. {% for col, vals in opts.items() if col in ('farm_id', 'machine_type', 'wind_id') %}{{ sel(col, vals) }}{% endfor %}
  38. </span>
  39. {% for col, vals in opts.items() if col not in ('farm_id', 'machine_type', 'wind_id') %}{{ sel(col, vals) }}{% endfor %}
  40. <label class="f">每页
  41. <select name="size" onchange="this.form.submit()">
  42. {% for s in [20, 50, 200, 500] %}<option value="{{ s }}" {{ 'selected' if size == s }}>{{ s }} 条</option>{% endfor %}
  43. </select>
  44. </label>
  45. {% if table == 'signal' %}
  46. <label class="f">最新值日期 <input name="day" class="mono" size="9" value="{{ day }}"></label>
  47. {% endif %}
  48. <button type="submit">查询</button>
  49. {% if table == 'signal' %}
  50. <a href="{{ refresh_url }}" class="loadable" data-ld="{{ ld_msg }}" data-ld-sub="{{ ld_sub }}"><button type="button" class="gray">刷新最新值</button></a>
  51. {% endif %}
  52. {% if q or filters %}<a href="/db/{{ table }}" class="hint">清空条件</a>{% endif %}
  53. </div>
  54. <div class="hint blk">导出的是当前筛选条件下的全部 {{ total|num }} 条,不只这一页{% if table == 'signal' %};测点导出带上 {{ day }} 扫到的最新值、采集/接收时标和时标标记(空白=这一天这个点没上报或没扫到,只要台账就在链接后加 ?values=0){% endif %}。
  55. 导出的文件改完直接从「导入 CSV」传回来:按主键只更新库里已有的记录,先出预览再写,一行都不会新增或删除。改动会立刻写进基础属性库,并顶一下点表版本让采集进程热重载(最多 5 秒)。</div>
  56. {% if table == 'signal' and rows %}
  57. <div class="hint blk">最新值取自 {{ day }} 原始 CSV 的尾部:本页 {{ rows|length }} 个点里 {{ lat_hit }} 个取到值{% if lat_hit %}(扫了 {{ lat_files|length }} 个文件 / {{ lat_scanned }} 行{% if lat_skipped %},还有 {{ lat_skipped }} 个风场没扫,按端口筛一下更快{% endif %}){% else %}(这一天没有读到值,先按端口筛或改日期){% endif %};空白表示尾部窗口里这个点没上报。页面不自动刷新,点「刷新最新值」重读。</div>
  58. {% endif %}
  59. </form>
  60. </div>
  61. {% include '_pager.html' %}
  62. <div class="wrap">
  63. <table class="{{ 'tbl-wide' if table in ('signal', 'port') else '' }}">
  64. <thead><tr>
  65. {% for col, cn, req in meta.cols %}<th{% if col in meta.pk %} style="background:#e8f0fe"{% endif %}>{{ cn }}{% if col in meta.pk %} *{% endif %}</th>
  66. {% if table == 'signal' and col == 'wind_id' %}<th title="机型不在测点台账里,是按 风场 + 机组号 从机组台账带出来的,要改去机组台账改">机型</th>{% endif %}{% endfor %}
  67. {% if table == 'signal' %}<th>最新值</th><th>采集时标</th>{% endif %}
  68. <th class="ops">操作</th>
  69. </tr></thead>
  70. <tbody>
  71. {% for r in rows %}
  72. <tr>
  73. {% for col, cn, req in meta.cols %}
  74. {% if col == 'farm_id' %}
  75. <td class="nw"><a href="/db/farm?farm_id={{ r[col]|urlencode }}" title="{{ r[col] }}">{{ farms.get(r[col], r[col]) or '-' }}</a>
  76. {% if table == 'farm' %} <span class="hint mono">{{ r[col] }}</span>{% endif %}</td>
  77. {% elif col == 'name' and table == 'port' %}
  78. <td>{{ r['_name_disp'] or '-' }}{% if not r[col] and r['_name_disp'] %} <span class="hint">(取自机组台账的风场名)</span>{% endif %}</td>
  79. {% elif col == 'enabled' %}
  80. <td>{% if r[col] %}<span class="chip ok">启用</span>{% else %}<span class="chip off">停用</span>{% endif %}</td>
  81. {% else %}
  82. <td class="{{ 'mono' if col in ('port', 'common_addr', 'obj_addr', 'signal_id', 'algo_signal', 'wind_id', 'engine_code', 'mill_type_code') else '' }}">
  83. {{ r[col] if r[col] not in (none, '') else '' }}</td>
  84. {% endif %}
  85. {% if table == 'signal' and col == 'wind_id' %}
  86. <td class="mono">{{ r.get('machine_type') or '-' }}</td>
  87. {% endif %}
  88. {% endfor %}
  89. {% if table == 'signal' %}
  90. {% set l = r.get('_lat') %}
  91. <td class="mono">{{ l.value if l else '-' }}{% if l and l.bad %} <span class="chip warn">时标异常</span>{% endif %}</td>
  92. <td class="mono" title="设备时标 {{ l.collect if l else '' }}">{{ l.recv if l else '-' }}</td>
  93. {% endif %}
  94. <td class="ops"><a href="{{ r['_edit'] }}">编辑</a>
  95. <form class="inline" method="post" action="{{ r['_del'] }}"
  96. onsubmit="return confirm('确定删除这条 {{ meta.cn }}?采集进程 5 秒内会重新加载点表。')">
  97. <button type="submit" class="mini red">删除</button>
  98. </form></td>
  99. </tr>
  100. {% else %}
  101. <tr><td colspan="{{ meta.cols|length + (4 if table == 'signal' else 1) }}" class="hint">没有符合条件的记录。</td></tr>
  102. {% endfor %}
  103. </tbody>
  104. </table>
  105. </div>
  106. {% include '_pager.html' %}
  107. {% endblock %}