From 05c8d321c10319ac4ec30e8263fa422261351d65 Mon Sep 17 00:00:00 2001 From: Loic d'Anterroches Date: Fri, 5 Dec 2008 20:37:24 +0100 Subject: [PATCH] Added developer/user dashboard for all the projects. This fixes issue 60. --- src/IDF/Views/User.php | 94 ++++++++++++++++++++++- src/IDF/conf/urls.php | 15 ++++ src/IDF/templates/idf/base-full.html | 2 +- src/IDF/templates/idf/base-simple.html | 4 +- src/IDF/templates/idf/base.html | 2 +- src/IDF/templates/idf/user/dashboard.html | 15 ++++ 6 files changed, 127 insertions(+), 5 deletions(-) create mode 100644 src/IDF/templates/idf/user/dashboard.html diff --git a/src/IDF/Views/User.php b/src/IDF/Views/User.php index 0c741bc..457c4d4 100644 --- a/src/IDF/Views/User.php +++ b/src/IDF/Views/User.php @@ -32,6 +32,74 @@ Pluf::loadFunction('Pluf_Shortcuts_RenderToResponse'); */ class IDF_Views_User { + /** + * Dashboard of a user. + * + * Shows all the open issues assigned to the user. + * + * TODO: This views is a SQL horror. What needs to be done to cut + * by many the number of SQL queries: + * - Add a table to cache the open/closed status ids for all the + * projects. + * - Left join the issues with the project to get the shortname. + * + */ + public $dashboard_precond = array('Pluf_Precondition::loginRequired'); + public function dashboard($request, $match, $working=true) + { + + $otags = array(); + // Note that this approach does not scale, we will need to add + // a table to cache the meaning of the tags for large forges. + foreach (IDF_Views::getProjects($request->user) as $project) { + $otags = array_merge($otags, $project->getTagIdsByStatus('open')); + } + if (count($otags) == 0) $otags[] = 0; + if ($working) { + $title = __('Your Dashboard - Working Issues'); + $f_sql = new Pluf_SQL('owner=%s AND status IN ('.implode(', ', $otags).')', array($request->user->id)); + } else { + $title = __('Your Dashboard - Submitted Issues'); + $f_sql = new Pluf_SQL('submitter=%s AND status IN ('.implode(', ', $otags).')', array($request->user->id)); + } + + // Get stats about the issues + $sql = new Pluf_SQL('submitter=%s AND status IN ('.implode(', ', $otags).')', array($request->user->id)); + $nb_submit = Pluf::factory('IDF_Issue')->getCount(array('filter'=>$sql->gen())); + $sql = new Pluf_SQL('owner=%s AND status IN ('.implode(', ', $otags).')', array($request->user->id)); + $nb_owner = Pluf::factory('IDF_Issue')->getCount(array('filter'=>$sql->gen())); + // Paginator to paginate the issues + $pag = new Pluf_Paginator(new IDF_Issue()); + $pag->class = 'recent-issues'; + $pag->item_extra_props = array('current_user' => $request->user); + $pag->summary = __('This table shows the open issues.'); + $pag->forced_where = $f_sql; + $pag->action = ($working) ? 'idf_dashboard' : 'idf_dashboard_submit'; + $pag->sort_order = array('modif_dtime', 'ASC'); // will be reverted + $pag->sort_reverse_order = array('modif_dtime'); + $list_display = array( + 'id' => __('Id'), + array('project', 'Pluf_Paginator_FkToString', __('Project')), + array('summary', 'IDF_Views_IssueSummaryAndLabels', __('Summary')), + array('status', 'IDF_Views_Issue_ShowStatus', __('Status')), + array('modif_dtime', 'Pluf_Paginator_DateAgo', __('Last Updated')), + ); + $pag->configure($list_display, array(), array('status', 'modif_dtime')); + $pag->items_per_page = 10; + $pag->no_results_text = ($working) ? __('No issues are assigned to you, yeah!') : __('All the issues you submitted are fixed, yeah!'); + $pag->setFromRequest($request); + return Pluf_Shortcuts_RenderToResponse('idf/user/dashboard.html', + array( + 'page_title' => $title, + 'nb_submit' => $nb_submit, + 'nb_owner' => $nb_owner, + 'issues' => $pag, + ), + $request); + + + } + /** * Simple management of the base info of the user. */ @@ -81,4 +149,28 @@ class IDF_Views_User $request); } -} \ No newline at end of file +} + +/** + * Display the summary of an issue, then on a new line, display the + * list of labels with a link to a view "by label only". + * + * The summary of the issue is linking to the issue. + */ +function IDF_Views_IssueSummaryAndLabels($field, $issue, $extra='') +{ + $project = $issue->get_project(); + $edit = Pluf_HTTP_URL_urlForView('IDF_Views_Issue::view', + array($project->shortname, $issue->id)); + $tags = array(); + foreach ($issue->get_tags_list() as $tag) { + $url = Pluf_HTTP_URL_urlForView('IDF_Views_Issue::listLabel', + array($project->shortname, $tag->id, 'open')); + $tags[] = sprintf('%s', $url, Pluf_esc((string) $tag)); + } + $out = ''; + if (count($tags)) { + $out = '
'.implode(', ', $tags).''; + } + return sprintf('%s', $edit, Pluf_esc($issue->summary)).$out; +} diff --git a/src/IDF/conf/urls.php b/src/IDF/conf/urls.php index 43693ca..30b5ee9 100644 --- a/src/IDF/conf/urls.php +++ b/src/IDF/conf/urls.php @@ -43,6 +43,21 @@ $ctl[] = array('regex' => '#^/preferences/$#', 'model' => 'IDF_Views_User', 'method' => 'myAccount'); +$ctl[] = array('regex' => '#^/dashboard/$#', + 'base' => $base, + 'priority' => 4, + 'model' => 'IDF_Views_User', + 'method' => 'dashboard', + 'name' => 'idf_dashboard'); + +$ctl[] = array('regex' => '#^/dashboard/submitted/$#', + 'base' => $base, + 'priority' => 4, + 'model' => 'IDF_Views_User', + 'method' => 'dashboard', + 'params' => false, + 'name' => 'idf_dashboard_submit'); + $ctl[] = array('regex' => '#^/u/(.*)/$#', 'base' => $base, 'priority' => 4, diff --git a/src/IDF/templates/idf/base-full.html b/src/IDF/templates/idf/base-full.html index 60c5639..0c09933 100644 --- a/src/IDF/templates/idf/base-full.html +++ b/src/IDF/templates/idf/base-full.html @@ -35,7 +35,7 @@
{if $project}

