partkeepr

fork of partkeepr
git clone https://git.e1e0.net/partkeepr.git
Log | Files | Refs | Submodules | README | LICENSE

commit 8a23ce11802914da37eda3779a33218e4e3b16ae
parent c710ebee94a52133aca093bcd1688fbdef3b9ffd
Author: Felicia Hummel <felicia@partkeepr.com>
Date:   Tue, 17 Oct 2017 15:15:10 +0200

Merge branch 'master' of github.com:partkeepr/PartKeepr

Diffstat:
Msrc/PartKeepr/FrontendBundle/Resources/public/js/Components/Project/MetaPartRowExpander.js | 2++
Msrc/PartKeepr/FrontendBundle/Resources/public/js/Components/Widgets/ColumnConfigurator/Panel.js | 9++++++++-
Msrc/PartKeepr/FrontendBundle/Resources/public/js/Components/Widgets/FieldSelector.js | 44+++++++++++++++++++++-----------------------
Msrc/PartKeepr/SetupBundle/Command/ImportUnitsCommand.php | 6+++++-
Msrc/PartKeepr/SetupBundle/Services/UnitSetupService.php | 9+++++++--
5 files changed, 43 insertions(+), 27 deletions(-)

diff --git a/src/PartKeepr/FrontendBundle/Resources/public/js/Components/Project/MetaPartRowExpander.js b/src/PartKeepr/FrontendBundle/Resources/public/js/Components/Project/MetaPartRowExpander.js @@ -1,6 +1,8 @@ Ext.define("PartKeepr.Components.ProjectReport.MetaPartRowExpander", { extend: "Ext.grid.plugin.RowWidget", + ptype: 'metapartrowexpander', + getHeaderConfig: function() { var config = this.callParent(arguments); diff --git a/src/PartKeepr/FrontendBundle/Resources/public/js/Components/Widgets/ColumnConfigurator/Panel.js b/src/PartKeepr/FrontendBundle/Resources/public/js/Components/Widgets/ColumnConfigurator/Panel.js @@ -154,12 +154,19 @@ Ext.define("PartKeepr.Components.Widgets.ColumnConfigurator.Panel", { var i, j; var columnRecord; this.originalColumnConfigurations = []; + var startColumn = 0; var columnConfig; var fieldsToCopy = this.getFieldsToCopy(); this.columnListGrid.getStore().removeAll(); - for (i = 0; i < columns.length; i++) + // In case we have a row expander which adds an additional column, skip the first column + if (this.grid.findPlugin("metapartrowexpander")) + { + startColumn++; + } + + for (i = startColumn; i < columns.length; i++) { columnRecord = Ext.create("PartKeepr.Models.ColumnConfiguration"); columnConfig = {}; diff --git a/src/PartKeepr/FrontendBundle/Resources/public/js/Components/Widgets/FieldSelector.js b/src/PartKeepr/FrontendBundle/Resources/public/js/Components/Widgets/FieldSelector.js @@ -22,11 +22,6 @@ Ext.define('PartKeepr.Components.Widgets.FieldSelector', { initiallyChecked: [], /** - * @var {Array} Contains the models already in the field tree - */ - visitedModels: [], - - /** * @var {Boolean} True to recurse into associations, false otherwise. */ recurseSubModels: true, @@ -50,17 +45,20 @@ Ext.define('PartKeepr.Components.Widgets.FieldSelector', { var rootNode = this.getRootNode(); rootNode.set("text", this.sourceModel.getName()); - this.treeMaker(rootNode, this.sourceModel, ""); + this.treeMaker(rootNode, this.sourceModel, "", undefined, []); rootNode.expand(); }, /** * Builds the field tree recursively. Handles infinite recursions (e.g. in trees). * - * @param {Ext.data.NodeInterface} The current node - * @param {Ext.data.Model} The model - * @param {String} The prefix. Omit if first called + * @param {Ext.data.NodeInterface} node The current node + * @param {Ext.data.Model} model The model + * @param {String} prefix The prefix. Omit if first called + * @param {Function} callback Te callback, optional + * @param {Array} originalVisitedModels The visited models in te subtree. Omit + * */ - treeMaker: function (node, model, prefix, callback) + treeMaker: function (node, model, prefix, callback, originalVisitedModels) { var fields = model.getFields(); var checked; @@ -68,18 +66,18 @@ Ext.define('PartKeepr.Components.Widgets.FieldSelector', { var j, childNode; var skipSubModel = false, associationAlreadyProcessed; - this.visitedModels.push(model.getName()); + var visitedModels = originalVisitedModels.slice(0); + visitedModels.push(model.getName()); + for (var i = 0; i < fields.length; i++) { if (!fields[i]["persist"]) { continue; } if (fields[i]["reference"] === null) { - checked = false; - if (Ext.Array.contains(this.initiallyChecked, prefix + fields[i].name)) { - checked = true; - } + + checked = Ext.Array.contains(this.initiallyChecked, prefix + fields[i].name); if (!Ext.Array.contains(this.excludeFields, prefix + fields[i].name)) { newNode = { @@ -99,8 +97,8 @@ Ext.define('PartKeepr.Components.Widgets.FieldSelector', { } else { if (this.recurseSubModels) { skipSubModel = false; - for (j = 0; j < this.visitedModels.length; j++) { - if (this.visitedModels[j] === fields[i].reference.cls.getName()) { + for (j = 0; j < visitedModels.length; j++) { + if (visitedModels[j] === fields[i].reference.cls.getName()) { skipSubModel = true; } } @@ -114,7 +112,7 @@ Ext.define('PartKeepr.Components.Widgets.FieldSelector', { if (skipSubModel === false) { childNode = node.appendChild({ text: fields[i].name, - expanded: true, + expanded: false, data: { name: prefix + fields[i].name, type: "manytoone", @@ -124,7 +122,7 @@ Ext.define('PartKeepr.Components.Widgets.FieldSelector', { leaf: false }); - this.treeMaker(childNode, fields[i].reference.cls, prefix + fields[i].name + "."); + this.treeMaker(childNode, fields[i].reference.cls, prefix + fields[i].name + ".", callback, visitedModels); } } } @@ -137,8 +135,8 @@ Ext.define('PartKeepr.Components.Widgets.FieldSelector', { for (i in associations) { associationAlreadyProcessed = false; if (typeof(associations[i].storeName) !== "undefined" && associations[i].isMany === true) { - for (j = 0; j < this.visitedModels.length; j++) { - if (this.visitedModels[j] === associations[i].type) { + for (j = 0; j < visitedModels.length; j++) { + if (visitedModels[j] === associations[i].type) { associationAlreadyProcessed = true; } } @@ -146,7 +144,7 @@ Ext.define('PartKeepr.Components.Widgets.FieldSelector', { if (!associationAlreadyProcessed) { childNode = node.appendChild({ text: associations[i].role, - expanded: true, + expanded: false, data: { name: prefix + associations[i].role, type: "onetomany", @@ -159,7 +157,7 @@ Ext.define('PartKeepr.Components.Widgets.FieldSelector', { childNode.set(callback(associations[i].cls, childNode)); } - this.treeMaker(childNode, associations[i].cls, prefix + associations[i].role + ".", callback); + this.treeMaker(childNode, associations[i].cls, prefix + associations[i].role + ".", callback, visitedModels); } } } diff --git a/src/PartKeepr/SetupBundle/Command/ImportUnitsCommand.php b/src/PartKeepr/SetupBundle/Command/ImportUnitsCommand.php @@ -4,6 +4,7 @@ namespace PartKeepr\SetupBundle\Command; use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; class ImportUnitsCommand extends ContainerAwareCommand @@ -13,11 +14,14 @@ class ImportUnitsCommand extends ContainerAwareCommand parent::configure(); $this->setName('partkeepr:setup:import-units'); $this->setDescription('Imports the default PartKeepr units'); + $this->addOption("update", null, InputOption::VALUE_NONE, "Updates existing units" ); } public function execute(InputInterface $input, OutputInterface $output) { - $return = $this->getContainer()->get('partkeepr.setup.unit_service')->importUnits(); + $update = $input->getOption("update"); + + $return = $this->getContainer()->get('partkeepr.setup.unit_service')->importUnits($update); $output->writeln(sprintf('%d units imported, %d existing units skipped', $return['imported'], $return['skipped'])); diff --git a/src/PartKeepr/SetupBundle/Services/UnitSetupService.php b/src/PartKeepr/SetupBundle/Services/UnitSetupService.php @@ -42,7 +42,7 @@ class UnitSetupService * * @return array An array with the keys "skipped" and "imported" which contain the number of units skipped and imported */ - public function importUnits() + public function importUnits($updateExisting = false) { $path = $this->kernel->locateResource(self::UNIT_PATH.self::UNIT_DATA); @@ -53,13 +53,17 @@ class UnitSetupService $skipped = 0; foreach ($data as $unitName => $unitData) { + $existing = true; $unit = $this->getUnit($unitName); if ($unit === null) { + $existing = false; $unit = new Unit(); $unit->setName($unitName); $unit->setSymbol($unitData['symbol']); + } + if (!$existing || $updateExisting || count($unit->getPrefixes()) === 0) { if (array_key_exists('prefixes', $unitData)) { if (!is_array($unitData['prefixes'])) { throw new \Exception($unitName." doesn't contain a prefix list, or the prefix list is not an array."); @@ -71,9 +75,10 @@ class UnitSetupService throw new \Exception('Unable to find SI Prefix '.$name); } - $unit->getPrefixes()[] = $prefix; + $unit->addPrefix($prefix); } } + $this->entityManager->persist($unit); $this->entityManager->flush(); $count++;