resolv conflict

This commit is contained in:
Cayo Puigdefabregas 2022-01-25 10:37:30 +01:00
commit 55ce612b2a
11 changed files with 1089 additions and 53 deletions

View File

@ -1,11 +1,23 @@
import json
from flask_wtf import FlaskForm
from wtforms import StringField, validators
from flask import g
from wtforms import StringField, validators, MultipleFileField, FloatField, IntegerField
from flask import g, request
from sqlalchemy.util import OrderedSet
from json.decoder import JSONDecodeError
from ereuse_devicehub.db import db
from ereuse_devicehub.resources.device.models import Device
from ereuse_devicehub.resources.device.models import Device, Computer, Smartphone, Cellphone, \
Tablet, Monitor, Mouse, Keyboard, \
MemoryCardReader, SAI
from ereuse_devicehub.resources.action.models import RateComputer, Snapshot, VisualTest
from ereuse_devicehub.resources.action.schemas import Snapshot as SnapshotSchema
from ereuse_devicehub.resources.lot.models import Lot
from ereuse_devicehub.resources.tag.model import Tag
from ereuse_devicehub.resources.enums import SnapshotSoftware, Severity
from ereuse_devicehub.resources.user.exceptions import InsufficientPermission
from ereuse_devicehub.resources.action.rate.v1_0 import CannotRate
from ereuse_devicehub.resources.device.sync import Sync
from ereuse_devicehub.resources.action.views.snapshot import save_json, move_json
class LotDeviceForm(FlaskForm):
@ -55,18 +67,16 @@ class LotForm(FlaskForm):
self.name.data = self.instance.name
def save(self):
name = self.name.data.strip()
if self.instance:
if self.instance.name == name:
return self.instance
self.instance.name = name
else:
self.instance = Lot(name=name)
if not self.id:
self.instance = Lot(name=self.name.data)
self.populate_obj(self.instance)
if not self.id:
self.id = self.instance.id
db.session.add(self.instance)
db.session.commit()
return self.instance
return self.id
db.session.commit()
return self.id
@ -78,6 +88,290 @@ class LotForm(FlaskForm):
return self.instance
class UploadSnapshotForm(FlaskForm):
snapshot = MultipleFileField(u'Select a Snapshot File', [validators.DataRequired()])
def validate(self, extra_validators=None):
is_valid = super().validate(extra_validators)
if not is_valid:
return False
data = request.files.getlist(self.snapshot.name)
if not data:
return False
self.snapshots = []
self.result = {}
for d in data:
filename = d.filename
self.result[filename] = 'Not processed'
d = d.stream.read()
if not d:
self.result[filename] = 'Error this snapshot is empty'
continue
try:
d_json = json.loads(d)
except JSONDecodeError:
self.result[filename] = 'Error this snapshot is not a json'
continue
uuid_snapshot = d_json.get('uuid')
if Snapshot.query.filter(Snapshot.uuid == uuid_snapshot).all():
self.result[filename] = 'Error this snapshot exist'
continue
self.snapshots.append((filename, d_json))
if not self.snapshots:
return False
return True
def save(self):
if any([x == 'Error' for x in self.result.values()]):
return
# result = []
self.sync = Sync()
schema = SnapshotSchema()
# self.tmp_snapshots = app.config['TMP_SNAPSHOTS']
# TODO @cayop get correct var config
self.tmp_snapshots = '/tmp/'
for filename, snapshot_json in self.snapshots:
path_snapshot = save_json(snapshot_json, self.tmp_snapshots, g.user.email)
snapshot_json.pop('debug', None)
snapshot_json = schema.load(snapshot_json)
response = self.build(snapshot_json)
if hasattr(response, 'type'):
self.result[filename] = 'Ok'
else:
self.result[filename] = 'Error'
move_json(self.tmp_snapshots, path_snapshot, g.user.email)
db.session.commit()
return response
def build(self, snapshot_json):
# this is a copy adaptated from ereuse_devicehub.resources.action.views.snapshot
device = snapshot_json.pop('device') # type: Computer
components = None
if snapshot_json['software'] == (SnapshotSoftware.Workbench or SnapshotSoftware.WorkbenchAndroid):
components = snapshot_json.pop('components', None) # type: List[Component]
if isinstance(device, Computer) and device.hid:
device.add_mac_to_hid(components_snap=components)
snapshot = Snapshot(**snapshot_json)
# Remove new actions from devices so they don't interfere with sync
actions_device = set(e for e in device.actions_one)
device.actions_one.clear()
if components:
actions_components = tuple(set(e for e in c.actions_one) for c in components)
for component in components:
component.actions_one.clear()
assert not device.actions_one
assert all(not c.actions_one for c in components) if components else True
db_device, remove_actions = self.sync.run(device, components)
del device # Do not use device anymore
snapshot.device = db_device
snapshot.actions |= remove_actions | actions_device # Set actions to snapshot
# commit will change the order of the components by what
# the DB wants. Let's get a copy of the list so we preserve order
ordered_components = OrderedSet(x for x in snapshot.components)
# Add the new actions to the db-existing devices and components
db_device.actions_one |= actions_device
if components:
for component, actions in zip(ordered_components, actions_components):
component.actions_one |= actions
snapshot.actions |= actions
if snapshot.software == SnapshotSoftware.Workbench:
# Check ownership of (non-component) device to from current.user
if db_device.owner_id != g.user.id:
raise InsufficientPermission()
# Compute ratings
try:
rate_computer, price = RateComputer.compute(db_device)
except CannotRate:
pass
else:
snapshot.actions.add(rate_computer)
if price:
snapshot.actions.add(price)
elif snapshot.software == SnapshotSoftware.WorkbenchAndroid:
pass # TODO try except to compute RateMobile
# Check if HID is null and add Severity:Warning to Snapshot
if snapshot.device.hid is None:
snapshot.severity = Severity.Warning
db.session.add(snapshot)
return snapshot
class NewDeviceForm(FlaskForm):
type = StringField(u'Type', [validators.DataRequired()])
label = StringField(u'Label')
serial_number = StringField(u'Seria Number', [validators.DataRequired()])
model = StringField(u'Model', [validators.DataRequired()])
manufacturer = StringField(u'Manufacturer', [validators.DataRequired()])
appearance = StringField(u'Appearance', [validators.Optional()])
functionality = StringField(u'Functionality', [validators.Optional()])
brand = StringField(u'Brand')
generation = IntegerField(u'Generation')
version = StringField(u'Version')
weight = FloatField(u'Weight', [validators.DataRequired()])
width = FloatField(u'Width', [validators.DataRequired()])
height = FloatField(u'Height', [validators.DataRequired()])
depth = FloatField(u'Depth', [validators.DataRequired()])
variant = StringField(u'Variant', [validators.Optional()])
sku = StringField(u'SKU', [validators.Optional()])
image = StringField(u'Image', [validators.Optional(), validators.URL()])
imei = IntegerField(u'IMEI', [validators.Optional()])
meid = StringField(u'MEID', [validators.Optional()])
resolution = IntegerField(u'Resolution width', [validators.Optional()])
screen = FloatField(u'Screen size', [validators.Optional()])
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.devices = {"Smartphone": Smartphone,
"Tablet": Tablet,
"Cellphone": Cellphone,
"Monitor": Monitor,
"Mouse": Mouse,
"Keyboard": Keyboard,
"SAI": SAI,
"MemoryCardReader": MemoryCardReader}
if not self.generation.data:
self.generation.data = 1
if not self.weight.data:
self.weight.data = 0.1
if not self.height.data:
self.height.data = 0.1
if not self.width.data:
self.width.data = 0.1
if not self.depth.data:
self.depth.data = 0.1
def validate(self, extra_validators=None):
error = ["Not a correct value"]
is_valid = super().validate(extra_validators)
if self.generation.data < 1:
self.generation.errors = error
is_valid = False
if self.weight.data < 0.1:
self.weight.errors = error
is_valid = False
if self.height.data < 0.1:
self.height.errors = error
is_valid = False
if self.width.data < 0.1:
self.width.errors = error
is_valid = False
if self.depth.data < 0.1:
self.depth.errors = error
is_valid = False
if self.imei.data:
if not 13 < len(str(self.imei.data)) < 17:
self.imei.errors = error
is_valid = False
if self.meid.data:
meid = self.meid.data
if not 13 < len(meid) < 17:
is_valid = False
try:
int(meid, 16)
except ValueError:
self.meid.errors = error
is_valid = False
if not is_valid:
return False
if self.image.data == '':
self.image.data = None
if self.manufacturer.data:
self.manufacturer.data = self.manufacturer.data.lower()
if self.model.data:
self.model.data = self.model.data.lower()
if self.serial_number.data:
self.serial_number.data = self.serial_number.data.lower()
return True
def save(self):
json_snapshot = {
'type': 'Snapshot',
'software': 'Web',
'version': '11.0',
'device': {
'type': self.type.data,
'model': self.model.data,
'manufacturer': self.manufacturer.data,
'serialNumber': self.serial_number.data,
'brand': self.brand.data,
'version': self.version.data,
'generation': self.generation.data,
'sku': self.sku.data,
'weight': self.weight.data,
'width': self.width.data,
'height': self.height.data,
'depth': self.depth.data,
'variant': self.variant.data,
'image': self.image.data
}
}
if self.appearance.data or self.functionality.data:
json_snapshot['device']['actions'] = [{
'type': 'VisualTest',
'appearanceRange': self.appearance.data,
'functionalityRange': self.functionality.data
}]
upload_form = UploadSnapshotForm()
upload_form.sync = Sync()
schema = SnapshotSchema()
self.tmp_snapshots = '/tmp/'
path_snapshot = save_json(json_snapshot, self.tmp_snapshots, g.user.email)
snapshot_json = schema.load(json_snapshot)
if self.type.data == 'Monitor':
snapshot_json['device'].resolution_width = self.resolution.data
snapshot_json['device'].size = self.screen.data
if self.type.data in ['Smartphone', 'Tablet', 'Cellphone']:
snapshot_json['device'].imei = self.imei.data
snapshot_json['device'].meid = self.meid.data
snapshot = upload_form.build(snapshot_json)
move_json(self.tmp_snapshots, path_snapshot, g.user.email)
if self.type.data == 'Monitor':
snapshot.device.resolution = self.resolution.data
snapshot.device.screen = self.screen.data
db.session.commit()
return snapshot
class TagForm(FlaskForm):
code = StringField(u'Code', [validators.length(min=1)])
@ -99,6 +393,3 @@ class NewActionForm(FlaskForm):
date = StringField(u'Date')
severity = StringField(u'Severity')
description = StringField(u'Description')
def save(self):
pass

