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

UI - Allow editors in full screen mode #1805

Merged
merged 3 commits into from
Nov 21, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
12 changes: 8 additions & 4 deletions ui/main.scss
Original file line number Diff line number Diff line change
Expand Up @@ -175,10 +175,14 @@ hr {
}

.editForgroundBig {
position: absolute;
right: 24px;
width: 90%;
height: 80%;
z-index: 1200;
position: fixed;
background-color: white;
top: 0;
bottom: 0;
right: 0;
left: 0;
height: auto;
}

.dropdown-menu {
Expand Down
2 changes: 1 addition & 1 deletion ui/modules/connections/connections.html
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ <h5 data-bs-toggle="collapse" data-bs-target="#connectionsEdit">
</div>
<div class="col-md-8 resizable_flex_column">
<h6>CRUD Connection</h6>
<crud-toolbar label="Connection Id" id="crudConnection" style="flex-grow: 1;" extraeditclass="editForgroundBig">
<crud-toolbar label="Connection Id" id="crudConnection" style="flex-grow: 1;">
<div class="input-group input-group-sm mb-1">
<label class="input-group-text">Template</label>
<div class="btn-group dropend">
Expand Down
2 changes: 1 addition & 1 deletion ui/modules/things/features.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ <h5 data-bs-toggle="collapse" data-bs-target="#collapseFeatures">
</ul>
<div class="tab-content" style="flex-grow: 1;" id="tabContentFeatures">
<div class="tab-pane container active no-margin" id="tabCrudFeature">
<crud-toolbar id="crudFeature" label="Feature ID" extraeditclass="editForgroundBig">
<crud-toolbar id="crudFeature" label="Feature ID">
<div class="input-group input-group-sm mb-1">
<label class="input-group-text">Definition</label>
<input type="text" class="form-control" id="inputFeatureDefinition" disabled></input>
Expand Down
2 changes: 1 addition & 1 deletion ui/modules/things/things.html
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
</div>
</div>
<div class="tab-pane fade container no-margin" style="height:100%;" id="tabModifyThing">
<crud-toolbar id="crudThings" label="Thing ID" extraeditclass="editForgroundBig">
<crud-toolbar id="crudThings" label="Thing ID">
<div class="input-group input-group-sm mb-1">
<label class="input-group-text" id="labelX">Definition</label>
<div class="btn-group dropend">
Expand Down
3 changes: 3 additions & 0 deletions ui/modules/utils/crudToolbar.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
<button class="btn btn-outline-secondary btn-sm" hidden id="buttonCancel" data-bs-toggle="tooltip" title="Cancel">
Cancel
</button>
<button type="button" id="buttonFullscreen" hidden class="btn btn-outline-secondary btn-sm button_round_both ms-1" title="Toggle fullscreen">
<i class="bi bi-arrows-fullscreen"></i>
</button>
<div class="invalid-feedback"></div>
</div>
<slot></slot>
Expand Down
91 changes: 50 additions & 41 deletions ui/modules/utils/crudToolbar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,15 @@
import * as Utils from '../utils.js';
import crudToolbarHTML from './crudToolbar.html';

const CLASS_BG = 'editBackground'
const CLASS_FG = 'editForground';
const CLASS_FG_FULLSCREEN = 'editForgroundBig';

let ICON_CLASS_FS = 'bi-arrows-fullscreen';
let ICON_CLASS_FS_EXIT = 'bi-fullscreen-exit';

const ATTR_FULLSCREEN = 'fullscreen';

class CrudToolbar extends HTMLElement {
isEditing = false;
isEditDisabled = false;
Expand All @@ -27,38 +36,14 @@ class CrudToolbar extends HTMLElement {
buttonUpdate: null,
buttonDelete: null,
buttonCancel: null,
buttonFullscreen: null,
divRoot: null,
};

static get observedAttributes() {
return [`extraeditclass`];
}

private _extraEditClass: string;

get extraeditclass() {
return this._extraEditClass;
}

set extraeditclass(val: string) {
if (val == null) { // check for null and undefined
this.removeAttribute('extraeditclass');
}
else {
this.setAttribute('extraeditclass', val);
}
}

get idValue() {
return this.dom.inputIdValue.value;
}

attributeChangedCallback(name, oldValue, newValue) {
if (name === `extraeditclass`) {
this._extraEditClass = newValue;
}
}

set idValue(newValue) {
(this.shadowRoot.getElementById('inputIdValue') as HTMLInputElement).value = newValue;
const buttonDelete = this.shadowRoot.getElementById('buttonDelete');
Expand All @@ -75,23 +60,32 @@ class CrudToolbar extends HTMLElement {

set createDisabled(newValue) {
this.isCreateDisabled = newValue;
this.setButtonState('buttonCreate', newValue);
this.lazyInit(this.dom.buttonCreate);
this.setButtonState(this.dom.buttonCreate, newValue);
}

set deleteDisabled(newValue) {
this.isDeleteDisabled = newValue;
this.setButtonState('buttonDelete', newValue);
this.lazyInit(this.dom.buttonDelete);
this.setButtonState(this.dom.buttonDelete, newValue);
}

set editDisabled(newValue) {
this.isEditDisabled = newValue;
if (!this.isEditing) {
this.setButtonState('buttonEdit', newValue);
this.lazyInit(this.dom.buttonEdit);
this.setButtonState(this.dom.buttonEdit, newValue);
}
}

setButtonState(buttonId, isDisabled) {
const button = this.shadowRoot.getElementById(buttonId);
lazyInit(element: HTMLElement) {
if (!element) {
Utils.getAllElementsById(this.dom, this.shadowRoot);
}
}

setButtonState(button: HTMLButtonElement, isDisabled: boolean) {
// const button = this.shadowRoot.getElementById(buttonId);

if (isDisabled) {
button.setAttribute('hidden', '');
Expand Down Expand Up @@ -120,6 +114,7 @@ class CrudToolbar extends HTMLElement {
this.dom.buttonCreate.onclick = this.eventDispatcher('onCreateClick');
this.dom.buttonUpdate.onclick = this.eventDispatcher('onUpdateClick');
this.dom.buttonDelete.onclick = this.eventDispatcher('onDeleteClick');
this.dom.buttonFullscreen.onclick = () => this.toggleFullscreen();
});
};

Expand All @@ -133,17 +128,16 @@ class CrudToolbar extends HTMLElement {

toggleEdit(isCancel) {
this.isEditing = !this.isEditing;
document.getElementById('modalCrudEdit').classList.toggle('editBackground');
this.dom.divRoot.classList.toggle('editForground');
if (this._extraEditClass) {
this.dom.divRoot.classList.toggle(this._extraEditClass);
}

if (this.isEditing || this.isEditDisabled) {
this.dom.buttonEdit.setAttribute('hidden', '');
} else {
this.dom.buttonEdit.removeAttribute('hidden');
}

// toggle modal mode;
document.getElementById('modalCrudEdit').classList.toggle(CLASS_BG);
document.body.classList.toggle('modal-open');
document.body.style.overflow = this.isEditing && this.hasAttribute(ATTR_FULLSCREEN) ? 'hidden' : '';
this.dom.divRoot.classList.toggle(this.hasAttribute(ATTR_FULLSCREEN) ? CLASS_FG_FULLSCREEN : CLASS_FG);

// toggle button states;
this.setButtonState(this.dom.buttonEdit, this.isEditing || this.isEditDisabled);
this.setButtonState(this.dom.buttonFullscreen, !this.isEditing);
this.dom.buttonCancel.toggleAttribute('hidden');

if (this.isEditing) {
Expand All @@ -159,8 +153,11 @@ class CrudToolbar extends HTMLElement {
if (this.isEditing || !this.dom.inputIdValue.value) {
this.dom.buttonDelete.setAttribute('hidden', '');
}


const allowIdChange = this.isEditing && (!this.dom.inputIdValue.value || this.hasAttribute('allowIdChange'));
this.dom.inputIdValue.disabled = !allowIdChange;

this.dispatchEvent(new CustomEvent('onEditToggle', {
composed: true,
detail: {
Expand All @@ -169,6 +166,18 @@ class CrudToolbar extends HTMLElement {
},
}));
}

toggleFullscreen() {
this.toggleAttribute(ATTR_FULLSCREEN);
this.dom.buttonFullscreen.querySelector('.bi').classList.toggle(ICON_CLASS_FS);
this.dom.buttonFullscreen.querySelector('.bi').classList.toggle(ICON_CLASS_FS_EXIT);
document.body.style.overflow = this.isEditing && this.hasAttribute(ATTR_FULLSCREEN) ? 'hidden' : '';
if (this.dom.divRoot.classList.contains(CLASS_FG)) {
this.dom.divRoot.classList.replace(CLASS_FG, CLASS_FG_FULLSCREEN);
} else {
this.dom.divRoot.classList.replace(CLASS_FG_FULLSCREEN, CLASS_FG);
}
}
}

customElements.define('crud-toolbar', CrudToolbar);
Loading