19 changed files with 1485 additions and 18 deletions
@ -0,0 +1,176 @@ |
|||
<!-- |
|||
|
|||
SPDX-FileCopyrightText: Copyright ThingsBoard, Inc. |
|||
SPDX-License-Identifier: BUSL-1.1 |
|||
|
|||
--> |
|||
<tb-home-card [card]="card" [count]="total()"> |
|||
<ng-container homeCardActions> |
|||
@if (total()) { |
|||
<div class="tb-toggle-header" role="group" [attr.aria-label]="'home.alarms.whose' | translate"> |
|||
<button type="button" class="tb-toggle-option" [attr.aria-pressed]="!mine()" (click)="setMine(false)">{{ 'home.alarms.all' | translate }}</button> |
|||
<button type="button" class="tb-toggle-option" [attr.aria-pressed]="mine()" (click)="setMine(true)">{{ 'home.alarms.mine' | translate }}</button> |
|||
</div> |
|||
} |
|||
@if (tenantAdmin) { |
|||
<button mat-button color="primary" type="button" class="tb-alarms-add" (click)="addAlarmRule()"> |
|||
<mat-icon>add</mat-icon> |
|||
<span class="tb-alarms-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> |
|||
<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"> |
|||
@for (tile of tiles(); track tile.severity) { |
|||
<button type="button" class="tb-alarms-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"> |
|||
{{ tile.count | shortNumber }} |
|||
@if (tile.hot) { |
|||
<tb-ai-sev-mark class="tb-alarms-tile-mark" severity="CRITICAL"></tb-ai-sev-mark> |
|||
} |
|||
</span> |
|||
</button> |
|||
} |
|||
</div> |
|||
@if (rows().length) { |
|||
<table class="tb-alarms-table" [class.mine]="mine()"> |
|||
<thead> |
|||
<tr> |
|||
<th class="col-severity sortable" [class.sorted]="sortKey() === 'severity'" [attr.aria-sort]="ariaSort('severity')"> |
|||
<button type="button" class="th-label" [matTooltip]="'home.alarms.sort-severity' | translate" (click)="sortBy('severity')"> |
|||
<span class="th-text">{{ 'home.alarms.severity' | translate }}</span> |
|||
<mat-icon class="tb-sort-icon">{{ sortKey() === 'severity' && !sortDesc() ? 'arrow_upward' : 'arrow_downward' }}</mat-icon> |
|||
</button> |
|||
</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')"> |
|||
<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> |
|||
</button> |
|||
</th> |
|||
@if (!mine()) { |
|||
<th class="col-assignee"><span class="th-text">{{ 'home.alarms.assignee' | translate }}</span></th> |
|||
} |
|||
<th class="col-ack" [matTooltip]="'home.alarms.acknowledged-tip' | translate">{{ 'home.alarms.ack' | translate }}</th> |
|||
<th class="col-actions"></th> |
|||
</tr> |
|||
</thead> |
|||
<tbody> |
|||
@for (row of rows(); track row.alarm.id.id) { |
|||
<tr (click)="openDetails(row)"> |
|||
<td class="col-severity"> |
|||
<span class="tb-alarms-sev"> |
|||
<tb-ai-sev-mark [severity]="row.alarm.severity"></tb-ai-sev-mark> |
|||
<span class="tb-alarms-sev-word">{{ severityLabel(row.alarm.severity) | translate }}</span> |
|||
</span> |
|||
</td> |
|||
<td class="col-type"> |
|||
<span class="tb-alarms-cell-main"> |
|||
<a class="tb-alarms-link" href="#" (click)="openDetails(row, $event)">{{ row.alarm.type }}</a> |
|||
</span> |
|||
<span class="tb-alarms-cell-sub"> |
|||
<a class="tb-alarms-link tb-alarms-origin" [routerLink]="row.originatorLink" (click)="stop($event)">{{ row.alarm.originatorDisplayName || row.alarm.originatorName }}</a> |
|||
<span class="tb-alarms-sub-age"> · {{ row.ago }}</span> |
|||
</span> |
|||
</td> |
|||
<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> |
|||
@if (!mine()) { |
|||
<td class="col-assignee"> |
|||
@if (row.assigneeName) { |
|||
<span class="tb-alarms-assignee" [class.me]="row.mine" role="img" |
|||
[attr.aria-label]="row.mine ? ('home.alarms.assigned-you' | translate) : ('home.alarms.assigned-to' | translate: {name: row.assigneeName})" |
|||
[matTooltip]="row.mine ? ('home.alarms.assigned-you' | translate) : ('home.alarms.assigned-to' | translate: {name: row.assigneeName})">{{ row.initials }}</span> |
|||
} @else { |
|||
<span class="tb-alarms-assign-cell"> |
|||
<span class="tb-alarms-dash" [matTooltip]="'home.alarms.not-assigned' | translate">—</span> |
|||
<button mat-icon-button type="button" class="tb-alarms-assign" [matTooltip]="'home.alarms.assign-me' | translate" |
|||
[attr.aria-label]="'home.alarms.assign-me' | translate" (click)="assignToMe(row, $event)"> |
|||
<mat-icon>person_add</mat-icon> |
|||
</button> |
|||
</span> |
|||
} |
|||
</td> |
|||
} |
|||
<td class="col-ack"> |
|||
@if (row.alarm.acknowledged) { |
|||
<mat-icon class="tb-alarms-acked" role="img" [matTooltip]="'home.alarms.acknowledged-tip' | translate" |
|||
[attr.aria-label]="'home.alarms.acknowledged-tip' | translate">check_circle</mat-icon> |
|||
} @else { |
|||
<button mat-icon-button type="button" class="tb-alarms-ack" [matTooltip]="'home.alarms.acknowledge' | translate" |
|||
[attr.aria-label]="'home.alarms.acknowledge' | translate" (click)="acknowledge(row, $event)"> |
|||
<mat-icon class="off">radio_button_unchecked</mat-icon> |
|||
<mat-icon class="on">check_circle_outline</mat-icon> |
|||
</button> |
|||
} |
|||
</td> |
|||
<td class="col-actions"> |
|||
<button mat-icon-button type="button" class="tb-alarms-menu" [matMenuTriggerFor]="alarmMenu" [matMenuTriggerData]="{row}" |
|||
[attr.aria-label]="'home.alarms.actions' | translate" (click)="stop($event)"> |
|||
<mat-icon>more_vert</mat-icon> |
|||
</button> |
|||
</td> |
|||
</tr> |
|||
} |
|||
</tbody> |
|||
</table> |
|||
} @else if (alarmsLoaded()) { |
|||
<div class="tb-alarms-empty-note">{{ emptyNote().key | translate: emptyNote().params }}</div> |
|||
} |
|||
@if (!few() || listed()) { |
|||
<div class="tb-alarms-footer"> |
|||
@if (!few()) { |
|||
<button mat-button type="button" class="tb-alarms-toggle" (click)="toggleExpanded()"> |
|||
<mat-icon>{{ expanded() ? 'expand_less' : 'expand_more' }}</mat-icon> |
|||
{{ toggleLabel() | translate }} |
|||
</button> |
|||
} |
|||
<span class="tb-alarms-spacer"></span> |
|||
@if (shown() < listed()) { |
|||
<span class="tb-alarms-footer-count">{{ 'home.alarms.shown-of' | translate: {shown: shown(), total: (listed() | shortNumber)} }}</span> |
|||
} |
|||
@if (listed()) { |
|||
<a class="tb-alarms-view-all" routerLink="/alarms/alarms" [queryParams]="viewAllParams()">{{ 'home.alarms.view-all' | translate }}<mat-icon>chevron_right</mat-icon></a> |
|||
} |
|||
</div> |
|||
} |
|||
} |
|||
</tb-home-card> |
|||
|
|||
<mat-menu #alarmMenu="matMenu" xPosition="before" class="tb-ai-chat-menu tb-alarms-home-menu"> |
|||
<ng-template matMenuContent let-row="row"> |
|||
<button mat-menu-item [disabled]="row.alarm.acknowledged" (click)="acknowledge(row)"> |
|||
<mat-icon fontSet="material-icons-round">{{ row.alarm.acknowledged ? 'done_all' : 'done' }}</mat-icon> |
|||
<span>{{ (row.alarm.acknowledged ? 'home.alarms.acknowledged-tip' : 'home.alarms.acknowledge') | translate }}</span> |
|||
</button> |
|||
@if (!row.mine) { |
|||
<button mat-menu-item (click)="assignToMe(row)"> |
|||
<mat-icon fontSet="material-icons-round">person_add</mat-icon> |
|||
<span>{{ 'home.alarms.assign-me' | translate }}</span> |
|||
</button> |
|||
} |
|||
<button mat-menu-item (click)="openDetails(row)"> |
|||
<mat-icon fontSet="material-icons-round">open_in_new</mat-icon> |
|||
<span>{{ 'home.alarms.open-details' | translate }}</span> |
|||
</button> |
|||
<button mat-menu-item class="danger" (click)="clear(row)"> |
|||
<mat-icon fontSet="material-icons-round">clear</mat-icon> |
|||
<span>{{ 'home.alarms.clear' | translate }}</span> |
|||
</button> |
|||
</ng-template> |
|||
</mat-menu> |
|||
@ -0,0 +1,640 @@ |
|||
// SPDX-FileCopyrightText: Copyright ThingsBoard, Inc. |
|||
// SPDX-License-Identifier: BUSL-1.1 |
|||
:host { |
|||
display: block; |
|||
min-width: 0; |
|||
container: tb-alarms-home / inline-size; |
|||
} |
|||
|
|||
.tb-toggle-header { |
|||
display: inline-flex; |
|||
box-sizing: border-box; |
|||
height: 32px; |
|||
max-width: 100%; |
|||
padding: 2px; |
|||
border-radius: 100px; |
|||
background: rgba(0, 0, 0, 0.06); |
|||
} |
|||
|
|||
.tb-toggle-option { |
|||
flex: 1 1 auto; |
|||
height: 28px; |
|||
margin: 0; |
|||
padding: 0 12px; |
|||
border: 1px solid transparent; |
|||
border-radius: 20px; |
|||
background: none; |
|||
font: 400 14px/26px var(--tb-font, Roboto, sans-serif); |
|||
letter-spacing: 0.2px; |
|||
white-space: nowrap; |
|||
color: var(--tb-text-muted, rgba(0, 0, 0, 0.56)); |
|||
cursor: pointer; |
|||
|
|||
&[aria-pressed="true"] { |
|||
background: #fff; |
|||
box-shadow: 0 1px 2px rgba(16, 24, 40, 0.10), 0 1px 4px rgba(16, 24, 40, 0.06); |
|||
font-weight: 500; |
|||
line-height: 24px; |
|||
color: var(--tb-ink, rgba(0, 0, 0, 0.87)); |
|||
} |
|||
|
|||
&:focus-visible { |
|||
outline: 2px solid var(--tb-primary-500); |
|||
outline-offset: -2px; |
|||
} |
|||
} |
|||
|
|||
.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, .tb-alarms-view-all { |
|||
&, &:hover, &:focus, &:active { |
|||
border-bottom: none; |
|||
} |
|||
} |
|||
|
|||
.tb-alarms-clear-link { |
|||
font-weight: 500; |
|||
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; |
|||
|
|||
&.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 { |
|||
width: 20px; |
|||
height: 20px; |
|||
} |
|||
|
|||
.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; |
|||
} |
|||
} |
|||
|
|||
td.col-type .tb-alarms-cell-main { |
|||
display: flex; |
|||
min-width: 0; |
|||
max-width: 220px; |
|||
overflow: hidden; |
|||
text-overflow: ellipsis; |
|||
} |
|||
|
|||
td.col-origin { |
|||
max-width: 160px; |
|||
overflow: hidden; |
|||
text-overflow: ellipsis; |
|||
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; |
|||
padding-right: 8px; |
|||
text-align: center; |
|||
} |
|||
|
|||
.col-actions { |
|||
width: 32px; |
|||
padding-right: 0; |
|||
text-align: right; |
|||
} |
|||
} |
|||
|
|||
.tb-alarms-sev { |
|||
display: inline-flex; |
|||
align-items: center; |
|||
gap: 8px; |
|||
white-space: nowrap; |
|||
} |
|||
|
|||
.tb-alarms-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 { |
|||
text-decoration: underline; |
|||
} |
|||
} |
|||
|
|||
.tb-alarms-origin { |
|||
color: inherit; |
|||
} |
|||
|
|||
.tb-alarms-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-alarms-origin { |
|||
color: var(--tb-text-secondary, rgba(0, 0, 0, 0.6)); |
|||
|
|||
&:hover { |
|||
color: var(--tb-ink, rgba(0, 0, 0, 0.87)); |
|||
} |
|||
} |
|||
} |
|||
|
|||
.tb-alarms-assignee { |
|||
display: inline-flex; |
|||
align-items: center; |
|||
justify-content: center; |
|||
width: 24px; |
|||
height: 24px; |
|||
border-radius: 50%; |
|||
background: rgba(0, 0, 0, 0.06); |
|||
font: 500 10px/1 var(--tb-font, Roboto, sans-serif); |
|||
color: var(--tb-ink-76, rgba(0, 0, 0, 0.76)); |
|||
vertical-align: middle; |
|||
|
|||
&.me { |
|||
background: var(--tb-primary-500); |
|||
color: var(--tb-primary-contrast-500, #fff); |
|||
} |
|||
} |
|||
|
|||
.tb-alarms-assign-cell { |
|||
display: inline-grid; |
|||
place-items: center; |
|||
vertical-align: middle; |
|||
|
|||
> * { |
|||
grid-area: 1 / 1; |
|||
} |
|||
} |
|||
|
|||
.tb-alarms-dash { |
|||
color: var(--tb-text-muted, rgba(0, 0, 0, 0.56)); |
|||
} |
|||
|
|||
.tb-alarms-assign.mat-mdc-icon-button, .tb-alarms-ack.mat-mdc-icon-button, .tb-alarms-menu.mat-mdc-icon-button { |
|||
--mdc-icon-button-state-layer-size: 32px; |
|||
--mat-icon-button-state-layer-size: 32px; |
|||
display: inline-flex; |
|||
align-items: center; |
|||
justify-content: center; |
|||
width: 32px; |
|||
height: 32px; |
|||
margin: -6px 0; |
|||
padding: 0; |
|||
vertical-align: middle; |
|||
color: var(--tb-ink-54, rgba(0, 0, 0, 0.54)); |
|||
|
|||
.mat-icon { |
|||
width: 20px; |
|||
height: 20px; |
|||
font-size: 20px; |
|||
} |
|||
|
|||
.mat-mdc-button-touch-target { |
|||
width: 32px; |
|||
height: 32px; |
|||
} |
|||
|
|||
&:is(:hover, :focus-visible) { |
|||
color: var(--tb-ink, rgba(0, 0, 0, 0.87)); |
|||
} |
|||
} |
|||
|
|||
.tb-alarms-assign.mat-mdc-icon-button { |
|||
visibility: hidden; |
|||
background: var(--tb-surface, #fff); |
|||
} |
|||
|
|||
.tb-alarms-ack.mat-mdc-icon-button { |
|||
.on { |
|||
display: none; |
|||
} |
|||
|
|||
&:is(:hover, :focus-visible) { |
|||
.off { |
|||
display: none; |
|||
} |
|||
|
|||
.on { |
|||
display: inline-block; |
|||
} |
|||
} |
|||
} |
|||
|
|||
.tb-alarms-acked { |
|||
width: 20px; |
|||
height: 20px; |
|||
font-size: 20px; |
|||
vertical-align: middle; |
|||
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)); |
|||
} |
|||
|
|||
.tb-alarms-footer { |
|||
display: flex; |
|||
flex-wrap: wrap; |
|||
align-items: center; |
|||
gap: 8px; |
|||
min-height: 36px; |
|||
padding-top: 8px; |
|||
border-top: 1px solid rgba(0, 0, 0, 0.05); |
|||
font: 400 14px/20px var(--tb-font, Roboto, sans-serif); |
|||
color: var(--tb-text-secondary, rgba(0, 0, 0, 0.6)); |
|||
|
|||
.tb-alarms-toggle.mat-mdc-button { |
|||
margin-left: -8px; |
|||
color: var(--tb-ink-76, rgba(0, 0, 0, 0.76)); |
|||
} |
|||
} |
|||
|
|||
.tb-alarms-spacer { |
|||
flex: 1 1 auto; |
|||
} |
|||
|
|||
.tb-alarms-footer-count { |
|||
font-variant-numeric: tabular-nums; |
|||
} |
|||
|
|||
.tb-alarms-view-all { |
|||
display: inline-flex; |
|||
align-items: center; |
|||
height: 36px; |
|||
margin-right: -8px; |
|||
padding: 0 4px 0 8px; |
|||
border-radius: 4px; |
|||
font-weight: 500; |
|||
font-size: 14px; |
|||
letter-spacing: 0.03125em; |
|||
white-space: nowrap; |
|||
text-decoration: none; |
|||
color: var(--tb-ink-76, rgba(0, 0, 0, 0.76)); |
|||
transition: background-color .15s ease; |
|||
|
|||
.mat-icon { |
|||
width: 18px; |
|||
height: 18px; |
|||
font-size: 18px; |
|||
} |
|||
|
|||
&:hover { |
|||
background: rgba(0, 0, 0, 0.04); |
|||
color: var(--tb-ink, rgba(0, 0, 0, 0.87)); |
|||
} |
|||
|
|||
&:focus-visible { |
|||
outline: 2px solid var(--tb-primary-500); |
|||
outline-offset: -2px; |
|||
} |
|||
} |
|||
|
|||
@container tb-alarms-home (max-width: 599px) { |
|||
.tb-alarms-table { |
|||
.col-origin { |
|||
display: none; |
|||
} |
|||
|
|||
td.col-type { |
|||
width: 99%; |
|||
max-width: 0; |
|||
padding-top: 6px; |
|||
padding-bottom: 6px; |
|||
|
|||
.tb-alarms-cell-main { |
|||
max-width: none; |
|||
} |
|||
} |
|||
|
|||
.col-severity { |
|||
width: 1%; |
|||
padding-right: 4px; |
|||
} |
|||
|
|||
tbody td.col-severity { |
|||
padding-top: 6px; |
|||
vertical-align: top; |
|||
} |
|||
|
|||
th.col-severity .th-text { |
|||
position: absolute; |
|||
width: 1px; |
|||
height: 1px; |
|||
overflow: hidden; |
|||
clip: rect(0 0 0 0); |
|||
} |
|||
} |
|||
|
|||
.tb-alarms-sev { |
|||
gap: 0; |
|||
height: 20px; |
|||
} |
|||
|
|||
.tb-alarms-sev-word { |
|||
position: absolute; |
|||
width: 1px; |
|||
height: 1px; |
|||
overflow: hidden; |
|||
clip: rect(0 0 0 0); |
|||
white-space: nowrap; |
|||
} |
|||
|
|||
.tb-alarms-cell-sub { |
|||
display: block; |
|||
} |
|||
|
|||
.tb-alarms-sub-age { |
|||
display: none; |
|||
} |
|||
} |
|||
|
|||
@container tb-alarms-home (max-width: 459px) { |
|||
.tb-alarms-table { |
|||
.col-age { |
|||
display: none; |
|||
} |
|||
|
|||
th.col-assignee .th-text { |
|||
position: absolute; |
|||
width: 1px; |
|||
height: 1px; |
|||
overflow: hidden; |
|||
clip: rect(0 0 0 0); |
|||
} |
|||
} |
|||
|
|||
.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; |
|||
} |
|||
} |
|||
@ -1,16 +1,427 @@ |
|||
// 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 { MatDialog } from '@angular/material/dialog'; |
|||
import { TranslateService } from '@ngx-translate/core'; |
|||
import { AppState } from '@core/core.state'; |
|||
import { getCurrentAuthUser } from '@core/auth/auth.selectors'; |
|||
import { TelemetryWebsocketService } from '@core/ws/telemetry-websocket.service'; |
|||
import { AlarmService } from '@core/http/alarm.service'; |
|||
import { DialogService } from '@core/services/dialog.service'; |
|||
import { ToastNotificationService } from '@core/services/toast-notification.service'; |
|||
import { AlarmCountCmd, AlarmDataCmd, TelemetrySubscriber } from '@shared/models/telemetry/telemetry.models'; |
|||
import { AlarmData, AlarmDataPageLink, EntityKeyType } from '@shared/models/query/query.models'; |
|||
import { Direction } from '@shared/models/page/sort-order'; |
|||
import { AlarmSearchStatus, AlarmSeverity, alarmSeverityTranslations } from '@shared/models/alarm.models'; |
|||
import { Authority } from '@shared/models/authority.enum'; |
|||
import { EntityType } from '@shared/models/entity-type.models'; |
|||
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 { AlarmDetailsDialogComponent, AlarmDetailsDialogData } from '@home/components/alarm/alarm-details-dialog.component'; |
|||
|
|||
const PREVIEW = 5; |
|||
const SLACK = 2; |
|||
const ROW_LIMIT = 10; |
|||
const MINUTE = 60000; |
|||
const MINE_KEY = 'tb-home-alarms-mine'; |
|||
const SEVERITIES = [AlarmSeverity.CRITICAL, AlarmSeverity.MAJOR, AlarmSeverity.MINOR, AlarmSeverity.WARNING]; |
|||
|
|||
type AlarmSortKey = 'severity' | 'createdTime'; |
|||
|
|||
interface SeverityTile { |
|||
severity: AlarmSeverity; |
|||
count: number; |
|||
pressed: boolean; |
|||
hot: boolean; |
|||
} |
|||
|
|||
export interface AlarmHomeRow { |
|||
alarm: AlarmData; |
|||
ago: string; |
|||
originatorLink: string | null; |
|||
assigneeName: string | null; |
|||
initials: string; |
|||
mine: boolean; |
|||
} |
|||
|
|||
const readMine = (): boolean => { |
|||
try { |
|||
return localStorage.getItem(MINE_KEY) === '1'; |
|||
} catch { |
|||
return false; |
|||
} |
|||
}; |
|||
|
|||
const writeMine = (mine: boolean): void => { |
|||
try { |
|||
if (mine) { |
|||
localStorage.setItem(MINE_KEY, '1'); |
|||
} else { |
|||
localStorage.removeItem(MINE_KEY); |
|||
} |
|||
} catch { |
|||
return; |
|||
} |
|||
}; |
|||
|
|||
@Component({ |
|||
selector: 'tb-alarms-home', |
|||
template: `<tb-home-card [card]="card"></tb-home-card>`, |
|||
templateUrl: './alarms-home.component.html', |
|||
styleUrls: ['./alarms-home.component.scss'], |
|||
standalone: false, |
|||
changeDetection: ChangeDetectionStrategy.OnPush |
|||
}) |
|||
export class AlarmsHomeComponent { |
|||
|
|||
readonly card = HOME_CARDS[HomeCardId.ALARMS]; |
|||
|
|||
private telemetryWsService = inject(TelemetryWebsocketService); |
|||
private zone = inject(NgZone); |
|||
private store = inject(Store<AppState>); |
|||
private router = inject(Router); |
|||
private dialog = inject(MatDialog); |
|||
private dialogService = inject(DialogService); |
|||
private alarmService = inject(AlarmService); |
|||
private toast = inject(ToastNotificationService); |
|||
private translate = inject(TranslateService); |
|||
|
|||
private readonly authUser = getCurrentAuthUser(this.store); |
|||
private readonly userId = this.authUser?.userId; |
|||
readonly tenantAdmin = this.authUser?.authority === Authority.TENANT_ADMIN; |
|||
|
|||
readonly mine = signal(readMine()); |
|||
readonly severity = signal<AlarmSeverity | null>(null); |
|||
readonly expanded = signal(false); |
|||
readonly sortKey = signal<AlarmSortKey>('severity'); |
|||
readonly sortDesc = signal(true); |
|||
|
|||
readonly total = signal<number | null>(null); |
|||
private readonly severityCounts = new Map<AlarmSeverity, WritableSignal<number | null>>( |
|||
SEVERITIES.map(severity => [severity, signal<number | null>(null)]) |
|||
); |
|||
|
|||
private readonly alarms = signal<AlarmData[] | null>(null); |
|||
readonly listed = signal(0); |
|||
readonly alarmsLoaded = computed(() => this.alarms() !== null); |
|||
private readonly now = signal(Date.now()); |
|||
|
|||
private totalSubscriber: TelemetrySubscriber | null = null; |
|||
private severitySubscribers: TelemetrySubscriber[] = []; |
|||
private dataSubscriber: TelemetrySubscriber | null = null; |
|||
|
|||
readonly tiles = computed<SeverityTile[]>(() => { |
|||
const pressed = this.severity(); |
|||
return SEVERITIES.map(severity => { |
|||
const count = this.severityCounts.get(severity)() ?? 0; |
|||
return {severity, count, pressed: pressed === severity, hot: severity === AlarmSeverity.CRITICAL && count > 0}; |
|||
}).filter(tile => tile.severity === AlarmSeverity.CRITICAL || tile.count > 0 || tile.pressed); |
|||
}); |
|||
|
|||
readonly few = computed(() => this.listed() <= PREVIEW + SLACK); |
|||
|
|||
readonly shown = computed(() => { |
|||
const listed = this.listed(); |
|||
if (this.few()) { |
|||
return listed; |
|||
} |
|||
return this.expanded() ? Math.min(listed, ROW_LIMIT) : PREVIEW; |
|||
}); |
|||
|
|||
readonly toggleLabel = computed(() => { |
|||
if (this.expanded()) { |
|||
return 'home.alarms.show-less'; |
|||
} |
|||
return this.listed() <= ROW_LIMIT ? 'home.alarms.show-all' : 'home.alarms.show-more'; |
|||
}); |
|||
|
|||
readonly rows = computed<AlarmHomeRow[]>(() => { |
|||
const now = this.now(); |
|||
return (this.alarms() ?? []).slice(0, this.shown()).map(alarm => this.toRow(alarm, now)); |
|||
}); |
|||
|
|||
readonly emptyNote = computed<{key: string; params: Record<string, string>}>(() => { |
|||
const severity = this.severity(); |
|||
const mine = this.mine(); |
|||
if (severity) { |
|||
return { |
|||
key: mine ? 'home.alarms.none-severity-mine' : 'home.alarms.none-severity', |
|||
params: {severity: this.translate.instant(alarmSeverityTranslations.get(severity)).toLowerCase()} |
|||
}; |
|||
} |
|||
return {key: mine ? 'home.alarms.none-mine' : 'home.alarms.none-active', params: {}}; |
|||
}); |
|||
|
|||
readonly viewAllParams = computed<Record<string, unknown>>(() => { |
|||
const severity = this.severity(); |
|||
return { |
|||
...(severity ? {severityList: [severity]} : {}), |
|||
...(this.mine() ? {assignedToMe: true} : {}) |
|||
}; |
|||
}); |
|||
|
|||
private readonly pageLink = computed<AlarmDataPageLink>(() => { |
|||
const severity = this.severity(); |
|||
const key = this.sortKey(); |
|||
const desc = this.sortDesc(); |
|||
return { |
|||
page: 0, |
|||
pageSize: this.expanded() ? ROW_LIMIT : PREVIEW + SLACK, |
|||
sortOrder: { |
|||
key: {type: EntityKeyType.ALARM_FIELD, key}, |
|||
direction: key === 'severity' ? (desc ? Direction.ASC : Direction.DESC) : (desc ? Direction.DESC : Direction.ASC) |
|||
}, |
|||
statusList: [AlarmSearchStatus.ACTIVE], |
|||
...(severity ? {severityList: [severity]} : {}), |
|||
...(this.mine() && this.userId ? {assigneeId: {entityType: EntityType.USER, id: this.userId}} : {}) |
|||
}; |
|||
}); |
|||
|
|||
constructor() { |
|||
this.totalSubscriber = this.subscribeCount(this.total); |
|||
effect(() => { |
|||
const mine = this.mine(); |
|||
untracked(() => this.subscribeSeverityCounts(mine)); |
|||
}); |
|||
effect(() => { |
|||
const pageLink = this.pageLink(); |
|||
untracked(() => this.subscribeAlarms(pageLink)); |
|||
}); |
|||
const tick = setInterval(() => this.now.set(Date.now()), MINUTE); |
|||
inject(DestroyRef).onDestroy(() => { |
|||
clearInterval(tick); |
|||
this.totalSubscriber?.unsubscribe(); |
|||
this.severitySubscribers.forEach(subscriber => subscriber.unsubscribe()); |
|||
this.dataSubscriber?.unsubscribe(); |
|||
}); |
|||
} |
|||
|
|||
severityLabel(severity: AlarmSeverity | string): string { |
|||
return alarmSeverityTranslations.get(severity as AlarmSeverity) ?? String(severity); |
|||
} |
|||
|
|||
setMine(mine: boolean): void { |
|||
if (mine !== this.mine()) { |
|||
this.mine.set(mine); |
|||
writeMine(mine); |
|||
} |
|||
} |
|||
|
|||
pick(tile: SeverityTile): void { |
|||
if (tile.count || tile.pressed) { |
|||
this.severity.set(tile.pressed ? null : tile.severity); |
|||
} |
|||
} |
|||
|
|||
sortBy(key: AlarmSortKey): void { |
|||
if (this.sortKey() === key) { |
|||
this.sortDesc.set(!this.sortDesc()); |
|||
} else { |
|||
this.sortKey.set(key); |
|||
this.sortDesc.set(true); |
|||
} |
|||
} |
|||
|
|||
ariaSort(key: AlarmSortKey): string { |
|||
if (this.sortKey() !== key) { |
|||
return 'none'; |
|||
} |
|||
return this.sortDesc() ? 'descending' : 'ascending'; |
|||
} |
|||
|
|||
toggleExpanded(): void { |
|||
this.expanded.set(!this.expanded()); |
|||
} |
|||
|
|||
addAlarmRule(): void { |
|||
this.router.navigateByUrl('/alarms/alarm-rules'); |
|||
} |
|||
|
|||
openDetails(row: AlarmHomeRow, $event?: Event): void { |
|||
$event?.preventDefault(); |
|||
$event?.stopPropagation(); |
|||
this.dialog.open<AlarmDetailsDialogComponent, AlarmDetailsDialogData, boolean>(AlarmDetailsDialogComponent, { |
|||
disableClose: true, |
|||
panelClass: ['tb-dialog', 'tb-fullscreen-dialog'], |
|||
data: { |
|||
alarmId: row.alarm.id.id, |
|||
alarm: row.alarm, |
|||
allowAcknowledgment: true, |
|||
allowClear: true, |
|||
displayDetails: true, |
|||
allowAssign: true |
|||
} |
|||
}).afterClosed().subscribe(changed => { |
|||
if (changed) { |
|||
this.refresh(); |
|||
} |
|||
}); |
|||
} |
|||
|
|||
stop($event: Event): void { |
|||
$event.stopPropagation(); |
|||
} |
|||
|
|||
acknowledge(row: AlarmHomeRow, $event?: Event): void { |
|||
$event?.stopPropagation(); |
|||
if (row.alarm.acknowledged) { |
|||
return; |
|||
} |
|||
this.patch(row.alarm.id.id, {acknowledged: true}); |
|||
this.alarmService.ackAlarm(row.alarm.id.id).subscribe({ |
|||
next: () => { |
|||
this.notify('home.alarms.acknowledged', row); |
|||
this.refresh(); |
|||
}, |
|||
error: () => this.refresh() |
|||
}); |
|||
} |
|||
|
|||
assignToMe(row: AlarmHomeRow, $event?: Event): void { |
|||
$event?.stopPropagation(); |
|||
if (this.userId) { |
|||
this.alarmService.assignAlarm(row.alarm.id.id, this.userId).subscribe(() => { |
|||
this.notify('home.alarms.assigned', row); |
|||
this.refresh(); |
|||
}); |
|||
} |
|||
} |
|||
|
|||
clear(row: AlarmHomeRow): void { |
|||
const name = this.alarmName(row); |
|||
this.dialogService.confirm( |
|||
this.translate.instant('home.alarms.clear-title', {name}), |
|||
this.translate.instant('home.alarms.clear-text'), |
|||
this.translate.instant('action.cancel'), |
|||
this.translate.instant('home.alarms.clear') |
|||
).subscribe(confirmed => { |
|||
if (confirmed) { |
|||
this.alarmService.clearAlarm(row.alarm.id.id).subscribe(() => { |
|||
this.notify('home.alarms.cleared', row); |
|||
this.refresh(); |
|||
}); |
|||
} |
|||
}); |
|||
} |
|||
|
|||
private subscribeAlarms(pageLink: AlarmDataPageLink): void { |
|||
this.dataSubscriber?.unsubscribe(); |
|||
const cmd = new AlarmDataCmd(); |
|||
cmd.query = { |
|||
entityFilter: null, |
|||
pageLink, |
|||
alarmFields: [], |
|||
entityFields: [], |
|||
latestValues: [] |
|||
}; |
|||
const subscriber = new TelemetrySubscriber(this.telemetryWsService, this.zone); |
|||
subscriber.subscriptionCommands.push(cmd); |
|||
this.dataSubscriber = subscriber; |
|||
subscriber.alarmData$.subscribe(update => { |
|||
if (update.data) { |
|||
this.listed.set(update.data.totalElements); |
|||
this.alarms.set(update.data.data); |
|||
} else if (update.update) { |
|||
const byId = new Map(update.update.map(alarm => [alarm.id.id, alarm])); |
|||
this.alarms.set((this.alarms() ?? []).map(alarm => byId.get(alarm.id.id) ?? alarm)); |
|||
} |
|||
}); |
|||
subscriber.subscribe(); |
|||
} |
|||
|
|||
private subscribeSeverityCounts(mine: boolean): void { |
|||
this.severitySubscribers.forEach(subscriber => subscriber.unsubscribe()); |
|||
this.severitySubscribers = SEVERITIES.map(severity => this.subscribeCount(this.severityCounts.get(severity), severity, mine)); |
|||
} |
|||
|
|||
private subscribeCount(target: WritableSignal<number | null>, severity?: AlarmSeverity, mine = false): TelemetrySubscriber { |
|||
const cmd = new AlarmCountCmd(); |
|||
cmd.query = { |
|||
entityFilter: null, |
|||
statusList: [AlarmSearchStatus.ACTIVE], |
|||
...(severity ? {severityList: [severity]} : {}), |
|||
...(mine && this.userId ? {assigneeId: {entityType: EntityType.USER, id: this.userId}} : {}) |
|||
}; |
|||
const subscriber = new TelemetrySubscriber(this.telemetryWsService, this.zone); |
|||
subscriber.subscriptionCommands.push(cmd); |
|||
subscriber.alarmCount$.subscribe(update => target.set(update.count ?? 0)); |
|||
subscriber.subscribe(); |
|||
return subscriber; |
|||
} |
|||
|
|||
private refresh(): void { |
|||
this.subscribeAlarms(this.pageLink()); |
|||
this.totalSubscriber?.unsubscribe(); |
|||
this.totalSubscriber = this.subscribeCount(this.total); |
|||
this.subscribeSeverityCounts(this.mine()); |
|||
} |
|||
|
|||
private patch(alarmId: string, change: Partial<AlarmData>): void { |
|||
const alarms = this.alarms(); |
|||
if (alarms) { |
|||
this.alarms.set(alarms.map(alarm => alarm.id.id === alarmId ? {...alarm, ...change} : alarm)); |
|||
} |
|||
} |
|||
|
|||
private notify(key: string, row: AlarmHomeRow): void { |
|||
this.toast.dispatchNotification({ |
|||
message: this.translate.instant(key, {name: this.alarmName(row)}), |
|||
type: 'info', |
|||
duration: 4000, |
|||
horizontalPosition: 'right', |
|||
verticalPosition: 'bottom', |
|||
panelClass: 'tb-home-toast' |
|||
}); |
|||
} |
|||
|
|||
private alarmName(row: AlarmHomeRow): string { |
|||
return this.translate.instant('home.alarms.name', {type: row.alarm.type, originator: row.alarm.originatorName ?? ''}); |
|||
} |
|||
|
|||
private toRow(alarm: AlarmData, now: number): AlarmHomeRow { |
|||
const assignee = alarm.assigneeId ? alarm.assignee : null; |
|||
const assigneeName = assignee ? [assignee.firstName, assignee.lastName].filter(Boolean).join(' ') || assignee.email : null; |
|||
const initials = assignee |
|||
? (assignee.firstName && assignee.lastName ? assignee.firstName[0] + assignee.lastName[0] : (assigneeName ?? '').slice(0, 2)).toUpperCase() |
|||
: ''; |
|||
const originator = alarm.originator; |
|||
return { |
|||
alarm, |
|||
ago: this.ago(now - (alarm.createdTime ?? now)), |
|||
originatorLink: originator ? getEntityDetailsPageURL(originator.id, originator.entityType as EntityType) : null, |
|||
assigneeName, |
|||
initials, |
|||
mine: !!alarm.assigneeId && alarm.assigneeId.id === this.userId |
|||
}; |
|||
} |
|||
|
|||
private ago(ms: number): string { |
|||
const min = ms / MINUTE; |
|||
if (min < 1) { |
|||
return this.translate.instant('home.alarms.ago.now'); |
|||
} |
|||
if (min < 60) { |
|||
return this.translate.instant('home.alarms.ago.min', {count: Math.round(min)}); |
|||
} |
|||
if (min < 24 * 60) { |
|||
return this.translate.instant('home.alarms.ago.hour', {count: Math.floor(min / 60)}); |
|||
} |
|||
if (min < 7 * 24 * 60) { |
|||
return this.translate.instant('home.alarms.ago.day', {count: Math.floor(min / (24 * 60))}); |
|||
} |
|||
return this.translate.instant('home.alarms.ago.week', {count: Math.floor(min / (7 * 24 * 60))}); |
|||
} |
|||
} |
|||
|
|||
@ -0,0 +1,11 @@ |
|||
// SPDX-FileCopyrightText: Copyright ThingsBoard, Inc. |
|||
// SPDX-License-Identifier: BUSL-1.1 |
|||
.mat-mdc-menu-panel.tb-alarms-home-menu { |
|||
&.mat-menu-below { |
|||
margin-top: 4px; |
|||
} |
|||
|
|||
&.mat-menu-above { |
|||
margin-bottom: 4px; |
|||
} |
|||
} |
|||
Loading…
Reference in new issue