From 5318d84b15def31f6273410030b7ff5d4fa813c6 Mon Sep 17 00:00:00 2001 From: Jon Pugh Date: Sat, 6 Aug 2016 12:12:34 -0400 Subject: [PATCH 01/59] Issue #2212149: Make task queue refresh configurable. --- task/hosting_task.js | 9 +++++---- task/hosting_task.module | 13 +++++++++++++ 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/task/hosting_task.js b/task/hosting_task.js index 97930da6..5f7fe9f2 100644 --- a/task/hosting_task.js +++ b/task/hosting_task.js @@ -24,7 +24,8 @@ hostingTaskRefreshList = function() { $("#hosting-task-list").html(data.markup); hostingTaskBindButtons('#hosting-task-list'); - setTimeout("hostingTaskRefreshList()", 30000); + console.log(Drupal.settings.hostingTaskRefresh.refreshTimeout, 'setting timeout'); + setTimeout("hostingTaskRefreshList()", Drupal.settings.hostingTaskRefresh.refreshTimeout); } } @@ -47,7 +48,7 @@ hostingTaskRefreshQueueBlock = function() { $("#block-views-hosting-task-list-block .content").html(data.markup); hostingTaskBindButtons('#block-views-hosting-task-list-block'); - setTimeout("hostingTaskRefreshQueueBlock()", 30000); + setTimeout("hostingTaskRefreshQueueBlock()", Drupal.settings.hostingTaskRefresh.refreshTimeout); } hostingTaskAddOverlay('#block-views-hosting-task-list-block .view-content'); @@ -56,8 +57,8 @@ hostingTaskRefreshQueueBlock = function() { $(document).ready(function() { $(document).data('hostingOpenModalFrame', false); - setTimeout("hostingTaskRefreshList()", 30000); - setTimeout("hostingTaskRefreshQueueBlock()", 30000); + setTimeout("hostingTaskRefreshList()", Drupal.settings.hostingTaskRefresh.refreshTimeout); + setTimeout("hostingTaskRefreshQueueBlock()", Drupal.settings.hostingTaskRefresh.refreshTimeout); hostingTaskBindButtons($(this)); $('#hosting-task-confirm-form-actions a').click(function() { if (parent.Drupal.modalFrame.isOpen) { diff --git a/task/hosting_task.module b/task/hosting_task.module index e5837033..178e1851 100644 --- a/task/hosting_task.module +++ b/task/hosting_task.module @@ -4,6 +4,19 @@ * Web server node type is defined here. */ +/** + * Implements hook_init(). + * + * Adds refreshTimeout javascript variable. + */ +function hosting_task_init() { + $settings['hostingTaskRefresh'] = array( + 'refreshTimeout' => variable_get('hosting_task_refresh_timeout', 3000), + ); + drupal_add_js($settings, 'setting'); +} + + /** * Implements hook_menu(). */ From 866739ef34e237ec729ac3548a1701d6c95139a8 Mon Sep 17 00:00:00 2001 From: Jon Pugh Date: Sat, 6 Aug 2016 12:14:14 -0400 Subject: [PATCH 02/59] Set it to use the current default refresh time, 30 seconds. --- task/hosting_task.module | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/task/hosting_task.module b/task/hosting_task.module index 178e1851..953e53aa 100644 --- a/task/hosting_task.module +++ b/task/hosting_task.module @@ -11,7 +11,7 @@ */ function hosting_task_init() { $settings['hostingTaskRefresh'] = array( - 'refreshTimeout' => variable_get('hosting_task_refresh_timeout', 3000), + 'refreshTimeout' => variable_get('hosting_task_refresh_timeout', 30000), ); drupal_add_js($settings, 'setting'); } From a94e2e93daadceeef60da8a1c7a91ae5bb9d753e Mon Sep 17 00:00:00 2001 From: Jon Pugh Date: Tue, 9 Aug 2016 10:16:13 -0400 Subject: [PATCH 03/59] Issue #2212149 by Jon Pugh: Improve task queue AJAX refresh, remove old drupal_add_js() calls --- platform/hosting_platform.module | 2 -- server/hosting_server.module | 2 -- site/hosting_site.nodeapi.inc | 2 -- task/hosting_task.module | 3 --- 4 files changed, 9 deletions(-) diff --git a/platform/hosting_platform.module b/platform/hosting_platform.module index 82704da1..9c135798 100644 --- a/platform/hosting_platform.module +++ b/platform/hosting_platform.module @@ -768,8 +768,6 @@ function hosting_platform_view($node, $view_mode, $langcode = NULL) { 'changed' => $node->changed, ); drupal_add_js($settings, array('type' => 'setting', 'scope' => JS_DEFAULT)); - - drupal_add_js(drupal_get_path('module', 'hosting_task') . '/hosting_task.js'); } return $node; diff --git a/server/hosting_server.module b/server/hosting_server.module index 601ad585..da8508e6 100644 --- a/server/hosting_server.module +++ b/server/hosting_server.module @@ -722,8 +722,6 @@ function hosting_server_view($node, $view_mode, $langcode = NULL) { 'changed' => $node->changed, ); drupal_add_js($settings, array('type' => 'setting', 'scope' => JS_DEFAULT)); - - drupal_add_js(drupal_get_path('module', 'hosting_task') . '/hosting_task.js'); } } diff --git a/site/hosting_site.nodeapi.inc b/site/hosting_site.nodeapi.inc index f7dc81f3..096dd3ee 100644 --- a/site/hosting_site.nodeapi.inc +++ b/site/hosting_site.nodeapi.inc @@ -111,8 +111,6 @@ function hosting_site_view($node, $view_mode, $langcode = NULL) { 'changed' => $node->changed, ); drupal_add_js($settings, array('type' => 'setting', 'scope' => JS_DEFAULT)); - - drupal_add_js(drupal_get_path('module', 'hosting_task') . '/hosting_task.js'); } return $node; } diff --git a/task/hosting_task.module b/task/hosting_task.module index 953e53aa..7e7c64a1 100644 --- a/task/hosting_task.module +++ b/task/hosting_task.module @@ -579,7 +579,6 @@ function hosting_add_task($nid, $type, $args = NULL, $status = HOSTING_TASK_QUEU * Implements hook_form(). */ function hosting_task_confirm_form($form, $form_state, $node, $task) { - drupal_add_js(drupal_get_path('module', 'hosting_task') . '/hosting_task.js'); $tasks = hosting_available_tasks($node->type); if (!isset($tasks[$task]['dialog']) || !$tasks[$task]['dialog']) { @@ -1719,8 +1718,6 @@ function hosting_task_preprocess_views_view_table(&$vars) { switch ($id) { case 'hosting_task_list-block': - drupal_add_js(drupal_get_path('module', 'hosting_task') . '/hosting_task.js'); - $settings['hostingTaskRefresh'] = array( 'queueBlock' => 1, ); From 0d020a771cb9328b62ed0dc389ee5387eaf82db8 Mon Sep 17 00:00:00 2001 From: Jon Pugh Date: Tue, 9 Aug 2016 10:16:13 -0400 Subject: [PATCH 04/59] Issue #2212149 by Jon Pugh: Improve task queue AJAX refresh, remove old drupal_add_js() calls --- platform/hosting_platform.module | 2 -- server/hosting_server.module | 2 -- site/hosting_site.nodeapi.inc | 2 -- task/hosting_task.module | 3 --- 4 files changed, 9 deletions(-) diff --git a/platform/hosting_platform.module b/platform/hosting_platform.module index 82704da1..9c135798 100644 --- a/platform/hosting_platform.module +++ b/platform/hosting_platform.module @@ -768,8 +768,6 @@ function hosting_platform_view($node, $view_mode, $langcode = NULL) { 'changed' => $node->changed, ); drupal_add_js($settings, array('type' => 'setting', 'scope' => JS_DEFAULT)); - - drupal_add_js(drupal_get_path('module', 'hosting_task') . '/hosting_task.js'); } return $node; diff --git a/server/hosting_server.module b/server/hosting_server.module index 601ad585..da8508e6 100644 --- a/server/hosting_server.module +++ b/server/hosting_server.module @@ -722,8 +722,6 @@ function hosting_server_view($node, $view_mode, $langcode = NULL) { 'changed' => $node->changed, ); drupal_add_js($settings, array('type' => 'setting', 'scope' => JS_DEFAULT)); - - drupal_add_js(drupal_get_path('module', 'hosting_task') . '/hosting_task.js'); } } diff --git a/site/hosting_site.nodeapi.inc b/site/hosting_site.nodeapi.inc index f7dc81f3..096dd3ee 100644 --- a/site/hosting_site.nodeapi.inc +++ b/site/hosting_site.nodeapi.inc @@ -111,8 +111,6 @@ function hosting_site_view($node, $view_mode, $langcode = NULL) { 'changed' => $node->changed, ); drupal_add_js($settings, array('type' => 'setting', 'scope' => JS_DEFAULT)); - - drupal_add_js(drupal_get_path('module', 'hosting_task') . '/hosting_task.js'); } return $node; } diff --git a/task/hosting_task.module b/task/hosting_task.module index 953e53aa..7e7c64a1 100644 --- a/task/hosting_task.module +++ b/task/hosting_task.module @@ -579,7 +579,6 @@ function hosting_add_task($nid, $type, $args = NULL, $status = HOSTING_TASK_QUEU * Implements hook_form(). */ function hosting_task_confirm_form($form, $form_state, $node, $task) { - drupal_add_js(drupal_get_path('module', 'hosting_task') . '/hosting_task.js'); $tasks = hosting_available_tasks($node->type); if (!isset($tasks[$task]['dialog']) || !$tasks[$task]['dialog']) { @@ -1719,8 +1718,6 @@ function hosting_task_preprocess_views_view_table(&$vars) { switch ($id) { case 'hosting_task_list-block': - drupal_add_js(drupal_get_path('module', 'hosting_task') . '/hosting_task.js'); - $settings['hostingTaskRefresh'] = array( 'queueBlock' => 1, ); From 58d6121abb8cbf46156ce1923f2246dcb5bd4921 Mon Sep 17 00:00:00 2001 From: Jon Pugh Date: Wed, 19 Oct 2016 10:37:23 -0400 Subject: [PATCH 05/59] Issue #2212149: Improve task queue AJAX refresh. Progress in implementing Vue.js. - Rewrite hosting_task.js to follow Drupal.behaviours pattern and to implement Vue.js app. - Return JSON results via hosting/tasks/queue hosting_task_ajax_queue() menu callback. - Add views template for hosting-task-list tables to allow embedding of Vue.js markup. - Add hostingTasks javascript settings and vue.js to View hosting_task_list-block. --- task/hosting_task.js | 212 ++++++++++-------- task/hosting_task.module | 14 +- ...iews-view-table--hosting-task-list.tpl.php | 45 ++++ 3 files changed, 177 insertions(+), 94 deletions(-) create mode 100644 task/views-view-table--hosting-task-list.tpl.php diff --git a/task/hosting_task.js b/task/hosting_task.js index ae8cfe88..d12c06be 100644 --- a/task/hosting_task.js +++ b/task/hosting_task.js @@ -1,91 +1,125 @@ (function($) { - -hostingTaskRefreshList = function() { - if (!Drupal.settings.hostingTaskRefresh.nid) { - return null; - } - - var hostingTaskListRefreshCallback = function(data, responseText) { - // If the node has been modified, reload the whole page. - if (Drupal.settings.hostingTaskRefresh.changed < data.changed) { - // only reload if there is no modal frame currently open - if ($(document).data('hostingOpenModalFrame') != true) { - // If a specific URL was specified, go there. - if (data.navigate_url) { - document.location = data.navigate_url; - } - // Fall back to just doing a reload of the current page. - else { - document.location.reload(); - } - } - } - else { - $("#hosting-task-list").html(data.markup); - - hostingTaskBindButtons('#hosting-task-list'); - setTimeout("hostingTaskRefreshList()", Drupal.settings.hostingTaskRefresh.refreshTimeout); - } - } - - hostingTaskAddOverlay('#hosting-task-list'); - $.get(Drupal.settings.basePath + 'hosting/tasks/' + Drupal.settings.hostingTaskRefresh.nid + '/list', null, hostingTaskListRefreshCallback , 'json' ); -} - - -function hostingTaskAddOverlay(elem) { - $(elem).prepend('
'); -} - - -hostingTaskRefreshQueueBlock = function() { - if (Drupal.settings.hostingTaskRefresh.queueBlock != 1) { - return null; - } - - var hostingTaskQueueRefreshCallback = function(data, responseText) { - $("#block-views-hosting-task-list-block .content").html(data.markup); - - hostingTaskBindButtons('#block-views-hosting-task-list-block'); - setTimeout("hostingTaskRefreshQueueBlock()", Drupal.settings.hostingTaskRefresh.refreshTimeout); - } - - hostingTaskAddOverlay('#block-views-hosting-task-list-block .view-content'); - $.get(Drupal.settings.basePath + 'hosting/tasks/queue', null, hostingTaskQueueRefreshCallback , 'json'); -} - -$(document).ready(function() { - $(document).data('hostingOpenModalFrame', false); - setTimeout("hostingTaskRefreshList()", Drupal.settings.hostingTaskRefresh.refreshTimeout); - setTimeout("hostingTaskRefreshQueueBlock()", Drupal.settings.hostingTaskRefresh.refreshTimeout); - hostingTaskBindButtons($(this)); - $('#hosting-task-confirm-form-actions a').click(function() { - if (parent.Drupal.modalFrame.isOpen) { - setTimeout(function() { parent.Drupal.modalFrame.close({}, {}); }, 1); - return false; + Drupal.behaviors.hostingTasks = { + attach: function (context, settings) { + Drupal.settings.hostingTasks.vue = new Vue({ + el: '#hostingTasks', + data: { + tasks: Drupal.settings.hostingTasks.tasks, + classObject: function () { + return { + 'hosting-warning': this.hosting_task_task_status == 3, + 'hosting-success': this.hosting_task_task_status == 1, + } + } + }, + }); + + setTimeout("Drupal.behaviors.hostingTasks.checkTasks()", settings.hostingTasks.refreshTimeout); + }, + checkTasks: function () { + var url = Drupal.settings.hostingTasks.url; + $.getJSON(url, function (data) { + console.log(data); + Drupal.settings.hostingTasks.vue.tasks = data.tasks; + // console.log(Drupal.settings.hostingTasks.vue.data); + // Drupal.settings.hostingTasks.vue.data.tasks = data.tasks; + + if (Drupal.settings.hostingTasks.halt != true) { + setTimeout("Drupal.behaviors.hostingTasks.checkTasks()", Drupal.settings.hostingTasks.refreshTimeout); + } + }); + }, } - }); - -}); - -hostingTaskBindButtons = function(elem) { - $('.hosting-button-dialog', elem).click(function() { - $(document).data('hostingOpenModalFrame', true) - var options = { - url : Drupal.settings.basePath + 'hosting/js' + $(this).attr('href'), - draggable : false, - width : 600, - height : 150, - onSubmit : function() { - $(document).data('hostingOpenModalFrame', false) - hostingTaskRefreshQueueBlock(); - hostingTaskRefreshList(); - } - } - Drupal.modalFrame.open(options); - return false; - }); -} - - -})(jQuery); +}(jQuery)); + +// (function($) { +// +// hostingTaskRefreshList = function() { +// if (!Drupal.settings.hostingTaskRefresh.nid) { +// return null; +// } +// +// var hostingTaskListRefreshCallback = function(data, responseText) { +// // If the node has been modified, reload the whole page. +// if (Drupal.settings.hostingTaskRefresh.changed < data.changed) { +// // only reload if there is no modal frame currently open +// if ($(document).data('hostingOpenModalFrame') != true) { +// // If a specific URL was specified, go there. +// if (data.navigate_url) { +// document.location = data.navigate_url; +// } +// // Fall back to just doing a reload of the current page. +// else { +// document.location.reload(); +// } +// } +// } +// else { +// $("#hosting-task-list").html(data.markup); +// +// hostingTaskBindButtons('#hosting-task-list'); +// setTimeout("hostingTaskRefreshList()", Drupal.settings.hostingTaskRefresh.refreshTimeout); +// } +// } +// +// hostingTaskAddOverlay('#hosting-task-list'); +// $.get(Drupal.settings.basePath + 'hosting/tasks/' + Drupal.settings.hostingTaskRefresh.nid + '/list', null, hostingTaskListRefreshCallback , 'json' ); +// } +// +// +// function hostingTaskAddOverlay(elem) { +// $(elem).prepend('
'); +// } +// +// +// hostingTaskRefreshQueueBlock = function() { +// if (Drupal.settings.hostingTaskRefresh.queueBlock != 1) { +// return null; +// } +// +// var hostingTaskQueueRefreshCallback = function(data, responseText) { +// // $("#block-views-hosting-task-list-block .content").html(data.markup); +// // +// // hostingTaskBindButtons('#block-views-hosting-task-list-block'); +// setTimeout("hostingTaskRefreshQueueBlock()", Drupal.settings.hostingTaskRefresh.refreshTimeout); +// } +// +// // hostingTaskAddOverlay('#block-views-hosting-task-list-block .view-content'); +// $.get(Drupal.settings.basePath + 'hosting/tasks/queue', null, hostingTaskQueueRefreshCallback , 'json'); +// } +// +// $(document).ready(function() { +// $(document).data('hostingOpenModalFrame', false); +// setTimeout("hostingTaskRefreshList()", Drupal.settings.hostingTaskRefresh.refreshTimeout); +// setTimeout("hostingTaskRefreshQueueBlock()", Drupal.settings.hostingTaskRefresh.refreshTimeout); +// hostingTaskBindButtons($(this)); +// $('#hosting-task-confirm-form-actions a').click(function() { +// if (parent.Drupal.modalFrame.isOpen) { +// setTimeout(function() { parent.Drupal.modalFrame.close({}, {}); }, 1); +// return false; +// } +// }); +// +// }); +// +// hostingTaskBindButtons = function(elem) { +// $('.hosting-button-dialog', elem).click(function() { +// $(document).data('hostingOpenModalFrame', true) +// var options = { +// url : Drupal.settings.basePath + 'hosting/js' + $(this).attr('href'), +// draggable : false, +// width : 600, +// height : 150, +// onSubmit : function() { +// $(document).data('hostingOpenModalFrame', false) +// hostingTaskRefreshQueueBlock(); +// hostingTaskRefreshList(); +// } +// } +// Drupal.modalFrame.open(options); +// return false; +// }); +// } +// +// +// })(jQuery); diff --git a/task/hosting_task.module b/task/hosting_task.module index c566f153..a88b7a7e 100644 --- a/task/hosting_task.module +++ b/task/hosting_task.module @@ -204,11 +204,7 @@ function hosting_task_ajax_list($node) { * AJAX callback for refreshing task list. */ function hosting_task_ajax_queue() { - $view = views_get_view('hosting_task_list'); - $view->set_display('block'); - $view->pre_execute(); - $return['markup'] = $view->render('block'); - + $return['tasks'] = views_get_view_result('hosting_task_list', 'block'); drupal_json_output($return); exit(); } @@ -1697,6 +1693,7 @@ function hosting_task_views_api() { return array( 'api' => 3, 'path' => drupal_get_path('module', 'hosting_task') . '/includes/views', + 'template path' => drupal_get_path('module', 'hosting_task'), ); } @@ -1726,7 +1723,14 @@ function hosting_task_preprocess_views_view_table(&$vars) { $settings['hostingTaskRefresh'] = array( 'queueBlock' => 1, ); + $settings['hostingTasks'] = array( + 'url' => url("hosting/tasks/queue"), + 'refreshTimeout' => 2000, + 'tasks' => views_get_view_result('hosting_task_list', 'block'), + ); drupal_add_js($settings, 'setting'); + drupal_add_js(drupal_get_path('module', 'hosting_task') . '/hosting_task.js'); + drupal_add_js('https://npmcdn.com/vue/dist/vue.js', 'external'); break; } } diff --git a/task/views-view-table--hosting-task-list.tpl.php b/task/views-view-table--hosting-task-list.tpl.php new file mode 100644 index 00000000..25096b6f --- /dev/null +++ b/task/views-view-table--hosting-task-list.tpl.php @@ -0,0 +1,45 @@ + + + id="hostingTasks"> + + + + + + + $label): ?> + + + + + + + > + + + +
scope="col"> + +
+ {{ task.hosting_task_task_type }} {{ task.hosting_task_task_status }} +
From f7ce3150c788420ff407da01c5abc285b63532a4 Mon Sep 17 00:00:00 2001 From: Jon Pugh Date: Wed, 19 Oct 2016 11:09:39 -0400 Subject: [PATCH 06/59] Issue #2212149: Improve task queue AJAX refresh. Progress in implementing Vue.js. - Add a views_post_execute hook to alter task data. - Wrap TR in template so we can apply class to TR. --- task/hosting_task.js | 2 +- task/hosting_task.module | 14 ++++++++++++++ task/views-view-table--hosting-task-list.tpl.php | 8 +++++--- 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/task/hosting_task.js b/task/hosting_task.js index d12c06be..88653355 100644 --- a/task/hosting_task.js +++ b/task/hosting_task.js @@ -19,7 +19,7 @@ checkTasks: function () { var url = Drupal.settings.hostingTasks.url; $.getJSON(url, function (data) { - console.log(data); + // console.log(data); Drupal.settings.hostingTasks.vue.tasks = data.tasks; // console.log(Drupal.settings.hostingTasks.vue.data); // Drupal.settings.hostingTasks.vue.data.tasks = data.tasks; diff --git a/task/hosting_task.module b/task/hosting_task.module index a88b7a7e..39c11c6b 100644 --- a/task/hosting_task.module +++ b/task/hosting_task.module @@ -1735,6 +1735,20 @@ function hosting_task_preprocess_views_view_table(&$vars) { } } +/** + * + */ +function hosting_task_views_post_execute(&$view) { + + // Parse Results on hosting_task_list view. + if ($view->name == 'hosting_task_list') { + foreach ($view->result as $i => &$result) { + $result->status_class = hosting_task_status_class($result->hosting_task_task_status); + $result->ref_url = url("node/$result->node_hosting_task_nid"); + } + } +} + /** * Set a task's status according to its log. * diff --git a/task/views-view-table--hosting-task-list.tpl.php b/task/views-view-table--hosting-task-list.tpl.php index 25096b6f..ec55329c 100644 --- a/task/views-view-table--hosting-task-list.tpl.php +++ b/task/views-view-table--hosting-task-list.tpl.php @@ -36,10 +36,12 @@ - > - - {{ task.hosting_task_task_type }} {{ task.hosting_task_task_status }} + From 04a4bdd25fa882bcfc8fd2ea5c3d5f1155de885b Mon Sep 17 00:00:00 2001 From: Jon Pugh Date: Wed, 19 Oct 2016 11:16:11 -0400 Subject: [PATCH 07/59] Issue #2212149: Improve task queue AJAX refresh. Progress in implementing Vue.js. - Adding "View" button to task logs. --- task/hosting_task.module | 2 ++ task/views-view-table--hosting-task-list.tpl.php | 3 +++ 2 files changed, 5 insertions(+) diff --git a/task/hosting_task.module b/task/hosting_task.module index 39c11c6b..0040d57c 100644 --- a/task/hosting_task.module +++ b/task/hosting_task.module @@ -1745,6 +1745,8 @@ function hosting_task_views_post_execute(&$view) { foreach ($view->result as $i => &$result) { $result->status_class = hosting_task_status_class($result->hosting_task_task_status); $result->ref_url = url("node/$result->node_hosting_task_nid"); + $result->task_url = url("hosting/task/$result->nid"); + $result->task_link_text = t('View'); } } } diff --git a/task/views-view-table--hosting-task-list.tpl.php b/task/views-view-table--hosting-task-list.tpl.php index ec55329c..b88790be 100644 --- a/task/views-view-table--hosting-task-list.tpl.php +++ b/task/views-view-table--hosting-task-list.tpl.php @@ -41,6 +41,9 @@ {{ task.hosting_task_task_type }}: {{ task.node_hosting_task_title }} + + {{ task.task_link_text }} + From 4cbe5473591f9f337d09dfca25285ffa78530d0d Mon Sep 17 00:00:00 2001 From: Jon Pugh Date: Wed, 19 Oct 2016 11:39:28 -0400 Subject: [PATCH 08/59] Issue #2212149: Improve task queue AJAX refresh. Progress in implementing Vue.js. - Renaming table views template to only affect the block. --- ....tpl.php => views-view-table--hosting-task-list-block.tpl.php} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename task/{views-view-table--hosting-task-list.tpl.php => views-view-table--hosting-task-list-block.tpl.php} (100%) diff --git a/task/views-view-table--hosting-task-list.tpl.php b/task/views-view-table--hosting-task-list-block.tpl.php similarity index 100% rename from task/views-view-table--hosting-task-list.tpl.php rename to task/views-view-table--hosting-task-list-block.tpl.php From 078cd390a562cb2185b5a918adaaa4ef06c7c5cd Mon Sep 17 00:00:00 2001 From: Jon Pugh Date: Wed, 19 Oct 2016 11:42:24 -0400 Subject: [PATCH 09/59] Issue #2212149: Improve task queue AJAX refresh. Progress in implementing Vue.js. - Renaming table views template to only affect the block. --- ...tpl.php => views-view-table--hosting-task-list--block.tpl.php} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename task/{views-view-table--hosting-task-list-block.tpl.php => views-view-table--hosting-task-list--block.tpl.php} (100%) diff --git a/task/views-view-table--hosting-task-list-block.tpl.php b/task/views-view-table--hosting-task-list--block.tpl.php similarity index 100% rename from task/views-view-table--hosting-task-list-block.tpl.php rename to task/views-view-table--hosting-task-list--block.tpl.php From ee239e6277261f0f140145f8e7d6f0b5205c1c67 Mon Sep 17 00:00:00 2001 From: Jon Pugh Date: Wed, 19 Oct 2016 11:47:13 -0400 Subject: [PATCH 10/59] Issue #2212149: Improve task queue AJAX refresh. Progress in implementing Vue.js. - Removing unused experimental vue.js class binding. --- task/hosting_task.js | 6 ------ 1 file changed, 6 deletions(-) diff --git a/task/hosting_task.js b/task/hosting_task.js index 63905380..ddd5fca5 100644 --- a/task/hosting_task.js +++ b/task/hosting_task.js @@ -6,12 +6,6 @@ el: '#hostingTasks', data: { tasks: Drupal.settings.hostingTasks.tasks, - classObject: function () { - return { - 'hosting-warning': this.hosting_task_task_status == 3, - 'hosting-success': this.hosting_task_task_status == 1, - } - } }, }); From d133c6f3845f183ce933b547155f12a90b254f7d Mon Sep 17 00:00:00 2001 From: Jon Pugh Date: Wed, 19 Oct 2016 16:00:58 -0400 Subject: [PATCH 11/59] Issue #2212149: Improve task queue AJAX refresh. Progress in implementing Vue.js. - Creating a custom theme function/template for available tasks table. - Moving hosting task settings to hook_prepreprocess_page() so it loads on every page. Load available tasks on pages node pages. - Combining tasks and available tasks in a single payload. - Adding vue model for available tasks. --- task/hosting-task-table.tpl.php | 53 +++++++ task/hosting_task.js | 22 ++- task/hosting_task.module | 248 +++++++++++++++++++++----------- 3 files changed, 235 insertions(+), 88 deletions(-) create mode 100644 task/hosting-task-table.tpl.php diff --git a/task/hosting-task-table.tpl.php b/task/hosting-task-table.tpl.php new file mode 100644 index 00000000..dd833092 --- /dev/null +++ b/task/hosting-task-table.tpl.php @@ -0,0 +1,53 @@ + + + + + + + + + + + + +
+ + + +
\ No newline at end of file diff --git a/task/hosting_task.js b/task/hosting_task.js index ddd5fca5..9adf1300 100644 --- a/task/hosting_task.js +++ b/task/hosting_task.js @@ -2,6 +2,8 @@ Drupal.behaviors.hostingTasks = { attach: function (context, settings) { + + // Attach to the global hosting tasks block. Drupal.settings.hostingTasks.vue = new Vue({ el: '#hostingTasks', data: { @@ -9,16 +11,30 @@ }, }); + // Attach to the available_tasks block, if there is one. + if ($('#hosting-task-list').length > 0) { + Drupal.settings.hostingTasks.vueAvailable = new Vue({ + el: '#hosting-task-list', + data: { + tasks: Drupal.settings.hostingAvailableTasks, + }, + }); + + } + setTimeout("Drupal.behaviors.hostingTasks.checkTasks()", settings.hostingTasks.refreshTimeout); }, checkTasks: function () { var url = Drupal.settings.hostingTasks.url; $.getJSON(url, function (data) { - // console.log(data); + + // Replace vue data with new data. Drupal.settings.hostingTasks.vue.tasks = data.tasks; - // console.log(Drupal.settings.hostingTasks.vue.data); - // Drupal.settings.hostingTasks.vue.data.tasks = data.tasks; + if (data.availableTasks && Drupal.settings.hostingTasks.vueAvailable) { + Drupal.settings.hostingTasks.vueAvailable.tasks = data.availableTasks; + } + // Stop if needed. if (Drupal.settings.hostingTasks.halt != true) { setTimeout("Drupal.behaviors.hostingTasks.checkTasks()", Drupal.settings.hostingTasks.refreshTimeout); } diff --git a/task/hosting_task.module b/task/hosting_task.module index 0040d57c..f7d86a29 100644 --- a/task/hosting_task.module +++ b/task/hosting_task.module @@ -10,10 +10,10 @@ * Adds refreshTimeout javascript variable. */ function hosting_task_init() { - $settings['hostingTaskRefresh'] = array( - 'refreshTimeout' => variable_get('hosting_task_refresh_timeout', 30000), - ); - drupal_add_js($settings, 'setting'); +// $settings['hostingTaskRefresh'] = array( +// 'refreshTimeout' => variable_get('hosting_task_refresh_timeout', 30000), +// ); +// drupal_add_js($settings, 'setting'); } @@ -48,13 +48,12 @@ function hosting_task_menu() { } } - $items['hosting/tasks/%node/list'] = array( + $items['hosting/json/tasks'] = array( 'title' => 'Task list', 'description' => 'AJAX callback for refreshing task list', 'page callback' => 'hosting_task_ajax_list', - 'page arguments' => array(2), - 'access callback' => 'node_access', - 'access arguments' => array('view', 2), + 'page arguments' => array(3), + 'access arguments' => array('access task logs'), 'type' => MENU_CALLBACK, ); @@ -68,14 +67,6 @@ function hosting_task_menu() { 'type' => MENU_CALLBACK, ); - $items['hosting/tasks/queue'] = array( - 'title' => 'Task list', - 'description' => 'AJAX callback for refreshing task queue', - 'page callback' => 'hosting_task_ajax_queue', - 'access arguments' => array('access task logs'), - 'type' => MENU_CALLBACK, - ); - // Custom path to task node views for overlay. // See hosting_task_overlay_paths(). $items['hosting/task/%node'] = array( @@ -192,19 +183,20 @@ function hosting_task_ajax_command_hosting_table_check($selector, $url, $setting /** * Page callback to provide JSON output for a task. */ -function hosting_task_ajax_list($node) { - $return['markup'] = hosting_task_table($node); - $return['changed'] = $node->changed; - $return['navigate_url'] = url('node/' . $node->nid); - drupal_json_output($return); - exit(); -} +function hosting_task_ajax_list($nid = NULL) { -/** - * AJAX callback for refreshing task list. - */ -function hosting_task_ajax_queue() { + // Load available tasks if a node is specified and accessible. + $node = node_load($nid); + if ($node && node_access('view', $node)) { + $return['availableTasks'] = array_values(hosting_task_fetch_tasks($node->nid)); + $return['changed'] = $node->changed; + $return['navigate_url'] = url('node/' . $node->nid); + } + + // Load global tasks for block. $return['tasks'] = views_get_view_result('hosting_task_list', 'block'); + + // Output JSON drupal_json_output($return); exit(); } @@ -1454,56 +1446,12 @@ function hosting_task_list($filter_by = NULL, $filter_value = NULL) { * simple interface. */ function hosting_task_table($node) { - $output = ''; - - $headers[] = t('Task'); - $headers[] = array( - 'data' => t('Actions'), - 'class' => array('hosting-actions'), - ); - - $tasklist = hosting_task_fetch_tasks($node->nid); - $rows = array(); - - foreach ($tasklist as $task => $info) { - $row = array(); - - if (!isset($info['nid']) && !$info['task_permitted']) { - // Just don't show those tasks, since we'll not be able to run them. - continue; - } - - if (empty($info['title'])) { - // Skip tasks from types that have since been removed. - continue; - } - - $row['type'] = array( - 'data' => $info['title'], - 'class' => array('hosting-status'), - ); - $actions = array(); - - if (isset($info['task_status']) && ($info['task_status'] == 0)) { - $actions['cancel'] = _hosting_task_button(t('Cancel'), sprintf("hosting/tasks/%d/cancel", $info['nid']), t("Cancel the task and remove it from the queue"), 'hosting-button-stop', !$info['task_permitted']); - } - else { - $actions['run'] = _hosting_task_button(t('Run'), sprintf("hosting_confirm/%d/%s_%s", $node->nid, $node->type, $task), $info['description'], 'hosting-button-run', $info['task_permitted'], $info['dialog']); - } - - $actions['log'] = _hosting_task_button(t('View'), isset($info['nid']) ? 'hosting/task/' . $info['nid'] : '', t("Display the task log"), 'hosting-button-log', isset($info['nid']) && user_access('access task logs'), TRUE, FALSE); - $row['actions'] = array( - 'data' => implode('', $actions), - 'class' => array('hosting-actions'), - ); - - $rows[] = array( - 'data' => $row, - 'class' => array($info['class']), - ); - } - $output .= theme('table', array('header' => $headers, 'rows' => $rows, 'attributes' => array('class' => array('hosting-table')))); - return $output; + $tasks = hosting_task_fetch_tasks($node->nid); + $settings['hostingTasks']['availableTasks'] = $tasks; + drupal_add_js($settings, 'setting'); + drupal_add_js(drupal_get_path('module', 'hosting_task') . '/hosting_task.js'); + drupal_add_js('https://npmcdn.com/vue/dist/vue.js', 'external'); + return theme('hosting_task_table'); } /** @@ -1625,6 +1573,8 @@ function hosting_task_fetch_tasks($rid) { $tasks = hosting_available_tasks($node->type); ksort($tasks); + global $user; + foreach ($tasks as $type => $hook_task) { if (!isset($return[$type])) { @@ -1636,6 +1586,8 @@ function hosting_task_fetch_tasks($rid) { $task = array(); $task = array_merge($return[$type], $hook_task); + $task['task_type'] = $type; + $allowed = (isset($task['exists']) && !in_array($task['task_status'], array(HOSTING_TASK_QUEUED, HOSTING_TASK_PROCESSING))) || !isset($task['exists']); if ($allowed && empty($task['hidden']) && $access_callback($node, $type)) { $task['task_permitted'] = TRUE; @@ -1652,11 +1604,105 @@ function hosting_task_fetch_tasks($rid) { } $task['class'] = hosting_task_status_class($task['task_status']); + // Generate Links + $task['view_link'] = FALSE; + $task['run_link'] = FALSE; + $task['cancel_link'] = FALSE; + + $nid = $task['nid']; + $ref_type = $node->type; + $task_type = $task['task_type']; + + // View Logs link + if (drupal_valid_path("hosting/task/{$nid}")) { + $task['view_link'] = array( + 'url' => url("hosting/task/{$nid}"), + 'title' => t('Display the task log.'), + 'text' => t('View'), + ); + } + + // Cancel Task link + if (isset($task['task_status']) && ($task['task_status'] === HOSTING_TASK_QUEUED)) { +// $actions['cancel'] = _hosting_task_button(t('Cancel'), sprintf("hosting/tasks/%d/cancel", $info['nid']), t("Cancel the task and remove it from the queue"), 'hosting-button-stop', !$info['task_permitted']); + + $task['cancel_link'] = array( + 'url' => url("hosting/tasks/{$nid}/cancel"), + 'title' => t('Cancel the task and remove it from the queue.'), + 'text' => t('Cancel'), + ); + } + else { +// $actions['run'] = _hosting_task_button(t('Run'), sprintf("hosting_confirm/%d/%s_%s", $node->nid, $node->type, $task), $info['description'], 'hosting-button-run', $info['task_permitted'], $info['dialog']); + $task['run_link'] = array( + 'url' => url("hosting_confirm/{$rid}/{$ref_type}_{$task_type}", array( + 'query'=> array( + 'token' => drupal_get_token($user->uid), + ) + )), + 'title' => $task['description'], + 'text' => t('Run'), + ); + } + + $return[$type] = $task; } return $return; } +//$output = ''; +// +//$headers[] = t('Task'); +//$headers[] = array( +// 'data' => t('Actions'), +// 'class' => array('hosting-actions'), +//); +// +//$tasklist = hosting_task_fetch_tasks($node->nid); +//$rows = array(); +// +//foreach ($tasklist as $task => $info) { +// $row = array(); +// +// if (!isset($info['nid']) && !$info['task_permitted']) { +// // Just don't show those tasks, since we'll not be able to run them. +// continue; +// } +// +// if (empty($info['title'])) { +// // Skip tasks from types that have since been removed. +// continue; +// } +// +// $row['type'] = array( +// 'data' => $info['title'], +// 'class' => array('hosting-status'), +// ); +// $actions = array(); +// +// if (isset($info['task_status']) && ($info['task_status'] == 0)) { +// $actions['cancel'] = _hosting_task_button(t('Cancel'), sprintf("hosting/tasks/%d/cancel", $info['nid']), t("Cancel the task and remove it from the queue"), 'hosting-button-stop', !$info['task_permitted']); +// } +// else { +// $actions['run'] = _hosting_task_button(t('Run'), sprintf("hosting_confirm/%d/%s_%s", $node->nid, $node->type, $task), $info['description'], 'hosting-button-run', $info['task_permitted'], $info['dialog']); +// } +// +// $actions['log'] = _hosting_task_button(t('View'), isset($info['nid']) ? 'hosting/task/' . $info['nid'] : '', t("Display the task log"), 'hosting-button-log', isset($info['nid']) && user_access('access task logs'), TRUE, FALSE); +// $row['actions'] = array( +// 'data' => implode('', $actions), +// 'class' => array('hosting-actions'), +// ); +// +// $rows[] = array( +// 'data' => $row, +// 'class' => array($info['class']), +// ); +//} +//$output .= theme('table', array('header' => $headers, 'rows' => $rows, 'attributes' => array('class' => array('hosting-table')))); +//return $output; + + /** * Traslate a task status code into a css class. @@ -1723,18 +1769,35 @@ function hosting_task_preprocess_views_view_table(&$vars) { $settings['hostingTaskRefresh'] = array( 'queueBlock' => 1, ); - $settings['hostingTasks'] = array( - 'url' => url("hosting/tasks/queue"), - 'refreshTimeout' => 2000, - 'tasks' => views_get_view_result('hosting_task_list', 'block'), - ); - drupal_add_js($settings, 'setting'); - drupal_add_js(drupal_get_path('module', 'hosting_task') . '/hosting_task.js'); - drupal_add_js('https://npmcdn.com/vue/dist/vue.js', 'external'); + break; } } +/** + * Implements hook_preprocess_HOOK(). + */ +function hosting_task_preprocess_page(&$variables) { + $settings['hostingTasks'] = array( + 'url' => url("hosting/json/tasks"), + 'refreshTimeout' => 2000, + 'tasks' => views_get_view_result('hosting_task_list', 'block'), + ); + + // If on a hosting node page... + if (isset($variables['node']) && !empty($variables['node']->nid)) { + $availableTasks = hosting_task_fetch_tasks($variables['node']->nid); + + // Get rid of array keys so it becomes an array. + $settings['hostingAvailableTasks'] = array_values($availableTasks); + $settings['hostingTasks']['url'] = url("hosting/json/tasks/" . $variables['node']->nid); + } + + drupal_add_js($settings, 'setting'); + drupal_add_js(drupal_get_path('module', 'hosting_task') . '/hosting_task.js'); + drupal_add_js('https://npmcdn.com/vue/dist/vue.js', 'external'); +} + /** * */ @@ -1909,3 +1972,18 @@ function hosting_task_entity_property_info_alter(&$info) { ); */ } + +/** + * Implements hook_theme(). + */ +function hosting_task_theme($existing, $type, $theme, $path) { + $theme = array(); + $theme['hosting_task_table'] = array( + 'template' => 'hosting-task-table', + 'variables' => array( + array('header' => NULL, 'rows' => NULL, 'attributes' => array(), 'caption' => NULL, 'colgroups' => array(), 'sticky' => TRUE, 'empty' => ''), + 'path' => drupal_get_path('module', 'hosting_task'), + ) + ); + return $theme; +} \ No newline at end of file From 8b397e29a112a981063354ada8c3e675efdaffa3 Mon Sep 17 00:00:00 2001 From: Jon Pugh Date: Wed, 19 Oct 2016 16:04:50 -0400 Subject: [PATCH 12/59] Issue #2212149: Improve task queue AJAX refresh. Progress in implementing Vue.js. - Fixing link to task logs. --- task/views-view-table--hosting-task-list--block.tpl.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/task/views-view-table--hosting-task-list--block.tpl.php b/task/views-view-table--hosting-task-list--block.tpl.php index b88790be..9060dabe 100644 --- a/task/views-view-table--hosting-task-list--block.tpl.php +++ b/task/views-view-table--hosting-task-list--block.tpl.php @@ -42,7 +42,7 @@ {{ task.hosting_task_task_type }}: {{ task.node_hosting_task_title }} - {{ task.task_link_text }} + {{ task.task_link_text }} From b16e3dcdb65424f3d0d307607b6b135ec9040b52 Mon Sep 17 00:00:00 2001 From: Jon Pugh Date: Wed, 19 Oct 2016 16:12:30 -0400 Subject: [PATCH 13/59] Issue #2212149: Improve task queue AJAX refresh. Progress in implementing Vue.js. - Add a watch function to allow for attachingBehaviors --- task/hosting_task.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/task/hosting_task.js b/task/hosting_task.js index 9adf1300..9b027eaa 100644 --- a/task/hosting_task.js +++ b/task/hosting_task.js @@ -9,6 +9,11 @@ data: { tasks: Drupal.settings.hostingTasks.tasks, }, + watch: { + tasks: function (val) { + // Drupal.attachBehaviors('#hostingTasks a'); + }, + } }); // Attach to the available_tasks block, if there is one. From 293f21a45bf52cb4838237b26d9c3e11e11a7c21 Mon Sep 17 00:00:00 2001 From: Jon Pugh Date: Wed, 19 Oct 2016 16:23:57 -0400 Subject: [PATCH 14/59] Issue #2212149: Improve task queue AJAX refresh. Progress in implementing Vue.js. - Only show view link if there is a task nid. --- task/hosting_task.module | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/task/hosting_task.module b/task/hosting_task.module index f7d86a29..b3019652 100644 --- a/task/hosting_task.module +++ b/task/hosting_task.module @@ -1614,7 +1614,7 @@ function hosting_task_fetch_tasks($rid) { $task_type = $task['task_type']; // View Logs link - if (drupal_valid_path("hosting/task/{$nid}")) { + if (!empty($nid) && drupal_valid_path("hosting/task/{$nid}")) { $task['view_link'] = array( 'url' => url("hosting/task/{$nid}"), 'title' => t('Display the task log.'), From fd15e79f6579a5be33b7709708b0494a007860db Mon Sep 17 00:00:00 2001 From: Jon Pugh Date: Wed, 19 Oct 2016 19:11:49 -0400 Subject: [PATCH 15/59] Issue #2212149: Improve task queue AJAX refresh. Progress in implementing Vue.js. - Hide tasks if they are not permitted and they have no task NID. - Add "disabled" buttons. - Hide the entire row if the task is "hidden". --- task/hosting-task-table.tpl.php | 15 +++++++-- task/hosting_task.module | 55 +++------------------------------ 2 files changed, 18 insertions(+), 52 deletions(-) diff --git a/task/hosting-task-table.tpl.php b/task/hosting-task-table.tpl.php index dd833092..63c989ed 100644 --- a/task/hosting-task-table.tpl.php +++ b/task/hosting-task-table.tpl.php @@ -13,7 +13,7 @@