Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
iglocska committed Feb 21, 2023
2 parents 648291b + 9bc1ba8 commit a7dca82
Show file tree
Hide file tree
Showing 114 changed files with 5,238 additions and 2,374 deletions.
2 changes: 1 addition & 1 deletion INSTALL/cerebrate_nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ server {
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php/php-fpm.sock;
fastcgi_pass unix:/var/run/php/php8.1-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
Expand Down
160 changes: 160 additions & 0 deletions config/Migrations/20221130000000_MoreDataOnMetaFields.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
<?php
declare(strict_types=1);

use Migrations\AbstractMigration;
use Phinx\Db\Adapter\MysqlAdapter;

final class MoreDataOnMetaFields extends AbstractMigration
{
public $autoId = false; // turn off automatic `id` column create. We want it to be `int(10) unsigned`

/**
* Change Method.
*
* Write your reversible migrations using this method.
*
* More information on writing migrations is available here:
* https://book.cakephp.org/phinx/0/en/migrations.html#the-change-method
*
* Remember to call "create()" or "update()" and NOT "save()" when working
* with the Table class.
*/
public function change(): void
{
$metaFieldTable = $this->table('meta_fields');
if (!$metaFieldTable->hasColumn('meta_template_directory_id')) {
$metaFieldTable
->addColumn('meta_template_directory_id', 'integer', [
'default' => null,
'null' => false,
'signed' => false,
'length' => 10
])
->addIndex('meta_template_directory_id')
->update();
}

$exists = $this->hasTable('meta_template_name_directory');
if (!$exists) {
$templateNameDirectoryTable = $this->table('meta_template_name_directory', [
'signed' => false,
'collation' => 'utf8mb4_unicode_ci'
]);
$templateNameDirectoryTable
->addColumn('id', 'integer', [
'autoIncrement' => true,
'limit' => 10,
'signed' => false,
])
->addPrimaryKey('id')
->addColumn('name', 'string', [
'null' => false,
'limit' => 191,
'collation' => 'utf8mb4_unicode_ci',
'encoding' => 'utf8mb4',
])
->addColumn('namespace', 'string', [
'null' => false,
'limit' => 191,
'collation' => 'utf8mb4_unicode_ci',
'encoding' => 'utf8mb4',
])
->addColumn('version', 'string', [
'null' => false,
'limit' => 191,
'collation' => 'utf8mb4_unicode_ci',
'encoding' => 'utf8mb4',
])
->addColumn('uuid', 'uuid', [
'null' => false,
'default' => null,
]);

$templateNameDirectoryTable
->addIndex(['uuid', 'version'], ['unique' => true])
->addIndex('name')
->addIndex('namespace');

$templateNameDirectoryTable->create();

$allTemplates = $this->getAllTemplates();
$this->populateTemplateDirectoryTable($allTemplates);

$metaTemplateTable = $this->table('meta_templates');
$metaTemplateTable
->addColumn('meta_template_directory_id', 'integer', [
'default' => null,
'null' => false,
'signed' => false,
'length' => 10
])
->update();
$this->assignTemplateDirectory($allTemplates);
$metaTemplateTable
->addForeignKey('meta_template_directory_id', 'meta_template_name_directory', 'id', ['delete' => 'CASCADE', 'update' => 'CASCADE'])
->save();

$metaFieldTable
->dropForeignKey('meta_template_id')
->dropForeignKey('meta_template_field_id')
->addForeignKey('meta_template_directory_id', 'meta_template_name_directory', 'id', ['delete' => 'CASCADE', 'update' => 'CASCADE'])
->save();
}
}

private function populateTemplateDirectoryTable(array $allTemplates): void
{
$builder = $this->getQueryBuilder()
->insert(['uuid', 'name', 'namespace', 'version'])
->into('meta_template_name_directory');

if (!empty($allTemplates)) {
foreach ($allTemplates as $template) {
$builder->values([
'uuid' => $template['uuid'],
'name' => $template['name'],
'namespace' => $template['namespace'],
'version' => $template['version'],
]);
}
$builder->execute();
}
}

private function assignTemplateDirectory(array $allTemplates): void
{
foreach ($allTemplates as $template) {
$directory_template = $this->getDirectoryTemplate($template['uuid'], $template['version'])[0];
$this->getQueryBuilder()
->update('meta_templates')
->set('meta_template_directory_id', $directory_template['id'])
->where(['meta_template_id' => $template['id']])
->execute();
$this->getQueryBuilder()
->update('meta_fields')
->set('meta_template_directory_id', $directory_template['id'])
->where(['id' => $template['id']])
->execute();
}
}

private function getAllTemplates(): array
{
return $this->getQueryBuilder()
->select(['id', 'uuid', 'name', 'namespace', 'version'])
->from('meta_templates')
->execute()->fetchAll('assoc');
}

private function getDirectoryTemplate(string $uuid, string $version): array
{
return $this->getQueryBuilder()
->select(['id', 'uuid', 'version'])
->from('meta_template_name_directory')
->where([
'uuid' => $uuid,
'version' => $version,
])
->execute()->fetchAll('assoc');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,28 +50,28 @@

$table = $this->Bootstrap->table(['small' => true, 'bordered' => false, 'striped' => false, 'hover' => false], [
'fields' => [
['key' => 'created', 'label' => __('Date'), 'formatter' => function($value, $row) {
['path' => 'created', 'label' => __('Date'), 'formatter' => function($value, $row) {
return $value->i18nFormat('yyyy-MM-dd HH:mm:ss');
}],
['key' => 'connector', 'label' => __('Tool Name'), 'formatter' => function($connector, $row) {
['path' => 'connector', 'label' => __('Tool Name'), 'formatter' => function($connector, $row) {
return sprintf('<a href="%s" target="_blank">%s</a>',
$this->Url->build(['controller' => 'localTools', 'action' => 'viewConnector', $connector['name']]),
sprintf('%s (v%s)', h($connector['name']), h($connector['connector_version']))
);
}],
['key' => 'brood', 'label' => __('Brood'), 'formatter' => function($brood, $row) {
['path' => 'brood', 'label' => __('Brood'), 'formatter' => function($brood, $row) {
return sprintf('<a href="%s" target="_blank">%s</a>',
$this->Url->build(['controller' => 'broods', 'action' => 'view', $brood['id']]),
h($brood['name'])
);
}],
['key' => 'individual', 'label' => __('Individual'), 'formatter' => function($individual, $row) {
['path' => 'individual', 'label' => __('Individual'), 'formatter' => function($individual, $row) {
return sprintf('<a href="%s" target="_blank">%s</a>',
$this->Url->build(['controller' => 'users', 'action' => 'view', $individual['id']]),
h($individual['email'])
);
}],
['key' => 'individual.alignments', 'label' => __('Alignment'), 'formatter' => function($alignments, $row) {
['path' => 'individual.alignments', 'label' => __('Alignment'), 'formatter' => function($alignments, $row) {
$html = '';
foreach ($alignments as $alignment) {
$html .= sprintf('<div class="text-nowrap"><b>%s</b> @ <a href="%s" target="_blank">%s</a></div>',
Expand Down Expand Up @@ -101,7 +101,7 @@

$requestData = $this->Bootstrap->collapse(
[
'title' => __('Inter-connection data'),
'text' => __('Inter-connection data'),
'open' => true,
],
sprintf('<pre class="p-2 rounded mb-0" style="background: #eeeeee55;"><code>%s</code></pre>', json_encode($request['data'], JSON_PRETTY_PRINT))
Expand Down
133 changes: 115 additions & 18 deletions libraries/default/InboxProcessors/templates/Notification/DataChange.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<?php
$randomIdOld = Cake\Utility\Security::randomString(8);
$randomIdNew = Cake\Utility\Security::randomString(8);

if (!empty($data['summary'])) {
$changedSummary = h($data['summary']);
} else if (!empty($data['summaryTemplate']) && !empty($data['summaryMessage'])) {
Expand Down Expand Up @@ -28,32 +31,126 @@
]
]);

$properties = array_unique(array_merge(array_keys($data['original']), array_keys($data['changed'])));
$tableData = [];
foreach ($properties as $i => $property) {
$tableData[] = [
$property,
$data['original'][$property] ?? '',
$data['changed'][$property] ?? '',
];
}
$emptyValueHTML = $this->Bootstrap->node('span', ['class' => ['text-muted', 'fw-light', 'fst-italic']], __('- empty -'));

$diffTable = $this->Bootstrap->table(
[
'hover' => false,
'striped' => false,
'bordered' => false,
],
[
'items' => $tableData,
'fields' => [
[
'label' => __('Property name'),
'formatter' => function ($field, $row) {
return $this->Bootstrap->node('pre', [], h($field));
}
],
[
'label' => __('Old value'),
'formatter' => function ($field, $row) use ($randomIdOld, $emptyValueHTML) {
$fieldText = is_array($field) ? json_encode($field, JSON_FORCE_OBJECT | JSON_PRETTY_PRINT) : $field;
$config = [
'text' => $fieldText,
'variant' => 'danger',
'dismissible' => false,
'class' => ['p-2', 'mb-0', !empty($fieldText) && is_array($field) ? "json_container_{$randomIdOld}" : ''],
];
if (empty($fieldText)) {
$config['html'] = $emptyValueHTML;
} else {
$config['text'] = $fieldText;
}
return $this->Bootstrap->alert($config);
}
],
[
'label' => __('New value'),
'formatter' => function ($field, $row) use ($randomIdNew, $emptyValueHTML) {
$fieldText = is_array($field) ? json_encode($field, JSON_FORCE_OBJECT | JSON_PRETTY_PRINT) : $field;
$config = [
'text' => $fieldText,
'variant' => 'success',
'dismissible' => false,
'class' => ['p-2', 'mb-0', !empty($fieldText) && is_array($field) ? "json_container_{$randomIdNew}" : ''],
];
if (empty($fieldText)) {
$config['html'] = $emptyValueHTML;
} else {
$config['text'] = $fieldText;
}
return $this->Bootstrap->alert($config);
}
],
],
]
);


$cards = sprintf(
'<div class="container">
<div class="row">
<div class="col">%s</div>
<div class="col">%s</div>
</div>
</div>',
$this->Bootstrap->card([
'headerText' => __('Original values'),
'bodyHTML' => $this->element('genericElements/SingleViews/Fields/jsonField', ['field' => ['raw' => $data['original']]])
]),
$this->Bootstrap->card([
'headerText' => __('Changed values'),
'bodyHTML' => $this->element('genericElements/SingleViews/Fields/jsonField', ['field' => ['raw' => $data['changed']]])
])
);

$collapse = $this->Bootstrap->collapse([
'button' => [
'text' => __('Show raw changes'),
'variant' => 'link',
],
'card' => false
], $cards);

echo $this->Bootstrap->modal([
'title' => __('Acknowledge notification'),
'size' => 'xl',
'type' => 'confirm',
'bodyHtml' => sprintf(
'<div class="d-none">%s</div>
<div class="container">
<div class="row">
<p>%s</p>
<div class="col">%s</div>
<div class="col">%s</div>
</div>
</div>',
'<div class="d-none">%s</div><p>%s</p>%s%s',
$form,
$changedSummary,
$this->Bootstrap->card([
'headerText' => __('Original values'),
'bodyHTML' => $this->element('genericElements/SingleViews/Fields/jsonField', ['field' => ['raw' => $data['original']]])
]),
$this->Bootstrap->card([
'headerText' => __('Changed values'),
'bodyHTML' => $this->element('genericElements/SingleViews/Fields/jsonField', ['field' => ['raw' => $data['changed']]])
])
$diffTable,
$collapse
),
'confirmText' => __('Acknowledge & Discard'),
'confirmIcon' => 'check',
'confirmButton' => [
'text' => __('Acknowledge & Discard'),
'icon' => 'check',
]
]);
?>
</div>

<script type="text/javascript">
$(document).ready(function() {
const $containerOld = $('.json_container_<?= $randomIdOld; ?>')
const $containerNew = $('.json_container_<?= $randomIdNew; ?>')
if ($containerOld.length == 1) {
$containerOld.html(syntaxHighlightJson($containerOld.text()));
}
if ($containerNew.length == 1) {
$containerNew.html(syntaxHighlightJson($containerNew.text()));
}
});
</script>
Loading

0 comments on commit a7dca82

Please sign in to comment.