From deafb8b957f463953d5f283b537a498610d76507 Mon Sep 17 00:00:00 2001 From: Jean-Yves Gaulier Date: Thu, 23 Jun 2016 20:22:25 +0200 Subject: [PATCH 1/4] PHRAS-1177_change-multi-on-field - add : now the "multi" attribute on a field can be changed after creation - change : field template #time 3h --- .../Controller/Admin/FieldsController.php | 3 +- lib/classes/databox.php | 3 +- lib/classes/databox/field.php | 20 ++- .../web/admin/fields/templates.html.twig | 122 +++++++++--------- .../Phrasea/Controller/Admin/FieldsTest.php | 11 +- tests/classes/databox/fieldTest.php | 6 +- www/scripts/apps/admin/fields/views/edit.js | 15 ++- 7 files changed, 103 insertions(+), 77 deletions(-) diff --git a/lib/Alchemy/Phrasea/Controller/Admin/FieldsController.php b/lib/Alchemy/Phrasea/Controller/Admin/FieldsController.php index c13efa100d..02822d9228 100644 --- a/lib/Alchemy/Phrasea/Controller/Admin/FieldsController.php +++ b/lib/Alchemy/Phrasea/Controller/Admin/FieldsController.php @@ -210,7 +210,7 @@ class FieldsController extends Controller $this->validateTagField($data); try { - $field = \databox_field::create($this->app, $databox, $data['name'], $data['multi']); + $field = \databox_field::create($this->app, $databox, $data['name']); $this->updateFieldWithData($field, $data); $field->save(); } catch (\Exception $e) { @@ -308,6 +308,7 @@ class FieldsController extends Controller ->set_business($data['business']) ->set_aggregable($data['aggregable']) ->set_indexable($data['indexable']) + ->set_multi($data['multi']) ->set_required($data['required']) ->set_separator($data['separator']) ->set_readonly($data['readonly']) diff --git a/lib/classes/databox.php b/lib/classes/databox.php index f52e2b492a..f4cba4d84d 100644 --- a/lib/classes/databox.php +++ b/lib/classes/databox.php @@ -451,8 +451,9 @@ class databox extends base implements ThumbnailedElement $multi = isset($field['multi']) ? (Boolean) (string) $field['multi'] : false; - $meta_struct_field = databox_field::create($this->app, $this, $fname, $multi); + $meta_struct_field = databox_field::create($this->app, $this, $fname); $meta_struct_field + ->set_multi($multi) ->set_readonly(isset($field['readonly']) ? (string) $field['readonly'] : 0) ->set_indexable(isset($field['index']) ? (string) $field['index'] : '1') ->set_separator(isset($field['separator']) ? (string) $field['separator'] : '') diff --git a/lib/classes/databox/field.php b/lib/classes/databox/field.php index 4e4eb70970..c2de3168e5 100644 --- a/lib/classes/databox/field.php +++ b/lib/classes/databox/field.php @@ -564,6 +564,18 @@ class databox_field implements cache_cacheableInterface return $this; } + /** + * + * @param boolean $bool + * @return databox_field + */ + public function set_multi($bool) + { + $this->multi = (bool)$bool; + + return $this; + } + /** * Set a vocabulary * @@ -892,7 +904,7 @@ class databox_field implements cache_cacheableInterface * * @throws \Exception_InvalidArgument */ - public static function create(Application $app, databox $databox, $name, $multi) + public static function create(Application $app, databox $databox, $name) { $sorter = 0; @@ -911,7 +923,7 @@ class databox_field implements cache_cacheableInterface `thumbtitle`, `multi`, `business`, `aggregable`, `report`, `sorter`, `separator`) VALUES (null, :name, '', 0, 0, 1, 'string', '', - null, :multi, + null, 0, 0, 0, 1, :sorter, '')"; $name = self::generateName($name); @@ -920,10 +932,8 @@ class databox_field implements cache_cacheableInterface throw new \Exception_InvalidArgument(); } - $multi = $multi ? 1 : 0; - $stmt = $databox->get_connection()->prepare($sql); - $stmt->execute([':name' => $name, ':sorter' => $sorter, ':multi' => $multi]); + $stmt->execute([':name' => $name, ':sorter' => $sorter]); $id = $databox->get_connection()->lastInsertId(); $stmt->closeCursor(); diff --git a/templates/web/admin/fields/templates.html.twig b/templates/web/admin/fields/templates.html.twig index ad6a890f88..62e335cd8b 100644 --- a/templates/web/admin/fields/templates.html.twig +++ b/templates/web/admin/fields/templates.html.twig @@ -119,45 +119,20 @@ - - <% if(field.multi == true) { %> - - <% } else { %> - - <% } %> {% trans %}Multivalued{% endtrans %} + + +
-

