Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[QR-code] - Widget redirects to Mobile app #10591

Merged
merged 25 commits into from
May 17, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
d0ff4a2
mobile app QR code initial implementation
dashevchenko Apr 18, 2024
67ba644
moved all apis to one controller
dashevchenko Apr 24, 2024
b216898
updated default mobile app settings, fixed permission
dashevchenko Apr 24, 2024
dc5f592
added mobile app settings cleanup for tenant deletion
dashevchenko Apr 25, 2024
0003caf
added id, createdTime to mobile app setting entity, added MobileAppSe…
dashevchenko Apr 30, 2024
3e0fad4
merged with master
dashevchenko Apr 30, 2024
f934863
fixed api test
dashevchenko May 2, 2024
949eb67
merged with master
dashevchenko May 2, 2024
0bf5290
code formatting
dashevchenko May 2, 2024
a057f42
UI: mobile app QR code UI initial implementation
rusikv May 2, 2024
4ee969f
fixed mobile application validator
dashevchenko May 5, 2024
953c215
UI: added separate mobile qrcode widget to cards bundle
rusikv May 7, 2024
012457e
Add mobileQrEnabled to system params
ViacheslavKlimov May 7, 2024
0d7d9b4
Refactoring for mobile settings api
ViacheslavKlimov May 7, 2024
d163b56
UI: mobile qrcode improvements
rusikv May 7, 2024
034ed62
Merge branch 'qrCode' of github.com:dashevchenko/thingsboard into qrCode
vvlladd28 May 7, 2024
2bbeb6a
UI: Added support mobileQrEnabled settings in tenant admin home page …
vvlladd28 May 7, 2024
0bc0422
UI: added mobile app qr code to sys admin home page
rusikv May 9, 2024
14ebfe7
UI: mobile app qrcode widgets update
rusikv May 9, 2024
2187246
UI: added preview images for mobile app qr code widgets
rusikv May 10, 2024
bb8be27
Merge remote-tracking branch 'upstream/master' into qrCode
rusikv May 10, 2024
ffbb2c7
UI: refactor mobile app qr code widgets validationm, cleanup widgets …
rusikv May 10, 2024
9d71bb7
UI: clean up sysadmin, tenant home pages jsons
rusikv May 10, 2024
45ed484
UI: mobile app qr code improvements, cleanup
rusikv May 15, 2024
a4e5b94
Update home-links-routing.module.ts
ikulikov May 17, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Prev Previous commit
Next Next commit
UI: added mobile app qr code to sys admin home page
  • Loading branch information
rusikv committed May 9, 2024
commit 0bc04222ba91302efce90c62b849ed6c83729770
2 changes: 1 addition & 1 deletion ui-ngx/src/app/core/services/utils.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import {
guid,
hashCode,
isDefined,
isDefinedAndNotNull, isNotEmptyStr,
isDefinedAndNotNull,
isString,
isUndefined,
objToBase64,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
color: rgba(0, 0, 0, 0.76);

@media #{$mat-md-lg} {
padding-bottom: 0;
font-weight: 500;
font-size: 14px;
line-height: 20px;
Expand All @@ -43,6 +44,11 @@
.tb-qrcode-label {
font-size: 14px;
color: rgba(0, 0, 0, 0.54);

@media #{$mat-md-lg} {
font-size: 11px;
line-height: 16px;
}
}

.tb-qrcode {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@ import { DashboardService } from '@core/http/dashboard.service';
import { select, Store } from '@ngrx/store';
import { AppState } from '@core/core.state';
import { map } from 'rxjs/operators';
import { getCurrentAuthUser, selectPersistDeviceStateToTelemetryAndMobileQrEnabled } from '@core/auth/auth.selectors';
import {
getCurrentAuthUser,
selectMobileQrEnabled,
selectPersistDeviceStateToTelemetryAndMobileQrEnabled
} from '@core/auth/auth.selectors';
import { EntityKeyType } from '@shared/models/query/query.models';
import { ResourcesService } from '@core/services/resources.service';

Expand All @@ -45,20 +49,32 @@ const updateDeviceActivityKeyFilterIfNeeded = (store: Store<AppState>,
}
}
}
if (params.mobileQrEnabled) {
for (const widgetId of Object.keys(dashboard.configuration.widgets)) {
if (dashboard.configuration.widgets[widgetId].config.title === 'Select show mobile QR code') {
dashboard.configuration.widgets[widgetId].config.settings.markdownTextFunction =
(dashboard.configuration.widgets[widgetId].config.settings.markdownTextFunction as string)
.replace('\'${mobileQrEnabled}\'', String(params.mobileQrEnabled));
}
}
}
return dashboard;
return params.mobileQrEnabled ? toggleMobileQRCodeDisplay(dashboard) : dashboard;
})
))
);

