From 0f8d5b314c4fde06474a70d38aa87b47581028c9 Mon Sep 17 00:00:00 2001 From: Robert Lyon Date: Tue, 21 May 2019 12:37:10 +1200 Subject: [PATCH] Bug 1829940: Placeholder block This patch does the following: - Create new blocktype 'placeholder' - Make sure it is copyable - Make sure it is versionable - Allow tags for it and that it works with create page via tags - Populate instance config with content types using 'showmore' pagination behatnotneeded Change-Id: I8437fbab587b5dc8661512ce8d227161f0129475 Signed-off-by: Robert Lyon --- .../placeholder/blockoptions.json.php | 57 +++++++++ .../lang/en.utf8/blocktype.placeholder.php | 18 +++ htdocs/blocktype/placeholder/lib.php | 112 ++++++++++++++++++ htdocs/blocktype/placeholder/version.php | 16 +++ htdocs/js/paginator.js | 4 + htdocs/js/views.js | 8 ++ htdocs/lib/db/upgrade.php | 7 ++ htdocs/lib/version.php | 2 +- htdocs/lib/web.php | 3 + .../blocktype/placeholder/templates/body.tpl | 1 + .../placeholder/templates/contenttypes.tpl | 11 ++ .../templates/contenttypeslist.tpl | 8 ++ .../raw/sass/layout/card/_card-quarter.scss | 22 ++++ .../features/user_content/placeholder.feature | 27 +++++ 14 files changed, 295 insertions(+), 1 deletion(-) create mode 100644 htdocs/blocktype/placeholder/blockoptions.json.php create mode 100644 htdocs/blocktype/placeholder/lang/en.utf8/blocktype.placeholder.php create mode 100644 htdocs/blocktype/placeholder/lib.php create mode 100644 htdocs/blocktype/placeholder/version.php create mode 100644 htdocs/theme/raw/plugintype/blocktype/placeholder/templates/body.tpl create mode 100644 htdocs/theme/raw/plugintype/blocktype/placeholder/templates/contenttypes.tpl create mode 100644 htdocs/theme/raw/plugintype/blocktype/placeholder/templates/contenttypeslist.tpl create mode 100644 test/behat/features/user_content/placeholder.feature diff --git a/htdocs/blocktype/placeholder/blockoptions.json.php b/htdocs/blocktype/placeholder/blockoptions.json.php new file mode 100644 index 0000000000..96bb7c43d3 --- /dev/null +++ b/htdocs/blocktype/placeholder/blockoptions.json.php @@ -0,0 +1,57 @@ + $count, + 'limit' => $limit, + 'offset' => $offset, + 'orderby' => 'popular', + 'databutton' => 'showmorebtn', + 'jscall' => 'wire_blockoptions', + 'jsonscript' => 'blocktype/placeholder/blockoptions.json.php', + 'extra' => array('viewid' => $viewid), +)); + +$smarty = smarty_core(); +$smarty->assign('types', $types); +$typeslist = $smarty->fetch('blocktype:placeholder:contenttypeslist.tpl'); +$typeslist .= $pagination['html']; + +json_reply(false, array( + 'message' => null, + 'data' => array( + 'tablerows' => $typeslist, + 'pagination_js' => $pagination['javascript'], + 'count' => $count, + 'results' => $count . ' ' . ($count == 1 ? get_string('result') : get_string('results')), + 'offset' => $offset, + 'setlimit' => $setlimit, + 'jscall' => 'wire_blockoptions', + ) +)); diff --git a/htdocs/blocktype/placeholder/lang/en.utf8/blocktype.placeholder.php b/htdocs/blocktype/placeholder/lang/en.utf8/blocktype.placeholder.php new file mode 100644 index 0000000000..ca43bf67e2 --- /dev/null +++ b/htdocs/blocktype/placeholder/lang/en.utf8/blocktype.placeholder.php @@ -0,0 +1,18 @@ + 500); + } + + public static function render_instance(BlockInstance $instance, $editing=false, $versioning=false) { + global $USER, $THEME; + $configdata = $instance->get('configdata'); + + $smarty = smarty_core(); + $smarty->assign('placeholdertext', get_string('placeholdertext', 'blocktype.placeholder')); + return $smarty->fetch('blocktype:placeholder:body.tpl'); + } + + public static function has_instance_config() { + return true; + } + + public static function instance_config_form(BlockInstance $instance) { + global $USER; + + $view = $instance->get_view(); + + $elements = array(); + $elements['types'] = array( + 'type' => 'fieldset', + 'legend' => get_string('contenttypes', 'blocktype.placeholder'), + 'elements' => array( + 'contenttypes' => array( + 'type' => 'html', + 'value' => '', + ), + ), + ); + $offset = 0; + $limit = 4; + list($count, $types) = self::get_content_types($view, $offset, $limit); + $pagination = build_showmore_pagination(array( + 'count' => $count, + 'limit' => $limit, + 'offset' => $offset, + 'orderby' => 'popular', + 'databutton' => 'showmorebtn', + 'jscall' => 'wire_blockoptions', + 'jsonscript' => 'blocktype/placeholder/blockoptions.json.php', + 'extra' => array('viewid' => $view->get('id')), + )); + $smarty = smarty_core(); + $smarty->assign('types', $types); + $typeslist = $smarty->fetch('blocktype:placeholder:contenttypeslist.tpl'); + $smarty->assign('typeslist', $typeslist); + $smarty->assign('pagination', $pagination); + $typeshtml = $smarty->fetch('blocktype:placeholder:contenttypes.tpl'); + + $elements['types']['elements']['contenttypes']['value'] = $typeshtml; + $elements['tags'] = array( + 'type' => 'tags', + 'title' => get_string('tags'), + 'description' => get_string('tagsdescblock'), + 'defaultvalue' => $instance->get('tags'), + 'help' => false, + ); + + return $elements; + } + + public static function instance_config_save($values, $instance) { + unset($values['contenttypes']); + return $values; + } + + public static function get_content_types($view, $offset = 0, $limit = 8) { + $categories = $view->get('categorydata'); + $blocks = array(); + foreach ($categories as $c) { + $blocktypes = PluginBlockType::get_blocktypes_for_category($c['name'], $view); + if ($c['name'] == 'shortcut') { + foreach ($blocktypes as $key => $blocktype) { + if ($blocktype['name'] == 'placeholder') { + unset($blocktypes[$key]); // do not allow placeholder to select itself + } + } + } + $blocks = array_merge($blocks, $blocktypes); + } + $count = count($blocks); + $blocks = array_slice($blocks, $offset, $limit); + return array($count, $blocks); + } +} diff --git a/htdocs/blocktype/placeholder/version.php b/htdocs/blocktype/placeholder/version.php new file mode 100644 index 0000000000..6eb3867d15 --- /dev/null +++ b/htdocs/blocktype/placeholder/version.php @@ -0,0 +1,16 @@ +version = 2019052100; +$config->release = '1.0.0'; diff --git a/htdocs/js/paginator.js b/htdocs/js/paginator.js index 011354cd9a..fba02c8a6c 100644 --- a/htdocs/js/paginator.js +++ b/htdocs/js/paginator.js @@ -323,6 +323,10 @@ function pagination_showmore(btn) { sendjsonrequest(config['wwwroot'] + btn.data('jsonscript'), params, 'POST', function(data) { var btnid = btn.prop('id'); btn.parent().replaceWith(data.data.tablerows); + // Run post 'show more' js function if needed + if (data.data.jscall) { + window[data.data.jscall](); + } // we have a new 'showmore' button so wire it up jQuery('#' + btnid).on('click', function(e) { e.preventDefault(); diff --git a/htdocs/js/views.js b/htdocs/js/views.js index 16b72fe828..baeec690de 100644 --- a/htdocs/js/views.js +++ b/htdocs/js/views.js @@ -172,6 +172,10 @@ } + ViewManager.blockOptions = function() { + console.log('in block options'); + } + //Private Methods ///////////////// function init() { @@ -1402,3 +1406,7 @@ function blockConfigSuccess(form, data) { function blockConfigError(form, data) { return ViewManager.blockConfigError(form, data); } + +function wire_blockoptions() { + return ViewManager.blockOptions(); +} diff --git a/htdocs/lib/db/upgrade.php b/htdocs/lib/db/upgrade.php index d444f09dca..cb9918dd32 100644 --- a/htdocs/lib/db/upgrade.php +++ b/htdocs/lib/db/upgrade.php @@ -1382,5 +1382,12 @@ function xmldb_core_upgrade($oldversion=0) { } } + if ($oldversion < 2019080200) { + log_debug('Force install of placeholder block plugin'); + if ($data = check_upgrades('blocktype.placeholder')) { + upgrade_plugin($data); + } + } + return $status; } diff --git a/htdocs/lib/version.php b/htdocs/lib/version.php index cf4fb201c9..0e56a5a979 100644 --- a/htdocs/lib/version.php +++ b/htdocs/lib/version.php @@ -16,7 +16,7 @@ $config = new stdClass(); // See https://wiki.mahara.org/wiki/Developer_Area/Version_Numbering_Policy // For upgrades on stable branches, increment the version by one. On master, use the date. -$config->version = 2019062600; +$config->version = 2019080200; $config->series = '19.10'; $config->release = '19.10dev'; $config->minupgradefrom = 2017031605; diff --git a/htdocs/lib/web.php b/htdocs/lib/web.php index 1da42b2943..25c72aca80 100755 --- a/htdocs/lib/web.php +++ b/htdocs/lib/web.php @@ -4464,6 +4464,9 @@ function build_showmore_pagination($params) { $js .= ' pagination_showmore(jQuery(this));'; $js .= ' }'; $js .= '});' . "\n"; + if (isset($params['jscall']) && $params['jscall']) { + $js .= 'window[\'' . $params['jscall'] . '\']();' . "\n"; + } } return array('html' => $output, 'javascript' => $js); diff --git a/htdocs/theme/raw/plugintype/blocktype/placeholder/templates/body.tpl b/htdocs/theme/raw/plugintype/blocktype/placeholder/templates/body.tpl new file mode 100644 index 0000000000..e1b666c197 --- /dev/null +++ b/htdocs/theme/raw/plugintype/blocktype/placeholder/templates/body.tpl @@ -0,0 +1 @@ +

{str tag=placeholdertext section=blocktype.placeholder}

\ No newline at end of file diff --git a/htdocs/theme/raw/plugintype/blocktype/placeholder/templates/contenttypes.tpl b/htdocs/theme/raw/plugintype/blocktype/placeholder/templates/contenttypes.tpl new file mode 100644 index 0000000000..5b6f4ae3fa --- /dev/null +++ b/htdocs/theme/raw/plugintype/blocktype/placeholder/templates/contenttypes.tpl @@ -0,0 +1,11 @@ +
+{$typeslist|safe} +{if $pagination.html} + {$pagination.html|safe} +{/if} +
+{if $pagination.javascript} + +{/if} diff --git a/htdocs/theme/raw/plugintype/blocktype/placeholder/templates/contenttypeslist.tpl b/htdocs/theme/raw/plugintype/blocktype/placeholder/templates/contenttypeslist.tpl new file mode 100644 index 0000000000..1e4d67e6d1 --- /dev/null +++ b/htdocs/theme/raw/plugintype/blocktype/placeholder/templates/contenttypeslist.tpl @@ -0,0 +1,8 @@ +{foreach from=$types item=type} +
+
+
+
{$type.title}
+
+
+{/foreach} diff --git a/htdocs/theme/raw/sass/layout/card/_card-quarter.scss b/htdocs/theme/raw/sass/layout/card/_card-quarter.scss index 2431a9400a..3974bebb3a 100644 --- a/htdocs/theme/raw/sass/layout/card/_card-quarter.scss +++ b/htdocs/theme/raw/sass/layout/card/_card-quarter.scss @@ -222,6 +222,28 @@ } } +.card-option { + width: 50%; + float: left; + padding-left: 15px; + padding-right: 15px; + margin-bottom: 30px; + height: 60px; + @include media-breakpoint-up(md) { + width: 25%; + } + .card { + padding: 10px; + cursor: pointer; + div { + text-align: center; + &.icon { + padding-bottom: 5px; + } + } + } +} + // Make collection list dropdown align right on the right most card .card-quarter { &:nth-child(even) .collection-list .dropdown-menu, diff --git a/test/behat/features/user_content/placeholder.feature b/test/behat/features/user_content/placeholder.feature new file mode 100644 index 0000000000..6bd95a726e --- /dev/null +++ b/test/behat/features/user_content/placeholder.feature @@ -0,0 +1,27 @@ +@javascript @core @blocktype @blocktype_placeholder +Feature: Adding a placeholder block to a page + As a student + I need to be able to add a placeholder block to my portfolio + +Background: +Given the following "users" exist: + | username | password | email | firstname | lastname | institution | authname | role | + | UserA | Kupuh1pa! | UserA@example.org | Angela | User | mahara | internal | member | + + And the following "pages" exist: + | title | description | ownertype | ownername | + | Page UserA_01 | Page 01| user | UserA | + +Scenario: + # Logging in as a user + Given I log in as "UserA" with password "Kupuh1pa!" + And I choose "Pages and collections" in "Create" from main menu + And I click on "Edit" in "Page UserA_01" card menu + # Add a placeholder block + And I follow "Placeholder" in the "blocktype sidebar" property + And I press "Add" + And I fill in the following: + | Block title | Mahara placeholder block | + And I press "Save" + And I display the page + Then I should see "Please configure the block to choose what type of block this should be" -- GitLab