Skip to content

Commit

Permalink
[batch] Separate closed and open projects on billing limits page (#13215
Browse files Browse the repository at this point in the history
)

Fixes #13205 

Possible billing project states are defined in the database schema:

```mysql
CREATE TABLE IF NOT EXISTS `billing_projects` (
  `name` VARCHAR(100) NOT NULL,
  `name_cs` VARCHAR(100) NOT NULL COLLATE utf8mb4_0900_as_cs,
  `status` ENUM('open', 'closed', 'deleted') NOT NULL DEFAULT 'open',
  `limit` DOUBLE DEFAULT NULL,
  `msec_mcpu` BIGINT DEFAULT 0,
  PRIMARY KEY (`name`)
) ENGINE = InnoDB;
CREATE INDEX `billing_project_status` ON `billing_projects` (`status`);
CREATE UNIQUE INDEX `billing_project_name_cs` ON `billing_projects` (`name_cs`);
CREATE INDEX `billing_project_name_cs_status` ON `billing_projects` (`name_cs`, `status`);
```
  • Loading branch information
jigold authored Jun 27, 2023
1 parent 3f4c39a commit 4e03b5f
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 3 deletions.
9 changes: 8 additions & 1 deletion batch/batch/front_end/front_end.py
Original file line number Diff line number Diff line change
Expand Up @@ -2217,7 +2217,14 @@ async def ui_get_billing_limits(request, userdata):

billing_projects = await query_billing_projects_with_cost(db, user=user)

page_context = {'billing_projects': billing_projects, 'is_developer': userdata['is_developer']}
open_billing_projects = [bp for bp in billing_projects if bp['status'] == 'open']
closed_billing_projects = [bp for bp in billing_projects if bp['status'] == 'closed']

page_context = {
'open_billing_projects': open_billing_projects,
'closed_billing_projects': closed_billing_projects,
'is_developer': userdata['is_developer'],
}
return await render_template('batch', request, userdata, 'billing_limits.html', page_context)


Expand Down
42 changes: 40 additions & 2 deletions batch/batch/front_end/templates/billing_limits.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
{% block title %}Billing Limits{% endblock %}
{% block content %}
<h1>Billing Project Limits</h1>
{% if open_billing_projects %}
<div class='flex-col' style="overflow: auto;">
<table class="data-table" id="billing_limits">
<h2>Open Projects</h2>
<table class="data-table" id="open-billing-limits">
<thead>
<tr>
<th>Billing Project</th>
Expand All @@ -12,7 +14,7 @@ <h1>Billing Project Limits</h1>
</tr>
</thead>
<tbody>
{% for row in billing_projects %}
{% for row in open_billing_projects %}
<tr>
<td>{{ row['billing_project'] }}</td>
<td>{{ row['accrued_cost'] }}</td>
Expand All @@ -34,4 +36,40 @@ <h1>Billing Project Limits</h1>
</tbody>
</table>
</div>
{% endif %}
{% if closed_billing_projects %}
<div class='flex-col' style="overflow: auto;">
<h2>Closed Projects</h2>
<table class="data-table" id="closed-billing-limits">
<thead>
<tr>
<th>Billing Project</th>
<th>Accrued Cost</th>
<th>Limit</th>
</tr>
</thead>
<tbody>
{% for row in closed_billing_projects %}
<tr>
<td>{{ row['billing_project'] }}</td>
<td>{{ row['accrued_cost'] }}</td>
{% if is_developer %}
<td>
<form action="{{ base_path }}/billing_limits/{{ row['billing_project'] }}/edit" method="POST">
<input type="hidden" name="_csrf" value="{{ csrf_token }}">
<input type="text" required name="limit" value="{{ row['limit'] }}">
<button>
Edit
</button>
</form>
</td>
{% else %}
<td>{{ row['limit'] }}</td>
{% endif %}
</tr>
{% endfor %}
</tbody>
</table>
</div>
{% endif %}
{% endblock %}

0 comments on commit 4e03b5f

Please sign in to comment.