diff --git a/client/actions/assignments/api.ts b/client/actions/assignments/api.ts index 0f0a425cd..b451ccf8f 100644 --- a/client/actions/assignments/api.ts +++ b/client/actions/assignments/api.ts @@ -162,6 +162,7 @@ const query = ({ dateFilter = null, size = null, ignoreScheduledUpdates = false, + max_results = null, }) => ( (dispatch, getState, {api}) => { const filterByValues = { @@ -190,6 +191,7 @@ const query = ({ return api('assignments').query({ page: page, + max_results: max_results, sort: sort, source: JSON.stringify(size !== null ? {query, size} : diff --git a/client/actions/assignments/tests/api_test.ts b/client/actions/assignments/tests/api_test.ts index 42e9c8e60..7a2f6e48b 100644 --- a/client/actions/assignments/tests/api_test.ts +++ b/client/actions/assignments/tests/api_test.ts @@ -152,6 +152,7 @@ describe('actions.assignments.api', () => { page: 2, sort: '[("_created", 1)]', source: source, + max_results: null, }); done(); @@ -180,6 +181,7 @@ describe('actions.assignments.api', () => { page: 3, sort: '[("_updated", -1)]', source: source, + max_results: null, }); done(); @@ -208,6 +210,7 @@ describe('actions.assignments.api', () => { page: 3, sort: '[("_updated", -1)]', source: source, + max_results: null }); done(); @@ -236,6 +239,7 @@ describe('actions.assignments.api', () => { page: 3, sort: '[("_updated", -1)]', source: source, + max_results: null, }); done(); @@ -263,6 +267,7 @@ describe('actions.assignments.api', () => { page: 3, sort: '[("_updated", -1)]', source: source, + max_results: null, }); done(); @@ -290,6 +295,7 @@ describe('actions.assignments.api', () => { page: 3, sort: '[("priority", -1)]', source: source, + max_results: null, }); done(); @@ -317,6 +323,7 @@ describe('actions.assignments.api', () => { page: 3, sort: '[("priority", 1)]', source: source, + max_results: null, }); done(); @@ -371,6 +378,7 @@ describe('actions.assignments.api', () => { page: 1, sort: '[("priority", 1)]', source: source, + max_results: null, }); done(); @@ -399,6 +407,7 @@ describe('actions.assignments.api', () => { page: 1, sort: '[("_updated", -1)]', source: source, + max_results: null, }); done(); diff --git a/client/actions/assignments/tests/ui_test.ts b/client/actions/assignments/tests/ui_test.ts index 6fa8fed53..1a11f60be 100644 --- a/client/actions/assignments/tests/ui_test.ts +++ b/client/actions/assignments/tests/ui_test.ts @@ -116,6 +116,7 @@ describe('actions.assignments.ui', () => { type: null, priority: null, ignoreScheduledUpdates: false, + max_results: 100, }]); expect(assignmentsApi.receivedAssignments.callCount).toBe(1); diff --git a/client/actions/assignments/ui.ts b/client/actions/assignments/ui.ts index 05c58ed0e..ef788479c 100644 --- a/client/actions/assignments/ui.ts +++ b/client/actions/assignments/ui.ts @@ -201,6 +201,9 @@ const queryAndSetAssignmentListGroups = (groupKey, page = 1) => ( querySearchSettings.page = page; querySearchSettings.dateFilter = group.dateFilter; querySearchSettings.orderDirection = assignmentListSelectors.sortOrder(getState()); + if (group.max_results) { + querySearchSettings.max_results = group.max_results; + } return dispatch(assignments.api.query(querySearchSettings)) .then((data) => { diff --git a/client/constants/assignments.ts b/client/constants/assignments.ts index d497e0b81..3e5e6d4cd 100644 --- a/client/constants/assignments.ts +++ b/client/constants/assignments.ts @@ -86,18 +86,21 @@ export const ASSIGNMENTS = { id: 'TODO', label: 'To Do', states: ['assigned', 'submitted'], + max_results: 100, emptyMessage: 'There are no assignments to do', }, IN_PROGRESS: { id: 'IN_PROGRESS', label: 'In Progress', states: ['in_progress'], + max_results: 100, emptyMessage: 'There are no assignments in progress', }, COMPLETED: { id: 'COMPLETED', label: 'Completed', states: ['completed', 'cancelled'], + max_results: 100, emptyMessage: 'There are no assignments completed', }, CURRENT: { diff --git a/server/planning/assignments/assignments.py b/server/planning/assignments/assignments.py index ff0e2dbec..95012c881 100644 --- a/server/planning/assignments/assignments.py +++ b/server/planning/assignments/assignments.py @@ -85,29 +85,43 @@ def on_fetched_item_archive(self, doc): def _enhance_archive_items(self, docs): ids = [str(item["assignment_id"]) for item in docs if item.get("assignment_id")] - assignments = { - str(item[config.ID_FIELD]): item for item in self.get_from_mongo(req=None, lookup={"_id": {"$in": ids}}) - } + if len(ids): + assignments = { + str(item[config.ID_FIELD]): item for item in self.get_from_mongo(req=None, lookup={"_id": {"$in": ids}}) + } - for doc in docs: - if doc.get("assignment_id") in assignments: - doc["assignment"] = assignments[doc["assignment_id"]].get("assigned_to") or {} + for doc in docs: + if doc.get("assignment_id") in assignments: + doc["assignment"] = assignments[doc["assignment_id"]].get("assigned_to") or {} def on_fetched(self, docs): - for doc in docs["_items"]: - self._enchance_assignment(doc) + self._enhance_assignments(docs.get("_items", [])) def on_fetched_item(self, doc): - self._enchance_assignment(doc) + self._enhance_assignments([doc]) - def _enchance_assignment(self, doc): + def _enhance_assignments(self, docs): """Populate `item_ids` with ids for all linked Archive items for an Assignment""" + items = list(self.get_archive_items_for_assignments([str(doc.get(config.ID_FIELD)) for doc in docs])) + for doc in docs: + ids = [str(item.get("_id")) for item in items if str(item.get("assignment_id")) == str(doc.get("_id"))] + if len(ids): + doc["item_ids"] = ids + + self.set_type(doc, doc) - results = self.get_archive_items_for_assignment(doc) - if results.count() > 0: - doc["item_ids"] = [str(item.get(config.ID_FIELD)) for item in results] + def get_archive_items_for_assignments(self, assignment_ids): + """ + Given an array of assignment id's return the matching items + :param assignment_ids: + :return: + """ + query = {"query": {"filtered": {"filter": {"terms": {"assignment_id": assignment_ids}}}}} - self.set_type(doc, doc) + req = ParsedRequest() + repos = "archive,published,archived" + req.args = {"source": json.dumps(query), "repo": repos} + return get_resource_service("search").get(req=req, lookup=None) def get_archive_items_for_assignment(self, assignment): """Using the `search` resource service, retrieve the list of Archive items linked to the provided Assignment."""