Skip to content

Commit 292b490

Browse files
authored
Merge pull request #684 from favicode/fix/real-time-logging-v2
Real-Time Log streaming fix #682
2 parents ce32d82 + 738d768 commit 292b490

File tree

3 files changed

+34
-22
lines changed

3 files changed

+34
-22
lines changed

Controller/Adminhtml/FastlyCdn/Logging/CreateEndpoint.php

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,11 @@
2929
use Magento\Framework\Controller\Result\JsonFactory;
3030

3131
/**
32-
* Class CreateEndpoint
33-
* @package Fastly\Cdn\Controller\Adminhtml\FastlyCdn\Logging
32+
* Class CreateEndpoint for Logging
3433
*/
3534
class CreateEndpoint extends Action
3635
{
37-
const ADMIN_RESOURCE = 'Magento_Config::config';
36+
public const ADMIN_RESOURCE = 'Magento_Config::config';
3837

3938
/**
4039
* @var Http
@@ -113,6 +112,11 @@ public function execute()
113112
$this->getRequest()->getParam('condition_priority')
114113
);
115114

115+
$selectedConditions = $this->getRequest()->getParam('conditions', '');
116+
if (!$condition) {
117+
$condition = $selectedConditions;
118+
}
119+
116120
$params = array_merge(
117121
$this->getRequest()->getParam('log_endpoint'),
118122
['response_condition' => $condition]
@@ -152,17 +156,18 @@ public function execute()
152156
}
153157

154158
/**
159+
*
155160
* @param $clone
156161
* @param $conditionName
157162
* @param $applyIf
158163
* @param $conditionPriority
159-
* @return string|null
164+
* @return string
160165
* @throws \Magento\Framework\Exception\LocalizedException
161166
*/
162167
private function createCondition($clone, $conditionName, $applyIf, $conditionPriority)
163168
{
164169
if (!$conditionName || !$applyIf || !$conditionPriority) {
165-
return null;
170+
return '';
166171
}
167172
$condition = [
168173
'name' => $conditionName,

Controller/Adminhtml/FastlyCdn/Logging/UpdateEndpoint.php

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,11 @@
2929
use Magento\Framework\Controller\Result\JsonFactory;
3030

3131
/**
32-
* Class UpdateEndpoint
33-
* @package Fastly\Cdn\Controller\Adminhtml\FastlyCdn\Logging
32+
* Class UpdateEndpoint for Logging
3433
*/
3534
class UpdateEndpoint extends Action
3635
{
37-
const ADMIN_RESOURCE = 'Magento_Config::config';
36+
public const ADMIN_RESOURCE = 'Magento_Config::config';
3837

3938
/**
4039
* @var Http
@@ -84,6 +83,7 @@ public function __construct(
8483
}
8584

8685
/**
86+
*
8787
* @return \Magento\Framework\App\ResponseInterface|\Magento\Framework\Controller\Result\Json|\Magento\Framework\Controller\ResultInterface
8888
*/
8989
public function execute()
@@ -114,14 +114,15 @@ public function execute()
114114
$this->getRequest()->getParam('condition_priority')
115115
);
116116

117-
$params = array_merge(
118-
$this->getRequest()->getParam('log_endpoint'),
119-
['response_condition' => $condition]
120-
);
121-
117+
$selectedConditions = $this->getRequest()->getParam('conditions', '');
118+
if (!$condition) {
119+
$condition = $selectedConditions;
120+
}
121+
$params = $this->getRequest()->getParam('log_endpoint');
122122
$params = array_filter($params);
123-
//Array filter removes empty strings, but empty compression_codec param turns off compression formats
124-
if (!isset($params['compression_codec'])){
123+
$params['response_condition'] = $condition;
124+
125+
if (!isset($params['compression_codec'])) {
125126
$params['compression_codec'] = "";
126127
}
127128
$endpoint = $this->api->updateLogEndpoint($clone->number, $endpointType, $params, $oldName);
@@ -157,17 +158,18 @@ public function execute()
157158
}
158159

159160
/**
161+
*
160162
* @param $clone
161163
* @param $conditionName
162164
* @param $applyIf
163165
* @param $conditionPriority
164-
* @return string|null
166+
* @return string
165167
* @throws \Magento\Framework\Exception\LocalizedException
166168
*/
167169
private function createCondition($clone, $conditionName, $applyIf, $conditionPriority)
168170
{
169171
if (!$conditionName || !$applyIf || !$conditionPriority) {
170-
return null;
172+
return '';
171173
}
172174
$condition = [
173175
'name' => $conditionName,

view/adminhtml/web/js/log-endpoints.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,14 +96,20 @@ define([
9696
$('#condition_priority').val('');
9797
return getResponseConditions(active_version, loaderVisibility)
9898
.done(function (response) {
99-
let html = '';
10099
$('#attach_span').hide();
101100
if (response !== false) {
101+
let conditionElement = document.getElementById('conditions');
102102
conditions = response.conditions;
103-
html += '<option value="">no condition</option>';
103+
let option = document.createElement("option");
104+
option.text = 'no condition';
105+
option.value = '';
106+
conditionElement.add(option);
104107
$.each(conditions, function (index, condition) {
105-
if (condition.type === "REQUEST") {
106-
html += '<option value="'+_.escape(condition.name)+'">'+_.escape(condition.name)+' ('+condition.type+') '+_.escape(condition.statement)+'</option>';
108+
if (condition.type === "RESPONSE") {
109+
let option = document.createElement("option");
110+
option.text = _.escape(condition.name) +' ('+condition.type+') ' + _.escape(condition.statement);
111+
option.value = _.escape(condition.name);
112+
conditionElement.add(option);
107113
}
108114
});
109115
}
@@ -112,7 +118,6 @@ define([
112118
$('#detach').show();
113119
$('#create-response-condition').show();
114120
$('#sep').show();
115-
$('#conditions').html(html);
116121
})
117122
}
118123

0 commit comments

Comments
 (0)