-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Phillip Kruger <[email protected]>
- Loading branch information
1 parent
ea88a3c
commit 329058d
Showing
4 changed files
with
193 additions
and
22 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
102 changes: 99 additions & 3 deletions
102
...ons/vertx-http/dev-ui-resources/src/main/resources/dev-ui/qwc/qwc-configuration-editor.js
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 |
---|---|---|
@@ -1,23 +1,119 @@ | ||
import { LitElement, html, css } from 'lit'; | ||
import { JsonRpc } from 'jsonrpc'; | ||
import { notifier } from 'notifier'; | ||
import 'qui-code-block'; | ||
import '@vaadin/button'; | ||
import '@vaadin/icon'; | ||
import '@vaadin/progress-bar'; | ||
|
||
/** | ||
* This component allows users to change the configuration in an online editor | ||
*/ | ||
export class QwcConfigurationEditor extends LitElement { | ||
jsonRpc = new JsonRpc(this); | ||
|
||
static styles = css` | ||
:host { | ||
display: flex; | ||
flex-direction:column; | ||
gap: 20px; | ||
} | ||
.toolbar { | ||
display: flex; | ||
gap: 20px; | ||
align-items: center; | ||
} | ||
`; | ||
|
||
static properties = { | ||
static properties = { | ||
_type: {state: true}, | ||
_value: {state: true}, | ||
_error: {state: true}, | ||
_inProgress: {state: true, type: Boolean} | ||
}; | ||
|
||
constructor() { | ||
super(); | ||
this._error = null; | ||
this._value = null; | ||
this._type = null; | ||
this._inProgress = false; | ||
} | ||
|
||
connectedCallback() { | ||
super.connectedCallback(); | ||
this.jsonRpc.getProjectProperties().then(e => { | ||
if(e.result.error){ | ||
this._error = e.result.error; | ||
}else{ | ||
this._type = e.result.type; | ||
this._value = e.result.value; | ||
} | ||
}); | ||
|
||
this.addEventListener('keydown', this._handleCtrlS); | ||
} | ||
|
||
disconnectedCallback() { | ||
this.removeEventListener('keydown', this._handleCtrlS); | ||
super.disconnectedCallback(); | ||
} | ||
|
||
_handleCtrlS(e){ | ||
if (e.ctrlKey && e.key === 's') { | ||
e.preventDefault(); | ||
this._save(); | ||
} | ||
} | ||
|
||
render() { | ||
return html`<span>TODO: Configuration properties editor</span>`; | ||
if(this._error){ | ||
return html`<span>Error: ${this._error}</span>`; | ||
} | ||
|
||
if(this._value){ | ||
return html` | ||
${this._renderToolbar()} | ||
<qui-code-block id="code" | ||
mode='${this._type}' | ||
content='${this._value}' | ||
value='${this._value}' | ||
editable> | ||
</qui-code-block>`; | ||
} | ||
} | ||
|
||
_renderToolbar(){ | ||
return html`<div class="toolbar"> | ||
<code>application.${this._type}</code> | ||
${this._renderProgressOrButton()} | ||
</div>`; | ||
} | ||
|
||
_renderProgressOrButton(){ | ||
if(this._inProgress){ | ||
return html`<vaadin-progress-bar class="progress" indeterminate></vaadin-progress-bar>`; | ||
}else{ | ||
return html`<vaadin-button @click="${() => this._save()}"> | ||
<vaadin-icon icon="font-awesome-solid:floppy-disk" slot="prefix"></vaadin-icon> | ||
Save | ||
</vaadin-button>`; | ||
} | ||
} | ||
|
||
_save(){ | ||
this._inProgress = true; | ||
let newValue = this.shadowRoot.getElementById('code').getAttribute('value'); | ||
this.jsonRpc.updateProperties({content: newValue, type: this._type}).then(jsonRpcResponse => { | ||
this._inProgress = false; | ||
if(jsonRpcResponse.result === false){ | ||
notifier.showErrorMessage("Configuration failed to update. See log file for details"); | ||
}else{ | ||
notifier.showSuccessMessage("Configuration successfully updated"); | ||
} | ||
}); | ||
} | ||
} | ||
|
||
customElements.define('qwc-configuration-editor', QwcConfigurationEditor); | ||
customElements.define('qwc-configuration-editor', QwcConfigurationEditor); | ||
|
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