Skip to content

Commit

Permalink
feat: Compare action points
Browse files Browse the repository at this point in the history
  • Loading branch information
attiks committed Nov 7, 2023
1 parent f452bab commit db07c19
Show file tree
Hide file tree
Showing 8 changed files with 108 additions and 20 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ $config['ocha_ai_summarize.settings']['claude_api_key'] = 'zz';
## Cron

```bash
drush queue:process ocha_ai_summarize_extract_text
drush queue:process ocha_ai_summarize_summarize
drush queue:process ocha_ai_summarize_action_points
drush queue:process ocha_ai_summarize_extract_text --verbose
drush queue:process ocha_ai_summarize_summarize --verbose
drush queue:process ocha_ai_summarize_action_points --verbose
```

We can either use cron to run the queues or run them separatly
Expand Down
42 changes: 29 additions & 13 deletions config/core.entity_form_display.node.action_points.default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,17 @@ dependencies:
config:
- field.field.node.action_points.field_action_points
- field.field.node.action_points.field_ai_brain
- field.field.node.action_points.field_auto_create
- field.field.node.action_points.field_automatic_mode
- field.field.node.action_points.field_document
- field.field.node.action_points.field_document_text
- node.type.action_points
- workflows.workflow.action_points
module:
- content_moderation
- file
- path
- private_content
- text
id: node.action_points.default
targetEntityType: node
Expand All @@ -21,41 +24,48 @@ mode: default
content:
created:
type: datetime_timestamp
weight: 8
weight: 10
region: content
settings: { }
third_party_settings: { }
field_action_points:
type: text_textarea
weight: 7
weight: 9
region: content
settings:
rows: 5
placeholder: ''
third_party_settings: { }
field_ai_brain:
type: options_select
weight: 2
weight: 3
region: content
settings: { }
third_party_settings: { }
field_auto_create:
type: boolean_checkbox
weight: 4
region: content
settings:
display_label: true
third_party_settings: { }
field_automatic_mode:
type: boolean_checkbox
weight: 3
weight: 5
region: content
settings:
display_label: true
third_party_settings: { }
field_document:
type: file_generic
weight: 4
weight: 6
region: content
settings:
progress_indicator: throbber
third_party_settings: { }
field_document_text:
type: string_textarea
weight: 6
weight: 8
region: content
settings:
rows: 5
Expand All @@ -70,33 +80,39 @@ content:
third_party_settings: { }
moderation_state:
type: moderation_state_default
weight: 13
weight: 15
region: content
settings: { }
third_party_settings: { }
path:
type: path
weight: 11
weight: 13
region: content
settings: { }
third_party_settings: { }
private:
type: private
weight: 2
region: content
settings: { }
third_party_settings: { }
promote:
type: boolean_checkbox
weight: 9
weight: 11
region: content
settings:
display_label: true
third_party_settings: { }
status:
type: boolean_checkbox
weight: 14
weight: 16
region: content
settings:
display_label: true
third_party_settings: { }
sticky:
type: boolean_checkbox
weight: 10
weight: 12
region: content
settings:
display_label: true
Expand All @@ -111,7 +127,7 @@ content:
third_party_settings: { }
uid:
type: entity_reference_autocomplete
weight: 5
weight: 7
region: content
settings:
match_operator: CONTAINS
Expand All @@ -120,7 +136,7 @@ content:
placeholder: ''
third_party_settings: { }
url_redirects:
weight: 12
weight: 14
region: content
settings: { }
third_party_settings: { }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ dependencies:
config:
- field.field.node.action_points.field_action_points
- field.field.node.action_points.field_ai_brain
- field.field.node.action_points.field_auto_create
- field.field.node.action_points.field_automatic_mode
- field.field.node.action_points.field_document
- field.field.node.action_points.field_document_text
Expand Down Expand Up @@ -62,6 +63,7 @@ content:
weight: 5
region: content
hidden:
field_auto_create: true
field_document_text: true
langcode: true
private: true
15 changes: 15 additions & 0 deletions config/core.entity_view_display.node.action_points.teaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,40 @@ dependencies:
- core.entity_view_mode.node.teaser
- field.field.node.action_points.field_action_points
- field.field.node.action_points.field_ai_brain
- field.field.node.action_points.field_auto_create
- field.field.node.action_points.field_automatic_mode
- field.field.node.action_points.field_document
- field.field.node.action_points.field_document_text
- node.type.action_points
module:
- private_content
- user
id: node.action_points.teaser
targetEntityType: node
bundle: action_points
mode: teaser
content:
content_moderation_control:
settings: { }
third_party_settings: { }
weight: -20
region: content
links:
settings: { }
third_party_settings: { }
weight: 100
region: content
private:
type: private
label: above
settings: { }
third_party_settings: { }
weight: 1
region: content
hidden:
field_action_points: true
field_ai_brain: true
field_auto_create: true
field_automatic_mode: true
field_document: true
field_document_text: true
Expand Down
21 changes: 21 additions & 0 deletions config/field.field.node.action_points.field_auto_create.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
uuid: a9a7c299-5c07-4960-ad2d-ab102203acc0
langcode: en
status: true
dependencies:
config:
- field.storage.node.field_auto_create
- node.type.action_points
id: node.action_points.field_auto_create
field_name: field_auto_create
entity_type: node
bundle: action_points
label: "Automatically create for other AI's"
description: "When checked will automatically create the same workflow for the other AI's."
required: false
translatable: false
default_value: { }
default_value_callback: ''
settings:
on_label: 'On'
off_label: 'Off'
field_type: boolean
11 changes: 11 additions & 0 deletions html/modules/custom/ocha_ai_summarize/ocha_ai_summarize.module
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,17 @@ function ocha_ai_summarize_node_view_action_points(array &$build, EntityInterfac
'#items' => array_values($states),
'#weight' => -100,
];

