Skip to content

Commit

Permalink
feat: history buttons for assets and staff (#31)
Browse files Browse the repository at this point in the history
* feat: history buttons for assets and staff

* style: formatting app.py
  • Loading branch information
drahamim authored Feb 25, 2023
1 parent e65678c commit d42fc35
Show file tree
Hide file tree
Showing 4 changed files with 123 additions and 1 deletion.
23 changes: 22 additions & 1 deletion src/invenflask/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ def checkin():
('Available', asset_id))
conn.commit()
flash('Asset checkin Completed')
return redirect(url_for('checkout'))
return redirect(url_for('checkin'))
except sqlite3.IntegrityError as e:
flash(f"{e}")
return redirect(url_for('checkin'))
Expand Down Expand Up @@ -464,3 +464,24 @@ def parseCSV_staff(
flash("Asset upload failed import")
return redirect(url_for('create_asset'))
return redirect(url_for('status'))


@app.route('/single_history/<rq_type>/<item_id>')
def single_history(rq_type, item_id):

if rq_type == 'asset':
conn = get_db()
current = conn.execute(
'select * from checkouts where assetid = ?', (item_id,))
history = conn.execute(
'select * from history where assetid = ?', (item_id,))
conn.commit()
if rq_type == 'staff':
conn = get_db()
current = conn.execute(
'select * from checkouts where staffid = ?', (item_id,))
history = conn.execute(
'select * from history where staffid = ?', (item_id,))
conn.commit()
return render_template('single_history.html', hist_type=rq_type,
current=current, history=history)
94 changes: 94 additions & 0 deletions src/invenflask/templates/single_history.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
{% extends 'base.html' %}

{% block content %}
{% if hist_type == 'staff' %}
<h1>Staff History</h1>
<label></label>
<table id="current" class="table table-striped">
<thead>
<tr>
<th>Asset ID</th>
<th>Time Stamp</th>
</tr>
</thead>
<tbody>
{% for item in current %}
<tr>
<td>{{ item.assetid }}</td>
<td>{{ item.timestamp }}</td>
</tr>
{% endfor %}
</tbody>
</table>

<label>History</label>
<table id="history" class="table table-striped">
<thead>
<tr>
<th>Asset ID</th>
<th>Check Out</th>
<th>Check In</th>
</tr>
</thead>
<tbody>
{% for item in history %}
<tr>
<td>{{ item.assetid }}</td>
<td>{{ item.checkouttime }}</td>
<td>{{ item.returntime }}</td>
</tr>
{% endfor %}
</tbody>
</table>

{% else %}

<h1> Asset History </h1>
<label>Current</label>
<table id="Staff" class="table table-striped">
<thead>
<tr>
<th style="text-align:left">Staff ID</th>
<th style="text-align:left">Department</th>
<th style="text-align:left">Timestamp</th>
</tr>
</thead>
<tbody>
{% for item in current %}
<tr>
<td>{{ item.staffid }}</td>
<td>{{ item.department }}</td>
<td>{{ item.timestamp }}</td>
</tr>
{% endfor %}
</tbody>
</table>

<label>History</label>
<table id="history" class="table table-striped">
<thead>
<tr>
<th>Staff ID</th>
<th>Department</th>
<th>division</th>
<th>Check Out</th>
<th>Check In</th>
</tr>
</thead>
<tbody>
{% for item in history %}
<tr>
<td>{{ item.staffid }}</td>
<td>{{ item.department }}</td>
<td>{{ item.division }}</td>
<td>{{ item.checkouttime }}</td>
<td>{{ item.returntime }}</td>
</tr>
</tbody>
</table>
{% endfor %}

{% endif %}
{{ data_var|safe }}

{% endblock %}
4 changes: 4 additions & 0 deletions src/invenflask/templates/staff.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
<th style="text-align:left">Division</th>
<th style="text-align:left">Department</th>
<th style="text-align:left">Title</th>
<th style="text-align:left">Edit</th>
<th style="text-align:left">History</th>
</tr>
</thead>
<tbody>
Expand All @@ -23,6 +25,8 @@
<td>{{ staff.title }}</td>
<td><button type="button" onclick="document.location.href='/staff/edit/{{staff.id}}'">Edit</button>
</td>
<td><button type="button" onclick="document.location.href='/single_history/staff/{{staff.id}}'">History</button>
</td>
</tr>
{% endfor %}
</tbody>
Expand Down
3 changes: 3 additions & 0 deletions src/invenflask/templates/status.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<th>Type</th>
<th>Status</th>
<th>Edit</th>
<th>History</th>
</tr>
</thead>
<tbody>
Expand All @@ -18,6 +19,8 @@
<td>{{ asset.asset_status }}</td>
<td><button type="button" onclick="document.location.href='/{{asset.id}}/edit/'">Edit</button>
</td>
<td><button type="button" onclick="document.location.href='/single_history/asset/{{asset.id}}'">History</button>
</td>
</tr>
{% endfor %}
</tbody>
Expand Down

0 comments on commit d42fc35

Please sign in to comment.