Browse Source

feat: the Home Devices card: the count of all devices and the Inactive and Active tiles from entity counts; the list from entity data subscriptions on the device state keys (attributes or time series, as the platform keeps them), inactive first with the most recently silent on top, then the devices that never connected, then the active, reversible and sortable by name; a device opens its details page and View all and Add device keep their filter and action. The Home cards share their tiles, table, empty state and Add button styles. A dynamic entity data subscription now also sends the entity fields that changed (a renamed device) when its entities stay the same

pull/16848/head
Igor Kulikov 2 weeks ago
parent
commit
9618b5b1e3
  1. 4
      application/src/main/java/org/thingsboard/server/service/subscription/TbAbstractDataSubCtx.java
  2. 33
      application/src/main/java/org/thingsboard/server/service/subscription/TbEntityDataSubCtx.java
  3. 121
      ui-ngx/src/app/modules/home/pages/home-links/home/components/_home-table.scss
  4. 281
      ui-ngx/src/app/modules/home/pages/home-links/home/components/_home-tiles.scss
  5. 24
      ui-ngx/src/app/modules/home/pages/home-links/home/components/alarms-home.component.html
  6. 279
      ui-ngx/src/app/modules/home/pages/home-links/home/components/alarms-home.component.scss
  7. 18
      ui-ngx/src/app/modules/home/pages/home-links/home/components/dashboards-home.component.html
  8. 147
      ui-ngx/src/app/modules/home/pages/home-links/home/components/dashboards-home.component.scss
  9. 96
      ui-ngx/src/app/modules/home/pages/home-links/home/components/devices-home.component.html
  10. 118
      ui-ngx/src/app/modules/home/pages/home-links/home/components/devices-home.component.scss
  11. 344
      ui-ngx/src/app/modules/home/pages/home-links/home/components/devices-home.component.ts
  12. 8
      ui-ngx/src/app/modules/home/pages/home-links/home/components/home-list-footer.component.scss
  13. 24
      ui-ngx/src/assets/locale/locale.constant-en_US.json

4
application/src/main/java/org/thingsboard/server/service/subscription/TbAbstractDataSubCtx.java

