Skip to content

Commit

Permalink
Merge pull request #299 from harena-lab/development
Browse files Browse the repository at this point in the history
refactor (message): major refactory of message protocol
  • Loading branch information
santanche authored Nov 23, 2021
2 parents 85e7faf + 84394fb commit 3d6b57e
Show file tree
Hide file tree
Showing 75 changed files with 538 additions and 462 deletions.
4 changes: 2 additions & 2 deletions src/adonisjs/public/author/js/author.js
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ class AuthorManager {
async _caseLoad (caseId) {
Basic.service.currentCaseId = caseId

const caseObj = await MessageBus.i.request('data/case/' + caseId + '/get', null, null, true)
const caseObj = await MessageBus.i.request('case/get/' + caseId, null, null, true)

this._currentCaseTitle = caseObj.message.title
await this._compile(caseObj.message.source)
Expand Down Expand Up @@ -542,7 +542,7 @@ class AuthorManager {
Comments.prepare(this._compiledCase, knotid)
if (Panels.s.commentsVisible)
MessageBus.i.publish('control/comments/editor')
MessageBus.i.publish('control/case/ready', null, true)
MessageBus.i.publish('case/ready/' + Basic.service.currentCaseId, null, true)
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/adonisjs/public/author/js/draft.js
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ class DraftManager {
}

async downloadCase (topic, message) {
const caseObj = await MessageBus.i.request('data/case/' + message + '/get', null, null, true)
const caseObj = await MessageBus.i.request('case/get/' + message, null, null, true)
Basic.service.downloadFile(
caseObj.message.source, caseObj.message.title + '.md')
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class VersumContextManager {
this.updateVisibility = this.updateVisibility.bind(this)

MessageBus.i.subscribe('control/translate/example', this.translate)
MessageBus.i.subscribe('var/output/changed', this.updateVisibility)
MessageBus.i.subscribe('input/changed/output', this.updateVisibility)
}

async translate (topic, message) {
Expand Down
18 changes: 10 additions & 8 deletions src/adonisjs/public/dccs/components/control/dcc-compute.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class DCCCompute extends DCCBase {
if (this.active) {
const variables = DCCCompute.filterVariables(this._compiled, false)
for (let v of variables)
this._subscribe('var/' + v + '/set', this.update)
this._subscribe('var/set/' + v.replace(/\./g, '/'), this.update)
}
}
}
Expand Down Expand Up @@ -70,7 +70,7 @@ class DCCCompute extends DCCBase {
this.update()
}

async update() {
async update () {
const result = await DCCCompute.computeExpression(this._compiled, this._bus)
if (result)
await this.multiRequest('true', null)
Expand Down Expand Up @@ -101,9 +101,9 @@ class DCCCompute extends DCCBase {
case 'divert-script':
let message
if (expression.target.startsWith('Case.'))
{ message = 'case/' + expression.target.substring(5) + '/navigate' }
{ message = 'case/navigate/' + expression.target.substring(5) }
else
{ message = 'knot/' + expression.target + '/navigate' }
{ message = 'knot/navigate/' + expression.target.replace(/\./g, '/') }
let cBus = (bus != null) ? bus : MessageBus.i
if (expression.parameter) {
bus.publish(message, expression.parameter, true)
Expand Down Expand Up @@ -227,15 +227,16 @@ class DCCCompute extends DCCBase {
if (s[0] != null) {
result = DCCCompute.computeCompiled(s[1])
let cBus = (bus != null) ? bus : MessageBus.i
await cBus.request('var/' + s[0] + '/set', result, null, true)
await cBus.request('var/set/' + s[0].replace(/\./g, '/'),
result, null, true)
} else if (compiledSet.length == 1) {
result = DCCCompute.computeCompiled(s[1])
// looks for a variable inside the expression
/*
if (autoAssign) {
let variable = s[1].find(el => el[0] == 3)
if (variable)
await this._request('var/' + variable[1] + '/set', result, null, true)
await this._request('var/set/' + variable[1].replace(/\./g, '/'), result, null, true)
}
*/
}
Expand Down Expand Up @@ -269,8 +270,9 @@ class DCCCompute extends DCCBase {
for (let c of compiled)
if (c[0] == DCCCompute.role.variable) {
let cBus = (bus != null) ? bus : MessageBus.i
if (cBus.hasSubscriber('var/' + c[1] + '/get')) {
const mess = await cBus.request('var/' + c[1] + '/get', null, null, true)
if (cBus.hasSubscriber('var/get/' + c[1].replace(/\./g, '/'), true)) {
const mess = await cBus.request('var/get/' + c[1].replace(/\./g, '/'),
null, null, true)
if (mess.message != null) {
const value = (mess.message.body != null)
? mess.message.body : mess.message
Expand Down
2 changes: 1 addition & 1 deletion src/adonisjs/public/dccs/components/data/dcc-submit.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class DCCSubmit extends DCCButton {
const topic = (this.hasAttribute('topic'))
? this.topic
: (this.hasAttribute('variable'))
? 'var/' + this.variable + '/changed'
? 'input/changed/' + this.variable.replace(/\./g, '/')
: 'button/' + this.label + '/clicked'
if (this.hasAttribute('message')) { message.value = this.message }
let form = null
Expand Down
12 changes: 8 additions & 4 deletions src/adonisjs/public/dccs/components/visual/dcc-button.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@ class DCCButton extends DCCBlock {
connectedCallback () {
super.connectedCallback()

if (this.hasAttribute('topic') && this.topic.endsWith('/navigate')) {
if (this.hasAttribute('topic') &&
MessageBus.extractLevel(this.topic, 2) == 'navigate') {
this.navigationBlocked = this.navigationBlocked.bind(this)
this._subscribe('+/+/navigate/blocked', this.navigationBlocked)
this._subscribe(MessageBus.extractLevelsSegment(this.topic, 1, 2) + '/!',
this.navigationBlocked)
}

this._publish('control/button/' +
Expand Down Expand Up @@ -153,10 +155,12 @@ class DCCButton extends DCCBlock {
const v = (this.variable.includes(':'))
? this.variable.substring(0, this.variable.indexOf(':')) : this.variable
message.value = (this.variable.endsWith(':label')) ? this.label : this.message
this._publish('var/' + v + '/changed', message, true)
this._publish('input/changed/' + v.replace(/\./g, '/'), message, true)
}
if (this.hasAttribute('label') || this.hasAttribute('topic')) {
if (this.hasAttribute('topic') && this.topic.endsWith('/navigate')) { this._active = false }
if (this.hasAttribute('topic') &&
MessageBus.extractLevel(this.topic, 2) == 'navigate')
this._active = false
const topic = (this.hasAttribute('topic'))
? this.topic : 'button/' + this.label + '/clicked'
if (this.hasAttribute('message')) { message.value = this.message }
Expand Down
11 changes: 5 additions & 6 deletions src/adonisjs/public/dccs/components/visual/dcc-expression.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class DCCExpression extends DCCVisual {
// also monitors all messages
if (this.active) {
this.stateChanged = this.stateChanged.bind(this)
this._subscribe('var/+/state_changed', this.stateChanged)
this._subscribe('input/state/#', this.stateChanged)
this._stateValues = {}
}

Expand All @@ -47,10 +47,10 @@ class DCCExpression extends DCCVisual {
if (this.active) {
this.variableUpdated = this.variableUpdated.bind(this)
const variables = DCCCompute.filterVariables(this._compiled, false)
// this._subscribe(// 'var/' + this._variable + '/set', this.variableUpdated)
this._subscribe('var/*/set', this.variableUpdated)
this._subscribe('var/set/*', this.variableUpdated)
for (let v of variables)
this._subscribe('var/' + v + '/set', this.variableUpdated)
this._subscribe('var/set/' + v.replace(/\./g, '/'),
this.variableUpdated)
}
}
}
Expand All @@ -66,7 +66,6 @@ class DCCExpression extends DCCVisual {

async _showResult () {
let result = await DCCCompute.computeExpression(this._compiled)
// let result = await this._request('var/' + this._variable + '/get', null, null, true)
if (result == null) {
result = ''
} else {
Expand Down Expand Up @@ -139,7 +138,7 @@ class DCCExpression extends DCCVisual {
}

stateChanged (topic, message) {
const id = MessageBus.extractLevel(topic, 2)
const id = MessageBus.extractLevelsSegment(topic, 3).replace(/\//g, '.')

if (id.startsWith(this._variable)) {
const subid = id.substring(this._variable.length + 1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ class DCCGroupMarker extends DCCBase {
this._subscribe('dcc/marker-spot/set', this.setMarkerSpot)
this._subscribe('dcc/marker-spot/selected', this.spotSelected)

this._publish('var/' + this.context + '/group_input/ready',
this._publish('input/ready/</' + this.context.replace(/\./g, '/'),
DCCGroupMarker.elementTag)

if (this.hasAttribute('editor')) {
Expand Down Expand Up @@ -349,7 +349,7 @@ class DCCGroupMarker extends DCCBase {
width="1000"
height="1000"
preserveAspectRatio="xMinYMin meet"
xlink:href="[image]"/>
xlink:href="[image]"/>
</g>
</g>
</svg>`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class DCCInputOption extends DCCInput {

// <TODO> align with dcc-state-select
if (this._parent == null) {
this._publish('var/' + this._variable + '/input/ready',
this._publish('input/ready/' + this._variable.replace(/\./g, '/'),
{
sourceType: DCCInputOption.elementTag,
content: this.value
Expand Down Expand Up @@ -100,7 +100,7 @@ class DCCInputOption extends DCCInput {

inputChanged () {
this.changed = true
this._publish('var/' + this._variable + '/changed',
this._publish('input/changed/' + this._variable.replace(/\./g, '/'),
{
sourceType: DCCInputOption.elementTag,
value: this.value
Expand Down Expand Up @@ -233,7 +233,7 @@ class DCCInputChoice extends DCCInput {
}

this.changed = true
this._publish('var/' + this._variable + '/changed',
this._publish('input/changed/' + this._variable.replace(/\./g, '/'),
{
sourceType: DCCInputChoice.elementTag,
value: this._value
Expand Down Expand Up @@ -400,7 +400,7 @@ class DCCInputChoice extends DCCInput {
this._presentationIsReady()

// <TODO> align with dcc-state-select
this._publish('var/' + this._variable + '/group_input/ready',
this._publish('input/ready/</' + this._variable.replace(/\./g, '/'),
DCCInputChoice.elementTag)
}

Expand Down
9 changes: 5 additions & 4 deletions src/adonisjs/public/dccs/components/visual/dcc-input-table.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ class DCCInputTable extends DCCInput {
super.connectedCallback()
this.innerHTML = ''

this._publish('var/' + this._variable + '/input/ready',
DCCInputTable.elementTag)
this._publish('input/ready/' + this._variable.replace(/\./g, '/'),
DCCInputTable.elementTag)
}

disconnectedCallback () {
Expand Down Expand Up @@ -87,7 +87,7 @@ class DCCInputTable extends DCCInput {
const row = parseInt(id.substring(p + 1)) - 1
this._value[row][col] = event.target.value

this._publish('var/' + this._variable + '/changed',
this._publish('input/changed/' + this._variable.replace(/\./g, '/'),
{
sourceType: DCCInputTable.elementTag,
value: this._value
Expand Down Expand Up @@ -129,7 +129,8 @@ class DCCInputTable extends DCCInput {

if (this.hasAttribute('player')) {
const value = await this._request(
'var/' + this.player + '/get/sub', this.innerHTML, null, true)
'var/get/>/' + this.player.replace(/\./g, '/'),
this.innerHTML, null, true)
console.log('=== return value')
console.log(value)
const input = value.message
Expand Down
6 changes: 3 additions & 3 deletions src/adonisjs/public/dccs/components/visual/dcc-input-typed.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class DCCInputTyped extends DCCInput {
super.connectedCallback()
this.innerHTML = ''

this._publish('var/' + this._variable + '/input/ready',
this._publish('input/ready/' + this._variable.replace(/\./g, '/'),
DCCInputTyped.elementTag)
}

Expand Down Expand Up @@ -55,7 +55,7 @@ class DCCInputTyped extends DCCInput {
inputTyped () {
this.changed = true
this.value = this._inputVariable.value
this._publish('var/' + this._variable + '/typed',
this._publish('input/typed/' + this._variable.replace(/\./g, '/'),
{
sourceType: DCCInputTyped.elementTag,
value: this.value
Expand All @@ -65,7 +65,7 @@ class DCCInputTyped extends DCCInput {
inputChanged () {
this.changed = true
this.value = this._inputVariable.value
this._publish('var/' + this._variable + '/changed',
this._publish('input/changed/' + this._variable.replace(/\./g, '/'),
{
sourceType: DCCInputTyped.elementTag,
value: this.value
Expand Down
4 changes: 2 additions & 2 deletions src/adonisjs/public/dccs/components/visual/dcc-input.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ class DCCInput extends DCCBlock {
? this._statement
: this._variable.substring(this._variable.lastIndexOf('.') + 1)

this._publish('var/' + this._variable + '/input/mandatory',
inputIndication)
this._publish('input/mandatory/' + this._variable.replace(/\./g, '/'),
inputIndication)
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/adonisjs/public/dccs/components/visual/dcc-slider.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class DCCSlider extends DCCInput {
super.connectedCallback()
this.innerHTML = ''

this._publish('var/' + this._variable + '/input/ready',
this._publish('input/ready/' + this._variable.replace(/\./g, '/'),
DCCSlider.elementTag)
}

Expand Down Expand Up @@ -69,7 +69,7 @@ class DCCSlider extends DCCInput {
this.changed = true
this._value = this._inputVariable.value
if (this._inputIndex) { this._inputIndex.innerHTML = this._value }
this._publish('var/' + this._variable + '/changed',
this._publish('input/changed/' + this._variable.replace(/\./g, '/'),
{
sourceType: DCCSlider.elementTag,
value: this._value
Expand Down
23 changes: 15 additions & 8 deletions src/adonisjs/public/dccs/components/visual/dcc-state-select.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class DCCStateSelect extends DCCVisual {

this._render()

this._publish('var/' + this.completeId + '/subinput/ready',
this._publish('input/ready/>/' + this.completeId.replace(/\./g, '/'),
{
sourceType: DCCStateSelect.elementTag,
content: this.innerHTML
Expand Down Expand Up @@ -134,7 +134,8 @@ class DCCStateSelect extends DCCVisual {
}

set selection (newValue) {
if (this._statesArr && this._statesArr.includes(newValue)) { this._selectionIndex = this._statesArr.indexOf(newValue) }
if (this._statesArr && this._statesArr.includes(newValue))
this._selectionIndex = this._statesArr.indexOf(newValue)
this.setAttribute('selection', newValue)
}

Expand All @@ -143,16 +144,22 @@ class DCCStateSelect extends DCCVisual {
}

set selectionIndex (newValue) {
if (this._statesArr && this._statesArr[newValue]) { this.selection = this._statesArr[newValue] } else { this._selectionIndex = newValue }
if (this._statesArr && this._statesArr[newValue])
this.selection = this._statesArr[newValue]
else
this._selectionIndex = newValue
}

/* Rendering */

async _render () {
if (this.states != null) {
if (this.hasAttribute('answer') || this.author) { this.selection = this.answer } else if (this.hasAttribute('player')) {
if (this.hasAttribute('answer') || this.author)
this.selection = this.answer
else if (this.hasAttribute('player')) {
const value = await this._request(
'var/' + this.player + '/get/sub', this.innerHTML, null, true)
'var/get/>/' + this.player.replace(/\./g, '/'),
this.innerHTML, null, true)
this.selection = value.message
} else {
this._presentation.addEventListener('mouseover', this._showState)
Expand Down Expand Up @@ -196,7 +203,7 @@ class DCCStateSelect extends DCCVisual {
_changeState () {
if (this.states != null) {
this.selectionIndex = (this.selectionIndex + 1) % this._statesArr.length
this._publish('var/' + this.completeId + '/state_changed',
this._publish('input/state/' + this.completeId.replace(/\./g, '/'),
{
sourceType: DCCStateSelect.elementTag,
state: this.selection,
Expand Down Expand Up @@ -240,8 +247,8 @@ class DCCGroupSelect extends DCCBlock {
this._groupReady = true
this._answerRequests()

this._publish('var/' + this.variable + '/group_input/ready',
DCCGroupSelect.elementTag)
this._publish('input/ready/</' + this.variable.replace(/\./g, '/'),
DCCGroupSelect.elementTag)
}

disconnectedCallback () {
Expand Down
Loading

0 comments on commit 3d6b57e

Please sign in to comment.