if ($entity->hasField('field_auto_create') && $entity->get('field_auto_create')->value && $active == 'action_points_created') {
$build['compare'] = [
'#type' => 'link',
'#title' => t('Compare action points'),
'#url' => Url::fromRoute('ocha_ai_summarize.compare.action_points', [
'id' => $entity->id(),
]),
'#weight' => 100,
];
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,11 @@ ocha_ai_summarize.compare.summary:
requirements:
_permission: 'ocha_ai_summarize compare summary'
id: ^\d+$
ocha_ai_summarize.compare.action_points:
path: '/node/{id}/compare'
defaults:
_title: 'Action points comparison'
_controller: '\Drupal\ocha_ai_summarize\Controller\CompareSummaryController::compare'
requirements:
_permission: 'ocha_ai_summarize compare summary'
id: ^\d+$
Original file line number Diff line number Diff line change
Expand Up @@ -13,31 +13,46 @@ class CompareSummaryController extends ControllerBase {
* Output comparison.
*/
public function compare($id = NULL) {
/** @var \Drupal\node\Entity\Node $node */
$node = $this->entityTypeManager()
->getStorage('node')
->load($id);

$field_name = 'field_summary';
$caption = $this->t('Summary comparison');
if ($node->bundle() == 'action_points') {
$field_name = 'field_action_points';
$caption = $this->t('Action point comparison');
}

$ais = $node->get('field_ai_brain')->getSettings()['allowed_values'];

/** @var \Drupal\node\Entity\Node $nodes */
$nodes = $this->entityTypeManager()
->getStorage('node')
->loadByProperties([
'type' => 'summary',
'type' => $node->bundle(),
'field_document.target_id' => $node->get('field_document')->target_id,
]);

$headers = [];
$columns = [];
$tags = [];

foreach ($nodes as $node) {
$headers[] = $node->get('field_ai_brain')->value;
$columns[] = $node->get('field_summary')->value;
$headers[] = $ais[$node->get('field_ai_brain')->value];
$columns[] = $node->get($field_name)->value;
$tags = array_merge($tags, $node->getCacheTags());
}

$build = [
'#type' => 'table',
'#caption' => $this->t('Summary comparison'),
'#caption' => $caption,
'#header' => $headers,
'#rows' => [$columns],
'#cache' => [
'tags' => $tags,
],
];

return $build;
Expand Down

0 comments on commit db07c19

Please sign in to comment.