Commit ed4debdc authored by Richard Mansfield's avatar Richard Mansfield
Browse files

Add render_self for plan artefact


Signed-off-by: default avatarRichard Mansfield <richardm@catalyst.net.nz>
parent 41be8bcf
......@@ -78,7 +78,7 @@ class PluginBlocktypePlans extends PluginBlocktype {
public static function build_plans_html(&$tasks, $editing=false, BlockInstance $instance) {
$smarty = smarty_core();
$smarty->assign_by_ref('tasks', $tasks);
$tasks['tablerows'] = $smarty->fetch('blocktype:plans:taskrows.tpl');
$tasks['tablerows'] = $smarty->fetch('artefact:plans:taskrows.tpl');
if ($editing) {
return;
}
......@@ -89,7 +89,7 @@ class PluginBlocktypePlans extends PluginBlocktype {
'class' => 'center nojs-hidden-block',
'datatable' => 'tasktable_' . $blockid,
'url' => $baseurl,
'jsonscript' => 'artefact/plans/blocktype/plans/tasks.json.php',
'jsonscript' => 'artefact/plans/viewtasks.json.php',
'count' => $tasks['count'],
'limit' => $tasks['limit'],
'offset' => $tasks['offset'],
......
......@@ -230,9 +230,32 @@ class ArtefactTypePlan extends ArtefactType {
return $elements;
}
// @TODO
public function render_self() {
return array('html' => '<div>' . hsc($this->title) . '</div>', 'javascript' => '');
public function render_self($options) {
$this->add_to_render_path($options);
$tasks = ArtefactTypeTask::get_tasks($this->id);
$template = 'artefact:plans:taskrows.tpl';
$baseurl = get_config('wwwroot') . 'view/artefact.php?artefact=' . $this->id . '&view=' . $options['viewid'];
$pagination = array(
'baseurl' => $baseurl,
'id' => 'task_pagination',
'datatable' => 'tasklist',
'jsonscript' => 'artefact/plans/viewtasks.json.php',
);
ArtefactTypeTask::render_tasks($tasks, $template, $options, $pagination);
$smarty = smarty_core();
$smarty->assign_by_ref('tasks', $tasks);
$smarty->assign(
'artefacttitle',
'<a href="' . get_config('wwwroot') . 'view/artefact.php?artefact=' . $this->id
. '&view=' . $options['viewid'] . '">' . hsc($this->title) . '</a>'
);
$smarty->assign('plan', $this);
return array('html' => $smarty->fetch('artefact:plans:viewplan.tpl'), 'javascript' => '');
}
}
......@@ -454,7 +477,6 @@ class ArtefactTypeTask extends ArtefactType {
* @return array (count: integer, data: array)
*/
public static function get_tasks($plan, $offset=0, $limit=10) {
global $USER;
$datenow = time(); // time now to use for formatting tasks by completion
($results = get_records_sql_array("
......@@ -462,10 +484,9 @@ class ArtefactTypeTask extends ArtefactType {
a.title, a.description, a.parent
FROM {artefact} a
JOIN {artefact_plans_task} at ON at.artefact = a.id
WHERE a.owner = ? AND a.artefacttype = 'task'
AND a.parent = ?
WHERE a.artefacttype = 'task' AND a.parent = ?
ORDER BY at.completiondate DESC
LIMIT ? OFFSET ?", array($USER->get('id'), $plan, $limit, $offset)))
LIMIT ? OFFSET ?", array($plan, $limit, $offset)))
|| ($results = array());
// format the date and setup completed for display if task is incomplete
......@@ -482,7 +503,7 @@ class ArtefactTypeTask extends ArtefactType {
}
$result = array(
'count' => count_records('artefact', 'owner', $USER->get('id'), 'artefacttype', 'task', 'parent', $plan),
'count' => count_records('artefact', 'artefacttype', 'task', 'parent', $plan),
'data' => $results,
'offset' => $offset,
'limit' => $limit,
......@@ -521,6 +542,32 @@ class ArtefactTypeTask extends ArtefactType {
$tasks['pagination'] = $pagination['html'];
$tasks['pagination_js'] = $pagination['javascript'];
}
// @TODO: make blocktype use this too
public function render_tasks(&$tasks, $template, $options, $pagination) {
$smarty = smarty_core();
$smarty->assign_by_ref('tasks', $tasks);
$smarty->assign_by_ref('options', $options);
$tasks['tablerows'] = $smarty->fetch($template);
if ($tasks['limit']) {
$pagination = build_pagination(array(
'id' => $pagination['id'],
'class' => 'center',
'datatable' => $pagination['datatable'],
'url' => $pagination['baseurl'],
'jsonscript' => $pagination['jsonscript'],
'count' => $tasks['count'],
'limit' => $tasks['limit'],
'offset' => $tasks['offset'],
'numbersincludefirstlast' => false,
'resultcounttextsingular' => get_string('task', 'artefact.plans'),
'resultcounttextplural' => get_string('tasks', 'artefact.plans'),
));
$tasks['pagination'] = $pagination['html'];
$tasks['pagination_js'] = $pagination['javascript'];
}
}
}
?>
<table id="tasktable">
<colgroup width="50%" span="2"></colgroup>
<thead>
<tr>
<th class="c1">{str tag='completiondate' section='artefact.plans'}</th>
<th class="c2">{str tag='title' section='artefact.plans'}</th>
<th class="c3">{str tag='completed' section='artefact.plans'}</th>
</tr>
</thead>
<tbody>
{$tasks.tablerows|safe}
</tbody>
</table>
<div id="plans_page_container">{$tasks.pagination|safe}</div>
<script>
{literal}
function rewriteTaskTitles() {
forEach(
getElementsByTagAndClassName('a', 'task-title','tasktable'),
function(element) {
connect(element, 'onclick', function(e) {
e.stop();
var description = getFirstElementByTagAndClassName('div', 'task-desc', element.parentNode);
toggleElementClass('hidden', description);
});
}
);
}
addLoadEvent(function() {
{/literal}{$tasks.pagination_js|safe}{literal}
removeElementClass('plans_page_container', 'hidden');
});
function TaskPager() {
var self = this;
paginatorProxy.addObserver(self);
connect(self, 'pagechanged', rewriteTaskTitles);
}
var taskPager = new TaskPager();
addLoadEvent(rewriteTaskTitles);
{/literal}
</script>
......@@ -28,17 +28,36 @@
define('INTERNAL', 1);
define('JSON', 1);
require(dirname(dirname(dirname(dirname(dirname(__FILE__))))) . '/init.php');
require(dirname(dirname(dirname(__FILE__))) . '/init.php');
safe_require('artefact', 'plans');
require_once(get_config('docroot') . 'blocktype/lib.php');
require_once(get_config('docroot') . 'artefact/plans/blocktype/plans/lib.php');
$limit = param_integer('limit', 10);
$offset = param_integer('offset', 0);
$bi = new BlockInstance(param_integer('block'));
$configdata = $bi->get('configdata');
$limit = param_integer('limit', 10);
if ($blockid = param_integer('block', null)) {
$bi = new BlockInstance($blockid);
$configdata = $bi->get('configdata');
$tasks = ArtefactTypeTask::get_tasks($configdata['artefactid'], $offset, $limit);
PluginBlocktypePlans::build_plans_html($tasks, false, $bi);
}
else {
$planid = param_integer('artefact');
$viewid = param_integer('view');
$options = array('viewid' => $viewid);
$tasks = ArtefactTypeTask::get_tasks($planid, $offset, $limit);
$template = 'artefact:plans:taskrows.tpl';
$baseurl = get_config('wwwroot') . 'view/artefact.php?artefact=' . $planid . '&view=' . $options['viewid'];
$pagination = array(
'baseurl' => $baseurl,
'id' => 'task_pagination',
'datatable' => 'tasklist',
'jsonscript' => 'artefact/plans/viewtasks.json.php',
);
$tasks = ArtefactTypeTask::get_tasks($configdata['artefactid'], $offset, $limit);
PluginBlocktypePlans::build_plans_html($tasks, false, $bi);
ArtefactTypeTask::render_tasks($tasks, $template, $options, $pagination);
}
json_reply(false, (object) array('message' => false, 'data' => $tasks));
......@@ -643,8 +643,7 @@ class BlockInstance {
// If this block is for just one artefact, we set the title of the
// block to be a link to view more information about that artefact
$configdata = $this->get('configdata');
// @TODO: Remove this hack soon, once plan artefact has render_self.
if (!empty($configdata['artefactid']) && $this->get('blocktype') != 'plans') {
if (!empty($configdata['artefactid'])) {
$smarty->assign('viewartefacturl', get_config('wwwroot') . 'view/artefact.php?artefact='
. $configdata['artefactid'] . '&view=' . $this->get('view'));
}
......
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