From 6845e087f2002f497a42749ded8e45383f9648e4 Mon Sep 17 00:00:00 2001 From: Thomas Kuschel Date: Sun, 15 Oct 2023 11:40:55 +0200 Subject: [PATCH] UPD edit form --- admin/forms/part.xml | 55 +++++++++++++++++++++---- admin/language/en-GB/com_depot.ini | 8 +++- admin/sql/install.mysql.utf8.sql | 38 +++++++++++++++++ admin/sql/updates/mysql/0.9.0.sql | 42 +++++++++++++++++++ admin/src/Table/PartTable.php | 47 +++++++++++++++++++++ admin/tmpl/part/edit.php | 66 +++++++++++++++++------------- depot.xml | 4 +- 7 files changed, 220 insertions(+), 40 deletions(-) create mode 100644 admin/sql/updates/mysql/0.9.0.sql diff --git a/admin/forms/part.xml b/admin/forms/part.xml index eca411e..66a44e3 100644 --- a/admin/forms/part.xml +++ b/admin/forms/part.xml @@ -28,14 +28,6 @@ description="COM_DEPOT_FIELD_QUANTITY_EXP_DESC" default="0" /> - JTRASHED +
+ + + + + +
diff --git a/admin/language/en-GB/com_depot.ini b/admin/language/en-GB/com_depot.ini index 98b5f8e..3d2c331 100644 --- a/admin/language/en-GB/com_depot.ini +++ b/admin/language/en-GB/com_depot.ini @@ -8,13 +8,19 @@ COM_DEPOT_FIELD_ALIAS_PLACEHOLDER="Auto-generate from component name" COM_DEPOT_FIELD_COMPONENT_NAME_DESC="The name of the component is unique. Please do not enter special characters or umlauts." COM_DEPOT_FIELD_COMPONENT_NAME_LABEL="Component Name" +COM_DEPOT_FIELD_CREATED_LABEL="Created" +COM_DEPOT_FIELD_CREATED_BY_LABEL="Created by" +COM_DEPOT_FIELD_MODIFIED_LABEL="Modified" +COM_DEPOT_FIELD_MODIFIED_BY_LABEL="Modified by" COM_DEPOT_FIELD_QUANTITY_LABEL="Quantity" COM_DEPOT_FIELD_QUANTITY_DESC="Enter here the current number of components" COM_DEPOT_FIELD_QUANTITY_EXP_LABEL="Quantity Exponent" -COM_DEPOT_FIELD_QUANTITY_EXP_DESC="Exponent (10^x of the number, usually 0 i.e. 10⁰)" +COM_DEPOT_FIELD_QUANTITY_EXP_DESC="Exponent (10^x of the number, usually 0, i.e. 10⁰)" COM_DEPOT_FIELD_SELECT_MANUFACTURER="Manufacturer" COM_DEPOT_LEGEND_DETAILS="Component Details" +COM_DEPOT_LEGEND_STATISTICS="Component Statistics" COM_DEPOT_SELECT_YOUR_OPTION="Select your option" COM_DEPOT_TAB_NEW_PART="New Component" COM_DEPOT_TAB_EDIT_PART="Component Details" +COM_DEPOT_TAB_STATISTICS="Component Statistics" COM_DEPOT_XML_DESCRIPTION="Depot, the component warehouse" diff --git a/admin/sql/install.mysql.utf8.sql b/admin/sql/install.mysql.utf8.sql index 235da7c..ac57fe6 100644 --- a/admin/sql/install.mysql.utf8.sql +++ b/admin/sql/install.mysql.utf8.sql @@ -79,3 +79,41 @@ INSERT INTO `#__depot_manufacturer` (`name_short`, `name_long`, `url`, 'Diodes, ECAD Models, ICs, MOSFETs, Protection Devices, AEC-Q qualified',''), ('ST','STMicroelectronics','https://www.st.com', 'Microprocessors, Audio ICs, OPamps, Diodes, Memories, MEMS, NFCs, Transistors, Wireless, Automotive electronics, etc.',''); + +DROP TABLE IF EXISTS `#__jron_stock`; +CREATE TABLE `#__jron_stock` ( + `id` SERIAL, + `name` VARCHAR(1024) NOT NULL DEFAULT '', + -- `alias` VARCHAR(1024) NOT NULL DEFAULT '', + `owner` INT(10) UNSIGNED NOT NULL DEFAULT 0, + `created` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00', + `created_by` INT(10) UNSIGNED NOT NULL DEFAULT 0, + `checked_out` INT(11) NOT NULL DEFAULT 0, + `checked_out_time` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00', + `modified` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00', + `modified_by` INT(10) UNSIGNED NOT NULL DEFAULT 0, + `description` VARCHAR(4000) NOT NULL DEFAULT '', + `params` VARCHAR(1024) NOT NULL DEFAULT '', + `location` VARCHAR(1024) NOT NULL DEFAULT '', + `latitude` DECIMAL(9,7) NOT NULL DEFAULT 48.31738798930856, + `longitude` DECIMAL(10,7) NOT NULL DEFAULT 16.313504251028924, + `state` TINYINT(4) NOT NULL DEFAULT 0, + `access` TINYINT(4) NOT NULL DEFAULT 0, + PRIMARY KEY (`id`), + UNIQUE KEY `nameindex` (`name`,`owner`) + ) + ENGINE=InnoDB + AUTO_INCREMENT=0 + DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; + +INSERT INTO `#__jron_stock`(`name`, `location`, `description`, `state`, `access`) VALUES +('Semiconductors workshop cabinet depot', 'Tom''s office, Martinstr. 58a, 3400 Klosterneuburg', + 'MARS Svratka Workshop Depot 5x12 (60) compartments à 54 x 35 x 140 mm',1,0), +('Resistors workshop cabinet depot', 'Tom''s office, Martinstr. 58a, 3400 Klosterneuburg', + 'MARS Svratka Workshop Depot 2x5x12 + 1x5x7+3 (158) compartments à 54 x 35 x 140 mm',1,0), +('Capacitors/Inductors workshop cabinet depot', 'Tom''s office, Martinstr. 58a, 3400 Klosterneuburg', + 'MARS Svratka Workshop Depot 5x12 (60) compartments à 54 x 35 x 140 mm',1,0), +('Plugs/Sockets/other workshop cabinet depot', 'Tom''s office, Martinstr. 58a, 3400 Klosterneuburg', + 'MARS Svratka Workshop Depot 5x12 (60) compartments à 54 x 35 x 140 mm',1,0), +('SMD cabinet', 'Tom''s office, Martinstr. 58a, 3400 Klosterneuburg', + 'SMD cabinet, conductive, 6-times cabinet with inlays, 6 x 7*6 (252) round boxes, each ø 27 x 13 mm',1,0); diff --git a/admin/sql/updates/mysql/0.9.0.sql b/admin/sql/updates/mysql/0.9.0.sql new file mode 100644 index 0000000..d29ebbd --- /dev/null +++ b/admin/sql/updates/mysql/0.9.0.sql @@ -0,0 +1,42 @@ +-- @package Depot.SQL MariaDB -- UPDATE to 0.9.0 +-- @subpackage com_depot +-- @author Thomas Kuschel +-- @copyright (C) 2023 KW4NZ, +-- @license GNU General Public License version 2 or later; see LICENSE.md +-- @since 0.9.0 + +CREATE TABLE IF NOT EXISTS `#__depot_stock` ( + `id` SERIAL, + `name` VARCHAR(1024) NOT NULL DEFAULT '', + -- `alias` VARCHAR(1024) NOT NULL DEFAULT '', + `owner` INT(10) UNSIGNED NOT NULL DEFAULT 0, + `created` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00', + `created_by` INT(10) UNSIGNED NOT NULL DEFAULT 0, + `checked_out` INT(11) NOT NULL DEFAULT 0, + `checked_out_time` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00', + `modified` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00', + `modified_by` INT(10) UNSIGNED NOT NULL DEFAULT 0, + `description` VARCHAR(4000) NOT NULL DEFAULT '', + `params` VARCHAR(1024) NOT NULL DEFAULT '', + `location` VARCHAR(1024) NOT NULL DEFAULT '', + `latitude` DECIMAL(9,7) NOT NULL DEFAULT 48.31738798930856, + `longitude` DECIMAL(10,7) NOT NULL DEFAULT 16.313504251028924, + `state` TINYINT(4) NOT NULL DEFAULT 0, + `access` TINYINT(4) NOT NULL DEFAULT 0, + PRIMARY KEY (`id`), + UNIQUE KEY `nameindex` (`name`,`owner`) +) ENGINE=InnoDB + AUTO_INCREMENT=0 + DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; + +INSERT INTO `#__depot_stock` (`name`, `location`, `description`, `state`, `access`) VALUES +('Semiconductors workshop cabinet depot', 'Tom''s office, Martinstr. 58a, 3400 Klosterneuburg', + 'MARS Svratka Workshop Depot 5x12 (60) compartments à 54 x 35 x 140 mm',1,0), +('Resistors workshop cabinet depot', 'Tom''s office, Martinstr. 58a, 3400 Klosterneuburg', + 'MARS Svratka Workshop Depot 2x5x12 + 1x5x7+3 (158) compartments à 54 x 35 x 140 mm',1,0), +('Capacitors/Inductors workshop cabinet depot', 'Tom''s office, Martinstr. 58a, 3400 Klosterneuburg', + 'MARS Svratka Workshop Depot 5x12 (60) compartments à 54 x 35 x 140 mm',1,0), +('Plugs/Sockets/other workshop cabinet depot', 'Tom''s office, Martinstr. 58a, 3400 Klosterneuburg', + 'MARS Svratka Workshop Depot 5x12 (60) compartments à 54 x 35 x 140 mm',1,0), +('SMD cabinet', 'Tom''s office, Martinstr. 58a, 3400 Klosterneuburg', + 'SMD cabinet, conductive, 6-times cabinet with inlays, 6 x 7*6 (252) round boxes, each ø 27 x 13 mm',1,0); diff --git a/admin/src/Table/PartTable.php b/admin/src/Table/PartTable.php index 9611b21..3e54e26 100644 --- a/admin/src/Table/PartTable.php +++ b/admin/src/Table/PartTable.php @@ -10,6 +10,7 @@ namespace KW4NZ\Component\Depot\Administrator\Table; +use Joomla\CMS\Factory; use Joomla\CMS\Table\Table; use Joomla\Database\DatabaseDriver; @@ -21,4 +22,50 @@ class PartTable extends Table { parent::__construct('#__depot', 'id', $db); } + + public function store($updateNulls = true) + { + $app = Factory::getApplication(); + $date = Factory::getDate()->toSql(); + // $user = Factory::getUser(); + // $user = $this->getCurrentUser(); + $user = $app->getIdentity(); + + if (!$this->created) { + $this->created = $date; + } + + if (!$this->created_by) { + $this->created_by = $user->get('id'); + } + + if ($this->id) { + // existing item + $this->modified_by = $user->get('id'); + $this->modified = $date; + } else { + // set modified to created date if not set + if (!$this->modified) { + $this->modified = $this->created; + } + if (empty($this->modified_by)) { + $this->modified_by = $this->created_by; + } + } + + // Verify that the alias is unique + $table = $app->bootComponent('com_depot')->getMVCFactory()->createTable('Part', 'Administrator'); + if ($table->load(['alias' => $this->alias]) && ($table->id != $this->id || $this->id == 0)) { + $this->setError('Alias is not unique.'); + + if ($table->state == -2) { + $this->setError('Alias is not unique. The item is in Trash.'); + } + + return false; + } + + return parent::store($updateNulls); + } + } \ No newline at end of file diff --git a/admin/tmpl/part/edit.php b/admin/tmpl/part/edit.php index 96b6072..80c3a53 100644 --- a/admin/tmpl/part/edit.php +++ b/admin/tmpl/part/edit.php @@ -19,36 +19,44 @@ $wa->useScript('form.validate') ?>
- -
- 'details'] - ); ?> - item->id) ? Text::_('COM_DEPOT_TAB_NEW_PART') : - Text::_('COM_DEPOT_TAB_EDIT_PART') - ); ?> -
- - - -
-
- form->renderFieldset('details'); ?> -
-
- form->getInput('description'); ?> -
+ 'details']); ?> + item->id) ? Text::_('COM_DEPOT_TAB_NEW_PART') : + Text::_('COM_DEPOT_TAB_EDIT_PART') + ); ?> +
+ + + +
+
+ form->renderFieldset('details'); ?>
-
- - -
+
+ form->getInput('description'); ?> +
+
+ + + + +
+ + + +
+
+ form->renderFieldset('statistics'); ?> +
+
+
+ + + +
\ No newline at end of file diff --git a/depot.xml b/depot.xml index a7d8419..9f38c12 100644 --- a/depot.xml +++ b/depot.xml @@ -2,12 +2,12 @@ Depot KW4NZ - 2023-10-06 + 2023-10-15 (C) KW4NZ Thomas Kuschel GPL v2 +; see LICENSE.md thomas@kuschel.at https://kuschel.at - 0.0.5 + 0.9.0 COM_DEPOT_XML_DESCRIPTION KW4NZ\Component\Depot