Add dashboard state widget. Improve dashboard state component configuration. Fix markdown widget rendering when no datasource specified.

This commit is contained in:
Igor Kulikov 2022-01-14 13:01:32 +02:00
parent 1df1531723
commit 01cb2e1282
6 changed files with 92 additions and 16 deletions

File diff suppressed because one or more lines are too long

View File

@ -15,7 +15,7 @@
limitations under the License. limitations under the License.
--> -->
<tb-dashboard-page <tb-dashboard-page *ngIf="stateExists"
[embedded]="true" [embedded]="true"
[syncStateWithQueryParam]="false" [syncStateWithQueryParam]="false"
[hideToolbar]="true" [hideToolbar]="true"
@ -23,3 +23,6 @@
[dashboard]="dashboard" [dashboard]="dashboard"
[parentDashboard]="parentDashboard"> [parentDashboard]="parentDashboard">
</tb-dashboard-page> </tb-dashboard-page>
<div class="tb-absolute-fill tb-widget-error" *ngIf="!stateExists">
<span>{{ 'dashboard.non-existent-dashboard-state-error' | translate:{stateId} }}</span>
</div>

View File

@ -0,0 +1,22 @@
/**
* Copyright © 2016-2021 The Thingsboard Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
:host {
position: relative;
display: block;
width: 100%;
height: 100%;
}

View File

@ -14,14 +14,14 @@
/// limitations under the License. /// limitations under the License.
/// ///
import { ChangeDetectorRef, Component, Input, OnDestroy, OnInit } from '@angular/core'; import { ChangeDetectorRef, Component, HostBinding, Input, OnDestroy, OnInit } from '@angular/core';
import { PageComponent } from '@shared/components/page.component'; import { PageComponent } from '@shared/components/page.component';
import { Store } from '@ngrx/store'; import { Store } from '@ngrx/store';
import { AppState } from '@core/core.state'; import { AppState } from '@core/core.state';
import { Dashboard } from '@shared/models/dashboard.models'; import { Dashboard, DashboardLayoutId } from '@shared/models/dashboard.models';
import { StateObject } from '@core/api/widget-api.models'; import { StateObject } from '@core/api/widget-api.models';
import { updateEntityParams, WidgetContext } from '@home/models/widget-component.models'; import { updateEntityParams, WidgetContext } from '@home/models/widget-component.models';
import { deepClone, objToBase64 } from '@core/utils'; import { deepClone, isDefinedAndNotNull, isNotEmptyStr, objToBase64 } from '@core/utils';
import { IDashboardComponent } from '@home/models/dashboard-component.models'; import { IDashboardComponent } from '@home/models/dashboard-component.models';
import { EntityId } from '@shared/models/id/entity-id'; import { EntityId } from '@shared/models/id/entity-id';
import { Subscription } from 'rxjs'; import { Subscription } from 'rxjs';
@ -29,7 +29,7 @@ import { Subscription } from 'rxjs';
@Component({ @Component({
selector: 'tb-dashboard-state', selector: 'tb-dashboard-state',
templateUrl: './dashboard-state.component.html', templateUrl: './dashboard-state.component.html',
styleUrls: [] styleUrls: ['./dashboard-state.component.scss']
}) })
export class DashboardStateComponent extends PageComponent implements OnInit, OnDestroy { export class DashboardStateComponent extends PageComponent implements OnInit, OnDestroy {
@ -42,6 +42,15 @@ export class DashboardStateComponent extends PageComponent implements OnInit, On
@Input() @Input()
syncParentStateParams = false; syncParentStateParams = false;
@Input()
defaultAutofillLayout = true;
@Input()
defaultMargin;
@Input()
defaultBackgroundColor;
@Input() @Input()
entityParamName: string; entityParamName: string;
@ -54,6 +63,8 @@ export class DashboardStateComponent extends PageComponent implements OnInit, On
parentDashboard: IDashboardComponent; parentDashboard: IDashboardComponent;
stateExists = true;
private stateSubscription: Subscription; private stateSubscription: Subscription;
constructor(protected store: Store<AppState>, constructor(protected store: Store<AppState>,
@ -63,14 +74,31 @@ export class DashboardStateComponent extends PageComponent implements OnInit, On
ngOnInit(): void { ngOnInit(): void {
this.dashboard = deepClone(this.ctx.stateController.dashboardCtrl.dashboardCtx.getDashboard()); this.dashboard = deepClone(this.ctx.stateController.dashboardCtrl.dashboardCtx.getDashboard());
this.updateCurrentState(); const state = this.dashboard.configuration.states[this.stateId];
this.parentDashboard = this.ctx.parentDashboard ? if (state) {
this.ctx.parentDashboard : this.ctx.dashboard; for (const layoutId of Object.keys(state.layouts)) {
if (this.syncParentStateParams) { if (this.defaultAutofillLayout) {
this.stateSubscription = this.ctx.stateController.dashboardCtrl.dashboardCtx.stateChanged.subscribe(() => { state.layouts[layoutId as DashboardLayoutId].gridSettings.autoFillHeight = true;
this.updateCurrentState(); state.layouts[layoutId as DashboardLayoutId].gridSettings.mobileAutoFillHeight = true;
this.cd.markForCheck(); }
}); if (isDefinedAndNotNull(this.defaultMargin)) {
state.layouts[layoutId as DashboardLayoutId].gridSettings.margin = this.defaultMargin;
}
if (isNotEmptyStr(this.defaultBackgroundColor)) {
state.layouts[layoutId as DashboardLayoutId].gridSettings.backgroundColor = this.defaultBackgroundColor;
}
}
this.updateCurrentState();
this.parentDashboard = this.ctx.parentDashboard ?
this.ctx.parentDashboard : this.ctx.dashboard;
if (this.syncParentStateParams) {
this.stateSubscription = this.ctx.stateController.dashboardCtrl.dashboardCtx.stateChanged.subscribe(() => {
this.updateCurrentState();
this.cd.markForCheck();
});
}
} else {
this.stateExists = false;
} }
} }

View File

@ -88,7 +88,11 @@ export class MarkdownWidgetComponent extends PageComponent implements OnInit {
textSearch: null, textSearch: null,
dynamic: true dynamic: true
}; };
this.ctx.defaultSubscription.subscribeAllForPaginatedData(pageLink, null); if (this.ctx.widgetConfig.datasources.length) {
this.ctx.defaultSubscription.subscribeAllForPaginatedData(pageLink, null);
} else {
this.onDataUpdated();
}
} }
public onDataUpdated() { public onDataUpdated() {

View File

@ -867,7 +867,8 @@
"unassign-dashboards-from-edge-title": "Are you sure you want to unassign { count, plural, 1 {1 dashboard} other {# dashboards} }?", "unassign-dashboards-from-edge-title": "Are you sure you want to unassign { count, plural, 1 {1 dashboard} other {# dashboards} }?",
"unassign-dashboards-from-edge-text": "After the confirmation all selected dashboards will be unassigned and won't be accessible by the edge.", "unassign-dashboards-from-edge-text": "After the confirmation all selected dashboards will be unassigned and won't be accessible by the edge.",
"assign-dashboard-to-edge": "Assign Dashboard(s) To Edge", "assign-dashboard-to-edge": "Assign Dashboard(s) To Edge",
"assign-dashboard-to-edge-text": "Please select the dashboards to assign to the edge" "assign-dashboard-to-edge-text": "Please select the dashboards to assign to the edge",
"non-existent-dashboard-state-error": "Dashboard state with id \"{{ stateId }}\" is not found"
}, },
"datakey": { "datakey": {
"settings": "Settings", "settings": "Settings",