Skip to content

Commit

Permalink
feat (case): case resume
Browse files Browse the repository at this point in the history
  • Loading branch information
santanche committed Jan 20, 2022
1 parent 3315b0c commit 4d94987
Show file tree
Hide file tree
Showing 4 changed files with 114 additions and 27 deletions.
4 changes: 0 additions & 4 deletions src/adonisjs/public/infra/dcc-logger-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,6 @@ class DCCLoggerManager extends DCCLight {

async _notifyLogger (topic, message, track) {
if (track) {
console.log('=== logger DCC: ' + topic)
console.log(message)

console.log('========== creating logger ==========')
let logger = await MessageBus.i.request('logger/create/post',
{
caseId: message.caseId,
Expand Down
96 changes: 84 additions & 12 deletions src/adonisjs/public/player/js/htracker.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
class Tracker {
constructor () {
this._variables = {}
this._varUpdated = {}
// this._varChanged = {} <FUTURE>
this._mandatoryFilled = {}
this._groupInput = null

this._knotTrack = []
this._caseCompleted = false
this.initializeTrack()

this.inputReady = this.inputReady.bind(this)
MessageBus.i.subscribe('input/ready/#', this.inputReady)
Expand All @@ -32,6 +25,17 @@ class Tracker {
MessageBus.i.subscribe('input/submit/*', this.submitVariables)
}

initializeTrack () {
this._variables = {}
this._varUpdated = {}
// this._varChanged = {} <FUTURE>
this._mandatoryFilled = {}
this._groupInput = null

this._knotTrack = []
this._caseCompleted = false
}

_extractEntityId (topic, position) {
return MessageBus.extractLevelsSegment(topic, position).replace(/\//g, '.')
}
Expand All @@ -48,6 +52,7 @@ class Tracker {
const v = this._extractEntityId(topic, 3)
if (v != null)
this._mandatoryFilled[v] = { message: message, filled: false }
this._trackStore()
}
}

Expand All @@ -57,12 +62,14 @@ class Tracker {
const v = this._extractEntityId(topic, position)
if (v != null && this._variables[v] == null)
switch (type) {
case '<' : this._updateVariable(v, {})
this._groupInput = v
case '<' : this._groupInput = v
this._updateVariable(v, {})
break
case '>' : if (this._groupInput != null)
case '>' : if (this._groupInput != null) {
this._variables[this._groupInput][v] =
{ content: message.content, state: ' ' }
this._trackStore()
}
break
default: this._updateVariable(v, '')
}
Expand All @@ -79,9 +86,11 @@ class Tracker {
}

stateChanged (topic, message) {
if (this._groupInput != null)
if (this._groupInput != null) {
this._variables[this._groupInput][this._extractEntityId(topic, 3)].state =
message.state
this._trackStore()
}
}

submitVariables (topic, message) {
Expand All @@ -92,6 +101,7 @@ class Tracker {
this._varUpdated[v] = false
}
}
this._trackStore()
}

/* <FUTURE>
Expand All @@ -114,6 +124,7 @@ class Tracker {
this._varUpdated[variable] = true
if (this._mandatoryFilled[variable] !== undefined) {
this._mandatoryFilled[variable].filled = (value.length > 0) }
this._trackStore()
}
}

Expand All @@ -122,6 +133,7 @@ class Tracker {
this._knotTrack.push(
{knotid: this._extractEntityId(topic, 3),
timeStart: currentDateTime.toJSON()})
this._trackStore()
}

inputSummary (topic, message) {
Expand All @@ -131,6 +143,7 @@ class Tracker {

caseCompleted (topic, message) {
if (!this._caseCompleted) {
this._caseCompleted = true
const currentDateTime = new Date()
let kt = {
event: topic,
Expand All @@ -139,11 +152,70 @@ class Tracker {
if (message && message.knotid)
kt.knotid = message.knotid
this._knotTrack.push(kt)
this._trackStore()
MessageBus.i.publish('case/summary/' + MessageBus.extractLevel(topic, 3),
{userId: message.userId,
caseId: message.caseId,
knotTrack: this._knotTrack,
variables: this._variables}, true)
}
}

caseHalt (userId, caseId, instanceId) {
const track = this._trackRetrieve()
if (track != null) {
const currentDateTime = new Date()
track.knotTrack.push(
{event: '*** case halted ***',
timeResume: currentDateTime.toJSON()}
)
track.variables['case halted'] = '*** case halted ***'
MessageBus.i.publish('case/summary/' + instanceId,
{userId: userId,
caseId: caseId,
knotTrack: track.knotTrack,
variables: track.variables}, true)
}
}

/*
* State Storage
*/
_trackStore () {
localStorage.setItem(Tracker.storeId,
JSON.stringify(
{knotTrack: this._knotTrack,
variables: this._variables,
varUpdated: this._varUpdated,
mandatoryFilled: this._mandatoryFilled,
groupInput: this._groupInput,
caseCompleted: this._caseCompleted
}
))
}

_trackRetrieve () {
let track = null
const trackS = localStorage.getItem(Tracker.storeId)
if (trackS != null)
track = JSON.parse(trackS)
return track
}

pendingTrackRestore () {
const track = this._trackRetrieve()
if (track != null) {
this._knotTrack = track.knotTrack
this._variables = track.variables
this._varUpdated = track.varUpdated
this._mandatoryFilled = track.mandatoryFilled
this._groupInput = track.groupInput
this._caseCompleted = track.caseCompleted
}
return (track != null)
}
}

(function () {
Tracker.storeId = 'harena-track'
})()
18 changes: 11 additions & 7 deletions src/adonisjs/public/player/js/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ class PlayerManager {
}
this._state.historyRecord(target)
// this._updateFlowKnot(target)
if (message.value) {
if (message && message.value) {
this._state.parameter = message.value
this.knotLoad(target, message.value)
} else {
Expand Down Expand Up @@ -206,7 +206,7 @@ class PlayerManager {
window.onbeforeunload = function() {
return "";
}
const preCaseOff = true
const resumeActive = true // activates and deactivates case resume
this._mainPanel = document.querySelector('#player-panel')

const parameters = window.location.search.substr(1)
Expand All @@ -227,14 +227,18 @@ class PlayerManager {
} else { precase = null }

let resume = false
if (!this._previewCase && this._state.pendingPlayCheck() && !preCaseOff) {
const pPlay = this._state.pendingPlayCheck()
if (!this._previewCase && pPlay != null && resumeActive) {
this._tracker.caseHalt(pPlay.userid, pPlay.caseid, pPlay.running.runningId)

// <TODO> adjust for name: (precase == null || this._state.pendingPlayId() == precase)) {
const decision = await DCCNoticeInput.displayNotice(
'You have an unfinished case. Do you want to continue?',
'message', 'Yes', 'No')
if (decision == 'Yes') {
resume = true
this._state.pendingPlayRestore()
const currKnot = this._state.pendingPlayRestore()
this._tracker.pendingTrackRestore()
DCCCommonServer.instance.token = this._state.token

// <TODO> provisory deactivation
Expand All @@ -252,9 +256,9 @@ class PlayerManager {
this._state.currentCase = this._state.currentCase
await this._caseLoad(this._state.currentCase)

this._caseFlow()
MessageBus.i.publish('knot/navigate/<<', null, true)
} else { this._state.sessionCompleted() }
// this._caseFlow()
MessageBus.i.publish('knot/navigate/' + currKnot, null, true)
} // else { this._state.sessionCompleted() }
}

if (!resume) {
Expand Down
23 changes: 19 additions & 4 deletions src/adonisjs/public/player/js/state.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ class PlayState {
history: [],
parameter: null,
nextKnot: 1,
completed: false
completed: false,
flow: null
}

this._metastate = {}
Expand All @@ -37,6 +38,19 @@ class PlayState {
MessageBus.i.subscribe('var/set/#', this.variableSet)
}

/*
* Properties
*/

// <TODO> Provisory - bring all flow dynamics to here
get flow() {
return this._state.flow
}

set flow(newFlow) {
this._state.flow = newFlow
}

/*
* State Storage
*/
Expand All @@ -53,7 +67,7 @@ class PlayState {

sessionRecord (topic) {
this._state.userid = MessageBus.extractLevel(topic, 3)
this._stateStore()
// this._stateStore()
}

sessionCompleted () {
Expand All @@ -63,7 +77,7 @@ class PlayState {

pendingPlayCheck () {
const state = this._stateRetrieve()
return (state != null)
return (state != null && !state.completed) ? state : null
}

pendingPlayId () {
Expand All @@ -74,7 +88,8 @@ class PlayState {
pendingPlayRestore () {
let currentKnot = null
this._state = this._stateRetrieve()
if (this._state.history.length > 0) { currentKnot = this._state.history[this._state.history.length - 1] }
if (this._state.history.length > 0) {
currentKnot = this._state.history[this._state.history.length - 1] }
return currentKnot
}

Expand Down

0 comments on commit 4d94987

Please sign in to comment.