Skip to content

Commit 2d6d55b

Browse files
authored
Merge pull request #1805 from thfries/ui_fullscreen_editors
UI - Allow editors in full screen mode
2 parents 619913c + 306fe6f commit 2d6d55b

File tree

6 files changed

+64
-48
lines changed

6 files changed

+64
-48
lines changed

Diff for: ui/main.scss

+8-4
Original file line numberDiff line numberDiff line change
@@ -184,10 +184,14 @@ hr {
184184
}
185185

186186
.editForgroundBig {
187-
position: absolute;
188-
right: 24px;
189-
width: 90%;
190-
height: 80%;
187+
z-index: 1200;
188+
position: fixed;
189+
background-color: white;
190+
top: 0;
191+
bottom: 0;
192+
right: 0;
193+
left: 0;
194+
height: auto;
191195
}
192196

193197
.dropdown-menu {

Diff for: ui/modules/connections/connections.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ <h5 data-bs-toggle="collapse" data-bs-target="#connectionsEdit">
4343
</div>
4444
<div class="col-md-8 resizable_flex_column">
4545
<h6>CRUD Connection</h6>
46-
<crud-toolbar label="Connection Id" id="crudConnection" style="flex-grow: 1;" extraeditclass="editForgroundBig">
46+
<crud-toolbar label="Connection Id" id="crudConnection" style="flex-grow: 1;">
4747
<div class="input-group input-group-sm mb-1">
4848
<label class="input-group-text">Template</label>
4949
<div class="btn-group dropend">

Diff for: ui/modules/things/features.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ <h5 data-bs-toggle="collapse" data-bs-target="#collapseFeatures">
3434
</ul>
3535
<div class="tab-content" style="flex-grow: 1;" id="tabContentFeatures">
3636
<div class="tab-pane container active no-margin" id="tabCrudFeature">
37-
<crud-toolbar id="crudFeature" label="Feature ID" extraeditclass="editForgroundBig">
37+
<crud-toolbar id="crudFeature" label="Feature ID">
3838
<div class="input-group input-group-sm mb-1">
3939
<label class="input-group-text">Definition</label>
4040
<input type="text" class="form-control" id="inputFeatureDefinition" disabled></input>

Diff for: ui/modules/things/things.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767
</div>
6868
</div>
6969
<div class="tab-pane fade container no-margin" style="height:100%;" id="tabModifyThing">
70-
<crud-toolbar id="crudThings" label="Thing ID" extraeditclass="editForgroundBig">
70+
<crud-toolbar id="crudThings" label="Thing ID">
7171
<div class="input-group input-group-sm mb-1">
7272
<label class="input-group-text" id="labelX">Definition</label>
7373
<div class="btn-group dropend">

Diff for: ui/modules/utils/crudToolbar.html

+3
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323
<button class="btn btn-outline-secondary btn-sm" hidden id="buttonCancel" data-bs-toggle="tooltip" title="Cancel">
2424
Cancel
2525
</button>
26+
<button type="button" id="buttonFullscreen" hidden class="btn btn-outline-secondary btn-sm button_round_both ms-1" title="Toggle fullscreen">
27+
<i class="bi bi-arrows-fullscreen"></i>
28+
</button>
2629
<div class="invalid-feedback"></div>
2730
</div>
2831
<slot></slot>

Diff for: ui/modules/utils/crudToolbar.ts

+50-41
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,15 @@
1414
import * as Utils from '../utils.js';
1515
import crudToolbarHTML from './crudToolbar.html';
1616

17+
const CLASS_BG = 'editBackground'
18+
const CLASS_FG = 'editForground';
19+
const CLASS_FG_FULLSCREEN = 'editForgroundBig';
20+
21+
let ICON_CLASS_FS = 'bi-arrows-fullscreen';
22+
let ICON_CLASS_FS_EXIT = 'bi-fullscreen-exit';
23+
24+
const ATTR_FULLSCREEN = 'fullscreen';
25+
1726
export enum CrudOperation {
1827
CREATE,
1928
UPDATE,
@@ -33,38 +42,14 @@ export class CrudToolbar extends HTMLElement {
3342
buttonUpdate: null,
3443
buttonDelete: null,
3544
buttonCancel: null,
45+
buttonFullscreen: null,
3646
divRoot: null,
3747
};
3848

39-
static get observedAttributes() {
40-
return [`extraeditclass`];
41-
}
42-
43-
private _extraEditClass: string;
44-
45-
get extraeditclass() {
46-
return this._extraEditClass;
47-
}
48-
49-
set extraeditclass(val: string) {
50-
if (val == null) { // check for null and undefined
51-
this.removeAttribute('extraeditclass');
52-
}
53-
else {
54-
this.setAttribute('extraeditclass', val);
55-
}
56-
}
57-
5849
get idValue() {
5950
return this.dom.inputIdValue.value;
6051
}
6152

62-
attributeChangedCallback(name, oldValue, newValue) {
63-
if (name === `extraeditclass`) {
64-
this._extraEditClass = newValue;
65-
}
66-
}
67-
6853
set idValue(newValue) {
6954
const domInput: HTMLInputElement = this.shadowRoot.getElementById('inputIdValue') as HTMLInputElement;
7055
domInput.value = newValue;
@@ -91,23 +76,32 @@ export class CrudToolbar extends HTMLElement {
9176

9277
set createDisabled(newValue: boolean) {
9378
this.isCreateDisabled = newValue;
94-
this.setButtonState('buttonCreate', newValue);
79+
this.lazyInit(this.dom.buttonCreate);
80+
this.setButtonState(this.dom.buttonCreate, newValue);
9581
}
9682

9783
set deleteDisabled(newValue: boolean) {
9884
this.isDeleteDisabled = newValue;
99-
this.setButtonState('buttonDelete', newValue);
85+
this.lazyInit(this.dom.buttonDelete);
86+
this.setButtonState(this.dom.buttonDelete, newValue);
10087
}
10188

10289
set editDisabled(newValue: boolean) {
10390
this.isEditDisabled = newValue;
10491
if (!this.isEditing) {
105-
this.setButtonState('buttonEdit', newValue);
92+
this.lazyInit(this.dom.buttonEdit);
93+
this.setButtonState(this.dom.buttonEdit, newValue);
10694
}
10795
}
10896

109-
setButtonState(buttonId, isDisabled) {
110-
const button = this.shadowRoot.getElementById(buttonId);
97+
lazyInit(element: HTMLElement) {
98+
if (!element) {
99+
Utils.getAllElementsById(this.dom, this.shadowRoot);
100+
}
101+
}
102+
103+
setButtonState(button: HTMLButtonElement, isDisabled: boolean) {
104+
// const button = this.shadowRoot.getElementById(buttonId);
111105

112106
if (isDisabled) {
113107
button.setAttribute('hidden', '');
@@ -136,6 +130,7 @@ export class CrudToolbar extends HTMLElement {
136130
this.dom.buttonCreate.onclick = this.eventDispatcher('onCreateClick');
137131
this.dom.buttonUpdate.onclick = this.eventDispatcher('onUpdateClick');
138132
this.dom.buttonDelete.onclick = this.eventDispatcher('onDeleteClick');
133+
this.dom.buttonFullscreen.onclick = () => this.toggleFullscreen();
139134
this.dom.inputIdValue.addEventListener('change', (event) => {
140135
(event.target as HTMLElement).classList.remove('is-invalid');
141136
this.dispatchEvent(new CustomEvent('onIdValueChange', { composed: true }));
@@ -153,17 +148,16 @@ export class CrudToolbar extends HTMLElement {
153148

154149
toggleEdit(isCancel) {
155150
this.isEditing = !this.isEditing;
156-
document.getElementById('modalCrudEdit').classList.toggle('editBackground');
157-
this.dom.divRoot.classList.toggle('editForground');
158-
if (this._extraEditClass) {
159-
this.dom.divRoot.classList.toggle(this._extraEditClass);
160-
}
161-
162-
if (this.isEditing || this.isEditDisabled) {
163-
this.dom.buttonEdit.setAttribute('hidden', '');
164-
} else {
165-
this.dom.buttonEdit.removeAttribute('hidden');
166-
}
151+
152+
// toggle modal mode;
153+
document.getElementById('modalCrudEdit').classList.toggle(CLASS_BG);
154+
document.body.classList.toggle('modal-open');
155+
document.body.style.overflow = this.isEditing && this.hasAttribute(ATTR_FULLSCREEN) ? 'hidden' : '';
156+
this.dom.divRoot.classList.toggle(this.hasAttribute(ATTR_FULLSCREEN) ? CLASS_FG_FULLSCREEN : CLASS_FG);
157+
158+
// toggle button states;
159+
this.setButtonState(this.dom.buttonEdit, this.isEditing || this.isEditDisabled);
160+
this.setButtonState(this.dom.buttonFullscreen, !this.isEditing);
167161
this.dom.buttonCancel.toggleAttribute('hidden');
168162

169163
if (this.isEditing) {
@@ -179,8 +173,11 @@ export class CrudToolbar extends HTMLElement {
179173
if (this.isEditing || !this.dom.inputIdValue.value) {
180174
this.dom.buttonDelete.setAttribute('hidden', '');
181175
}
176+
177+
182178
const allowIdChange = this.isEditing && (!this.dom.inputIdValue.value || this.hasAttribute('allowIdChange'));
183179
this.dom.inputIdValue.disabled = !allowIdChange;
180+
184181
this.dispatchEvent(new CustomEvent('onEditToggle', {
185182
composed: true,
186183
detail: {
@@ -189,6 +186,18 @@ export class CrudToolbar extends HTMLElement {
189186
},
190187
}));
191188
}
189+
190+
toggleFullscreen() {
191+
this.toggleAttribute(ATTR_FULLSCREEN);
192+
this.dom.buttonFullscreen.querySelector('.bi').classList.toggle(ICON_CLASS_FS);
193+
this.dom.buttonFullscreen.querySelector('.bi').classList.toggle(ICON_CLASS_FS_EXIT);
194+
document.body.style.overflow = this.isEditing && this.hasAttribute(ATTR_FULLSCREEN) ? 'hidden' : '';
195+
if (this.dom.divRoot.classList.contains(CLASS_FG)) {
196+
this.dom.divRoot.classList.replace(CLASS_FG, CLASS_FG_FULLSCREEN);
197+
} else {
198+
this.dom.divRoot.classList.replace(CLASS_FG_FULLSCREEN, CLASS_FG);
199+
}
200+
}
192201
}
193202

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

0 commit comments

Comments
 (0)