Skip to content

Commit

Permalink
Merge pull request #10 from section-io/ui-modification
Browse files Browse the repository at this point in the history
Ui modifications
  • Loading branch information
ElijahGlover committed Sep 25, 2016
2 parents 46a322b + 65654ad commit 0b91089
Show file tree
Hide file tree
Showing 10 changed files with 483 additions and 140 deletions.
29 changes: 7 additions & 22 deletions Block/Adminhtml/Report/Edit/Tab/Metrics.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,35 +10,30 @@

class Metrics extends Generic implements TabInterface
{
/** @var \Sectionio\Metrics\Model\AccountFactory $accountFactory */
protected $accountFactory;
/** @var \Sectionio\Metrics\Model\ApplicationFactory $applicationFactory */
protected $applicationFactory;
/** @var \Sectionio\Metrics\Helper\Data $helper */
protected $helper;
/** @var \Sectionio\Metrics\Helper\State $helper */
protected $state;

/**
* @param \Magento\Backend\Block\Template\Context $context
* @param \Magento\Framework\Registry $registry
* @param \Magento\Framework\Data\FormFactory $formFactory
* @param \Sectionio\Metrics\Model\AccountFactory $accountFactory
* @param \Sectionio\Metrics\Model\ApplicationFactory $applicationFactory
* @param \Sectionio\Metrics\Helper\Data $helper
* @param \Sectionio\Metrics\Helper\State $state
* @param array $data
*/
public function __construct(
\Magento\Backend\Block\Template\Context $context,
\Magento\Framework\Registry $registry,
\Magento\Framework\Data\FormFactory $formFactory,
\Sectionio\Metrics\Model\AccountFactory $accountFactory,
\Sectionio\Metrics\Model\ApplicationFactory $applicationFactory,
\Sectionio\Metrics\Helper\Data $helper,
\Sectionio\Metrics\Helper\State $state,
array $data = []
) {
parent::__construct($context, $registry, $formFactory, $data);
$this->accountFactory = $accountFactory;
$this->applicationFactory = $applicationFactory;
$this->helper = $helper;
$this->state = $state;
$this->setUseContainer(true);
}

Expand All @@ -61,10 +56,6 @@ protected function _construct()
*/
protected function _prepareForm()
{
/** @var \Sectionio\Metrics\Model\AccountFactory $accountFactory */
$accountFactory = $this->accountFactory->create();
/** @var \Sectionio\Metrics\Model\ApplicationFactory $applicationFactory */
$applicationFactory = $this->applicationFactory->create();
/** @var $count */
$count = 0;
/** @var \Magento\Framework\Data\Form $form */
Expand All @@ -73,15 +64,9 @@ protected function _prepareForm()
);

/** @var int $account_id */
$account_id = $this->accountFactory->create()->getCollection()
->addFieldToFilter('is_active', ['eq' => '1'])
->getFirstItem()
->getData('account_id');
$account_id = $this->state->getAccountId();
/** @var int $application_id */
$application_id = $this->applicationFactory->create()->getCollection()
->addFieldToFilter('is_active', ['eq' => '1'])
->getFirstItem()
->getData('application_id');
$application_id = $this->state->getApplicationId();

/** @var array() $data */
if ($data = $this->helper->getMetrics($account_id, $application_id)) {
Expand Down
121 changes: 95 additions & 26 deletions Block/Adminhtml/Report/Edit/Tab/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,41 +16,50 @@ class Settings extends Generic implements TabInterface
protected $accountFactory;
/** @var \Sectionio\Metrics\Model\ApplicationFactory $applicationFactory */
protected $applicationFactory;
// var \Sectionio\Metrics\Helper\Data $helper
protected $helper;
// var \Sectionio\Metrics\Helper\Status $state
protected $state;
/** @var \Magento\PageCache\Model\Config $pageCacheConfig */
protected $pageCacheConfig;
/** @var \Magento\Backend\Model\UrlInterface $urlBuilder */
protected $urlBuilder;

protected $logger;

/**
* @param \Magento\Backend\Block\Template\Context $context
* @param \Magento\Framework\Registry $registry
* @param \Magento\Framework\Data\FormFactory $formFactory
* @param \Magento\PageCache\Model\Config $pageCacheConfig
* @param \Sectionio\Metrics\Model\SettingsFactory $settingsFactory
* @param \Sectionio\Metrics\Model\AccountFactory $accountFactory
* @param \Sectionio\Metrics\Model\ApplicationFactory $applicationFactory
* @param \Sectionio\Metrics\Helper\Data $helper
* @param \Sectionio\Metrics\Helper\Data $state
* @param \Magento\Backend\Model\UrlInterface $urlBuilder
* @param \Magento\PageCache\Model\Config $pageCacheConfig
* @param array $data
*/
public function __construct(
\Magento\Backend\Block\Template\Context $context,
\Magento\Framework\Registry $registry,
\Magento\Framework\Data\FormFactory $formFactory,
\Magento\PageCache\Model\Config $pageCacheConfig,
\Sectionio\Metrics\Model\SettingsFactory $settingsFactory,
\Sectionio\Metrics\Model\AccountFactory $accountFactory,
\Sectionio\Metrics\Model\ApplicationFactory $applicationFactory,
\Sectionio\Metrics\Helper\Data $helper,
\Sectionio\Metrics\Helper\State $state,
\Magento\Backend\Model\UrlInterface $urlBuilder,
\Magento\PageCache\Model\Config $pageCacheConfig,
array $data = []
) {
parent::__construct($context, $registry, $formFactory, $data);
$this->pageCacheConfig = $pageCacheConfig;
$this->settingsFactory = $settingsFactory;
$this->accountFactory = $accountFactory;
$this->applicationFactory = $applicationFactory;
$this->helper = $helper;
$this->state = $state;
$this->urlBuilder = $urlBuilder;
$this->pageCacheConfig = $pageCacheConfig;
$this->logger = $context->getLogger();
$this->setUseContainer(true);
}
Expand All @@ -64,7 +73,7 @@ protected function _construct()
{
parent::_construct();
$this->setId('edit_defaults');
$this->setTitle(__('Account and Application Settings'));
$this->setTitle(__('Management'));
}

/**
Expand All @@ -82,16 +91,31 @@ protected function _prepareForm()
$applicationFactory = $this->applicationFactory->create();
/** @var \Magento\Framework\Data\Form $form */
$form = $this->_formFactory->create(
['data' => ['id' => 'edit_settings', 'action' => $this->getData('action'), 'method' => 'post']]
['data' => [
'id' => 'edit_settings',
'action' => $this->getData('action'),
'method' => 'post']
]
);

$pageMessages = [];

// if Magento is configured to used FPC instead of Varnish, warn the user to change it
if ($this->pageCacheConfig->getType() != \Magento\PageCache\Model\Config::VARNISH) {
$cacheUrl = $this->urlBuilder->getUrl('adminhtml/system_config/edit/section/system');
$pageMessages[] = [
'type' => 'error',
'message' => 'Magento is configured to use the built-in Full Page Cache not Varnish. To use section.io\'s caching you need to change this option to "Varnish Cache" under the Full Page Cache settings in <a href="' . $cacheUrl . '">Stores Configuration</a>'
];
}

$fieldset = $form->addFieldset(
'edit_form_fieldset_settings',
['legend' => __('section.io Default Account and Application')]
['legend' => __('Account and Application Selection')]
);

$placeholder = $fieldset->addField('label', 'hidden', [
'value' => __('section.io Default Account and Application'),
'value' => __('Account and Application Selection'),
]);


Expand All @@ -113,9 +137,10 @@ protected function _prepareForm()
'refresh_defaults',
'button',
[
'value' => __('Refresh Accounts and Applications'),
'title' => __('Click here to update available accounts and applications.'),
'onclick' => "setLocation('{$url}')"
'value' => __('Refresh Accounts and Applications'),
'title' => __('Update available accounts and applications.'),
'onclick' => "setLocation('{$url}')",
'class' => 'action action-secondary',
]
);
/** @var array() $accountData */
Expand Down Expand Up @@ -186,30 +211,74 @@ protected function _prepareForm()
'save_defaults',
'submit',
[
'value' => __('Save Settings'),
'class' => 'action-save action-secondary',
'style' => 'width:auto'
'value' => __('Update application'),
'class' => 'action-save action-primary',
'style' => 'width: auto;'
]
);
}
// no credential provided
else {
$pageMessages[] = [ 'type' => 'error', 'message' => 'Unable to retrieve account and application data at this time. Please reset your account credentials and try again. For questions or assistance, please <a href="https://community.section.io/tags/magento" target="_blank">click here.</a>.'];
}

