84 changed files with 1946 additions and 1100 deletions
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -1,13 +0,0 @@ |
|||
// SPDX-FileCopyrightText: Copyright The ThingsBoard Authors
|
|||
// SPDX-License-Identifier: Apache-2.0
|
|||
package org.thingsboard.server.common.data.iot_hub; |
|||
|
|||
import lombok.Data; |
|||
import org.thingsboard.server.common.data.id.DashboardId; |
|||
|
|||
@Data |
|||
public class DashboardInstalledItemDescriptor implements IotHubInstalledItemDescriptor { |
|||
|
|||
private DashboardId dashboardId; |
|||
|
|||
} |
|||
@ -0,0 +1,188 @@ |
|||
// SPDX-FileCopyrightText: Copyright ThingsBoard, Inc.
|
|||
// SPDX-License-Identifier: BUSL-1.1
|
|||
package org.thingsboard.server.common.data; |
|||
|
|||
import com.fasterxml.jackson.databind.JsonNode; |
|||
import com.fasterxml.jackson.databind.node.JsonNodeFactory; |
|||
import com.fasterxml.jackson.databind.node.ObjectNode; |
|||
import com.fasterxml.jackson.databind.node.TextNode; |
|||
import lombok.Getter; |
|||
import lombok.RequiredArgsConstructor; |
|||
import org.junit.jupiter.params.ParameterizedTest; |
|||
import org.junit.jupiter.params.provider.EnumSource; |
|||
|
|||
import java.util.function.Consumer; |
|||
import java.util.function.ObjLongConsumer; |
|||
import java.util.function.Predicate; |
|||
|
|||
import static org.assertj.core.api.Assertions.assertThat; |
|||
|
|||
class UserTest { |
|||
|
|||
private static final long TS = 1_700_000_000_000L; |
|||
|
|||
@Getter |
|||
@RequiredArgsConstructor |
|||
enum PolicyDocument { |
|||
|
|||
PRIVACY_POLICY(DataConstants.PRIVACY_POLICY_ACCEPTED, DataConstants.PRIVACY_POLICY_ACCEPTED_TS, |
|||
User::setPrivacyPolicyAccepted, User::setPrivacyPolicyAccepted, User::isPrivacyPolicyAccepted), |
|||
TERMS_OF_USE(DataConstants.TERMS_OF_USE_ACCEPTED, DataConstants.TERMS_OF_USE_ACCEPTED_TS, |
|||
User::setTermsOfUseAccepted, User::setTermsOfUseAccepted, User::isTermsOfUseAccepted); |
|||
|
|||
private final String acceptedKey; |
|||
private final String acceptedTsKey; |
|||
private final Consumer<User> accept; |
|||
private final ObjLongConsumer<User> acceptAt; |
|||
private final Predicate<User> accepted; |
|||
|
|||
PolicyDocument other() { |
|||
return this == PRIVACY_POLICY ? TERMS_OF_USE : PRIVACY_POLICY; |
|||
} |
|||
|
|||
} |
|||
|
|||
@ParameterizedTest |
|||
@EnumSource(PolicyDocument.class) |
|||
void shouldCreateAdditionalInfo_whenAdditionalInfoIsNull(PolicyDocument document) { |
|||
// GIVEN
|
|||
User user = new User(); |
|||
|
|||
// WHEN
|
|||
document.getAcceptAt().accept(user, TS); |
|||
|
|||
// THEN
|
|||
assertAcceptedAt(user, document, TS); |
|||
} |
|||
|
|||
@ParameterizedTest |
|||
@EnumSource(PolicyDocument.class) |
|||
void shouldReplaceAdditionalInfo_whenAdditionalInfoIsNotObject(PolicyDocument document) { |
|||
// GIVEN
|
|||
User user = new User(); |
|||
user.setAdditionalInfo(TextNode.valueOf("not an object")); |
|||
|
|||
// WHEN
|
|||
document.getAcceptAt().accept(user, TS); |
|||
|
|||
// THEN
|
|||
assertAcceptedAt(user, document, TS); |
|||
} |
|||
|
|||
@ParameterizedTest |
|||
@EnumSource(PolicyDocument.class) |
|||
void shouldPreserveExistingFields_whenAdditionalInfoIsObject(PolicyDocument document) { |
|||
// GIVEN
|
|||
User user = new User(); |
|||
ObjectNode additionalInfo = JsonNodeFactory.instance.objectNode(); |
|||
additionalInfo.put("lang", "en_US"); |
|||
user.setAdditionalInfo(additionalInfo); |
|||
|
|||
// WHEN
|
|||
document.getAcceptAt().accept(user, TS); |
|||
|
|||
// THEN
|
|||
assertAcceptedAt(user, document, TS); |
|||
assertThat(user.getAdditionalInfo().get("lang").asText()).isEqualTo("en_US"); |
|||
} |
|||
|
|||
@ParameterizedTest |
|||
@EnumSource(PolicyDocument.class) |
|||
void shouldOverwriteTimestamp_whenAcceptedAgain(PolicyDocument document) { |
|||
// GIVEN
|
|||
User user = new User(); |
|||
document.getAcceptAt().accept(user, TS); |
|||
|
|||
// WHEN
|
|||
document.getAcceptAt().accept(user, TS + 1); |
|||
|
|||
// THEN
|
|||
assertAcceptedAt(user, document, TS + 1); |
|||
} |
|||
|
|||
@ParameterizedTest |
|||
@EnumSource(PolicyDocument.class) |
|||
void shouldNotTouchOtherDocument(PolicyDocument document) { |
|||
// GIVEN
|
|||
User user = new User(); |
|||
|
|||
// WHEN
|
|||
document.getAcceptAt().accept(user, TS); |
|||
|
|||
// THEN
|
|||
PolicyDocument other = document.other(); |
|||
assertThat(user.getAdditionalInfo().has(other.getAcceptedKey())).isFalse(); |
|||
assertThat(user.getAdditionalInfo().has(other.getAcceptedTsKey())).isFalse(); |
|||
assertThat(other.getAccepted().test(user)).isFalse(); |
|||
} |
|||
|
|||
@ParameterizedTest |
|||
@EnumSource(PolicyDocument.class) |
|||
void shouldStampCurrentTime_whenAcceptedWithoutTimestamp(PolicyDocument document) { |
|||
// GIVEN
|
|||
User user = new User(); |
|||
long before = System.currentTimeMillis(); |
|||
|
|||
// WHEN
|
|||
document.getAccept().accept(user); |
|||
|
|||
// THEN
|
|||
long after = System.currentTimeMillis(); |
|||
assertThat(document.getAccepted().test(user)).isTrue(); |
|||
assertThat(user.getAdditionalInfo().get(document.getAcceptedTsKey()).asLong()).isBetween(before, after); |
|||
} |
|||
|
|||
@ParameterizedTest |
|||
@EnumSource(PolicyDocument.class) |
|||
void shouldReportAccepted_whenMarked(PolicyDocument document) { |
|||
// GIVEN
|
|||
User user = new User(); |
|||
document.getAcceptAt().accept(user, TS); |
|||
|
|||
// WHEN-THEN
|
|||
assertThat(document.getAccepted().test(user)).isTrue(); |
|||
} |
|||
|
|||
@ParameterizedTest |
|||
@EnumSource(PolicyDocument.class) |
|||
void shouldReportNotAccepted_whenAdditionalInfoIsNull(PolicyDocument document) { |
|||
// GIVEN
|
|||
User user = new User(); |
|||
|
|||
// WHEN-THEN
|
|||
assertThat(document.getAccepted().test(user)).isFalse(); |
|||
} |
|||
|
|||
@ParameterizedTest |
|||
@EnumSource(PolicyDocument.class) |
|||
void shouldReportNotAccepted_whenFlagIsAbsent(PolicyDocument document) { |
|||
// GIVEN
|
|||
User user = new User(); |
|||
user.setAdditionalInfo(JsonNodeFactory.instance.objectNode()); |
|||
|
|||
// WHEN-THEN
|
|||
assertThat(document.getAccepted().test(user)).isFalse(); |
|||
} |
|||
|
|||
@ParameterizedTest |
|||
@EnumSource(PolicyDocument.class) |
|||
void shouldReportNotAccepted_whenFlagIsFalse(PolicyDocument document) { |
|||
// GIVEN
|
|||
User user = new User(); |
|||
ObjectNode additionalInfo = JsonNodeFactory.instance.objectNode(); |
|||
additionalInfo.put(document.getAcceptedKey(), false); |
|||
user.setAdditionalInfo(additionalInfo); |
|||
|
|||
// WHEN-THEN
|
|||
assertThat(document.getAccepted().test(user)).isFalse(); |
|||
} |
|||
|
|||
private static void assertAcceptedAt(User user, PolicyDocument document, long expectedTs) { |
|||
JsonNode additionalInfo = user.getAdditionalInfo(); |
|||
assertThat(additionalInfo).isInstanceOf(ObjectNode.class); |
|||
assertThat(additionalInfo.get(document.getAcceptedKey()).asBoolean()).isTrue(); |
|||
assertThat(additionalInfo.get(document.getAcceptedTsKey()).asLong()).isEqualTo(expectedTs); |
|||
assertThat(document.getAccepted().test(user)).isTrue(); |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,31 @@ |
|||
<!-- |
|||
|
|||
SPDX-FileCopyrightText: Copyright The ThingsBoard Authors |
|||
SPDX-License-Identifier: Apache-2.0 |
|||
|
|||
--> |
|||
<mat-expansion-panel [expanded]="expanded" class="tb-iot-hub-facet-panel"> |
|||
<mat-expansion-panel-header> |
|||
<mat-panel-title>{{ label | translate }}</mat-panel-title> |
|||
</mat-expansion-panel-header> |
|||
|
|||
@if (searchable) { |
|||
<div class="tb-iot-hub-facet-search"> |
|||
<mat-icon>search</mat-icon> |
|||
<input [placeholder]="'iot-hub.search' | translate" [ngModel]="search" (ngModelChange)="onSearchChange($event)"> |
|||
@if (search) { |
|||
<button mat-icon-button class="tb-iot-hub-facet-search-clear" (click)="onSearchChange('')"> |
|||
<mat-icon>close</mat-icon> |
|||
</button> |
|||
} |
|||
</div> |
|||
} |
|||
|
|||
<div class="tb-iot-hub-facet-items" [class.scrollable]="scrollable"> |
|||
@for (key of visibleOptions; track key) { |
|||
<mat-checkbox [checked]="isSelected(key)" (change)="onToggle(key)"> |
|||
{{ labelFor(key) }} |
|||
</mat-checkbox> |
|||
} |
|||
</div> |
|||
</mat-expansion-panel> |
|||
@ -0,0 +1,63 @@ |
|||
// SPDX-FileCopyrightText: Copyright The ThingsBoard Authors |
|||
// SPDX-License-Identifier: Apache-2.0 |
|||
@import "./iot-hub-common"; |
|||
|
|||
// Matches the type pages' filter panel, minus its rail indent. |
|||
.tb-iot-hub-facet-panel.mat-expansion-panel { |
|||
box-shadow: none; |
|||
border-radius: 0; |
|||
background: transparent; |
|||
|
|||
// Text is indented by --tb-facet-indent (set by the host); the rules between facets are not. |
|||
.mat-expansion-panel-header { |
|||
padding: 8px 16px 8px var(--tb-facet-indent, 16px); |
|||
height: 48px; |
|||
min-height: 48px; |
|||
} |
|||
|
|||
::ng-deep .mat-expansion-panel-header-title { |
|||
font-size: 14px; |
|||
font-weight: 500; |
|||
color: rgba(0, 0, 0, 0.87); |
|||
} |
|||
|
|||
::ng-deep .mat-expansion-panel-body { |
|||
padding: 0 8px 8px var(--tb-facet-indent, 16px); |
|||
} |
|||
|
|||
mat-checkbox { |
|||
display: block; |
|||
overflow: hidden; |
|||
|
|||
&:hover { |
|||
background: rgba(0, 0, 0, 0.04); |
|||
} |
|||
} |
|||
|
|||
.tb-iot-hub-facet-items { |
|||
// Capped only when long enough to scroll. |
|||
&.scrollable { |
|||
max-height: 280px; |
|||
overflow-y: auto; |
|||
} |
|||
|
|||
@include tb-iot-hub-hover-scrollbar; |
|||
} |
|||
|
|||
.tb-iot-hub-facet-search { |
|||
@include tb-iot-hub-search-container; |
|||
margin: 4px 8px 8px 0; |
|||
|
|||
mat-icon { |
|||
@include tb-iot-hub-search-icon(rgba(0, 0, 0, 0.54)); |
|||
} |
|||
|
|||
input { |
|||
@include tb-iot-hub-search-input-text(0.2px); |
|||
} |
|||
|
|||
.tb-iot-hub-facet-search-clear.mat-mdc-icon-button { |
|||
@include tb-iot-hub-search-clear; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,60 @@ |
|||
// SPDX-FileCopyrightText: Copyright The ThingsBoard Authors
|
|||
// SPDX-License-Identifier: Apache-2.0
|
|||
import { Component, EventEmitter, Input, OnChanges, Output } from '@angular/core'; |
|||
import { filterByLabel, IOT_HUB_FILTER_SCROLL_THRESHOLD } from '@home/components/iot-hub/iot-hub-utils'; |
|||
|
|||
/** |
|||
* One checkbox facet of a filter panel: a title, the option keys, and the set of keys currently |
|||
* selected. Presentational only - the host decides what a toggle means. |
|||
*/ |
|||
@Component({ |
|||
selector: 'tb-iot-hub-facet-list', |
|||
standalone: false, |
|||
templateUrl: './iot-hub-facet-list.component.html', |
|||
styleUrls: ['./iot-hub-facet-list.component.scss'] |
|||
}) |
|||
export class TbIotHubFacetListComponent implements OnChanges { |
|||
|
|||
/** Translation key for the facet's heading. */ |
|||
@Input() label: string; |
|||
|
|||
@Input() options: string[] = []; |
|||
|
|||
/** Keys the host has selected. The host hands over a new Set on every toggle. */ |
|||
@Input() selected = new Set<string>(); |
|||
|
|||
/** Turns an option key into what the user reads. */ |
|||
@Input() labelFor: (key: string) => string = (key) => key; |
|||
|
|||
@Input() expanded = true; |
|||
|
|||
@Output() toggled = new EventEmitter<string>(); |
|||
|
|||
search = ''; |
|||
searchable = false; |
|||
visibleOptions: string[] = []; |
|||
scrollable = false; |
|||
|
|||
ngOnChanges(): void { |
|||
this.searchable = this.options.length > IOT_HUB_FILTER_SCROLL_THRESHOLD; |
|||
this.applySearch(); |
|||
} |
|||
|
|||
onSearchChange(search: string): void { |
|||
this.search = search; |
|||
this.applySearch(); |
|||
} |
|||
|
|||
isSelected(key: string): boolean { |
|||
return this.selected.has(key); |
|||
} |
|||
|
|||
onToggle(key: string): void { |
|||
this.toggled.emit(key); |
|||
} |
|||
|
|||
private applySearch(): void { |
|||
this.visibleOptions = filterByLabel(this.options, this.search, this.labelFor); |
|||
this.scrollable = this.visibleOptions.length > IOT_HUB_FILTER_SCROLL_THRESHOLD; |
|||
} |
|||
} |
|||
|
Before Width: | Height: | Size: 95 KiB |
Loading…
Reference in new issue