Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

change sort ordering and date displays on dashboards #2320

Merged
merged 4 commits into from
Dec 19, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doajtest/testdrive/todo_associate.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ def build_application(title, lmu_diff, cd_diff, status, editor=None):
ap.set_id(ap.makeid())
ap.set_last_manual_update(dates.before(datetime.utcnow(), lmu_diff))
ap.set_created(dates.before(datetime.utcnow(), cd_diff))
ap.set_date_applied(dates.before(datetime.utcnow(), cd_diff))
ap.set_application_status(status)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can be extract for other build_application to reuse


if editor is not None:
Expand Down
1 change: 1 addition & 0 deletions doajtest/testdrive/todo_editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ def build_application(title, lmu_diff, cd_diff, status, editor=None, editor_grou
ap.application_type = constants.APPLICATION_TYPE_NEW_APPLICATION
ap.set_last_manual_update(dates.before(datetime.utcnow(), lmu_diff))
ap.set_created(dates.before(datetime.utcnow(), cd_diff))
ap.set_date_applied(dates.before(datetime.utcnow(), cd_diff))
ap.set_application_status(status)

if editor is not None:
Expand Down
1 change: 1 addition & 0 deletions doajtest/testdrive/todo_maned_editor_associate.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ def build_application(title, lmu_diff, cd_diff, status, editor=None, editor_grou
ap.application_type = constants.APPLICATION_TYPE_NEW_APPLICATION
ap.set_last_manual_update(dates.before(datetime.utcnow(), lmu_diff))
ap.set_created(dates.before(datetime.utcnow(), cd_diff))
ap.set_date_applied(dates.before(datetime.utcnow(), cd_diff))
ap.set_application_status(status)

if editor is not None:
Expand Down
52 changes: 32 additions & 20 deletions portality/bll/services/todo.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ def _rationalise_todos(self, todos, size):
class TodoRules(object):
@classmethod
def maned_stalled(cls, size, maned_of):
sort_date = "created_date"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can be extract to global variable default_rule_sort_field

stalled = TodoQuery(
musts=[
TodoQuery.lmu_older_than(8),
Expand All @@ -166,13 +167,14 @@ def maned_stalled(cls, size, maned_of):
must_nots=[
TodoQuery.status([constants.APPLICATION_STATUS_ACCEPTED, constants.APPLICATION_STATUS_REJECTED])
],
sort="last_manual_update",
sort=sort_date,
size=size
)
return constants.TODO_MANED_STALLED, stalled, "last_manual_update", 0
return constants.TODO_MANED_STALLED, stalled, sort_date, 0

@classmethod
def maned_follow_up_old(cls, size, maned_of):
sort_date = "created_date"
follow_up_old = TodoQuery(
musts=[
TodoQuery.cd_older_than(10),
Expand All @@ -181,38 +183,41 @@ def maned_follow_up_old(cls, size, maned_of):
must_nots=[
TodoQuery.status([constants.APPLICATION_STATUS_ACCEPTED, constants.APPLICATION_STATUS_REJECTED])
],
sort="created_date",
sort=sort_date,
size=size
)
return constants.TODO_MANED_FOLLOW_UP_OLD, follow_up_old, "created_date", 0
return constants.TODO_MANED_FOLLOW_UP_OLD, follow_up_old, sort_date, 0

@classmethod
def maned_ready(cls, size, maned_of):
sort_date = "created_date"
ready = TodoQuery(
musts=[
TodoQuery.status([constants.APPLICATION_STATUS_READY]),
TodoQuery.editor_group(maned_of)
],
sort="last_manual_update",
sort=sort_date,
size=size
)
return constants.TODO_MANED_READY, ready, "created_date", 1
return constants.TODO_MANED_READY, ready, sort_date, 1

@classmethod
def maned_completed(cls, size, maned_of):
sort_date = "created_date"
completed = TodoQuery(
musts=[
TodoQuery.status([constants.APPLICATION_STATUS_COMPLETED]),
TodoQuery.lmu_older_than(2),
TodoQuery.editor_group(maned_of)
],
sort="last_manual_update",
sort=sort_date,
size=size
)
return constants.TODO_MANED_COMPLETED, completed, "last_manual_update", 0
return constants.TODO_MANED_COMPLETED, completed, sort_date, 0

@classmethod
def maned_assign_pending(cls, size, maned_of):
sort_date = "created_date"
assign_pending = TodoQuery(
musts=[
TodoQuery.exists("admin.editor_group"),
Expand All @@ -223,13 +228,14 @@ def maned_assign_pending(cls, size, maned_of):
must_nots=[
TodoQuery.exists("admin.editor")
],
sort="created_date",
sort=sort_date,
size=size
)
return constants.TODO_MANED_ASSIGN_PENDING, assign_pending, "last_manual_update", 0
return constants.TODO_MANED_ASSIGN_PENDING, assign_pending, sort_date, 0

@classmethod
def editor_stalled(cls, groups, size):
sort_date = "created_date"
stalled = TodoQuery(
musts=[
TodoQuery.lmu_older_than(6),
Expand All @@ -243,13 +249,14 @@ def editor_stalled(cls, groups, size):
constants.APPLICATION_STATUS_READY
])
],
sort="last_manual_update",
sort=sort_date,
size=size
)
return constants.TODO_EDITOR_STALLED, stalled, "last_manual_update", 0
return constants.TODO_EDITOR_STALLED, stalled, sort_date, 0

@classmethod
def editor_follow_up_old(cls, groups, size):
sort_date = "created_date"
follow_up_old = TodoQuery(
musts=[
TodoQuery.cd_older_than(8),
Expand All @@ -263,26 +270,28 @@ def editor_follow_up_old(cls, groups, size):
constants.APPLICATION_STATUS_READY
])
],
sort="created_date",
sort=sort_date,
size=size
)
return constants.TODO_EDITOR_FOLLOW_UP_OLD, follow_up_old, "created_date", 0
return constants.TODO_EDITOR_FOLLOW_UP_OLD, follow_up_old, sort_date, 0

@classmethod
def editor_completed(cls, groups, size):
sort_date = "created_date"
completed = TodoQuery(
musts=[
TodoQuery.status([constants.APPLICATION_STATUS_COMPLETED]),
TodoQuery.editor_groups(groups),
TodoQuery.is_new_application()
],
sort="last_manual_update",
sort=sort_date,
size=size
)
return constants.TODO_EDITOR_COMPLETED, completed, "last_manual_update", 1
return constants.TODO_EDITOR_COMPLETED, completed, sort_date, 1

@classmethod
def editor_assign_pending(cls, groups, size):
sort_date = "created_date"
assign_pending = TodoQuery(
musts=[
TodoQuery.editor_groups(groups),
Expand All @@ -292,14 +301,14 @@ def editor_assign_pending(cls, groups, size):
must_nots=[
TodoQuery.exists("admin.editor")
],
sort="created_date",
sort=sort_date,
size=size
)
return constants.TODO_EDITOR_ASSIGN_PENDING, assign_pending, "created_date", 1
return constants.TODO_EDITOR_ASSIGN_PENDING, assign_pending, sort_date, 1

@classmethod
def associate_stalled(cls, acc_id, size):
sort_field = "last_manual_update"
sort_field = "created_date"
stalled = TodoQuery(
musts=[
TodoQuery.lmu_older_than(3),
Expand Down Expand Up @@ -383,7 +392,10 @@ class TodoQuery(object):
~~^->Elasticsearch:Technology~~
"""
lmu_sort = {"last_manual_update" : {"order" : "asc"}}
cd_sort = {"created_date" : {"order" : "asc"}}
# cd_sort = {"created_date" : {"order" : "asc"}}
# NOTE that admin.date_applied and created_date should be the same for applications, but for some reason this is not always the case
# therefore, we take a created_date sort to mean a date_applied sort
cd_sort = {"admin.date_applied": {"order": "asc"}}

def __init__(self, musts=None, must_nots=None, sort="last_manual_update", size=10):
self._musts = [] if musts is None else musts
Expand Down
11 changes: 10 additions & 1 deletion portality/models/v2/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from portality import constants
from portality.core import app
from portality.lib import es_data_mapping
from portality.lib import es_data_mapping, coerce, dates
from portality.models.v2 import shared_structs
from portality.models.v2.journal import JournalLikeObject, Journal
from portality.lib.coerce import COERCE_MAP
Expand Down Expand Up @@ -150,10 +150,19 @@ def application_status(self):
def set_application_status(self, val):
self.__seamless__.set_with_struct("admin.application_status", val)

def set_date_applied(self, date=None):
if date is None:
date = dates.now_str()
self.__seamless__.set_with_struct("admin.date_applied", date)

@property
def date_applied(self):
return self.__seamless__.get_single("admin.date_applied")

@property
def date_applied_timestamp(self):
return self.__seamless__.get_single("admin.date_applied", coerce=coerce.to_datestamp())

@date_applied.setter
def date_applied(self, val):
self.__seamless__.set_with_struct("admin.date_applied", val)
Expand Down
4 changes: 2 additions & 2 deletions portality/templates/dashboard/_todo.html
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@
{% set action = TODOS[todo.action_id[0]] %}
{% set app_route = "admin.application" if current_user.has_role("admin") else "editor.application" %}
{% set app_url = url_for(app_route, application_id=todo.object_id) %}
{% set app_date = todo.object.created_timestamp %}
<li class="todo-list__item" data-app-url="{{ app_url }}">
{% set app_date = todo.object.date_applied_timestamp %}
<li class="todo-list__item" data-app-url="{{ app_url }}" data-action-ids="{{ todo.action_id|join(",") }}">
<article class="flex-col flex-space-between card card--compact" style="border-color: {{ action.colour }};">
<div class="flex">
<a href="{{ app_url }}" target="_blank" title="{{ todo.title }}">
Expand Down