From b876d97ca1c72302bb85abd3ee30f3e86e608d1a Mon Sep 17 00:00:00 2001 From: jygaulier Date: Tue, 16 Mar 2021 13:44:44 +0100 Subject: [PATCH] [skip ci] PHRAS-3381_tx-as-classification-plan_MASTER fix : "replace_all" ok back : ok is handled WIP --- .../dist/production.js | 17 -------- .../dist/production.min.js | 17 -------- .../src/components/thesaurus/index.js | 19 +-------- .../Phrasea/Twig/PhraseanetExtension.php | 4 +- lib/classes/record/adapter.php | 41 +++++++++++-------- .../prod/Thesaurus/droppedrecords.html.twig | 27 +++++++++--- 6 files changed, 47 insertions(+), 78 deletions(-) diff --git a/Phraseanet-production-client/dist/production.js b/Phraseanet-production-client/dist/production.js index 4f68596d43..591d8f01de 100644 --- a/Phraseanet-production-client/dist/production.js +++ b/Phraseanet-production-client/dist/production.js @@ -11638,23 +11638,6 @@ var thesaurusService = function thesaurusService(services) { // title: localeService.t('add data'), loading: true }, 0); - // dlg.setContent(""); - - // let parms = { - // url: '/thesaurus/drop_records.php', - // data: { - // 'sbas_id': sbas_id, - // 'tx_term_id': tx_term_id, - // 'lst': lstRecords - // }, - // async: true, - // cache: false, - // dataType: 'json', - // // timeout: 10 * 60 * 1000, // 10 minutes ! - // success: function (result, textStatus) { - // dlg.setContent(result); - // } - // }; _jquery2.default.get(url + 'prod/thesaurus/droprecords', { 'dlg_level': 0, diff --git a/Phraseanet-production-client/dist/production.min.js b/Phraseanet-production-client/dist/production.min.js index 4f68596d43..591d8f01de 100644 --- a/Phraseanet-production-client/dist/production.min.js +++ b/Phraseanet-production-client/dist/production.min.js @@ -11638,23 +11638,6 @@ var thesaurusService = function thesaurusService(services) { // title: localeService.t('add data'), loading: true }, 0); - // dlg.setContent(""); - - // let parms = { - // url: '/thesaurus/drop_records.php', - // data: { - // 'sbas_id': sbas_id, - // 'tx_term_id': tx_term_id, - // 'lst': lstRecords - // }, - // async: true, - // cache: false, - // dataType: 'json', - // // timeout: 10 * 60 * 1000, // 10 minutes ! - // success: function (result, textStatus) { - // dlg.setContent(result); - // } - // }; _jquery2.default.get(url + 'prod/thesaurus/droprecords', { 'dlg_level': 0, diff --git a/Phraseanet-production-client/src/components/thesaurus/index.js b/Phraseanet-production-client/src/components/thesaurus/index.js index dff75cbdc6..51144defee 100644 --- a/Phraseanet-production-client/src/components/thesaurus/index.js +++ b/Phraseanet-production-client/src/components/thesaurus/index.js @@ -266,27 +266,10 @@ const thesaurusService = services => { customWidth: 770, customHeight: 400, // title: localeService.t('add data'), - loading: true, + loading: true }, 0 ); - // dlg.setContent(""); - - // let parms = { - // url: '/thesaurus/drop_records.php', - // data: { - // 'sbas_id': sbas_id, - // 'tx_term_id': tx_term_id, - // 'lst': lstRecords - // }, - // async: true, - // cache: false, - // dataType: 'json', - // // timeout: 10 * 60 * 1000, // 10 minutes ! - // success: function (result, textStatus) { - // dlg.setContent(result); - // } - // }; $.get( `${url}prod/thesaurus/droprecords`, diff --git a/lib/Alchemy/Phrasea/Twig/PhraseanetExtension.php b/lib/Alchemy/Phrasea/Twig/PhraseanetExtension.php index 13a1b0de3c..bc8d315419 100644 --- a/lib/Alchemy/Phrasea/Twig/PhraseanetExtension.php +++ b/lib/Alchemy/Phrasea/Twig/PhraseanetExtension.php @@ -4,10 +4,10 @@ namespace Alchemy\Phrasea\Twig; use Alchemy\Phrasea\Application; use Alchemy\Phrasea\Collection\CollectionHelper; +use Alchemy\Phrasea\Http\StaticFile\StaticMode; use Alchemy\Phrasea\Model\Entities\ElasticsearchRecord; use Alchemy\Phrasea\Model\Entities\User; use Alchemy\Phrasea\Model\RecordInterface; -use Alchemy\Phrasea\Http\StaticFile\StaticMode; use Alchemy\Phrasea\SearchEngine\Elastic\Structure\Flag; class PhraseanetExtension extends \Twig_Extension @@ -59,7 +59,7 @@ class PhraseanetExtension extends \Twig_Extension { return [ // change this version when you change JS file to force the navigation to reload js file - 'jsFileVersion' => 8 + 'jsFileVersion' => 9 ]; } diff --git a/lib/classes/record/adapter.php b/lib/classes/record/adapter.php index 1242e210ef..ad321b0d1a 100644 --- a/lib/classes/record/adapter.php +++ b/lib/classes/record/adapter.php @@ -1128,7 +1128,7 @@ class record_adapter implements RecordInterface, cache_cacheableInterface public function setMetadatasByActions(stdClass $actions) { // WIP crashes when trying to access an undefined stdClass property ? should return null ? - // $this->apply_body($actions); + $this->apply_body($actions); return $this; } @@ -1141,20 +1141,19 @@ class record_adapter implements RecordInterface, cache_cacheableInterface /** * @param stdClass $b - * @param record_adapter $record * @throws Exception */ private function apply_body(stdClass $b) { // do metadatas ops - if (is_array($b->metadatas)) { + if (is_array(@$b->metadatas)) { $this->do_metadatas($b->metadatas); } // do sb ops - if (is_array($b->status)) { + if (is_array(@$b->status)) { $this->do_status($b->status); } - if(!is_null($b->base_id)) { + if(!is_null(@$b->base_id)) { $this->do_collection($b->base_id); } } @@ -1176,8 +1175,10 @@ class record_adapter implements RecordInterface, cache_cacheableInterface /** * @param $metadatas * @throws Exception + * + * nb : use of "silent" @ operator on stdClass member access (equals null in not defined) is more simple than "iseet()" or "empty()" */ - private function do_metadatas($metadatas) + private function do_metadatas(array $metadatas) { /** @var databox_field[] $struct */ $struct = $this->getDatabox()->get_meta_structure(); @@ -1192,15 +1193,16 @@ class record_adapter implements RecordInterface, cache_cacheableInterface } $metadatas_ops = []; + /** @var stdClass $_m */ foreach ($metadatas as $_m) { // sanity - if($_m->meta_struct_id && $_m->field_name) { // WIP crashes if meta_struct_id is undefined + if(@$_m->meta_struct_id && @$_m->field_name) { // WIP crashes if meta_struct_id is undefined throw new Exception("define meta_struct_id OR field_name, not both."); } // select fields that match meta_struct_id or field_name (can be arrays) $fields_list = null; // to filter caption_fields from record, default all $struct_fields = []; // struct fields that match meta_struct_id or field_name - $field_keys = $_m->meta_struct_id ? $_m->meta_struct_id : $_m->field_name; // can be null if none defined (=match all) + $field_keys = @$_m->meta_struct_id ?: @$_m->field_name; // can be null if none defined (=match all) if($field_keys !== null) { if (!is_array($field_keys)) { $field_keys = [$field_keys]; @@ -1222,9 +1224,9 @@ class record_adapter implements RecordInterface, cache_cacheableInterface } $caption_fields = $this->get_caption()->get_fields($fields_list, true); - $meta_id = is_null($_m->meta_id) ? null : (int)($_m->meta_id); + $meta_id = isset($_m->meta_id) ? (int)($_m->meta_id) : null; - if(!($match_method = (string)($_m->match_method))) { + if(!($match_method = (string)(@$_m->match_method))) { $match_method = 'ignore_case'; } if(!in_array($match_method, ['strict', 'ignore_case', 'regexp'])) { @@ -1232,7 +1234,7 @@ class record_adapter implements RecordInterface, cache_cacheableInterface } $values = []; - if(is_array($_m->value)) { + if(is_array(@$_m->value)) { foreach ($_m->value as $v) { if(($v = trim((string)$v)) !== '') { $values[] = $v; @@ -1240,16 +1242,16 @@ class record_adapter implements RecordInterface, cache_cacheableInterface } } else { - if(($v = trim((string)($_m->value))) !== '') { + if(($v = trim((string)(@$_m->value))) !== '') { $values[] = $v; } } - if(!($action = (string)($_m->action))) { + if(!($action = (string)(@$_m->action))) { $action = 'set'; } - switch ($_m->action) { + switch ($action) { case 'set': $ops = $this->metadata_set($struct_fields, $caption_fields, $meta_id, $values); break; @@ -1260,6 +1262,9 @@ class record_adapter implements RecordInterface, cache_cacheableInterface $ops = $this->metadata_replace($caption_fields, $meta_id, $match_method, $values, null); break; case 'replace': + if (!isset($_m->replace_with)) { + throw new Exception("missing mandatory \"replace_with\" for action \"replace\"."); + } if (!is_string($_m->replace_with) && !is_null($_m->replace_with)) { throw new Exception("bad \"replace_with\" for action \"replace\"."); } @@ -1285,13 +1290,13 @@ class record_adapter implements RecordInterface, cache_cacheableInterface * @return array * @throws Exception */ - private function do_status($statuses) + private function do_status(array $statuses) { $datas = strrev($this->getStatus()); foreach ($statuses as $status) { - $n = (int)($status->bit); - $value = (int)($status->state); + $n = (int)(@$status->bit); + $value = (int)(@$status->state); if ($n > 31 || $n < 4) { throw new Exception(sprintf("Invalid status bit number (%s).", $n)); } @@ -1327,7 +1332,7 @@ class record_adapter implements RecordInterface, cache_cacheableInterface * @return array ops to execute * @throws Exception */ - private function metadata_set(array $struct_fields, $caption_fields, $meta_id, $values): array + private function metadata_set(array $struct_fields, array $caption_fields, $meta_id, array $values): array { $ops = []; diff --git a/templates/web/prod/Thesaurus/droppedrecords.html.twig b/templates/web/prod/Thesaurus/droppedrecords.html.twig index dd5f0a4155..b0c629c9c8 100644 --- a/templates/web/prod/Thesaurus/droppedrecords.html.twig +++ b/templates/web/prod/Thesaurus/droppedrecords.html.twig @@ -47,7 +47,7 @@ {# do NOT mix the following 2 options as one #} - + @@ -78,8 +78,11 @@ // let $container = $('#DroppedOnTH_form'); let dlg = dialog.get({{ dlg_level }}); + // todo : find dlg container by .widget() ? let $container = dlg.getDomElement().parent(); // the whole dlg, including title & buttons + // todo : fix black-dialog-wrap + // $container.addClass('black-dialog-wrap'); dlg.setOption("title", "editing {{ received_cnt }} record(s)"); dlg.setOption("buttons", [ @@ -92,11 +95,22 @@ let data = []; $(' .fieldSelect').filter(function () { return $(this).prop('selectedIndex')>0;}).each(function () { let n = $(this).data('n'); - data.push({ - 'field_name': $(this).val(), - 'action' : $(' .actionSelect._'+n, $container).val(), - 'value' : $(' .synonym._'+n, $container).val() - }); + let action = $(' .actionSelect._'+n, $container).val(); + if(action === 'replace') { + // replace ll multi-v needs a "replace_by" arg + data.push({ + 'field_name': $(this).val(), + 'action': action, + 'replace_with': $(' .synonym._' + n, $container).val() + }); + } + else { + data.push({ + 'field_name': $(this).val(), + 'action': action, + 'value': $(' .synonym._' + n, $container).val() + }); + } }); data = { 'records': {{ records|json_encode|raw }}, @@ -114,6 +128,7 @@ data: JSON.stringify(data), success: function (data, textStatus) { console.log(data); + dlg.close(); } }, );