Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add comments on a rule #997 #1001

Merged
merged 12 commits into from
Apr 24, 2023
2 changes: 1 addition & 1 deletion .env
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
MYDDLEWARE_VERSION=3.3.1d
MYDDLEWARE_VERSION=3.3.1e

APP_SECRET=Thissecretisnotsosecretchangeit
APP_ENV=prod
Expand Down
39 changes: 39 additions & 0 deletions assets/js/fiche.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,45 @@ $(function() {
});
});

// --For 'description' in the detail view of the rule
$('.edit-button').on('click', function() {
var field = $(this).parent();
var editForm = field.find('.edit-form');
var valueField = field.find('.value');
var newValueField = editForm.find('textarea');
var saveButton = editForm.find('button[type="submit"]');
// Retrieve the identifier of the rule
var ruleId = editForm.find('input[name="ruleId"]').val();

valueField.hide();
editForm.show();
newValueField.val(valueField.text().trim());

saveButton.on('click', function(event) {
event.preventDefault();

var newValue = newValueField.val().trim();
var updateUrl = editForm.attr('action');

$.ajax({
type: 'POST',
url: updateUrl,
data: {
ruleId: ruleId,
description: newValue
},
success: function(response) {
valueField.text(newValue);
valueField.show();
editForm.hide();
},
error: function(error) {
console.log(error);
}
});
});
});

// Récupère la liste des params
function recup_params() {
var params = [];
Expand Down
34 changes: 34 additions & 0 deletions src/Controller/DefaultController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2937,4 +2937,38 @@ public function execRuleById($id, Request $request)
'formIdBatch' => $form->createView()
]);
}

/**
* @Route("/rule/update_description", name="update_rule_description", methods={"POST"})
*/
public function updateDescription(Request $request): Response
{
$ruleId = $request->request->get('ruleId');
$description = $request->request->get('description');
$entityManager = $this->getDoctrine()->getManager();

// Retrieve the RuleParam entity using the ruleId
$rule = $entityManager->getRepository(RuleParam::class)->findOneBy(['rule' => $ruleId]);

if (!$rule) {
throw $this->createNotFoundException('Couldn\'t find specified rule in database');
}

// Retrieve the RuleParam with the name "description" and the same rule as the previously retrieved entity
$descriptionRuleParam = $entityManager->getRepository(RuleParam::class)->findOneBy([
'rule' => $rule->getRule(),
'name' => 'description'
]);

// Check if the description entity was found
if (!$descriptionRuleParam) {
throw $this->createNotFoundException('Couldn\'t find description rule parameter');
}

// Update the value of the description
$descriptionRuleParam->setValue($description);
$entityManager->flush();

return new Response('', Response::HTTP_OK);
}
}
24 changes: 19 additions & 5 deletions src/Manager/DocumentManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ class documentcore
protected $jobId;
protected $key;
protected $docIdRefError;
protected $env;
protected bool $transformError = false;
protected ?ToolsManager $tools;
protected $api; // Specify if the class is called by the API
Expand Down Expand Up @@ -122,6 +123,7 @@ public function __construct(
$this->tools = $tools;
$this->formulaManager = $formulaManager;
$this->solutionManager = $solutionManager;
$this->env = $_SERVER['APP_ENV'];
}