View File

@ -1,12 +1,13 @@
import flask
from flask.views import View
from flask import Blueprint, url_for
from flask import Blueprint, url_for, request
from flask_login import login_required, current_user
from ereuse_devicehub.resources.lot.models import Lot
from ereuse_devicehub.resources.tag.model import Tag
from ereuse_devicehub.resources.device.models import Device
from ereuse_devicehub.inventory.forms import LotDeviceForm, LotForm, TagForm
from ereuse_devicehub.inventory.forms import LotDeviceForm, LotForm, UploadSnapshotForm, \
NewDeviceForm, TagForm
devices = Blueprint('inventory.devices', __name__, url_prefix='/inventory')
@ -15,18 +16,21 @@ class DeviceListView(View):
decorators = [login_required]
template_name = 'inventory/device_list.html'
def dispatch_request(self, id=None):
def dispatch_request(self, lot_id=None):
# TODO @cayop adding filter
# https://github.com/eReuse/devicehub-teal/blob/testing/ereuse_devicehub/resources/device/views.py#L56
filter_types = ['Desktop', 'Laptop', 'Server']
lots = Lot.query.filter(Lot.owner_id == current_user.id)
lot = None
if id:
lot = lots.filter(Lot.id == id).one()
if lot_id:
lot = lots.filter(Lot.id == lot_id).one()
devices = [dev for dev in lot.devices if dev.type in filter_types]
devices = sorted(devices, key=lambda x: x.updated, reverse=True)
else:
devices = Device.query.filter(
Device.owner_id == current_user.id).filter(
Device.type.in_(filter_types)).filter(Device.lots == None)
Device.type.in_(filter_types)).filter(Device.lots == None).order_by(
Device.updated.desc())
context = {'devices': devices,
'lots': lots,
@ -35,6 +39,20 @@ class DeviceListView(View):
return flask.render_template(self.template_name, **context)
class DeviceDetailsView(View):
decorators = [login_required]
template_name = 'inventory/device_details.html'
def dispatch_request(self, id):
lots = Lot.query.filter(Lot.owner_id == current_user.id)
device = Device.query.filter(
Device.owner_id == current_user.id).filter(Device.devicehub_id == id).one()
context = {'device': device,
'lots': lots}
return flask.render_template(self.template_name, **context)
class LotDeviceAddView(View):
methods = ['POST']
decorators = [login_required]
@ -45,8 +63,7 @@ class LotDeviceAddView(View):
if form.validate_on_submit():
form.save()
next_url = url_for('inventory.devices.lotdevicelist', id=form.lot.data)
return flask.redirect(next_url)
return flask.redirect(request.referrer)
class LotDeviceDeleteView(View):
@ -59,29 +76,42 @@ class LotDeviceDeleteView(View):
if form.validate_on_submit():
form.remove()
next_url = url_for('inventory.devices.lotdevicelist', id=form.lot.data)
return flask.redirect(next_url)
# TODO @cayop It's possible this redirect not work in production
return flask.redirect(request.referrer)
class LotView(View):
class LotCreateView(View):
methods = ['GET', 'POST']
decorators = [login_required]
template_name = 'inventory/lot.html'
title = "Add a new lot"
def dispatch_request(self, id=None):
if id:
self.title = "Edit lot"
def dispatch_request(self):
form = LotForm()
if form.validate_on_submit():
form.save()
next_url = url_for('inventory.devices.lotdevicelist', lot_id=form.id)
return flask.redirect(next_url)
lots = Lot.query.filter(Lot.owner_id == current_user.id)
return flask.render_template(self.template_name, form=form, title=self.title, lots=lots)
class LotUpdateView(View):
methods = ['GET', 'POST']
decorators = [login_required]
template_name = 'inventory/lot.html'
title = "Edit a new lot"
def dispatch_request(self, id):
form = LotForm(id=id)
if form.validate_on_submit():
form.save()
lot_id = id
if not id:
lot_id = form.instance.id
next_url = url_for('inventory.devices.lotdevicelist', id=lot_id)
next_url = url_for('inventory.devices.lotdevicelist', lot_id=id)
return flask.redirect(next_url)
return flask.render_template(self.template_name, form=form, title=self.title)
lots = Lot.query.filter(Lot.owner_id == current_user.id)
return flask.render_template(self.template_name, form=form, title=self.title, lots=lots)
class LotDeleteView(View):
@ -96,6 +126,36 @@ class LotDeleteView(View):
return flask.redirect(next_url)
class UploadSnapshotView(View):
methods = ['GET', 'POST']
decorators = [login_required]
template_name = 'inventory/upload_snapshot.html'
def dispatch_request(self):
lots = Lot.query.filter(Lot.owner_id == current_user.id).all()
form = UploadSnapshotForm()
if form.validate_on_submit():
form.save()
return flask.render_template(self.template_name, form=form, lots=lots)
class CreateDeviceView(View):
methods = ['GET', 'POST']
decorators = [login_required]
template_name = 'inventory/create_device.html'
def dispatch_request(self):
lots = Lot.query.filter(Lot.owner_id == current_user.id).all()
form = NewDeviceForm()
if form.validate_on_submit():
form.save()
next_url = url_for('inventory.devices.devicelist')
return flask.redirect(next_url)
return flask.render_template(self.template_name, form=form, lots=lots)
class TagListView(View):
methods = ['GET']
decorators = [login_required]
@ -125,11 +185,14 @@ class TagAddView(View):
devices.add_url_rule('/device/', view_func=DeviceListView.as_view('devicelist'))
devices.add_url_rule('/lot/<string:id>/device/', view_func=DeviceListView.as_view('lotdevicelist'))
devices.add_url_rule('/device/<string:id>/', view_func=DeviceDetailsView.as_view('device_details'))
devices.add_url_rule('/lot/<string:lot_id>/device/', view_func=DeviceListView.as_view('lotdevicelist'))
devices.add_url_rule('/lot/devices/add/', view_func=LotDeviceAddView.as_view('lot_devices_add'))
devices.add_url_rule('/lot/devices/del/', view_func=LotDeviceDeleteView.as_view('lot_devices_del'))
devices.add_url_rule('/lot/add/', view_func=LotView.as_view('lot_add'))
devices.add_url_rule('/lot/add/', view_func=LotCreateView.as_view('lot_add'))
devices.add_url_rule('/lot/<string:id>/del/', view_func=LotDeleteView.as_view('lot_del'))
devices.add_url_rule('/lot/<string:id>/', view_func=LotView.as_view('lot_edit'))
devices.add_url_rule('/lot/<string:id>/', view_func=LotUpdateView.as_view('lot_edit'))
devices.add_url_rule('/upload-snapshot/', view_func=UploadSnapshotView.as_view('upload_snapshot'))
devices.add_url_rule('/device/add/', view_func=CreateDeviceView.as_view('device_add'))
devices.add_url_rule('/tag/', view_func=TagListView.as_view('taglist'))
devices.add_url_rule('/tag/add/', view_func=TagAddView.as_view('tag_add'))

View File

@ -0,0 +1,23 @@
$(document).ready(function() {
$("#type").on("change", deviceInputs);
deviceInputs();
})
function deviceInputs() {
if ($("#type").val() == 'Monitor') {
$("#screen").show();
$("#resolution").show();
$("#imei").hide();
$("#meid").hide();
} else if (['Smartphone', 'Cellphone', 'Tablet'].includes($("#type").val())) {
$("#screen").hide();
$("#resolution").hide();
$("#imei").show();
$("#meid").show();
} else {
$("#screen").hide();
$("#resolution").hide();
$("#imei").hide();
$("#meid").hide();
}
}

View File

@ -105,7 +105,7 @@
{% for lot in lots %}
{% if lot.is_incominig %}
<li>
<a href="{{ url_for('inventory.devices.lotdevicelist', id=lot.id) }}">
<a href="{{ url_for('inventory.devices.lotdevicelist', lot_id=lot.id) }}">
<i class="bi bi-circle"></i><span>{{ lot.name }}</span>
</a>
</li>
@ -122,7 +122,7 @@
{% for lot in lots %}
{% if lot.is_outgoing %}
<li>
<a href="{{ url_for('inventory.devices.lotdevicelist', id=lot.id) }}">
<a href="{{ url_for('inventory.devices.lotdevicelist', lot_id=lot.id) }}">
<i class="bi bi-circle"></i><span>{{ lot.name }}</span>
</a>
</li>
@ -133,18 +133,18 @@
<li class="nav-item">
<a class="nav-link collapsed" data-bs-target="#temporal-lots-nav" data-bs-toggle="collapse" href="#">
<i class="bi bi-layout-text-window-reverse"></i><span>Temporal Lots</span><i class="bi bi-chevron-down ms-auto"></i>
<i class="bi bi-layout-text-window-reverse"></i><span>Temporary Lots</span><i class="bi bi-chevron-down ms-auto"></i>
</a>
<ul id="temporal-lots-nav" class="nav-content collapse " data-bs-parent="#sidebar-nav">
<li>
<a href="{{ url_for('inventory.devices.lot_add')}}">
<i class="bi bi-plus" style="font-size: larger;"></i><span>New temporal lot</span>
<i class="bi bi-plus" style="font-size: larger;"></i><span>New temporary lot</span>
</a>
</li>
{% for lot in lots %}
{% if lot.is_temporary %}
<li>
<a href="{{ url_for('inventory.devices.lotdevicelist', id=lot.id) }}">
<a href="{{ url_for('inventory.devices.lotdevicelist', lot_id=lot.id) }}">
<i class="bi bi-circle"></i><span>{{ lot.name }}</span>
</a>
</li>

View File

@ -0,0 +1,391 @@
{% extends "ereuse_devicehub/base_site.html" %}
{% block main %}
<div class="pagetitle">
<h1>{{ title }}</h1>
<nav>
<ol class="breadcrumb">
<li class="breadcrumb-item"><a href="index.html">Inventory</a></li>
<li class="breadcrumb-item">New Device</li>
</ol>
</nav>
</div><!-- End Page Title -->
<section class="section profile">
<div class="row">
<div class="col-xl-8">
<div class="card">
<div class="card-body">
<div class="pt-4 pb-2">
<h5 class="card-title text-center pb-0 fs-4">New Device</h5>
{% if form.form_errors %}
<p class="text-danger">
{% for error in form.form_errors %}
{{ error }}<br/>
{% endfor %}
</p>
{% endif %}
</div>
<form method="post" class="row g-3 needs-validation" novalidate>
{{ form.csrf_token }}
<div class="col-12">
<div class="form-group has-validation mb-2">
<label for="name" class="form-label">Type *</label>
<select id="type" class="form-control" name="type" required="">
<option value="">Select one Type</option>
<optgroup label="Computer Monitor">
<option value="Monitor"
{% if form.type.data == 'Monitor' %} selected="selected"{% endif %}>Monitor</option>
</optgroup>
<optgroup label="Mobile">
<option value="Smartphone"
{% if form.type.data == 'Smartphone' %} selected="selected"{% endif %}>Smartphone</option>
<option value="Tablet"
{% if form.type.data == 'Tablet' %} selected="selected"{% endif %}>Tablet</option>
<option value="Cellphone"
{% if form.type.data == 'Cellphone' %} selected="selected"{% endif %}>Cellphone</option>
</optgroup>
<optgroup label="Computer Accessory">
<option value="Mouse"
{% if form.type.data == 'Mouse' %} selected="selected"{% endif %}>Mouse</option>
<option value="MemoryCardReader"
{% if form.type.data == 'MemoryCardReader' %} selected="selected"{% endif %}>Memory card reader</option>
<option value="SAI"
{% if form.type.data == 'SAI' %} selected="selected"{% endif %}>SAI</option>
<option value="Keyboard"
{% if form.type.data == 'Keyboard' %} selected="selected"{% endif %}>Keyboard</option>
</optgroup>
</select>
<small class="text-muted form-text">Type of devices</small>
{% if form.type.errors %}
<p class="text-danger">
{% for error in form.type.errors %}
{{ error }}<br/>
{% endfor %}
</p>
{% endif %}
</div>
<div class="form-group mb-2">
<label for="label" class="form-label">Label</label>
{{ form.label(class_="form-control") }}
<small class="text-muted form-text">Label that you want link to this device</small>
{% if form.label.errors %}
<p class="text-danger">
{% for error in form.label.errors %}
{{ error }}<br/>
{% endfor %}
</p>
{% endif %}
</div>
<div class="from-group has-validation mb-2">
<label for="serialNumber" class="form-label">{{ form.serial_number.label }} *</label>
{{ form.serial_number(class_="form-control") }}
<small class="text-muted form-text">Serial number of this device</small>
{% if form.serial_number.errors %}
<p class="text-danger">
{% for error in form.serial_number.errors %}
{{ error }}<br/>
{% endfor %}
</p>
{% endif %}
</div>
<div class="from-group has-validation mb-2">
<label for="model" class="form-label">{{ form.model.label }} *</label>
{{ form.model(class_="form-control") }}
<small class="text-muted form-text">Name of model</small>
{% if form.model.errors %}
<p class="text-danger">
{% for error in form.model.errors %}
{{ error }}<br/>
{% endfor %}
</p>
{% endif %}
</div>
<div class="from-group has-validation mb-2">
<label for="model" class="form-label">{{ form.manufacturer.label }} *</label>
{{ form.manufacturer(class_="form-control") }}
<small class="text-muted form-text">Name of manufacturer</small>
{% if form.manufacturer.errors %}
<p class="text-danger">
{% for error in form.manufacturer.errors %}
{{ error }}<br/>
{% endfor %}
</p>
{% endif %}
</div>
<div class="from-group has-validation mb-2">
<label for="model" class="form-label">{{ form.appearance.label }}</label>
<div class="form-check">
<input class="form-check-input" type="radio" name="appearance" value="Z">
<label class="form-check-label">0. The device is new.</label>
</div>
<div class="form-check">
<input class="form-check-input" type="radio" name="appearance" value="A">
<label class="form-check-label">A. Like new (no visual damage))</label>
</div>
<div class="form-check">
<input class="form-check-input" type="radio" name="appearance" value="B">
<label class="form-check-label">B. In very good condition (small visual damage to hard-to-detect parts)</label>
</div>
<div class="form-check">
<input class="form-check-input" type="radio" name="appearance" value="C">
<label class="form-check-label">C. In good condition (small visual damage to easy-to-detect parts, not the screen))</label>
</div>
<div class="form-check">
<input class="form-check-input" type="radio" name="appearance" value="D">
<label class="form-check-label">D. It is acceptable (visual damage to visible parts, not on the screen)</label>
</div>
<div class="form-check">
<input class="form-check-input" type="radio" name="appearance" value="E">
<label class="form-check-label">E. It is unacceptable (substantial visual damage that may affect use)</label>
</div>
<small class="text-muted form-text">Rate the imperfections that affect the device aesthetically, but not its use.</small>
{% if form.appearance.errors %}
<p class="text-danger">
{% for error in form.appearance.errors %}
{{ error }}<br/>
{% endfor %}
</p>
{% endif %}
</div>
<div class="from-group has-validation mb-2">
<label for="model" class="form-label">{{ form.functionality.label }}</label>
<div class="form-check">
<input class="form-check-input" type="radio" name="functionality" value="A">
<label class="form-check-label">A. Everything works perfectly (buttons, and no scratches on the screen)</label>
</div>
<div class="form-check">
<input class="form-check-input" type="radio" name="functionality" value="B">
<label class="form-check-label">B. There is a hard to press button or small scratches on the corners of the screen</label>
</div>
<div class="form-check">
<input class="form-check-input" type="radio" name="functionality" value="C">
<label class="form-check-label">C. A non-essential button does not work; the screen has multiple scratches on the corners</label>
</div>
<div class="form-check">
<input class="form-check-input" type="radio" name="functionality" value="D">
<label class="form-check-label">D. Multiple buttons do not work properly; the screen has severe damage that may affect use</label>
</div>
<small class="text-muted form-text">It qualifies the defects of a device that affect its use.</small>
{% if form.functionality.errors %}
<p class="text-danger">
{% for error in form.functionality.errors %}
{{ error }}<br/>
{% endfor %}
</p>
{% endif %}
</div>
<div class="from-group has-validation mb-2">
<label for="model" class="form-label">{{ form.brand.label }}</label>
{{ form.brand(class_="form-control") }}
<small class="text-muted form-text">A naming for consumers. This field can represent several models, so it can be ambiguous, and it is not used to identify the product.</small>
{% if form.brand.errors %}
<p class="text-danger">
{% for error in form.brand.errors %}
{{ error }}<br/>
{% endfor %}
</p>
{% endif %}
</div>
<div class="from-group has-validation mb-2">
<label for="model" class="form-label">{{ form.generation.label }} *</label>
{{ form.generation(class_="form-control") }}
<small class="text-muted form-text">The generation of the device.</small>
{% if form.generation.errors %}
<p class="text-danger">
{% for error in form.generation.errors %}
{{ error }}<br/>
{% endfor %}
</p>
{% endif %}
</div>
<div class="from-group has-validation mb-2">
<label for="model" class="form-label">{{ form.version.label }}</label>
{{ form.version(class_="form-control") }}
<small class="text-muted form-text">The version code o fthis device, like 'v1' or 'A001'.</small>
{% if form.version.errors %}
<p class="text-danger">
{% for error in form.version.errors %}
{{ error }}<br/>
{% endfor %}
</p>
{% endif %}
</div>
<div class="from-group has-validation mb-2">
<label for="model" class="form-label">{{ form.weight.label }} *</label>
{{ form.weight(class_="form-control") }}
<small class="text-muted form-text">The weight of the device in Kg.</small>
{% if form.weight.errors %}
<p class="text-danger">
{% for error in form.weight.errors %}
{{ error }}<br/>
{% endfor %}
</p>
{% endif %}
</div>
<div class="from-group has-validation mb-2">
<label for="model" class="form-label">{{ form.width.label }} *</label>
{{ form.width(class_="form-control") }}
<small class="text-muted form-text">The width of the device in meters.</small>
{% if form.width.errors %}
<p class="text-danger">
{% for error in form.width.errors %}
{{ error }}<br/>
{% endfor %}
</p>
{% endif %}
</div>
<div class="from-group has-validation mb-2">
<label for="model" class="form-label">{{ form.height.label }} *</label>
{{ form.height(class_="form-control") }}
<small class="text-muted form-text">The height of the device in meters.</small>
{% if form.height.errors %}
<p class="text-danger">
{% for error in form.height.errors %}
{{ error }}<br/>
{% endfor %}
</p>
{% endif %}
</div>
<div class="from-group has-validation mb-2">
<label for="model" class="form-label">{{ form.depth.label }} *</label>
{{ form.depth(class_="form-control") }}
<small class="text-muted form-text">The depth of the device in meters.</small>
{% if form.depth.errors %}
<p class="text-danger">
{% for error in form.depth.errors %}
{{ error }}<br/>
{% endfor %}
</p>
{% endif %}
</div>
<div class="from-group has-validation mb-2">
<label for="model" class="form-label">{{ form.variant.label }}</label>
{{ form.variant(class_="form-control") }}
<small class="text-muted form-text">A variant or sub-model of the device.</small>
{% if form.variant.errors %}
<p class="text-danger">
{% for error in form.variant.errors %}
{{ error }}<br/>
{% endfor %}
</p>
{% endif %}
</div>
<div class="from-group has-validation mb-2">
<label for="model" class="form-label">{{ form.sku.label }}</label>
{{ form.sku(class_="form-control") }}
<small class="text-muted form-text">The Stock Keeping Unit (SKU), i.e. a merchant-specific identifier for a product or service.</small>
{% if form.sku.errors %}
<p class="text-danger">
{% for error in form.sku.errors %}
{{ error }}<br/>
{% endfor %}
</p>
{% endif %}
</div>
<div class="from-group has-validation mb-2">
<label for="image" class="form-label">{{ form.image.label }}</label>
{{ form.image(class_="form-control") }}
<small class="text-muted form-text">An URL containing an image of the device.</small>
{% if form.image.errors %}
<p class="text-danger">
{% for error in form.image.errors %}
{{ error }}<br/>
{% endfor %}
</p>
{% endif %}
</div>
<div id="imei" class="from-group has-validation mb-2">
<label for="imei" class="form-label">{{ form.imei.label }}</label>
{{ form.imei(class_="form-control") }}
<small class="text-muted form-text">A number from 14 to 16 digits.</small>
{% if form.imei.errors %}
<p class="text-danger">
{% for error in form.imei.errors %}
{{ error }}<br/>
{% endfor %}
</p>
{% endif %}
</div>
<div id="meid" class="from-group has-validation mb-2">
<label for="meid" class="form-label">{{ form.meid.label }}</label>
{{ form.meid(class_="form-control") }}
<small class="text-muted form-text">14 hexadecimal digits.</small>
{% if form.meid.errors %}
<p class="text-danger">
{% for error in form.meid.errors %}
{{ error }}<br/>
{% endfor %}
</p>
{% endif %}
</div>
<div id="resolution" class="from-group has-validation mb-2">
<label for="resolution" class="form-label">{{ form.resolution.label }}</label>
{{ form.resolution(class_="form-control") }}
<small class="text-muted form-text">The resolution width of the screen.</small>
{% if form.resolution.errors %}
<p class="text-danger">
{% for error in form.resolution.errors %}
{{ error }}<br/>
{% endfor %}
</p>
{% endif %}
</div>
<div id="screen" class="from-group has-validation mb-2">
<label for="screen" class="form-label">{{ form.screen.label }}</label>
{{ form.screen(class_="form-control") }}
<small class="text-muted form-text">The size of the screen.</small>
{% if form.screen.errors %}
<p class="text-danger">
{% for error in form.screen.errors %}
{{ error }}<br/>
{% endfor %}
</p>
{% endif %}
</div>
</div>
<div class="col-12">
<a href="{{ url_for('inventory.devices.devicelist') }}" class="btn btn-danger">Cancel</a>
<button class="btn btn-primary" type="submit">Save</button>
</div>
</form>
</div>
</div>
</div>
<div class="col-xl-8">
</div>
</div>
</section>
<script src="{{ url_for('static', filename='js/jquery-3.6.0.min.js') }}"></script>
<script src="{{ url_for('static', filename='js/create_device.js') }}"></script>
{% endblock main %}

