Browse Source
AI chat: Generate dashboard with AI in the chat, docked chat head, tooltips and QA fixespull/16870/head
committed by
GitHub
95 changed files with 830 additions and 639 deletions
@ -1,15 +0,0 @@ |
|||
<!-- |
|||
|
|||
SPDX-FileCopyrightText: Copyright ThingsBoard, Inc. |
|||
SPDX-License-Identifier: BUSL-1.1 |
|||
|
|||
--> |
|||
<div class="tb-generated flex flex-col items-center justify-center"> |
|||
<div class="panel flex max-w-full flex-col items-center gap-6 rounded-lg p-10"> |
|||
<img [src]="data?.image || generateImage" alt="Loading"> |
|||
<div class="flex flex-col items-center gap-1"> |
|||
<span class="msg text-xl font-semibold" [class.text-changed]="statusMessageChanged">{{ statusMessage | translate }}</span> |
|||
<span class="info">{{ 'solution-creator.estimate-wait-time' | translate: {time: (data.estimateWaitTime | milliSecondsToTimeString:true : true)} }}</span> |
|||
</div> |
|||
</div> |
|||
</div> |
|||
@ -1,34 +0,0 @@ |
|||
// SPDX-FileCopyrightText: Copyright ThingsBoard, Inc. |
|||
// SPDX-License-Identifier: BUSL-1.1 |
|||
.tb-generated { |
|||
z-index: 3; |
|||
.panel { |
|||
box-shadow: 0 6px 12px 0 rgba(0, 0, 0, 0.04), 0 12px 32px 0 rgba(0, 0, 0, 0.08); |
|||
background-color: #fff; |
|||
width: 500px; |
|||
} |
|||
img { |
|||
width: 200px; |
|||
} |
|||
.info { |
|||
white-space: pre-line; |
|||
text-align: center; |
|||
line-height: 1.5; |
|||
letter-spacing: 0.15px; |
|||
} |
|||
|
|||
.msg.text-changed { |
|||
animation: fadeInSlideUp 0.5s ease-out forwards; |
|||
} |
|||
|
|||
@keyframes fadeInSlideUp { |
|||
0% { |
|||
opacity: 0; |
|||
transform: translateY(15px); |
|||
} |
|||
100% { |
|||
opacity: 1; |
|||
transform: translateY(0); |
|||
} |
|||
} |
|||
} |
|||
@ -1,61 +0,0 @@ |
|||
// SPDX-FileCopyrightText: Copyright ThingsBoard, Inc.
|
|||
// SPDX-License-Identifier: BUSL-1.1
|
|||
import { Component, DestroyRef, Inject, OnInit, ViewEncapsulation } from '@angular/core'; |
|||
import { DialogComponent } from '@shared/components/dialog.component'; |
|||
import { Store } from '@ngrx/store'; |
|||
import { AppState } from '@core/core.state'; |
|||
import { Router } from '@angular/router'; |
|||
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog'; |
|||
import { from, of } from 'rxjs'; |
|||
import { concatMap, delay } from 'rxjs/operators'; |
|||
import { takeUntilDestroyed } from '@angular/core/rxjs-interop'; |
|||
import { generatedStateImages } from '@home/components/ai/ai.models'; |
|||
|
|||
export interface AiLoadingModalData { |
|||
messages: Array<{text: string; delay: number}>; |
|||
estimateWaitTime: number; |
|||
image?: string; |
|||
} |
|||
|
|||
@Component({ |
|||
selector: 'tb-ai-loading-modal', |
|||
templateUrl: './ai-loading-modal.component.html', |
|||
styleUrl: './ai-loading-modal.component.scss', |
|||
encapsulation: ViewEncapsulation.None, |
|||
standalone: false, |
|||
host: { |
|||
style: 'width: 100%; height: 100%; min-height: 100%; display: flex; overflow: hidden;' |
|||
} |
|||
}) |
|||
export class AiLoadingModalComponent extends DialogComponent<AiLoadingModalComponent> implements OnInit { |
|||
|
|||
generateImage: string = generatedStateImages[Math.floor(Math.random() * generatedStateImages.length)]; |
|||
statusMessage: string = ''; |
|||
statusMessageChanged = false; |
|||
|
|||
constructor(protected store: Store<AppState>, |
|||
protected router: Router, |
|||
@Inject(MAT_DIALOG_DATA) public data: AiLoadingModalData, |
|||
public dialogRef: MatDialogRef<AiLoadingModalComponent>, |
|||
private destroyRef: DestroyRef) { |
|||
super(store, router, dialogRef); |
|||
} |
|||
|
|||
ngOnInit() { |
|||
this.initGenerateState(); |
|||
} |
|||
|
|||
private initGenerateState(): void { |
|||
from(this.data.messages).pipe( |
|||
concatMap(message => of(message).pipe(delay(message.delay))), |
|||
takeUntilDestroyed(this.destroyRef) |
|||
).subscribe((msg) => { |
|||
this.statusMessageChanged = true; |
|||
this.statusMessage = msg.text; |
|||
setTimeout(() => { |
|||
this.statusMessageChanged = false; |
|||
}, 500); |
|||
}); |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,70 @@ |
|||
// SPDX-FileCopyrightText: Copyright ThingsBoard, Inc.
|
|||
// SPDX-License-Identifier: BUSL-1.1
|
|||
import { Directive, ElementRef, HostListener, inject, Provider } from '@angular/core'; |
|||
import { MAT_TOOLTIP_DEFAULT_OPTIONS, MatTooltip, MatTooltipDefaultOptions } from '@angular/material/tooltip'; |
|||
|
|||
export const AI_TOOLTIP_OPTIONS: MatTooltipDefaultOptions = { |
|||
showDelay: 500, |
|||
hideDelay: 0, |
|||
touchendHideDelay: 1500, |
|||
disableTooltipInteractivity: true, |
|||
tooltipClass: 'tb-ai-tip' |
|||
}; |
|||
|
|||
export const AI_TOOLTIP_PROVIDERS: Provider[] = [{provide: MAT_TOOLTIP_DEFAULT_OPTIONS, useValue: AI_TOOLTIP_OPTIONS}]; |
|||
|
|||
const NEXT_AT_ONCE_MS = 400; |
|||
|
|||
let lastTipAt = 0; |
|||
|
|||
@Directive({ |
|||
selector: '[matTooltip]', |
|||
standalone: true |
|||
}) |
|||
export class AiTooltipChainDirective { |
|||
|
|||
private tooltip = inject(MatTooltip, {self: true}); |
|||
private host = inject<ElementRef<HTMLElement>>(ElementRef); |
|||
|
|||
@HostListener('mouseenter') |
|||
onEnter(): void { |
|||
if (this.inChat()) { |
|||
this.tooltip.showDelay = Date.now() - lastTipAt < NEXT_AT_ONCE_MS ? 0 : AI_TOOLTIP_OPTIONS.showDelay; |
|||
} |
|||
} |
|||
|
|||
@HostListener('mouseleave') |
|||
onLeave(): void { |
|||
if (this.inChat() && this.tooltip._isTooltipVisible()) { |
|||
lastTipAt = Date.now(); |
|||
} |
|||
} |
|||
|
|||
@HostListener('focus') |
|||
onFocus(): void { |
|||
if (this.inChat()) { |
|||
this.tooltip.showDelay = this.host.nativeElement.matches(':focus-visible') ? 0 : AI_TOOLTIP_OPTIONS.showDelay; |
|||
} |
|||
} |
|||
|
|||
private inChat(): boolean { |
|||
return (this.tooltip.tooltipClass as string | string[]) === AI_TOOLTIP_OPTIONS.tooltipClass; |
|||
} |
|||
} |
|||
|
|||
@Directive({ |
|||
selector: '[aiTipIfCut]', |
|||
standalone: true |
|||
}) |
|||
export class AiTipIfCutDirective { |
|||
|
|||
private tooltip = inject(MatTooltip, {self: true}); |
|||
private host = inject<ElementRef<HTMLElement>>(ElementRef); |
|||
|
|||
@HostListener('mouseenter') |
|||
@HostListener('focus') |
|||
check(): void { |
|||
const element = this.host.nativeElement.querySelector<HTMLElement>('.tb-ai-cut') ?? this.host.nativeElement; |
|||
this.tooltip.disabled = element.scrollWidth <= element.clientWidth + 1; |
|||
} |
|||
} |
|||
@ -1,22 +0,0 @@ |
|||
// SPDX-FileCopyrightText: Copyright ThingsBoard, Inc.
|
|||
// SPDX-License-Identifier: BUSL-1.1
|
|||
export const generatedStateImages: string[] = [ |
|||
'/assets/solution-creator/building-animated.webp', |
|||
'/assets/solution-creator/catch-animated.webp', |
|||
'/assets/solution-creator/dashboard-animated.webp', |
|||
'/assets/solution-creator/forest-animated.webp', |
|||
'/assets/solution-creator/parachute-animated.webp', |
|||
'/assets/solution-creator/rocket-animated.webp' |
|||
]; |
|||
|
|||
export const dashboardGenerateImage = '/assets/solution-creator/dashboard-animated.webp'; |
|||
|
|||
export const generateDashboardSteps = [ |
|||
{ text: 'solution-creator.step-reading-device-data', delay: 0 }, |
|||
{ text: 'solution-creator.step-analyzing-telemetry-attributes', delay: 2000 }, |
|||
{ text: 'solution-creator.step-selecting-widgets', delay: 10000 }, |
|||
{ text: 'solution-creator.step-configuring-titles-units-ranges', delay: 15000 }, |
|||
{ text: 'solution-creator.step-designing-layout', delay: 25000 }, |
|||
{ text: 'solution-creator.step-arranging-widgets', delay: 35000 }, |
|||
{ text: 'solution-creator.step-loading-adding-finishing-touches', delay: 45000 }, |
|||
] |
|||
|
Before Width: | Height: | Size: 971 KiB |
|
Before Width: | Height: | Size: 777 KiB |
|
Before Width: | Height: | Size: 1.1 MiB |
|
Before Width: | Height: | Size: 2.2 MiB |
|
Before Width: | Height: | Size: 2.3 MiB |
|
Before Width: | Height: | Size: 2.6 MiB |
Loading…
Reference in new issue