From 4e3e8c1158c6e6e4f337551ce2099ec36e3ba418 Mon Sep 17 00:00:00 2001 From: Gorrie Date: Mon, 25 Jan 2016 19:08:57 +1300 Subject: [PATCH 1/8] Added links via templates MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Now additional links can be added via mysite yml file. Example ‘’’ DevTasks: tasks: devtest: title: 'Dev/Test' link: 'dev/tests/all' ‘’’ --- code/DevTasks.php | 37 ++++++++++++++++++++++++ code/FancyDevBuild.php | 12 -------- javascript/LeftAndMain.Fancy-devbuild.js | 10 +++---- 3 files changed, 41 insertions(+), 18 deletions(-) create mode 100644 code/DevTasks.php delete mode 100644 code/FancyDevBuild.php diff --git a/code/DevTasks.php b/code/DevTasks.php new file mode 100644 index 0000000..6f9ab79 --- /dev/null +++ b/code/DevTasks.php @@ -0,0 +1,37 @@ + array( + 'title' => 'Dev/Build', + 'link' => 'dev/build' + ) + ); + $config_tasks = Config::inst()->get(__CLASS__, 'tasks'); + // debug::dump($config_tasks); + $tasks = array_merge_recursive($default_tasks, $config_tasks); + + foreach ($tasks as $item => $values) { + // Add your own attributes onto the link. In our case, we want to + // open the link in a new window (not the original) + $attributes = array( + 'class' => 'devbuild-trigger', + 'target' => '_blank', + 'data-title' => $values['title'], + 'data-link' => $values['link'] + ); + + // priority controls the ordering of the link in the stack. The + // lower the number, the lower in the list + $priority = -90; + CMSMenu::add_link($item, $values['title'], '#', $priority, $attributes); + } + } +} diff --git a/code/FancyDevBuild.php b/code/FancyDevBuild.php deleted file mode 100644 index 63f2cec..0000000 --- a/code/FancyDevBuild.php +++ /dev/null @@ -1,12 +0,0 @@ - Dev/Build'); // look out for click $(dev_trigger).click(function(e) { @@ -11,11 +9,11 @@ e.preventDefault(); if ($this.data("executing")) return false; - $this.set_trigger("Building...","loading"); + $this.set_trigger("Building...", "loading"); $.ajax({ method: "POST", - url: "dev/build" + url: $this.data('link') }) .done(function( data, textStatus, xhr ) { // remove classes @@ -24,7 +22,7 @@ // search for any errors from returned data if (data.search("ERROR") > 0) { // change text to show an error has occured - $this.attr('href', 'dev/build') + $this.attr('href', $this.data('link')) .set_trigger("Build failed","error"); setTimeout(function(){ $this.reset_trigger(); @@ -63,7 +61,7 @@ .removeClass("error loading success") .removeData("executing") .children(".text") - .text("Dev/Build"); + .text($(this).data('title')); }; }(jQuery)); From 4df8be8a7b97e8f0021518a3c2274ce942100e1a Mon Sep 17 00:00:00 2001 From: Gorrie Date: Mon, 25 Jan 2016 19:47:10 +1300 Subject: [PATCH 2/8] Code clean up --- code/DevTasks.php | 5 ++--- javascript/LeftAndMain.Fancy-devbuild.js | 4 +++- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/code/DevTasks.php b/code/DevTasks.php index 6f9ab79..cfbc8b6 100644 --- a/code/DevTasks.php +++ b/code/DevTasks.php @@ -15,7 +15,7 @@ public function init() { ) ); $config_tasks = Config::inst()->get(__CLASS__, 'tasks'); - // debug::dump($config_tasks); + $tasks = array_merge_recursive($default_tasks, $config_tasks); foreach ($tasks as $item => $values) { @@ -23,7 +23,6 @@ public function init() { // open the link in a new window (not the original) $attributes = array( 'class' => 'devbuild-trigger', - 'target' => '_blank', 'data-title' => $values['title'], 'data-link' => $values['link'] ); @@ -31,7 +30,7 @@ public function init() { // priority controls the ordering of the link in the stack. The // lower the number, the lower in the list $priority = -90; - CMSMenu::add_link($item, $values['title'], '#', $priority, $attributes); + CMSMenu::add_link($item, '', '#', $priority, $attributes); } } } diff --git a/javascript/LeftAndMain.Fancy-devbuild.js b/javascript/LeftAndMain.Fancy-devbuild.js index 4b82b19..b8286c7 100644 --- a/javascript/LeftAndMain.Fancy-devbuild.js +++ b/javascript/LeftAndMain.Fancy-devbuild.js @@ -4,7 +4,9 @@ default_doc_title = document.title; // look out for click - $(dev_trigger).click(function(e) { + $(dev_trigger).each(function(){ + $(this).children('.text').text($(this).data('title')); + }).click(function(e) { var $this = $(this); e.preventDefault(); if ($this.data("executing")) return false; From 68a3d108193674d279582a089c428666081f129a Mon Sep 17 00:00:00 2001 From: Gorrie Date: Mon, 25 Jan 2016 20:00:07 +1300 Subject: [PATCH 3/8] Added reset timer to config and added default values --- code/DevTasks.php | 8 +++++--- javascript/LeftAndMain.Fancy-devbuild.js | 4 ++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/code/DevTasks.php b/code/DevTasks.php index cfbc8b6..2d9746c 100644 --- a/code/DevTasks.php +++ b/code/DevTasks.php @@ -11,7 +11,8 @@ public function init() { $default_tasks = array( 'devbuild' => array( 'title' => 'Dev/Build', - 'link' => 'dev/build' + 'link' => 'dev/build', + 'reset_time' => '5000' ) ); $config_tasks = Config::inst()->get(__CLASS__, 'tasks'); @@ -23,8 +24,9 @@ public function init() { // open the link in a new window (not the original) $attributes = array( 'class' => 'devbuild-trigger', - 'data-title' => $values['title'], - 'data-link' => $values['link'] + 'data-title' => (isset($values['title']) ? $values['title'] : $item), + 'data-link' => $values['link'], + 'data-reset-time' => (isset($values['reset_time']) ? $values['reset_time'] : '5000') ); // priority controls the ordering of the link in the stack. The diff --git a/javascript/LeftAndMain.Fancy-devbuild.js b/javascript/LeftAndMain.Fancy-devbuild.js index b8286c7..e841181 100644 --- a/javascript/LeftAndMain.Fancy-devbuild.js +++ b/javascript/LeftAndMain.Fancy-devbuild.js @@ -1,13 +1,13 @@ (function($) { var dev_trigger = ".devbuild-trigger", - reset_time = 5000, default_doc_title = document.title; // look out for click $(dev_trigger).each(function(){ $(this).children('.text').text($(this).data('title')); }).click(function(e) { - var $this = $(this); + var $this = $(this), + reset_time = $this.data('reset-time'); e.preventDefault(); if ($this.data("executing")) return false; From b421309b973ef2cc1c9e9218d627602b733f4488 Mon Sep 17 00:00:00 2001 From: Gorrie Date: Mon, 25 Jan 2016 20:14:47 +1300 Subject: [PATCH 4/8] Removed recursive array merge Removed recursive array merge --- code/DevTasks.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/DevTasks.php b/code/DevTasks.php index 2d9746c..d2121d4 100644 --- a/code/DevTasks.php +++ b/code/DevTasks.php @@ -17,7 +17,7 @@ public function init() { ); $config_tasks = Config::inst()->get(__CLASS__, 'tasks'); - $tasks = array_merge_recursive($default_tasks, $config_tasks); + $tasks = array_merge($default_tasks, $config_tasks); foreach ($tasks as $item => $values) { // Add your own attributes onto the link. In our case, we want to From 6a01e83422a97d81aa242ada2663b309b1a0882d Mon Sep 17 00:00:00 2001 From: Gorrie Date: Mon, 25 Jan 2016 20:18:37 +1300 Subject: [PATCH 5/8] Fixed check for changes --- javascript/LeftAndMain.Fancy-devbuild.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/javascript/LeftAndMain.Fancy-devbuild.js b/javascript/LeftAndMain.Fancy-devbuild.js index e841181..80df028 100644 --- a/javascript/LeftAndMain.Fancy-devbuild.js +++ b/javascript/LeftAndMain.Fancy-devbuild.js @@ -31,7 +31,7 @@ }, reset_time); } else { // change text back to default - changes = $().find("li[style='color: blue'").length; + changes = $().find("li[style='color: blue'], li[style='color: green'").length; $this.set_trigger(changes+" Changes occurred","success"); setTimeout(function(){ $this.reset_trigger(); From 70bc5e8a9baa2709ae0c15dcbe7b54a3206c85e6 Mon Sep 17 00:00:00 2001 From: Gorrie Date: Mon, 25 Jan 2016 20:33:03 +1300 Subject: [PATCH 6/8] Fixed summary --- javascript/LeftAndMain.Fancy-devbuild.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/javascript/LeftAndMain.Fancy-devbuild.js b/javascript/LeftAndMain.Fancy-devbuild.js index 80df028..3900ac6 100644 --- a/javascript/LeftAndMain.Fancy-devbuild.js +++ b/javascript/LeftAndMain.Fancy-devbuild.js @@ -31,7 +31,7 @@ }, reset_time); } else { // change text back to default - changes = $().find("li[style='color: blue'], li[style='color: green'").length; + changes = $(data).find("li[style='color: blue'], li[style='color: green']").length; $this.set_trigger(changes+" Changes occurred","success"); setTimeout(function(){ $this.reset_trigger(); From 8afd6eecec05aab937eb61881efa2ed225a3f0ee Mon Sep 17 00:00:00 2001 From: Gorrie Date: Mon, 25 Jan 2016 20:35:05 +1300 Subject: [PATCH 7/8] Added extension --- _config/config.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/_config/config.yml b/_config/config.yml index d41f9f9..11b734c 100644 --- a/_config/config.yml +++ b/_config/config.yml @@ -7,6 +7,5 @@ LeftAndMain: - 'fancy-devbuild/javascript/LeftAndMain.Fancy-devbuild.js' extra_requirements_css: - 'fancy-devbuild/css/fancydevbuild.css' -ContentController: extensions: - - FancyDevBuild + - DevTasks From feed0899d73099d11b108986812c0dffd1d4391d Mon Sep 17 00:00:00 2001 From: Gorrie Date: Mon, 25 Jan 2016 20:52:57 +1300 Subject: [PATCH 8/8] Added check for array from config and code clean --- code/DevTasks.php | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/code/DevTasks.php b/code/DevTasks.php index d2121d4..ed6a2c7 100644 --- a/code/DevTasks.php +++ b/code/DevTasks.php @@ -3,25 +3,26 @@ /** * Fancy Dev Build base class * - * @package fancy-devbuild + * @package DevTasks * */ class DevTasks extends LeftAndMainExtension { public function init() { - $default_tasks = array( + $tasks = array( 'devbuild' => array( 'title' => 'Dev/Build', 'link' => 'dev/build', 'reset_time' => '5000' ) ); - $config_tasks = Config::inst()->get(__CLASS__, 'tasks'); - $tasks = array_merge($default_tasks, $config_tasks); + $config_tasks = Config::inst()->get(__CLASS__, 'tasks'); + if (is_array($config_tasks)) { + $tasks = array_merge($tasks, $config_tasks); + } foreach ($tasks as $item => $values) { - // Add your own attributes onto the link. In our case, we want to - // open the link in a new window (not the original) + $attributes = array( 'class' => 'devbuild-trigger', 'data-title' => (isset($values['title']) ? $values['title'] : $item),