View File

@ -0,0 +1,150 @@
{% extends "ereuse_devicehub/base_site.html" %}
{% block main %}
<link href="https://cdn.jsdelivr.net/npm/simple-datatables@latest/dist/style.css" rel="stylesheet" type="text/css">
<div class="pagetitle">
<h1>Inventory</h1>
<nav>
<ol class="breadcrumb">
<li class="breadcrumb-item"><a href="{{ url_for('inventory.devices.devicelist')}}">Inventory</a></li>
<li class="breadcrumb-item active">Details device</li>
<li class="breadcrumb-item active">{{ device.devicehub_id }}</li>
</ol>
</nav>
</div><!-- End Page Title -->
<section class="section profile">
<div class="row">
<div class="col-xl-12">
<div class="card">
<div class="card-body pt-3">
<h3>{{ device.devicehub_id }}</h3>
<!-- Bordered Tabs -->
<ul class="nav nav-tabs nav-tabs-bordered">
<li class="nav-item">
<button class="nav-link active" data-bs-toggle="tab" data-bs-target="#type">Type</button>
</li>
<li class="nav-item">
<button class="nav-link" data-bs-toggle="tab" data-bs-target="#status">Status</button>
</li>
<li class="nav-item">
<button class="nav-link" data-bs-toggle="tab" data-bs-target="#rate">Rate</button>
</li>
<li class="nav-item">
<button class="nav-link" data-bs-toggle="tab" data-bs-target="#traceability">Traceability log</button>
</li>
<li class="nav-item">
<button class="nav-link" data-bs-toggle="tab" data-bs-target="#components">Components</button>
</li>
</ul>
<div class="tab-content pt-2">
<div class="tab-pane fade show active" id="type">
<h5 class="card-title">Type Details</h5>
<div class="row">
<div class="col-lg-3 col-md-4 label ">Type</div>
<div class="col-lg-9 col-md-8">{{ device.type }}</div>
</div>
<div class="row">
<div class="col-lg-3 col-md-4 label">Manufacturer</div>
<div class="col-lg-9 col-md-8">{{ device.manufacturer }}</div>
</div>
<div class="row">
<div class="col-lg-3 col-md-4 label">Model</div>
<div class="col-lg-9 col-md-8">{{ device.model }}</div>
</div>
<div class="row">
<div class="col-lg-3 col-md-4 label">Serial Number</div>
<div class="col-lg-9 col-md-8">{{ device.serial_number }}</div>
</div>
</div>
<div class="tab-pane fade profile-overview" id="status">
<h5 class="card-title">Status Details</h5>
<div class="row">
<div class="col-lg-3 col-md-4 label">Physical States</div>
<div class="col-lg-9 col-md-8">{{ device.physical or '' }}</div>
</div>
<div class="row">
<div class="col-lg-3 col-md-4 label">Trading States</div>
<div class="col-lg-9 col-md-8">{{ device.last_action_trading or ''}}</div>
</div>
<div class="row">
<div class="col-lg-3 col-md-4 label">Usage States</div>
<div class="col-lg-9 col-md-8">{{ device.usage or '' }}</div>
</div>
</div>
<div class="tab-pane fade profile-overview" id="rate">
<h5 class="card-title">Rate Details</h5>
<div class="row">
<div class="col-lg-3 col-md-4 label">Rating</div>
<div class="col-lg-9 col-md-8">{{ device.rate or '' }}</div>
</div>
<div class="row">
<div class="col-lg-3 col-md-4 label">Processor</div>
<div class="col-lg-9 col-md-8">{{ device.rate.processor or '' }}</div>
</div>
<div class="row">
<div class="col-lg-3 col-md-4 label">RAM</div>
<div class="col-lg-9 col-md-8">{{ device.rate.ram or '' }}</div>
</div>
<div class="row">
<div class="col-lg-3 col-md-4 label">Data storage</div>
<div class="col-lg-9 col-md-8">{{ device.rate.data_storage or '' }}</div>
</div>
</div>
<div class="tab-pane fade profile-overview" id="traceability">
<h5 class="card-title">Traceability log Details</h5>
<div class="list-group col-6">
{% for action in device.actions %}
<div class="list-group-item d-flex justify-content-between align-items-center">
{{ action.type }} {{ action.severity }}
<small class="text-muted">{{ action.created.strftime('%H:%M %d-%m-%Y') }}</small>
</div>
{% endfor %}
</div>
</div>
<div class="tab-pane fade profile-overview" id="components">
<h5 class="card-title">Components Details</h5>
<div class="list-group col-6">
{% for component in device.components|sort(attribute='type') %}
<div class="list-group-item">
<div class="d-flex w-100 justify-content-between">
<h5 class="mb-1">{{ component.type }}</h5>
<small class="text-muted">{{ component.created.strftime('%H:%M %d-%m-%Y') }}</small>
</div>
<p class="mb-1">
{{ component.manufacturer }}<br />
{{ component.model }}<br />
</p>
<small class="text-muted">
{% if component.type in ['RamModule', 'HardDrive', 'SolidStateDrive'] %}
{{ component.size }}MB
{% endif %}
</small>
</div>
{% endfor %}
</div>
</div>
</div>
</div>
</div>
</div>
</section>
{% endblock main %}

