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

UHC Visits count and last visited date contact default sort #4770

Merged
merged 16 commits into from
Aug 15, 2018

Conversation

dianabarsan
Copy link
Member

Description

Adds visit count display in contacts list. Visit count display is conditioned by the same permission as displaying last visited date. Visits are counted based on the calendar month, with each month starting on either the 1st or on a configurable date. Visit counters may be color coded if a specific visit count goal configured.

Adds configuration option to enable contacts list to be sorted by last visited date by default.

Adds uhc configuration with options to enable/disable default sorting contacts lists by last visited date, visit counter settings for monthly count goal and the month reset/start date.

#4758
#4752

Review checklist

  • Readable: Concise, well named, follows the style guide, documented if necessary.
  • Documented: Announced in Changes.md in plain English. Configuration and user documentation on medic-docs
  • Tested: Unit and/or e2e where appropriate
  • Internationalised: All user facing text
  • Backwards compatible: Works with existing data and configuration or includes a migration. Any breaking changes documented in Changes.md.

@dianabarsan dianabarsan requested a review from SCdF August 6, 2018 18:36
@dianabarsan
Copy link
Member Author

Please review, @SCdF . Thanks!

@dianabarsan dianabarsan requested review from SCdF and removed request for SCdF August 13, 2018 06:45
Copy link
Contributor

@SCdF SCdF left a comment

Choose a reason for hiding this comment

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

Nice!

Some changes, specifically I don't think you need to reimplement Math.max (understandable, I presume you tried to use it in the row list item but found out LiveList's terrible secret!)

Really happy to see we don't need to emit ~30 times for every document!

@@ -35,6 +35,10 @@
@failed-state-color: #DA4548;
@received-state-color: #E9AA22;

/* Visit count progress colors */
@visits-started-color: #C38813;
Copy link
Contributor

Choose a reason for hiding this comment

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

"started" doesn't make much sense to me, given that it's used in context of a warning. I think either the warning flag should change or this var name should.

Maybe visit-goal-started / visit-goal-incomplete? (and visit-goal-done to match).

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure :)

],
"uhc": {
"contacts_default_sort": {
"last_visited_date": false
Copy link
Contributor

Choose a reason for hiding this comment

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

for later migratory reasons, unless there is a strong reason for this, IMO this should be "contacts_defaults_sort": "last_visited_date" and then we just inject that directly in later on (instead of checking the boolean).

Copy link
Member Author

Choose a reason for hiding this comment

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

The reason I structured it like this is so it's self explanatory and people who configure don't need to use exact word matches to get the configuration to work.

Copy link
Member Author

Choose a reason for hiding this comment

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

I switched it to the way you indicated but did not set the default config to use "last_visited_date" as default sort order, so this feature will need to be documented.
Also, I changed the sort string from camelCase to _underscore so configuration values are consistent ("lastVisitedDate" -> "last_visited_date").

if ($scope.lastVisitedDateExtras &&
uhcSettings.contacts_default_sort &&
uhcSettings.contacts_default_sort.last_visited_date) {
$scope.sortDirection = $scope.defaultSortDirection = 'lastVisitedDate';
Copy link
Contributor

Choose a reason for hiding this comment

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

.i.e. here we would say $scope.sortDirection = $scope.defaultSortDirection = uhcSettings.contacts_default_sort

doc.fields.visited_contact_uuid &&
liveList.contains({ _id: doc.fields.visited_contact_uuid })
) {
return true;
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe just return the boolean expression?

@@ -0,0 +1,18 @@
angular.module('inboxFilters').filter('maxInteger', function() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we need this filter? AFAICT it's only used in JS code that could just use Math.max

@@ -82,6 +83,23 @@ angular.module('inboxServices').factory('LiveListConfig',
scope.overdue = contact.lastVisitedDate <= oneMonthAgo;
scope.summary = $translate.instant('contact.last.visited.date', { date: relativeDayFilter(contact.lastVisitedDate, true) });
}

scope.visits = {
count: $translate.instant('contacts.visits.count', { count: maxIntegerFilter(contact.visitCount, 99) }),
Copy link
Contributor

Choose a reason for hiding this comment

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

replace with Math.max?

count: $translate.instant('contacts.visits.count', { count: maxIntegerFilter(contact.visitCount, 99) }),
summary: contact.visitCount === 1 ?
$translate.instant('contacts.visits.count.visit') :
$translate.instant('contacts.visits.count.visits'),
Copy link
Contributor

Choose a reason for hiding this comment

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

I haven't looked at what capabilities angular translate has, but a lot of them support plurals in the actual translation itself. This is useful as certain languages do plurals differently (I have no idea about the ones we support, but there are languages with no plurals, or 3-4 different states, etc)

Copy link
Member Author

Choose a reason for hiding this comment

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

This is correct! Thanks for pointing it out!

var stats = visitStats[row.key] || { lastVisitedDate: -1, visitCount: 0 };

if (stats.lastVisitedDate < row.value) {
stats.lastVisitedDate = row.value;
Copy link
Contributor

Choose a reason for hiding this comment

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

IDK if you find this easier to read, but this can be just Math.min

var lastVisitedDatePromise = getLastVisitedDates(searchResults, extensions.visitCountSettings);

result = $q
.all([ dataRecordsPromise, lastVisitedDatePromise ])
Copy link
Contributor

Choose a reason for hiding this comment

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

any reason for refactoring out passing a map to $q.all? IMO it's more readable, because you're not relying on an array matching up, and you get to actually name things.

Copy link
Member Author

Choose a reason for hiding this comment

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

I refactored it because the Q we used in Karma doesn't support mapping and I wanted to make the code testable. Promise.all doesn't support mapping either.

@@ -96,4 +98,177 @@ describe('Search service', function() {

});

describe('dateLastVisited', () => {
beforeEach(() => {
clock = sinon.useFakeTimers(moment('2018-08-20 18:18:18').valueOf());
Copy link
Contributor

Choose a reason for hiding this comment

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

cool, I did not know about this!

@dianabarsan dianabarsan requested a review from SCdF August 15, 2018 09:30
@dianabarsan
Copy link
Member Author

Please take another look, @SCdF . Thanks!

Copy link
Contributor

@SCdF SCdF left a comment

Choose a reason for hiding this comment

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

LGTM!

@dianabarsan dianabarsan merged commit 0600396 into 2.18.x Aug 15, 2018
@dianabarsan dianabarsan deleted the 4758-visits-counter branch August 15, 2018 10:04
dianabarsan added a commit that referenced this pull request Aug 15, 2018
Adds visit count display in contacts list. Visit count display is
conditioned by the same permission as displaying last visited date.
Visits are counted based on the calendar month, with each month
starting on either the 1st or on a configurable date. Visit counters
may be color coded if a specific visit count goal configured.

Adds UHC app configuration section.
Adds UHC configuration with options to select default sorting contacts
lists by last visited date, visit counter settings for monthly count
goal and the month reset/start date.

#4758
#4752
dianabarsan added a commit that referenced this pull request Aug 15, 2018
Adds visit count display in contacts list. Visit count display is
conditioned by the same permission as displaying last visited date.
Visits are counted based on the calendar month, with each month
starting on either the 1st or on a configurable date. Visit counters
may be color coded if a specific visit count goal configured.

Adds UHC app configuration section.
Adds UHC configuration with options to select default sorting contacts
lists by last visited date, visit counter settings for monthly count
goal and the month reset/start date.

#4758
#4752
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants