Skip to content

Commit

Permalink
Merge pull request #324 from harena-lab/development
Browse files Browse the repository at this point in the history
New computation and conditional mechanisms
  • Loading branch information
santanche authored Jan 20, 2022
2 parents d9b6007 + 4d94987 commit fa3a10a
Show file tree
Hide file tree
Showing 27 changed files with 491 additions and 421 deletions.
14 changes: 7 additions & 7 deletions src/adonisjs/public/author/drafts/category/cases/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -255,23 +255,23 @@ <h5 class="" id="modal-notice-txt"></h5>
<div class="share-cases-element wrapper-checkbox-select-case" hidden>
<div class="col">
<div class="form-check share-checkbox">
<input class="form-check-input" type="checkbox" id="c{{c.cases.id}}" value="{{c.cases.id}}">
<input class="form-check-input" type="checkbox" id="c{{c.id}}" value="{{c.id}}">
</div>
</div>
</div>
<div id="b{{c.cases.id}}" class="row draft-author-case-container">
<div id="b{{c.id}}" class="row draft-author-case-container">
<div class="col draft-case-title">
<label class="ml-2">{{c.cases.title}}</label>
<label class="ml-2">{{c.title}}</label>

<div class="row">
<h6>Created by {{c.cases.author_grade}}: {{c.cases.username}} ({{c.cases.institution_acronym}})</h6>
<h6>Created by {{c.author_grade}}: {{c.username}} ({{c.institution_acronym}})</h6>
</div>
</div>

<div class="d-flex justify-content-end justify-content-center buttons-container">
<div id="e{{c.cases.id}}" class="col author-panel-button align-self-center pt-2 pb-2">EDIT</div>
<div id="p{{c.cases.id}}" class="col author-panel-button align-self-center pt-2 pb-2">PREVIEW</div>
<div id="d{{c.cases.id}}" class="col author-panel-button align-self-center pt-2 pb-2">DELETE</div>
<div id="e{{c.id}}" class="col author-panel-button align-self-center pt-2 pb-2">EDIT</div>
<div id="p{{c.id}}" class="col author-panel-button align-self-center pt-2 pb-2">PREVIEW</div>
<div id="d{{c.id}}" class="col author-panel-button align-self-center pt-2 pb-2">DELETE</div>
</div>
</div>
{{@endfor}}
Expand Down
10 changes: 5 additions & 5 deletions src/adonisjs/public/author/drafts/feedback/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -243,21 +243,21 @@ <h5 class="" id="modal-notice-txt"></h5>
<div class="share-cases-element wrapper-checkbox-select-case" hidden>
<div class="col">
<div class="form-check share-checkbox">
<input class="form-check-input" type="checkbox" id="c{{c.cases.id}}" value="{{c.cases.id}}">
<input class="form-check-input" type="checkbox" id="c{{c.id}}" value="{{c.id}}">
</div>
</div>
</div>
<div id="b{{c.cases.id}}" class="row draft-author-case-container">
<div id="b{{c.id}}" class="row draft-author-case-container">
<div class="col draft-case-title">
<label class="ml-2">{{c.cases.title}}</label>
<label class="ml-2">{{c.title}}</label>

<div class="row">
<h6>Created by: {{c.cases.username}} ({{c.cases.institution_acronym}}) || {{c.cases.feedback}}</h6>
<h6>Created by: {{c.username}} ({{c.institution_acronym}}) || {{c.feedback}}</h6>
</div>
</div>

<div class="d-flex justify-content-end justify-content-center buttons-container">
<div id="e{{c.cases.id}}" class="col author-panel-button align-self-center pt-2 pb-2">VIEW FEEDBACK</div>
<div id="e{{c.id}}" class="col author-panel-button align-self-center pt-2 pb-2">VIEW FEEDBACK</div>
</div>
</div>
{{@endfor}}
Expand Down
14 changes: 7 additions & 7 deletions src/adonisjs/public/author/drafts/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -282,23 +282,23 @@ <h5 class="" id="modal-notice-txt"></h5>
<div class="share-cases-element wrapper-checkbox-select-case" hidden>
<div class="col">
<div class="form-check share-checkbox">
<input class="form-check-input" type="checkbox" id="c{{c.cases.id}}" value="{{c.cases.id}}">
<input class="form-check-input" type="checkbox" id="c{{c.id}}" value="{{c.id}}">
</div>
</div>
</div>
<div id="b{{c.cases.id}}" class="row draft-author-case-container">
<div id="b{{c.id}}" class="row draft-author-case-container">
<div class="col draft-case-title">
<label class="ml-2">{{c.cases.title}}</label>
<label class="ml-2">{{c.title}}</label>

<div class="row">
<h6>Created by {{c.cases.author_grade}}: {{c.cases.username}} ({{c.cases.institution_acronym}})</h6>
<h6>Created by {{c.author_grade}}: {{c.username}} ({{c.institution_acronym}})</h6>
</div>
</div>

<div class="d-flex justify-content-end justify-content-center buttons-container">
<div id="e{{c.cases.id}}" class="col author-panel-button align-self-center pt-2 pb-2">EDIT</div>
<div id="p{{c.cases.id}}" class="col author-panel-button align-self-center pt-2 pb-2">PREVIEW</div>
<div id="d{{c.cases.id}}" class="col author-panel-button align-self-center pt-2 pb-2">DELETE</div>
<div id="e{{c.id}}" class="col author-panel-button align-self-center pt-2 pb-2">EDIT</div>
<div id="p{{c.id}}" class="col author-panel-button align-self-center pt-2 pb-2">PREVIEW</div>
<div id="d{{c.id}}" class="col author-panel-button align-self-center pt-2 pb-2">DELETE</div>
</div>
</div>
{{@endfor}}
Expand Down
14 changes: 7 additions & 7 deletions src/adonisjs/public/author/partials/case-list-min.html
Original file line number Diff line number Diff line change
Expand Up @@ -59,22 +59,22 @@
<!-- checkbox for selecting cases -->
<!-- <div class="col">
<div class="form-check" id="share-checkbox">
<input class="form-check-input" type="checkbox" id="c{{c.cases.id}}" value="{{c.cases.id}}">
<input class="form-check-input" type="checkbox" id="c{{c.id}}" value="{{c.id}}">
</div>
</div> -->
<div id="b{{c.cases.id}}" class="row draft-author-case-container">
<div id="b{{c.id}}" class="row draft-author-case-container">
<div class="col draft-case-title">
<label class="ml-2">{{c.cases.title}}</label>
<label class="ml-2">{{c.title}}</label>

<div class="row">
<h6>Created by {{c.cases.author_grade}}: {{c.cases.username}} ({{c.cases.institution_acronym}})</h6>
<h6>Created by {{c.author_grade}}: {{c.username}} ({{c.institution_acronym}})</h6>
</div>
</div>

<div class="d-flex justify-content-end justify-content-center buttons-container">
<div id="e{{c.cases.id}}" class="col author-panel-button align-self-center pt-2 pb-2">EDIT</div>
<div id="p{{c.cases.id}}" class="col author-panel-button align-self-center pt-2 pb-2">PREVIEW</div>
<div id="d{{c.cases.id}}" class="col author-panel-button align-self-center pt-2 pb-2">DELETE</div>
<div id="e{{c.id}}" class="col author-panel-button align-self-center pt-2 pb-2">EDIT</div>
<div id="p{{c.id}}" class="col author-panel-button align-self-center pt-2 pb-2">PREVIEW</div>
<div id="d{{c.id}}" class="col author-panel-button align-self-center pt-2 pb-2">DELETE</div>
</div>
</div>
{{@endfor}}
Expand Down
4 changes: 4 additions & 0 deletions src/adonisjs/public/dccs/base/primitive-dcc.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ class PrimitiveDCC extends HTMLElement {
this._bus.provides(id, topic, service)
}