View File

@ -6,11 +6,11 @@
<h1>Inventory</h1>
<nav>
<ol class="breadcrumb">
<li class="breadcrumb-item"><a href="index.html">Inventory</a></li>
<li class="breadcrumb-item"><a href="{{ url_for('inventory.devices.devicelist')}}">Inventory</a></li>
{% if not lot %}
<li class="breadcrumb-item active">Unassgined</li>
{% elif lot.is_temporary %}
<li class="breadcrumb-item active">Temporal Lot</li>
<li class="breadcrumb-item active">Temporary Lot</li>
<li class="breadcrumb-item active">{{ lot.name }}</li>
{% elif lot.is_incominig %}
<li class="breadcrumb-item active">Incoming Lot</li>
@ -45,11 +45,11 @@
<div class="btn-group dropdown ml-1">
{% if lot and lot.is_temporary and not lot.devices %}
<a href="{{ url_for('inventory.devices.lot_del', id=lot.id)}}" type="button" class="btn btn-primary">
<button type="button" class="btn btn-primary dropdown-toggle" data-bs-toggle="modal" data-bs-target="#btnRemoveLots">
<i class="bi bi-trash"></i>
Remove Lot
<span class="caret"></span>
</a>
</button>
{% else %}
<button id="btnLots" type="button" class="btn btn-primary dropdown-toggle" data-bs-toggle="dropdown" aria-expanded="false">
<i class="bi bi-folder2"></i>
@ -162,7 +162,7 @@
<i class="bi bi-reply"></i>
Exports
</button>
<ul class="dropdown-menu" aria-labelledby="btnLots"">
<ul class="dropdown-menu" aria-labelledby="btnExport">
<li>
<a href="javascript:openAdd()" class="dropdown-item">
<i class="bi bi-plus"></i>
@ -183,7 +183,7 @@
<i class="bi bi-tag"></i>
Tags
</button>
<ul class="dropdown-menu" aria-labelledby="btnLots"">
<ul class="dropdown-menu" aria-labelledby="btnTags">
<li>
<a href="javascript:openAdd()" class="dropdown-item">
<i class="bi bi-plus"></i>
@ -199,6 +199,27 @@
</ul>
</div>
<div class="btn-group dropdown ml-1" uib-dropdown="">
<button id="btnSnapshot" type="button" class="btn btn-primary dropdown-toggle" data-bs-toggle="dropdown" aria-expanded="false">
<i class="bi bi-tag"></i>
New Device
</button>
<ul class="dropdown-menu" aria-labelledby="btnSnapshot">
<li>
<a href="{{ url_for('inventory.devices.upload_snapshot') }}" class="dropdown-item">
<i class="bi bi-plus"></i>
Upload a new Snapshot
</a>
</li>
<li>
<a href="{{ url_for('inventory.devices.device_add') }}" class="dropdown-item">
<i class="bi bi-plus"></i>
Create a new Device
</a>
</li>
</ul>
</div>
<div class="tab-content pt-2">
<div class="tab-pane fade show active profile-overview" id="profile-overview">
@ -219,11 +240,11 @@
{% for dev in devices %}
<tr>
<td><input type="checkbox" class="deviceSelect" data="{{ dev.id }}"/></td>
<td>{{ dev.type }} {{ dev.manufacturer }} {{ dev.model }}</td>
<td>{{ dev.devicehub_id }}</td>
<td><a href={{ url_for('inventory.devices.device_details', id=dev.devicehub_id)}}>{{ dev.type }} {{ dev.manufacturer }} {{ dev.model }}</a></td>
<td><a href={{ url_for('inventory.devices.device_details', id=dev.devicehub_id)}}>{{ dev.devicehub_id }}</a></td>
<td>
{% for t in dev.tags %}
{{ t.code }}{% if not loop.last %},{% endif %}
{% for t in dev.tags | sort(attribute="id") %}
{{ t.id }}{% if not loop.last %},{% endif %}
{% endfor %}
</td>
<td>{% if dev.status %}{{ dev.status }}{% endif %}</td>
@ -241,8 +262,9 @@
</div>
</div>
</section>
{% include "inventory/addinglot.html" %}
{% include "inventory/removinglot.html" %}
{% include "inventory/addDeviceslot.html" %}
{% include "inventory/removeDeviceslot.html" %}
{% include "inventory/removelot.html" %}
{% include "inventory/actions.html" %}
<!-- CDN -->

