Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom operators #1

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions static/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,14 @@ host.BrowserHost = class {
openFileDialog.click();
});
}

const makeCustomOperatorSidebar = this.document.getElementById('make-custom-operator');
makeCustomOperatorSidebar.addEventListener('click', () => {
const customOperatorSidebar = new sidebar.CustomOperatorSidebar(this);
console.log(sidebar);
this._view._sidebar.open(customOperatorSidebar.render(), 'Custom Operator'); // bad practice change later
})

const githubButton = this.document.getElementById('github-button');
const githubLink = this.document.getElementById('logo-github');
if (githubButton && githubLink) {
Expand Down
59 changes: 59 additions & 0 deletions static/view-sidebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,7 @@ sidebar.NodeSidebar = class {
_raise(event, data) {
if (this._events && this._events[event]) {
for (const callback of this._events[event]) {
console.log(`raised event ${event} data ${data}`)
callback(this, data);
}
}
Expand Down Expand Up @@ -545,6 +546,64 @@ sidebar.NodeSidebar = class {
}
};

sidebar.CustomOperatorSidebar = class {
constructor(host) {
this._host = host;
this._elements = [];

this._addEditableProperty('type');
this._addHeader('Attributes');
this._addProperty('addProperty test', new sidebar.ValueTextView(this._host, "foo"));
this._addHeader('Inputs');
this._addHeader('Outputs');
}

render() {
return this._elements;
}

_addHeader(title) {
const headerElement = this._host.document.createElement('div');
headerElement.className = 'sidebar-view-header';
headerElement.innerText = title;
this._elements.push(headerElement);
}

_addProperty(name, value) {
const item = new sidebar.NameValueView(this._host, name, value);
this._elements.push(item.render());
}

_addEditableProperty(name) {
const valueElement = this._host.document.createElement('div');
valueElement.className = 'sidebar-view-item-value'
const inputElement = this._host.document.createElement('input');
inputElement.setAttribute('type', 'text');
inputElement.setAttribute('value', '');
inputElement.setAttribute('title', '');
inputElement.setAttribute('size', '42');
valueElement.appendChild(inputElement);

this._elements.push((new sidebar.NameValueView(this._host, name, {render() {return [valueElement];}})).render());
}

/*
_addButton(title) {
const buttonElement = this._host.document.createElement('button');
buttonElement.className = 'sidebar-view-button';
buttonElement.innerText = title;
this._elements.push(buttonElement);

if (title === 'Create') {
buttonElement.addEventListener('click', () => {
// put this code somewhere else later?

});
}
}
*/
}

sidebar.NameValueView = class {

constructor(host, name, value) {
Expand Down
1 change: 1 addition & 0 deletions templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,7 @@
<select id="add-node-dropdown" class="graph-op-add-node-dropdown">
</select>
<button id="load-model" class="graph-button-load">LoadModel</button>
<button id="make-custom-operator" class="graph-op-button-makeCustomOperator">Make custom operator</button>

<button id="back-button" class="toolbar-back-button" title="Back">
&#x276E;
Expand Down