$messagesHtml = '
<div class="messages">';
if ($this->state->getApplicationId() != null) {
$managementFieldset = $form->addFieldset(
'field_fieldset_settings',
['legend' => __('Management')]
);

//Varnish Configuration
$managementFieldset->addField(
'vcl_lbl',
'label',
[
'value' => 'Update Varnish Configuration with section.io. It will update and apply configuration in the Production branch.',
]
);
$managementFieldset->addField(
'vcl_btn',
'submit',
[
'name' => 'vcl_btn',
'value' => __('Update Varnish Configuration'),
'class' => 'action action-secondary',
'style' => 'width: auto;'
]
);

//HTTPS one click
$hostname = $this->state->getHostname();
$managementFieldset->addField(
'certificate_lbl',
'label',
[
'value' => 'Complementary one click HTTPS certificate via LetsEncrypt. Domain ' . $hostname . ' must be live on the internet exposed with port 80.',
]
);
$managementFieldset->addField(
'certificate_btn',
'submit',
[
'name' => 'certificate_btn',
'value' => __('One click HTTPS'),
'class' => 'action action-secondary',
'style' => 'width: auto;'
]
);
}
} else {
// no credential provided
$pageMessages[] = [
'type' => 'error',
'message' => 'Unable to retrieve account and application data at this time. Please reset your account credentials and try again. For questions or assistance, please <a href="https://community.section.io/tags/magento" target="_blank">click here.</a>.'
];
}

