2018-04-06 00:57:36 +00:00
|
|
|
import pickBy from 'lodash-es/pickBy'
|
2018-03-10 06:31:26 +00:00
|
|
|
|
2018-03-03 22:15:50 +00:00
|
|
|
export function timelineMixins (Store) {
|
2018-01-28 21:09:39 +00:00
|
|
|
Store.prototype.setForTimeline = function (instanceName, timelineName, obj) {
|
2018-03-04 20:55:45 +00:00
|
|
|
let valuesToSet = {}
|
|
|
|
for (let key of Object.keys(obj)) {
|
|
|
|
let rootKey = `timelineData_${key}`
|
|
|
|
let root = this.get(rootKey) || {}
|
|
|
|
let instanceData = root[instanceName] = root[instanceName] || {}
|
|
|
|
instanceData[timelineName] = obj[key]
|
|
|
|
valuesToSet[rootKey] = root
|
|
|
|
}
|
|
|
|
|
|
|
|
this.set(valuesToSet)
|
2018-01-28 21:09:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Store.prototype.getForTimeline = function (instanceName, timelineName, key) {
|
2018-03-04 20:55:45 +00:00
|
|
|
let rootKey = `timelineData_${key}`
|
|
|
|
let root = this.get(rootKey)
|
|
|
|
return root && root[instanceName] && root[instanceName][timelineName]
|
2018-01-28 21:09:39 +00:00
|
|
|
}
|
2018-02-10 21:57:04 +00:00
|
|
|
|
2018-03-21 07:53:52 +00:00
|
|
|
Store.prototype.getForCurrentTimeline = function (key) {
|
|
|
|
let instanceName = this.get('currentInstance')
|
|
|
|
let timelineName = this.get('currentTimeline')
|
|
|
|
return this.getForTimeline(instanceName, timelineName, key)
|
|
|
|
}
|
|
|
|
|
2018-03-11 00:21:10 +00:00
|
|
|
Store.prototype.getAllTimelineData = function (instanceName, key) {
|
|
|
|
let root = this.get(`timelineData_${key}`) || {}
|
|
|
|
return root[instanceName] || {}
|
|
|
|
}
|
|
|
|
|
2018-02-10 21:57:04 +00:00
|
|
|
Store.prototype.setForCurrentTimeline = function (obj) {
|
|
|
|
let instanceName = this.get('currentInstance')
|
|
|
|
let timelineName = this.get('currentTimeline')
|
|
|
|
this.setForTimeline(instanceName, timelineName, obj)
|
|
|
|
}
|
2018-03-10 06:31:26 +00:00
|
|
|
|
2018-03-11 00:21:10 +00:00
|
|
|
Store.prototype.getThreads = function (instanceName) {
|
|
|
|
let instanceData = this.getAllTimelineData(instanceName, 'timelineItemIds')
|
2018-03-10 06:31:26 +00:00
|
|
|
|
|
|
|
return pickBy(instanceData, (value, key) => {
|
|
|
|
return key.startsWith('status/')
|
|
|
|
})
|
|
|
|
}
|
2018-01-28 21:09:39 +00:00
|
|
|
}
|