_withhold (id, topic) {
this._bus.withhold(id, topic)
}

_connect (id, topic, callback) {
this._bus.connect(id, topic, callback)
}
Expand Down
117 changes: 78 additions & 39 deletions src/adonisjs/public/dccs/components/control/dcc-compute.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
class DCCCompute extends DCCBase {
constructor () {
super()
this._completed = false
this._updated = false
}

async connectedCallback () {
Expand All @@ -13,29 +13,39 @@ class DCCCompute extends DCCBase {

if (this.hasAttribute('id')) {
this.computeStatus = this.computeStatus.bind(this)
this._subscribe('compute/status/' + this.id)
this._subscribe('compute/status/' + this.id, this.computeStatus)
}

this._notifyCompleted = this.hasAttribute('id')
this._condition = (this.hasAttribute('condition'))
? DCCCompute.compileStatementSet(this.condition.toLowerCase()) : null

this._compiled = null
if (this.hasAttribute('expression')) {
this._compiled =
DCCCompute.compileStatementSet(this.expression.toLowerCase())
if (this.hasAttribute('dependency')) {
this.newExpressionUpdate = this.newExpressionUpdate.bind(this)
this._subscribe('compute/completed/' + this.dependency,
this.newExpressionUpdate)
this._dependencyCompleted = this._dependencyCompleted.bind(this)
this._subscribe('compute/updated/' + this.dependency,
this._dependencyCompleted)
this._publish('compute/status/' + this.dependency)
} else if (this._compiled != null && this.active)
await this.newExpressionUpdate()
await this._newExpressionUpdate()
}

if (this.hasAttribute('id'))
if (this.hasAttribute('id')) {
this._provides(this.id, 'compute/update', this.update)
this.calculate = this.calculate.bind(this)
this._provides(this.id, 'compute/calculate', this.calculate)
}
}

async disconnectedCallback() {
await this._unsubscribeVariables()
this._unsubscribe('compute/status/' + this.id, this.computeStatus)
if (this.hasAttribute('id')) {
this._withhold(this.id, 'compute/update')
this._withhold(this.id, 'compute/calculate')
}
}

async _subscribeVariables () {
Expand All @@ -53,7 +63,13 @@ class DCCCompute extends DCCBase {
}
}

async newExpressionUpdate () {
_dependencyCompleted () {
this._unsubscribe('compute/updated/' + this.dependency,
this._dependencyCompleted)
this._newExpressionUpdate()
}

async _newExpressionUpdate () {
await this.update()
await this._subscribeVariables()
}
Expand All @@ -64,7 +80,17 @@ class DCCCompute extends DCCBase {

static get observedAttributes () {
return DCCBase.observedAttributes.concat(
['expression', 'onload', 'active', 'dependency'])
['condition', 'expression', 'active', 'dependency'])
}

get condition () {
return this.getAttribute('condition')
}

set condition (newValue) {
this.setAttribute('condition', newValue)
this._condition = (newValue != null)
? DCCCompute.compileStatementSet(newValue.toLowerCase()) : null
}

get expression () {
Expand All @@ -73,17 +99,11 @@ class DCCCompute extends DCCBase {

set expression (newValue) {
this.setAttribute('expression', newValue)
this._compiled = (newValue != null)
? DCCCompute.compileStatementSet(newValue.toLowerCase()) : null
this._newExpressionUpdate()
}

get onload () {
return this.hasAttribute('onload')
}

set onload (isOnload) {
if (isOnload) { this.setAttribute('onload', '') } else { this.removeAttribute('onload') }
}

// defines if the display is activelly updated
get active () {
return this.hasAttribute('active')
Expand Down Expand Up @@ -111,22 +131,27 @@ class DCCCompute extends DCCBase {
}

async update () {
const result = await DCCCompute.computeExpression(
this._compiled, this._bus)
if (result) {
this._completed = true
await this.multiRequest('true', null)
if (this._notifyCompleted) {
this._notifyCompleted = false
await this._publish('compute/completed/' + this.id)
}
} else
await this.multiRequest('false', null)
let result = null
if (this._condition == null ||
await DCCCompute.computeExpression(this._condition, this._bus)) {
result = await DCCCompute.computeExpression(
this._compiled, this._bus, true)
if (result._final)
await this.multiRequest('true', null)
else
await this.multiRequest('false', null)
}
this._updated = true
await this._publish('compute/updated/' + this.id, result)
}

computeStatus () {
if (this._completed)
this.publish('compute/completed/' + this.id)
if (this._updated)
this.publish('compute/updated/' + this.id)
}

async calculate () {
return await DCCCompute.computeExpression(this._compiled, this._bus, true)
}

async connectionReady (id, topic) {
Expand Down Expand Up @@ -233,7 +258,8 @@ class DCCCompute extends DCCBase {
stack.push([matchContent, DCCCompute.precedence[matchContent]])
break
case 'closeParentheses':
while (stack.length > 0 && stack[stack.length - 1][0] != '(') { compiled.push([DCCCompute.role.operator, stack.pop()[0]]) }
while (stack.length > 0 && stack[stack.length - 1][0] != '(')
compiled.push([DCCCompute.role.operator, stack.pop()[0]])
if (stack.length > 0) {
stack.pop()
if (stack.length > 0 && stack[stack.length - 1][1] ==
Expand Down Expand Up @@ -269,19 +295,24 @@ class DCCCompute extends DCCBase {

/*
* Computes a set of expressions, updating variables.
* It returns the value of the last variable.
* It returns the value of the last variable as default.
* - allResults: indicates that all results will be returned
*/
static async computeExpression (compiledSet, bus) {
static async computeExpression (compiledSet, bus, allResults) {
let result = null
let all = {}
for (let s of compiledSet) {
await DCCCompute.updateVariables(s[1], bus)
const r = DCCCompute.computeCompiled(s[1])
if (s[0] != null) {
result = DCCCompute.computeCompiled(s[1])
all[s[0]] = r
result = r
let cBus = (bus != null) ? bus : MessageBus.i
await cBus.request('var/set/' + s[0].replace(/\./g, '/'),
result, null, true)
r, null, true)
} else if (compiledSet.length == 1) {
result = DCCCompute.computeCompiled(s[1])
all['value'] = r
result = r
// looks for a variable inside the expression
/*
if (autoAssign) {
Expand All @@ -292,6 +323,10 @@ class DCCCompute extends DCCBase {
*/
}
}
if (allResults) {
all._final = result
result = all
}
return result
}

Expand Down Expand Up @@ -359,6 +394,7 @@ class DCCCompute extends DCCBase {
case '*': stack.push(a * b); break
case '/': stack.push(a / b); break
case '^': stack.push(Math.pow(a, b)); break
case '=': stack.push(a == b); break;
case '>': stack.push(a > b); break;
case '<': stack.push(a < b); break;
case '>=': stack.push(a >= b); break;
Expand Down Expand Up @@ -387,6 +423,9 @@ class DCCCompute extends DCCBase {
case 'random':
stack.push(Math.floor(Math.random() * (stack.pop()+1)))
break
case 'abs':
stack.push(Math.abs(stack.pop()))
break
}
}
}
Expand All @@ -406,6 +445,7 @@ class DCCCompute extends DCCBase {
}

DCCCompute.precedence = {
'(': 0,
'or': 1,
'and': 2,
'=': 3,
Expand All @@ -420,8 +460,7 @@ class DCCCompute extends DCCBase {
'*': 5,
'^': 6,
'not': 7,
function: 8,
'(': 9
function: 8
}

DCCCompute.element = {
Expand Down
Loading

0 comments on commit fa3a10a

Please sign in to comment.