@ -66,6 +66,9 @@ public abstract class TbAbstractDataSubCtx<T extends AbstractDataQuery<? extends
return query != null && query.getPageLink().isDynamic();
}
protected void onSameEntities(Map<EntityId, EntityData> newDataMap) {
}
@Override
protected synchronized void update() {
PageData<EntityData> newData = findEntityData();
@ -78,6 +81,7 @@ public abstract class TbAbstractDataSubCtx<T extends AbstractDataQuery<? extends
Map<EntityId, EntityData> newDataMap = newData.getData().stream().collect(Collectors.toMap(EntityData::getEntityId, Function.identity(), (a, b) -> a));
if (oldDataMap.size() == newDataMap.size() && oldDataMap.keySet().equals(newDataMap.keySet())) {
log.trace("[{}][{}] No updates to entity data found", sessionRef.getSessionId(), cmdId);
onSameEntities(newDataMap);
} else {
this.data = newData;
doUpdate(newDataMap);

33
application/src/main/java/org/thingsboard/server/service/subscription/TbEntityDataSubCtx.java

@ -3,6 +3,7 @@
// SPDX-License-Identifier: Apache-2.0 AND BUSL-1.1
package org.thingsboard.server.service.subscription;
import java.util.Objects;
import lombok.Getter;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
@ -177,6 +178,38 @@ public class TbEntityDataSubCtx extends TbAbstractDataSubCtx<EntityDataQuery> {
});
}
@Override
protected void onSameEntities(Map<EntityId, EntityData> newDataMap) {
List<EntityData> changed = new ArrayList<>();
for (EntityData current : data.getData()) {
EntityData fresh = newDataMap.get(current.getEntityId());
Map<String, TsValue> freshFields = fresh != null && fresh.getLatest() != null ? fresh.getLatest().get(EntityKeyType.ENTITY_FIELD) : null;
if (freshFields == null || freshFields.isEmpty() || current.getLatest() == null) {
continue;
}
if (!sameFieldValues(current.getLatest().get(EntityKeyType.ENTITY_FIELD), freshFields)) {
current.getLatest().put(EntityKeyType.ENTITY_FIELD, freshFields);
changed.add(new EntityData(current.getEntityId(), false, false, Map.of(EntityKeyType.ENTITY_FIELD, freshFields), null));
}
}
if (!changed.isEmpty()) {
sendWsMsg(new EntityDataUpdate(cmdId, null, changed, maxEntitiesPerDataSubscription));
}
}
private static boolean sameFieldValues(Map<String, TsValue> current, Map<String, TsValue> fresh) {
if (current == null || current.size() != fresh.size()) {
return false;
}
for (Map.Entry<String, TsValue> entry : fresh.entrySet()) {
TsValue value = current.get(entry.getKey());
if (value == null || !Objects.equals(value.getValue(), entry.getValue().getValue())) {
return false;
}
}
return true;
}
@Override
public synchronized void doUpdate(Map<EntityId, EntityData> newDataMap) {
this.updateLatestTsData(this.data);

121
ui-ngx/src/app/modules/home/pages/home-links/home/components/_home-table.scss

@ -0,0 +1,121 @@
// SPDX-FileCopyrightText: Copyright ThingsBoard, Inc.
// SPDX-License-Identifier: BUSL-1.1
.tb-home-table {
width: 100%;
border-collapse: collapse;
th {
height: 32px;
padding: 0 12px 0 0;
border-bottom: 1px solid var(--tb-line, rgba(0, 0, 0, 0.12));
font: 400 12px/16px var(--tb-font, Roboto, sans-serif);
letter-spacing: 0.25px;
text-align: left;
white-space: nowrap;
color: var(--tb-text-muted, rgba(0, 0, 0, 0.56));
}
.th-label {
display: inline-flex;
align-items: center;
gap: 4px;
margin: 0;
padding: 0;
border: 0;
background: none;
font: inherit;
letter-spacing: inherit;
color: inherit;
cursor: pointer;
user-select: none;
&:hover {
color: var(--tb-text-secondary, rgba(0, 0, 0, 0.6));
.tb-sort-icon {
opacity: .6;
}
}
&:focus-visible {
outline: 2px solid var(--tb-primary-500);
outline-offset: 2px;
border-radius: 2px;
}
}
.tb-sort-icon {
width: 16px;
height: 16px;
font-size: 16px;
opacity: 0;
color: var(--tb-text-secondary, rgba(0, 0, 0, 0.6));
transition: opacity .15s ease;
}
th.sorted .tb-sort-icon {
opacity: 1;
}
td {
height: 36px;
padding: 0 12px 0 0;
border-bottom: 1px solid rgba(0, 0, 0, 0.06);
font: 400 14px/20px var(--tb-font, Roboto, sans-serif);
letter-spacing: 0.2px;
vertical-align: middle;
white-space: nowrap;
font-variant-numeric: tabular-nums;
color: var(--tb-ink, rgba(0, 0, 0, 0.87));
}
tbody tr {
cursor: pointer;
&:last-child td {
border-bottom: none;
}
&:hover td {
background: rgba(0, 0, 0, 0.02);
}
}
.col-time {
text-align: right;
}
td.col-time {
color: var(--tb-text-secondary, rgba(0, 0, 0, 0.6));
}
th.col-time .th-label {
flex-direction: row-reverse;
}
}
.tb-home-cell-link {
min-width: 0;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
color: var(--tb-ink, rgba(0, 0, 0, 0.87));
text-decoration: none;
&, &:hover, &:focus, &:active {
border-bottom: none;
}
&:hover {
text-decoration: underline;
}
}
.tb-home-sr-only {
position: absolute;
width: 1px;
height: 1px;
overflow: hidden;
clip: rect(0 0 0 0);
white-space: nowrap;
}

281
ui-ngx/src/app/modules/home/pages/home-links/home/components/_home-tiles.scss

@ -0,0 +1,281 @@
// SPDX-FileCopyrightText: Copyright ThingsBoard, Inc.
// SPDX-License-Identifier: BUSL-1.1
.tb-home-tiles {
display: flex;
flex-wrap: wrap;
gap: 8px;
}
.tb-home-tile {
--tb-sel: var(--tb-ink-76, rgba(0, 0, 0, 0.76));
position: relative;
display: flex;
flex: 0 0 auto;
flex-direction: column;
justify-content: space-evenly;
box-sizing: border-box;
width: 104px;
min-width: 0;
margin: 0;
padding: 5px 10px;
border: 1px solid rgba(0, 0, 0, 0.10);
border-radius: var(--tb-tile-radius, 10px);
background: #fff;
text-align: left;
color: inherit;
cursor: pointer;
transition: border-color .15s ease, background-color .15s ease;
&:hover {
border-color: rgba(0, 0, 0, 0.22);
}
&:focus-visible {
outline: 2px solid var(--tb-primary-500);
outline-offset: 2px;
}
&[aria-pressed="true"], &[aria-pressed="true"]:hover {
padding-left: 8px;
border-color: transparent;
border-left: 3px solid var(--tb-sel);
border-radius: 0 var(--tb-tile-radius, 10px) var(--tb-tile-radius, 10px) 0;
background: color-mix(in srgb, var(--tb-sel) 6%, #fff);
.tb-home-tile-label {
color: var(--tb-ink, rgba(0, 0, 0, 0.87));
}
}
&.can-reset {
.tb-home-tile-label {
padding-right: 16px;
}
&::after {
content: 'close';
position: absolute;
top: 4px;
right: 4px;
width: 20px;
height: 20px;
border-radius: 50%;
font-family: 'Material Icons';
font-size: 16px;
line-height: 20px;
text-align: center;
font-feature-settings: 'liga';
color: var(--tb-ink-54, rgba(0, 0, 0, 0.54));
}
&:hover::after {
background: #fff;
color: var(--tb-ink, rgba(0, 0, 0, 0.87));
}
}
&.zero {
.tb-home-tile-count {
color: var(--tb-ink-38, rgba(0, 0, 0, 0.38));
}
&:disabled {
cursor: default;
&:hover {
border-color: rgba(0, 0, 0, 0.10);
}
}
}
}
.tb-home-tile-label {
overflow: hidden;
font: 400 14px/20px var(--tb-font, Roboto, sans-serif);
letter-spacing: 0.1px;
white-space: nowrap;
text-overflow: ellipsis;
color: var(--tb-ink-76, rgba(0, 0, 0, 0.76));
}
.tb-home-tile-count {
display: flex;
align-items: center;
gap: 6px;
font: 500 20px/28px var(--tb-font, Roboto, sans-serif);
white-space: nowrap;
font-variant-numeric: tabular-nums;
color: var(--tb-ink, rgba(0, 0, 0, 0.87));
}
.tb-home-all-clear {
display: flex;
align-items: center;
gap: 12px;
padding: 2px 0;
font: 400 14px/20px var(--tb-font, Roboto, sans-serif);
letter-spacing: 0.2px;
color: var(--tb-text-secondary, rgba(0, 0, 0, 0.6));
}
.tb-home-all-clear-glyph {
display: inline-flex;
flex: none;
align-items: center;
justify-content: center;
width: 36px;
height: 36px;
border-radius: 50%;
background: var(--tb-ok-tint, rgba(25, 128, 56, 0.08));
color: var(--tb-ok, #198038);
.mat-icon {
width: 20px;
height: 20px;
font-size: 20px;
color: inherit;
}
}
.tb-home-empty-note {
padding: 4px 0;
font: 400 14px/20px var(--tb-font, Roboto, sans-serif);
letter-spacing: 0.2px;
color: var(--tb-text-secondary, rgba(0, 0, 0, 0.6));
}
@container (max-width: 459px) {
.tb-home-tile {
flex: 1 1 88px;
width: auto;
max-width: 140px;
padding-left: 8px;
padding-right: 8px;
}
.tb-home-tile-label {
letter-spacing: 0;
}
}
.tb-home-setup-empty {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
gap: 8px;
padding: 8px 16px 12px;
text-align: center;
}
.tb-home-setup-empty-glyph {
display: inline-flex;
flex: none;
align-items: center;
justify-content: center;
width: 44px;
height: 44px;
border-radius: 50%;
background: color-mix(in srgb, var(--tb-primary-500) 10%, transparent);
color: var(--tb-primary-500);
.mat-icon {
width: 20px;
height: 20px;
font-size: 20px;
color: inherit;
}
}
.tb-home-setup-empty-text {
display: flex;
flex-direction: column;
gap: 4px;
min-width: 0;
p {
max-width: 36em;
margin: 0;
font: 400 14px/20px var(--tb-font, Roboto, sans-serif);
letter-spacing: 0.2px;
color: var(--tb-text-secondary, rgba(0, 0, 0, 0.6));
}
}
.tb-home-setup-empty-title {
font: 500 14px/20px var(--tb-font, Roboto, sans-serif);
letter-spacing: 0.25px;
color: var(--tb-text-secondary, rgba(0, 0, 0, 0.6));
}
.tb-home-setup-empty-actions {
display: flex;
flex-wrap: wrap;
align-items: center;
justify-content: center;
gap: 4px 16px;
font: 400 14px/20px var(--tb-font, Roboto, sans-serif);
a {
border-radius: 4px;
text-decoration: underline;
text-decoration-thickness: 1px;
text-underline-offset: 3px;
text-decoration-color: transparent;
color: var(--tb-primary-500);
transition: text-decoration-color .15s ease;
&, &:hover, &:focus, &:active {
border-bottom: none;
}
&:hover {
text-decoration-color: currentColor;
}
&:focus-visible {
outline: 2px solid var(--tb-primary-500);
outline-offset: 2px;
}
}
}
.tb-home-ext {
width: 14px;
height: 14px;
margin-left: 2px;
font-size: 14px;
line-height: 14px;
vertical-align: -2px;
opacity: .7;
}
.tb-home-add.mat-mdc-button {
&, &:hover, &:focus, &:active {
border-bottom: none;
}
.mat-icon {
margin-right: 6px;
}
}
@container (max-width: 459px) {
.tb-home-add.mat-mdc-button {
min-width: 40px;
padding: 0 8px;
.mat-icon {
margin: 0;
}
.tb-home-add-label {
position: absolute;
width: 1px;
height: 1px;
overflow: hidden;
clip: rect(0 0 0 0);
white-space: nowrap;
}
}
}

24
ui-ngx/src/app/modules/home/pages/home-links/home/components/alarms-home.component.html

@ -10,28 +10,28 @@
<tb-home-toggle [options]="whoseOptions" [value]="mine()" [label]="'home.alarms.whose' | translate" (valueChange)="setMine($event)"></tb-home-toggle>
}
@if (tenantAdmin) {
<button mat-button color="primary" type="button" class="tb-alarms-add" (click)="addAlarmRule()">
<button mat-button color="primary" type="button" class="tb-home-add" (click)="addAlarmRule()">
<mat-icon>add</mat-icon>
<span class="tb-alarms-add-label">{{ 'home.alarms.add-rule' | translate }}</span>
<span class="tb-home-add-label">{{ 'home.alarms.add-rule' | translate }}</span>
</button>
}
</ng-container>
@if (total() === 0) {
<div class="tb-alarms-clear">
<span class="tb-alarms-clear-glyph" aria-hidden="true"><mat-icon>check</mat-icon></span>
<div class="tb-home-all-clear">
<span class="tb-home-all-clear-glyph" aria-hidden="true"><mat-icon>check</mat-icon></span>
<span>{{ 'home.alarms.no-active' | translate }} <a class="tb-alarms-clear-link" routerLink="/alarms/alarms" [queryParams]="{statusList: ['CLEARED']}">{{ 'home.alarms.view-cleared' | translate }}</a></span>
</div>
} @else if (total()) {
<div class="tb-alarms-tiles">
<div class="tb-home-tiles">
@for (tile of tiles(); track tile.severity) {
<button type="button" class="tb-alarms-tile" [class]="tile.severity.toLowerCase()" [class.zero]="!tile.count"
<button type="button" class="tb-home-tile" [class]="tile.severity.toLowerCase()" [class.zero]="!tile.count"
[class.can-reset]="tile.pressed" [disabled]="!tile.count && !tile.pressed"
[attr.aria-pressed]="tile.count || tile.pressed ? tile.pressed : null"
[matTooltip]="(tile.pressed ? 'home.alarms.show-every' : 'home.alarms.show-only') | translate: {severity: (severityLabel(tile.severity) | translate)}"
[matTooltipDisabled]="!tile.count && !tile.pressed" matTooltipPosition="above"
(click)="pick(tile)">
<span class="tb-alarms-tile-label">{{ severityLabel(tile.severity) | translate }}</span>
<span class="tb-alarms-tile-count">
<span class="tb-home-tile-label">{{ severityLabel(tile.severity) | translate }}</span>
<span class="tb-home-tile-count">
{{ tile.count | shortNumber }}
@if (tile.hot) {
<tb-ai-sev-mark class="tb-alarms-tile-mark" severity="CRITICAL"></tb-ai-sev-mark>
@ -41,7 +41,7 @@
}
</div>
@if (rows().length) {
<table class="tb-alarms-table" [class.mine]="mine()">
<table class="tb-home-table tb-alarms-table" [class.mine]="mine()">
<thead>
<tr>
<th class="col-severity sortable" [class.sorted]="sortKey() === 'severity'" [attr.aria-sort]="ariaSort('severity')">
@ -52,7 +52,7 @@
</th>
<th class="col-type">{{ 'home.alarms.type' | translate }}</th>
<th class="col-origin">{{ 'home.alarms.originator' | translate }}</th>
<th class="col-age sortable" [class.sorted]="sortKey() === 'createdTime'" [attr.aria-sort]="ariaSort('createdTime')">
<th class="col-age col-time sortable" [class.sorted]="sortKey() === 'createdTime'" [attr.aria-sort]="ariaSort('createdTime')">
<button type="button" class="th-label" [matTooltip]="'home.alarms.sort-started' | translate" (click)="sortBy('createdTime')">
<span class="th-text">{{ 'home.alarms.started' | translate }}</span>
<mat-icon class="tb-sort-icon">{{ sortKey() === 'createdTime' && !sortDesc() ? 'arrow_upward' : 'arrow_downward' }}</mat-icon>
@ -86,7 +86,7 @@
<td class="col-origin">
<a class="tb-alarms-link tb-alarms-origin" [routerLink]="row.originatorLink" (click)="stop($event)">{{ row.alarm.originatorDisplayName || row.alarm.originatorName }}</a>
</td>
<td class="col-age" [matTooltip]="'home.alarms.started-at' | translate: {time: (row.alarm.createdTime | date: 'd MMM, HH:mm')}">{{ row.ago }}</td>
<td class="col-age col-time" [matTooltip]="'home.alarms.started-at' | translate: {time: (row.alarm.createdTime | date: 'd MMM, HH:mm')}">{{ row.ago }}</td>
@if (!mine()) {
<td class="col-assignee">
@if (row.assigneeName) {
@ -127,7 +127,7 @@
</tbody>
</table>
} @else if (alarmsLoaded()) {
<div class="tb-alarms-empty-note">{{ emptyNote().key | translate: emptyNote().params }}</div>
<div class="tb-home-empty-note">{{ emptyNote().key | translate: emptyNote().params }}</div>
}
<tb-home-list-footer [total]="listed()" [expanded]="expanded()" link="/alarms/alarms" [params]="viewAllParams()"
(expandedChange)="expanded.set($event)"></tb-home-list-footer>

279
ui-ngx/src/app/modules/home/pages/home-links/home/components/alarms-home.component.scss

@ -1,46 +1,14 @@
// SPDX-FileCopyrightText: Copyright ThingsBoard, Inc.
// SPDX-License-Identifier: BUSL-1.1
@use './home-tiles';
@use './home-table';
:host {
display: block;
min-width: 0;
container: tb-alarms-home / inline-size;
}
.tb-alarms-add.mat-mdc-button {
.mat-icon {
margin-right: 6px;
}
}
.tb-alarms-clear {
display: flex;
align-items: center;
gap: 12px;
padding: 2px 0;
font: 400 14px/20px var(--tb-font, Roboto, sans-serif);
letter-spacing: 0.2px;
color: var(--tb-text-secondary, rgba(0, 0, 0, 0.6));
}
.tb-alarms-clear-glyph {
display: inline-flex;
flex: none;
align-items: center;
justify-content: center;
width: 36px;
height: 36px;
border-radius: 50%;
background: var(--tb-ok-tint, rgba(25, 128, 56, 0.08));
color: var(--tb-ok, #198038);
.mat-icon {
width: 20px;
height: 20px;
font-size: 20px;
color: inherit;
}
}
.tb-alarms-clear-link, .tb-alarms-link {
&, &:hover, &:focus, &:active {
border-bottom: none;
@ -52,117 +20,11 @@
color: var(--tb-primary-500);
}
.tb-alarms-tiles {
display: flex;
flex-wrap: wrap;
gap: 8px;
}
.tb-alarms-tile {
--tb-sel: var(--tb-ink-76, rgba(0, 0, 0, 0.76));
position: relative;
display: flex;
flex: 0 0 auto;
flex-direction: column;
justify-content: space-evenly;
box-sizing: border-box;
width: 104px;
min-width: 0;
margin: 0;
padding: 5px 10px;
border: 1px solid rgba(0, 0, 0, 0.10);
border-radius: var(--tb-tile-radius, 10px);
background: #fff;
text-align: left;
color: inherit;
cursor: pointer;
transition: border-color .15s ease, background-color .15s ease;
.tb-home-tile {
&.critical { --tb-sel: var(--tb-sev-critical, #D12730); }
&.major { --tb-sel: var(--tb-sev-major, #F35E09); }
&.minor { --tb-sel: var(--tb-sev-minor, #B47604); }
&.warning { --tb-sel: var(--tb-sev-warning, #B47604); }
&:hover {
border-color: rgba(0, 0, 0, 0.22);
}
&:focus-visible {
outline: 2px solid var(--tb-primary-500);
outline-offset: 2px;
}
&[aria-pressed="true"], &[aria-pressed="true"]:hover {
padding-left: 8px;
border-color: transparent;
border-left: 3px solid var(--tb-sel);
border-radius: 0 var(--tb-tile-radius, 10px) var(--tb-tile-radius, 10px) 0;
background: color-mix(in srgb, var(--tb-sel) 6%, #fff);
.tb-alarms-tile-label {
color: var(--tb-ink, rgba(0, 0, 0, 0.87));
}
}
&.can-reset {
.tb-alarms-tile-label {
padding-right: 16px;
}
&::after {
content: 'close';
position: absolute;
top: 4px;
right: 4px;
width: 20px;
height: 20px;
border-radius: 50%;
font-family: 'Material Icons';
font-size: 16px;
line-height: 20px;
text-align: center;
font-feature-settings: 'liga';
color: var(--tb-ink-54, rgba(0, 0, 0, 0.54));
}
&:hover::after {
background: #fff;
color: var(--tb-ink, rgba(0, 0, 0, 0.87));
}
}
&.zero {
.tb-alarms-tile-count {
color: var(--tb-ink-38, rgba(0, 0, 0, 0.38));
}
&:disabled {
cursor: default;
&:hover {
border-color: rgba(0, 0, 0, 0.10);
}
}
}
}
.tb-alarms-tile-label {
overflow: hidden;
font: 400 14px/20px var(--tb-font, Roboto, sans-serif);
letter-spacing: 0.1px;
white-space: nowrap;
text-overflow: ellipsis;
color: var(--tb-ink-76, rgba(0, 0, 0, 0.76));
}
.tb-alarms-tile-count {
display: flex;
align-items: center;
gap: 6px;
font: 500 20px/28px var(--tb-font, Roboto, sans-serif);
white-space: nowrap;
font-variant-numeric: tabular-nums;
color: var(--tb-ink, rgba(0, 0, 0, 0.87));
}
.tb-alarms-tile-mark ::ng-deep svg {
@ -171,88 +33,8 @@
}
.tb-alarms-table {
width: 100%;
border-collapse: collapse;
th {
height: 32px;
padding: 0 12px 0 0;
border-bottom: 1px solid var(--tb-line, rgba(0, 0, 0, 0.12));
font: 400 12px/16px var(--tb-font, Roboto, sans-serif);
letter-spacing: 0.25px;
text-align: left;
white-space: nowrap;
color: var(--tb-text-muted, rgba(0, 0, 0, 0.56));
}
.th-label {
display: inline-flex;
align-items: center;
gap: 4px;
margin: 0;
padding: 0;
border: 0;
background: none;
font: inherit;
letter-spacing: inherit;
color: inherit;
cursor: pointer;
user-select: none;
&:hover {
color: var(--tb-text-secondary, rgba(0, 0, 0, 0.6));
.tb-sort-icon {
opacity: .6;
}
}
&:focus-visible {
outline: 2px solid var(--tb-primary-500);
outline-offset: 2px;
border-radius: 2px;
}
}
.tb-sort-icon {
width: 16px;
height: 16px;
font-size: 16px;
opacity: 0;
color: var(--tb-text-secondary, rgba(0, 0, 0, 0.6));
transition: opacity .15s ease;
}
th.sorted .tb-sort-icon {
opacity: 1;
}
td {
height: 36px;
padding: 0 12px 0 0;
border-bottom: 1px solid rgba(0, 0, 0, 0.06);
font: 400 14px/20px var(--tb-font, Roboto, sans-serif);
letter-spacing: 0.2px;
vertical-align: middle;
white-space: nowrap;
font-variant-numeric: tabular-nums;
color: var(--tb-ink, rgba(0, 0, 0, 0.87));
}
tbody tr {
cursor: pointer;
&:last-child td {
border-bottom: none;
}
&:hover td {
background: rgba(0, 0, 0, 0.02);
}
&:is(:hover, :focus-within) .tb-alarms-assign {
visibility: visible;
}
tbody tr:is(:hover, :focus-within) .tb-alarms-assign {
visibility: visible;
}
td.col-type .tb-alarms-cell-main {
@ -270,18 +52,6 @@
color: var(--tb-text-secondary, rgba(0, 0, 0, 0.6));
}
td.col-age {
color: var(--tb-text-secondary, rgba(0, 0, 0, 0.6));
}
.col-age {
text-align: right;
}
th.col-age .th-label {
flex-direction: row-reverse;
}
.col-assignee, .col-ack {
width: 1%;
padding-left: 8px;
@ -428,13 +198,6 @@
color: var(--tb-ink-54, rgba(0, 0, 0, 0.54));
}
.tb-alarms-empty-note {
padding: 4px 0;
font: 400 14px/20px var(--tb-font, Roboto, sans-serif);
letter-spacing: 0.2px;
color: var(--tb-text-secondary, rgba(0, 0, 0, 0.6));
}
@container tb-alarms-home (max-width: 599px) {
.tb-alarms-table {
.col-origin {
@ -512,34 +275,4 @@
.tb-alarms-sub-age {
display: inline;
}
.tb-alarms-tile {
flex: 1 1 88px;
width: auto;
max-width: 140px;
padding-left: 8px;
padding-right: 8px;
}
.tb-alarms-tile-label {
letter-spacing: 0;
}
.tb-alarms-add.mat-mdc-button {
min-width: 40px;
padding: 0 8px;
.mat-icon {
margin: 0;
}
}
.tb-alarms-add-label {
position: absolute;
width: 1px;
height: 1px;
overflow: hidden;
clip: rect(0 0 0 0);
white-space: nowrap;
}
}

18
ui-ngx/src/app/modules/home/pages/home-links/home/components/dashboards-home.component.html

@ -10,26 +10,26 @@
<tb-home-toggle [options]="tabOptions" [value]="tab()" [label]="'home.dashboards.view' | translate" (valueChange)="setTab($event)"></tb-home-toggle>
}
@if (canAdd) {
<a mat-button color="primary" class="tb-dashboards-add" routerLink="/dashboards/all" [queryParams]="{action: 'add'}">
<a mat-button color="primary" class="tb-home-add" routerLink="/dashboards/all" [queryParams]="{action: 'add'}">
<mat-icon>add</mat-icon>
<span class="tb-dashboards-add-label">{{ 'home.dashboards.add' | translate }}</span>
<span class="tb-home-add-label">{{ 'home.dashboards.add' | translate }}</span>
</a>
}
</ng-container>
@if (loaded()) {
@if (!total()) {
<div class="tb-dashboards-empty">
<span class="tb-dashboards-empty-glyph" aria-hidden="true"><mat-icon>{{ tenantAdmin ? 'dashboard_customize' : 'dashboard' }}</mat-icon></span>
<div class="tb-home-setup-empty">
<span class="tb-home-setup-empty-glyph" aria-hidden="true"><mat-icon>{{ tenantAdmin ? 'dashboard_customize' : 'dashboard' }}</mat-icon></span>
@if (tenantAdmin) {
<div class="tb-dashboards-empty-text">
<div class="tb-home-setup-empty-text">
<p>{{ 'home.dashboards.none' | translate }}</p>
<div class="tb-dashboards-empty-actions">
<div class="tb-home-setup-empty-actions">
<a routerLink="/iot-hub/solution-templates">{{ 'home.dashboards.from-template' | translate }}</a>
<a [href]="howToLink" target="_blank" rel="noopener">{{ 'home.dashboards.how-to' | translate }}<mat-icon class="tb-dashboards-ext" aria-hidden="true">north_east</mat-icon><span class="tb-dashboards-sr">{{ 'home.dashboards.opens-new-tab' | translate }}</span></a>
<a [href]="howToLink" target="_blank" rel="noopener">{{ 'home.dashboards.how-to' | translate }}<mat-icon class="tb-home-ext" aria-hidden="true">north_east</mat-icon><span class="tb-home-sr-only">{{ 'home.dashboards.opens-new-tab' | translate }}</span></a>
</div>
</div>
} @else {
<div class="tb-dashboards-empty-title">{{ 'home.dashboards.none-assigned' | translate }}</div>
<div class="tb-home-setup-empty-title">{{ 'home.dashboards.none-assigned' | translate }}</div>
}
</div>
} @else {
@ -60,7 +60,7 @@
</tbody>
</table>
} @else {
<div class="tb-dashboards-empty-note">{{ (tab() === 'last' ? 'home.dashboards.none-viewed' : 'home.dashboards.none-starred') | translate }}</div>
<div class="tb-home-empty-note">{{ (tab() === 'last' ? 'home.dashboards.none-viewed' : 'home.dashboards.none-starred') | translate }}</div>
}
@if (tab() === 'starred') {
<div class="tb-dashboards-picker">

147
ui-ngx/src/app/modules/home/pages/home-links/home/components/dashboards-home.component.scss

@ -1,21 +1,14 @@
// SPDX-FileCopyrightText: Copyright ThingsBoard, Inc.
// SPDX-License-Identifier: BUSL-1.1
@use './home-tiles';
@use './home-table';
:host {
display: block;
min-width: 0;
container: tb-dashboards-home / inline-size;
}
.tb-dashboards-add.mat-mdc-button {
&, &:hover, &:focus, &:active {
border-bottom: none;
}
.mat-icon {
margin-right: 6px;
}
}
.tb-dashboards-table {
width: 100%;
border-collapse: collapse;
@ -65,13 +58,13 @@
white-space: nowrap;
a {
color: var(--tb-ink, rgba(0, 0, 0, 0.87));
text-decoration: none;
&, &:hover, &:focus, &:active {
border-bottom: none;
}
color: var(--tb-ink, rgba(0, 0, 0, 0.87));
text-decoration: none;
&:hover {
text-decoration: underline;
}
@ -127,13 +120,6 @@
}
}
.tb-dashboards-empty-note {
padding: 4px 0;
font: 400 14px/20px var(--tb-font, Roboto, sans-serif);
letter-spacing: 0.2px;
color: var(--tb-text-secondary, rgba(0, 0, 0, 0.6));
}
.tb-dashboards-picker {
position: relative;
}
@ -316,124 +302,3 @@
font-size: 13px;
color: var(--tb-text-secondary, rgba(0, 0, 0, 0.6));
}
.tb-dashboards-empty {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
gap: 8px;
padding: 8px 16px 12px;
text-align: center;
}
.tb-dashboards-empty-glyph {
display: inline-flex;
flex: none;
align-items: center;
justify-content: center;
width: 44px;
height: 44px;
border-radius: 50%;
background: color-mix(in srgb, var(--tb-primary-500) 10%, transparent);
color: var(--tb-primary-500);
.mat-icon {
width: 20px;
height: 20px;
font-size: 20px;
color: inherit;
}
}
.tb-dashboards-empty-text {
display: flex;
flex-direction: column;
gap: 4px;
min-width: 0;
p {
max-width: 36em;
margin: 0;
font: 400 14px/20px var(--tb-font, Roboto, sans-serif);
letter-spacing: 0.2px;
color: var(--tb-text-secondary, rgba(0, 0, 0, 0.6));
}
}
.tb-dashboards-empty-title {
font: 500 14px/20px var(--tb-font, Roboto, sans-serif);
letter-spacing: 0.25px;
color: var(--tb-text-secondary, rgba(0, 0, 0, 0.6));
}
.tb-dashboards-empty-actions {
display: flex;
flex-wrap: wrap;
align-items: center;
justify-content: center;
gap: 4px 16px;
font: 400 14px/20px var(--tb-font, Roboto, sans-serif);
a {
&, &:hover, &:focus, &:active {
border-bottom: none;
}
border-radius: 4px;
text-decoration: underline;
text-decoration-thickness: 1px;
text-underline-offset: 3px;
text-decoration-color: transparent;
color: var(--tb-primary-500);
transition: text-decoration-color .15s ease;
&:hover {
text-decoration-color: currentColor;
}
&:focus-visible {
outline: 2px solid var(--tb-primary-500);
outline-offset: 2px;
}
}
}
.tb-dashboards-ext {
width: 14px;
height: 14px;
margin-left: 2px;
font-size: 14px;
line-height: 14px;
vertical-align: -2px;
opacity: .7;
}
.tb-dashboards-sr {
position: absolute;
width: 1px;
height: 1px;
overflow: hidden;
clip: rect(0 0 0 0);
white-space: nowrap;
}
@container tb-dashboards-home (max-width: 459px) {
.tb-dashboards-add.mat-mdc-button {
min-width: 40px;
padding: 0 8px;
.mat-icon {
margin: 0;
}
}
.tb-dashboards-add-label {
position: absolute;
width: 1px;
height: 1px;
overflow: hidden;
clip: rect(0 0 0 0);
white-space: nowrap;
}
}

96
ui-ngx/src/app/modules/home/pages/home-links/home/components/devices-home.component.html

@ -0,0 +1,96 @@
<!--
SPDX-FileCopyrightText: Copyright ThingsBoard, Inc.
SPDX-License-Identifier: BUSL-1.1
-->
<tb-home-card [card]="card" [count]="total()">
<ng-container homeCardActions>
@if (canAdd) {
<a mat-button color="primary" class="tb-home-add" routerLink="/entities/devices/all" [queryParams]="{action: 'add'}">
<mat-icon>add</mat-icon>
<span class="tb-home-add-label">{{ 'home.devices.add' | translate }}</span>
</a>
}
</ng-container>
@if (total() === 0) {
<div class="tb-home-setup-empty">
<span class="tb-home-setup-empty-glyph" aria-hidden="true"><mat-icon>memory</mat-icon></span>
@if (tenantAdmin) {
<div class="tb-home-setup-empty-text">
<p>{{ 'home.devices.none' | translate }}</p>
<div class="tb-home-setup-empty-actions">
<a [href]="howToLink" target="_blank" rel="noopener">{{ 'home.devices.how-to' | translate }}<mat-icon class="tb-home-ext" aria-hidden="true">north_east</mat-icon><span class="tb-home-sr-only">{{ 'home.dashboards.opens-new-tab' | translate }}</span></a>
</div>
</div>
} @else {
<div class="tb-home-setup-empty-title">{{ 'home.devices.none-assigned' | translate }}</div>
}
</div>
} @else if (total()) {
<div class="tb-home-tiles">
@for (tile of tiles(); track tile.state) {
<button type="button" class="tb-home-tile" [class]="tile.state" [class.zero]="!tile.count" [class.can-reset]="tile.pressed"
[disabled]="!tile.count && !tile.pressed" [attr.aria-pressed]="tile.count || tile.pressed ? tile.pressed : null"
[matTooltip]="(tile.pressed ? 'home.devices.show-every' : 'home.devices.show-only-' + tile.state) | translate"
[matTooltipDisabled]="!tile.count && !tile.pressed" matTooltipPosition="above" (click)="pick(tile)">
<span class="tb-home-tile-label">{{ 'home.devices.' + tile.state | translate }}</span>
<span class="tb-home-tile-count">{{ tile.count | shortNumber }}</span>
</button>
}
</div>
@if (allActive()) {
<div class="tb-home-all-clear">
<span class="tb-home-all-clear-glyph" aria-hidden="true"><mat-icon>check</mat-icon></span>
<span>{{ (total() === 1 ? 'home.devices.one-active' : 'home.devices.all-active') | translate: {count: total()} }}</span>
</div>
}
@if (rows().length) {
<table class="tb-home-table tb-devices-table">
<thead>
<tr>
<th class="col-name sortable" [class.sorted]="sortKey() === 'name'" [attr.aria-sort]="ariaSort('name')">
<button type="button" class="th-label" [matTooltip]="'home.devices.sort-name' | translate" (click)="sortBy('name')">
<span>{{ 'home.devices.name' | translate }}</span>
<mat-icon class="tb-sort-icon">{{ sortIcon('name') }}</mat-icon>
</button>
</th>
<th class="col-profile">{{ 'home.devices.profile' | translate }}</th>
<th class="col-state"><span class="th-text">{{ 'home.devices.state' | translate }}</span></th>
<th class="col-time sortable" [class.sorted]="sortKey() === 'last'" [attr.aria-sort]="ariaSort('last')">
<button type="button" class="th-label" [matTooltip]="'home.devices.sort-last' | translate" (click)="sortBy('last')">
<span>{{ 'home.devices.last-activity' | translate }}</span>
<mat-icon class="tb-sort-icon">{{ sortIcon('last') }}</mat-icon>
</button>
</th>
</tr>
</thead>
<tbody>
@for (row of rows(); track row.id) {
<tr (click)="open(row)">
<td class="col-name">
<span class="tb-devices-cell-main"><a class="tb-home-cell-link" [routerLink]="row.url" (click)="$event.stopPropagation()">{{ row.name }}</a></span>
<span class="tb-devices-cell-sub">{{ row.profile }}</span>
</td>
<td class="col-profile">{{ row.profile }}</td>
<td class="col-state">
<span class="tb-devices-state" [class.active]="row.active" [class.inactive]="!row.active">
<span class="tb-devices-state-word">{{ (row.active ? 'home.devices.active' : 'home.devices.inactive') | translate }}</span>
</span>
</td>
@if (row.lastActivity) {
<td class="col-time" [matTooltip]="'home.devices.last-activity-at' | translate: {time: (row.lastActivity | date: 'd MMM, HH:mm')}">{{ row.ago }}</td>
} @else {
<td class="col-time"><span class="tb-devices-never" [matTooltip]="'home.devices.no-data' | translate">{{ 'home.devices.never' | translate }}</span></td>
}
</tr>
}
</tbody>
</table>
} @else if (loaded()) {
<div class="tb-home-empty-note">{{ ('home.devices.none-' + (filter() ?? 'active')) | translate }}</div>
}
<tb-home-list-footer [total]="listed()" [expanded]="expanded()" link="/entities/devices/all" [params]="viewAllParams()"
(expandedChange)="expanded.set($event)"></tb-home-list-footer>
}
</tb-home-card>

118
ui-ngx/src/app/modules/home/pages/home-links/home/components/devices-home.component.scss

@ -0,0 +1,118 @@
// SPDX-FileCopyrightText: Copyright ThingsBoard, Inc.
// SPDX-License-Identifier: BUSL-1.1
@use './home-tiles';
@use './home-table';
:host {
display: block;
min-width: 0;
container: tb-devices-home / inline-size;
}
.tb-home-tile {
&.inactive:not(.zero) {
--tb-sel: var(--tb-crit, #D12730);
}
&.active {
--tb-sel: var(--tb-ok, #198038);
}
}
.tb-devices-table {
.tb-devices-cell-main {
display: flex;
min-width: 0;
max-width: 220px;
overflow: hidden;
text-overflow: ellipsis;
}
td.col-profile {
max-width: 160px;
overflow: hidden;
text-overflow: ellipsis;
color: var(--tb-text-secondary, rgba(0, 0, 0, 0.6));
}
.col-state {
white-space: nowrap;
}
}
.tb-devices-cell-sub {
display: none;
overflow: hidden;
font-size: 12px;
line-height: 16px;
white-space: nowrap;
text-overflow: ellipsis;
color: var(--tb-text-secondary, rgba(0, 0, 0, 0.6));
}
.tb-devices-state {
display: inline-flex;
align-items: center;
gap: 6px;
font: 400 13px/20px var(--tb-font, Roboto, sans-serif);
color: var(--tb-ink-76, rgba(0, 0, 0, 0.76));
&::before {
content: '';
box-sizing: border-box;
width: 8px;
height: 8px;
border-radius: 50%;
background: var(--tb-ink-38, rgba(0, 0, 0, 0.38));
}
&.active::before {
background: var(--tb-ok, #198038);
}
&.inactive::before {
border: 2px solid var(--tb-crit, #D12730);
background: transparent;
}
}
.tb-devices-never {
color: var(--tb-text-muted, rgba(0, 0, 0, 0.56));
}
@container tb-devices-home (max-width: 599px) {
.tb-devices-state {
gap: 0;
}
.tb-devices-state-word, .tb-devices-table th.col-state .th-text {
position: absolute;
width: 1px;
height: 1px;
overflow: hidden;
clip: rect(0 0 0 0);
white-space: nowrap;
}
}
@container tb-devices-home (max-width: 459px) {
.tb-devices-table {
.col-profile {
display: none;
}
td.col-name {
width: 99%;
padding-top: 6px;
padding-bottom: 6px;
}
.tb-devices-cell-main {
max-width: none;
}
}
.tb-devices-cell-sub {
display: block;
}
}

344
ui-ngx/src/app/modules/home/pages/home-links/home/components/devices-home.component.ts

@ -1,16 +1,356 @@
// SPDX-FileCopyrightText: Copyright ThingsBoard, Inc.
// SPDX-License-Identifier: BUSL-1.1
import { ChangeDetectionStrategy, Component } from '@angular/core';
import {
ChangeDetectionStrategy,
Component,
computed,
DestroyRef,
effect,
inject,
NgZone,
signal,
untracked,
WritableSignal
} from '@angular/core';
import { Router } from '@angular/router';
import { Store } from '@ngrx/store';
import { TranslateService } from '@ngx-translate/core';
import { take } from 'rxjs/operators';
import { AppState } from '@core/core.state';
import { getCurrentAuthUser, selectPersistDeviceStateToTelemetry } from '@core/auth/auth.selectors';
import { TelemetryWebsocketService } from '@core/ws/telemetry-websocket.service';
import { UserPermissionsService } from '@core/http/user-permissions.service';
import { EntityCountCmd, EntityDataCmd, TelemetrySubscriber } from '@shared/models/telemetry/telemetry.models';
import { AliasFilterType } from '@shared/models/alias.models';
import { EntityType } from '@shared/models/entity-type.models';
import {
BooleanOperation,
EntityData,
EntityDataPageLink,
EntityKey,
EntityKeyType,
EntityKeyValueType,
FilterPredicateType,
KeyFilter,
NumericOperation
} from '@shared/models/query/query.models';
import { Direction } from '@shared/models/page/sort-order';
import { Authority } from '@shared/models/authority.enum';
import { Operation, Resource } from '@shared/models/security.models';
import { HelpLinks } from '@shared/models/constants';
import { HomeCardId } from '@shared/models/user-settings.models';
import { getEntityDetailsPageURL } from '@core/utils';
import { HOME_CARDS } from '@home/pages/home-links/home/home-cards.models';
import { homeAgo, homeListPageSize, homeListShown } from '@home/pages/home-links/home/home-list.models';
type DeviceState = 'inactive' | 'active';
type DeviceSortKey = 'last' | 'name';
const MINUTE = 60000;
interface DeviceQuery {
state: DeviceState | null;
sortKey: EntityKey;
direction: Direction;
withActivity?: boolean;
neverConnected?: boolean;
counted: boolean;
}
interface DeviceTile {
state: DeviceState;
count: number;
pressed: boolean;
}
export interface DeviceHomeRow {
id: string;
name: string;
profile: string;
active: boolean;
lastActivity: number | null;
ago: string;
url: string;
}
@Component({
selector: 'tb-devices-home',
template: `<tb-home-card [card]="card"></tb-home-card>`,
templateUrl: './devices-home.component.html',
styleUrls: ['./devices-home.component.scss'],
standalone: false,
changeDetection: ChangeDetectionStrategy.OnPush
})
export class DevicesHomeComponent {
readonly card = HOME_CARDS[HomeCardId.DEVICES];
readonly howToLink = HelpLinks.linksMap.devices;
private telemetryWsService = inject(TelemetryWebsocketService);
private zone = inject(NgZone);
private store = inject(Store<AppState>);
private router = inject(Router);
private translate = inject(TranslateService);
private userPermissions = inject(UserPermissionsService);
private readonly authUser = getCurrentAuthUser(this.store);
readonly tenantAdmin = this.authUser?.authority === Authority.TENANT_ADMIN;
readonly canAdd = this.tenantAdmin && this.userPermissions.hasGenericPermission(Resource.DEVICE, Operation.CREATE);
readonly filter = signal<DeviceState | null>(null);
readonly expanded = signal(false);
readonly sortKey = signal<DeviceSortKey>('last');
readonly sortDesc = signal(true);
readonly total = signal<number | null>(null);
readonly inactive = signal<number | null>(null);
readonly active = signal<number | null>(null);
private readonly stateKeyType = signal<EntityKeyType | null>(null);
private readonly lists = signal<(EntityData[] | null)[]>([]);
private readonly listTotals = signal<number[]>([]);
private readonly now = signal(Date.now());
private countSubscribers: TelemetrySubscriber[] = [];
private dataSubscribers: TelemetrySubscriber[] = [];
readonly tiles = computed<DeviceTile[]>(() => {
const filter = this.filter();
return [
{state: 'inactive', count: this.inactive() ?? 0, pressed: filter === 'inactive'},
{state: 'active', count: this.active() ?? 0, pressed: filter === 'active'}
];
});
readonly allActive = computed(() => !this.filter() && this.inactive() === 0 && !!this.total());
readonly loaded = computed(() => this.lists().length > 0 && this.lists().every(list => list !== null));
readonly listed = computed(() => this.listTotals().reduce((sum, count, index) =>
this.listQueries[index]?.counted ? sum + count : sum, 0));
private listQueries: DeviceQuery[] = [];
readonly rows = computed<DeviceHomeRow[]>(() => {
const keyType = this.stateKeyType();
const now = this.now();
const merged = this.lists().flatMap((list, index) => {
const rows = list ?? [];
return this.listQueries[index]?.neverConnected && keyType
? rows.filter(data => !Number(data.latest?.[keyType]?.lastActivityTime?.value))
: rows;
});
return merged.slice(0, homeListShown(this.listed(), this.expanded())).map(data => this.toRow(data, keyType, now));
});
readonly viewAllParams = computed(() => {
const filter = this.filter();
return filter ? {active: filter === 'active'} : null;
});
private readonly queries = computed<DeviceQuery[]>(() => {
const keyType = this.stateKeyType();
if (!keyType) {
return [];
}
const filter = this.filter();
const desc = this.sortDesc();
if (this.sortKey() === 'name') {
return [{state: filter, sortKey: {type: EntityKeyType.ENTITY_FIELD, key: 'name'}, direction: desc ? Direction.DESC : Direction.ASC, counted: true}];
}
const lastActivity: EntityKey = {type: keyType, key: 'lastActivityTime'};
const silent: DeviceQuery = {state: 'inactive', sortKey: lastActivity, direction: desc ? Direction.DESC : Direction.ASC,
withActivity: true, counted: false};
const never: DeviceQuery = {state: 'inactive', sortKey: lastActivity, direction: Direction.DESC, neverConnected: true, counted: true};
const active: DeviceQuery = {state: 'active', sortKey: lastActivity, direction: desc ? Direction.ASC : Direction.DESC, counted: true};
const inactive = desc ? [silent, never] : [never, silent];
if (filter === 'inactive') {
return inactive;
}
if (filter === 'active') {
return [active];
}
return desc ? [...inactive, active] : [active, ...inactive];
});
constructor() {
this.store.select(selectPersistDeviceStateToTelemetry).pipe(take(1)).subscribe(persisted => {
const keyType = persisted ? EntityKeyType.TIME_SERIES : EntityKeyType.SERVER_ATTRIBUTE;
this.countSubscribers = [
this.subscribeCount(this.total),
this.subscribeCount(this.inactive, this.activeFilter(keyType, false)),
this.subscribeCount(this.active, this.activeFilter(keyType, true))
];
this.stateKeyType.set(keyType);
});
effect(() => {
const queries = this.queries();
const pageSize = homeListPageSize(this.expanded());
untracked(() => this.subscribeLists(queries, pageSize));
});
const tick = setInterval(() => this.now.set(Date.now()), MINUTE);
inject(DestroyRef).onDestroy(() => {
clearInterval(tick);
this.countSubscribers.forEach(subscriber => subscriber.unsubscribe());
this.dataSubscribers.forEach(subscriber => subscriber.unsubscribe());
});
}
pick(tile: DeviceTile): void {
if (tile.count || tile.pressed) {
this.filter.set(tile.pressed ? null : tile.state);
}
}
sortBy(key: DeviceSortKey): void {
if (this.sortKey() === key) {
this.sortDesc.set(!this.sortDesc());
} else {
this.sortKey.set(key);
this.sortDesc.set(key === 'last');
}
}
ariaSort(key: DeviceSortKey): string {
if (this.sortKey() !== key) {
return 'none';
}
return this.sortDesc() ? 'descending' : 'ascending';
}
sortIcon(key: DeviceSortKey): string {
if (key === 'name') {
return this.sortKey() === 'name' && this.sortDesc() ? 'arrow_downward' : 'arrow_upward';
}
return this.sortKey() === 'last' && !this.sortDesc() ? 'arrow_upward' : 'arrow_downward';
}
open(row: DeviceHomeRow): void {
this.router.navigateByUrl(row.url);
}
private subscribeLists(queries: DeviceQuery[], pageSize: number): void {
this.dataSubscribers.forEach(subscriber => subscriber.unsubscribe());
const keyType = this.stateKeyType();
if (!keyType || !queries.length) {
this.dataSubscribers = [];
return;
}
this.listQueries = queries;
const previous = this.lists();
const previousTotals = this.listTotals();
this.lists.set(queries.map((_, index) => previous[index] ?? null));
this.listTotals.set(queries.map((_, index) => previousTotals[index] ?? 0));
this.dataSubscribers = queries.map((query, index) => {
const cmd = new EntityDataCmd();
const pageLink: EntityDataPageLink = {
page: 0,
pageSize: query.neverConnected ? pageSize * 2 : pageSize,
sortOrder: {key: query.sortKey, direction: query.direction},
dynamic: true
};
cmd.query = {
entityFilter: {type: AliasFilterType.entityType, entityType: EntityType.DEVICE},
pageLink,
keyFilters: [
...(query.state ? this.activeFilter(keyType, query.state === 'active') : []),
...(query.withActivity ? [this.hasActivityFilter(keyType)] : [])
],
entityFields: [
{type: EntityKeyType.ENTITY_FIELD, key: 'name'},
{type: EntityKeyType.ENTITY_FIELD, key: 'type'}
],
latestValues: [
{type: keyType, key: 'active'},
{type: keyType, key: 'lastActivityTime'}
]
};
cmd.latestCmd = {keys: [{type: keyType, key: 'active'}, {type: keyType, key: 'lastActivityTime'}]};
const subscriber = new TelemetrySubscriber(this.telemetryWsService, this.zone);
subscriber.subscriptionCommands.push(cmd);
subscriber.entityData$.subscribe(update => {
if (update.data) {
this.setList(index, update.data.data, update.data.totalElements);
} else if (update.update) {
const list = this.lists()[index] ?? [];
const byId = new Map(update.update.map(data => [data.entityId.id, data]));
this.setList(index, list.map(data => this.merge(data, byId.get(data.entityId.id))), null);
}
});
subscriber.subscribe();
return subscriber;
});
}
private setList(index: number, data: EntityData[], total: number | null): void {
const lists = [...this.lists()];
lists[index] = data;
this.lists.set(lists);
if (total !== null) {
const totals = [...this.listTotals()];
totals[index] = total;
this.listTotals.set(totals);
}
}
private merge(current: EntityData, update?: EntityData): EntityData {
if (!update) {
return current;
}
const latest = {...current.latest};
Object.keys(update.latest ?? {}).forEach(type => latest[type] = {...(latest[type] ?? {}), ...update.latest[type]});
return {...current, latest};
}
private subscribeCount(target: WritableSignal<number | null>, keyFilters?: KeyFilter[]): TelemetrySubscriber {
const cmd = new EntityCountCmd();
cmd.query = {
entityFilter: {type: AliasFilterType.entityType, entityType: EntityType.DEVICE},
keyFilters
};
const subscriber = new TelemetrySubscriber(this.telemetryWsService, this.zone);
subscriber.subscriptionCommands.push(cmd);
subscriber.entityCount$.subscribe(update => target.set(update.count ?? 0));
subscriber.subscribe();
return subscriber;
}
private activeFilter(keyType: EntityKeyType, active: boolean): KeyFilter[] {
return [{
key: {type: keyType, key: 'active'},
valueType: EntityKeyValueType.BOOLEAN,
predicate: {
type: FilterPredicateType.BOOLEAN,
operation: BooleanOperation.EQUAL,
value: {defaultValue: active}
}
}];
}
private hasActivityFilter(keyType: EntityKeyType): KeyFilter {
return {
key: {type: keyType, key: 'lastActivityTime'},
valueType: EntityKeyValueType.NUMERIC,
predicate: {
type: FilterPredicateType.NUMERIC,
operation: NumericOperation.GREATER,
value: {defaultValue: 0}
}
};
}
private toRow(data: EntityData, keyType: EntityKeyType | null, now: number): DeviceHomeRow {
const fields = data.latest?.[EntityKeyType.ENTITY_FIELD] ?? {};
const state = keyType ? data.latest?.[keyType] ?? {} : {};
const lastActivity = Number(state.lastActivityTime?.value) || null;
return {
id: data.entityId.id,
name: fields.name?.value ?? '',
profile: fields.type?.value ?? '',
active: state.active?.value === 'true',
lastActivity,
ago: lastActivity ? homeAgo(this.translate, now - lastActivity) : '',
url: getEntityDetailsPageURL(data.entityId.id, EntityType.DEVICE)
};
}
}

8
ui-ngx/src/app/modules/home/pages/home-links/home/components/home-list-footer.component.scss

@ -30,10 +30,6 @@
}
.tb-home-list-view-all {
&, &:hover, &:focus, &:active {
border-bottom: none;
}
display: inline-flex;
align-items: center;
height: 36px;
@ -48,6 +44,10 @@
color: var(--tb-ink-76, rgba(0, 0, 0, 0.76));
transition: background-color .15s ease;
&, &:hover, &:focus, &:active {
border-bottom: none;
}
.mat-icon {
width: 18px;
height: 18px;

24
ui-ngx/src/assets/locale/locale.constant-en_US.json

@ -8628,6 +8628,30 @@
"starred-toast": "“{{title}}” starred",
"opens-new-tab": "(opens in a new tab)"
},
"devices": {
"add": "Add device",
"none": "No devices yet. Add a device to see its state here.",
"none-assigned": "No devices assigned to you yet",
"how-to": "How to connect a device",
"inactive": "Inactive",
"active": "Active",
"show-only-inactive": "Show inactive only",
"show-only-active": "Show active only",
"show-every": "Show all devices",
"one-active": "The device is active.",
"all-active": "All {{count}} devices are active.",
"name": "Name",
"profile": "Device profile",
"state": "State",
"last-activity": "Last activity",
"last-activity-at": "Last activity {{time}}",
"sort-name": "Sort by name",
"sort-last": "Sort by last activity",
"never": "never",
"no-data": "No data received yet",
"none-inactive": "No inactive devices.",
"none-active": "No active devices."
},
"list": {
"show-more": "Show more",
"show-all": "Show all",

Loading…
Cancel
Save