{% trans %}Advanced field parameters{% endtrans %}

- - - - - - - - - - - - - - - - - - - - - - -
- -
- -
<% if(field['vocabulary-type'] != null && field['vocabulary-type'] != '') { %> @@ -168,36 +143,23 @@ <% } %>
- -
- - - -

{% trans %}Display & action settings{% endtrans %}

+ + + + + + + + + + + + + + + + + + + +
+ + + +
+ +
+ + + +
+ +
diff --git a/tests/Alchemy/Tests/Phrasea/Controller/Admin/FieldsTest.php b/tests/Alchemy/Tests/Phrasea/Controller/Admin/FieldsTest.php index 8e10b1842c..e13f9e4e9a 100644 --- a/tests/Alchemy/Tests/Phrasea/Controller/Admin/FieldsTest.php +++ b/tests/Alchemy/Tests/Phrasea/Controller/Admin/FieldsTest.php @@ -154,7 +154,7 @@ class FieldsTest extends \PhraseanetAuthenticatedWebTestCase ]]; foreach ($fields as $fieldData) { - $field = \databox_field::create($this->getApplication(), $databox, $fieldData['name'], $fieldData['multi']); + $field = \databox_field::create($this->getApplication(), $databox, $fieldData['name']); $field ->set_thumbtitle($fieldData['thumbtitle']) ->set_tag(\databox_field::loadClassFromTagName($fieldData['tag'])) @@ -167,7 +167,8 @@ class FieldsTest extends \PhraseanetAuthenticatedWebTestCase ->set_tbranch($fieldData['tbranch']) ->set_report($fieldData['report']) ->setVocabularyControl(null) - ->setVocabularyRestricted(false); + ->setVocabularyRestricted(false) + ->set_multi($fieldData['multi']); $field->save(); $fieldObjects[] = $field; } @@ -271,7 +272,7 @@ class FieldsTest extends \PhraseanetAuthenticatedWebTestCase $app = $this->getApplication(); $databox = $this->getFirstDatabox($app); - $field = \databox_field::create($app, $databox, 'testfield' . mt_rand(), false); + $field = \databox_field::create($app, $databox, 'testfield' . mt_rand()); $data = $field->toArray(); @@ -289,7 +290,7 @@ class FieldsTest extends \PhraseanetAuthenticatedWebTestCase $app = $this->getApplication(); $databox = $this->getFirstDatabox($app); - $field = \databox_field::create($app, $databox, 'testfield' . mt_rand(), false); + $field = \databox_field::create($app, $databox, 'testfield' . mt_rand()); $data = $field->toArray(); @@ -308,7 +309,7 @@ class FieldsTest extends \PhraseanetAuthenticatedWebTestCase $app = $this->getApplication(); $databox = $this->getFirstDatabox($app); - $field = \databox_field::create($app, $databox, 'testfield' . mt_rand(), false); + $field = \databox_field::create($app, $databox, 'testfield' . mt_rand()); $fieldId = $field->get_id(); $data = $field->toArray(); diff --git a/tests/classes/databox/fieldTest.php b/tests/classes/databox/fieldTest.php index 35187d6d4d..1d9710cad1 100644 --- a/tests/classes/databox/fieldTest.php +++ b/tests/classes/databox/fieldTest.php @@ -32,10 +32,12 @@ class databox_fieldTest extends \PhraseanetTestCase $this->object_multi = $this->databox->get_meta_structure()->get_element_by_name($this->name_multi); if (! $this->object_mono instanceof databox_field) { - $this->object_mono = databox_field::create(self::$DI['app'], $this->databox, $this->name_mono, false); + $this->object_mono = databox_field::create(self::$DI['app'], $this->databox, $this->name_mono); + $this->object_mono->set_multi(false); } if (! $this->object_multi instanceof databox_field) { - $this->object_multi = databox_field::create(self::$DI['app'], $this->databox, $this->name_multi, true); + $this->object_multi = databox_field::create(self::$DI['app'], $this->databox, $this->name_multi); + $this->object_mono->set_multi(true); } } diff --git a/www/scripts/apps/admin/fields/views/edit.js b/www/scripts/apps/admin/fields/views/edit.js index 5fc0e10037..f5c0e8b98c 100644 --- a/www/scripts/apps/admin/fields/views/edit.js +++ b/www/scripts/apps/admin/fields/views/edit.js @@ -93,7 +93,8 @@ define([ "keyup input.input-label": "labelChangedAction", "change input[type=checkbox]": "fieldChangedAction", "change select": "selectionChangedAction", - "click .lng-label a": "_toggleLabels" + "click .lng-label a": "_toggleLabels", + "click input#multi": "multiClickdAction" }, triggerControlledVocabulary: function (e) { if ($(e.target, this.$el).find("option:selected").val() === "") { @@ -133,6 +134,16 @@ define([ return this; }, + multiClickdAction: function (e) { + if($(e.target).is(":checked")) { + $("#separatorZone").show(); + } + else { + $("#separatorZone").hide(); + } + + return this; + }, tagFieldChangedAction: function (e) { var $this = this; var fieldTag = $(e.target); @@ -154,7 +165,7 @@ define([ } else { $this.fieldChangedAction(e); } - } + }; if ("" !== fieldTagValue) { var jqxhr = $.get("/admin/fields/tags/" + fieldTagValue, onFieldValid).fail(function () { From 6572f3ba147ff8e56f106684ccca197d79462c87 Mon Sep 17 00:00:00 2001 From: Jean-Yves Gaulier Date: Thu, 23 Jun 2016 20:39:09 +0200 Subject: [PATCH 2/4] PHRAS-1177_change-multi-on-field - fix : multi field gets the default separator #time 10m --- lib/classes/databox/field.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/classes/databox/field.php b/lib/classes/databox/field.php index c2de3168e5..f64b43d57f 100644 --- a/lib/classes/databox/field.php +++ b/lib/classes/databox/field.php @@ -572,7 +572,7 @@ class databox_field implements cache_cacheableInterface public function set_multi($bool) { $this->multi = (bool)$bool; - + $this->separator = self::checkMultiSeparator($this->separator, $this->multi); return $this; } From 351dc5e0c716479c90f9137f02b5ce8a562e48f7 Mon Sep 17 00:00:00 2001 From: Jean-Yves Gaulier Date: Mon, 27 Jun 2016 14:39:20 +0200 Subject: [PATCH 3/4] PHRAS-1177_change-multi-on-field - fix : test #time 30m --- tests/classes/databox/fieldTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/classes/databox/fieldTest.php b/tests/classes/databox/fieldTest.php index 1d9710cad1..ce3dc44385 100644 --- a/tests/classes/databox/fieldTest.php +++ b/tests/classes/databox/fieldTest.php @@ -37,7 +37,7 @@ class databox_fieldTest extends \PhraseanetTestCase } if (! $this->object_multi instanceof databox_field) { $this->object_multi = databox_field::create(self::$DI['app'], $this->databox, $this->name_multi); - $this->object_mono->set_multi(true); + $this->object_multi->set_multi(true); } } From e10a6f8ebd5dde797fb02b389fc27bbf805b1c99 Mon Sep 17 00:00:00 2001 From: Jean-Yves Gaulier Date: Mon, 27 Jun 2016 16:45:51 +0200 Subject: [PATCH 4/4] PHRAS-1177_change-multi-on-field - change : no more "multi" checkbox when creating a field - new field is not "report" anymore #time 1h --- lib/classes/databox/field.php | 4 ++-- templates/web/admin/fields/templates.html.twig | 4 +--- www/scripts/apps/admin/fields/views/create.js | 3 ++- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/lib/classes/databox/field.php b/lib/classes/databox/field.php index f64b43d57f..2cbdc9679b 100644 --- a/lib/classes/databox/field.php +++ b/lib/classes/databox/field.php @@ -923,8 +923,8 @@ class databox_field implements cache_cacheableInterface `thumbtitle`, `multi`, `business`, `aggregable`, `report`, `sorter`, `separator`) VALUES (null, :name, '', 0, 0, 1, 'string', '', - null, 0, - 0, 0, 1, :sorter, '')"; + null, 0, 0, 0, + 1, :sorter, '')"; $name = self::generateName($name); diff --git a/templates/web/admin/fields/templates.html.twig b/templates/web/admin/fields/templates.html.twig index 62e335cd8b..284380457b 100644 --- a/templates/web/admin/fields/templates.html.twig +++ b/templates/web/admin/fields/templates.html.twig @@ -60,13 +60,11 @@
-
+ diff --git a/www/scripts/apps/admin/fields/views/create.js b/www/scripts/apps/admin/fields/views/create.js index 66d3b140b9..e79b09aa1d 100644 --- a/www/scripts/apps/admin/fields/views/create.js +++ b/www/scripts/apps/admin/fields/views/create.js @@ -130,7 +130,8 @@ define([ "label_fr": $("#new-label_fr", this.$el).val(), "label_de": $("#new-label_de", this.$el).val(), "label_nl": $("#new-label_nl", this.$el).val(), - "multi": $("#new-multivalued", this.$el).is(":checked") + "multi": $("#new-multivalued", this.$el).is(":checked"), + "report": false }); field.save(null, {