Skip to content
Snippets Groups Projects
Commit d0dfa712 authored by Benjamin Bertrand's avatar Benjamin Bertrand
Browse files

Move QR codes to attributes table

- Remove QRcodes page
- Add Status to attributes page (only allow admin to add new statuses)

Actions QR Codes not visible anymore. Required ones shall be put on the
page where they are used.
parent 26ca9034
No related branches found
No related tags found
No related merge requests found
......@@ -201,20 +201,6 @@ def edit_item(ics_id):
return render_template('inventory/edit_item.html', form=form)
@bp.route('/qrcodes/<kind>')
@login_required
def qrcodes(kind='Action'):
try:
model = getattr(models, kind)
except AttributeError:
raise utils.CSEntryError(f"Unknown model '{kind}'", status_code=422)
items = db.session.query(model).order_by(model.name)
images = [{'name': item.name,
'data': item.base64_image()}
for item in items]
return render_template('inventory/qrcodes.html', kind=kind, images=images)
@bp.route('/attributes/<kind>', methods=('GET', 'POST'))
@login_groups_accepted('admin', 'create')
def attributes(kind):
......@@ -235,15 +221,15 @@ def attributes(kind):
return render_template('inventory/attributes.html', kind=kind, form=form)
@bp.route('/_retrieve_attributes_name/<kind>')
@bp.route('/_retrieve_attributes/<kind>')
@login_required
def retrieve_attributes_name(kind):
def retrieve_attributes(kind):
try:
model = getattr(models, kind)
except AttributeError:
raise utils.CSEntryError(f"Unknown model '{kind}'", status_code=422)
items = db.session.query(model).order_by(model.name)
data = [(item.name, item.description) for item in items]
data = [(item.base64_image(), item.name, item.description) for item in items]
return jsonify(data=data)
......
......@@ -4,11 +4,23 @@ $(document).ready(function() {
"ajax": function(data, callback, settings) {
var kind = $('li a.nav-link.active').text();
$.getJSON(
$SCRIPT_ROOT + "/inventory/_retrieve_attributes_name/" + kind,
$SCRIPT_ROOT + "/inventory/_retrieve_attributes/" + kind,
function(json) {
callback(json);
});
},
"order": [[1, 'asc']],
"columnDefs": [
{
"targets": [0],
"orderable": false,
"render": function(data, type, row) {
// render QR code from base64 string
return '<img class="img-fluid" src="data:image/png;base64,' + data + '">';
},
"width": "6%",
}
],
"paging": false
});
......
......@@ -14,8 +14,6 @@
href="{{ url_for('inventory.list_items') }}">Items</a>
<a class="list-group-item list-group-item-action {{ is_active(path.startswith("/inventory/attributes")) }}"
href="{{ url_for('inventory.attributes', kind='Manufacturer') }}">Attributes</a>
<a class="list-group-item list-group-item-action {{ is_active(path.startswith("/inventory/qrcodes")) }}"
href="{{ url_for('inventory.qrcodes', kind='Action') }}">QR Codes</a>
<a class="list-group-item list-group-item-action {{ is_active(path.startswith("/inventory/scanner")) }}"
href="{{ url_for('inventory.scanner') }}">Scanner setup</a>
{% elif path.startswith("/network") %}
......
......@@ -5,7 +5,7 @@
{% block main %}
<ul class="nav nav-tabs">
{% for attribute in ('Manufacturer', 'Model', 'Location') %}
{% for attribute in ('Manufacturer', 'Model', 'Location', 'Status') %}
<li class="nav-item">
<a class="nav-link {% if attribute == kind %}active{% endif %}" href="{{ url_for('inventory.attributes', kind=attribute) }}">{{ attribute }}</a>
</li>
......@@ -14,22 +14,25 @@
<br>
<form id="attributeForm" method="POST">
{{ form.hidden_tag() }}
{{ render_field(form.name) }}
{{ render_field(form.description) }}
<div class="form-group row">
<div class="col-sm-10">
<button type="submit" class="btn btn-primary">Create</button>
{% if kind in ('Manufacturer', 'Model', 'Location') or (current_user.is_authenticated and current_user.is_admin) %}
<form id="attributeForm" method="POST">
{{ form.hidden_tag() }}
{{ render_field(form.name) }}
{{ render_field(form.description) }}
<div class="form-group row">
<div class="col-sm-10">
<button type="submit" class="btn btn-primary">Create</button>
</div>
</div>
</div>
</form>
</form>
<hr class="separator">
<hr class="separator">
{%- endif %}
<table id="attributes_table" class="table table-bordered table-hover table-sm" cellspacing="0" width="100%">
<thead>
<tr>
<th></th>
<th>Name</th>
<th>Description</th>
</tr>
......
{% extends "base-fluid.html" %}
{% block title %}QR Codes - CSEntry{% endblock %}
{% block main %}
<ul class="nav nav-tabs">
{% for item in ('Action', 'Manufacturer', 'Model', 'Location', 'Status') %}
<li class="nav-item">
<a class="nav-link {% if kind == item %}active{% endif %}" href="{{ url_for('inventory.qrcodes', kind=item) }}">{{ item }}</a>
</li>
{% endfor %}
</ul>
<br>
<div class="row">
{% for image in images %}
<div class="col-md-3">
<div class="card">
<img class="card-img-top" src="data:image/png;base64,{{ image.data }}">
<div class="card-body">
<h4 class="card-title">{{ image.name }}</h4>
</div>
</div>
</div>
{% endfor %}
</div>
{%- endblock %}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment