-
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 #253 from harena-lab/development
Text editor big refactor
- Loading branch information
Showing
42 changed files
with
1,718 additions
and
626 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/** | ||
* Embeds a data model | ||
*/ | ||
|
||
class DCCModel extends DCCBase { | ||
connectedCallback () { | ||
super.connectedCallback() | ||
|
||
this.requestSchema = this.requestSchema.bind(this) | ||
MessageBus.int.subscribe('data/schema/' + this.id, this.requestSchema) | ||
|
||
console.log('=== model schema') | ||
console.log(this.schema) | ||
} | ||
|
||
/* Properties | ||
**********/ | ||
|
||
get schema () { | ||
return (this._content != null) ? this._content.schema : null; | ||
} | ||
|
||
requestSchema (topic, message) { | ||
MessageBus.int.publish(MessageBus.buildResponseTopic(topic, message), this.schema) | ||
} | ||
} | ||
|
||
(function () { | ||
DCC.component('dcc-model', DCCModel) | ||
})() |
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,100 @@ | ||
/** | ||
* Embeds a data model | ||
*/ | ||
|
||
class DCCRest extends DCCBase { | ||
constructor () { | ||
super() | ||
} | ||
|
||
async connectedCallback () { | ||
super.connectedCallback() | ||
|
||
// this.presentReport = this.presentReport.bind(this) | ||
|
||
/* | ||
const schema = await this.request('data/schema') | ||
console.log('=== schema') | ||
console.log(schema) | ||
*/ | ||
} | ||
|
||
async connect (id, topic) { | ||
super.connect(id, topic) | ||
const schema = await this.request('data/schema') | ||
} | ||
|
||
async restRequest(method, parameters) { | ||
console.log('=== rest request') | ||
console.log(method) | ||
console.log(parameters) | ||
if (this._content != null && this._content.paths != null) { | ||
const paths = Object.keys(this._content.paths) | ||
if (paths.length > 0) { | ||
let url = paths[0] | ||
for (let p in parameters) | ||
url = url.replace('{' + p + '}', parameters[p]) | ||
const request = { | ||
method: method.toUpperCase(), | ||
url: url, | ||
crossDomain: true, | ||
headers: { | ||
'Access-Control-Allow-Origin': '*' | ||
} | ||
} | ||
console.log("=== request header") | ||
console.log(request) | ||
axios(request) | ||
.then(function (response) { | ||
console.log('=== REST response') | ||
console.log(response) | ||
// MessageBus.ext.publish(MessageBus.buildResponseTopic(topic, message), | ||
// response.data.source) | ||
}) | ||
.catch(function (error) { | ||
console.log('=== REST error') | ||
console.log(error) | ||
}) | ||
/* | ||
const header = { | ||
async: true, | ||
crossDomain: true, | ||
method: method.toUpperCase(), | ||
headers: { | ||
'Access-Control-Allow-Origin': '*', | ||
'Content-Type': 'application/json' | ||
} | ||
} | ||
const response = await fetch(url, header) | ||
const jsonResponse = await response.json() | ||
*/ | ||
} | ||
} | ||
} | ||
|
||
async notify (topic, message) { | ||
console.log('=== notify') | ||
console.log(topic) | ||
console.log(message.role) | ||
if (message.role) { | ||
switch (message.role.toLowerCase()) { | ||
case 'get': | ||
if (topic.startsWith('var/')) { | ||
let parameters = {} | ||
parameters[MessageBus.extractLevel(topic, 2)] = | ||
((message.body) | ||
? ((message.body.value) ? message.body.value : message) | ||
: ((message.value) ? message.value : message)) | ||
this.restRequest('get', parameters) | ||
} | ||
break | ||
} | ||
} | ||
} | ||
|
||
} | ||
|
||
(function () { | ||
DCC.component('dcc-rest', DCCRest) | ||
})() |
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,47 @@ | ||
/** | ||
* Embeds a data model | ||
*/ | ||
|
||
class DCCSubmit extends DCCButton { | ||
connectedCallback () { | ||
super.connectedCallback() | ||
} | ||
|
||
async connect (id, topic) { | ||
super.connect(id, topic) | ||
const result = await this.request('data/schema') | ||
if (result != null && result[id] != null) | ||
this._schema = result[id] | ||
console.log('=== requested schema') | ||
console.log(this._schema) | ||
} | ||
|
||
_computeTrigger () { | ||
if (this._active) { | ||
const message = { sourceType: this.nodeName.toLowerCase() } | ||
if (this.hasAttribute('label') || this.hasAttribute('topic')) { | ||
const topic = (this.hasAttribute('topic')) | ||
? this.topic : 'button/' + this.label + '/submit' | ||
if (this.hasAttribute('message')) { message.value = this.message } | ||
if (this._schema != null) { | ||
const schema = Object.keys(this._schema) | ||
console.log('=== form schema') | ||
console.log(schema) | ||
for (let s of schema) { | ||
let field = document.querySelector('#' + s) | ||
if (field != null) | ||
message[s] = field.value | ||
} | ||
} | ||
console.log('=== form') | ||
console.log(topic) | ||
console.log(message) | ||
MessageBus.ext.publish(topic, message) | ||
} | ||
} | ||
} | ||
} | ||
|
||
(function () { | ||
DCC.component('dcc-submit', DCCSubmit) | ||
})() |
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
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,49 @@ | ||
/* DCC Connector | ||
**************/ | ||
|
||
class ConnectDCC extends HTMLElement { | ||
connectedCallback () { | ||
if (this.hasAttribute('to') && this.hasAttribute('topic')) { | ||
this._fromObj = (this.hasAttribute('from')) | ||
? document.querySelector('#' + this.from) : this.parentNode | ||
console.log("=== to connect") | ||
console.log(this._fromObj) | ||
this._fromObj.connect(this.to, this.topic) | ||
} | ||
} | ||
|
||
/* Properties | ||
**********/ | ||
|
||
static get observedAttributes () { | ||
return ['from', 'to', 'topic'] | ||
} | ||
|
||
get from () { | ||
return this.getAttribute('from') | ||
} | ||
|
||
set from (newValue) { | ||
this.setAttribute('from', newValue) | ||
} | ||
|
||
get to () { | ||
return this.getAttribute('to') | ||
} | ||
|
||
set to (newValue) { | ||
this.setAttribute('to', newValue) | ||
} | ||
|
||
get topic () { | ||
return this.getAttribute('topic') | ||
} | ||
|
||
set topic (newValue) { | ||
this.setAttribute('topic', newValue) | ||
} | ||
} | ||
|
||
(function () { | ||
customElements.define('connect-dcc', ConnectDCC) | ||
})() |
Oops, something went wrong.