Skip to content

Commit e85f185

Browse files
asasui-2ruki2067
authored andcommitted
Add a remove-display modal to confirm the removal
1 parent c56d06d commit e85f185

File tree

4 files changed

+78
-25
lines changed

4 files changed

+78
-25
lines changed

base/cvd/cuttlefish/host/frontend/webrtc/html_client/client.html

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,15 @@ <h2>Add display</h2>
293293
<button id='display-add-confirm' title='Add a new display' class='modal-button'>Add</button>
294294
</div>
295295
</div>
296+
<div id='display-remove-modal' class='modal' data-removal_display_id='0'>
297+
<div id='display-remove-modal-header' class='modal-header'>
298+
<h2 id='display-remove-text'></h2>
299+
</div>
300+
<div class='display-remove-buttons'>
301+
<button id='display-remove-modal-confirm' title='Confirm' class='modal-button'>confirm</button>
302+
<button id='display-remove-modal-cancel' title='Cancel' class='modal-button '>cancel</button>
303+
</div>
304+
</div>
296305
<script src="js/adb.js"></script>
297306
<script src="js/location.js"></script>
298307
<script src="js/keyboard.js"></script>
@@ -307,7 +316,7 @@ <h2>Add display</h2>
307316
<div class="device-display">
308317
<div class="device-display-info">
309318
<div class="device-display-info-text"></div>
310-
<button class="material-icons device-display-remove-button" title="Remove display">delete</button>
319+
<button class="material-icons device-display-remove-modal-button" title="Remove display">delete</button>
311320
</div>
312321
<div class="device-video-container">
313322
<video autoplay muted playsinline src="/" class="device-display-video"></video>
@@ -316,4 +325,3 @@ <h2>Add display</h2>
316325
</template>
317326
</body>
318327
</html>
319-

