From 1f63c056a3207511216b2dde5c44e77d76afcdc5 Mon Sep 17 00:00:00 2001 From: ShvaykaD Date: Thu, 15 Jul 2021 10:55:37 +0300 Subject: [PATCH 01/33] improved tests for proto fields explicit presence validation --- .../AbstractCoapAttributesIntegrationTest.java | 9 --------- .../AbstractCoapAttributesProtoIntegrationTest.java | 5 +---- .../AbstractCoapTimeseriesProtoIntegrationTest.java | 3 +-- .../AbstractMqttAttributesIntegrationTest.java | 9 --------- .../AbstractMqttAttributesProtoIntegrationTest.java | 5 +---- .../AbstractMqttTimeseriesProtoIntegrationTest.java | 3 +-- 6 files changed, 4 insertions(+), 30 deletions(-) diff --git a/application/src/test/java/org/thingsboard/server/transport/coap/telemetry/attributes/AbstractCoapAttributesIntegrationTest.java b/application/src/test/java/org/thingsboard/server/transport/coap/telemetry/attributes/AbstractCoapAttributesIntegrationTest.java index 40b69995b7..aac8933af0 100644 --- a/application/src/test/java/org/thingsboard/server/transport/coap/telemetry/attributes/AbstractCoapAttributesIntegrationTest.java +++ b/application/src/test/java/org/thingsboard/server/transport/coap/telemetry/attributes/AbstractCoapAttributesIntegrationTest.java @@ -154,15 +154,6 @@ public abstract class AbstractCoapAttributesIntegrationTest extends AbstractCoap case "key1": assertEquals("", value); break; - case "key2": - assertEquals(false, value); - break; - case "key3": - assertEquals(0.0, value); - break; - case "key4": - assertEquals(0, value); - break; case "key5": assertNotNull(value); assertEquals(2, ((LinkedHashMap) value).size()); diff --git a/application/src/test/java/org/thingsboard/server/transport/coap/telemetry/attributes/AbstractCoapAttributesProtoIntegrationTest.java b/application/src/test/java/org/thingsboard/server/transport/coap/telemetry/attributes/AbstractCoapAttributesProtoIntegrationTest.java index 1937bf769c..b3e9ea4ef6 100644 --- a/application/src/test/java/org/thingsboard/server/transport/coap/telemetry/attributes/AbstractCoapAttributesProtoIntegrationTest.java +++ b/application/src/test/java/org/thingsboard/server/transport/coap/telemetry/attributes/AbstractCoapAttributesProtoIntegrationTest.java @@ -123,12 +123,9 @@ public abstract class AbstractCoapAttributesProtoIntegrationTest extends Abstrac assertNotNull(postAttributesMsgDescriptor); DynamicMessage postAttributesMsg = postAttributesBuilder .setField(postAttributesMsgDescriptor.findFieldByName("key1"), "") - .setField(postAttributesMsgDescriptor.findFieldByName("key2"), false) - .setField(postAttributesMsgDescriptor.findFieldByName("key3"), 0.0) - .setField(postAttributesMsgDescriptor.findFieldByName("key4"), 0) .setField(postAttributesMsgDescriptor.findFieldByName("key5"), jsonObject) .build(); - processAttributesTest(Arrays.asList("key1", "key2", "key3", "key4", "key5"), postAttributesMsg.toByteArray(), true); + processAttributesTest(Arrays.asList("key1", "key5"), postAttributesMsg.toByteArray(), true); } } diff --git a/application/src/test/java/org/thingsboard/server/transport/coap/telemetry/timeseries/AbstractCoapTimeseriesProtoIntegrationTest.java b/application/src/test/java/org/thingsboard/server/transport/coap/telemetry/timeseries/AbstractCoapTimeseriesProtoIntegrationTest.java index 8e045de317..699ba1e24d 100644 --- a/application/src/test/java/org/thingsboard/server/transport/coap/telemetry/timeseries/AbstractCoapTimeseriesProtoIntegrationTest.java +++ b/application/src/test/java/org/thingsboard/server/transport/coap/telemetry/timeseries/AbstractCoapTimeseriesProtoIntegrationTest.java @@ -207,10 +207,9 @@ public abstract class AbstractCoapTimeseriesProtoIntegrationTest extends Abstrac .setField(postTelemetryMsgDescriptor.findFieldByName("key1"), "") .setField(postTelemetryMsgDescriptor.findFieldByName("key2"), false) .setField(postTelemetryMsgDescriptor.findFieldByName("key3"), 0.0) - .setField(postTelemetryMsgDescriptor.findFieldByName("key4"), 0) .setField(postTelemetryMsgDescriptor.findFieldByName("key5"), jsonObject) .build(); - processTestPostTelemetry(postTelemetryMsg.toByteArray(), Arrays.asList("key1", "key2", "key3", "key4", "key5"), false, true); + processTestPostTelemetry(postTelemetryMsg.toByteArray(), Arrays.asList("key1", "key2", "key3", "key5"), false, true); } @Test diff --git a/application/src/test/java/org/thingsboard/server/transport/mqtt/telemetry/attributes/AbstractMqttAttributesIntegrationTest.java b/application/src/test/java/org/thingsboard/server/transport/mqtt/telemetry/attributes/AbstractMqttAttributesIntegrationTest.java index ef06c28cbd..2ad4377f5b 100644 --- a/application/src/test/java/org/thingsboard/server/transport/mqtt/telemetry/attributes/AbstractMqttAttributesIntegrationTest.java +++ b/application/src/test/java/org/thingsboard/server/transport/mqtt/telemetry/attributes/AbstractMqttAttributesIntegrationTest.java @@ -192,15 +192,6 @@ public abstract class AbstractMqttAttributesIntegrationTest extends AbstractMqtt case "key1": assertEquals("", value); break; - case "key2": - assertEquals(false, value); - break; - case "key3": - assertEquals(0.0, value); - break; - case "key4": - assertEquals(0, value); - break; case "key5": assertNotNull(value); assertEquals(2, ((LinkedHashMap) value).size()); diff --git a/application/src/test/java/org/thingsboard/server/transport/mqtt/telemetry/attributes/AbstractMqttAttributesProtoIntegrationTest.java b/application/src/test/java/org/thingsboard/server/transport/mqtt/telemetry/attributes/AbstractMqttAttributesProtoIntegrationTest.java index 25bf0b6b70..c77691981e 100644 --- a/application/src/test/java/org/thingsboard/server/transport/mqtt/telemetry/attributes/AbstractMqttAttributesProtoIntegrationTest.java +++ b/application/src/test/java/org/thingsboard/server/transport/mqtt/telemetry/attributes/AbstractMqttAttributesProtoIntegrationTest.java @@ -119,12 +119,9 @@ public abstract class AbstractMqttAttributesProtoIntegrationTest extends Abstrac assertNotNull(postAttributesMsgDescriptor); DynamicMessage postAttributesMsg = postAttributesBuilder .setField(postAttributesMsgDescriptor.findFieldByName("key1"), "") - .setField(postAttributesMsgDescriptor.findFieldByName("key2"), false) - .setField(postAttributesMsgDescriptor.findFieldByName("key3"), 0.0) - .setField(postAttributesMsgDescriptor.findFieldByName("key4"), 0) .setField(postAttributesMsgDescriptor.findFieldByName("key5"), jsonObject) .build(); - processAttributesTest(POST_DATA_ATTRIBUTES_TOPIC, Arrays.asList("key1", "key2", "key3", "key4", "key5"), postAttributesMsg.toByteArray(), true); + processAttributesTest(POST_DATA_ATTRIBUTES_TOPIC, Arrays.asList("key1", "key5"), postAttributesMsg.toByteArray(), true); } @Test diff --git a/application/src/test/java/org/thingsboard/server/transport/mqtt/telemetry/timeseries/AbstractMqttTimeseriesProtoIntegrationTest.java b/application/src/test/java/org/thingsboard/server/transport/mqtt/telemetry/timeseries/AbstractMqttTimeseriesProtoIntegrationTest.java index 2d9e041eb1..9b0fa5dd33 100644 --- a/application/src/test/java/org/thingsboard/server/transport/mqtt/telemetry/timeseries/AbstractMqttTimeseriesProtoIntegrationTest.java +++ b/application/src/test/java/org/thingsboard/server/transport/mqtt/telemetry/timeseries/AbstractMqttTimeseriesProtoIntegrationTest.java @@ -204,10 +204,9 @@ public abstract class AbstractMqttTimeseriesProtoIntegrationTest extends Abstrac .setField(postTelemetryMsgDescriptor.findFieldByName("key1"), "") .setField(postTelemetryMsgDescriptor.findFieldByName("key2"), false) .setField(postTelemetryMsgDescriptor.findFieldByName("key3"), 0.0) - .setField(postTelemetryMsgDescriptor.findFieldByName("key4"), 0) .setField(postTelemetryMsgDescriptor.findFieldByName("key5"), jsonObject) .build(); - processTelemetryTest(POST_DATA_TELEMETRY_TOPIC, Arrays.asList("key1", "key2", "key3", "key4", "key5"), postTelemetryMsg.toByteArray(), false, true); + processTelemetryTest(POST_DATA_TELEMETRY_TOPIC, Arrays.asList("key1", "key2", "key3", "key5"), postTelemetryMsg.toByteArray(), false, true); } @Test From 40252c99b1f330696903a15ab1aae5ee661e1103 Mon Sep 17 00:00:00 2001 From: Chantsova Ekaterina Date: Thu, 22 Jul 2021 15:39:57 +0300 Subject: [PATCH 02/33] UI: add custom interval option to charts comparison --- ui-ngx/src/app/core/api/widget-api.models.ts | 1 + ui-ngx/src/app/core/api/widget-subscription.ts | 5 ++++- .../components/widget/lib/flot-widget.models.ts | 14 ++++++++++++++ .../home/components/widget/widget.component.ts | 3 ++- ui-ngx/src/app/shared/models/time/time.models.ts | 15 ++++++++++++--- ui-ngx/src/app/shared/models/widget.models.ts | 1 + .../src/assets/locale/locale.constant-en_US.json | 1 + 7 files changed, 35 insertions(+), 5 deletions(-) diff --git a/ui-ngx/src/app/core/api/widget-api.models.ts b/ui-ngx/src/app/core/api/widget-api.models.ts index d473296a4c..d17d065de7 100644 --- a/ui-ngx/src/app/core/api/widget-api.models.ts +++ b/ui-ngx/src/app/core/api/widget-api.models.ts @@ -238,6 +238,7 @@ export interface WidgetSubscriptionOptions { legendConfig?: LegendConfig; comparisonEnabled?: boolean; timeForComparison?: moment_.unitOfTime.DurationConstructor; + comparisonCustomIntervalValue?: number; decimals?: number; units?: string; callbacks?: WidgetSubscriptionCallbacks; diff --git a/ui-ngx/src/app/core/api/widget-subscription.ts b/ui-ngx/src/app/core/api/widget-subscription.ts index 32f0f90005..4e6c5f3738 100644 --- a/ui-ngx/src/app/core/api/widget-subscription.ts +++ b/ui-ngx/src/app/core/api/widget-subscription.ts @@ -109,6 +109,7 @@ export class WidgetSubscription implements IWidgetSubscription { units: string; comparisonEnabled: boolean; timeForComparison: ComparisonDuration; + comparisonCustomIntervalValue: number; comparisonTimeWindow: WidgetTimewindow; timewindowForComparison: SubscriptionTimewindow; @@ -233,6 +234,7 @@ export class WidgetSubscription implements IWidgetSubscription { this.comparisonEnabled = options.comparisonEnabled && isHistoryTypeTimewindow(this.timeWindowConfig); if (this.comparisonEnabled) { this.timeForComparison = options.timeForComparison; + this.comparisonCustomIntervalValue = options.comparisonCustomIntervalValue; this.comparisonTimeWindow = {}; this.timewindowForComparison = null; @@ -1154,7 +1156,8 @@ export class WidgetSubscription implements IWidgetSubscription { } private updateSubscriptionForComparison(): SubscriptionTimewindow { - this.timewindowForComparison = createTimewindowForComparison(this.subscriptionTimewindow, this.timeForComparison); + this.timewindowForComparison = createTimewindowForComparison(this.subscriptionTimewindow, this.timeForComparison, + this.comparisonCustomIntervalValue); this.updateComparisonTimewindow(); return this.timewindowForComparison; } diff --git a/ui-ngx/src/app/modules/home/components/widget/lib/flot-widget.models.ts b/ui-ngx/src/app/modules/home/components/widget/lib/flot-widget.models.ts index 836897740a..6186db3fe1 100644 --- a/ui-ngx/src/app/modules/home/components/widget/lib/flot-widget.models.ts +++ b/ui-ngx/src/app/modules/home/components/widget/lib/flot-widget.models.ts @@ -145,6 +145,7 @@ export interface TbFlotComparisonSettings { comparisonEnabled: boolean; timeForComparison: ComparisonDuration; xaxisSecond: TbFlotSecondXAxisSettings; + comparisonCustomIntervalValue?: number; } export interface TbFlotThresholdsSettings { @@ -546,6 +547,11 @@ const chartSettingsSchemaForComparison: JsonSettingsSchema = { type: 'string', default: 'previousInterval' }, + comparisonCustomIntervalValue: { + title: 'Custom interval value (ms)', + type: 'number', + default: 7200000 + }, xaxisSecond: { title: 'Second X axis', type: 'object', @@ -596,9 +602,17 @@ const chartSettingsSchemaForComparison: JsonSettingsSchema = { { value: 'years', label: 'Year ago' + }, + { + value: 'customInterval', + label: 'Custom interval' } ] }, + { + key: 'comparisonCustomIntervalValue', + condition: 'model.timeForComparison === "customInterval"' + }, { key: 'xaxisSecond', items: [ diff --git a/ui-ngx/src/app/modules/home/components/widget/widget.component.ts b/ui-ngx/src/app/modules/home/components/widget/widget.component.ts index dee17a000c..81ac4037bf 100644 --- a/ui-ngx/src/app/modules/home/components/widget/widget.component.ts +++ b/ui-ngx/src/app/modules/home/components/widget/widget.component.ts @@ -907,7 +907,8 @@ export class WidgetComponent extends PageComponent implements OnInit, AfterViewI warnOnPageDataOverflow: this.typeParameters.warnOnPageDataOverflow, ignoreDataUpdateOnIntervalTick: this.typeParameters.ignoreDataUpdateOnIntervalTick, comparisonEnabled: comparisonSettings.comparisonEnabled, - timeForComparison: comparisonSettings.timeForComparison + timeForComparison: comparisonSettings.timeForComparison, + comparisonCustomIntervalValue: comparisonSettings.comparisonCustomIntervalValue }; if (this.widget.type === widgetType.alarm) { options.alarmSource = deepClone(this.widget.config.alarmSource); diff --git a/ui-ngx/src/app/shared/models/time/time.models.ts b/ui-ngx/src/app/shared/models/time/time.models.ts index c9520f09df..96a8ec720b 100644 --- a/ui-ngx/src/app/shared/models/time/time.models.ts +++ b/ui-ngx/src/app/shared/models/time/time.models.ts @@ -15,7 +15,7 @@ /// import { TimeService } from '@core/services/time.service'; -import { deepClone, isDefined, isUndefined } from '@app/core/utils'; +import { deepClone, isDefined, isNumeric, isUndefined } from '@app/core/utils'; import * as moment_ from 'moment'; import * as momentTz from 'moment-timezone'; @@ -28,7 +28,7 @@ export const DAY = 24 * HOUR; export const WEEK = 7 * DAY; export const YEAR = DAY * 365; -export type ComparisonDuration = moment_.unitOfTime.DurationConstructor | 'previousInterval'; +export type ComparisonDuration = moment_.unitOfTime.DurationConstructor | 'previousInterval' | 'customInterval'; export enum TimewindowType { REALTIME, @@ -640,7 +640,7 @@ export function calculateIntervalComparisonEndTime(interval: QuickTimeInterval, } export function createTimewindowForComparison(subscriptionTimewindow: SubscriptionTimewindow, - timeUnit: ComparisonDuration): SubscriptionTimewindow { + timeUnit: ComparisonDuration, customIntervalValue: number): SubscriptionTimewindow { const timewindowForComparison: SubscriptionTimewindow = { fixedWindow: null, realtimeWindowMs: null, @@ -667,6 +667,15 @@ export function createTimewindowForComparison(subscriptionTimewindow: Subscripti endTimeMs = subscriptionTimewindow.fixedWindow.startTimeMs; startTimeMs = endTimeMs - timeInterval; } + } else if (timeUnit === 'customInterval') { + if (isNumeric(customIntervalValue) && isFinite(customIntervalValue) && customIntervalValue > 0) { + const timeInterval = subscriptionTimewindow.fixedWindow.endTimeMs - subscriptionTimewindow.fixedWindow.startTimeMs; + endTimeMs = subscriptionTimewindow.fixedWindow.endTimeMs - Math.round(customIntervalValue); + startTimeMs = endTimeMs - timeInterval; + } else { + endTimeMs = subscriptionTimewindow.fixedWindow.endTimeMs; + startTimeMs = subscriptionTimewindow.fixedWindow.startTimeMs; + } } else { const timeInterval = subscriptionTimewindow.fixedWindow.endTimeMs - subscriptionTimewindow.fixedWindow.startTimeMs; endTimeMs = moment(subscriptionTimewindow.fixedWindow.endTimeMs).subtract(1, timeUnit).valueOf(); diff --git a/ui-ngx/src/app/shared/models/widget.models.ts b/ui-ngx/src/app/shared/models/widget.models.ts index edf0eb803a..378fc5f70e 100644 --- a/ui-ngx/src/app/shared/models/widget.models.ts +++ b/ui-ngx/src/app/shared/models/widget.models.ts @@ -467,6 +467,7 @@ export interface WidgetActionDescriptor extends CustomActionDescriptor { export interface WidgetComparisonSettings { comparisonEnabled?: boolean; timeForComparison?: moment_.unitOfTime.DurationConstructor; + comparisonCustomIntervalValue?: number; } export interface WidgetConfig { diff --git a/ui-ngx/src/assets/locale/locale.constant-en_US.json b/ui-ngx/src/assets/locale/locale.constant-en_US.json index 1c5bc2ed8e..8addfd4c72 100644 --- a/ui-ngx/src/assets/locale/locale.constant-en_US.json +++ b/ui-ngx/src/assets/locale/locale.constant-en_US.json @@ -2258,6 +2258,7 @@ "total": "total", "comparison-time-ago": { "previousInterval": "(previous interval)", + "customInterval": "(custom interval)", "days": "(day ago)", "weeks": "(week ago)", "months": "(month ago)", From 02061c8b27a4c8eb11dd9d076de4ddf554da3c62 Mon Sep 17 00:00:00 2001 From: rusikv Date: Fri, 6 Aug 2021 17:04:54 +0300 Subject: [PATCH 03/33] UI: add copy user id button in user details --- .../modules/home/pages/user/user.component.html | 11 +++++++++++ .../modules/home/pages/user/user.component.ts | 17 ++++++++++++++++- .../assets/locale/locale.constant-en_US.json | 4 +++- .../assets/locale/locale.constant-ru_RU.json | 4 +++- .../assets/locale/locale.constant-uk_UA.json | 4 +++- 5 files changed, 36 insertions(+), 4 deletions(-) diff --git a/ui-ngx/src/app/modules/home/pages/user/user.component.html b/ui-ngx/src/app/modules/home/pages/user/user.component.html index 63154139e3..0a9ca2079b 100644 --- a/ui-ngx/src/app/modules/home/pages/user/user.component.html +++ b/ui-ngx/src/app/modules/home/pages/user/user.component.html @@ -53,6 +53,17 @@ [fxShow]="!hideDelete() && !isEdit"> {{'user.delete' | translate }} +
+ +
diff --git a/ui-ngx/src/app/modules/home/pages/user/user.component.ts b/ui-ngx/src/app/modules/home/pages/user/user.component.ts index 7187731b5c..801126d3a5 100644 --- a/ui-ngx/src/app/modules/home/pages/user/user.component.ts +++ b/ui-ngx/src/app/modules/home/pages/user/user.component.ts @@ -25,6 +25,8 @@ import { map } from 'rxjs/operators'; import { Authority } from '@shared/models/authority.enum'; import { isDefinedAndNotNull, isUndefined } from '@core/utils'; import { EntityTableConfig } from '@home/models/entity/entities-table-config.models'; +import { ActionNotificationShow } from '@app/core/notification/notification.actions'; +import { TranslateService } from '@ngx-translate/core'; @Component({ selector: 'tb-user', @@ -44,7 +46,8 @@ export class UserComponent extends EntityComponent { @Optional() @Inject('entity') protected entityValue: User, @Optional() @Inject('entitiesTableConfig') protected entitiesTableConfigValue: EntityTableConfig, public fb: FormBuilder, - protected cd: ChangeDetectorRef) { + protected cd: ChangeDetectorRef, + protected translate: TranslateService) { super(store, fb, entityValue, entitiesTableConfigValue, cd); } @@ -100,4 +103,16 @@ export class UserComponent extends EntityComponent { isDefinedAndNotNull(entity.additionalInfo.homeDashboardHideToolbar) ? entity.additionalInfo.homeDashboardHideToolbar : true}}); } + onUserCopiedId($event) { + this.store.dispatch(new ActionNotificationShow( + { + message: this.translate.instant('user.idCopiedMessage'), + type: 'success', + duration: 750, + verticalPosition: 'bottom', + horizontalPosition: 'right' + } + )) + } + } diff --git a/ui-ngx/src/assets/locale/locale.constant-en_US.json b/ui-ngx/src/assets/locale/locale.constant-en_US.json index 8d1632a241..b7212ca68e 100644 --- a/ui-ngx/src/assets/locale/locale.constant-en_US.json +++ b/ui-ngx/src/assets/locale/locale.constant-en_US.json @@ -2809,7 +2809,9 @@ "disable-account": "Disable User Account", "enable-account": "Enable User Account", "enable-account-message": "User account was successfully enabled!", - "disable-account-message": "User account was successfully disabled!" + "disable-account-message": "User account was successfully disabled!", + "copyId": "Copy user Id", + "idCopiedMessage": "User Id has been copied to clipboard" }, "value": { "type": "Value type", diff --git a/ui-ngx/src/assets/locale/locale.constant-ru_RU.json b/ui-ngx/src/assets/locale/locale.constant-ru_RU.json index 9ba75064db..5916860fb0 100644 --- a/ui-ngx/src/assets/locale/locale.constant-ru_RU.json +++ b/ui-ngx/src/assets/locale/locale.constant-ru_RU.json @@ -1510,7 +1510,9 @@ "disable-account": "Отключить учетную запись пользователя", "enable-account": "Включить учетную запись пользователя", "enable-account-message": "Учетная запись пользователя была успешно включена!", - "disable-account-message": "Учетная запись пользователя была успешно отключена!" + "disable-account-message": "Учетная запись пользователя была успешно отключена!", + "copyId": "Копировать ИД пользователя", + "idCopiedMessage": "ИД пользователя скопирован в буфер обмена" }, "value": { "type": "Тип значения", diff --git a/ui-ngx/src/assets/locale/locale.constant-uk_UA.json b/ui-ngx/src/assets/locale/locale.constant-uk_UA.json index 23bb56cf29..20615d34e3 100644 --- a/ui-ngx/src/assets/locale/locale.constant-uk_UA.json +++ b/ui-ngx/src/assets/locale/locale.constant-uk_UA.json @@ -2078,7 +2078,9 @@ "disable-account": "Вимкнути обліковий запис користувача", "enable-account": "Увімкнути обліковий запис користувача", "enable-account-message": "Обліковий запис користувача успішно увімкнено!", - "disabled-account-message": "Обліковий запис користувача успішно вимкнено!" + "disabled-account-message": "Обліковий запис користувача успішно вимкнено!", + "copyId": "Копіювати Id користувача", + "idCopiedMessage": "Id користувача було скопійовано в буфер обміну" }, "value": { "type": "Тип значення", From 05d1c0f9b3caf82a826c9670b9958a3541133faf Mon Sep 17 00:00:00 2001 From: rusikv Date: Fri, 6 Aug 2021 18:56:26 +0300 Subject: [PATCH 04/33] UI: name function typo fix --- ui-ngx/src/app/modules/home/pages/user/user.component.html | 2 +- ui-ngx/src/app/modules/home/pages/user/user.component.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ui-ngx/src/app/modules/home/pages/user/user.component.html b/ui-ngx/src/app/modules/home/pages/user/user.component.html index 0a9ca2079b..424cdd8f05 100644 --- a/ui-ngx/src/app/modules/home/pages/user/user.component.html +++ b/ui-ngx/src/app/modules/home/pages/user/user.component.html @@ -56,7 +56,7 @@
+ { this.props.onTidy ? : null }
'; +} + +(window as any).markdownCopyCode = (id: number) => { + const text = $('#copyCodeId' + id).text(); + navigator.clipboard.writeText(text).then(() => { + import('tooltipster').then( + () => { + const copyBtn = $('#copyCodeBtn' + id); + if (!copyBtn.hasClass('tooltipstered')) { + copyBtn.tooltipster( + { + content: 'Copied!', + theme: 'tooltipster-shadow', + delay: 0, + trigger: 'custom', + triggerClose: { + click: true, + tap: true, + scroll: true, + mouseleave: true + }, + side: 'bottom', + distance: 12, + trackOrigin: true + } + ); + } + const tooltip = copyBtn.tooltipster('instance'); + tooltip.open(); + } + ); + }); +}; diff --git a/ui-ngx/src/app/shared/shared.module.ts b/ui-ngx/src/app/shared/shared.module.ts index 02c5824807..7ae1796c4f 100644 --- a/ui-ngx/src/app/shared/shared.module.ts +++ b/ui-ngx/src/app/shared/shared.module.ts @@ -14,7 +14,7 @@ /// limitations under the License. /// -import { NgModule } from '@angular/core'; +import { NgModule, SecurityContext } from '@angular/core'; import { CommonModule, DatePipe } from '@angular/common'; import { FooterComponent } from '@shared/components/footer.component'; import { LogoComponent } from '@shared/components/logo.component'; @@ -78,6 +78,7 @@ import { DatetimePeriodComponent } from '@shared/components/time/datetime-period import { EnumToArrayPipe } from '@shared/pipe/enum-to-array.pipe'; import { ClipboardModule } from 'ngx-clipboard'; import { ValueInputComponent } from '@shared/components/value-input.component'; +import { MarkdownModule, MarkedOptions } from 'ngx-markdown'; import { FullscreenDirective } from '@shared/components/fullscreen.directive'; import { HighlightPipe } from '@shared/pipe/highlight.pipe'; import { DashboardAutocompleteComponent } from '@shared/components/dashboard-autocomplete.component'; @@ -145,6 +146,7 @@ import { OtaPackageAutocompleteComponent } from '@shared/components/ota-package/ import { MAT_DATE_LOCALE } from '@angular/material/core'; import { CopyButtonComponent } from '@shared/components/button/copy-button.component'; import { TogglePasswordComponent } from '@shared/components/button/toggle-password.component'; +import { markedOptionsFactory } from '@shared/components/markdown.factory'; @NgModule({ providers: [ @@ -294,7 +296,15 @@ import { TogglePasswordComponent } from '@shared/components/button/toggle-passwo NgxHmCarouselModule, DndModule, NgxFlowModule, - NgxFlowchartModule + NgxFlowchartModule, + // ngx-markdown + MarkdownModule.forRoot({ + sanitize: SecurityContext.NONE, + markedOptions: { + provide: MarkedOptions, + useFactory: markedOptionsFactory + } + }) ], exports: [ FooterComponent, @@ -386,6 +396,7 @@ import { TogglePasswordComponent } from '@shared/components/button/toggle-passwo NgxHmCarouselModule, DndModule, NgxFlowchartModule, + MarkdownModule, ConfirmDialogComponent, AlertDialogComponent, TodoDialogComponent, diff --git a/ui-ngx/yarn.lock b/ui-ngx/yarn.lock index 3038f57bab..1436e3e77f 100644 --- a/ui-ngx/yarn.lock +++ b/ui-ngx/yarn.lock @@ -1817,6 +1817,11 @@ resolved "https://registry.yarnpkg.com/@types/lodash/-/lodash-4.14.170.tgz#0d67711d4bf7f4ca5147e9091b847479b87925d6" integrity sha512-bpcvu/MKHHeYX+qeEN8GE7DIravODWdACVA1ctevD8CN24RhPZIKMn9ntfAsrvLfSX3cR5RrBKAbYm9bGs0A+Q== +"@types/marked@^1.1.0": + version "1.2.2" + resolved "https://registry.yarnpkg.com/@types/marked/-/marked-1.2.2.tgz#1f858a0e690247ecf3b2eef576f98f86e8d960d4" + integrity sha512-wLfw1hnuuDYrFz97IzJja0pdVsC0oedtS4QsKH1/inyW9qkLQbXgMUqEQT0MVtUBx3twjWeInUfjQbhBVLECXw== + "@types/minimatch@*": version "3.0.3" resolved "https://registry.yarnpkg.com/@types/minimatch/-/minimatch-3.0.3.tgz#3dca0e3f33b200fc7d1139c0cd96c1268cadfd9d" @@ -4137,6 +4142,11 @@ emoji-regex@^8.0.0: resolved "https://registry.yarnpkg.com/emoji-regex/-/emoji-regex-8.0.0.tgz#e818fd69ce5ccfcb404594f842963bf53164cc37" integrity sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A== +emoji-toolkit@^6.0.1: + version "6.6.0" + resolved "https://registry.yarnpkg.com/emoji-toolkit/-/emoji-toolkit-6.6.0.tgz#e7287c43a96f940ec4c5428cd7100a40e57518f1" + integrity sha512-pEu0kow2p1N8zCKnn/L6H0F3rWUBB3P3hVjr/O5yl1fK7N9jU4vO4G7EFapC5Y3XwZLUCY0FZbOPyTkH+4V2eQ== + emojis-list@^3.0.0: version "3.0.0" resolved "https://registry.yarnpkg.com/emojis-list/-/emojis-list-3.0.0.tgz#5570662046ad29e2e916e71aae260abdff4f6a78" @@ -6126,6 +6136,13 @@ karma@~6.3.2: ua-parser-js "^0.7.23" yargs "^16.1.1" +katex@^0.12.0: + version "0.12.0" + resolved "https://registry.yarnpkg.com/katex/-/katex-0.12.0.tgz#2fb1c665dbd2b043edcf8a1f5c555f46beaa0cb9" + integrity sha512-y+8btoc/CK70XqcHqjxiGWBOeIL8upbS0peTPXTvgrh21n1RiWWcIpSWM+4uXq+IAgNh9YYQWdc7LVDPDAEEAg== + dependencies: + commander "^2.19.0" + killable@^1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/killable/-/killable-1.0.1.tgz#4c8ce441187a061c7474fb87ca08e2a638194892" @@ -6425,6 +6442,11 @@ map-visit@^1.0.0: dependencies: object-visit "^1.0.0" +marked@^1.1.0: + version "1.2.9" + resolved "https://registry.yarnpkg.com/marked/-/marked-1.2.9.tgz#53786f8b05d4c01a2a5a76b7d1ec9943d29d72dc" + integrity sha512-H8lIX2SvyitGX+TRdtS06m1jHMijKN/XjfH6Ooii9fvxMlh8QdqBfBDkGUpMWH2kQNrtixjzYUa3SH8ROTgRRw== + material-design-icons@^3.0.1: version "3.0.1" resolved "https://registry.yarnpkg.com/material-design-icons/-/material-design-icons-3.0.1.tgz#9a71c48747218ebca51e51a66da682038cdcb7bf" @@ -6877,6 +6899,18 @@ ngx-hm-carousel@^2.0.0-rc.1: hammerjs "^2.0.8" resize-observer-polyfill "^1.5.1" +ngx-markdown@^10.1.1: + version "10.1.1" + resolved "https://registry.yarnpkg.com/ngx-markdown/-/ngx-markdown-10.1.1.tgz#17840c773db7ced4b18ccbf2e8cb06182e422de3" + integrity sha512-bUVgN6asb35d5U4xM5CNfo7pSpuwqJSdTgK0PhNZzLiaiyPIK2owtLF6sWGhxTThJu+LngJPjj4MQ+AFe/s8XQ== + dependencies: + "@types/marked" "^1.1.0" + emoji-toolkit "^6.0.1" + katex "^0.12.0" + marked "^1.1.0" + prismjs "^1.20.0" + tslib "^2.0.0" + ngx-sharebuttons@^8.0.5: version "8.0.5" resolved "https://registry.yarnpkg.com/ngx-sharebuttons/-/ngx-sharebuttons-8.0.5.tgz#49481fcb8bf9541747fd72093eca6f4777c1d371" @@ -7877,6 +7911,11 @@ pretty-bytes@^5.3.0: resolved "https://registry.yarnpkg.com/pretty-bytes/-/pretty-bytes-5.6.0.tgz#356256f643804773c82f64723fe78c92c62beaeb" integrity sha512-FFw039TmrBqFK8ma/7OL3sDz/VytdtJr044/QUJtH0wK9lb9jLq9tJyIxUwtQJHwar2BqtiA4iCWSwo9JLkzFg== +prismjs@^1.20.0: + version "1.24.1" + resolved "https://registry.yarnpkg.com/prismjs/-/prismjs-1.24.1.tgz#c4d7895c4d6500289482fa8936d9cdd192684036" + integrity sha512-mNPsedLuk90RVJioIky8ANZEwYm5w9LcvCXrxHlwf4fNVSn8jEipMybMkWUyyF0JhnC+C4VcOVSBuHRKs1L5Ow== + prismjs@^1.23.0: version "1.23.0" resolved "https://registry.yarnpkg.com/prismjs/-/prismjs-1.23.0.tgz#d3b3967f7d72440690497652a9d40ff046067f33" From c04747cdd8149330bfd526d018d4cfe5621bb5f0 Mon Sep 17 00:00:00 2001 From: Igor Kulikov Date: Thu, 19 Aug 2021 19:31:48 +0300 Subject: [PATCH 24/33] Improve markdown widget css processing --- .../widget/lib/markdown-widget.component.html | 2 +- .../widget/lib/markdown-widget.component.ts | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/ui-ngx/src/app/modules/home/components/widget/lib/markdown-widget.component.html b/ui-ngx/src/app/modules/home/components/widget/lib/markdown-widget.component.html index df6c55762d..13b1428cb1 100644 --- a/ui-ngx/src/app/modules/home/components/widget/lib/markdown-widget.component.html +++ b/ui-ngx/src/app/modules/home/components/widget/lib/markdown-widget.component.html @@ -15,4 +15,4 @@ limitations under the License. --> - + diff --git a/ui-ngx/src/app/modules/home/components/widget/lib/markdown-widget.component.ts b/ui-ngx/src/app/modules/home/components/widget/lib/markdown-widget.component.ts index 111b74eed4..211ac17398 100644 --- a/ui-ngx/src/app/modules/home/components/widget/lib/markdown-widget.component.ts +++ b/ui-ngx/src/app/modules/home/components/widget/lib/markdown-widget.component.ts @@ -14,7 +14,7 @@ /// limitations under the License. /// -import { ChangeDetectorRef, Component, ElementRef, Input, OnInit } from '@angular/core'; +import { ChangeDetectorRef, Component, Input, OnInit } from '@angular/core'; import { PageComponent } from '@shared/components/page.component'; import { WidgetContext } from '@home/models/widget-component.models'; import { Store } from '@ngrx/store'; @@ -56,8 +56,9 @@ export class MarkdownWidgetComponent extends PageComponent implements OnInit { markdownText: string; + markdownClass: string; + constructor(protected store: Store, - private elementRef: ElementRef, private cd: ChangeDetectorRef) { super(store); } @@ -66,15 +67,14 @@ export class MarkdownWidgetComponent extends PageComponent implements OnInit { this.ctx.$scope.markdownWidget = this; this.settings = this.ctx.settings; this.markdownTextFunction = this.settings.useMarkdownTextFunction ? parseFunction(this.settings.markdownTextFunction, ['data']) : null; - + this.markdownClass = 'markdown-widget'; const cssString = this.settings.markdownCss; if (isNotEmptyStr(cssString)) { const cssParser = new cssjs(); cssParser.testMode = false; - const namespace = 'entities-hierarchy-' + hashCode(cssString); - cssParser.cssPreviewNamespace = namespace; - cssParser.createStyleElement(namespace, cssString); - $(this.elementRef.nativeElement).addClass(namespace); + this.markdownClass += '-' + hashCode(cssString); + cssParser.cssPreviewNamespace = 'tb-markdown-view.' + this.markdownClass; + cssParser.createStyleElement(this.markdownClass, cssString); } } From f6a2fdfd11334ed5cae7ef172ec070d809b02214 Mon Sep 17 00:00:00 2001 From: Igor Kulikov Date: Thu, 19 Aug 2021 19:34:10 +0300 Subject: [PATCH 25/33] Add upgrade to 3.3.1 --- .../thingsboard/server/install/ThingsboardInstallService.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/application/src/main/java/org/thingsboard/server/install/ThingsboardInstallService.java b/application/src/main/java/org/thingsboard/server/install/ThingsboardInstallService.java index b3f0d644c7..43cf213a16 100644 --- a/application/src/main/java/org/thingsboard/server/install/ThingsboardInstallService.java +++ b/application/src/main/java/org/thingsboard/server/install/ThingsboardInstallService.java @@ -200,7 +200,8 @@ public class ThingsboardInstallService { dataUpdateService.updateData("3.2.2"); systemDataLoaderService.createOAuth2Templates(); - + case "3.3.0": + log.info("Upgrading ThingsBoard from version 3.3.0 to 3.3.1 ..."); log.info("Updating system data..."); systemDataLoaderService.updateSystemWidgets(); break; From 2797367e41ab9a827e69b19aaa4c148a580ddff2 Mon Sep 17 00:00:00 2001 From: Igor Kulikov Date: Thu, 19 Aug 2021 19:49:51 +0300 Subject: [PATCH 26/33] Update docker pkg upgrade version --- msa/tb/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/msa/tb/pom.xml b/msa/tb/pom.xml index 7ad9d9f992..d9442e8d51 100644 --- a/msa/tb/pom.xml +++ b/msa/tb/pom.xml @@ -39,7 +39,7 @@ tb-postgres tb-cassandra /usr/share/${pkg.name} - 3.3.0 + 3.3.1 From 2f7a8c9534e981786a8fef2e1adaae1eb1dc2a22 Mon Sep 17 00:00:00 2001 From: Vladyslav_Prykhodko Date: Thu, 19 Aug 2021 16:23:43 +0300 Subject: [PATCH 27/33] UI: reduced minimum time for power mode settings --- .../profile/device/common/power-mode-setting.component.html | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ui-ngx/src/app/modules/home/components/profile/device/common/power-mode-setting.component.html b/ui-ngx/src/app/modules/home/components/profile/device/common/power-mode-setting.component.html index a61a2a3a09..b501cfa1c2 100644 --- a/ui-ngx/src/app/modules/home/components/profile/device/common/power-mode-setting.component.html +++ b/ui-ngx/src/app/modules/home/components/profile/device/common/power-mode-setting.component.html @@ -29,14 +29,14 @@ @@ -45,7 +45,7 @@ [labelText]="'device-profile.psm-activity-timer'" [requiredText]="'device-profile.psm-activity-timer-required'" [patternText]="'device-profile.psm-activity-timer-pattern'" - [minTime]="2000" + [minTime]="1280" [minText]="'device-profile.psm-activity-timer-min'" formControlName="psmActivityTimer"> From 5007eccb26b74d19d183852d073ab542fb60602a Mon Sep 17 00:00:00 2001 From: Volodymyr Babak Date: Fri, 20 Aug 2021 10:36:56 +0300 Subject: [PATCH 28/33] Added logs for edge license check. Replaced Object class with JsonNode --- .../server/controller/EdgeController.java | 50 +++++++++++-------- common/dao-api/pom.xml | 5 ++ .../server/dao/edge/EdgeService.java | 8 +-- .../server/dao/edge/EdgeServiceImpl.java | 10 ++-- 4 files changed, 44 insertions(+), 29 deletions(-) diff --git a/application/src/main/java/org/thingsboard/server/controller/EdgeController.java b/application/src/main/java/org/thingsboard/server/controller/EdgeController.java index 5184591fe5..c2f43cf9d3 100644 --- a/application/src/main/java/org/thingsboard/server/controller/EdgeController.java +++ b/application/src/main/java/org/thingsboard/server/controller/EdgeController.java @@ -15,8 +15,11 @@ */ package org.thingsboard.server.controller; +import com.fasterxml.jackson.databind.JsonNode; import com.google.common.util.concurrent.ListenableFuture; +import lombok.extern.slf4j.Slf4j; import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestBody; @@ -59,6 +62,7 @@ import java.util.stream.Collectors; @RestController @TbCoreComponent +@Slf4j @RequestMapping("/api") public class EdgeController extends BaseController { @@ -544,27 +548,6 @@ public class EdgeController extends BaseController { } } - @RequestMapping(value = "/license/checkInstance", method = RequestMethod.POST) - @ResponseBody - public Object checkInstance(@RequestBody Object request) throws ThingsboardException { - try { - return edgeService.checkInstance(request); - } catch (Exception e) { - throw new ThingsboardException(e, ThingsboardErrorCode.SUBSCRIPTION_VIOLATION); - } - } - - @RequestMapping(value = "/license/activateInstance", params = {"licenseSecret", "releaseDate"}, method = RequestMethod.POST) - @ResponseBody - public Object activateInstance(@RequestParam String licenseSecret, - @RequestParam String releaseDate) throws ThingsboardException { - try { - return edgeService.activateInstance(licenseSecret, releaseDate); - } catch (Exception e) { - throw new ThingsboardException(e, ThingsboardErrorCode.SUBSCRIPTION_VIOLATION); - } - } - @PreAuthorize("hasAuthority('TENANT_ADMIN')") @RequestMapping(value = "/edge/missingToRelatedRuleChains/{edgeId}", method = RequestMethod.GET) @ResponseBody @@ -583,4 +566,29 @@ public class EdgeController extends BaseController { private void cleanUpLicenseKey(Edge edge) { edge.setEdgeLicenseKey(null); } + + @RequestMapping(value = "/license/checkInstance", method = RequestMethod.POST) + @ResponseBody + public ResponseEntity checkInstance(@RequestBody JsonNode request) throws ThingsboardException { + log.debug("Checking instance [{}]", request); + try { + return edgeService.checkInstance(request); + } catch (Exception e) { + log.error("Error occurred: [{}]", e.getMessage(), e); + throw new ThingsboardException(e, ThingsboardErrorCode.SUBSCRIPTION_VIOLATION); + } + } + + @RequestMapping(value = "/license/activateInstance", params = {"licenseSecret", "releaseDate"}, method = RequestMethod.POST) + @ResponseBody + public ResponseEntity activateInstance(@RequestParam String licenseSecret, + @RequestParam String releaseDate) throws ThingsboardException { + log.debug("Activating instance [{}], [{}]", licenseSecret, releaseDate); + try { + return edgeService.activateInstance(licenseSecret, releaseDate); + } catch (Exception e) { + log.error("Error occurred: [{}]", e.getMessage(), e); + throw new ThingsboardException(e, ThingsboardErrorCode.SUBSCRIPTION_VIOLATION); + } + } } diff --git a/common/dao-api/pom.xml b/common/dao-api/pom.xml index e6032f8b97..89b59ee300 100644 --- a/common/dao-api/pom.xml +++ b/common/dao-api/pom.xml @@ -81,6 +81,11 @@ spring-boot-autoconfigure provided + + org.springframework + spring-web + provided + com.datastax.oss java-driver-core diff --git a/common/dao-api/src/main/java/org/thingsboard/server/dao/edge/EdgeService.java b/common/dao-api/src/main/java/org/thingsboard/server/dao/edge/EdgeService.java index f9d09a43ae..27a665f97f 100644 --- a/common/dao-api/src/main/java/org/thingsboard/server/dao/edge/EdgeService.java +++ b/common/dao-api/src/main/java/org/thingsboard/server/dao/edge/EdgeService.java @@ -15,16 +15,16 @@ */ package org.thingsboard.server.dao.edge; +import com.fasterxml.jackson.databind.JsonNode; import com.google.common.util.concurrent.ListenableFuture; +import org.springframework.http.ResponseEntity; import org.thingsboard.server.common.data.EntitySubtype; import org.thingsboard.server.common.data.edge.Edge; import org.thingsboard.server.common.data.edge.EdgeInfo; import org.thingsboard.server.common.data.edge.EdgeSearchQuery; import org.thingsboard.server.common.data.id.CustomerId; -import org.thingsboard.server.common.data.id.DashboardId; import org.thingsboard.server.common.data.id.EdgeId; import org.thingsboard.server.common.data.id.EntityId; -import org.thingsboard.server.common.data.id.RuleChainId; import org.thingsboard.server.common.data.id.TenantId; import org.thingsboard.server.common.data.page.PageData; import org.thingsboard.server.common.data.page.PageLink; @@ -86,9 +86,9 @@ public interface EdgeService { PageData findRelatedEdgeIdsByEntityId(TenantId tenantId, EntityId entityId, PageLink pageLink); - Object checkInstance(Object request); + ResponseEntity checkInstance(JsonNode request); - Object activateInstance(String licenseSecret, String releaseDate); + ResponseEntity activateInstance(String licenseSecret, String releaseDate); String findMissingToRelatedRuleChains(TenantId tenantId, EdgeId edgeId); } diff --git a/dao/src/main/java/org/thingsboard/server/dao/edge/EdgeServiceImpl.java b/dao/src/main/java/org/thingsboard/server/dao/edge/EdgeServiceImpl.java index 59291bc320..87e8dcbc04 100644 --- a/dao/src/main/java/org/thingsboard/server/dao/edge/EdgeServiceImpl.java +++ b/dao/src/main/java/org/thingsboard/server/dao/edge/EdgeServiceImpl.java @@ -15,6 +15,7 @@ */ package org.thingsboard.server.dao.edge; +import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.node.ArrayNode; import com.fasterxml.jackson.databind.node.ObjectNode; @@ -34,6 +35,7 @@ import org.springframework.cache.Cache; import org.springframework.cache.CacheManager; import org.springframework.cache.annotation.CacheEvict; import org.springframework.cache.annotation.Cacheable; +import org.springframework.http.ResponseEntity; import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; import org.springframework.http.client.SimpleClientHttpRequestFactory; import org.springframework.stereotype.Service; @@ -543,16 +545,16 @@ public class EdgeServiceImpl extends AbstractEntityService implements EdgeServic } @Override - public Object checkInstance(Object request) { - return this.restTemplate.postForEntity(EDGE_LICENSE_SERVER_ENDPOINT + "/api/license/checkInstance", request, Object.class, new Object[0]); + public ResponseEntity checkInstance(JsonNode request) { + return this.restTemplate.postForEntity(EDGE_LICENSE_SERVER_ENDPOINT + "/api/license/checkInstance", request, JsonNode.class); } @Override - public Object activateInstance(String edgeLicenseSecret, String releaseDate) { + public ResponseEntity activateInstance(String edgeLicenseSecret, String releaseDate) { Map params = new HashMap<>(); params.put("licenseSecret", edgeLicenseSecret); params.put("releaseDate", releaseDate); - return this.restTemplate.postForEntity(EDGE_LICENSE_SERVER_ENDPOINT + "/api/license/activateInstance?licenseSecret={licenseSecret}&releaseDate={releaseDate}", (Object) null, Object.class, params); + return this.restTemplate.postForEntity(EDGE_LICENSE_SERVER_ENDPOINT + "/api/license/activateInstance?licenseSecret={licenseSecret}&releaseDate={releaseDate}", null, JsonNode.class, params); } @Override From ba6d18b1b25d87e85e250858cb15f284d93f1282 Mon Sep 17 00:00:00 2001 From: blackstar-baba <535650957@qq.com> Date: Sat, 21 Aug 2021 15:17:56 +0800 Subject: [PATCH 29/33] Fix: resources-library page can't be redirected In SysAdmin HomePage, "resources-library" page can't be redirected --- ui-ngx/src/app/core/services/menu.service.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ui-ngx/src/app/core/services/menu.service.ts b/ui-ngx/src/app/core/services/menu.service.ts index 9436c0dd93..f44c8091af 100644 --- a/ui-ngx/src/app/core/services/menu.service.ts +++ b/ui-ngx/src/app/core/services/menu.service.ts @@ -219,7 +219,7 @@ export class MenuService { { name: 'resource.resources-library', icon: 'folder', - path: '/resources-library' + path: '/settings/resources-library' } ] } From 97e1a900f25589853dd8598e513105b406517508 Mon Sep 17 00:00:00 2001 From: Volodymyr Babak Date: Mon, 23 Aug 2021 21:57:03 +0300 Subject: [PATCH 30/33] EdgeGrpcClient: added compression --- .../src/main/java/org/thingsboard/edge/rpc/EdgeGrpcClient.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/edge-api/src/main/java/org/thingsboard/edge/rpc/EdgeGrpcClient.java b/common/edge-api/src/main/java/org/thingsboard/edge/rpc/EdgeGrpcClient.java index 4c74fdc2f9..b65706a5a2 100644 --- a/common/edge-api/src/main/java/org/thingsboard/edge/rpc/EdgeGrpcClient.java +++ b/common/edge-api/src/main/java/org/thingsboard/edge/rpc/EdgeGrpcClient.java @@ -92,7 +92,7 @@ public class EdgeGrpcClient implements EdgeRpcClient { channel = builder.build(); EdgeRpcServiceGrpc.EdgeRpcServiceStub stub = EdgeRpcServiceGrpc.newStub(channel); log.info("[{}] Sending a connect request to the TB!", edgeKey); - this.inputStream = stub.handleMsgs(initOutputStream(edgeKey, onUplinkResponse, onEdgeUpdate, onDownlink, onError)); + this.inputStream = stub.withCompression("gzip").handleMsgs(initOutputStream(edgeKey, onUplinkResponse, onEdgeUpdate, onDownlink, onError)); this.inputStream.onNext(RequestMsg.newBuilder() .setMsgType(RequestMsgType.CONNECT_RPC_MESSAGE) .setConnectRequestMsg(ConnectRequestMsg.newBuilder().setEdgeRoutingKey(edgeKey).setEdgeSecret(edgeSecret).build()) From 647c69529c4a84c7063bb856a4dd6feea376ed05 Mon Sep 17 00:00:00 2001 From: Vladyslav_Prykhodko Date: Wed, 25 Aug 2021 16:14:26 +0300 Subject: [PATCH 31/33] UI: Fixed toggle to editor full-screen mode in JSON forms --- .../shared/components/json-form/json-form.component.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/ui-ngx/src/app/shared/components/json-form/json-form.component.ts b/ui-ngx/src/app/shared/components/json-form/json-form.component.ts index 22661f89cd..93675fd6f2 100644 --- a/ui-ngx/src/app/shared/components/json-form/json-form.component.ts +++ b/ui-ngx/src/app/shared/components/json-form/json-form.component.ts @@ -15,6 +15,7 @@ /// import { + ChangeDetectorRef, Component, ElementRef, forwardRef, @@ -113,7 +114,8 @@ export class JsonFormComponent implements OnInit, ControlValueAccessor, Validato constructor(public elementRef: ElementRef, private translate: TranslateService, private dialogs: DialogService, - protected store: Store) { + protected store: Store, + private cd: ChangeDetectorRef) { } ngOnInit(): void { @@ -216,8 +218,8 @@ export class JsonFormComponent implements OnInit, ControlValueAccessor, Validato } private onIconClick(key: (string | number)[], - val: string, - iconSelectedFn: (icon: string) => void) { + val: string, + iconSelectedFn: (icon: string) => void) { this.dialogs.materialIconPicker(val).subscribe((icon) => { if (icon && iconSelectedFn) { iconSelectedFn(icon); @@ -229,6 +231,7 @@ export class JsonFormComponent implements OnInit, ControlValueAccessor, Validato this.targetFullscreenElement = element; this.isFullscreen = !this.isFullscreen; this.fullscreenFinishFn = fullscreenFinishFn; + this.cd.markForCheck(); } onFullscreenChanged(fullscreen: boolean) { From 37fd7f4988f703f5d0f6aed2a7cc5856ff2bba7f Mon Sep 17 00:00:00 2001 From: Andrii Shvaika Date: Thu, 26 Aug 2021 15:51:59 +0300 Subject: [PATCH 32/33] Validation and Replacement of Queue names in the Device profile --- .../server/actors/ActorSystemContext.java | 1 - .../server/controller/QueueController.java | 29 +++------ .../routing/HashPartitionServiceTest.java | 8 ++- .../server/queue/QueueService.java | 28 +++++++++ common/dao-api/pom.xml | 4 ++ .../server/queue/DefaultQueueService.java | 62 +++++++++++++++++++ .../queue/discovery/HashPartitionService.java | 8 ++- .../settings/TbQueueRuleEngineSettings.java | 2 - .../dao/device/DeviceProfileServiceImpl.java | 13 +++- .../add-device-profile-dialog.component.ts | 1 + .../queue/queue-type-list.component.ts | 5 -- 11 files changed, 127 insertions(+), 34 deletions(-) create mode 100644 common/cluster-api/src/main/java/org/thingsboard/server/queue/QueueService.java create mode 100644 common/queue/src/main/java/org/thingsboard/server/queue/DefaultQueueService.java diff --git a/application/src/main/java/org/thingsboard/server/actors/ActorSystemContext.java b/application/src/main/java/org/thingsboard/server/actors/ActorSystemContext.java index 07ce35d116..b01ee4f6a6 100644 --- a/application/src/main/java/org/thingsboard/server/actors/ActorSystemContext.java +++ b/application/src/main/java/org/thingsboard/server/actors/ActorSystemContext.java @@ -486,7 +486,6 @@ public class ActorSystemContext { return partitionService.resolve(serviceType, queueName, tenantId, entityId); } - public String getServiceId() { return serviceInfoProvider.getServiceId(); } diff --git a/application/src/main/java/org/thingsboard/server/controller/QueueController.java b/application/src/main/java/org/thingsboard/server/controller/QueueController.java index cf0dcd8fae..ad3b05d987 100644 --- a/application/src/main/java/org/thingsboard/server/controller/QueueController.java +++ b/application/src/main/java/org/thingsboard/server/controller/QueueController.java @@ -15,7 +15,7 @@ */ package org.thingsboard.server.controller; -import org.springframework.beans.factory.annotation.Autowired; +import lombok.RequiredArgsConstructor; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; @@ -24,41 +24,26 @@ import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.RestController; import org.thingsboard.server.common.data.exception.ThingsboardException; import org.thingsboard.server.common.msg.queue.ServiceType; -import org.thingsboard.server.queue.settings.TbQueueRuleEngineSettings; -import org.thingsboard.server.queue.settings.TbRuleEngineQueueConfiguration; +import org.thingsboard.server.queue.QueueService; import org.thingsboard.server.queue.util.TbCoreComponent; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; -import java.util.stream.Collectors; +import java.util.Set; @RestController @TbCoreComponent @RequestMapping("/api") +@RequiredArgsConstructor public class QueueController extends BaseController { - @Autowired(required = false) - private TbQueueRuleEngineSettings ruleEngineSettings; + private final QueueService queueService; @PreAuthorize("hasAuthority('TENANT_ADMIN')") @RequestMapping(value = "/tenant/queues", params = {"serviceType"}, method = RequestMethod.GET) @ResponseBody - public List getTenantQueuesByServiceType(@RequestParam String serviceType) throws ThingsboardException { + public Set getTenantQueuesByServiceType(@RequestParam String serviceType) throws ThingsboardException { checkParameter("serviceType", serviceType); try { - ServiceType type = ServiceType.valueOf(serviceType); - switch (type) { - case TB_RULE_ENGINE: - if (ruleEngineSettings == null) { - return Arrays.asList("Main", "HighPriority", "SequentialByOriginator"); - } - return ruleEngineSettings.getQueues().stream() - .map(TbRuleEngineQueueConfiguration::getName) - .collect(Collectors.toList()); - default: - return Collections.emptyList(); - } + return queueService.getQueuesByServiceType(ServiceType.valueOf(serviceType)); } catch (Exception e) { throw handleException(e); } diff --git a/application/src/test/java/org/thingsboard/server/service/cluster/routing/HashPartitionServiceTest.java b/application/src/test/java/org/thingsboard/server/service/cluster/routing/HashPartitionServiceTest.java index 88d7796af5..820127a81c 100644 --- a/application/src/test/java/org/thingsboard/server/service/cluster/routing/HashPartitionServiceTest.java +++ b/application/src/test/java/org/thingsboard/server/service/cluster/routing/HashPartitionServiceTest.java @@ -21,11 +21,13 @@ import org.junit.Assert; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; +import org.mockito.Mockito; import org.mockito.junit.MockitoJUnitRunner; import org.springframework.context.ApplicationEventPublisher; import org.springframework.test.util.ReflectionTestUtils; import org.thingsboard.server.common.data.id.DeviceId; import org.thingsboard.server.common.data.id.TenantId; +import org.thingsboard.server.queue.QueueService; import org.thingsboard.server.queue.discovery.HashPartitionService; import org.thingsboard.server.common.msg.queue.ServiceType; import org.thingsboard.server.queue.discovery.TbServiceInfoProvider; @@ -57,6 +59,7 @@ public class HashPartitionServiceTest { private TenantRoutingInfoService routingInfoService; private ApplicationEventPublisher applicationEventPublisher; private TbQueueRuleEngineSettings ruleEngineSettings; + private QueueService queueService; private String hashFunctionName = "sha256"; @@ -67,10 +70,12 @@ public class HashPartitionServiceTest { applicationEventPublisher = mock(ApplicationEventPublisher.class); routingInfoService = mock(TenantRoutingInfoService.class); ruleEngineSettings = mock(TbQueueRuleEngineSettings.class); + queueService = mock(QueueService.class); clusterRoutingService = new HashPartitionService(discoveryService, routingInfoService, applicationEventPublisher, - ruleEngineSettings + ruleEngineSettings, + queueService ); when(ruleEngineSettings.getQueues()).thenReturn(Collections.emptyList()); ReflectionTestUtils.setField(clusterRoutingService, "coreTopic", "tb.core"); @@ -82,6 +87,7 @@ public class HashPartitionServiceTest { .setTenantIdLSB(TenantId.NULL_UUID.getLeastSignificantBits()) .addAllServiceTypes(Collections.singletonList(ServiceType.TB_CORE.name())) .build(); +// when(queueService.resolve(Mockito.any(), Mockito.anyString())).thenAnswer(i -> i.getArguments()[1]); // when(discoveryService.getServiceInfo()).thenReturn(currentServer); List otherServers = new ArrayList<>(); for (int i = 1; i < SERVER_COUNT; i++) { diff --git a/common/cluster-api/src/main/java/org/thingsboard/server/queue/QueueService.java b/common/cluster-api/src/main/java/org/thingsboard/server/queue/QueueService.java new file mode 100644 index 0000000000..a1a7cdd101 --- /dev/null +++ b/common/cluster-api/src/main/java/org/thingsboard/server/queue/QueueService.java @@ -0,0 +1,28 @@ +/** + * 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. + */ +package org.thingsboard.server.queue; + +import org.thingsboard.server.common.msg.queue.ServiceType; + +import java.util.Set; + +public interface QueueService { + + Set getQueuesByServiceType(ServiceType serviceType); + + String resolve(ServiceType serviceType, String queueName); + +} diff --git a/common/dao-api/pom.xml b/common/dao-api/pom.xml index 89b59ee300..5b83ac59e9 100644 --- a/common/dao-api/pom.xml +++ b/common/dao-api/pom.xml @@ -40,6 +40,10 @@ org.thingsboard.common data + + org.thingsboard.common + cluster-api + org.thingsboard.common message diff --git a/common/queue/src/main/java/org/thingsboard/server/queue/DefaultQueueService.java b/common/queue/src/main/java/org/thingsboard/server/queue/DefaultQueueService.java new file mode 100644 index 0000000000..cb87238dfe --- /dev/null +++ b/common/queue/src/main/java/org/thingsboard/server/queue/DefaultQueueService.java @@ -0,0 +1,62 @@ +/** + * 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. + */ +package org.thingsboard.server.queue; + +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import org.springframework.util.StringUtils; +import org.thingsboard.server.common.msg.queue.ServiceQueue; +import org.thingsboard.server.common.msg.queue.ServiceType; +import org.thingsboard.server.queue.settings.TbQueueRuleEngineSettings; +import org.thingsboard.server.queue.settings.TbRuleEngineQueueConfiguration; + +import javax.annotation.PostConstruct; +import java.util.Collections; +import java.util.LinkedHashSet; +import java.util.Set; +import java.util.stream.Collectors; + +@Service +@RequiredArgsConstructor +public class DefaultQueueService implements QueueService { + + private final TbQueueRuleEngineSettings ruleEngineSettings; + private Set ruleEngineQueues; + + @PostConstruct + public void init() { + ruleEngineQueues = ruleEngineSettings.getQueues().stream() + .map(TbRuleEngineQueueConfiguration::getName).collect(Collectors.toCollection(LinkedHashSet::new)); + } + + @Override + public Set getQueuesByServiceType(ServiceType type) { + if (type == ServiceType.TB_RULE_ENGINE) { + return ruleEngineQueues; + } else { + return Collections.emptySet(); + } + } + + @Override + public String resolve(ServiceType serviceType, String queueName) { + if (StringUtils.isEmpty(queueName) || !getQueuesByServiceType(serviceType).contains(queueName)) { + return ServiceQueue.MAIN; + } else { + return queueName; + } + } +} diff --git a/common/queue/src/main/java/org/thingsboard/server/queue/discovery/HashPartitionService.java b/common/queue/src/main/java/org/thingsboard/server/queue/discovery/HashPartitionService.java index f00c13bcd5..06c635761c 100644 --- a/common/queue/src/main/java/org/thingsboard/server/queue/discovery/HashPartitionService.java +++ b/common/queue/src/main/java/org/thingsboard/server/queue/discovery/HashPartitionService.java @@ -22,6 +22,7 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.ApplicationEventPublisher; import org.springframework.stereotype.Service; +import org.springframework.util.StringUtils; import org.thingsboard.server.common.data.id.EntityId; import org.thingsboard.server.common.data.id.TenantId; import org.thingsboard.server.common.msg.queue.ServiceQueue; @@ -30,6 +31,7 @@ import org.thingsboard.server.common.msg.queue.ServiceType; import org.thingsboard.server.common.msg.queue.TopicPartitionInfo; import org.thingsboard.server.gen.transport.TransportProtos; import org.thingsboard.server.gen.transport.TransportProtos.ServiceInfo; +import org.thingsboard.server.queue.QueueService; import org.thingsboard.server.queue.discovery.event.ClusterTopologyChangeEvent; import org.thingsboard.server.queue.discovery.event.PartitionChangeEvent; import org.thingsboard.server.queue.discovery.event.ServiceListChangedEvent; @@ -64,6 +66,7 @@ public class HashPartitionService implements PartitionService { private final TbServiceInfoProvider serviceInfoProvider; private final TenantRoutingInfoService tenantRoutingInfoService; private final TbQueueRuleEngineSettings tbQueueRuleEngineSettings; + private final QueueService queueService; private final ConcurrentMap partitionTopics = new ConcurrentHashMap<>(); private final ConcurrentMap partitionSizes = new ConcurrentHashMap<>(); private final ConcurrentMap tenantRoutingInfoMap = new ConcurrentHashMap<>(); @@ -81,11 +84,13 @@ public class HashPartitionService implements PartitionService { public HashPartitionService(TbServiceInfoProvider serviceInfoProvider, TenantRoutingInfoService tenantRoutingInfoService, ApplicationEventPublisher applicationEventPublisher, - TbQueueRuleEngineSettings tbQueueRuleEngineSettings) { + TbQueueRuleEngineSettings tbQueueRuleEngineSettings, + QueueService queueService) { this.serviceInfoProvider = serviceInfoProvider; this.tenantRoutingInfoService = tenantRoutingInfoService; this.applicationEventPublisher = applicationEventPublisher; this.tbQueueRuleEngineSettings = tbQueueRuleEngineSettings; + this.queueService = queueService; } @PostConstruct @@ -106,6 +111,7 @@ public class HashPartitionService implements PartitionService { @Override public TopicPartitionInfo resolve(ServiceType serviceType, String queueName, TenantId tenantId, EntityId entityId) { + queueName = queueService.resolve(serviceType, queueName); return resolve(new ServiceQueue(serviceType, queueName), tenantId, entityId); } diff --git a/common/queue/src/main/java/org/thingsboard/server/queue/settings/TbQueueRuleEngineSettings.java b/common/queue/src/main/java/org/thingsboard/server/queue/settings/TbQueueRuleEngineSettings.java index 327ac4408a..b9065324fd 100644 --- a/common/queue/src/main/java/org/thingsboard/server/queue/settings/TbQueueRuleEngineSettings.java +++ b/common/queue/src/main/java/org/thingsboard/server/queue/settings/TbQueueRuleEngineSettings.java @@ -36,8 +36,6 @@ public class TbQueueRuleEngineSettings { private String topic; private List queues; - //TODO 2.5 ybondarenko: make sure the queue names are valid to all queue providers. - // See how they are used in TbRuleEngineQueueFactory.createToRuleEngineMsgConsumer and all producers @PostConstruct public void validate() { queues.stream().filter(queue -> queue.getName().equals("Main")).findFirst().orElseThrow(() -> { diff --git a/dao/src/main/java/org/thingsboard/server/dao/device/DeviceProfileServiceImpl.java b/dao/src/main/java/org/thingsboard/server/dao/device/DeviceProfileServiceImpl.java index 58f005df02..720d50ad69 100644 --- a/dao/src/main/java/org/thingsboard/server/dao/device/DeviceProfileServiceImpl.java +++ b/dao/src/main/java/org/thingsboard/server/dao/device/DeviceProfileServiceImpl.java @@ -28,7 +28,7 @@ import com.squareup.wire.schema.internal.parser.ProtoFileElement; import com.squareup.wire.schema.internal.parser.ProtoParser; import com.squareup.wire.schema.internal.parser.TypeElement; import lombok.extern.slf4j.Slf4j; -import org.apache.commons.lang3.StringUtils; +import org.thingsboard.server.common.data.StringUtils; import org.hibernate.exception.ConstraintViolationException; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cache.Cache; @@ -63,6 +63,7 @@ import org.thingsboard.server.common.data.id.TenantId; import org.thingsboard.server.common.data.page.PageData; import org.thingsboard.server.common.data.page.PageLink; import org.thingsboard.server.common.data.rule.RuleChain; +import org.thingsboard.server.common.msg.queue.ServiceType; import org.thingsboard.server.dao.dashboard.DashboardService; import org.thingsboard.server.dao.entity.AbstractEntityService; import org.thingsboard.server.dao.exception.DataValidationException; @@ -72,6 +73,7 @@ import org.thingsboard.server.dao.service.DataValidator; import org.thingsboard.server.dao.service.PaginatedRemover; import org.thingsboard.server.dao.service.Validator; import org.thingsboard.server.dao.tenant.TenantDao; +import org.thingsboard.server.queue.QueueService; import java.util.Arrays; import java.util.Collections; @@ -82,7 +84,6 @@ import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.ReentrantLock; import java.util.stream.Collectors; -import static com.google.protobuf.FieldType.MESSAGE; import static org.thingsboard.server.common.data.CacheConstants.DEVICE_PROFILE_CACHE; import static org.thingsboard.server.dao.service.Validator.validateId; @@ -104,6 +105,9 @@ public class DeviceProfileServiceImpl extends AbstractEntityService implements D return "[Transport Configuration] invalid " + schemaName + " provided!"; } + @Autowired(required = false) + private QueueService queueService; + @Autowired private DeviceProfileDao deviceProfileDao; @@ -373,6 +377,11 @@ public class DeviceProfileServiceImpl extends AbstractEntityService implements D throw new DataValidationException("Another default device profile is present in scope of current tenant!"); } } + if (!StringUtils.isEmpty(deviceProfile.getDefaultQueueName()) && queueService != null){ + if(!queueService.getQueuesByServiceType(ServiceType.TB_RULE_ENGINE).contains(deviceProfile.getDefaultQueueName())){ + throw new DataValidationException("Device profile is referencing to non-existent queue!"); + } + } if (deviceProfile.getProvisionType() == null) { deviceProfile.setProvisionType(DeviceProfileProvisionType.DISABLED); } diff --git a/ui-ngx/src/app/modules/home/components/profile/add-device-profile-dialog.component.ts b/ui-ngx/src/app/modules/home/components/profile/add-device-profile-dialog.component.ts index 1a6a19bc2b..9dc4b2fd06 100644 --- a/ui-ngx/src/app/modules/home/components/profile/add-device-profile-dialog.component.ts +++ b/ui-ngx/src/app/modules/home/components/profile/add-device-profile-dialog.component.ts @@ -187,6 +187,7 @@ export class AddDeviceProfileDialogComponent extends name: this.deviceProfileDetailsFormGroup.get('name').value, type: this.deviceProfileDetailsFormGroup.get('type').value, image: this.deviceProfileDetailsFormGroup.get('image').value, + defaultQueueName: this.deviceProfileDetailsFormGroup.get('defaultQueueName').value, transportType: this.transportConfigFormGroup.get('transportType').value, provisionType: deviceProvisionConfiguration.type, provisionDeviceKey, diff --git a/ui-ngx/src/app/shared/components/queue/queue-type-list.component.ts b/ui-ngx/src/app/shared/components/queue/queue-type-list.component.ts index eb850aefda..bc5d40a9b0 100644 --- a/ui-ngx/src/app/shared/components/queue/queue-type-list.component.ts +++ b/ui-ngx/src/app/shared/components/queue/queue-type-list.component.ts @@ -155,12 +155,7 @@ export class QueueTypeListComponent implements ControlValueAccessor, OnInit, Aft return searchText ? queue.toUpperCase().startsWith(searchText.toUpperCase()) : true; }); if (result.length) { - if (searchText && searchText.length && result.indexOf(searchText) === -1) { - result.push(searchText); - } result.sort(); - } else if (searchText && searchText.length) { - result.push(searchText); } return result; }) From 0ee4907567f18768912982cf64f2fffbedbda62a Mon Sep 17 00:00:00 2001 From: Igor Kulikov Date: Thu, 26 Aug 2021 16:22:35 +0300 Subject: [PATCH 33/33] Improve queue name selector --- .../wizard/device-wizard-dialog.component.ts | 1 + .../queue/queue-type-list.component.html | 7 ++- .../queue/queue-type-list.component.ts | 47 ++++++++++++------- .../assets/locale/locale.constant-en_US.json | 5 +- .../assets/locale/locale.constant-ko_KR.json | 2 +- .../assets/locale/locale.constant-sl_SI.json | 2 +- 6 files changed, 43 insertions(+), 21 deletions(-) diff --git a/ui-ngx/src/app/modules/home/components/wizard/device-wizard-dialog.component.ts b/ui-ngx/src/app/modules/home/components/wizard/device-wizard-dialog.component.ts index fd7391dacc..09bd38d999 100644 --- a/ui-ngx/src/app/modules/home/components/wizard/device-wizard-dialog.component.ts +++ b/ui-ngx/src/app/modules/home/components/wizard/device-wizard-dialog.component.ts @@ -289,6 +289,7 @@ export class DeviceWizardDialogComponent extends const deviceProfile: DeviceProfile = { name: this.deviceWizardFormGroup.get('newDeviceProfileTitle').value, type: DeviceProfileType.DEFAULT, + defaultQueueName: this.deviceWizardFormGroup.get('defaultQueueName').value, transportType: this.transportConfigFormGroup.get('transportType').value, provisionType: deviceProvisionConfiguration.type, provisionDeviceKey, diff --git a/ui-ngx/src/app/shared/components/queue/queue-type-list.component.html b/ui-ngx/src/app/shared/components/queue/queue-type-list.component.html index b8902d0964..c05e0acdc2 100644 --- a/ui-ngx/src/app/shared/components/queue/queue-type-list.component.html +++ b/ui-ngx/src/app/shared/components/queue/queue-type-list.component.html @@ -34,7 +34,12 @@ #queueAutocomplete="matAutocomplete" [displayWith]="displayQueueFn"> - + + + + + {{ translate.get('queue.no-queues-matching', {queue: searchText}) | async }} + diff --git a/ui-ngx/src/app/shared/components/queue/queue-type-list.component.ts b/ui-ngx/src/app/shared/components/queue/queue-type-list.component.ts index bc5d40a9b0..11fe16731b 100644 --- a/ui-ngx/src/app/shared/components/queue/queue-type-list.component.ts +++ b/ui-ngx/src/app/shared/components/queue/queue-type-list.component.ts @@ -34,6 +34,10 @@ import { coerceBooleanProperty } from '@angular/cdk/coercion'; import { QueueService } from '@core/http/queue.service'; import { ServiceType } from '@shared/models/queue.models'; +interface Queue { + queueName: string; +} + @Component({ selector: 'tb-queue-type-list', templateUrl: './queue-type-list.component.html', @@ -48,7 +52,7 @@ export class QueueTypeListComponent implements ControlValueAccessor, OnInit, Aft queueFormGroup: FormGroup; - modelValue: string | null; + modelValue: Queue | null; private requiredValue: boolean; get required(): boolean { @@ -67,9 +71,9 @@ export class QueueTypeListComponent implements ControlValueAccessor, OnInit, Aft @ViewChild('queueInput', {static: true}) queueInput: ElementRef; - filteredQueues: Observable>; + filteredQueues: Observable>; - queues: Observable>; + queues: Observable>; searchText = ''; @@ -99,9 +103,15 @@ export class QueueTypeListComponent implements ControlValueAccessor, OnInit, Aft debounceTime(150), distinctUntilChanged(), tap(value => { - this.updateView(value); + let modelValue; + if (typeof value === 'string' || !value) { + modelValue = null; + } else { + modelValue = value; + } + this.updateView(modelValue); }), - map(value => value ? value : ''), + map(value => value ? (typeof value === 'string' ? value : value.queueName) : ''), switchMap(queue => this.fetchQueues(queue) ) ); } @@ -123,8 +133,8 @@ export class QueueTypeListComponent implements ControlValueAccessor, OnInit, Aft writeValue(value: string | null): void { this.searchText = ''; - this.modelValue = value; - this.queueFormGroup.get('queue').patchValue(value, {emitEvent: false}); + this.modelValue = value ? { queueName: value } : null; + this.queueFormGroup.get('queue').patchValue(this.modelValue, {emitEvent: false}); this.dirty = true; } @@ -135,37 +145,42 @@ export class QueueTypeListComponent implements ControlValueAccessor, OnInit, Aft } } - updateView(value: string | null) { + updateView(value: Queue | null) { if (this.modelValue !== value) { this.modelValue = value; - this.propagateChange(this.modelValue); + this.propagateChange(this.modelValue ? this.modelValue.queueName : null); } } - displayQueueFn(queue?: string): string | undefined { - return queue ? queue : undefined; + displayQueueFn(queue?: Queue): string | undefined { + return queue ? queue.queueName : undefined; } - fetchQueues(searchText?: string): Observable> { + fetchQueues(searchText?: string): Observable> { this.searchText = searchText; return this.getQueues().pipe( - catchError(() => of([])), + catchError(() => of([] as Array)), map(queues => { const result = queues.filter( queue => { - return searchText ? queue.toUpperCase().startsWith(searchText.toUpperCase()) : true; + return searchText ? queue.queueName.toUpperCase().startsWith(searchText.toUpperCase()) : true; }); if (result.length) { - result.sort(); + result.sort((q1, q2) => q1.queueName.localeCompare(q2.queueName)); } return result; }) ); } - getQueues(): Observable> { + getQueues(): Observable> { if (!this.queues) { this.queues = this.queueService. getTenantQueuesByServiceType(this.queueType, {ignoreLoading: true}).pipe( + map((queues) => { + return queues.map((queueName) => { + return { queueName }; + }); + }), publishReplay(1), refCount() ); diff --git a/ui-ngx/src/assets/locale/locale.constant-en_US.json b/ui-ngx/src/assets/locale/locale.constant-en_US.json index e23d5508df..58d11487dc 100644 --- a/ui-ngx/src/assets/locale/locale.constant-en_US.json +++ b/ui-ngx/src/assets/locale/locale.constant-en_US.json @@ -1082,7 +1082,7 @@ "default-rule-chain": "Default rule chain", "mobile-dashboard": "Mobile dashboard", "mobile-dashboard-hint": "Used by mobile application as a device details dashboard", - "select-queue-hint": "Select from a drop-down list or add a custom name.", + "select-queue-hint": "Select from a drop-down list.", "delete-device-profile-title": "Are you sure you want to delete the device profile '{{deviceProfileName}}'?", "delete-device-profile-text": "Be careful, after the confirmation the device profile and all related data will become unrecoverable.", "delete-device-profiles-title": "Are you sure you want to delete { count, plural, 1 {1 device profile} other {# device profiles} }?", @@ -2570,7 +2570,8 @@ "queue": { "select_name": "Select queue name", "name": "Queue Name", - "name_required": "Queue name is required!" + "name_required": "Queue name is required!", + "no-queues-matching": "No queues matching '{{queue}}' were found." }, "tenant": { "tenant": "Tenant", diff --git a/ui-ngx/src/assets/locale/locale.constant-ko_KR.json b/ui-ngx/src/assets/locale/locale.constant-ko_KR.json index 56ae7d0fc3..35a291931d 100644 --- a/ui-ngx/src/assets/locale/locale.constant-ko_KR.json +++ b/ui-ngx/src/assets/locale/locale.constant-ko_KR.json @@ -959,7 +959,7 @@ "profile-configuration": "프로파일 설정", "transport-configuration": "전송 설정", "default-rule-chain": "기본 규칙 사슬", - "select-queue-hint": "Select from a drop-down list or add a custom name.", + "select-queue-hint": "Select from a drop-down list.", "delete-device-profile-title": "Are you sure you want to delete the device profile '{{deviceProfileName}}'?", "delete-device-profile-text": "Be careful, after the confirmation the device profile and all related data will become unrecoverable.", "delete-device-profiles-title": "Are you sure you want to delete { count, plural, 1 {1 개 장치 프로파일} other {# 개 장치 프로파일} }?", diff --git a/ui-ngx/src/assets/locale/locale.constant-sl_SI.json b/ui-ngx/src/assets/locale/locale.constant-sl_SI.json index 8016988f8d..3e3b252bf6 100644 --- a/ui-ngx/src/assets/locale/locale.constant-sl_SI.json +++ b/ui-ngx/src/assets/locale/locale.constant-sl_SI.json @@ -959,7 +959,7 @@ "profile-configuration": "Profile configuration", "transport-configuration": "Transport configuration", "default-rule-chain": "Default rule chain", - "select-queue-hint": "Select from a drop-down list or add a custom name.", + "select-queue-hint": "Select from a drop-down list.", "delete-device-profile-title": "Are you sure you want to delete the device profile '{{deviceProfileName}}'?", "delete-device-profile-text": "Be careful, after the confirmation the device profile and all related data will become unrecoverable.", "delete-device-profiles-title": "Are you sure you want to delete { count, plural, 1 {1 device profile} other {# device profiles} }?",