-
-
Notifications
You must be signed in to change notification settings - Fork 204
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
Conversation
Change integer filter from max digits to max number.
Please review, @SCdF . Thanks! |
There was a problem hiding this 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!
static/css/variables.less
Outdated
@@ -35,6 +35,10 @@ | |||
@failed-state-color: #DA4548; | |||
@received-state-color: #E9AA22; | |||
|
|||
/* Visit count progress colors */ | |||
@visits-started-color: #C38813; |
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure :)
api/config.default.json
Outdated
], | ||
"uhc": { | ||
"contacts_default_sort": { | ||
"last_visited_date": false |
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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").
static/js/controllers/contacts.js
Outdated
if ($scope.lastVisitedDateExtras && | ||
uhcSettings.contacts_default_sort && | ||
uhcSettings.contacts_default_sort.last_visited_date) { | ||
$scope.sortDirection = $scope.defaultSortDirection = 'lastVisitedDate'; |
There was a problem hiding this comment.
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
static/js/controllers/contacts.js
Outdated
doc.fields.visited_contact_uuid && | ||
liveList.contains({ _id: doc.fields.visited_contact_uuid }) | ||
) { | ||
return true; |
There was a problem hiding this comment.
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?
static/js/filters/number.js
Outdated
@@ -0,0 +1,18 @@ | |||
angular.module('inboxFilters').filter('maxInteger', function() { |
There was a problem hiding this comment.
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
static/js/services/live-list.js
Outdated
@@ -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) }), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
replace with Math.max
?
static/js/services/live-list.js
Outdated
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'), |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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!
static/js/services/search.js
Outdated
var stats = visitStats[row.key] || { lastVisitedDate: -1, visitCount: 0 }; | ||
|
||
if (stats.lastVisitedDate < row.value) { | ||
stats.lastVisitedDate = row.value; |
There was a problem hiding this comment.
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
static/js/services/search.js
Outdated
var lastVisitedDatePromise = getLastVisitedDates(searchResults, extensions.visitCountSettings); | ||
|
||
result = $q | ||
.all([ dataRecordsPromise, lastVisitedDatePromise ]) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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()); |
There was a problem hiding this comment.
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!
Please take another look, @SCdF . Thanks! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
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
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
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