Skip to content

Commit

Permalink
Merge pull request #278 from Inchoo/feature/#237-edge-module-last-con…
Browse files Browse the repository at this point in the history
…fig-update

Added upload date to edge modules active modules list
  • Loading branch information
vvuksan authored May 21, 2019
2 parents 0b22ed2 + 5345e57 commit b9eff3e
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 6 deletions.
3 changes: 1 addition & 2 deletions Controller/Adminhtml/FastlyCdn/Manifest/Save.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
use Magento\Framework\Exception\LocalizedException;

/**
* Class Create
*
* Class Save
* @package Fastly\Cdn\Controller\Adminhtml\FastlyCdn\Manifest
*/
class Save extends Action
Expand Down
1 change: 1 addition & 0 deletions Controller/Adminhtml/FastlyCdn/Manifest/ToggleModules.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ public function execute()
}
$manifest->setManifestId($moduleId);
$manifest->setManifestStatus(0);
$manifest->setLastUploaded(null);
}
$this->saveManifest($manifest);
}
Expand Down
34 changes: 31 additions & 3 deletions Controller/Adminhtml/FastlyCdn/Manifest/Upload.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
use Fastly\Cdn\Helper\Vcl;
use Fastly\Cdn\Model\Config\Backend\CustomSnippetUpload;
use Fastly\Cdn\Model\Modly\Manifest;
use Fastly\Cdn\Model\ManifestFactory;
use Fastly\Cdn\Model\ResourceModel\Manifest as ManifestResource;
use Magento\Framework\Exception\LocalizedException;

class Upload extends Action
Expand Down Expand Up @@ -40,16 +42,28 @@ class Upload extends Action
*/
private $vcl;

/**
* @var Manifest
*/
private $manifest;

/***
* @var ManifestFactory
*/
private $manifestFactory;

/**
* @var ManifestResource
*/
private $manifestResource;

/**
* @var CustomSnippetUpload
*/
private $customSnippetUpload;

/**
* Upload constructor.
*
* @param Context $context
* @param Http $request
* @param JsonFactory $resultJsonFactory
Expand All @@ -58,6 +72,8 @@ class Upload extends Action
* @param Vcl $vcl
* @param CustomSnippetUpload $customSnippetUpload
* @param Manifest $manifest
* @param ManifestFactory $manifestFactory
* @param ManifestResource $manifestResource
*/
public function __construct(
Context $context,
Expand All @@ -67,7 +83,9 @@ public function __construct(
Api $api,
Vcl $vcl,
CustomSnippetUpload $customSnippetUpload,
manifest $manifest
Manifest $manifest,
ManifestFactory $manifestFactory,
ManifestResource $manifestResource
) {
$this->request = $request;
$this->resultJson = $resultJsonFactory;
Expand All @@ -76,6 +94,8 @@ public function __construct(
$this->vcl = $vcl;
$this->customSnippetUpload = $customSnippetUpload;
$this->manifest = $manifest;
$this->manifestFactory = $manifestFactory;
$this->manifestResource = $manifestResource;
parent::__construct($context);
}

Expand Down Expand Up @@ -116,9 +136,17 @@ public function execute()
$comment = ['comment' => 'Magento Module uploaded the "'.$moduleId.'" Edge Module'];
$this->api->addComment($clone->number, $comment);

$moduleUploadDate = date("Y-m-d H:i:s");
$manifest = $this->manifestFactory->create();
$manifest->setManifestId($moduleId);
$manifest->setLastUploaded($moduleUploadDate);

$this->manifestResource->save($manifest);

return $result->setData([
'status' => true,
'active_version' => $clone->number
'active_version' => $clone->number,
'last_uploaded' => $moduleUploadDate
]);
} catch (\Exception $e) {
return $result->setData([
Expand Down
26 changes: 26 additions & 0 deletions Setup/UpgradeSchema.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ public function upgrade(SchemaSetupInterface $setup, ModuleContextInterface $con
$this->createModlyManifestTable($installer);
}

if (version_compare($context->getVersion(), '1.0.13', '<=')) {
$this->upgradeModlyManifestTable($installer);
}

$installer->endSetup();
}

Expand Down Expand Up @@ -181,4 +185,26 @@ public function createModlyManifestTable(
$connection->createTable($table);
}
}

/**
* @param SchemaSetupInterface $installer
*/
public function upgradeModlyManifestTable(
SchemaSetupInterface $installer
) {
$connection = $installer->getConnection();
$tableName = $installer->getTable('fastly_modly_manifests');

if ($installer->getConnection()->isTableExists($tableName) == true) {
$connection->addColumn(
$tableName,
'last_uploaded',
[
'type' => \Magento\Framework\DB\Ddl\Table::TYPE_DATETIME,
'nullable' => true,
'comment' => 'Last uploaded',
]
);
}
}
}
2 changes: 1 addition & 1 deletion etc/module.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Fastly_Cdn" setup_version="1.0.12">
<module name="Fastly_Cdn" setup_version="1.0.13">
<sequence>
<module name="Magento_Store"/>
<module name="Magento_PageCache" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ $_colspan = $block->isAddAfter() ? 2 : 1;
<?php foreach ($block->getColumns() as $columnName => $column) : ?>
<th><?php /* @noEscape */ echo $column['label']; ?></th>
<?php endforeach;?>
<th class="col-date" colspan="<?php /* @noEscape */ echo $_colspan; ?>">Upload Date</th>
<th class="col-actions" colspan="<?php /* @noEscape */ echo $_colspan; ?>">Action</th>
</tr>
</thead>
Expand Down
10 changes: 10 additions & 0 deletions view/adminhtml/web/js/modly.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ define([
let successAllModulesBtnMsg = $('#fastly-success-all-modules-button-msg');
let errorAllModulesBtnMsg = $('#fastly-error-all-modules-button-msg');
let warningAllModulesBtnMsg = $('#fastly-warning-all-modules-button-msg');
let module_field;

let active_version = setServiceLabel.active_version;

Expand Down Expand Up @@ -94,6 +95,7 @@ define([
modal.modal('closeModal');
resetAllMessages();
successAllModulesBtnMsg.text($.mage.__('The '+ moduleId +' module has been successfully uploaded to the Fastly service.')).show();
module_field.closest('tr').find('.col-date').text(response.last_uploaded);
} else {
resetAllMessages();
showErrorMessage(response.msg);
Expand Down Expand Up @@ -221,10 +223,12 @@ define([
let moduleNote = $('<p class="note"></p>');
let moduleNoteSpan = $('<span></span>');
let moduleActionCell = $('<td class="col-actions"></td>');
let moduleDateCell = $('<td class="col-date"></td>');
let moduleActionButton = $('<button title="Edit module" type="button">');

moduleRow.attr('id', 'fastly_' + index);
moduleRow.append(moduleCell);
moduleRow.append(moduleDateCell);
moduleRow.append(moduleActionCell);
moduleCell.append(moduleSpan);
moduleCell.append(moduleNote);
Expand All @@ -235,6 +239,11 @@ define([
moduleSpan.wrapInner('<b></b>');
moduleNote.append(moduleNoteSpan);
moduleNoteSpan.text(module.manifest_description);
if (module.last_uploaded !== null) {
moduleDateCell.text(module.last_uploaded);
} else {
moduleDateCell.text('Not uploaded');
}
moduleActionCell.append(moduleActionButton);
moduleActionButton.attr('data-module-id', module.manifest_id);
moduleActionButton.attr('id', 'fastly-edit-active-modules' + index);
Expand Down Expand Up @@ -702,6 +711,7 @@ define([

$('body').on('click', 'button.fastly-edit-active-modules-icon', function () {
let module_id = $(this).data('module-id');
module_field = $(this);
let properties = [];
let message = $('<div class="message"></div>');
let title = '';
Expand Down

0 comments on commit b9eff3e

Please sign in to comment.