Skip to content

Commit

Permalink
Merge pull request #831 from rdmorganiser/order_tasks_views
Browse files Browse the repository at this point in the history
Order tasks/issues an views in projects
  • Loading branch information
jochenklar authored Nov 24, 2023
2 parents 749f45e + ed83257 commit 971fa7f
Show file tree
Hide file tree
Showing 20 changed files with 126 additions and 9 deletions.
8 changes: 6 additions & 2 deletions rdmo/management/assets/js/components/edit/EditTask.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,18 @@ const EditTask = ({ config, task, elements, elementActions}) => {
rows={4} onChange={updateTask} />

<div className="row">
<div className="col-sm-6">
<div className="col-sm-4">
<Checkbox config={config} element={task} field="locked"
onChange={updateTask} />
</div>
<div className="col-sm-6">
<div className="col-sm-4">
<Checkbox config={config} element={task} field="available"
onChange={updateTask} />
</div>
<div className="col-sm-4">
<Number config={config} element={task} field="order"
onChange={updateTask} />
</div>
</div>

<Tabs id="#task-tabs" defaultActiveKey={0} animation={false}>
Expand Down
9 changes: 7 additions & 2 deletions rdmo/management/assets/js/components/edit/EditView.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import get from 'lodash/get'

import CodeMirror from './common/CodeMirror'
import Checkbox from './common/Checkbox'
import Number from './common/Number'
import Select from './common/Select'
import Text from './common/Text'
import Textarea from './common/Textarea'
Expand Down Expand Up @@ -70,14 +71,18 @@ const EditView = ({ config, view, elements, elementActions }) => {
rows={4} onChange={updateView} />

<div className="row">
<div className="col-sm-6">
<div className="col-sm-4">
<Checkbox config={config} element={view} field="locked"
onChange={updateView} />
</div>
<div className="col-sm-6">
<div className="col-sm-4">
<Checkbox config={config} element={view} field="available"
onChange={updateView} />
</div>
<div className="col-sm-4">
<Number config={config} element={view} field="order"
onChange={updateView} />
</div>
</div>

<Tabs id="#view-tabs" defaultActiveKey={0} animation={false}>
Expand Down
17 changes: 16 additions & 1 deletion rdmo/management/assets/js/components/element/Task.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from 'react'
import PropTypes from 'prop-types'
import get from 'lodash/get'

import { filterElement } from '../../utils/filter'
import { buildPath } from '../../utils/location'
Expand All @@ -21,6 +22,8 @@ const Task = ({ config, task, elementActions, filter=false, filterSites=false, f
const toggleAvailable = () => elementActions.storeElement('tasks', {...task, available: !task.available })
const toggleLocked = () => elementActions.storeElement('tasks', {...task, locked: !task.locked })

const fetchCondition = (index) => elementActions.fetchElement('conditions', task.conditions[index])

return showElement && (
<li className="list-group-item">
<div className="element">
Expand All @@ -40,8 +43,20 @@ const Task = ({ config, task, elementActions, filter=false, filterSites=false, f
<div>
<p>
<strong>{gettext('Task')}{': '}</strong>
<CodeLink className="code-tasks" uri={task.uri} onClick={() => fetchEdit()} />
{task.title}
</p>
{
get(config, 'display.uri.tasks', true) && <p>
<CodeLink className="code-tasks" uri={task.uri} onClick={() => fetchEdit()} />
</p>
}
{
get(config, 'display.uri.conditions', true) && task.condition_uris.map((uri, index) => (
<p key={index}>
<CodeLink className="code-conditions" uri={uri} onClick={() => fetchCondition(index)} />
</p>
))
}
<ElementErrors element={task} />
</div>
</div>
Expand Down
12 changes: 12 additions & 0 deletions rdmo/management/assets/js/components/elements/Tasks.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { getUriPrefixes } from '../../utils/filter'

import { FilterString, FilterUriPrefix, FilterSite} from '../common/Filter'
import { BackButton, NewButton } from '../common/Buttons'
import { Checkbox } from '../common/Checkboxes'

import Task from '../element/Task'

Expand All @@ -16,6 +17,9 @@ const Tasks = ({ config, tasks, configActions, elementActions }) => {
const updateFilterSite = (value) => configActions.updateConfig('filter.sites', value)
const updateFilterEditor = (value) => configActions.updateConfig('filter.editors', value)

const updateDisplayTasksURI = (value) => configActions.updateConfig('display.uri.tasks', value)
const updateDisplayConditionsURI = (value) => configActions.updateConfig('display.uri.conditions', value)

const createTask = () => elementActions.createElement('tasks')

return (
Expand Down Expand Up @@ -51,6 +55,14 @@ const Tasks = ({ config, tasks, configActions, elementActions }) => {
</>
}
</div>
<div className="checkboxes">
<span className="mr-10">{gettext('Show URIs:')}</span>
<Checkbox label={<code className="code-tasks">{gettext('Tasks')}</code>}
value={get(config, 'display.uri.tasks', true)} onChange={updateDisplayTasksURI} />
<Checkbox label={<code className="code-conditions">{gettext('Conditions')}</code>}
value={get(config, 'display.uri.conditions', true)} onChange={updateDisplayConditionsURI} />
</div>

</div>

<ul className="list-group">
Expand Down
17 changes: 17 additions & 0 deletions rdmo/projects/migrations/0060_alter_issue_options.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Generated by Django 4.2.6 on 2023-11-18 10:23

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('projects', '0059_project_progress'),
]

operations = [
migrations.AlterModelOptions(
name='issue',
options={'ordering': ('project__title', 'task__uri'), 'verbose_name': 'Issue', 'verbose_name_plural': 'Issues'},
),
]
2 changes: 1 addition & 1 deletion rdmo/projects/models/issue.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class Issue(models.Model):
)

class Meta:
ordering = ('project__title', )
ordering = ('project__title', 'task__uri')
verbose_name = _('Issue')
verbose_name_plural = _('Issues')

Expand Down
4 changes: 2 additions & 2 deletions rdmo/projects/templates/projects/project_detail_views.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ <h2>{% trans 'Views' %}</h2>

{% include 'projects/project_detail_views_help.html' %}

{% if project.views.exists %}
{% if views %}

<table class="table">
<thead>
Expand All @@ -27,7 +27,7 @@ <h2>{% trans 'Views' %}</h2>
</th>
</thead>
<tbody>
{% for view in project.views.all %}
{% for view in views %}
<tr>
<td>
<a href="{% url 'project_view' project.pk view.pk %}">{{ view.title }}</a>
Expand Down
5 changes: 4 additions & 1 deletion rdmo/projects/views/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,10 @@ def get_context_data(self, **kwargs):
context['memberships'] = memberships.order_by('user__last_name', '-project__level')
context['integrations'] = integrations.order_by('provider_key', '-project__level')
context['providers'] = get_plugins('PROJECT_ISSUE_PROVIDERS')
context['issues'] = [issue for issue in project.issues.all() if issue.resolve(values)]
context['issues'] = [
issue for issue in project.issues.order_by('-status', 'task__order', 'task__uri') if issue.resolve(values)
]
context['views'] = project.views.order_by('order', 'uri')
context['snapshots'] = project.snapshots.all()
context['invites'] = project.invites.all()
context['membership'] = Membership.objects.filter(project=project, user=self.request.user).first()
Expand Down
2 changes: 2 additions & 0 deletions rdmo/tasks/imports.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ def import_task(element, save=False, user=None):

set_common_fields(task, element)

task.order = element.get('order') or 0

set_lang_field(task, 'title', element)
set_lang_field(task, 'text', element)

Expand Down
18 changes: 18 additions & 0 deletions rdmo/tasks/migrations/0036_task_order.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 4.2.6 on 2023-11-18 10:23

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('tasks', '0035_uri_path'),
]

operations = [
migrations.AddField(
model_name='task',
name='order',
field=models.IntegerField(default=0, help_text='The position of this task in lists.', verbose_name='Order'),
),
]
5 changes: 5 additions & 0 deletions rdmo/tasks/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ class Task(TranslationMixin, models.Model):
verbose_name=_('Locked'),
help_text=_('Designates whether this task can be changed.')
)
order = models.IntegerField(
default=0,
verbose_name=_('Order'),
help_text=_('The position of this task in lists.')
)
catalogs = models.ManyToManyField(
Catalog, blank=True,
verbose_name=_('Catalogs'),
Expand Down
1 change: 1 addition & 0 deletions rdmo/tasks/renderers/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ def render_task(self, xml, task):
self.render_text_element(xml, 'uri_prefix', {}, task['uri_prefix'])
self.render_text_element(xml, 'uri_path', {}, task['uri_path'])
self.render_text_element(xml, 'dc:comment', {}, task['comment'])
self.render_text_element(xml, 'order', {}, task['order'])

for lang_code, lang_string, lang_field in get_languages():
self.render_text_element(xml, 'title', {'lang': lang_code}, task['title_%s' % lang_code])
Expand Down
1 change: 1 addition & 0 deletions rdmo/tasks/serializers/export.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class Meta:
'uri_prefix',
'uri_path',
'comment',
'order',
'start_attribute',
'end_attribute',
'days_before',
Expand Down
7 changes: 7 additions & 0 deletions rdmo/tasks/serializers/v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ class TaskSerializer(TranslationSerializerMixin, ElementModelSerializerMixin,
warning = serializers.SerializerMethodField()
read_only = serializers.SerializerMethodField()

condition_uris = serializers.SerializerMethodField()

projects_count = serializers.IntegerField(read_only=True)

class Meta:
Expand All @@ -33,6 +35,7 @@ class Meta:
'uri_path',
'comment',
'locked',
'order',
'available',
'catalogs',
'sites',
Expand All @@ -47,6 +50,7 @@ class Meta:
'text',
'warning',
'read_only',
'condition_uris',
'projects_count',
)
trans_fields = (
Expand All @@ -61,6 +65,9 @@ class Meta:
'title',
)

def get_condition_uris(self, obj):
return [condition.uri for condition in obj.conditions.all()]


class TaskIndexSerializer(serializers.ModelSerializer):

Expand Down
1 change: 1 addition & 0 deletions rdmo/views/imports.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ def import_view(element, save=False, user=None):

set_common_fields(view, element)

view.order = element.get('order') or 0
view.template = element.get('template')

set_lang_field(view, 'title', element)
Expand Down
18 changes: 18 additions & 0 deletions rdmo/views/migrations/0029_view_order.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 4.2.6 on 2023-11-18 10:23

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('views', '0028_uri_path'),
]

operations = [
migrations.AddField(
model_name='view',
name='order',
field=models.IntegerField(default=0, help_text='The position of this view in lists.', verbose_name='Order'),
),
]
5 changes: 5 additions & 0 deletions rdmo/views/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ class View(models.Model, TranslationMixin):
verbose_name=_('Locked'),
help_text=_('Designates whether this view can be changed.')
)
order = models.IntegerField(
default=0,
verbose_name=_('Order'),
help_text=_('The position of this view in lists.')
)
catalogs = models.ManyToManyField(
Catalog, blank=True,
verbose_name=_('Catalogs'),
Expand Down
1 change: 1 addition & 0 deletions rdmo/views/renderers/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ def render_view(self, xml, view):
self.render_text_element(xml, 'uri_prefix', {}, view['uri_prefix'])
self.render_text_element(xml, 'uri_path', {}, view['uri_path'])
self.render_text_element(xml, 'dc:comment', {}, view['comment'])
self.render_text_element(xml, 'order', {}, view['order'])

for lang_code, lang_string, lang_field in get_languages():
self.render_text_element(xml, 'title', {'lang': lang_code}, view['title_%s' % lang_code])
Expand Down
1 change: 1 addition & 0 deletions rdmo/views/serializers/export.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class Meta:
'uri_prefix',
'uri_path',
'comment',
'order',
'catalogs',
'template'
)
Expand Down
1 change: 1 addition & 0 deletions rdmo/views/serializers/v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class Meta:
'uri_path',
'comment',
'locked',
'order',
'available',
'catalogs',
'sites',
Expand Down

0 comments on commit 971fa7f

Please sign in to comment.