const toggleMobileQRCodeDisplayIfNeeded = (store: Store<AppState>,
dashboard$: Observable<HomeDashboard>): Observable<HomeDashboard> =>
store.pipe(select(selectMobileQrEnabled)).pipe(
mergeMap((mobileQrEnabled) => dashboard$.pipe(
map((dashboard) => {
return mobileQrEnabled ? toggleMobileQRCodeDisplay(dashboard) : dashboard;
})
))
);

const toggleMobileQRCodeDisplay = (dashboard: HomeDashboard) => {
for (const widgetId of Object.keys(dashboard.configuration.widgets)) {
if (dashboard.configuration.widgets[widgetId].config.title === 'Select show mobile QR code') {
dashboard.configuration.widgets[widgetId].config.settings.markdownTextFunction =
(dashboard.configuration.widgets[widgetId].config.settings.markdownTextFunction as string)
.replace('\'${mobileQrEnabled}\'', String(true));
}
}
return dashboard;
}

export const homeDashboardResolver: ResolveFn<HomeDashboard> = (
route: ActivatedRouteSnapshot,
state: RouterStateSnapshot,
Expand All @@ -73,7 +89,7 @@ export const homeDashboardResolver: ResolveFn<HomeDashboard> = (
const authority = getCurrentAuthUser(store).authority;
switch (authority) {
case Authority.SYS_ADMIN:
dashboard$ = resourcesService.loadJsonResource(sysAdminHomePageJson);
dashboard$ = toggleMobileQRCodeDisplayIfNeeded(store, resourcesService.loadJsonResource(sysAdminHomePageJson));
break;
case Authority.TENANT_ADMIN:
dashboard$ = updateDeviceActivityKeyFilterIfNeeded(store, resourcesService.loadJsonResource(tenantAdminHomePageJson));
Expand Down
229 changes: 189 additions & 40 deletions ui-ngx/src/assets/dashboard/sys_admin_home_page.json
Original file line number Diff line number Diff line change
Expand Up @@ -377,38 +377,6 @@
"id": "867f82cf-ecf2-2d5c-35cb-08c6f2edc3a4",
"typeFullFqn": "system.home_page_widgets.documentation_links"
},
"a23185ad-dc46-806c-0e50-5b21fb080ace": {
"type": "static",
"sizeX": 7.5,
"sizeY": 6.5,
"config": {
"datasources": [],
"timewindow": {
"realtime": {
"timewindowMs": 60000
}
},
"showTitle": false,
"backgroundColor": "rgb(255, 255, 255)",
"color": "rgba(0, 0, 0, 0.87)",
"padding": "16px",
"settings": {
"columns": 3
},
"title": "Getting started",
"dropShadow": false,
"enableFullscreen": false,
"widgetStyle": {},
"widgetCss": "",
"pageSize": 1024,
"noDataDisplayMessage": "",
"showLegend": false
},
"row": 0,
"col": 0,
"id": "a23185ad-dc46-806c-0e50-5b21fb080ace",
"typeFullFqn": "system.home_page_widgets.getting_started"
},
"b35fa1b0-7f95-0b23-fade-d066653a40e1": {
"type": "latest",
"sizeX": 5,
Expand Down Expand Up @@ -2640,6 +2608,152 @@
"row": 0,
"col": 0,
"id": "b9174a99-2a00-3dbe-0eae-927fd8506345"
},
"c02d59a0-c979-5ec6-7f58-a5d89ff66236": {
"type": "static",
"sizeX": 7.5,
"sizeY": 6.5,
"config": {
"datasources": [],
"timewindow": {
"realtime": {
"timewindowMs": 60000
}
},
"showTitle": false,
"backgroundColor": "rgb(255, 255, 255)",
"color": "rgba(0, 0, 0, 0.87)",
"padding": "16px",
"settings": {
"columns": 3
},
"title": "Getting started",
"dropShadow": false,
"enableFullscreen": false,
"widgetStyle": {},
"widgetCss": "",
"pageSize": 1024,
"noDataDisplayMessage": "",
"showLegend": false
},
"row": 0,
"col": 0,
"id": "c02d59a0-c979-5ec6-7f58-a5d89ff66236",
"typeFullFqn": "system.home_page_widgets.getting_started"
},
"53d5f2dd-d432-5362-745f-63bf4487dc96": {
"typeFullFqn": "system.home_page_widgets.home_page_mobile_app_qr_code",
"type": "static",
"sizeX": 6,
"sizeY": 3,
"config": {
"datasources": [
{
"type": "static",
"name": "function",
"dataKeys": [
{
"name": "f(x)",
"type": "function",
"label": "Random",
"color": "#2196f3",
"settings": {},
"_hash": 0.15479322438769105,
"funcBody": "var value = prevValue + Math.random() * 100 - 50;\nvar multiplier = Math.pow(10, 2 || 0);\nvar value = Math.round(value * multiplier) / multiplier;\nif (value < -1000) {\n\tvalue = -1000;\n} else if (value > 1000) {\n\tvalue = 1000;\n}\nreturn value;"
}
]
}
],
"timewindow": {
"realtime": {
"timewindowMs": 60000
}
},
"showTitle": false,
"backgroundColor": "rgb(255, 255, 255)",
"color": "rgba(0, 0, 0, 0.87)",
"padding": "8px",
"settings": {},
"title": "Mobile app QR code",
"dropShadow": false,
"enableFullscreen": false,
"widgetStyle": {},
"widgetCss": "",
"pageSize": 1024,
"noDataDisplayMessage": ""
},
"row": 0,
"col": 0,
"id": "53d5f2dd-d432-5362-745f-63bf4487dc96"
},
"0d34fa85-914f-30de-e3dd-7b7879f8d593": {
"typeFullFqn": "system.cards.markdown_card",
"type": "latest",
"sizeX": 5,
"sizeY": 3.5,
"config": {
"datasources": [],
"timewindow": {
"displayValue": "",
"selectedTab": 0,
"realtime": {
"realtimeType": 1,
"interval": 1000,
"timewindowMs": 60000,
"quickInterval": "CURRENT_DAY"
},
"history": {
"historyType": 0,
"interval": 1000,
"timewindowMs": 60000,
"fixedTimewindow": {
"startTimeMs": 1715012840937,
"endTimeMs": 1715099240937
},
"quickInterval": "CURRENT_DAY"
},
"aggregation": {
"type": "AVG",
"limit": 25000
}
},
"showTitle": false,
"backgroundColor": "#fff",
"color": "rgba(0, 0, 0, 0.87)",
"padding": "0px",
"settings": {
"useMarkdownTextFunction": true,
"markdownTextPattern": "### Markdown/HTML card\n - **Current entity**: ${entityName}.\n - **Current value**: ${Random}.",
"markdownTextFunction": "let html = '<div style=\"width: 100%; height: 100%;\">';\nlet supportMobile = '${mobileQrEnabled}' || false;\nif (supportMobile && typeof supportMobile === 'boolean') {\n ctx.dashboardWidget.widgetLayout.mobileHide = false;\n html += '<tb-dashboard-state stateId=\"mobile_app_qr_code\" [ctx]=\"ctx\"></tb-dashboard-state>';\n} else {\n ctx.dashboardWidget.widgetLayout.mobileHide = true;\n html += '<tb-getting-started-widget style=\"padding: 16px;\"></tb-getting-started-widget>';\n}\nhtml += '</div>';\nreturn html;",
"applyDefaultMarkdownStyle": false,
"markdownCss": ""
},
"title": "Select show mobile QR code",
"showTitleIcon": false,
"iconColor": "rgba(0, 0, 0, 0.87)",
"iconSize": "24px",
"titleTooltip": "",
"dropShadow": true,
"enableFullscreen": false,
"widgetStyle": {
"border": "none",
"boxShadow": "none",
"padding": 0
},
"titleStyle": {
"fontSize": "16px",
"fontWeight": 400
},
"showLegend": false,
"useDashboardTimewindow": true,
"displayTimewindow": true,
"widgetCss": "",
"pageSize": 1024,
"noDataDisplayMessage": ""
},
"row": 0,
"col": 0,
"id": "0d34fa85-914f-30de-e3dd-7b7879f8d593"
}
},
"states": {
Expand Down Expand Up @@ -2695,20 +2809,21 @@
"col": 0,
"mobileHide": true
},
"a23185ad-dc46-806c-0e50-5b21fb080ace": {
"sizeX": 35,
"sizeY": 58,
"row": 0,
"col": 85,
"mobileHide": true
},
"163025d8-3ca4-dd1e-c17b-e40d8e03e8a8": {
"sizeX": 44,
"sizeY": 15,
"mobileOrder": 0,
"mobileHeight": 7,
"row": 0,
"col": 0
},
"0d34fa85-914f-30de-e3dd-7b7879f8d593": {
"sizeX": 35,
"sizeY": 58,
"row": 0,
"col": 85,
"mobileHide": false,
"mobileHeight": 7
}
},
"gridSettings": {
Expand Down Expand Up @@ -2936,6 +3051,40 @@
}
}
}
},
"mobile_app_qr_code": {
"name": "Mobile App QR code",
"root": false,
"layouts": {
"main": {
"widgets": {
"c02d59a0-c979-5ec6-7f58-a5d89ff66236": {
"sizeX": 120,
"sizeY": 45,
"row": 0,
"col": 0,
"mobileHide": true
},
"53d5f2dd-d432-5362-745f-63bf4487dc96": {
"sizeX": 120,
"sizeY": 17,
"row": 45,
"col": 0
}
},
"gridSettings": {
"backgroundColor": "#eeeeee",
"columns": 120,
"margin": 12,
"outerMargin": false,
"backgroundSizeMode": "100%",
"autoFillHeight": true,
"backgroundImageUrl": null,
"mobileAutoFillHeight": false,
"mobileRowHeight": 20
}
}
}
}
},
"entityAliases": {
Expand Down Expand Up @@ -3051,4 +3200,4 @@
}
},
"name": "System Administrator Home Page"
}
}