-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #275 from performant-software/feature/cdc27_events
CDC #27 - Events
- Loading branch information
Showing
12 changed files
with
133 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// @flow | ||
|
||
class FuzzyDate { | ||
/** | ||
* Returns the passed date as a FuzzyDate input date. | ||
* | ||
* @param date | ||
* | ||
* @returns {{endDate: *, _destroy, accuracy, description, range, id, startDate: *}|null} | ||
*/ | ||
toFuzzyDate(date) { | ||
if (!date) { | ||
return null; | ||
} | ||
|
||
return { | ||
id: date.id, | ||
accuracy: date.accuracy, | ||
description: date.description, | ||
endDate: date.end_date, | ||
range: date.range, | ||
startDate: date.start_date, | ||
_destroy: date._destroy | ||
}; | ||
} | ||
|
||
/** | ||
* Returns the passed FuzzyDateable object for PUT/POST requests. | ||
* | ||
* @param dateable | ||
* @param attribute | ||
* | ||
* @returns {{}} | ||
*/ | ||
toPayload(dateable, attribute) { | ||
const date = dateable[attribute]; | ||
|
||
if (!date) { | ||
return null; | ||
} | ||
|
||
return { | ||
[attribute]: { | ||
id: date.id, | ||
accuracy: date.accuracy, | ||
description: date.description, | ||
end_date: date.endDate, | ||
range: date.range, | ||
start_date: date.startDate, | ||
_destroy: date._destroy | ||
} | ||
}; | ||
} | ||
} | ||
|
||
const FuzzyDateTransform: FuzzyDate = new FuzzyDate(); | ||
export default FuzzyDateTransform; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
// @flow | ||
|
||
import _ from 'underscore'; | ||
import Calendar from './Calendar'; | ||
import Browser from './Browser'; | ||
|
||
const DATE_SEPARATOR = ' - '; | ||
|
||
const DEFAULT_CALENDAR = Calendar.Calendars.gregorian; | ||
|
||
/** | ||
* Returns a view for the passed fuzzy date object and calendar. | ||
* | ||
* @param date | ||
* @param calendar | ||
* | ||
* @returns {null|string|*} | ||
*/ | ||
const getDateView = (date, cal = null) => { | ||
if (!date) { | ||
return null; | ||
} | ||
|
||
if (!(date.description || date.start_date)) { | ||
return null; | ||
} | ||
|
||
let calendar = cal; | ||
|
||
if (!calendar) { | ||
const locale = Browser.isBrowser() && navigator.language; | ||
calendar = new Calendar(locale, DEFAULT_CALENDAR); | ||
} | ||
|
||
// Use the description, if provided | ||
if (date.description) { | ||
return date.description; | ||
} | ||
|
||
// Otherwise, format the start and end dates | ||
const dateView = []; | ||
|
||
if (date.start_date) { | ||
const parsed = calendar.parseDate(date.start_date); | ||
dateView.push(calendar.format(parsed, date.accuracy)); | ||
} | ||
|
||
if (date.range && date.end_date) { | ||
const parsed = calendar.parseDate(date.end_date); | ||
dateView.push(calendar.format(parsed, date.accuracy)); | ||
} | ||
|
||
return _.isEmpty(dateView) ? null : dateView.join(DATE_SEPARATOR); | ||
}; | ||
|
||
export default { | ||
getDateView | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,5 +8,5 @@ | |
"packages/user-defined-fields", | ||
"packages/visualize" | ||
], | ||
"version": "2.1.2" | ||
"version": "2.1.3" | ||
} |