View File

@ -0,0 +1,23 @@
<div class="modal fade" id="btnRemoveLots" tabindex="-1" style="display: none;" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Remove Lot</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
Are you sure that you want to remove lot <strong>{{ lot.name }}</strong>?
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
<a href="{{ url_for('inventory.devices.lot_del', id=lot.id)}}" type="button" class="btn btn-primary">
Save changes
</a>
</div>
</div>
</div>
</div>

View File

@ -0,0 +1,73 @@
{% extends "ereuse_devicehub/base_site.html" %}
{% block main %}
<div class="pagetitle">
<h1>{{ title }}</h1>
<nav>
<ol class="breadcrumb">
<li class="breadcrumb-item"><a href="index.html">Inventory</a></li>
<li class="breadcrumb-item">Upload Snapshot</li>
</ol>
</nav>
</div><!-- End Page Title -->
<section class="section profile">
<div class="row">
<div class="col-xl-8">
<div class="card">
<div class="card-body">
<div class="pt-4 pb-2">
<h5 class="card-title text-center pb-0 fs-4">Upload Snapshot</h5>
<p class="text-center small">Please select a file snapshot.</p>
{% if form.form_errors %}
<p class="text-danger">
{% for error in form.form_errors %}
{{ error }}<br/>
{% endfor %}
</p>
{% endif %}
</div>
<form method="post" enctype="multipart/form-data" class="row g-3 needs-validation" novalidate>
{{ form.csrf_token }}
<div class="col-12">
<label for="name" class="form-label">Select a Snapshot file</label>
<div class="input-group has-validation">
{{ form.snapshot }}
<div class="invalid-feedback">You can select multiple files Snapshots JSON.</div>
</div>
{% if form.result %}
{% for filename, result in form.result.items() %}
{% if result == 'Ok' %}
<p class="text-success">
{{ filename }}: {{ result }}<br/>
</p>
{% else %}
<p class="text-danger">
{{ filename }}: {{ result }}<br/>
</p>
{% endif %}
{% endfor %}
{% endif %}
</div>
<div class="col-12">
<a href="{{ url_for('inventory.devices.devicelist') }}" class="btn btn-danger">Cancel</a>
<button class="btn btn-primary" type="submit">Send</button>
</div>
</form>
</div>
</div>
</div>
<div class="col-xl-8">
</div>
</div>
</section>
{% endblock main %}