$messagesHtml = '<div class="messages">';
foreach ($pageMessages as $msg) {
$messagesHtml .= '
<div class="message message-' . $msg['type'] . '">
' . $msg['message'] . '
</div>';
}

$messagesHtml .= '</div>
';

$messagesHtml .= '</div>';
$placeholder->setBeforeElementHtml($messagesHtml);

$this->setForm($form);
Expand All @@ -224,7 +293,7 @@ protected function _prepareForm()
*/
public function getTabLabel()
{
return __('Default Account and Application');
return __('Management');
}

/**
Expand All @@ -234,7 +303,7 @@ public function getTabLabel()
*/
public function getTabTitle()
{
return __('Default Account and Application');
return __('Management');
}

/**
Expand Down
2 changes: 1 addition & 1 deletion Block/Adminhtml/Report/Edit/Tabs.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ protected function _beforeToHtml()
$this->addTab(
'report_edit_tabs_settings',
[
'label' => __('Account and Application Settings'),
'label' => __('Management'),
'title' => __('Default Account / Application'),
'content' => $this->getLayout()->createBlock(
'Sectionio\Metrics\Block\Adminhtml\Report\Edit\Tab\Settings')
Expand Down
19 changes: 14 additions & 5 deletions Controller/Adminhtml/Report/FetchInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ class FetchInfo extends Action
protected $helper;
/** @var \Psr\Log\LoggerInterface $logger */
protected $logger;
/** @var \Sectionio\Metrics\Helper\Aperture $aperture */
protected $aperture;
/** @var \Sectionio\Metrics\Helper\State $state */
protected $state;

/**
* @param Magento\Backend\App\Action\Context $context
Expand All @@ -33,6 +37,7 @@ class FetchInfo extends Action
* @param \Sectionio\Metrics\Model\ApplicationFactory $applicationFactory
* @param \Sectionio\Metrics\Helper\Data $helper
* @param \Psr\Log\LoggerInterface $logger
* @param \Sectionio\Metrics\Helper\Aperture $aperture
*/
public function __construct(
\Magento\Backend\App\Action\Context $context,
Expand All @@ -42,7 +47,9 @@ public function __construct(
\Sectionio\Metrics\Model\AccountFactory $accountFactory,
\Sectionio\Metrics\Model\ApplicationFactory $applicationFactory,
\Sectionio\Metrics\Helper\Data $helper,
\Psr\Log\LoggerInterface $logger
\Psr\Log\LoggerInterface $logger,
\Sectionio\Metrics\Helper\Aperture $aperture,
\Sectionio\Metrics\Helper\State $state
) {

parent::__construct($context);
Expand All @@ -53,6 +60,7 @@ public function __construct(
$this->applicationFactory = $applicationFactory;
$this->helper = $helper;
$this->logger = $logger;
$this->state = $state;
}

/**
Expand Down Expand Up @@ -82,9 +90,11 @@ public function execute()

if (!$accountData) {
/** @var string $hostname */
$hostname = parse_url($this->storeManager->getStore()->getBaseUrl(), PHP_URL_HOST);
$hostname = $this->state->getHostname();
/** @var string $service_url */
$service_url = $this->helper->generateApertureUrl(['uriStem' => '/origin?hostName=' . $hostname]);
$service_url = $this->helper->generateApertureUrl([
'uriStem' => '/origin?hostName=' . $hostname
]);
/** @var array $origin */
$origin = json_decode($this->helper->performCurl($service_url)['body_content'], true);
/** @var string $origin_address */
Expand All @@ -105,8 +115,7 @@ public function execute()
$accountData[] = $account_content;

$this->logger->info('Retrieving certificate started for ' . $hostname);
$certificate_url = 'https://aperture.section.io/api/v1/account/' . $account_content['id'] . '/domain/' . $hostname . '/renewCertificate';
$certificate_response = $this->helper->performCurl($certificate_url, 'POST', []);
$certificate_response = $this->aperture->renewCertificate($account_content['id'], $hostname);
$this->logger->info('Retrieving certificate finished for ' . $hostname . ' with result ' . $certificate_response['http_code']);
}

Expand Down
Loading

0 comments on commit 0b91089

Please sign in to comment.