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 !$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'}
-{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} +