Skip to content
Open
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
5 changes: 5 additions & 0 deletions frontend/go.work.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
github.com/hashicorp/go-multierror v1.1.1/go.mod h1:iw975J/qwKPdAO1clOe2L8331t/9/fmwbPZ6JB6eMoM=
golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.18.0/go.mod h1:ILwASektA3OnRv7amZ1xhE/KTR+u50pbXfZ03+6Nx58=
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
8 changes: 8 additions & 0 deletions frontend/src/operator/webui/src/app/app.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@
<mat-toolbar class="cloud-android-toolbar">
<button mat-icon-button id="device-pane-toggle" (click)="snav.toggle()"><mat-icon>menu</mat-icon></button>
<h1 class="cloud-android-title">Cloud Android</h1>
<mat-slide-toggle
color="primary"
[checked]="(displaysService.addVertically$ | async)!"
(change)="displaysService.toggleAddVertically($event.checked)"
class="add-vertically-toggle"
>
Add Device Panel<br />Vertically
</mat-slide-toggle>
Comment thread
0405ysj marked this conversation as resolved.
</mat-toolbar>

<mat-sidenav-container class="drawer-container">
Expand Down
23 changes: 21 additions & 2 deletions frontend/src/operator/webui/src/app/app.component.scss
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,33 @@
}

.cloud-android-toolbar {
display: flex;
justify-content: space-between;
align-items: center;
position: relative;
background: #073042;
color: #eee;
box-shadow: 0px 4px 10px rgba(0, 0, 0, 0.5);
text-align: center;
}

.cloud-android-title {
margin: 0 auto;
position: absolute;
left: 50%;
transform: translateX(-50%);
margin: 0;
}

.add-vertically-toggle {
margin-left: auto;
font-size: 13px;
line-height: 1.2;
color: #fff;

::ng-deep .mdc-label {
color: #fff;
white-space: normal;
text-align: left;
}
}

.drawer-container {
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/operator/webui/src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {BUILD_VERSION} from '../environments/version'
})
export class AppComponent {
readonly version = BUILD_VERSION;
constructor(private displaysService: DisplaysService) {}
constructor(public displaysService: DisplaysService) {}

@HostListener('window:message', ['$event'])
onWindowMessage(e: MessageEvent) {
Expand Down
8 changes: 7 additions & 1 deletion frontend/src/operator/webui/src/app/displays.service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {Injectable, inject} from '@angular/core';
import {Subject, merge} from 'rxjs';
import {BehaviorSubject, Subject, merge} from 'rxjs';
import {map, mergeMap} from 'rxjs/operators';
import {DeviceService} from './device.service';

Expand All @@ -9,6 +9,12 @@ import {DeviceService} from './device.service';
export class DisplaysService {
private deviceService = inject(DeviceService);

addVertically$ = new BehaviorSubject<boolean>(false);

toggleAddVertically(enabled: boolean): void {
this.addVertically$.next(enabled);
}

private devices = this.deviceService.getAllDevices();

private visibleDeviceIds: string[] = [];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<div #viewPane>
<ktd-grid
class="view-pane"
compactType="horizontal"
[compactType]="(displaysService.addVertically$ | async) ? 'vertical' : 'horizontal'"
rowHeight="1"
scrollSpeed="4"
[cols]="cols"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,16 +237,25 @@ export class ViewPaneComponent implements OnInit, OnDestroy, AfterViewInit {
item: DeviceGridItem,
layout: DeviceGridItem[]
): DeviceGridItem {
const lastMaxY =
layout.length !== 0 ? Math.max(...layout.map(obj => obj.y)) : 0;
const lastRowLayout = layout.filter(obj => obj.y === lastMaxY);
const lastMaxX =
layout.length !== 0
? Math.max(...lastRowLayout.map(obj => obj.x))
: -item.w;

item.x = lastMaxX + item.w * 2 <= this.cols ? lastMaxX + item.w : 0;
item.y = lastMaxX + item.h * 2 <= this.cols ? lastMaxY : lastMaxY + item.h;
if (this.displaysService.addVertically$.value) {
const newItemY =
layout.length !== 0
? Math.max(...layout.map(obj => obj.y + obj.h))
: 0;
item.x = 0;
item.y = newItemY;
} else {
const lastItemY =
layout.length !== 0 ? Math.max(...layout.map(obj => obj.y)) : 0;
const lastRowLayout = layout.filter(obj => obj.y === lastItemY);
const lastItemX =
layout.length !== 0
? Math.max(...lastRowLayout.map(obj => obj.x))
: -item.w;

item.x = lastItemX + item.w * (1.0 / this.defaultDisplayZoom) <= this.cols ? lastItemX + item.w : 0;
item.y = lastItemX + item.w * (1.0 / this.defaultDisplayZoom) <= this.cols ? lastItemY : lastItemY + item.h;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For better visibility, please consider to remove ternary operator with complicated/duplicated condition.

Or, what about the code looks like below?

maxBottom= ...
if (this.displaysService.addVertically$.value) {
  stackVertical = true
} else {
  maxRight = ...
  stackVertical = maxRight + item.w * (1.0 / this.defaultDisplayZoom) <= this.col
}
if (stackVertical) {
  item.x = 0
  item.y = maxBottom + item.h
} else {
  item.x = maxRight + item.w
  item.y = maxBottom
}

}

item.placed = true;

Expand Down Expand Up @@ -294,6 +303,7 @@ export class ViewPaneComponent implements OnInit, OnDestroy, AfterViewInit {
}
layoutById.set(id, item);
});

return Array.from(layoutById, ([, value]) => value);
}, []), map(items => items.filter(item => item.visible)));

Expand Down
Loading