base/cvd/cuttlefish/host/frontend/webrtc/html_client/js/app.js

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,9 @@ class DeviceControlApp {
334334
createSelectListener('display-spec-preset-select', () => this.#updateDisplaySpecFrom());
335335
createButtonListener('display-add-confirm', null, this.#deviceConnection, evt => this.#onDisplayAdditionConfirm(evt));
336336

337+
createButtonListener('display-remove-modal-confirm',null,this.#deviceConnection, () => this.#handleDisplayRemovalModalAction('confirm'));
338+
createButtonListener('display-remove-modal-cancel',null,this.#deviceConnection, () => this.#handleDisplayRemovalModalAction('cancel'));
339+
337340
if (this.#deviceConnection.description.custom_control_panel_buttons.length >
338341
0) {
339342
document.getElementById('control-panel-custom-buttons').style.display =
@@ -677,12 +680,26 @@ class DeviceControlApp {
677680
this.#deviceConnection.sendControlMessage(JSON.stringify(message));
678681
}
679682

683+
#handleDisplayRemovalModalAction(action){
684+
const removeModalElement = document.getElementById('display-remove-modal');
685+
const removeDisplayId = removeModalElement.dataset.removal_display_id;
686+
let removeButtonId = removeDisplayId + '_remove_button';
687+
if(action === 'confirm'){
688+
this.#removeDisplay(removeDisplayId);
689+
} else {
690+
// Clear the dataset on cancel.
691+
delete removeModalElement.dataset.removal_display_id;
692+
}
693+
hideModal(removeButtonId,'display-remove-modal');
694+
}
695+
680696
#removeDisplay(displayId) {
681697
const message = {
682698
command: 'remove-display',
683699
display_id: displayId
684700
};
685701
this.#deviceConnection.sendControlMessage(JSON.stringify(message));
702+
console.debug(`display_id being removed in the removeDisplay function=${displayId}`);
686703
}
687704

688705
#showWebrtcError() {
@@ -940,11 +957,8 @@ class DeviceControlApp {
940957
deviceDisplayInfo.id = stream_id + '_info';
941958

942959
let deviceDisplayRemoveButton =
943-
displayFragment.querySelector('.device-display-remove-button');
944-
deviceDisplayRemoveButton.id = stream_id + '_remove_button';
945-
deviceDisplayRemoveButton.addEventListener('mousedown', () => {
946-
this.#removeDisplay(display_id);
947-
});
960+
displayFragment.querySelector('.device-display-remove-modal-button');
961+
deviceDisplayRemoveButton.id = display_id + '_remove_button';
948962

949963
deviceDisplayVideo = displayFragment.querySelector('video');
950964
deviceDisplayVideo.id = stream_id;
@@ -963,6 +977,17 @@ class DeviceControlApp {
963977

964978
deviceDisplays.appendChild(displayFragment);
965979

980+
createModalButton(deviceDisplayRemoveButton.id , 'display-remove-modal', null);
981+
let removeModalElement = document.getElementById('display-remove-modal');
982+
createButtonListener(deviceDisplayRemoveButton.id, null, this.#deviceConnection, () => {
983+
let removeDisplayText = document.getElementById('display-remove-text');
984+
985+
// Store the display ID of the most recently clicked trash icon.
986+
// This prevents the deletion of multiple displays.
987+
removeDisplayText.textContent = `Delete the display ${display_id} ?`;
988+
removeModalElement.dataset.removal_display_id = display_id;
989+
});
990+
966991
// Confusingly, events for adding tracks occur on the peer connection
967992
// but events for removing tracks occur on the stream.
968993
stream.addEventListener('removetrack', evt => {
@@ -1350,4 +1375,3 @@ function getStyleAfterRotation(rotationDeg, ar) {
13501375

13511376
return {transform, maxWidth, maxHeight};
13521377
}
1353-

base/cvd/cuttlefish/host/frontend/webrtc/html_client/js/controls.js

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -260,32 +260,47 @@ function positionModal(button_id, modal_id) {
260260
modalDiv.style.left = modalButton.offsetWidth + 30;
261261
}
262262

263+
function showModal(button_id,modal_id) {
264+
const modalButton = document.getElementById(button_id);
265+
const modalDiv = document.getElementById(modal_id);
266+
267+
modalButton.classList.add('modal-button-opened')
268+
modalDiv.style.display = 'block';
269+
}
270+
271+
function hideModal(button_id,hide_id){
272+
const modalButton = document.getElementById(button_id);
273+
const modalDivHide = document.getElementById(hide_id);
274+
275+
modalButton.classList.remove('modal-button-opened');
276+
modalDivHide.style.display = 'none';
277+
}
278+
263279
function createModalButton(button_id, modal_id, close_id, hide_id) {
264280
const modalButton = document.getElementById(button_id);
265281
const modalDiv = document.getElementById(modal_id);
266282
const modalHeader = modalDiv.querySelector('.modal-header');
267283
const modalClose = document.getElementById(close_id);
268-
const modalDivHide = document.getElementById(hide_id);
269284

270285
positionModal(button_id, modal_id);
271286

272-
function showHideModal(show) {
273-
if (show) {
274-
modalButton.classList.add('modal-button-opened')
275-
modalDiv.style.display = 'block';
276-
} else {
277-
modalButton.classList.remove('modal-button-opened')
278-
modalDiv.style.display = 'none';
287+
// Allow the show modal button to toggle the modal,
288+
modalButton.addEventListener('click', evt => {
289+
if(modalDiv.style.display != 'block'){
290+
showModal(button_id,modal_id);
291+
}else{
292+
hideModal(button_id,modal_id);
279293
}
280-
if (modalDivHide != null) {
281-
modalDivHide.style.display = 'none';
294+
295+
if (hide_id != null) {
296+
hideModal(button_id,hide_id);
282297
}
283-
}
284-
// Allow the show modal button to toggle the modal,
285-
modalButton.addEventListener(
286-
'click', evt => showHideModal(modalDiv.style.display != 'block'));
298+
});
299+
287300
// but the close button always closes.
288-
modalClose.addEventListener('click', evt => showHideModal(false));
301+
if(modalClose){
302+
modalClose.addEventListener('click', evt => hideModal(button_id,modal_id));
303+
}
289304

290305
// Allow the modal to be dragged by the header.
291306
let modalOffsets = {

base/cvd/cuttlefish/host/frontend/webrtc/html_client/style.css

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -405,8 +405,14 @@ button{
405405
align-items: center;
406406
}
407407

408-
.device-display-remove-button {
409-
color: var(--main-fg);
408+
.device-display-remove-modal-button {
409+
color: #fafafa;
410+
}
411+
412+
.display-remove-buttons {
413+
display: flex;
414+
margin: 5px;
415+
justify-content: space-between;
410416
}
411417

412418
/* The actual <video> element for each display. */

0 commit comments

Comments
 (0)