{$project}

{/if}

-{if !$user.isAnonymous()}{aurl 'url', 'IDF_Views_User::myAccount'}{blocktrans}Welcome, {$user}.{/blocktrans} {trans 'Sign Out'}{else}{trans 'Sign in or create your account'}{/if} +{if !$user.isAnonymous()}{aurl 'url', 'idf_dashboard'}{blocktrans}Welcome, {$user}.{/blocktrans} {trans 'Sign Out'}{else}{trans 'Sign in or create your account'}{/if} {if $project} | {trans 'Project List'}{/if} | {trans 'Help'}

diff --git a/src/IDF/templates/idf/base-simple.html b/src/IDF/templates/idf/base-simple.html index a2502fb..2da5bed 100644 --- a/src/IDF/templates/idf/base-simple.html +++ b/src/IDF/templates/idf/base-simple.html @@ -34,8 +34,8 @@

-{if !$user.isAnonymous()}{aurl 'url', 'IDF_Views_User::myAccount'}{blocktrans}Welcome, {$user}.{/blocktrans} {trans 'Sign Out'}{else}{trans 'Sign in or create your account'}{/if} -{if $isAdmin}| {trans 'Administer'}{/if} +{if !$user.isAnonymous()}{aurl 'url', 'idf_dashboard'}{blocktrans}Welcome, {$user}.{/blocktrans} {trans 'Sign Out'}{else}{trans 'Sign in or create your account'}{/if} + | {trans 'Project List'} {if $isAdmin}| {trans 'Administer'}{/if} | {trans 'Help'}

{block title}{$page_title}{/block}

diff --git a/src/IDF/templates/idf/base.html b/src/IDF/templates/idf/base.html index 069f9ff..cc6137b 100644 --- a/src/IDF/templates/idf/base.html +++ b/src/IDF/templates/idf/base.html @@ -35,7 +35,7 @@
{if $project}

{$project}

{/if}

-{if !$user.isAnonymous()}{aurl 'url', 'IDF_Views_User::myAccount'}{blocktrans}Welcome, {$user}.{/blocktrans} {trans 'Sign Out'}{else}{trans 'Sign in or create your account'}{/if} +{if !$user.isAnonymous()}{aurl 'url', 'idf_dashboard'}{blocktrans}Welcome, {$user}.{/blocktrans} {trans 'Sign Out'}{else}{trans 'Sign in or create your account'}{/if} {if $project} | {trans 'Project List'}{/if} {if $isAdmin}| {trans 'Administer'}{/if} | {trans 'Help'} diff --git a/src/IDF/templates/idf/user/dashboard.html b/src/IDF/templates/idf/user/dashboard.html new file mode 100644 index 0000000..67f9856 --- /dev/null +++ b/src/IDF/templates/idf/user/dashboard.html @@ -0,0 +1,15 @@ +{extends "idf/base-simple.html"} +{block body} +{$issues.render} +{/block} +{block context} +{if $nb_owner > 0} +

{trans 'Working issues:'} {$nb_owner}

+{/if} +

{trans 'Submitted issues:'} {$nb_submit}

+{aurl 'url', 'IDF_Views_User::myAccount'} +

{blocktrans}Update your account.{/blocktrans}

+{aurl 'url', 'IDF_Views_User::view', array($user.login)} +

{blocktrans}See your public profile.{/blocktrans}

+{/block} +