Skip to content

Commit

Permalink
todo: Count and show series in the TODO list
Browse files Browse the repository at this point in the history
Signed-off-by: Damien Lespiau <damien.lespiau@intel.com>
  • Loading branch information
Damien Lespiau committed Feb 29, 2016
1 parent 2212916 commit dd3ea79
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 26 deletions.
16 changes: 9 additions & 7 deletions htdocs/js/patchwork.js
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,7 @@ var pw = (function() {
ctx.api_base_url = ctx.base_url + '/api/1.0';

exports.user = ctx.user;
exports.project = ctx.project;
};

exports.init = function(init_ctx) {
Expand Down Expand Up @@ -682,17 +683,20 @@ var pw = (function() {
}).data('selectize');
};

exports.setup_series_list = function(selector, url, ordering) {
exports.setup_series_list = function(selector, url, params) {
var table = $(selector);

if (typeof ordering == 'undefined')
ordering = '-last_updated';
var all_params = {
ordering: '-last_updated',
related: 'expand',
};
$.extend(all_params, params);

if (typeof url == 'undefined') {
url = '/projects/' + ctx.project.name + '/series/';
if (!window.location.search)
history.replaceState(null, null,
'?' + $.param({ ordering: ordering }));
'?' + $.param({ ordering: all_params.ordering }));
}

exports.table = ctx.table = create_table({
Expand All @@ -709,9 +713,7 @@ var pw = (function() {
'Tests':'test_state',
},
'api_url': ctx.api_base_url + url,
'api_params': {
related: 'expand',
}
'api_params': all_params,
});

table.bind('dynatable:preinit', function(e, dynatable) {
Expand Down
14 changes: 12 additions & 2 deletions patchwork/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,8 @@ def contributor_projects(self):
def sync_person(self):
pass

def n_todo_patches(self):
return self.todo_patches().count()
def n_todo(self):
return self.todo_patches().count() + self.todo_series().count()

def todo_patches(self, project=None):

Expand All @@ -181,6 +181,16 @@ def todo_patches(self, project=None):
.values('pk').query)
return qs

def todo_series(self, project=None):
# filter on project, if necessary
if project:
qs = Series.objects.filter(project=project)
else:
qs = Series.objects

qs = qs.filter(reviewer=self.user)
return qs

def __str__(self):
return self.name()

Expand Down
10 changes: 5 additions & 5 deletions patchwork/templates/patchwork/profile.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ <h1>Your Profile</h1>
<div class="leftcol">
<div class="box">
<h2>Todo</h2>
{% if user.profile.n_todo_patches %}
{% if user.profile.n_todo %}
<p>Your <a href="{% url 'patchwork.views.user.todo_lists' %}">todo
list</a> contains {{ user.profile.n_todo_patches }}
patch{{ user.profile.n_todo_patches|pluralize:"es" }}.</p>
list</a> contains {{ user.profile.n_todo }}
patch{{ user.profile.n_todo|pluralize:"es" }}.</p>
{% else %}
<p>Your todo list contains patches that have been delegated to you. You
have no items in your todo list at present.</p>
<p>Your todo list contains patches and series that have been assigned to you.
You have no items in your todo list at present.</p>
{% endif %}
</div>

Expand Down
27 changes: 23 additions & 4 deletions patchwork/templates/patchwork/todo-list.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,33 @@

{% block title %}{{ user }}'s todo list{% endblock %}

{% block headers %}
<script language="JavaScript" type="text/javascript">
$(function () {
pw.setup_series_list('#serieslist', '/series/', {
project: pw.project.pk,
reviewer: pw.user.pk,
});
});
</script>
{% endblock %}

{% block body %}
<h1>TODO</h1>

<p>A Patchwork Todo-list contains patches that are assigned to you, and
are in an "action required" state
({% for state in action_required_states %}{% if forloop.last and not forloop.first %} or {% endif %}{{ state }}{% if not forloop.last and not forloop.first %}, {%endif %}{% endfor %}), and are not archived.
</p>
<p>The Patchwork TODO-list contains patches and series that are assigned to you
and need your attention. </p>

{% if n_series %}
<h2>Series</h2>

{% include "patchwork/series-list-table.html" %}
{% endif %}

{% if n_patches %}
<h2>Patches</h2>

{% include "patchwork/patch-list.html" %}
{% endif %}

{% endblock %}
10 changes: 6 additions & 4 deletions patchwork/templates/patchwork/todo-lists.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,20 @@
<h1>TODO</h1>

{% if todo_lists %}
<p>You have multiple todo lists. Each todo list contains patches for a single
project.</p>
<p>You have multiple todo lists. Each todo list contains series and patches for
a single project.</p>
<table class="vertical">
<tr>
<th>project</th>
<th>patches</th>
<th>Project</th>
<th>Series</th>
<th>Patches</th>
</tr>
{% for todo_list in todo_lists %}
<tr>
<td><a
href="{% url 'patchwork.views.user.todo_list' project_id=todo_list.project.linkname %}"
>{{ todo_list.project.name }}</a></td>
<td class="numberformat">{{ todo_list.n_series }}</td>
<td class="numberformat">{{ todo_list.n_patches }}</td>
</tr>
{% endfor %}
Expand Down
13 changes: 11 additions & 2 deletions patchwork/views/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,10 +194,16 @@ def todo_lists(request):

for project in Project.objects.all():
patches = request.user.profile.todo_patches(project=project)
if not patches.count():
series = request.user.profile.todo_series(project=project)

n_series = series.count()
n_patches = patches.count()
if (n_series + n_patches) == 0:
continue

todo_lists.append({'project': project, 'n_patches': patches.count()})
todo_lists.append({'project': project,
'n_series': n_series,
'n_patches': n_patches})

if len(todo_lists) == 1:
return HttpResponseRedirect(
Expand All @@ -215,6 +221,7 @@ def todo_lists(request):
def todo_list(request, project_id):
project = get_object_or_404(Project, linkname=project_id)
patches = request.user.profile.todo_patches(project=project)
series = request.user.profile.todo_series(project=project)
filter_settings = [(DelegateFilter,
{'delegate': request.user})]

Expand All @@ -226,4 +233,6 @@ def todo_list(request, project_id):

context['action_required_states'] = \
State.objects.filter(action_required=True).all()
context['n_patches'] = patches.count()
context['n_series'] = series.count()
return render_to_response('patchwork/todo-list.html', context)
5 changes: 3 additions & 2 deletions templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
{% endif %}
{% if project %}
, project: {
pk: {{ project.pk }},
name: '{{ project.linkname }}',
is_editable: {{ is_editable|default:"false" }},
},
Expand Down Expand Up @@ -100,14 +101,14 @@
{% if user.is_authenticated %}
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">
<span class="badge">{{ user.profile.n_todo_patches }}</span>
<span class="badge">{{ user.profile.n_todo }}</span>
<strong>{{ user.username }}</strong>&nbsp;<span class="caret"></span>
</a>
<ul class="dropdown-menu" role="menu">
<li>
<a href="{% url 'patchwork.views.user.todo_lists' %}">
Reviews pending
<span class="badge">{{ user.profile.n_todo_patches }}</span>
<span class="badge">{{ user.profile.n_todo }}</span>
</a>
</li>
{% if user.is_staff %}
Expand Down

0 comments on commit dd3ea79

Please sign in to comment.