public static function lstGblStatus(): array
Expand Down Expand Up @@ -361,8 +363,12 @@ public function filterDocument($ruleFilters)
}
try {
$filterOK = true;
// Si des filtres sont présents
if (!empty($ruleFilters)) {
// Only if there is a least one filter
// No filter on delete document as they will be filter after is Myddleware never sent the data
if (
!empty($ruleFilters)
AND $this->documentType != 'D'
) {
// Boucle sur les filtres
foreach ($ruleFilters as $ruleFilter) {
if (!$this->checkFilter($this->sourceData[$ruleFilter['target']], $ruleFilter['type'], $ruleFilter['value'])) {
Expand Down Expand Up @@ -689,7 +695,7 @@ public function checkPredecessorDocument(): bool
return true;
} catch (\Exception $e) {
// Reference document id is used to show which document is blocking the current document in Myddleware
$this->docIdRefError = (is_array($result) and !empty($result['id']) ? $result['id'] : '');
$this->docIdRefError = ((is_array($result) and !empty($result['id'])) ? $result['id'] : '');
$this->message .= 'Failed to check document predecessor : '.$e->getMessage().' '.$e->getFile().' Line : ( '.$e->getLine().' )';
$this->typeError = 'E';
$this->updateStatus('Predecessor_KO');
Expand Down Expand Up @@ -1922,7 +1928,11 @@ public function updateStatus($new_status)
WHERE
id = :id
';
if (!$this->api) {
// We don't send output for the API and Myddleware UI
if (
!$this->api
AND $this->env != 'prod'
) {
echo 'status '.$new_status.' id = '.$this->id.' '.$now.chr(10);
}
// Suppression de la dernière virgule
Expand Down Expand Up @@ -1962,7 +1972,11 @@ public function updateDeleteFlag($deleted)
WHERE
id = :id
';
if (!$this->api) {
// We don't send output for the API and Myddleware UI
if (
!$this->api
AND $this->env != 'prod'
) {
echo(!empty($deleted) ? 'Remove' : 'Restore').' document id = '.$this->id.' '.$now.chr(10);
}
$stmt = $this->connection->prepare($query);
Expand Down
8 changes: 5 additions & 3 deletions src/Manager/FormulaFunctionManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,22 +81,24 @@ public static function changeFormatDate($dateToChange, $oldFormat, $newFormat)
public static function changeValue($var, $arrayKeyToValue, $acceptNull = null)
{
// Transform string into an array
$arrayKeyToValue = json_decode(str_replace(['(', ')', '\''], ['{', '}', '"'], $arrayKeyToValue), true);
// Change first and last characters (parentheses) by accolades
// Replace ' before and after , and : by "
$arrayKeyToValue = json_decode('{"'.str_replace([ ':\'', '\':', ',\'', '\','], [ ':"', '":', ',"', '",'], substr($arrayKeyToValue,2,-2)).'"}', true);
if (in_array($var, array_keys($arrayKeyToValue))) {
return $arrayKeyToValue[$var];
}
if (!empty($acceptNull)) {
return '';
}
}

public static function changeMultiValue($var, $arrayKeyToValue, $delimiter)
{
// Transform $var into array
$return = '';
$arrayVar = explode($delimiter, $var);
if (!empty($arrayVar)) {
$arrayKeyToValue = json_decode(str_replace(['(', ')', '\''], ['{', '}', '"'], $arrayKeyToValue), true);
$arrayKeyToValue = json_decode('{"'.str_replace([ ':\'', '\':', ',\'', '\','], [ ':"', '":', ',"', '",'], substr($arrayKeyToValue,2,-2)).'"}', true);
foreach ($arrayVar as $varValue) {
// Transform string into an array
if (!empty($arrayKeyToValue[$varValue])) {
Expand Down
3 changes: 3 additions & 0 deletions src/Manager/JobManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,7 @@ public function runError($limit, $attempt)
foreach ($documentsError as $documentError) {
$this->ruleManager->setRule($documentError['rule_id']);
$this->ruleManager->setJobId($this->id);
$this->ruleManager->setManual($this->manual);
$this->ruleManager->setApi($this->api);
$errorActionDocument = $this->ruleManager->actionDocument($documentError['id'], 'rerun');
if (!empty($errorActionDocument)) {
Expand Down Expand Up @@ -501,6 +502,7 @@ public function massAction($action, $dataType, $ids, $forceAll, $fromStatus, $to
if ($param['ruleId'] != $document['rule_id']) {
$this->ruleManager->setApi($this->api);
$this->ruleManager->setJobId($this->id);
$this->ruleManager->setManual($this->manual);
$this->ruleManager->setRule($document['rule_id']);
}
$this->ruleManager->actionDocument($document['id'], $action, $toStatus);
Expand Down Expand Up @@ -544,6 +546,7 @@ public function readRecord($ruleId, $filterQuery, $filterValues, $usesDocumentId
// We instanciate the rule
$this->ruleManager->setRule($ruleId);
$this->ruleManager->setJobId($this->id);
$this->ruleManager->setManual($this->manual);
$this->ruleManager->setApi($this->api);

// We create an array that will match the initial structure of the function
Expand Down
2 changes: 1 addition & 1 deletion src/Manager/RuleManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,7 @@ protected function validateReadDataSource()

// Order data in the date_modified order
$modified = array_column($dataSourceValues, 'date_modified');
array_multisort($modified, SORT_ASC, $dataSourceValues);
array_multisort($modified, SORT_DESC, $dataSourceValues);
foreach ($dataSourceValues as $value) {
// Check if the previous record has the same date_modified than the current record
// Check only if offset isn't managed into the source application connector
Expand Down
4 changes: 2 additions & 2 deletions templates/Flux/view/view.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@
<th>{{'list_flux.tab.name'|trans}}</th>
<th>{{'list_flux.tab.source_id'|trans}}</th>
<th>{{'list_flux.tab.target_id'|trans}}</th>
<th>{{'list_flux.tab.date_modified'|trans}}</th>
<th>{{'list_flux.tab.dateref'|trans}}</th>
<th>{{'list_flux.tab.type'|trans}}</th>
<th>{{'list_flux.tab.statut'|trans}}</th>
</tr>
Expand All @@ -363,7 +363,7 @@
</td>
<td class="ctr">{{ flux.source }}</td>
<td class="ctr">{{ flux.target }}</td>
<td class="ctr">{{ flux.dateModified|date("d/m/Y H:i:s", timezone) }}</td>
<td class="ctr">{{ flux.sourceDateModified|date("d/m/Y H:i:s", timezone) }}</td>
<td class="ctr">{{ flux.type }}</td>
<td class="ctr">
<div class="gblstatus_{{ flux.globalStatus|lower }}">{{ flux.status }}
Expand Down
15 changes: 15 additions & 0 deletions templates/Rule/edit/onglets/infos.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,21 @@
{% endfor %}
{% endif %}
</table>
{% for param in rule.params %}
{% if param.name == 'description' %}
<div class="description-field">
<p class="title">{{ 'solution.params.description' | trans }}</p>
<div class="value">{{ param.value }}</div>
<button class="edit-button btn btn-dark">{{ 'Edit' | trans }}</button>
<form class="edit-form" style="display:none;" action="{{ path('update_rule_description') }}" method="post">
<textarea name="description" class="form-control m-2" data-rule-id="{{ rule.id }}">{{ param.value }}</textarea>
<input type="hidden" name="ruleId" value="{{ rule.id }}" />
<button type="submit" class="edit-button btn btn-success m-2">{{ 'Save' | trans }}</button>
</form>
</div>
{% endif %}
{% endfor %}

</div>
<div class="col">
<table id="tab_connector" class="table table-striped table-sm">
Expand Down