From 2543f7f7610db715b3a073cfdf07baacc2a4a2fd Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Fri, 9 Jun 2023 18:17:06 +0200 Subject: [PATCH] add datastorage placeholders --- ereuse_devicehub/inventory/forms.py | 27 +++++++++++++++++-- ereuse_devicehub/static/js/create_device.js | 26 ++++++++++++++---- .../templates/inventory/device_create.html | 21 ++++++++++++++- 3 files changed, 66 insertions(+), 8 deletions(-) diff --git a/ereuse_devicehub/inventory/forms.py b/ereuse_devicehub/inventory/forms.py index 6c2b428c..0d644565 100644 --- a/ereuse_devicehub/inventory/forms.py +++ b/ereuse_devicehub/inventory/forms.py @@ -55,9 +55,11 @@ from ereuse_devicehub.resources.device.models import ( DataStorage, Desktop, Device, + HardDrive, Keyboard, Laptop, MemoryCardReader, + Mobile, Monitor, Mouse, Other, @@ -65,6 +67,7 @@ from ereuse_devicehub.resources.device.models import ( Projector, Server, Smartphone, + SolidStateDrive, Tablet, TelevisionSet, ) @@ -100,7 +103,7 @@ DEVICES = { "Drives & Storage": [ "All DataStorage", "HardDrive", - "SolidStageDrive", + "SolidStateDrive", ], "Accessories": [ "All Accessories", @@ -128,6 +131,7 @@ MOBILE = ["Mobile", "Tablet", "Smartphone", "Cellphone"] STORAGE = ["HardDrive", "SolidStateDrive"] ACCESSORIES = ["Mouse", "MemoryCardReader", "SAI", "Keyboard"] OTHERS = ["Other"] +DATASTORAGE = ['HardDrive', 'SolidStateDrive'] class AdvancedSearchForm(FlaskForm): @@ -202,7 +206,7 @@ class FilterForm(FlaskForm): # Generic Filters if "All Devices" == self.device_type: - filter_type = COMPUTERS + MONITORS + MOBILE + OTHERS + filter_type = COMPUTERS + MONITORS + MOBILE + DATASTORAGE + OTHERS elif "All Computers" == self.device_type: filter_type = COMPUTERS @@ -398,6 +402,7 @@ class NewDeviceForm(FlaskForm): sku = StringField('SKU', [validators.Optional()]) image = URLField('Image', [validators.Optional(), validators.URL()]) imei = IntegerField('IMEI', [validators.Optional()]) + data_storage_size = IntegerField('Storage Size', [validators.Optional()]) meid = StringField('MEID', [validators.Optional()]) resolution = IntegerField('Resolution width', [validators.Optional()]) screen = FloatField('Screen size', [validators.Optional()]) @@ -417,6 +422,8 @@ class NewDeviceForm(FlaskForm): "Smartphone": Smartphone, "Tablet": Tablet, "Cellphone": Cellphone, + "HardDrive": HardDrive, + "SolidStateDrive": SolidStateDrive, "ComputerMonitor": ComputerMonitor, "Monitor": Monitor, "TelevisionSet": TelevisionSet, @@ -465,6 +472,7 @@ class NewDeviceForm(FlaskForm): if self._obj.type in ['Smartphone', 'Tablet', 'Cellphone']: self.imei.data = self._obj.imei self.meid.data = self._obj.meid + self.data_storage_size.data = self._obj.data_storage_size if self._obj.type == 'ComputerMonitor': self.resolution.data = self._obj.resolution_width self.screen.data = self._obj.size @@ -492,6 +500,7 @@ class NewDeviceForm(FlaskForm): if self._obj.type in ['Smartphone', 'Tablet', 'Cellphone']: self.imei.render_kw = disabled self.meid.render_kw = disabled + self.data_storage_size.render_kw = disabled if self._obj.type == 'ComputerMonitor': self.resolution.render_kw = disabled self.screen.render_kw = disabled @@ -561,6 +570,7 @@ class NewDeviceForm(FlaskForm): if commit: db.session.commit() + # import pdb; pdb.set_trace() def create_device(self): schema = SnapshotSchema() @@ -604,6 +614,10 @@ class NewDeviceForm(FlaskForm): if self.type.data in ['Smartphone', 'Tablet', 'Cellphone']: device.imei = self.imei.data device.meid = self.meid.data + device.data_storage_size = self.data_storage_size.data + + if self.type.data in ['HardDrive', 'SolidStateDrive']: + device.data_storage_size = self.data_storage_size.data device.image = URL(self.image.data) @@ -672,6 +686,7 @@ class NewDeviceForm(FlaskForm): if self._obj.type in ['Smartphone', 'Tablet', 'Cellphone']: self._obj.imei = self.imei.data self._obj.meid = self.meid.data + self._obj.data_storage_size = self.data_storage_size.data if ( self.appearance.data @@ -1084,6 +1099,14 @@ class DataWipeForm(ActionFormMixin): del self.document for dev in self._devices: ac = None + if isinstance(dev, Mobile) or isinstance(dev, DataStorage): + ac = Model() + self.populate_obj(ac) + ac.device_id = dev.id + ac.document = document.form._obj + db.session.add(ac) + continue + for hd in dev.components: if not isinstance(hd, DataStorage): continue diff --git a/ereuse_devicehub/static/js/create_device.js b/ereuse_devicehub/static/js/create_device.js index 4acece0f..34965cf6 100644 --- a/ereuse_devicehub/static/js/create_device.js +++ b/ereuse_devicehub/static/js/create_device.js @@ -1,28 +1,44 @@ $(document).ready(() => { - $("#type").on("change", deviceInputs); - $("#amount").on("change", amountInputs); + $("#type").on("change", deviceInputs2); + $("#amount").on("change", deviceInputs2); + deviceInputs2() +}) + +function deviceInputs2() { deviceInputs(); amountInputs(); -}) +} function deviceInputs() { if ($("#type").val() == "ComputerMonitor") { $("#screen").show(); $("#resolution").show(); + $("#components2").hide(); $("#imei").hide(); $("#meid").hide(); + $("#data_storage_size").hide(); } else if (["Smartphone", "Cellphone", "Tablet"].includes($("#type").val())) { $("#screen").hide(); $("#resolution").hide(); + $("#components2").hide(); $("#imei").show(); $("#meid").show(); + $("#data_storage_size").show(); + } else if (["HardDrive", "SolidStateDrive"].includes($("#type").val())) { + $("#screen").hide(); + $("#resolution").hide(); + $("#components2").hide(); + $("#imei").hide(); + $("#meid").hide(); + $("#data_storage_size").show(); } else { $("#screen").hide(); $("#resolution").hide(); $("#imei").hide(); $("#meid").hide(); + $("#data_storage_size").hide(); + $("#components2").show(); }; - amountInputs(); } function amountInputs() { @@ -35,6 +51,7 @@ function amountInputs() { $("#Sku").hide(); $("#imei").hide(); $("#meid").hide(); + $("#data_storage_size").hide(); } else { $("#Phid").show(); $("#Id_device_supplier").show(); @@ -42,6 +59,5 @@ function amountInputs() { $("#Serial_number").show(); $("#Part_number").show(); $("#Sku").show(); - deviceInputs(); }; } diff --git a/ereuse_devicehub/templates/inventory/device_create.html b/ereuse_devicehub/templates/inventory/device_create.html index 8ad8634a..3de677c9 100644 --- a/ereuse_devicehub/templates/inventory/device_create.html +++ b/ereuse_devicehub/templates/inventory/device_create.html @@ -62,6 +62,12 @@ + + + + @@ -152,7 +158,7 @@ {% endif %} -
+
{{ form.components(class_="form-control") }} Description of components @@ -434,6 +440,19 @@ {% endif %}
+
+ + {{ form.data_storage_size(class_="form-control") }} + Size in GB. + {% if form.data_storage_size.errors %} +

+ {% for error in form.data_storage_size.errors %} + {{ error }}
+ {% endfor %} +

+ {% endif %} +
+
{{ form.resolution(class_="form-control") }}