From 6fb4aeb303b8632e049b3333ff22637a053b542b Mon Sep 17 00:00:00 2001 From: "Peter Droogmans (attiks)" Date: Fri, 5 Apr 2024 11:16:18 +0200 Subject: [PATCH 1/2] feat: message, always auto mode --- ...orm_display.node.action_points.default.yml | 50 ++++++------------- ...tity_form_display.node.summary.default.yml | 34 ++++++------- config/filter.format.text_editor_simple.yml | 6 +++ config/views.view.my_documents.yml | 2 +- .../ocha_ai_summarize.module | 2 + 5 files changed, 39 insertions(+), 55 deletions(-) diff --git a/config/core.entity_form_display.node.action_points.default.yml b/config/core.entity_form_display.node.action_points.default.yml index 669c3a8..1a22099 100644 --- a/config/core.entity_form_display.node.action_points.default.yml +++ b/config/core.entity_form_display.node.action_points.default.yml @@ -28,13 +28,13 @@ mode: default content: created: type: datetime_timestamp - weight: 12 + weight: 11 region: content settings: { } third_party_settings: { } field_action_points: type: text_textarea - weight: 11 + weight: 10 region: content settings: rows: 5 @@ -48,7 +48,7 @@ content: third_party_settings: { } field_ai_feedback: type: comment_default - weight: 19 + weight: 16 region: content settings: { } third_party_settings: { } @@ -59,29 +59,22 @@ content: settings: display_label: true third_party_settings: { } - field_automatic_mode: - type: boolean_checkbox - weight: 5 - region: content - settings: - display_label: true - third_party_settings: { } field_document: type: file_generic - weight: 8 + weight: 7 region: content settings: progress_indicator: throbber third_party_settings: { } field_document_language: type: options_select - weight: 6 + weight: 5 region: content settings: { } third_party_settings: { } field_document_text: type: string_textarea - weight: 10 + weight: 9 region: content settings: rows: 5 @@ -89,7 +82,7 @@ content: third_party_settings: { } field_output_language: type: options_select - weight: 7 + weight: 6 region: content settings: { } third_party_settings: { } @@ -102,13 +95,13 @@ content: third_party_settings: { } moderation_state: type: moderation_state_default - weight: 17 + weight: 14 region: content settings: { } third_party_settings: { } path: type: path - weight: 15 + weight: 12 region: content settings: { } third_party_settings: { } @@ -118,23 +111,9 @@ content: region: content settings: { } third_party_settings: { } - promote: - type: boolean_checkbox - weight: 13 - region: content - settings: - display_label: true - third_party_settings: { } status: type: boolean_checkbox - weight: 18 - region: content - settings: - display_label: true - third_party_settings: { } - sticky: - type: boolean_checkbox - weight: 14 + weight: 15 region: content settings: display_label: true @@ -149,7 +128,7 @@ content: third_party_settings: { } uid: type: entity_reference_autocomplete - weight: 9 + weight: 8 region: content settings: match_operator: CONTAINS @@ -158,8 +137,11 @@ content: placeholder: '' third_party_settings: { } url_redirects: - weight: 16 + weight: 13 region: content settings: { } third_party_settings: { } -hidden: { } +hidden: + field_automatic_mode: true + promote: true + sticky: true diff --git a/config/core.entity_form_display.node.summary.default.yml b/config/core.entity_form_display.node.summary.default.yml index dda7748..6643ac0 100644 --- a/config/core.entity_form_display.node.summary.default.yml +++ b/config/core.entity_form_display.node.summary.default.yml @@ -28,7 +28,7 @@ mode: default content: created: type: datetime_timestamp - weight: 16 + weight: 15 region: content settings: { } third_party_settings: { } @@ -40,7 +40,7 @@ content: third_party_settings: { } field_ai_feedback: type: comment_default - weight: 18 + weight: 17 region: content settings: { } third_party_settings: { } @@ -51,29 +51,22 @@ content: settings: display_label: true third_party_settings: { } - field_automatic_mode: - type: boolean_checkbox - weight: 5 - region: content - settings: - display_label: true - third_party_settings: { } field_document: type: file_generic - weight: 9 + weight: 8 region: content settings: progress_indicator: throbber third_party_settings: { } field_document_language: type: options_select - weight: 7 + weight: 6 region: content settings: { } third_party_settings: { } field_document_text: type: string_textarea - weight: 10 + weight: 9 region: content settings: rows: 5 @@ -81,19 +74,19 @@ content: third_party_settings: { } field_number_of_paragraphs: type: options_select - weight: 6 + weight: 5 region: content settings: { } third_party_settings: { } field_output_language: type: options_select - weight: 8 + weight: 7 region: content settings: { } third_party_settings: { } field_summary: type: string_textarea - weight: 11 + weight: 10 region: content settings: rows: 5 @@ -108,13 +101,13 @@ content: third_party_settings: { } moderation_state: type: moderation_state_default - weight: 12 + weight: 11 region: content settings: { } third_party_settings: { } path: type: path - weight: 13 + weight: 12 region: content settings: { } third_party_settings: { } @@ -126,7 +119,7 @@ content: third_party_settings: { } status: type: boolean_checkbox - weight: 15 + weight: 14 region: content settings: display_label: true @@ -141,7 +134,7 @@ content: third_party_settings: { } uid: type: entity_reference_autocomplete - weight: 17 + weight: 16 region: content settings: match_operator: CONTAINS @@ -150,10 +143,11 @@ content: placeholder: '' third_party_settings: { } url_redirects: - weight: 14 + weight: 13 region: content settings: { } third_party_settings: { } hidden: + field_automatic_mode: true promote: true sticky: true diff --git a/config/filter.format.text_editor_simple.yml b/config/filter.format.text_editor_simple.yml index 22c2519..43810b2 100644 --- a/config/filter.format.text_editor_simple.yml +++ b/config/filter.format.text_editor_simple.yml @@ -6,6 +6,12 @@ name: 'Text Editor - Simple' format: text_editor_simple weight: 0 filters: + filter_autop: + id: filter_autop + provider: filter + status: true + weight: 0 + settings: { } filter_url: id: filter_url provider: filter diff --git a/config/views.view.my_documents.yml b/config/views.view.my_documents.yml index 4f868d1..cbef873 100644 --- a/config/views.view.my_documents.yml +++ b/config/views.view.my_documents.yml @@ -449,7 +449,7 @@ display: plugin_id: text empty: false content: - value: 'Welcome to OCHA’s private AI-based document summarization tool. You can upload documents written in any of the 6 UN languages and receive output in any of those languages. Since this is a proof-of-concept that is powered by AI, please check for mistakes.' + value: 'Welcome to OCHA’s private AI-based document summarization tool. You can upload documents written in any of the 6 UN languages and receive output in any of those languages. Since this is a proof-of-concept that is powered by AI, please check for mistakes.
' format: text_editor_simple tokenize: false footer: { } diff --git a/html/modules/custom/ocha_ai_summarize/ocha_ai_summarize.module b/html/modules/custom/ocha_ai_summarize/ocha_ai_summarize.module index d776b6f..0df9cfa 100644 --- a/html/modules/custom/ocha_ai_summarize/ocha_ai_summarize.module +++ b/html/modules/custom/ocha_ai_summarize/ocha_ai_summarize.module @@ -35,6 +35,8 @@ use Symfony\Component\Process\Process; function ocha_ai_summarize_node_insert(EntityInterface $entity) { ocha_ai_summarize_node_update($entity); + \Drupal::messenger()->addMessage(t("Your document has been queued for processing and will be ready in 10 to 15 minutes, you'll receive an email when it's ready.")); + // Auto create other nodes? /** @var \Drupal\node\Entity\Node $entity */ if (!$entity->hasField('field_auto_create')) { From a0e484bbafb6600887ec105f67f23ee6688293ba Mon Sep 17 00:00:00 2001 From: "Peter Droogmans (attiks)" Date: Fri, 5 Apr 2024 11:38:25 +0200 Subject: [PATCH 2/2] Display state --- .../ocha_ai_summarize.module | 48 +++++++++++++++++++ .../common_design_subtheme/css/styles.css | 8 ++++ 2 files changed, 56 insertions(+) diff --git a/html/modules/custom/ocha_ai_summarize/ocha_ai_summarize.module b/html/modules/custom/ocha_ai_summarize/ocha_ai_summarize.module index 0df9cfa..9026ad3 100644 --- a/html/modules/custom/ocha_ai_summarize/ocha_ai_summarize.module +++ b/html/modules/custom/ocha_ai_summarize/ocha_ai_summarize.module @@ -396,16 +396,64 @@ function ocha_ai_summarize_node_view(array &$build, EntityInterface $entity, Ent /** @var \Drupal\node\Entity\Node $entity */ switch ($entity->bundle()) { case 'summary': + ocha_ai_summarize_node_view_moderation_state($build, $entity, $display, $view_mode); ocha_ai_summarize_node_view_compare($build, $entity, $display, $view_mode); break; case 'action_points': + ocha_ai_summarize_node_view_moderation_state($build, $entity, $display, $view_mode); ocha_ai_summarize_node_view_action_points_compare($build, $entity, $display, $view_mode); break; } } +/** + * Implements hook_ENTITY_TYPE_view(). + */ +function ocha_ai_summarize_node_view_moderation_state(array &$build, EntityInterface $entity, EntityViewDisplayInterface $display, $view_mode) { + /** @var \Drupal\node\Entity\Node $entity */ + if ($entity->bundle() !== 'summary' && $entity->bundle() !== 'action_points') { + return; + } + + if ($entity->isPublished()) { + return; + } + + $content_moderation_state = ContentModerationState::loadFromModeratedEntity($entity); + if (!$content_moderation_state) { + $state = 'document_uploaded'; + } + else { + $state = $content_moderation_state->get('moderation_state')->value; + } + + // Do not display when in final state. + if ($state == 'summarized' || $state == 'action_points_created') { + return; + } + + /** @var \Drupal\content_moderation\ModerationInformation $moderation_information_service */ + $moderation_information_service = \Drupal::service('content_moderation.moderation_information'); + $workflow = $moderation_information_service->getWorkflowForEntity($entity); + $label = $workflow->getTypePlugin()->getState($state)->label(); + + $build['moderation_state'] = [ + '#type' => 'markup', + '#markup' => $label, + '#prefix' => '
' . t('Status') . '
', + '#suffix' => '
', + '#attributes' => [ + 'class' => [ + 'cd-button', + ], + ], + '#weight' => -100, + ]; + +} + /** * Implements hook_ENTITY_TYPE_view(). */ diff --git a/html/themes/custom/common_design_subtheme/css/styles.css b/html/themes/custom/common_design_subtheme/css/styles.css index f8c533e..4fc0c5d 100644 --- a/html/themes/custom/common_design_subtheme/css/styles.css +++ b/html/themes/custom/common_design_subtheme/css/styles.css @@ -67,3 +67,11 @@ ol.workflow-steps > li.to-do { .comment-form-feedback { margin-top: 2rem; } + +.field--label-inline .field__label { + padding-right: .3rem; +} + +.field--label-inline .field__label:after { + content: ':'; +}