From b3aadb83ab7624e70f4e5b8ebd81debb3cf3a71c Mon Sep 17 00:00:00 2001 From: aynsix Date: Mon, 12 Jul 2021 11:36:57 +0300 Subject: [PATCH] order field mapping in expose --- .../dist/production.js | 2 ++ .../dist/production.min.js | 2 ++ .../src/components/ui/workzone/index.js | 2 ++ .../Controller/PSExposeController.php | 28 ++++++++++++----- .../Worker/ExposeUploadWorker.php | 31 ++++++++++++------- .../prod/WorkZone/ExposeFieldList.html.twig | 14 +++++---- .../WorkZone/ExposeFieldMapping.html.twig | 1 - 7 files changed, 54 insertions(+), 26 deletions(-) diff --git a/Phraseanet-production-client/dist/production.js b/Phraseanet-production-client/dist/production.js index c013188305..a2b4682591 100644 --- a/Phraseanet-production-client/dist/production.js +++ b/Phraseanet-production-client/dist/production.js @@ -10055,6 +10055,8 @@ var workzone = function workzone(services) { }, success: function success(data) { (0, _jquery2.default)('#DIALOG-field-mapping .databox-field-list').empty().html(data); + + (0, _jquery2.default)('.field-list').sortable().disableSelection(); } }); }); diff --git a/Phraseanet-production-client/dist/production.min.js b/Phraseanet-production-client/dist/production.min.js index c013188305..a2b4682591 100644 --- a/Phraseanet-production-client/dist/production.min.js +++ b/Phraseanet-production-client/dist/production.min.js @@ -10055,6 +10055,8 @@ var workzone = function workzone(services) { }, success: function success(data) { (0, _jquery2.default)('#DIALOG-field-mapping .databox-field-list').empty().html(data); + + (0, _jquery2.default)('.field-list').sortable().disableSelection(); } }); }); diff --git a/Phraseanet-production-client/src/components/ui/workzone/index.js b/Phraseanet-production-client/src/components/ui/workzone/index.js index 51241cf547..ae80181cbb 100644 --- a/Phraseanet-production-client/src/components/ui/workzone/index.js +++ b/Phraseanet-production-client/src/components/ui/workzone/index.js @@ -145,6 +145,8 @@ const workzone = (services) => { }, success: function (data) { $('#DIALOG-field-mapping .databox-field-list').empty().html(data); + + $('.field-list').sortable().disableSelection(); } }); }); diff --git a/lib/Alchemy/Phrasea/PhraseanetService/Controller/PSExposeController.php b/lib/Alchemy/Phrasea/PhraseanetService/Controller/PSExposeController.php index 69f016ae01..a32a2eca78 100644 --- a/lib/Alchemy/Phrasea/PhraseanetService/Controller/PSExposeController.php +++ b/lib/Alchemy/Phrasea/PhraseanetService/Controller/PSExposeController.php @@ -728,23 +728,21 @@ class PSExposeController extends Controller 'message' => "Expose configuration not set!" ]); } + $exposeMappingName = $this->getExposeMappingName(); $clientAnnotationProfile = $this->getClientAnnotationProfile($exposeClient, $exposeName, $profile); - $fields = $this->getFields(); + $actualFieldsList = !empty($clientAnnotationProfile[$exposeMappingName]) ? $clientAnnotationProfile[$exposeMappingName] : []; + $fields = $this->getFields($actualFieldsList); return $this->render('prod/WorkZone/ExposeFieldList.html.twig', [ 'fields' => $fields, - 'actualFieldsList' => !empty($clientAnnotationProfile[$exposeMappingName]) ? $clientAnnotationProfile[$exposeMappingName] : [] ]); } public function getFieldMappingAction(PhraseaApplication $app, Request $request) { - $fields = $this->getFields(); - return $this->render('prod/WorkZone/ExposeFieldMapping.html.twig', [ - 'fields' => $fields, 'exposeName' => $request->get('exposeName') ]); } @@ -854,16 +852,32 @@ class PSExposeController extends Controller * * @return array */ - private function getFields() + private function getFields($actualFieldsList) { $databoxes = $this->getApplicationBox()->get_databoxes(); - $fields = []; + $fieldFromProfile = []; + foreach ($actualFieldsList as $value) { + $t = explode('_', $value); + $databox = $this->getApplicationBox()->get_databox($t[0]); + $viewName = $databox->get_viewname(); + + $fieldFromProfile[$viewName][$t[1]]['id'] = $value; + $fieldFromProfile[$viewName][$t[1]]['name'] = $databox->get_meta_structure()->get_element($t[1])->get_label($this->app['locale']); + $fieldFromProfile[$viewName][$t[1]]['checked'] = true; + } + + $fields = $fieldFromProfile; foreach ($databoxes as $databox) { foreach ($databox->get_meta_structure() as $meta) { // get databoxID_metaID for the checkbox name + if (!empty($fields[$databox->get_viewname()][$meta->get_id()]) && in_array($databox->get_sbas_id().'_'.$meta->get_id(), $fields[$databox->get_viewname()][$meta->get_id()])) { + continue; + } + $fields[$databox->get_viewname()][$meta->get_id()]['id'] = $databox->get_sbas_id().'_'.$meta->get_id(); $fields[$databox->get_viewname()][$meta->get_id()]['name'] = $meta->get_label($this->app['locale']); + } } diff --git a/lib/Alchemy/Phrasea/WorkerManager/Worker/ExposeUploadWorker.php b/lib/Alchemy/Phrasea/WorkerManager/Worker/ExposeUploadWorker.php index 76ec81404a..7066be08b1 100644 --- a/lib/Alchemy/Phrasea/WorkerManager/Worker/ExposeUploadWorker.php +++ b/lib/Alchemy/Phrasea/WorkerManager/Worker/ExposeUploadWorker.php @@ -96,26 +96,32 @@ class ExposeUploadWorker implements WorkerInterface $record = $this->findDataboxById($payload['databoxId'])->get_record($payload['recordId']); $helpers = new PhraseanetExtension($this->app); - $canSeeBusiness = $helpers->isGrantedOnCollection($record->getBaseId(), [\ACL::CANMODIFRECORD]); - $captionsByfield = $record->getCaption($helpers->getCaptionFieldOrder($record, $canSeeBusiness)); - - // this is the unique reference for record in phraseanet and assets in expose + // the identification of phraseanet instance in expose $phraseanetLocalId = $this->app['conf']->get(['phraseanet-service', 'phraseanet_local_id']); + $fieldListToUpload = $this->getFieldListToUpload($exposeClient, $payload['accessToken'], $payload['publicationId'], $phraseanetLocalId); $description = "
"; - foreach ($captionsByfield as $name => $value) { - $databoxId = $record->getDataboxId(); - $metaId = $record->get_caption()->get_field($name)->get_meta_struct_id(); + foreach ($fieldListToUpload as $value) { + // value as databoxId_metaId + $t = explode('_', $value); - if ($helpers->getCaptionFieldGuiVisible($record, $name) == 1 && in_array($databoxId . '_' . $metaId, $fieldListToUpload)) { - $fieldType = $record->get_caption()->get_field($name)->get_databox_field()->get_type(); - $fieldLabel = $helpers->getCaptionFieldLabel($record, $name); + // check if it is on the same databox + if ($payload['databoxId'] == $t[0]) { + $fieldName = $record->getDatabox()->get_meta_structure()->get_element($t[1])->get_name(); + if ($record->get_caption()->has_field($fieldName) && $helpers->getCaptionFieldGuiVisible($record, $fieldName) == 1) { + // retrieve value for the corresponding field + $captionField = $record->get_caption()->get_field($fieldName); + $fieldValues = $captionField->get_values(); - $description .= "
" . $fieldLabel. "
"; - $description .= "
" . $helpers->getCaptionField($record, $name, $value). "
"; + $fieldType = $captionField->get_databox_field()->get_type(); + $fieldLabel = $helpers->getCaptionFieldLabel($record, $fieldName); + + $description .= "
" . $fieldLabel. "
"; + $description .= "
" . $helpers->getCaptionField($record, $fieldName, $fieldValues). "
"; + } } } @@ -141,6 +147,7 @@ class ExposeUploadWorker implements WorkerInterface } } + // this is the unique reference for record in phraseanet and assets in expose // phraseanetLocalKey_basedID_record_id $assetId = $phraseanetLocalId.'_'.$record->getId(); diff --git a/templates/web/prod/WorkZone/ExposeFieldList.html.twig b/templates/web/prod/WorkZone/ExposeFieldList.html.twig index 8de28f3943..5ddd6bd46b 100644 --- a/templates/web/prod/WorkZone/ExposeFieldList.html.twig +++ b/templates/web/prod/WorkZone/ExposeFieldList.html.twig @@ -1,11 +1,13 @@ {% for dbName, field in fields %}
{{ dbName }} - {% for metaField in field %} - - {% endfor %} +
+ {% for metaField in field %} + + {% endfor %} +
{% endfor %} diff --git a/templates/web/prod/WorkZone/ExposeFieldMapping.html.twig b/templates/web/prod/WorkZone/ExposeFieldMapping.html.twig index 5646637ec3..c862747db3 100644 --- a/templates/web/prod/WorkZone/ExposeFieldMapping.html.twig +++ b/templates/web/prod/WorkZone/ExposeFieldMapping.html.twig @@ -10,7 +10,6 @@
- {% include 'prod/WorkZone/ExposeFieldList.html.twig' with {'fields':fields} %}