Commit 0f8d5b31 authored by Robert Lyon's avatar Robert Lyon

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's avatarRobert Lyon <robertl@catalyst.net.nz>
parent 4a5ce96d
<?php
/**
*
* @package mahara
* @subpackage core
* @author Catalyst IT Ltd
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL version 3 or later
* @copyright For copyright information on Mahara, please see the README file distributed with this software.
*
*/
define('INTERNAL', 1);
define('JSON', 1);
require(dirname(dirname(dirname(__FILE__))) . '/init.php');
require_once(get_config('libroot') . 'view.php');
safe_require('blocktype', 'placeholder');
$offset = param_integer('offset', 0);
$limit = param_integer('limit', 8);
$viewid = param_integer('viewid');
if (!can_view_view($viewid)) {
json_reply('local', get_string('accessdenied', 'error'));
}
$view = new View($viewid);
$setlimit = false;
$orderby = param_alphanum('orderby', null);
list($count, $types) = PluginBlocktypePlaceholder::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' => $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',
)
));
<?php
/**
*
* @package mahara
* @subpackage blocktype-inbox
* @author Catalyst IT Ltd
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL version 3 or later
* @copyright For copyright information on Mahara, please see the README file distributed with this software.
*
*/
defined('INTERNAL') || die();
$string['title'] = 'Placeholder';
$string['description'] = 'Placeholder block that allows you to select what type of block you want';
$string['placeholdertext'] = 'Please configure the block to choose what type of block this should be';
$string['defaulttitledescription'] = 'A default title will be generated if you leave the title field blank';
$string['contenttypes'] = 'Content types';
<?php
/**
*
* @package mahara
* @subpackage blocktype-inbox
* @author Catalyst IT Ltd
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL version 3 or later
* @copyright For copyright information on Mahara, please see the README file distributed with this software.
*
*/
defined('INTERNAL') || die();
class PluginBlocktypePlaceholder extends MaharaCoreBlocktype {
public static function get_title() {
return get_string('title', 'blocktype.placeholder');
}
public static function get_description() {
return get_string('description', 'blocktype.placeholder');
}
public static function get_categories() {
return array('shortcut' => 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);
}
}
<?php
/**
*
* @package mahara
* @subpackage blocktype-inbox
* @author Catalyst IT Ltd
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL version 3 or later
* @copyright For copyright information on Mahara, please see the README file distributed with this software.
*
*/
defined('INTERNAL') || die();
$config = new stdClass();
$config->version = 2019052100;
$config->release = '1.0.0';
......@@ -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();
......
......@@ -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();
}
......@@ -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;
}
......@@ -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;
......
......@@ -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);
......
<p class="content-text lead text-center">{str tag=placeholdertext section=blocktype.placeholder}</p>
\ No newline at end of file
<div id="placeholderlist">
{$typeslist|safe}
{if $pagination.html}
{$pagination.html|safe}
{/if}
</div>
{if $pagination.javascript}
<script>
{$pagination.javascript|safe}
</script>
{/if}
{foreach from=$types item=type}
<div class="card-option card-quarter">
<div class="card placeholder btn-secondary" data-option="{$type.name}" title="{$type.description}">
<div class="icon icon-lg icon-{$type.cssicon}"></div>
<div>{$type.title}</div>
</div>
</div>
{/foreach}
......@@ -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,
......
@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"
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment