140 changed files with 12138 additions and 809 deletions
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -0,0 +1,38 @@ |
|||
/** |
|||
* Copyright © 2016-2024 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.service.ws.notification.sub; |
|||
|
|||
|
|||
import lombok.Getter; |
|||
import org.thingsboard.server.common.data.id.EntityId; |
|||
import org.thingsboard.server.common.data.id.TenantId; |
|||
import org.thingsboard.server.service.subscription.TbSubscription; |
|||
import org.thingsboard.server.service.subscription.TbSubscriptionType; |
|||
|
|||
import java.util.concurrent.atomic.AtomicInteger; |
|||
import java.util.function.BiConsumer; |
|||
|
|||
@Getter |
|||
public abstract class AbstractNotificationSubscription<T> extends TbSubscription<T> { |
|||
|
|||
protected final AtomicInteger sequence = new AtomicInteger(); |
|||
protected final AtomicInteger totalUnreadCounter = new AtomicInteger(); |
|||
|
|||
public AbstractNotificationSubscription(String serviceId, String sessionId, int subscriptionId, TenantId tenantId, EntityId entityId, TbSubscriptionType type, BiConsumer<TbSubscription<T>, T> updateProcessor) { |
|||
super(serviceId, sessionId, subscriptionId, tenantId, entityId, type, updateProcessor); |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,23 @@ |
|||
/** |
|||
* Copyright © 2016-2024 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.rule.engine.util; |
|||
|
|||
public class GpsGeofencingEvents { |
|||
public static final String ENTERED = "Entered"; |
|||
public static final String INSIDE = "Inside"; |
|||
public static final String LEFT = "Left"; |
|||
public static final String OUTSIDE = "Outside"; |
|||
} |
|||
@ -0,0 +1,39 @@ |
|||
/** |
|||
* Copyright © 2016-2024 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.rule.engine.geo; |
|||
|
|||
import lombok.Data; |
|||
import org.thingsboard.server.common.data.id.EntityId; |
|||
|
|||
import java.util.HashMap; |
|||
import java.util.Map; |
|||
|
|||
@Data |
|||
public class GpsGeofencingActionTestCase { |
|||
|
|||
private EntityId entityId; |
|||
private Map<EntityId, EntityGeofencingState> entityStates; |
|||
private boolean msgInside; |
|||
private boolean reportPresenceStatusOnEachMessage; |
|||
|
|||
public GpsGeofencingActionTestCase(EntityId entityId, boolean msgInside, boolean reportPresenceStatusOnEachMessage, EntityGeofencingState entityGeofencingState) { |
|||
this.entityId = entityId; |
|||
this.msgInside = msgInside; |
|||
this.reportPresenceStatusOnEachMessage = reportPresenceStatusOnEachMessage; |
|||
this.entityStates = new HashMap<>(); |
|||
this.entityStates.put(entityId, entityGeofencingState); |
|||
} |
|||
} |
|||
@ -0,0 +1,259 @@ |
|||
/** |
|||
* Copyright © 2016-2024 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.rule.engine.geo; |
|||
|
|||
import org.junit.jupiter.api.AfterEach; |
|||
import org.junit.jupiter.api.BeforeEach; |
|||
import org.junit.jupiter.api.extension.ExtendWith; |
|||
import org.junit.jupiter.params.ParameterizedTest; |
|||
import org.junit.jupiter.params.provider.Arguments; |
|||
import org.junit.jupiter.params.provider.MethodSource; |
|||
import org.mockito.Mock; |
|||
import org.mockito.junit.jupiter.MockitoExtension; |
|||
import org.springframework.test.util.ReflectionTestUtils; |
|||
import org.thingsboard.common.util.JacksonUtil; |
|||
import org.thingsboard.rule.engine.AbstractRuleNodeUpgradeTest; |
|||
import org.thingsboard.rule.engine.api.TbContext; |
|||
import org.thingsboard.rule.engine.api.TbNode; |
|||
import org.thingsboard.rule.engine.api.TbNodeConfiguration; |
|||
import org.thingsboard.rule.engine.api.TbNodeException; |
|||
import org.thingsboard.server.common.data.id.DeviceId; |
|||
import org.thingsboard.server.common.data.id.EntityId; |
|||
import org.thingsboard.server.common.data.msg.TbMsgType; |
|||
import org.thingsboard.server.common.msg.TbMsg; |
|||
import org.thingsboard.server.common.msg.TbMsgMetaData; |
|||
import org.thingsboard.server.dao.attributes.AttributesService; |
|||
|
|||
import java.time.Duration; |
|||
import java.util.UUID; |
|||
import java.util.stream.Stream; |
|||
|
|||
import static org.mockito.ArgumentMatchers.any; |
|||
import static org.mockito.ArgumentMatchers.anyString; |
|||
import static org.mockito.ArgumentMatchers.eq; |
|||
import static org.mockito.Mockito.never; |
|||
import static org.mockito.Mockito.spy; |
|||
import static org.mockito.Mockito.verify; |
|||
import static org.mockito.Mockito.when; |
|||
import static org.thingsboard.rule.engine.util.GpsGeofencingEvents.ENTERED; |
|||
import static org.thingsboard.rule.engine.util.GpsGeofencingEvents.INSIDE; |
|||
import static org.thingsboard.rule.engine.util.GpsGeofencingEvents.LEFT; |
|||
import static org.thingsboard.rule.engine.util.GpsGeofencingEvents.OUTSIDE; |
|||
import static org.thingsboard.server.common.data.msg.TbNodeConnectionType.SUCCESS; |
|||
|
|||
@ExtendWith(MockitoExtension.class) |
|||
class TbGpsGeofencingActionNodeTest extends AbstractRuleNodeUpgradeTest { |
|||
|
|||
@Mock |
|||
private TbContext ctx; |
|||
@Mock |
|||
private AttributesService attributesService; |
|||
private TbGpsGeofencingActionNode node; |
|||
|
|||
@BeforeEach |
|||
void setUp() { |
|||
node = spy(new TbGpsGeofencingActionNode()); |
|||
} |
|||
|
|||
@AfterEach |
|||
void tearDown() { |
|||
node.destroy(); |
|||
} |
|||
|
|||
private static Stream<Arguments> givenReportPresenceStatusOnEachMessage_whenOnMsg_thenVerifyOutputMsgType() { |
|||
DeviceId deviceId = new DeviceId(UUID.randomUUID()); |
|||
long tsNow = System.currentTimeMillis(); |
|||
long tsNowMinusMinuteAndMillis = tsNow - Duration.ofMinutes(1).plusMillis(1).toMillis(); |
|||
return Stream.of( |
|||
// default config with presenceMonitoringStrategyOnEachMessage false and msgInside true
|
|||
Arguments.of(new GpsGeofencingActionTestCase(deviceId, true, false, |
|||
new EntityGeofencingState(false, 0, false)), ENTERED), |
|||
Arguments.of(new GpsGeofencingActionTestCase(deviceId, true, false, |
|||
new EntityGeofencingState(true, tsNow, false)), SUCCESS), |
|||
Arguments.of(new GpsGeofencingActionTestCase(deviceId, true, false, |
|||
new EntityGeofencingState(true, tsNowMinusMinuteAndMillis, false)), INSIDE), |
|||
Arguments.of(new GpsGeofencingActionTestCase(deviceId, true, false, |
|||
new EntityGeofencingState(true, tsNow, true)), SUCCESS), |
|||
// default config with presenceMonitoringStrategyOnEachMessage false and msgInside false
|
|||
Arguments.of(new GpsGeofencingActionTestCase(deviceId, false, false, |
|||
new EntityGeofencingState(false, 0, false)), LEFT), |
|||
Arguments.of(new GpsGeofencingActionTestCase(deviceId, false, false, |
|||
new EntityGeofencingState(false, tsNow, false)), SUCCESS), |
|||
Arguments.of(new GpsGeofencingActionTestCase(deviceId, false, false, |
|||
new EntityGeofencingState(false, tsNowMinusMinuteAndMillis, false)), OUTSIDE), |
|||
Arguments.of(new GpsGeofencingActionTestCase(deviceId, false, false, |
|||
new EntityGeofencingState(false, tsNow, true)), SUCCESS), |
|||
// default config with presenceMonitoringStrategyOnEachMessage true and msgInside true
|
|||
Arguments.of(new GpsGeofencingActionTestCase(deviceId, true, true, |
|||
new EntityGeofencingState(false, 0, false)), ENTERED), |
|||
Arguments.of(new GpsGeofencingActionTestCase(deviceId, true, true, |
|||
new EntityGeofencingState(true, tsNow, false)), INSIDE), |
|||
Arguments.of(new GpsGeofencingActionTestCase(deviceId, true, true, |
|||
new EntityGeofencingState(true, tsNowMinusMinuteAndMillis, false)), INSIDE), |
|||
// default config with presenceMonitoringStrategyOnEachMessage true and msgInside false
|
|||
Arguments.of(new GpsGeofencingActionTestCase(deviceId, false, true, |
|||
new EntityGeofencingState(false, 0, false)), LEFT), |
|||
Arguments.of(new GpsGeofencingActionTestCase(deviceId, false, true, |
|||
new EntityGeofencingState(false, tsNow, false)), OUTSIDE), |
|||
Arguments.of(new GpsGeofencingActionTestCase(deviceId, false, true, |
|||
new EntityGeofencingState(false, tsNowMinusMinuteAndMillis, false)), OUTSIDE) |
|||
); |
|||
} |
|||
|
|||
@ParameterizedTest |
|||
@MethodSource |
|||
void givenReportPresenceStatusOnEachMessage_whenOnMsg_thenVerifyOutputMsgType( |
|||
GpsGeofencingActionTestCase gpsGeofencingActionTestCase, |
|||
String expectedOutput |
|||
) throws TbNodeException { |
|||
// GIVEN
|
|||
var config = new TbGpsGeofencingActionNodeConfiguration().defaultConfiguration(); |
|||
config.setReportPresenceStatusOnEachMessage(gpsGeofencingActionTestCase.isReportPresenceStatusOnEachMessage()); |
|||
|
|||
node.init(ctx, new TbNodeConfiguration(JacksonUtil.valueToTree(config))); |
|||
|
|||
TbMsg msg = gpsGeofencingActionTestCase.isMsgInside() ? |
|||
getInsideRectangleTbMsg(gpsGeofencingActionTestCase.getEntityId()) : |
|||
getOutsideRectangleTbMsg(gpsGeofencingActionTestCase.getEntityId()); |
|||
|
|||
when(ctx.getAttributesService()).thenReturn(attributesService); |
|||
|
|||
ReflectionTestUtils.setField(node, "entityStates", gpsGeofencingActionTestCase.getEntityStates()); |
|||
|
|||
// WHEN
|
|||
node.onMsg(ctx, msg); |
|||
|
|||
// THEN
|
|||
verify(ctx.getAttributesService(), never()).find(any(), any(), any(), anyString()); |
|||
verify(ctx, never()).tellFailure(any(), any(Throwable.class)); |
|||
verify(ctx, never()).enqueueForTellNext(any(), eq(expectedOutput), any(), any()); |
|||
verify(ctx, never()).ack(any()); |
|||
|
|||
if (SUCCESS.equals(expectedOutput)) { |
|||
verify(ctx).tellSuccess(eq(msg)); |
|||
} else { |
|||
verify(ctx).tellNext(eq(msg), eq(expectedOutput)); |
|||
} |
|||
} |
|||
|
|||
private TbMsg getOutsideRectangleTbMsg(EntityId entityId) { |
|||
return getTbMsg(entityId, getMetadataForNewVersionPolygonPerimeter(), |
|||
GeoUtilTest.POINT_OUTSIDE_SIMPLE_RECT.getLatitude(), |
|||
GeoUtilTest.POINT_OUTSIDE_SIMPLE_RECT.getLongitude()); |
|||
} |
|||
|
|||
private TbMsg getInsideRectangleTbMsg(EntityId entityId) { |
|||
return getTbMsg(entityId, getMetadataForNewVersionPolygonPerimeter(), |
|||
GeoUtilTest.POINT_INSIDE_SIMPLE_RECT_CENTER.getLatitude(), |
|||
GeoUtilTest.POINT_INSIDE_SIMPLE_RECT_CENTER.getLongitude()); |
|||
} |
|||
|
|||
private TbMsg getTbMsg(EntityId entityId, TbMsgMetaData metadata, double latitude, double longitude) { |
|||
String data = "{\"latitude\": " + latitude + ", \"longitude\": " + longitude + "}"; |
|||
return TbMsg.newMsg(TbMsgType.POST_ATTRIBUTES_REQUEST, entityId, metadata, data); |
|||
} |
|||
|
|||
private TbMsgMetaData getMetadataForNewVersionPolygonPerimeter() { |
|||
var metadata = new TbMsgMetaData(); |
|||
metadata.putValue("ss_perimeter", GeoUtilTest.SIMPLE_RECT); |
|||
return metadata; |
|||
} |
|||
|
|||
// Rule nodes upgrade
|
|||
private static Stream<Arguments> givenFromVersionAndConfig_whenUpgrade_thenVerifyHasChangesAndConfig() { |
|||
return Stream.of( |
|||
// default config for version 0
|
|||
Arguments.of(0, |
|||
"{\n" + |
|||
" \"minInsideDuration\": 1,\n" + |
|||
" \"minOutsideDuration\": 1,\n" + |
|||
" \"minInsideDurationTimeUnit\": \"MINUTES\",\n" + |
|||
" \"minOutsideDurationTimeUnit\": \"MINUTES\",\n" + |
|||
" \"latitudeKeyName\": \"latitude\",\n" + |
|||
" \"longitudeKeyName\": \"longitude\",\n" + |
|||
" \"perimeterType\": \"POLYGON\",\n" + |
|||
" \"fetchPerimeterInfoFromMessageMetadata\": true,\n" + |
|||
" \"perimeterKeyName\": \"ss_perimeter\",\n" + |
|||
" \"polygonsDefinition\": null,\n" + |
|||
" \"centerLatitude\": null,\n" + |
|||
" \"centerLongitude\": null,\n" + |
|||
" \"range\": null,\n" + |
|||
" \"rangeUnit\": null\n" + |
|||
"}\n", |
|||
true, |
|||
"{\n" + |
|||
" \"minInsideDuration\": 1,\n" + |
|||
" \"minOutsideDuration\": 1,\n" + |
|||
" \"minInsideDurationTimeUnit\": \"MINUTES\",\n" + |
|||
" \"minOutsideDurationTimeUnit\": \"MINUTES\",\n" + |
|||
" \"reportPresenceStatusOnEachMessage\": false,\n" + |
|||
" \"latitudeKeyName\": \"latitude\",\n" + |
|||
" \"longitudeKeyName\": \"longitude\",\n" + |
|||
" \"perimeterType\": \"POLYGON\",\n" + |
|||
" \"fetchPerimeterInfoFromMessageMetadata\": true,\n" + |
|||
" \"perimeterKeyName\": \"ss_perimeter\",\n" + |
|||
" \"polygonsDefinition\": null,\n" + |
|||
" \"centerLatitude\": null,\n" + |
|||
" \"centerLongitude\": null,\n" + |
|||
" \"range\": null,\n" + |
|||
" \"rangeUnit\": null\n" + |
|||
"}\n"), |
|||
// default config for version 1 with upgrade from version 0
|
|||
Arguments.of(0, |
|||
"{\n" + |
|||
" \"minInsideDuration\": 1,\n" + |
|||
" \"minOutsideDuration\": 1,\n" + |
|||
" \"minInsideDurationTimeUnit\": \"MINUTES\",\n" + |
|||
" \"minOutsideDurationTimeUnit\": \"MINUTES\",\n" + |
|||
" \"reportPresenceStatusOnEachMessage\": false,\n" + |
|||
" \"latitudeKeyName\": \"latitude\",\n" + |
|||
" \"longitudeKeyName\": \"longitude\",\n" + |
|||
" \"perimeterType\": \"POLYGON\",\n" + |
|||
" \"fetchPerimeterInfoFromMessageMetadata\": true,\n" + |
|||
" \"perimeterKeyName\": \"ss_perimeter\",\n" + |
|||
" \"polygonsDefinition\": null,\n" + |
|||
" \"centerLatitude\": null,\n" + |
|||
" \"centerLongitude\": null,\n" + |
|||
" \"range\": null,\n" + |
|||
" \"rangeUnit\": null\n" + |
|||
"}\n", |
|||
false, |
|||
"{\n" + |
|||
" \"minInsideDuration\": 1,\n" + |
|||
" \"minOutsideDuration\": 1,\n" + |
|||
" \"minInsideDurationTimeUnit\": \"MINUTES\",\n" + |
|||
" \"minOutsideDurationTimeUnit\": \"MINUTES\",\n" + |
|||
" \"reportPresenceStatusOnEachMessage\": false,\n" + |
|||
" \"latitudeKeyName\": \"latitude\",\n" + |
|||
" \"longitudeKeyName\": \"longitude\",\n" + |
|||
" \"perimeterType\": \"POLYGON\",\n" + |
|||
" \"fetchPerimeterInfoFromMessageMetadata\": true,\n" + |
|||
" \"perimeterKeyName\": \"ss_perimeter\",\n" + |
|||
" \"polygonsDefinition\": null,\n" + |
|||
" \"centerLatitude\": null,\n" + |
|||
" \"centerLongitude\": null,\n" + |
|||
" \"range\": null,\n" + |
|||
" \"rangeUnit\": null\n" + |
|||
"}\n") |
|||
); |
|||
} |
|||
|
|||
@Override |
|||
protected TbNode getTestNode() { |
|||
return node; |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,197 @@ |
|||
<!-- |
|||
|
|||
Copyright © 2016-2024 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. |
|||
|
|||
--> |
|||
<ng-container [formGroup]="powerButtonWidgetConfigForm"> |
|||
<tb-target-device formControlName="targetDevice"></tb-target-device> |
|||
<div class="tb-form-panel"> |
|||
<div class="tb-form-panel-title" translate>widgets.power-button.behavior</div> |
|||
<div class="tb-form-row"> |
|||
<div class="fixed-title-width" tb-hint-tooltip-icon="{{'widgets.rpc-state.initial-state-hint' | translate}}" translate>widgets.rpc-state.initial-state</div> |
|||
<tb-get-value-action-settings fxFlex |
|||
panelTitle="widgets.rpc-state.initial-state" |
|||
[valueType]="valueType.BOOLEAN" |
|||
trueLabel="widgets.rpc-state.on" |
|||
falseLabel="widgets.rpc-state.off" |
|||
stateLabel="widgets.rpc-state.on" |
|||
[aliasController]="aliasController" |
|||
[targetDevice]="targetDevice" |
|||
[widgetType]="widgetType" |
|||
formControlName="initialState"></tb-get-value-action-settings> |
|||
</div> |
|||
<div class="tb-form-row space-between"> |
|||
<div class="fixed-title-width" tb-hint-tooltip-icon="{{'widgets.power-button.power-on-hint' | translate}}" translate>widgets.power-button.power-on</div> |
|||
<tb-set-value-action-settings fxFlex |
|||
panelTitle="widgets.power-button.power-on " |
|||
[aliasController]="aliasController" |
|||
[targetDevice]="targetDevice" |
|||
[widgetType]="widgetType" |
|||
formControlName="onUpdateState"></tb-set-value-action-settings> |
|||
</div> |
|||
<div class="tb-form-row space-between"> |
|||
<div class="fixed-title-width" tb-hint-tooltip-icon="{{'widgets.power-button.power-off-hint' | translate}}" translate>widgets.power-button.power-off</div> |
|||
<tb-set-value-action-settings fxFlex |
|||
panelTitle="widgets.power-button.power-off" |
|||
[aliasController]="aliasController" |
|||
[targetDevice]="targetDevice" |
|||
[widgetType]="widgetType" |
|||
formControlName="offUpdateState"></tb-set-value-action-settings> |
|||
</div> |
|||
<div class="tb-form-row"> |
|||
<div class="fixed-title-width" tb-hint-tooltip-icon="{{'widgets.rpc-state.disabled-state-hint' | translate}}" translate>widgets.rpc-state.disabled-state</div> |
|||
<tb-get-value-action-settings fxFlex |
|||
panelTitle="widgets.rpc-state.disabled-state" |
|||
[valueType]="valueType.BOOLEAN" |
|||
stateLabel="widgets.rpc-state.disabled" |
|||
[aliasController]="aliasController" |
|||
[targetDevice]="targetDevice" |
|||
[widgetType]="widgetType" |
|||
formControlName="disabledState"></tb-get-value-action-settings> |
|||
</div> |
|||
</div> |
|||
<div class="tb-form-panel"> |
|||
<div class="tb-form-panel-title" translate>widget-config.appearance</div> |
|||
<tb-image-cards-select rowHeight="1:1" |
|||
[cols]="{columns: 3, |
|||
breakpoints: { |
|||
'lt-sm': 1, |
|||
'lt-md': 2 |
|||
}}" |
|||
label="{{ 'widgets.power-button.layout' | translate }}" formControlName="layout"> |
|||
<tb-image-cards-select-option *ngFor="let layout of powerButtonLayouts" |
|||
[value]="layout" |
|||
[image]="powerButtonLayoutImageMap.get(layout)"> |
|||
{{ powerButtonLayoutTranslationMap.get(layout) | translate }} |
|||
</tb-image-cards-select-option> |
|||
</tb-image-cards-select> |
|||
<div class="tb-form-row column-xs"> |
|||
<mat-slide-toggle class="mat-slide fixed-title-width" formControlName="showTitle"> |
|||
{{ 'widget-config.title' | translate }} |
|||
</mat-slide-toggle> |
|||
<div fxFlex fxLayout="row" fxLayoutAlign="start center" fxLayoutGap="8px"> |
|||
<mat-form-field class="flex" appearance="outline" subscriptSizing="dynamic"> |
|||
<input matInput formControlName="title" placeholder="{{ 'widget-config.set' | translate }}"> |
|||
</mat-form-field> |
|||
<tb-font-settings formControlName="titleFont" |
|||
clearButton |
|||
[previewText]="powerButtonWidgetConfigForm.get('title').value" |
|||
[initialPreviewStyle]="widgetConfig.config.titleStyle"> |
|||
</tb-font-settings> |
|||
<tb-color-input asBoxInput |
|||
colorClearButton |
|||
formControlName="titleColor"> |
|||
</tb-color-input> |
|||
</div> |
|||
</div> |
|||
<div class="tb-form-row column-xs"> |
|||
<mat-slide-toggle class="mat-slide fixed-title-width" formControlName="showIcon"> |
|||
{{ 'widget-config.card-icon' | translate }} |
|||
</mat-slide-toggle> |
|||
<div fxFlex fxLayout="row" fxLayoutAlign="start center" fxLayoutGap="8px"> |
|||
<mat-form-field appearance="outline" class="flex number" subscriptSizing="dynamic"> |
|||
<input matInput type="number" min="0" formControlName="iconSize" placeholder="{{ 'widget-config.set' | translate }}"> |
|||
</mat-form-field> |
|||
<tb-css-unit-select fxFlex formControlName="iconSizeUnit"></tb-css-unit-select> |
|||
<tb-material-icon-select asBoxInput |
|||
iconClearButton |
|||
[color]="powerButtonWidgetConfigForm.get('iconColor').value" |
|||
formControlName="icon"> |
|||
</tb-material-icon-select> |
|||
<tb-color-input asBoxInput |
|||
colorClearButton |
|||
formControlName="iconColor"> |
|||
</tb-color-input> |
|||
</div> |
|||
</div> |
|||
<div class="tb-form-row space-between column-xs"> |
|||
<div>{{ 'widgets.power-button.power-on-colors' | translate }}</div> |
|||
<div fxLayout="row" fxLayoutAlign="start center" fxLayoutGap="12px"> |
|||
<div fxLayout="row" fxLayoutAlign="start center" fxLayoutGap="8px"> |
|||
<div translate>widgets.power-button.main</div> |
|||
<tb-color-input asBoxInput |
|||
formControlName="mainColorOn"> |
|||
</tb-color-input> |
|||
</div> |
|||
<mat-divider vertical></mat-divider> |
|||
<div fxLayout="row" fxLayoutAlign="start center" fxLayoutGap="8px"> |
|||
<div translate>widgets.power-button.background</div> |
|||
<tb-color-input asBoxInput |
|||
formControlName="backgroundColorOn"> |
|||
</tb-color-input> |
|||
</div> |
|||
</div> |
|||
</div> |
|||
<div class="tb-form-row space-between column-xs"> |
|||
<div>{{ 'widgets.power-button.power-off-colors' | translate }}</div> |
|||
<div fxLayout="row" fxLayoutAlign="start center" fxLayoutGap="12px"> |
|||
<div fxLayout="row" fxLayoutAlign="start center" fxLayoutGap="8px"> |
|||
<div translate>widgets.power-button.main</div> |
|||
<tb-color-input asBoxInput |
|||
formControlName="mainColorOff"> |
|||
</tb-color-input> |
|||
</div> |
|||
<mat-divider vertical></mat-divider> |
|||
<div fxLayout="row" fxLayoutAlign="start center" fxLayoutGap="8px"> |
|||
<div translate>widgets.power-button.background</div> |
|||
<tb-color-input asBoxInput |
|||
formControlName="backgroundColorOff"> |
|||
</tb-color-input> |
|||
</div> |
|||
</div> |
|||
</div> |
|||
<div class="tb-form-row space-between column-xs"> |
|||
<div>{{ 'widgets.power-button.disabled-colors' | translate }}</div> |
|||
<div fxLayout="row" fxLayoutAlign="start center" fxLayoutGap="12px"> |
|||
<div fxLayout="row" fxLayoutAlign="start center" fxLayoutGap="8px"> |
|||
<div translate>widgets.power-button.main</div> |
|||
<tb-color-input asBoxInput |
|||
formControlName="mainColorDisabled"> |
|||
</tb-color-input> |
|||
</div> |
|||
<mat-divider vertical></mat-divider> |
|||
<div fxLayout="row" fxLayoutAlign="start center" fxLayoutGap="8px"> |
|||
<div translate>widgets.power-button.background</div> |
|||
<tb-color-input asBoxInput |
|||
formControlName="backgroundColorDisabled"> |
|||
</tb-color-input> |
|||
</div> |
|||
</div> |
|||
</div> |
|||
</div> |
|||
<div class="tb-form-panel"> |
|||
<div class="tb-form-panel-title" translate>widget-config.card-appearance</div> |
|||
<div class="tb-form-row space-between"> |
|||
<div>{{ 'widgets.background.background' | translate }}</div> |
|||
<tb-background-settings formControlName="background"> |
|||
</tb-background-settings> |
|||
</div> |
|||
<div class="tb-form-row space-between column-lt-md"> |
|||
<div translate>widget-config.show-card-buttons</div> |
|||
<mat-chip-listbox multiple formControlName="cardButtons"> |
|||
<mat-chip-option value="fullscreen">{{ 'fullscreen.fullscreen' | translate }}</mat-chip-option> |
|||
</mat-chip-listbox> |
|||
</div> |
|||
<div class="tb-form-row space-between"> |
|||
<div>{{ 'widget-config.card-border-radius' | translate }}</div> |
|||
<mat-form-field appearance="outline" subscriptSizing="dynamic"> |
|||
<input matInput formControlName="borderRadius" placeholder="{{ 'widget-config.set' | translate }}"> |
|||
</mat-form-field> |
|||
</div> |
|||
</div> |
|||
<tb-widget-actions-panel |
|||
formControlName="actions"> |
|||
</tb-widget-actions-panel> |
|||
</ng-container> |
|||
@ -0,0 +1,195 @@ |
|||
///
|
|||
/// Copyright © 2016-2024 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.
|
|||
///
|
|||
|
|||
import { Component } from '@angular/core'; |
|||
import { UntypedFormBuilder, UntypedFormGroup, Validators } from '@angular/forms'; |
|||
import { Store } from '@ngrx/store'; |
|||
import { AppState } from '@core/core.state'; |
|||
import { BasicWidgetConfigComponent } from '@home/components/widget/config/widget-config.component.models'; |
|||
import { WidgetConfigComponentData } from '@home/models/widget-component.models'; |
|||
import { TargetDevice, WidgetConfig, } from '@shared/models/widget.models'; |
|||
import { WidgetConfigComponent } from '@home/components/widget/widget-config.component'; |
|||
import { isUndefined } from '@core/utils'; |
|||
import { ValueType } from '@shared/models/constants'; |
|||
import { |
|||
powerButtonDefaultSettings, |
|||
powerButtonLayoutImages, |
|||
powerButtonLayouts, |
|||
powerButtonLayoutTranslations, |
|||
PowerButtonWidgetSettings |
|||
} from '@home/components/widget/lib/rpc/power-button-widget.models'; |
|||
import { cssSizeToStrSize, resolveCssSize } from '@shared/models/widget-settings.models'; |
|||
|
|||
@Component({ |
|||
selector: 'tb-power-button-basic-config', |
|||
templateUrl: './power-button-basic-config.component.html', |
|||
styleUrls: ['../basic-config.scss'] |
|||
}) |
|||
export class PowerButtonBasicConfigComponent extends BasicWidgetConfigComponent { |
|||
|
|||
get targetDevice(): TargetDevice { |
|||
return this.powerButtonWidgetConfigForm.get('targetDevice').value; |
|||
} |
|||
|
|||
powerButtonLayouts = powerButtonLayouts; |
|||
|
|||
powerButtonLayoutTranslationMap = powerButtonLayoutTranslations; |
|||
powerButtonLayoutImageMap = powerButtonLayoutImages; |
|||
|
|||
valueType = ValueType; |
|||
|
|||
powerButtonWidgetConfigForm: UntypedFormGroup; |
|||
|
|||
constructor(protected store: Store<AppState>, |
|||
protected widgetConfigComponent: WidgetConfigComponent, |
|||
private fb: UntypedFormBuilder) { |
|||
super(store, widgetConfigComponent); |
|||
} |
|||
|
|||
protected configForm(): UntypedFormGroup { |
|||
return this.powerButtonWidgetConfigForm; |
|||
} |
|||
|
|||
protected onConfigSet(configData: WidgetConfigComponentData) { |
|||
const settings: PowerButtonWidgetSettings = {...powerButtonDefaultSettings, ...(configData.config.settings || {})}; |
|||
const iconSize = resolveCssSize(configData.config.iconSize); |
|||
this.powerButtonWidgetConfigForm = this.fb.group({ |
|||
targetDevice: [configData.config.targetDevice, []], |
|||
|
|||
initialState: [settings.initialState, []], |
|||
onUpdateState: [settings.onUpdateState, []], |
|||
offUpdateState: [settings.offUpdateState, []], |
|||
disabledState: [settings.disabledState, []], |
|||
|
|||
layout: [settings.layout, []], |
|||
|
|||
showTitle: [configData.config.showTitle, []], |
|||
title: [configData.config.title, []], |
|||
titleFont: [configData.config.titleFont, []], |
|||
titleColor: [configData.config.titleColor, []], |
|||
|
|||
showIcon: [configData.config.showTitleIcon, []], |
|||
iconSize: [iconSize[0], [Validators.min(0)]], |
|||
iconSizeUnit: [iconSize[1], []], |
|||
icon: [configData.config.titleIcon, []], |
|||
iconColor: [configData.config.iconColor, []], |
|||
|
|||
mainColorOn: [settings.mainColorOn, []], |
|||
backgroundColorOn: [settings.backgroundColorOn, []], |
|||
|
|||
mainColorOff: [settings.mainColorOff, []], |
|||
backgroundColorOff: [settings.backgroundColorOff, []], |
|||
|
|||
mainColorDisabled: [settings.mainColorDisabled, []], |
|||
backgroundColorDisabled: [settings.backgroundColorDisabled, []], |
|||
|
|||
background: [settings.background, []], |
|||
|
|||
cardButtons: [this.getCardButtons(configData.config), []], |
|||
borderRadius: [configData.config.borderRadius, []], |
|||
|
|||
actions: [configData.config.actions || {}, []] |
|||
}); |
|||
} |
|||
|
|||
protected prepareOutputConfig(config: any): WidgetConfigComponentData { |
|||
this.widgetConfig.config.targetDevice = config.targetDevice; |
|||
|
|||
this.widgetConfig.config.showTitle = config.showTitle; |
|||
this.widgetConfig.config.title = config.title; |
|||
this.widgetConfig.config.titleFont = config.titleFont; |
|||
this.widgetConfig.config.titleColor = config.titleColor; |
|||
|
|||
this.widgetConfig.config.showTitleIcon = config.showIcon; |
|||
this.widgetConfig.config.iconSize = cssSizeToStrSize(config.iconSize, config.iconSizeUnit); |
|||
this.widgetConfig.config.titleIcon = config.icon; |
|||
this.widgetConfig.config.iconColor = config.iconColor; |
|||
|
|||
this.widgetConfig.config.settings = this.widgetConfig.config.settings || {}; |
|||
|
|||
this.widgetConfig.config.settings.initialState = config.initialState; |
|||
this.widgetConfig.config.settings.onUpdateState = config.onUpdateState; |
|||
this.widgetConfig.config.settings.offUpdateState = config.offUpdateState; |
|||
this.widgetConfig.config.settings.disabledState = config.disabledState; |
|||
|
|||
this.widgetConfig.config.settings.layout = config.layout; |
|||
|
|||
this.widgetConfig.config.settings.mainColorOn = config.mainColorOn; |
|||
this.widgetConfig.config.settings.backgroundColorOn = config.backgroundColorOn; |
|||
|
|||
this.widgetConfig.config.settings.mainColorOff = config.mainColorOff; |
|||
this.widgetConfig.config.settings.backgroundColorOff = config.backgroundColorOff; |
|||
|
|||
this.widgetConfig.config.settings.mainColorDisabled = config.mainColorDisabled; |
|||
this.widgetConfig.config.settings.backgroundColorDisabled = config.backgroundColorDisabled; |
|||
|
|||
this.widgetConfig.config.settings.background = config.background; |
|||
|
|||
this.setCardButtons(config.cardButtons, this.widgetConfig.config); |
|||
this.widgetConfig.config.borderRadius = config.borderRadius; |
|||
|
|||
this.widgetConfig.config.actions = config.actions; |
|||
return this.widgetConfig; |
|||
} |
|||
|
|||
protected validatorTriggers(): string[] { |
|||
return ['showTitle', 'showIcon']; |
|||
} |
|||
|
|||
protected updateValidators(emitEvent: boolean, trigger?: string) { |
|||
const showTitle: boolean = this.powerButtonWidgetConfigForm.get('showTitle').value; |
|||
const showIcon: boolean = this.powerButtonWidgetConfigForm.get('showIcon').value; |
|||
if (showTitle) { |
|||
this.powerButtonWidgetConfigForm.get('title').enable(); |
|||
this.powerButtonWidgetConfigForm.get('titleFont').enable(); |
|||
this.powerButtonWidgetConfigForm.get('titleColor').enable(); |
|||
this.powerButtonWidgetConfigForm.get('showIcon').enable({emitEvent: false}); |
|||
if (showIcon) { |
|||
this.powerButtonWidgetConfigForm.get('iconSize').enable(); |
|||
this.powerButtonWidgetConfigForm.get('iconSizeUnit').enable(); |
|||
this.powerButtonWidgetConfigForm.get('icon').enable(); |
|||
this.powerButtonWidgetConfigForm.get('iconColor').enable(); |
|||
} else { |
|||
this.powerButtonWidgetConfigForm.get('iconSize').disable(); |
|||
this.powerButtonWidgetConfigForm.get('iconSizeUnit').disable(); |
|||
this.powerButtonWidgetConfigForm.get('icon').disable(); |
|||
this.powerButtonWidgetConfigForm.get('iconColor').disable(); |
|||
} |
|||
} else { |
|||
this.powerButtonWidgetConfigForm.get('title').disable(); |
|||
this.powerButtonWidgetConfigForm.get('titleFont').disable(); |
|||
this.powerButtonWidgetConfigForm.get('titleColor').disable(); |
|||
this.powerButtonWidgetConfigForm.get('showIcon').disable({emitEvent: false}); |
|||
this.powerButtonWidgetConfigForm.get('iconSize').disable(); |
|||
this.powerButtonWidgetConfigForm.get('iconSizeUnit').disable(); |
|||
this.powerButtonWidgetConfigForm.get('icon').disable(); |
|||
this.powerButtonWidgetConfigForm.get('iconColor').disable(); |
|||
} |
|||
} |
|||
|
|||
private getCardButtons(config: WidgetConfig): string[] { |
|||
const buttons: string[] = []; |
|||
if (isUndefined(config.enableFullscreen) || config.enableFullscreen) { |
|||
buttons.push('fullscreen'); |
|||
} |
|||
return buttons; |
|||
} |
|||
|
|||
private setCardButtons(buttons: string[], config: WidgetConfig) { |
|||
config.enableFullscreen = buttons.includes('fullscreen'); |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,271 @@ |
|||
<!-- |
|||
|
|||
Copyright © 2016-2024 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. |
|||
|
|||
--> |
|||
<ng-container [formGroup]="sliderWidgetConfigForm"> |
|||
<tb-target-device formControlName="targetDevice"></tb-target-device> |
|||
<div class="tb-form-panel"> |
|||
<div class="tb-form-panel-title" translate>widgets.slider.behavior</div> |
|||
<div class="tb-form-row"> |
|||
<div class="fixed-title-width" tb-hint-tooltip-icon="{{'widgets.slider.initial-value-hint' | translate}}" translate>widgets.slider.initial-value</div> |
|||
<tb-get-value-action-settings fxFlex |
|||
panelTitle="widgets.slider.initial-value" |
|||
[valueType]="valueType.DOUBLE" |
|||
[aliasController]="aliasController" |
|||
[targetDevice]="targetDevice" |
|||
[widgetType]="widgetType" |
|||
formControlName="initialState"></tb-get-value-action-settings> |
|||
</div> |
|||
<div class="tb-form-row space-between"> |
|||
<div class="fixed-title-width" tb-hint-tooltip-icon="{{'widgets.slider.on-value-change-hint' | translate}}" translate>widgets.slider.on-value-change</div> |
|||
<tb-set-value-action-settings fxFlex |
|||
panelTitle="widgets.slider.on-value-change" |
|||
[valueType]="valueType.DOUBLE" |
|||
[aliasController]="aliasController" |
|||
[targetDevice]="targetDevice" |
|||
[widgetType]="widgetType" |
|||
formControlName="valueChange"></tb-set-value-action-settings> |
|||
</div> |
|||
<div class="tb-form-row"> |
|||
<div class="fixed-title-width" tb-hint-tooltip-icon="{{'widgets.rpc-state.disabled-state-hint' | translate}}" translate>widgets.rpc-state.disabled-state</div> |
|||
<tb-get-value-action-settings fxFlex |
|||
panelTitle="widgets.rpc-state.disabled-state" |
|||
[valueType]="valueType.BOOLEAN" |
|||
stateLabel="widgets.rpc-state.disabled" |
|||
[aliasController]="aliasController" |
|||
[targetDevice]="targetDevice" |
|||
[widgetType]="widgetType" |
|||
formControlName="disabledState"></tb-get-value-action-settings> |
|||
</div> |
|||
</div> |
|||
<div class="tb-form-panel"> |
|||
<div class="tb-form-panel-title" translate>widget-config.appearance</div> |
|||
<tb-image-cards-select rowHeight="2:1" |
|||
[cols]="{columns: 3, |
|||
breakpoints: { |
|||
'lt-sm': 1, |
|||
'lt-md': 2 |
|||
}}" |
|||
label="{{ 'widgets.slider.layout' | translate }}" formControlName="layout"> |
|||
<tb-image-cards-select-option *ngFor="let layout of sliderLayouts" |
|||
[value]="layout" |
|||
[image]="sliderLayoutImageMap.get(layout)"> |
|||
{{ sliderLayoutTranslationMap.get(layout) | translate }} |
|||
</tb-image-cards-select-option> |
|||
</tb-image-cards-select> |
|||
<div class="tb-form-row"> |
|||
<mat-slide-toggle class="mat-slide" formControlName="autoScale"> |
|||
{{ 'widgets.slider.auto-scale' | translate }} |
|||
</mat-slide-toggle> |
|||
</div> |
|||
<div class="tb-form-row column-xs"> |
|||
<mat-slide-toggle class="mat-slide fixed-title-width" formControlName="showTitle"> |
|||
{{ 'widget-config.title' | translate }} |
|||
</mat-slide-toggle> |
|||
<div fxFlex fxLayout="row" fxLayoutAlign="start center" fxLayoutGap="8px"> |
|||
<mat-form-field class="flex" appearance="outline" subscriptSizing="dynamic"> |
|||
<input matInput formControlName="title" placeholder="{{ 'widget-config.set' | translate }}"> |
|||
</mat-form-field> |
|||
<tb-font-settings formControlName="titleFont" |
|||
clearButton |
|||
[previewText]="sliderWidgetConfigForm.get('title').value" |
|||
[initialPreviewStyle]="widgetConfig.config.titleStyle"> |
|||
</tb-font-settings> |
|||
<tb-color-input asBoxInput |
|||
colorClearButton |
|||
formControlName="titleColor"> |
|||
</tb-color-input> |
|||
</div> |
|||
</div> |
|||
<div class="tb-form-row column-xs"> |
|||
<mat-slide-toggle class="mat-slide fixed-title-width" formControlName="showIcon"> |
|||
{{ 'widgets.slider.icon' | translate }} |
|||
</mat-slide-toggle> |
|||
<div fxFlex fxLayout="row" fxLayoutAlign="start center" fxLayoutGap="8px"> |
|||
<mat-form-field appearance="outline" class="flex number" subscriptSizing="dynamic"> |
|||
<input matInput type="number" min="0" formControlName="iconSize" placeholder="{{ 'widget-config.set' | translate }}"> |
|||
</mat-form-field> |
|||
<tb-css-unit-select fxFlex formControlName="iconSizeUnit"></tb-css-unit-select> |
|||
<tb-material-icon-select asBoxInput |
|||
iconClearButton |
|||
[color]="sliderWidgetConfigForm.get('iconColor').value" |
|||
formControlName="icon"> |
|||
</tb-material-icon-select> |
|||
<tb-color-input asBoxInput |
|||
colorClearButton |
|||
formControlName="iconColor"> |
|||
</tb-color-input> |
|||
</div> |
|||
</div> |
|||
<div *ngIf="sliderWidgetConfigForm.get('layout').value !== sliderLayout.simplified" class="tb-form-row column-xs"> |
|||
<mat-slide-toggle class="mat-slide fixed-title-width" formControlName="showValue"> |
|||
{{ 'widgets.slider.value' | translate }} |
|||
</mat-slide-toggle> |
|||
<div fxFlex fxLayout="row" fxLayoutAlign="start center" fxLayoutGap="8px"> |
|||
<tb-unit-input class="flex" formControlName="valueUnits"></tb-unit-input> |
|||
<mat-form-field appearance="outline" class="flex number" subscriptSizing="dynamic"> |
|||
<input matInput formControlName="valueDecimals" type="number" min="0" max="15" step="1" placeholder="{{ 'widget-config.set' | translate }}"> |
|||
<div matSuffix fxHide.lt-md translate>widget-config.decimals-suffix</div> |
|||
</mat-form-field> |
|||
<tb-font-settings formControlName="valueFont" |
|||
[previewText]="valuePreviewFn"> |
|||
</tb-font-settings> |
|||
<tb-color-input asBoxInput |
|||
colorClearButton |
|||
formControlName="valueColor"> |
|||
</tb-color-input> |
|||
</div> |
|||
</div> |
|||
<div class="tb-form-row space-between column-xs"> |
|||
<div>{{ 'widgets.slider.range' | translate }}</div> |
|||
<div fxLayout="row" fxLayoutAlign="start center" fxLayoutGap="8px"> |
|||
<div class="tb-small-label" translate>widgets.slider.min</div> |
|||
<mat-form-field appearance="outline" class="number" subscriptSizing="dynamic"> |
|||
<input matInput formControlName="tickMin" type="number" placeholder="{{ 'widget-config.set' | translate }}"> |
|||
</mat-form-field> |
|||
<div class="tb-small-label" translate>widgets.slider.max</div> |
|||
<mat-form-field appearance="outline" class="number" subscriptSizing="dynamic"> |
|||
<input matInput formControlName="tickMax" type="number" placeholder="{{ 'widget-config.set' | translate }}"> |
|||
</mat-form-field> |
|||
</div> |
|||
</div> |
|||
<div class="tb-form-row space-between"> |
|||
<mat-slide-toggle class="mat-slide" formControlName="showTicks"> |
|||
{{ 'widgets.slider.range-ticks' | translate }} |
|||
</mat-slide-toggle> |
|||
<div fxLayout="row" fxLayoutAlign="start center" fxLayoutGap="8px"> |
|||
<tb-font-settings formControlName="ticksFont" |
|||
previewText="100"> |
|||
</tb-font-settings> |
|||
<tb-color-input asBoxInput |
|||
colorClearButton |
|||
formControlName="ticksColor"> |
|||
</tb-color-input> |
|||
</div> |
|||
</div> |
|||
<div class="tb-form-row space-between"> |
|||
<mat-slide-toggle class="mat-slide" formControlName="showTickMarks"> |
|||
{{ 'widgets.slider.tick-marks' | translate }} |
|||
</mat-slide-toggle> |
|||
<div fxLayout="row" fxLayoutAlign="start center" fxLayoutGap="8px"> |
|||
<mat-form-field appearance="outline" class="number" subscriptSizing="dynamic"> |
|||
<input matInput formControlName="tickMarksCount" type="number" min="2" |
|||
step="1" placeholder="{{ 'widget-config.set' | translate }}"> |
|||
</mat-form-field> |
|||
<tb-color-input asBoxInput |
|||
formControlName="tickMarksColor"> |
|||
</tb-color-input> |
|||
</div> |
|||
</div> |
|||
<div class="tb-form-row space-between column-xs"> |
|||
<div>{{ 'widgets.slider.colors' | translate }}</div> |
|||
<div fxLayout="row" fxLayoutAlign="start center" fxLayoutGap="12px"> |
|||
<div fxLayout="row" fxLayoutAlign="start center" fxLayoutGap="8px"> |
|||
<div translate>widgets.slider.main</div> |
|||
<tb-color-input asBoxInput |
|||
formControlName="mainColor"> |
|||
</tb-color-input> |
|||
</div> |
|||
<mat-divider vertical></mat-divider> |
|||
<div fxLayout="row" fxLayoutAlign="start center" fxLayoutGap="8px"> |
|||
<div translate>widgets.slider.background</div> |
|||
<tb-color-input asBoxInput |
|||
formControlName="backgroundColor"> |
|||
</tb-color-input> |
|||
</div> |
|||
</div> |
|||
</div> |
|||
<div class="tb-form-row space-between column-xs"> |
|||
<div>{{ 'widgets.rpc-state.disabled-state' | translate }}</div> |
|||
<div fxLayout="row" fxLayoutAlign="start center" fxLayoutGap="12px"> |
|||
<div fxLayout="row" fxLayoutAlign="start center" fxLayoutGap="8px"> |
|||
<div translate>widgets.slider.main</div> |
|||
<tb-color-input asBoxInput |
|||
formControlName="mainColorDisabled"> |
|||
</tb-color-input> |
|||
</div> |
|||
<mat-divider vertical></mat-divider> |
|||
<div fxLayout="row" fxLayoutAlign="start center" fxLayoutGap="8px"> |
|||
<div translate>widgets.slider.background</div> |
|||
<tb-color-input asBoxInput |
|||
formControlName="backgroundColorDisabled"> |
|||
</tb-color-input> |
|||
</div> |
|||
</div> |
|||
</div> |
|||
<div *ngIf="sliderWidgetConfigForm.get('layout').value === sliderLayout.extended" |
|||
class="tb-form-row column-xs"> |
|||
<div class="fixed-title-width"> |
|||
{{ 'widgets.slider.left-icon' | translate }} |
|||
</div> |
|||
<div fxFlex fxLayout="row" fxLayoutAlign="start center" fxLayoutGap="8px"> |
|||
<mat-form-field appearance="outline" class="flex number" subscriptSizing="dynamic"> |
|||
<input matInput type="number" min="0" formControlName="leftIconSize" placeholder="{{ 'widget-config.set' | translate }}"> |
|||
</mat-form-field> |
|||
<tb-css-unit-select fxFlex formControlName="leftIconSizeUnit"></tb-css-unit-select> |
|||
<tb-material-icon-select asBoxInput |
|||
[color]="sliderWidgetConfigForm.get('leftIconColor').value" |
|||
formControlName="leftIcon"> |
|||
</tb-material-icon-select> |
|||
<tb-color-input asBoxInput |
|||
formControlName="leftIconColor"> |
|||
</tb-color-input> |
|||
</div> |
|||
</div> |
|||
<div *ngIf="sliderWidgetConfigForm.get('layout').value === sliderLayout.extended" |
|||
class="tb-form-row column-xs"> |
|||
<div class="fixed-title-width"> |
|||
{{ 'widgets.slider.right-icon' | translate }} |
|||
</div> |
|||
<div fxFlex fxLayout="row" fxLayoutAlign="start center" fxLayoutGap="8px"> |
|||
<mat-form-field appearance="outline" class="flex number" subscriptSizing="dynamic"> |
|||
<input matInput type="number" min="0" formControlName="rightIconSize" placeholder="{{ 'widget-config.set' | translate }}"> |
|||
</mat-form-field> |
|||
<tb-css-unit-select fxFlex formControlName="rightIconSizeUnit"></tb-css-unit-select> |
|||
<tb-material-icon-select asBoxInput |
|||
[color]="sliderWidgetConfigForm.get('rightIconColor').value" |
|||
formControlName="rightIcon"> |
|||
</tb-material-icon-select> |
|||
<tb-color-input asBoxInput |
|||
formControlName="rightIconColor"> |
|||
</tb-color-input> |
|||
</div> |
|||
</div> |
|||
</div> |
|||
<div class="tb-form-panel"> |
|||
<div class="tb-form-panel-title" translate>widget-config.card-appearance</div> |
|||
<div class="tb-form-row space-between"> |
|||
<div>{{ 'widgets.background.background' | translate }}</div> |
|||
<tb-background-settings formControlName="background"> |
|||
</tb-background-settings> |
|||
</div> |
|||
<div class="tb-form-row space-between column-lt-md"> |
|||
<div translate>widget-config.show-card-buttons</div> |
|||
<mat-chip-listbox multiple formControlName="cardButtons"> |
|||
<mat-chip-option value="fullscreen">{{ 'fullscreen.fullscreen' | translate }}</mat-chip-option> |
|||
</mat-chip-listbox> |
|||
</div> |
|||
<div class="tb-form-row space-between"> |
|||
<div>{{ 'widget-config.card-border-radius' | translate }}</div> |
|||
<mat-form-field appearance="outline" subscriptSizing="dynamic"> |
|||
<input matInput formControlName="borderRadius" placeholder="{{ 'widget-config.set' | translate }}"> |
|||
</mat-form-field> |
|||
</div> |
|||
</div> |
|||
<tb-widget-actions-panel |
|||
formControlName="actions"> |
|||
</tb-widget-actions-panel> |
|||
</ng-container> |
|||
@ -0,0 +1,309 @@ |
|||
///
|
|||
/// Copyright © 2016-2024 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.
|
|||
///
|
|||
|
|||
import { Component } from '@angular/core'; |
|||
import { UntypedFormBuilder, UntypedFormGroup, Validators } from '@angular/forms'; |
|||
import { Store } from '@ngrx/store'; |
|||
import { AppState } from '@core/core.state'; |
|||
import { BasicWidgetConfigComponent } from '@home/components/widget/config/widget-config.component.models'; |
|||
import { WidgetConfigComponentData } from '@home/models/widget-component.models'; |
|||
import { TargetDevice, WidgetConfig, } from '@shared/models/widget.models'; |
|||
import { WidgetConfigComponent } from '@home/components/widget/widget-config.component'; |
|||
import { formatValue, isUndefined } from '@core/utils'; |
|||
import { ValueType } from '@shared/models/constants'; |
|||
import { |
|||
SliderLayout, |
|||
sliderLayoutImages, |
|||
sliderLayouts, |
|||
sliderLayoutTranslations, |
|||
sliderWidgetDefaultSettings, |
|||
SliderWidgetSettings |
|||
} from '@home/components/widget/lib/rpc/slider-widget.models'; |
|||
import { cssSizeToStrSize, resolveCssSize } from '@shared/models/widget-settings.models'; |
|||
|
|||
@Component({ |
|||
selector: 'tb-slider-basic-config', |
|||
templateUrl: './slider-basic-config.component.html', |
|||
styleUrls: ['../basic-config.scss'] |
|||
}) |
|||
export class SliderBasicConfigComponent extends BasicWidgetConfigComponent { |
|||
|
|||
get targetDevice(): TargetDevice { |
|||
return this.sliderWidgetConfigForm.get('targetDevice').value; |
|||
} |
|||
|
|||
sliderLayout = SliderLayout; |
|||
|
|||
sliderLayouts = sliderLayouts; |
|||
|
|||
sliderLayoutTranslationMap = sliderLayoutTranslations; |
|||
sliderLayoutImageMap = sliderLayoutImages; |
|||
|
|||
valueType = ValueType; |
|||
|
|||
sliderWidgetConfigForm: UntypedFormGroup; |
|||
|
|||
valuePreviewFn = this._valuePreviewFn.bind(this); |
|||
|
|||
constructor(protected store: Store<AppState>, |
|||
protected widgetConfigComponent: WidgetConfigComponent, |
|||
private fb: UntypedFormBuilder) { |
|||
super(store, widgetConfigComponent); |
|||
} |
|||
|
|||
protected configForm(): UntypedFormGroup { |
|||
return this.sliderWidgetConfigForm; |
|||
} |
|||
|
|||
protected onConfigSet(configData: WidgetConfigComponentData) { |
|||
const settings: SliderWidgetSettings = {...sliderWidgetDefaultSettings, ...(configData.config.settings || {})}; |
|||
const iconSize = resolveCssSize(configData.config.iconSize); |
|||
this.sliderWidgetConfigForm = this.fb.group({ |
|||
targetDevice: [configData.config.targetDevice, []], |
|||
|
|||
initialState: [settings.initialState, []], |
|||
valueChange: [settings.valueChange, []], |
|||
disabledState: [settings.disabledState, []], |
|||
|
|||
layout: [settings.layout, []], |
|||
autoScale: [settings.autoScale, []], |
|||
|
|||
showTitle: [configData.config.showTitle, []], |
|||
title: [configData.config.title, []], |
|||
titleFont: [configData.config.titleFont, []], |
|||
titleColor: [configData.config.titleColor, []], |
|||
|
|||
showIcon: [configData.config.showTitleIcon, []], |
|||
iconSize: [iconSize[0], [Validators.min(0)]], |
|||
iconSizeUnit: [iconSize[1], []], |
|||
icon: [configData.config.titleIcon, []], |
|||
iconColor: [configData.config.iconColor, []], |
|||
|
|||
showValue: [settings.showValue, []], |
|||
valueUnits: [settings.valueUnits, []], |
|||
valueDecimals: [settings.valueDecimals, []], |
|||
valueFont: [settings.valueFont, []], |
|||
valueColor: [settings.valueColor, []], |
|||
|
|||
tickMin: [settings.tickMin, []], |
|||
tickMax: [settings.tickMax, []], |
|||
|
|||
showTicks: [settings.showTicks, []], |
|||
ticksFont: [settings.ticksFont, []], |
|||
ticksColor: [settings.ticksColor, []], |
|||
|
|||
showTickMarks: [settings.showTickMarks, []], |
|||
tickMarksCount: [settings.tickMarksCount, [Validators.min(2)]], |
|||
tickMarksColor: [settings.tickMarksColor, []], |
|||
|
|||
mainColor: [settings.mainColor, []], |
|||
backgroundColor: [settings.backgroundColor, []], |
|||
|
|||
mainColorDisabled: [settings.mainColorDisabled, []], |
|||
backgroundColorDisabled: [settings.backgroundColorDisabled, []], |
|||
|
|||
leftIconSize: [settings.leftIconSize, [Validators.min(0)]], |
|||
leftIconSizeUnit: [settings.leftIconSizeUnit, []], |
|||
leftIcon: [settings.leftIcon, []], |
|||
leftIconColor: [settings.leftIconColor, []], |
|||
|
|||
rightIconSize: [settings.rightIconSize, [Validators.min(0)]], |
|||
rightIconSizeUnit: [settings.rightIconSizeUnit, []], |
|||
rightIcon: [settings.rightIcon, []], |
|||
rightIconColor: [settings.rightIconColor, []], |
|||
|
|||
background: [settings.background, []], |
|||
|
|||
cardButtons: [this.getCardButtons(configData.config), []], |
|||
borderRadius: [configData.config.borderRadius, []], |
|||
|
|||
actions: [configData.config.actions || {}, []] |
|||
}); |
|||
} |
|||
|
|||
protected prepareOutputConfig(config: any): WidgetConfigComponentData { |
|||
this.widgetConfig.config.targetDevice = config.targetDevice; |
|||
|
|||
this.widgetConfig.config.showTitle = config.showTitle; |
|||
this.widgetConfig.config.title = config.title; |
|||
this.widgetConfig.config.titleFont = config.titleFont; |
|||
this.widgetConfig.config.titleColor = config.titleColor; |
|||
|
|||
this.widgetConfig.config.showTitleIcon = config.showIcon; |
|||
this.widgetConfig.config.iconSize = cssSizeToStrSize(config.iconSize, config.iconSizeUnit); |
|||
this.widgetConfig.config.titleIcon = config.icon; |
|||
this.widgetConfig.config.iconColor = config.iconColor; |
|||
|
|||
this.widgetConfig.config.settings = this.widgetConfig.config.settings || {}; |
|||
|
|||
this.widgetConfig.config.settings.initialState = config.initialState; |
|||
this.widgetConfig.config.settings.valueChange = config.valueChange; |
|||
this.widgetConfig.config.settings.disabledState = config.disabledState; |
|||
|
|||
this.widgetConfig.config.settings.layout = config.layout; |
|||
this.widgetConfig.config.settings.autoScale = config.autoScale; |
|||
|
|||
this.widgetConfig.config.settings.showValue = config.showValue; |
|||
this.widgetConfig.config.settings.valueUnits = config.valueUnits; |
|||
this.widgetConfig.config.settings.valueDecimals = config.valueDecimals; |
|||
this.widgetConfig.config.settings.valueFont = config.valueFont; |
|||
this.widgetConfig.config.settings.valueColor = config.valueColor; |
|||
|
|||
this.widgetConfig.config.settings.tickMin = config.tickMin; |
|||
this.widgetConfig.config.settings.tickMax = config.tickMax; |
|||
|
|||
this.widgetConfig.config.settings.showTicks = config.showTicks; |
|||
this.widgetConfig.config.settings.ticksFont = config.ticksFont; |
|||
this.widgetConfig.config.settings.ticksColor = config.ticksColor; |
|||
|
|||
this.widgetConfig.config.settings.showTickMarks = config.showTickMarks; |
|||
this.widgetConfig.config.settings.tickMarksCount = config.tickMarksCount; |
|||
this.widgetConfig.config.settings.tickMarksColor = config.tickMarksColor; |
|||
|
|||
this.widgetConfig.config.settings.mainColor = config.mainColor; |
|||
this.widgetConfig.config.settings.backgroundColor = config.backgroundColor; |
|||
|
|||
this.widgetConfig.config.settings.mainColorDisabled = config.mainColorDisabled; |
|||
this.widgetConfig.config.settings.backgroundColorDisabled = config.backgroundColorDisabled; |
|||
|
|||
this.widgetConfig.config.settings.leftIconSize = config.leftIconSize; |
|||
this.widgetConfig.config.settings.leftIconSizeUnit = config.leftIconSizeUnit; |
|||
this.widgetConfig.config.settings.leftIcon = config.leftIcon; |
|||
this.widgetConfig.config.settings.leftIconColor = config.leftIconColor; |
|||
|
|||
this.widgetConfig.config.settings.rightIconSize = config.rightIconSize; |
|||
this.widgetConfig.config.settings.rightIconSizeUnit = config.rightIconSizeUnit; |
|||
this.widgetConfig.config.settings.rightIcon = config.rightIcon; |
|||
this.widgetConfig.config.settings.rightIconColor = config.rightIconColor; |
|||
|
|||
this.widgetConfig.config.settings.background = config.background; |
|||
|
|||
this.setCardButtons(config.cardButtons, this.widgetConfig.config); |
|||
this.widgetConfig.config.borderRadius = config.borderRadius; |
|||
|
|||
this.widgetConfig.config.actions = config.actions; |
|||
return this.widgetConfig; |
|||
} |
|||
|
|||
protected validatorTriggers(): string[] { |
|||
return ['showTitle', 'showIcon', 'showValue', 'showTicks', 'showTickMarks', 'layout']; |
|||
} |
|||
|
|||
protected updateValidators(emitEvent: boolean, trigger?: string) { |
|||
const showTitle: boolean = this.sliderWidgetConfigForm.get('showTitle').value; |
|||
const showIcon: boolean = this.sliderWidgetConfigForm.get('showIcon').value; |
|||
const showValue: boolean = this.sliderWidgetConfigForm.get('showValue').value; |
|||
const showTicks: boolean = this.sliderWidgetConfigForm.get('showTicks').value; |
|||
const showTickMarks: boolean = this.sliderWidgetConfigForm.get('showTickMarks').value; |
|||
const layout: SliderLayout = this.sliderWidgetConfigForm.get('layout').value; |
|||
|
|||
const valueEnabled = layout !== SliderLayout.simplified; |
|||
const leftRightIconsEnabled = layout === SliderLayout.extended; |
|||
|
|||
if (showTitle) { |
|||
this.sliderWidgetConfigForm.get('title').enable(); |
|||
this.sliderWidgetConfigForm.get('titleFont').enable(); |
|||
this.sliderWidgetConfigForm.get('titleColor').enable(); |
|||
this.sliderWidgetConfigForm.get('showIcon').enable({emitEvent: false}); |
|||
if (showIcon) { |
|||
this.sliderWidgetConfigForm.get('iconSize').enable(); |
|||
this.sliderWidgetConfigForm.get('iconSizeUnit').enable(); |
|||
this.sliderWidgetConfigForm.get('icon').enable(); |
|||
this.sliderWidgetConfigForm.get('iconColor').enable(); |
|||
} else { |
|||
this.sliderWidgetConfigForm.get('iconSize').disable(); |
|||
this.sliderWidgetConfigForm.get('iconSizeUnit').disable(); |
|||
this.sliderWidgetConfigForm.get('icon').disable(); |
|||
this.sliderWidgetConfigForm.get('iconColor').disable(); |
|||
} |
|||
} else { |
|||
this.sliderWidgetConfigForm.get('title').disable(); |
|||
this.sliderWidgetConfigForm.get('titleFont').disable(); |
|||
this.sliderWidgetConfigForm.get('titleColor').disable(); |
|||
this.sliderWidgetConfigForm.get('showIcon').disable({emitEvent: false}); |
|||
this.sliderWidgetConfigForm.get('iconSize').disable(); |
|||
this.sliderWidgetConfigForm.get('iconSizeUnit').disable(); |
|||
this.sliderWidgetConfigForm.get('icon').disable(); |
|||
this.sliderWidgetConfigForm.get('iconColor').disable(); |
|||
} |
|||
|
|||
if (valueEnabled && showValue) { |
|||
this.sliderWidgetConfigForm.get('valueUnits').enable(); |
|||
this.sliderWidgetConfigForm.get('valueDecimals').enable(); |
|||
this.sliderWidgetConfigForm.get('valueFont').enable(); |
|||
this.sliderWidgetConfigForm.get('valueColor').enable(); |
|||
} else { |
|||
this.sliderWidgetConfigForm.get('valueUnits').disable(); |
|||
this.sliderWidgetConfigForm.get('valueDecimals').disable(); |
|||
this.sliderWidgetConfigForm.get('valueFont').disable(); |
|||
this.sliderWidgetConfigForm.get('valueColor').disable(); |
|||
} |
|||
|
|||
if (showTicks) { |
|||
this.sliderWidgetConfigForm.get('ticksFont').enable(); |
|||
this.sliderWidgetConfigForm.get('ticksColor').enable(); |
|||
} else { |
|||
this.sliderWidgetConfigForm.get('ticksFont').disable(); |
|||
this.sliderWidgetConfigForm.get('ticksColor').disable(); |
|||
} |
|||
|
|||
if (showTickMarks) { |
|||
this.sliderWidgetConfigForm.get('tickMarksCount').enable(); |
|||
this.sliderWidgetConfigForm.get('tickMarksColor').enable(); |
|||
} else { |
|||
this.sliderWidgetConfigForm.get('tickMarksCount').disable(); |
|||
this.sliderWidgetConfigForm.get('tickMarksColor').disable(); |
|||
} |
|||
|
|||
if (leftRightIconsEnabled) { |
|||
this.sliderWidgetConfigForm.get('leftIconSize').enable(); |
|||
this.sliderWidgetConfigForm.get('leftIconSizeUnit').enable(); |
|||
this.sliderWidgetConfigForm.get('leftIcon').enable(); |
|||
this.sliderWidgetConfigForm.get('leftIconColor').enable(); |
|||
this.sliderWidgetConfigForm.get('rightIconSize').enable(); |
|||
this.sliderWidgetConfigForm.get('rightIconSizeUnit').enable(); |
|||
this.sliderWidgetConfigForm.get('rightIcon').enable(); |
|||
this.sliderWidgetConfigForm.get('rightIconColor').enable(); |
|||
} else { |
|||
this.sliderWidgetConfigForm.get('leftIconSize').disable(); |
|||
this.sliderWidgetConfigForm.get('leftIconSizeUnit').disable(); |
|||
this.sliderWidgetConfigForm.get('leftIcon').disable(); |
|||
this.sliderWidgetConfigForm.get('leftIconColor').disable(); |
|||
this.sliderWidgetConfigForm.get('rightIconSize').disable(); |
|||
this.sliderWidgetConfigForm.get('rightIconSizeUnit').disable(); |
|||
this.sliderWidgetConfigForm.get('rightIcon').disable(); |
|||
this.sliderWidgetConfigForm.get('rightIconColor').disable(); |
|||
} |
|||
} |
|||
|
|||
private getCardButtons(config: WidgetConfig): string[] { |
|||
const buttons: string[] = []; |
|||
if (isUndefined(config.enableFullscreen) || config.enableFullscreen) { |
|||
buttons.push('fullscreen'); |
|||
} |
|||
return buttons; |
|||
} |
|||
|
|||
private setCardButtons(buttons: string[], config: WidgetConfig) { |
|||
config.enableFullscreen = buttons.includes('fullscreen'); |
|||
} |
|||
|
|||
private _valuePreviewFn(): string { |
|||
const units: string = this.sliderWidgetConfigForm.get('valueUnits').value; |
|||
const decimals: number = this.sliderWidgetConfigForm.get('valueDecimals').value; |
|||
return formatValue(48, decimals, units, false); |
|||
} |
|||
} |
|||
@ -0,0 +1,26 @@ |
|||
<!-- |
|||
|
|||
Copyright © 2016-2024 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. |
|||
|
|||
--> |
|||
<div class="tb-power-button-panel" [style]="backgroundStyle$ | async"> |
|||
<div class="tb-power-button-overlay" [style]="overlayStyle"></div> |
|||
<ng-container *ngTemplateOutlet="widgetTitlePanel"></ng-container> |
|||
<div class="tb-power-button-content"> |
|||
<div #powerButtonShape class="tb-power-button-shape" [class.tb-power-button-pointer]="!disabled && (loading$ | async) === false"> |
|||
</div> |
|||
</div> |
|||
<mat-progress-bar class="tb-action-widget-progress" style="height: 4px;" color="accent" mode="indeterminate" *ngIf="loading$ | async"></mat-progress-bar> |
|||
</div> |
|||
@ -0,0 +1,64 @@ |
|||
/** |
|||
* Copyright © 2016-2024 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. |
|||
*/ |
|||
.tb-power-button-panel { |
|||
width: 100%; |
|||
height: 100%; |
|||
position: relative; |
|||
display: flex; |
|||
flex-direction: column; |
|||
gap: 16px; |
|||
padding: 20px 24px 24px 24px; |
|||
> div:not(.tb-power-button-overlay) { |
|||
z-index: 1; |
|||
} |
|||
.tb-power-button-overlay { |
|||
position: absolute; |
|||
top: 12px; |
|||
left: 12px; |
|||
bottom: 12px; |
|||
right: 12px; |
|||
} |
|||
div.tb-widget-title { |
|||
padding: 0; |
|||
} |
|||
.tb-power-button-content { |
|||
flex: 1; |
|||
min-width: 0; |
|||
min-height: 0; |
|||
.tb-power-button-shape { |
|||
width: 100%; |
|||
height: 100%; |
|||
display: flex; |
|||
align-items: center; |
|||
justify-content: center; |
|||
svg { |
|||
.tb-small-shadow { |
|||
filter: drop-shadow(0px 0px 4px rgba(0, 0, 0, 0.2)); |
|||
} |
|||
.tb-shadow { |
|||
filter: drop-shadow(0px 0px 10px rgba(0, 0, 0, 0.15)); |
|||
} |
|||
} |
|||
&.tb-power-button-pointer { |
|||
svg { |
|||
.tb-hover-circle { |
|||
cursor: pointer; |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,203 @@ |
|||
///
|
|||
/// Copyright © 2016-2024 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.
|
|||
///
|
|||
|
|||
import { |
|||
AfterViewInit, |
|||
ChangeDetectorRef, |
|||
Component, |
|||
ElementRef, |
|||
OnDestroy, |
|||
OnInit, |
|||
Renderer2, |
|||
ViewChild, |
|||
ViewEncapsulation |
|||
} from '@angular/core'; |
|||
import { BasicActionWidgetComponent, ValueSetter } from '@home/components/widget/lib/action/action-widget.models'; |
|||
import { backgroundStyle, ComponentStyle, overlayStyle } from '@shared/models/widget-settings.models'; |
|||
import { Observable } from 'rxjs'; |
|||
import { ResizeObserver } from '@juggle/resize-observer'; |
|||
import { ImagePipe } from '@shared/pipe/image.pipe'; |
|||
import { DomSanitizer } from '@angular/platform-browser'; |
|||
import { ValueType } from '@shared/models/constants'; |
|||
import { |
|||
powerButtonDefaultSettings, |
|||
PowerButtonShape, |
|||
powerButtonShapeSize, |
|||
PowerButtonWidgetSettings |
|||
} from '@home/components/widget/lib/rpc/power-button-widget.models'; |
|||
import { SVG, Svg } from '@svgdotjs/svg.js'; |
|||
|
|||
@Component({ |
|||
selector: 'tb-power-button-widget', |
|||
templateUrl: './power-button-widget.component.html', |
|||
styleUrls: ['../action/action-widget.scss', './power-button-widget.component.scss'], |
|||
encapsulation: ViewEncapsulation.None |
|||
}) |
|||
export class PowerButtonWidgetComponent extends |
|||
BasicActionWidgetComponent implements OnInit, AfterViewInit, OnDestroy { |
|||
|
|||
@ViewChild('powerButtonShape', {static: false}) |
|||
powerButtonShape: ElementRef<HTMLElement>; |
|||
|
|||
settings: PowerButtonWidgetSettings; |
|||
|
|||
backgroundStyle$: Observable<ComponentStyle>; |
|||
overlayStyle: ComponentStyle = {}; |
|||
|
|||
value = false; |
|||
disabled = false; |
|||
|
|||
private shapeResize$: ResizeObserver; |
|||
private drawSvgShapePending = false; |
|||
private svgShape: Svg; |
|||
private powerButtonSvgShape: PowerButtonShape; |
|||
private disabledState = false; |
|||
|
|||
private onValueSetter: ValueSetter<boolean>; |
|||
private offValueSetter: ValueSetter<boolean>; |
|||
|
|||
constructor(protected imagePipe: ImagePipe, |
|||
protected sanitizer: DomSanitizer, |
|||
private renderer: Renderer2, |
|||
protected cd: ChangeDetectorRef) { |
|||
super(cd); |
|||
} |
|||
|
|||
ngOnInit(): void { |
|||
super.ngOnInit(); |
|||
this.settings = {...powerButtonDefaultSettings, ...this.ctx.settings}; |
|||
|
|||
this.backgroundStyle$ = backgroundStyle(this.settings.background, this.imagePipe, this.sanitizer); |
|||
this.overlayStyle = overlayStyle(this.settings.background.overlay); |
|||
|
|||
const getInitialStateSettings = |
|||
{...this.settings.initialState, actionLabel: this.ctx.translate.instant('widgets.rpc-state.initial-state')}; |
|||
this.createValueGetter(getInitialStateSettings, ValueType.BOOLEAN, { |
|||
next: (value) => this.onValue(value) |
|||
}); |
|||
|
|||
const disabledStateSettings = |
|||
{...this.settings.disabledState, actionLabel: this.ctx.translate.instant('widgets.rpc-state.disabled-state')}; |
|||
this.createValueGetter(disabledStateSettings, ValueType.BOOLEAN, { |
|||
next: (value) => this.onDisabled(value) |
|||
}); |
|||
|
|||
const onUpdateStateSettings = {...this.settings.onUpdateState, |
|||
actionLabel: this.ctx.translate.instant('widgets.power-button.power-on')}; |
|||
this.onValueSetter = this.createValueSetter(onUpdateStateSettings); |
|||
|
|||
const offUpdateStateSettings = {...this.settings.offUpdateState, |
|||
actionLabel: this.ctx.translate.instant('widgets.power-button.power-off')}; |
|||
this.offValueSetter = this.createValueSetter(offUpdateStateSettings); |
|||
|
|||
this.loading$.subscribe((loading) => { |
|||
this.updateDisabledState(loading || this.disabled); |
|||
this.cd.markForCheck(); |
|||
}); |
|||
} |
|||
|
|||
ngAfterViewInit(): void { |
|||
if (this.drawSvgShapePending) { |
|||
this.drawSvg(); |
|||
} |
|||
super.ngAfterViewInit(); |
|||
} |
|||
|
|||
ngOnDestroy() { |
|||
if (this.shapeResize$) { |
|||
this.shapeResize$.disconnect(); |
|||
} |
|||
super.ngOnDestroy(); |
|||
} |
|||
|
|||
public onInit() { |
|||
super.onInit(); |
|||
const borderRadius = this.ctx.$widgetElement.css('borderRadius'); |
|||
this.overlayStyle = {...this.overlayStyle, ...{borderRadius}}; |
|||
if (this.powerButtonShape) { |
|||
this.drawSvg(); |
|||
} else { |
|||
this.drawSvgShapePending = true; |
|||
} |
|||
this.cd.detectChanges(); |
|||
} |
|||
|
|||
private onValue(value: boolean): void { |
|||
const newValue = !!value; |
|||
if (this.value !== newValue) { |
|||
this.value = newValue; |
|||
this.powerButtonSvgShape?.setValue(this.value); |
|||
this.cd.markForCheck(); |
|||
} |
|||
} |
|||
|
|||
private onDisabled(value: boolean): void { |
|||
const newDisabled = !!value; |
|||
if (this.disabled !== newDisabled) { |
|||
this.disabled = newDisabled; |
|||
this.updateDisabledState(this.disabled); |
|||
this.cd.markForCheck(); |
|||
} |
|||
} |
|||
|
|||
private onClick() { |
|||
if (!this.ctx.isEdit && !this.ctx.isPreview && !this.disabledState) { |
|||
this.onValue(!this.value); |
|||
const targetValue = this.value; |
|||
const targetSetter = targetValue ? this.onValueSetter : this.offValueSetter; |
|||
this.powerButtonSvgShape?.setPressed(true); |
|||
this.updateValue(targetSetter, targetValue, { |
|||
next: () => { |
|||
this.powerButtonSvgShape?.setPressed(false); |
|||
this.onValue(targetValue); |
|||
}, |
|||
error: () => { |
|||
this.powerButtonSvgShape?.setPressed(false); |
|||
this.onValue(!targetValue); |
|||
} |
|||
}); |
|||
} |
|||
} |
|||
|
|||
private drawSvg() { |
|||
this.svgShape = SVG().addTo(this.powerButtonShape.nativeElement).size(powerButtonShapeSize, powerButtonShapeSize); |
|||
this.renderer.setStyle(this.svgShape.node, 'overflow', 'visible'); |
|||
this.renderer.setStyle(this.svgShape.node, 'user-select', 'none'); |
|||
|
|||
this.powerButtonSvgShape = PowerButtonShape.fromSettings(this.ctx, this.svgShape, |
|||
this.settings, this.value, this.disabledState, () => this.onClick()); |
|||
|
|||
this.shapeResize$ = new ResizeObserver(() => { |
|||
this.onResize(); |
|||
}); |
|||
this.shapeResize$.observe(this.powerButtonShape.nativeElement); |
|||
this.onResize(); |
|||
} |
|||
|
|||
private updateDisabledState(disabled: boolean) { |
|||
this.disabledState = disabled; |
|||
this.powerButtonSvgShape?.setDisabled(this.disabledState); |
|||
} |
|||
|
|||
private onResize() { |
|||
const shapeWidth = this.powerButtonShape.nativeElement.getBoundingClientRect().width; |
|||
const shapeHeight = this.powerButtonShape.nativeElement.getBoundingClientRect().height; |
|||
const size = Math.min(shapeWidth, shapeHeight); |
|||
const scale = size / powerButtonShapeSize; |
|||
this.renderer.setStyle(this.svgShape.node, 'transform', `scale(${scale})`); |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,953 @@ |
|||
///
|
|||
/// Copyright © 2016-2024 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.
|
|||
///
|
|||
|
|||
import { BackgroundSettings, BackgroundType } from '@shared/models/widget-settings.models'; |
|||
import { AttributeScope } from '@shared/models/telemetry/telemetry.models'; |
|||
import { |
|||
DataToValueType, |
|||
GetValueAction, |
|||
GetValueSettings, |
|||
SetValueAction, |
|||
SetValueSettings, |
|||
ValueToDataType |
|||
} from '@shared/models/action-widget-settings.models'; |
|||
import { Circle, Effect, Element, G, Gradient, Runner, Svg, Text, Timeline } from '@svgdotjs/svg.js'; |
|||
import '@svgdotjs/svg.filter.js'; |
|||
import tinycolor from 'tinycolor2'; |
|||
import { WidgetContext } from '@home/models/widget-component.models'; |
|||
|
|||
export enum PowerButtonLayout { |
|||
default = 'default', |
|||
simplified = 'simplified', |
|||
outlined = 'outlined', |
|||
default_volume = 'default_volume', |
|||
simplified_volume = 'simplified_volume', |
|||
outlined_volume = 'outlined_volume' |
|||
} |
|||
|
|||
export const powerButtonLayouts = Object.keys(PowerButtonLayout) as PowerButtonLayout[]; |
|||
|
|||
export const powerButtonLayoutTranslations = new Map<PowerButtonLayout, string>( |
|||
[ |
|||
[PowerButtonLayout.default, 'widgets.power-button.layout-default'], |
|||
[PowerButtonLayout.simplified, 'widgets.power-button.layout-simplified'], |
|||
[PowerButtonLayout.outlined, 'widgets.power-button.layout-outlined'], |
|||
[PowerButtonLayout.default_volume, 'widgets.power-button.layout-default-volume'], |
|||
[PowerButtonLayout.simplified_volume, 'widgets.power-button.layout-simplified-volume'], |
|||
[PowerButtonLayout.outlined_volume, 'widgets.power-button.layout-outlined-volume'] |
|||
] |
|||
); |
|||
|
|||
export const powerButtonLayoutImages = new Map<PowerButtonLayout, string>( |
|||
[ |
|||
[PowerButtonLayout.default, 'assets/widget/power-button/default-layout.svg'], |
|||
[PowerButtonLayout.simplified, 'assets/widget/power-button/simplified-layout.svg'], |
|||
[PowerButtonLayout.outlined, 'assets/widget/power-button/outlined-layout.svg'], |
|||
[PowerButtonLayout.default_volume, 'assets/widget/power-button/default-volume-layout.svg'], |
|||
[PowerButtonLayout.simplified_volume, 'assets/widget/power-button/simplified-volume-layout.svg'], |
|||
[PowerButtonLayout.outlined_volume, 'assets/widget/power-button/outlined-volume-layout.svg'] |
|||
] |
|||
); |
|||
|
|||
export interface PowerButtonWidgetSettings { |
|||
initialState: GetValueSettings<boolean>; |
|||
disabledState: GetValueSettings<boolean>; |
|||
onUpdateState: SetValueSettings; |
|||
offUpdateState: SetValueSettings; |
|||
layout: PowerButtonLayout; |
|||
mainColorOn: string; |
|||
backgroundColorOn: string; |
|||
mainColorOff: string; |
|||
backgroundColorOff: string; |
|||
mainColorDisabled: string; |
|||
backgroundColorDisabled: string; |
|||
background: BackgroundSettings; |
|||
} |
|||
|
|||
export const powerButtonDefaultSettings: PowerButtonWidgetSettings = { |
|||
initialState: { |
|||
action: GetValueAction.EXECUTE_RPC, |
|||
defaultValue: false, |
|||
executeRpc: { |
|||
method: 'getState', |
|||
requestTimeout: 5000, |
|||
requestPersistent: false, |
|||
persistentPollingInterval: 1000 |
|||
}, |
|||
getAttribute: { |
|||
key: 'state', |
|||
scope: null |
|||
}, |
|||
getTimeSeries: { |
|||
key: 'state' |
|||
}, |
|||
dataToValue: { |
|||
type: DataToValueType.NONE, |
|||
compareToValue: true, |
|||
dataToValueFunction: '/* Should return boolean value */\nreturn data;' |
|||
} |
|||
}, |
|||
disabledState: { |
|||
action: GetValueAction.DO_NOTHING, |
|||
defaultValue: false, |
|||
getAttribute: { |
|||
key: 'state', |
|||
scope: null |
|||
}, |
|||
getTimeSeries: { |
|||
key: 'state' |
|||
}, |
|||
dataToValue: { |
|||
type: DataToValueType.NONE, |
|||
compareToValue: true, |
|||
dataToValueFunction: '/* Should return boolean value */\nreturn data;' |
|||
} |
|||
}, |
|||
onUpdateState: { |
|||
action: SetValueAction.EXECUTE_RPC, |
|||
executeRpc: { |
|||
method: 'setState', |
|||
requestTimeout: 5000, |
|||
requestPersistent: false, |
|||
persistentPollingInterval: 1000 |
|||
}, |
|||
setAttribute: { |
|||
key: 'state', |
|||
scope: AttributeScope.SHARED_SCOPE |
|||
}, |
|||
putTimeSeries: { |
|||
key: 'state' |
|||
}, |
|||
valueToData: { |
|||
type: ValueToDataType.CONSTANT, |
|||
constantValue: true, |
|||
valueToDataFunction: '/* Convert input boolean value to RPC parameters or attribute/time-series value */\nreturn value;' |
|||
} |
|||
}, |
|||
offUpdateState: { |
|||
action: SetValueAction.EXECUTE_RPC, |
|||
executeRpc: { |
|||
method: 'setState', |
|||
requestTimeout: 5000, |
|||
requestPersistent: false, |
|||
persistentPollingInterval: 1000 |
|||
}, |
|||
setAttribute: { |
|||
key: 'state', |
|||
scope: AttributeScope.SHARED_SCOPE |
|||
}, |
|||
putTimeSeries: { |
|||
key: 'state' |
|||
}, |
|||
valueToData: { |
|||
type: ValueToDataType.CONSTANT, |
|||
constantValue: false, |
|||
valueToDataFunction: '/* Convert input boolean value to RPC parameters or attribute/time-series value */ \n return value;' |
|||
} |
|||
}, |
|||
layout: PowerButtonLayout.default, |
|||
mainColorOn: '#3F52DD', |
|||
backgroundColorOn: '#FFFFFF', |
|||
mainColorOff: '#A2A2A2', |
|||
backgroundColorOff: '#FFFFFF', |
|||
mainColorDisabled: 'rgba(0,0,0,0.12)', |
|||
backgroundColorDisabled: '#FFFFFF', |
|||
background: { |
|||
type: BackgroundType.color, |
|||
color: '#fff', |
|||
overlay: { |
|||
enabled: false, |
|||
color: 'rgba(255,255,255,0.72)', |
|||
blur: 3 |
|||
} |
|||
} |
|||
}; |
|||
|
|||
interface PowerButtonColor { |
|||
hex: string; |
|||
opacity: number; |
|||
} |
|||
|
|||
type PowerButtonState = 'on' | 'off' | 'disabled'; |
|||
|
|||
interface PowerButtonColorState { |
|||
mainColor: PowerButtonColor; |
|||
backgroundColor: PowerButtonColor; |
|||
} |
|||
|
|||
type PowerButtonShapeColors = Record<PowerButtonState, PowerButtonColorState>; |
|||
|
|||
const createPowerButtonShapeColors = (settings: PowerButtonWidgetSettings): PowerButtonShapeColors => { |
|||
const mainColorOn = tinycolor(settings.mainColorOn); |
|||
const backgroundColorOn = tinycolor(settings.backgroundColorOn); |
|||
const mainColorOff = tinycolor(settings.mainColorOff); |
|||
const backgroundColorOff = tinycolor(settings.backgroundColorOff); |
|||
const mainColorDisabled = tinycolor(settings.mainColorDisabled); |
|||
const backgroundColorDisabled = tinycolor(settings.backgroundColorDisabled); |
|||
return { |
|||
on: { |
|||
mainColor: {hex: mainColorOn.toHexString(), opacity: mainColorOn.getAlpha()}, |
|||
backgroundColor: {hex: backgroundColorOn.toHexString(), opacity: backgroundColorOn.getAlpha()}, |
|||
}, |
|||
off: { |
|||
mainColor: {hex: mainColorOff.toHexString(), opacity: mainColorOff.getAlpha()}, |
|||
backgroundColor: {hex: backgroundColorOff.toHexString(), opacity: backgroundColorOff.getAlpha()}, |
|||
}, |
|||
disabled: { |
|||
mainColor: {hex: mainColorDisabled.toHexString(), opacity: mainColorDisabled.getAlpha()}, |
|||
backgroundColor: {hex: backgroundColorDisabled.toHexString(), opacity: backgroundColorDisabled.getAlpha()}, |
|||
} |
|||
}; |
|||
}; |
|||
|
|||
export const powerButtonShapeSize = 110; |
|||
const cx = powerButtonShapeSize / 2; |
|||
const cy = powerButtonShapeSize / 2; |
|||
|
|||
const powerButtonAnimation = (element: Element): Runner => element.animate(200, 0, 'now'); |
|||
|
|||
export abstract class PowerButtonShape { |
|||
|
|||
static fromSettings(ctx: WidgetContext, |
|||
svgShape: Svg, |
|||
settings: PowerButtonWidgetSettings, |
|||
value: boolean, |
|||
disabled: boolean, |
|||
onClick: () => void): PowerButtonShape { |
|||
switch (settings.layout) { |
|||
case PowerButtonLayout.default: |
|||
return new DefaultPowerButtonShape(ctx, svgShape, settings, value, disabled, onClick); |
|||
case PowerButtonLayout.simplified: |
|||
return new SimplifiedPowerButtonShape(ctx, svgShape, settings, value, disabled, onClick); |
|||
case PowerButtonLayout.outlined: |
|||
return new OutlinedPowerButtonShape(ctx, svgShape, settings, value, disabled, onClick); |
|||
case PowerButtonLayout.default_volume: |
|||
return new DefaultVolumePowerButtonShape(ctx, svgShape, settings, value, disabled, onClick); |
|||
case PowerButtonLayout.simplified_volume: |
|||
return new SimplifiedVolumePowerButtonShape(ctx, svgShape, settings, value, disabled, onClick); |
|||
case PowerButtonLayout.outlined_volume: |
|||
return new OutlinedVolumePowerButtonShape(ctx, svgShape, settings, value, disabled, onClick); |
|||
} |
|||
} |
|||
|
|||
protected readonly colors: PowerButtonShapeColors; |
|||
protected readonly onLabel: string; |
|||
protected readonly offLabel: string; |
|||
|
|||
protected backgroundShape: Circle; |
|||
protected hoverShape: Circle; |
|||
protected hovered = false; |
|||
protected pressed = false; |
|||
protected forcePressed = false; |
|||
|
|||
protected constructor(protected widgetContext: WidgetContext, |
|||
protected svgShape: Svg, |
|||
protected settings: PowerButtonWidgetSettings, |
|||
protected value: boolean, |
|||
protected disabled: boolean, |
|||
protected onClick: () => void) { |
|||
this.colors = createPowerButtonShapeColors(this.settings); |
|||
this.onLabel = this.widgetContext.translate.instant('widgets.power-button.on-label').toUpperCase(); |
|||
this.offLabel = this.widgetContext.translate.instant('widgets.power-button.off-label').toUpperCase(); |
|||
this._drawShape(); |
|||
} |
|||
|
|||
public setValue(value: boolean) { |
|||
if (this.value !== value) { |
|||
this.value = value; |
|||
this._drawState(); |
|||
} |
|||
} |
|||
|
|||
public setDisabled(disabled: boolean) { |
|||
if (this.disabled !== disabled) { |
|||
this.disabled = disabled; |
|||
this._drawState(); |
|||
} |
|||
} |
|||
|
|||
public setPressed(pressed: boolean) { |
|||
if (this.forcePressed !== pressed) { |
|||
this.forcePressed = pressed; |
|||
if (this.forcePressed && !this.pressed) { |
|||
this.onPressStart(); |
|||
} else if (!this.forcePressed && !this.pressed) { |
|||
this.onPressEnd(); |
|||
} |
|||
} |
|||
} |
|||
|
|||
private _drawShape() { |
|||
|
|||
this.backgroundShape = this.svgShape.circle(powerButtonShapeSize).center(cx, cy) |
|||
.fill({opacity: 0}).stroke({width: 0}); |
|||
|
|||
this.drawShape(); |
|||
|
|||
this.hoverShape = this.svgShape.circle(powerButtonShapeSize).center(cx, cy).addClass('tb-hover-circle') |
|||
.fill({color: '#000000', opacity: 0}); |
|||
this.hoverShape.on('mouseover', () => { |
|||
this.hovered = true; |
|||
if (!this.disabled) { |
|||
this.hoverShape.timeline().finish(); |
|||
this.hoverShape.animate(200).attr({'fill-opacity': 0.06}); |
|||
} |
|||
}); |
|||
this.hoverShape.on('mouseout', () => { |
|||
this.hovered = false; |
|||
this.hoverShape.timeline().finish(); |
|||
this.hoverShape.animate(200).attr({'fill-opacity': 0}); |
|||
this._cancelPressed(); |
|||
}); |
|||
this.hoverShape.on('touchmove', (event: TouchEvent) => { |
|||
const touch = event.touches[0]; |
|||
const element = document.elementFromPoint(touch.pageX,touch.pageY); |
|||
if (this.hoverShape.node !== element) { |
|||
this._cancelPressed(); |
|||
} |
|||
}); |
|||
this.hoverShape.on('touchcancel', () => { |
|||
this._cancelPressed(); |
|||
}); |
|||
this.hoverShape.on('mousedown touchstart', (event: Event) => { |
|||
if (event.type === 'mousedown') { |
|||
if ((event as MouseEvent).button !== 0) { |
|||
return; |
|||
} |
|||
} |
|||
if (!this.disabled && !this.pressed) { |
|||
this.pressed = true; |
|||
if (!this.forcePressed) { |
|||
this.onPressStart(); |
|||
} |
|||
} |
|||
}); |
|||
this.hoverShape.on('mouseup touchend touchcancel', () => { |
|||
if (this.pressed && !this.disabled) { |
|||
this.onClick(); |
|||
} |
|||
this._cancelPressed(); |
|||
}); |
|||
this._drawState(); |
|||
} |
|||
|
|||
private _cancelPressed() { |
|||
if (this.pressed) { |
|||
this.pressed = false; |
|||
if (!this.forcePressed) { |
|||
this.onPressEnd(); |
|||
} |
|||
} |
|||
} |
|||
|
|||
private _drawState() { |
|||
let colorState: PowerButtonColorState; |
|||
if (this.disabled) { |
|||
colorState = this.colors.disabled; |
|||
} else { |
|||
colorState = this.value ? this.colors.on : this.colors.off; |
|||
} |
|||
this.drawBackgroundState(colorState.backgroundColor); |
|||
this.drawColorState(colorState.mainColor); |
|||
if (this.value) { |
|||
this.drawOn(); |
|||
} else { |
|||
this.drawOff(); |
|||
} |
|||
if (this.disabled) { |
|||
this.hoverShape.timeline().finish(); |
|||
this.hoverShape.attr({'fill-opacity': 0}); |
|||
} else if (this.hovered) { |
|||
this.hoverShape.timeline().finish(); |
|||
this.hoverShape.animate(200).attr({'fill-opacity': 0.06}); |
|||
} |
|||
} |
|||
|
|||
private drawBackgroundState(backgroundColor: PowerButtonColor) { |
|||
this.backgroundShape.attr({ fill: backgroundColor.hex, 'fill-opacity': backgroundColor.opacity}); |
|||
} |
|||
|
|||
protected drawShape() {} |
|||
|
|||
protected drawColorState(_mainColor: PowerButtonColor) {} |
|||
|
|||
protected drawOff() {} |
|||
|
|||
protected drawOn() {} |
|||
|
|||
protected onPressStart() {} |
|||
|
|||
protected onPressEnd() {} |
|||
|
|||
protected createMask(shape: Element, maskElements: Element[]) { |
|||
const mask = |
|||
this.svgShape.mask().add(this.svgShape.rect().width('100%').height('100%').fill('#fff')); |
|||
maskElements.forEach(e => { |
|||
mask.add(e.fill('#000').attr({'fill-opacity': 1})); |
|||
}); |
|||
shape.maskWith(mask); |
|||
} |
|||
|
|||
protected createOnLabel(fontWeight = '500'): Text { |
|||
return this.createLabel(this.onLabel, fontWeight); |
|||
} |
|||
|
|||
protected createOffLabel(fontWeight = '500'): Text { |
|||
return this.createLabel(this.offLabel, fontWeight); |
|||
} |
|||
|
|||
private createLabel(text: string, fontWeight = '500'): Text { |
|||
return this.svgShape.text(text).font({ |
|||
family: 'Roboto', |
|||
weight: fontWeight, |
|||
style: 'normal', |
|||
size: '22px' |
|||
}).attr({x: '50%', y: '50%', 'text-anchor': 'middle', 'dominant-baseline': 'middle'}); |
|||
} |
|||
|
|||
} |
|||
|
|||
class InnerShadowCircle { |
|||
|
|||
private shadowCircle: Circle; |
|||
private blurEffect: Effect; |
|||
private offsetEffect: Effect; |
|||
private floodEffect: Effect; |
|||
|
|||
constructor(private svgShape: Svg, |
|||
private diameter: number, |
|||
private centerX: number, |
|||
private centerY: number, |
|||
private blur = 6, |
|||
private shadowOpacity = 0.6, |
|||
private dx = 0, |
|||
private dy = 0, |
|||
private shadowColor = '#000') { |
|||
|
|||
this.shadowCircle = this.svgShape.circle(this.diameter).center(this.centerX, this.centerY) |
|||
.fill({color: '#fff', opacity: 1}).stroke({width: 0}); |
|||
|
|||
this.shadowCircle.filterWith(add => { |
|||
add.x('-50%').y('-50%').width('200%').height('200%'); |
|||
let effect: Effect = add.componentTransfer(components => { |
|||
components.funcA({ type: 'table', tableValues: '1 0' }); |
|||
}).in(add.$fill); |
|||
effect = effect.gaussianBlur(this.blur, this.blur).attr({stdDeviation: this.blur}); |
|||
this.blurEffect = effect; |
|||
effect = effect.offset(this.dx, this.dy); |
|||
this.offsetEffect = effect; |
|||
effect = effect.flood(this.shadowColor, this.shadowOpacity); |
|||
this.floodEffect = effect; |
|||
effect = effect.composite(this.offsetEffect, 'in'); |
|||
effect.composite(add.$sourceAlpha, 'in'); |
|||
add.merge(m => { |
|||
m.mergeNode(add.$fill); |
|||
m.mergeNode(); |
|||
}); |
|||
}); |
|||
} |
|||
|
|||
public timeline(tl: Timeline): void { |
|||
this.blurEffect.timeline(tl); |
|||
this.offsetEffect.timeline(tl); |
|||
this.floodEffect.timeline(tl); |
|||
} |
|||
|
|||
public animate(blur: number, opacity: number, dx = 0, dy = 0): Runner { |
|||
powerButtonAnimation(this.blurEffect).attr({stdDeviation: blur}); |
|||
powerButtonAnimation(this.offsetEffect).attr({dx, dy}); |
|||
return powerButtonAnimation(this.floodEffect).attr({'flood-opacity': opacity}); |
|||
} |
|||
|
|||
public animateRestore(): Runner { |
|||
return this.animate(this.blur, this.shadowOpacity, this.dx, this.dy); |
|||
} |
|||
|
|||
public show(): void { |
|||
this.shadowCircle.show(); |
|||
} |
|||
|
|||
public hide(): void { |
|||
this.shadowCircle.hide(); |
|||
} |
|||
|
|||
} |
|||
|
|||
class DefaultPowerButtonShape extends PowerButtonShape { |
|||
|
|||
private outerBorder: Circle; |
|||
private outerBorderMask: Circle; |
|||
private offLabelShape: Text; |
|||
private onCircleShape: Circle; |
|||
private onLabelShape: Text; |
|||
private pressedShadow: InnerShadowCircle; |
|||
private pressedTimeline: Timeline; |
|||
private centerGroup: G; |
|||
|
|||
protected drawShape() { |
|||
this.outerBorder = this.svgShape.circle(powerButtonShapeSize).center(cx, cy) |
|||
.fill({opacity: 0}).stroke({width: 0}); |
|||
this.outerBorderMask = this.svgShape.circle(powerButtonShapeSize - 20).center(cx, cy); |
|||
this.createMask(this.outerBorder, [this.outerBorderMask]); |
|||
this.centerGroup = this.svgShape.group(); |
|||
this.offLabelShape = this.createOffLabel().addTo(this.centerGroup); |
|||
this.onCircleShape = this.svgShape.circle(powerButtonShapeSize - 20) |
|||
.center(cx, cy); |
|||
this.onLabelShape = this.createOnLabel(); |
|||
this.createMask(this.onCircleShape, [this.onLabelShape]); |
|||
this.pressedShadow = new InnerShadowCircle(this.svgShape, powerButtonShapeSize - 20, cx, cy, 0, 0); |
|||
|
|||
this.pressedTimeline = new Timeline(); |
|||
this.centerGroup.timeline(this.pressedTimeline); |
|||
this.onLabelShape.timeline(this.pressedTimeline); |
|||
this.pressedShadow.timeline(this.pressedTimeline); |
|||
} |
|||
|
|||
protected drawColorState(mainColor: PowerButtonColor) { |
|||
this.outerBorder.attr({ fill: mainColor.hex, 'fill-opacity': mainColor.opacity}); |
|||
this.offLabelShape.attr({ fill: mainColor.hex, 'fill-opacity': mainColor.opacity}); |
|||
this.onCircleShape.attr({ fill: mainColor.hex, 'fill-opacity': mainColor.opacity}); |
|||
} |
|||
|
|||
protected drawOff() { |
|||
this.outerBorderMask.radius((powerButtonShapeSize - 20)/2); |
|||
this.onCircleShape.hide(); |
|||
this.centerGroup.show(); |
|||
} |
|||
|
|||
protected drawOn() { |
|||
this.outerBorderMask.radius((powerButtonShapeSize - 2)/2); |
|||
this.centerGroup.hide(); |
|||
this.onCircleShape.show(); |
|||
} |
|||
|
|||
protected onPressStart() { |
|||
this.pressedTimeline.finish(); |
|||
const pressedScale = 0.75; |
|||
powerButtonAnimation(this.centerGroup).transform({scale: pressedScale}); |
|||
powerButtonAnimation(this.onLabelShape).transform({scale: pressedScale}); |
|||
this.pressedShadow.animate(6, 0.6); |
|||
} |
|||
|
|||
protected onPressEnd() { |
|||
this.pressedTimeline.finish(); |
|||
powerButtonAnimation(this.centerGroup).transform({scale: 1}); |
|||
powerButtonAnimation(this.onLabelShape).transform({scale: 1}); |
|||
this.pressedShadow.animateRestore(); |
|||
} |
|||
|
|||
} |
|||
|
|||
class SimplifiedPowerButtonShape extends PowerButtonShape { |
|||
|
|||
private outerBorder: Circle; |
|||
private outerBorderMask: Circle; |
|||
private onCircleShape: Circle; |
|||
private offLabelShape: Text; |
|||
private onLabelShape: Text; |
|||
private pressedShadow: InnerShadowCircle; |
|||
private pressedTimeline: Timeline; |
|||
private centerGroup: G; |
|||
|
|||
protected drawShape() { |
|||
this.outerBorder = this.svgShape.circle(powerButtonShapeSize).center(cx, cy) |
|||
.fill({opacity: 0}).stroke({width: 0}); |
|||
this.outerBorderMask = this.svgShape.circle(powerButtonShapeSize - 4).center(cx, cy); |
|||
this.createMask(this.outerBorder, [this.outerBorderMask]); |
|||
this.centerGroup = this.svgShape.group(); |
|||
this.offLabelShape = this.createOffLabel().addTo(this.centerGroup); |
|||
this.onCircleShape = this.svgShape.circle(powerButtonShapeSize).center(cx, cy); |
|||
this.onLabelShape = this.createOnLabel(); |
|||
this.createMask(this.onCircleShape, [this.onLabelShape]); |
|||
this.pressedShadow = new InnerShadowCircle(this.svgShape, powerButtonShapeSize - 4, cx, cy, 0, 0); |
|||
|
|||
this.pressedTimeline = new Timeline(); |
|||
this.centerGroup.timeline(this.pressedTimeline); |
|||
this.onLabelShape.timeline(this.pressedTimeline); |
|||
this.pressedShadow.timeline(this.pressedTimeline); |
|||
} |
|||
|
|||
protected drawColorState(mainColor: PowerButtonColor) { |
|||
this.outerBorder.attr({ fill: mainColor.hex, 'fill-opacity': mainColor.opacity}); |
|||
this.onCircleShape.attr({ fill: mainColor.hex, 'fill-opacity': mainColor.opacity}); |
|||
this.offLabelShape.attr({ fill: mainColor.hex, 'fill-opacity': mainColor.opacity}); |
|||
} |
|||
|
|||
protected drawOff() { |
|||
this.onCircleShape.hide(); |
|||
this.outerBorder.show(); |
|||
this.centerGroup.show(); |
|||
} |
|||
|
|||
protected drawOn() { |
|||
this.centerGroup.hide(); |
|||
this.outerBorder.hide(); |
|||
this.onCircleShape.show(); |
|||
} |
|||
|
|||
protected onPressStart() { |
|||
this.pressedTimeline.finish(); |
|||
const pressedScale = 0.75; |
|||
powerButtonAnimation(this.centerGroup).transform({scale: pressedScale}); |
|||
powerButtonAnimation(this.onLabelShape).transform({scale: pressedScale}); |
|||
this.pressedShadow.animate(6, 0.6); |
|||
} |
|||
|
|||
protected onPressEnd() { |
|||
this.pressedTimeline.finish(); |
|||
powerButtonAnimation(this.centerGroup).transform({scale: 1}); |
|||
powerButtonAnimation(this.onLabelShape).transform({scale: 1}); |
|||
this.pressedShadow.animateRestore(); |
|||
} |
|||
} |
|||
|
|||
class OutlinedPowerButtonShape extends PowerButtonShape { |
|||
private outerBorder: Circle; |
|||
private outerBorderMask: Circle; |
|||
private innerBorder: Circle; |
|||
private innerBorderMask: Circle; |
|||
private offLabelShape: Text; |
|||
private onCircleShape: Circle; |
|||
private onLabelShape: Text; |
|||
private pressedShadow: InnerShadowCircle; |
|||
private pressedTimeline: Timeline; |
|||
private centerGroup: G; |
|||
private onCenterGroup: G; |
|||
|
|||
protected drawShape() { |
|||
this.outerBorder = this.svgShape.circle(powerButtonShapeSize).center(cx, cy) |
|||
.fill({opacity: 0}).stroke({width: 0}); |
|||
this.outerBorderMask = this.svgShape.circle(powerButtonShapeSize - 2).center(cx, cy); |
|||
this.createMask(this.outerBorder, [this.outerBorderMask]); |
|||
this.innerBorder = this.svgShape.circle(powerButtonShapeSize - 20).center(cx, cy) |
|||
.fill({opacity: 0}).stroke({width: 0}); |
|||
this.innerBorderMask = this.svgShape.circle(powerButtonShapeSize - 24).center(cx, cy); |
|||
this.createMask(this.innerBorder, [this.innerBorderMask]); |
|||
this.centerGroup = this.svgShape.group(); |
|||
this.offLabelShape = this.createOffLabel().addTo(this.centerGroup); |
|||
this.onCenterGroup = this.svgShape.group(); |
|||
this.onCircleShape = this.svgShape.circle(powerButtonShapeSize - 28).center(cx, cy) |
|||
.addTo(this.onCenterGroup); |
|||
this.onLabelShape = this.createOnLabel(); |
|||
this.createMask(this.onCircleShape, [this.onLabelShape]); |
|||
this.pressedShadow = new InnerShadowCircle(this.svgShape, powerButtonShapeSize - 24, cx, cy, 0, 0); |
|||
|
|||
this.pressedTimeline = new Timeline(); |
|||
this.centerGroup.timeline(this.pressedTimeline); |
|||
this.onCenterGroup.timeline(this.pressedTimeline); |
|||
this.onLabelShape.timeline(this.pressedTimeline); |
|||
this.pressedShadow.timeline(this.pressedTimeline); |
|||
} |
|||
|
|||
protected drawColorState(mainColor: PowerButtonColor) { |
|||
this.outerBorder.attr({ fill: mainColor.hex, 'fill-opacity': mainColor.opacity}); |
|||
this.innerBorder.attr({ fill: mainColor.hex, 'fill-opacity': mainColor.opacity}); |
|||
this.offLabelShape.attr({ fill: mainColor.hex, 'fill-opacity': mainColor.opacity}); |
|||
this.onCircleShape.attr({ fill: mainColor.hex, 'fill-opacity': mainColor.opacity}); |
|||
} |
|||
|
|||
protected drawOff() { |
|||
this.onCenterGroup.hide(); |
|||
this.centerGroup.show(); |
|||
} |
|||
|
|||
protected drawOn() { |
|||
this.centerGroup.hide(); |
|||
this.onCenterGroup.show(); |
|||
} |
|||
|
|||
protected onPressStart() { |
|||
this.pressedTimeline.finish(); |
|||
const pressedScale = 0.75; |
|||
powerButtonAnimation(this.centerGroup).transform({scale: pressedScale}); |
|||
powerButtonAnimation(this.onCenterGroup).transform({scale: 0.98}); |
|||
powerButtonAnimation(this.onLabelShape).transform({scale: pressedScale / 0.98}); |
|||
this.pressedShadow.animate(6, 0.6); |
|||
} |
|||
|
|||
protected onPressEnd() { |
|||
this.pressedTimeline.finish(); |
|||
powerButtonAnimation(this.centerGroup).transform({scale: 1}); |
|||
powerButtonAnimation(this.onCenterGroup).transform({scale: 1}); |
|||
powerButtonAnimation(this.onLabelShape).transform({scale: 1}); |
|||
this.pressedShadow.animateRestore(); |
|||
} |
|||
} |
|||
|
|||
class DefaultVolumePowerButtonShape extends PowerButtonShape { |
|||
private outerBorder: Circle; |
|||
private outerBorderMask: Circle; |
|||
private outerBorderGradient: Gradient; |
|||
private innerBorder: Circle; |
|||
private innerBorderMask: Circle; |
|||
private innerBorderGradient: Gradient; |
|||
private innerShadow: InnerShadowCircle; |
|||
//private innerShadowGradient: Gradient;
|
|||
//private innerShadowGradientStop: Stop;
|
|||
private offLabelShape: Text; |
|||
private onCircleShape: Circle; |
|||
private onLabelShape: Text; |
|||
private pressedTimeline: Timeline; |
|||
private centerGroup: G; |
|||
|
|||
protected drawShape() { |
|||
this.outerBorder = this.svgShape.circle(powerButtonShapeSize).center(cx, cy) |
|||
.fill({opacity: 0}).stroke({width: 0}); |
|||
this.outerBorderMask = this.svgShape.circle(powerButtonShapeSize - 20).center(cx, cy); |
|||
this.createMask(this.outerBorder, [this.outerBorderMask]); |
|||
this.outerBorderGradient = this.svgShape.gradient('linear', (add) => { |
|||
add.stop(0, '#CCCCCC', 1); |
|||
add.stop(1, '#FFFFFF', 1); |
|||
}).from(0.268, 0.92).to(0.832, 0.1188); |
|||
this.innerBorder = this.svgShape.circle(powerButtonShapeSize - 20).center(cx, cy) |
|||
.fill({opacity: 0}).stroke({width: 0}); |
|||
this.innerBorderMask = this.svgShape.circle(powerButtonShapeSize - 24).center(cx, cy); |
|||
this.createMask(this.innerBorder, [this.innerBorderMask]); |
|||
this.innerBorderGradient = this.svgShape.gradient('linear', (add) => { |
|||
add.stop(0, '#CCCCCC', 1); |
|||
add.stop(1, '#FFFFFF', 1); |
|||
}).from(0.832, 0.1188).to(0.268, 0.92); |
|||
this.centerGroup = this.svgShape.group(); |
|||
this.offLabelShape = this.createOffLabel('400').addTo(this.centerGroup); |
|||
this.onCircleShape = this.svgShape.circle(powerButtonShapeSize - 24).center(cx, cy); |
|||
this.onLabelShape = this.createOnLabel('400'); |
|||
this.createMask(this.onCircleShape, [this.onLabelShape]); |
|||
this.innerShadow = new InnerShadowCircle(this.svgShape, powerButtonShapeSize - 24, cx, cy, 3, 0.3); |
|||
|
|||
this.pressedTimeline = new Timeline(); |
|||
this.centerGroup.timeline(this.pressedTimeline); |
|||
this.onLabelShape.timeline(this.pressedTimeline); |
|||
this.innerShadow.timeline(this.pressedTimeline); |
|||
} |
|||
|
|||
protected drawColorState(mainColor: PowerButtonColor){ |
|||
if (this.disabled) { |
|||
this.backgroundShape.removeClass('tb-small-shadow'); |
|||
if (!this.forcePressed) { |
|||
this.innerShadow.hide(); |
|||
} |
|||
this.outerBorder.attr({ fill: mainColor.hex, 'fill-opacity': mainColor.opacity}); |
|||
this.innerBorder.attr({fill: mainColor.hex, 'fill-opacity': mainColor.opacity}); |
|||
} else { |
|||
this.backgroundShape.addClass('tb-small-shadow'); |
|||
this.innerShadow.show(); |
|||
this.outerBorder.fill(this.outerBorderGradient); |
|||
this.outerBorder.attr({ 'fill-opacity': 1 }); |
|||
this.innerBorder.fill(this.innerBorderGradient); |
|||
this.innerBorder.attr({ 'fill-opacity': 1 }); |
|||
} |
|||
this.offLabelShape.attr({ fill: mainColor.hex, 'fill-opacity': mainColor.opacity}); |
|||
this.onCircleShape.attr({ fill: mainColor.hex, 'fill-opacity': mainColor.opacity}); |
|||
} |
|||
|
|||
protected drawOff() { |
|||
this.onCircleShape.hide(); |
|||
this.centerGroup.show(); |
|||
this.innerBorder.show(); |
|||
} |
|||
|
|||
protected drawOn() { |
|||
if (this.disabled) { |
|||
this.innerBorder.hide(); |
|||
} else { |
|||
this.innerBorder.show(); |
|||
} |
|||
this.centerGroup.hide(); |
|||
this.onCircleShape.show(); |
|||
} |
|||
|
|||
protected onPressStart() { |
|||
this.pressedTimeline.finish(); |
|||
this.innerShadow.show(); |
|||
const pressedScale = 0.75; |
|||
powerButtonAnimation(this.centerGroup).transform({scale: pressedScale}); |
|||
powerButtonAnimation(this.onLabelShape).transform({scale: pressedScale}); |
|||
this.innerShadow.animate(6, 0.6); |
|||
} |
|||
|
|||
protected onPressEnd() { |
|||
this.pressedTimeline.finish(); |
|||
powerButtonAnimation(this.centerGroup).transform({scale: 1}); |
|||
powerButtonAnimation(this.onLabelShape).transform({scale: 1}); |
|||
this.innerShadow.animateRestore().after(() => { |
|||
if (this.disabled) { |
|||
this.innerShadow.hide(); |
|||
} |
|||
}); |
|||
} |
|||
|
|||
} |
|||
|
|||
class SimplifiedVolumePowerButtonShape extends PowerButtonShape { |
|||
|
|||
private outerBorder: Circle; |
|||
private outerBorderMask: Circle; |
|||
private offLabelShape: Text; |
|||
private onLabelShape: Text; |
|||
private innerShadow: InnerShadowCircle; |
|||
private pressedShadow: InnerShadowCircle; |
|||
private pressedTimeline: Timeline; |
|||
private centerGroup: G; |
|||
private onCenterGroup: G; |
|||
|
|||
|
|||
protected drawShape() { |
|||
this.outerBorder = this.svgShape.circle(powerButtonShapeSize).center(cx, cy) |
|||
.fill({color: '#FAFAFA', opacity: 1}).stroke({width: 0}); |
|||
this.outerBorderMask = this.svgShape.circle(powerButtonShapeSize - 4).center(cx, cy); |
|||
this.createMask(this.outerBorder, [this.outerBorderMask]); |
|||
this.centerGroup = this.svgShape.group(); |
|||
this.offLabelShape = this.createOffLabel().addTo(this.centerGroup); |
|||
this.onCenterGroup = this.svgShape.group(); |
|||
this.onLabelShape = this.createOnLabel().addTo(this.onCenterGroup); |
|||
this.innerShadow = new InnerShadowCircle(this.svgShape, powerButtonShapeSize - 4, cx, cy, 3, 0.3); |
|||
this.pressedShadow = new InnerShadowCircle(this.svgShape, powerButtonShapeSize - 4, cx, cy, 0, 0); |
|||
this.pressedTimeline = new Timeline(); |
|||
this.centerGroup.timeline(this.pressedTimeline); |
|||
this.onCenterGroup.timeline(this.pressedTimeline); |
|||
this.pressedShadow.timeline(this.pressedTimeline); |
|||
} |
|||
|
|||
protected drawColorState(mainColor: PowerButtonColor){ |
|||
this.offLabelShape.attr({ fill: mainColor.hex, 'fill-opacity': mainColor.opacity}); |
|||
this.onLabelShape.attr({ fill: mainColor.hex, 'fill-opacity': mainColor.opacity}); |
|||
} |
|||
|
|||
protected drawOff() { |
|||
if (!this.pressed) { |
|||
this.backgroundShape.addClass('tb-shadow'); |
|||
} |
|||
this.innerShadow.hide(); |
|||
this.onCenterGroup.hide(); |
|||
this.centerGroup.show(); |
|||
} |
|||
|
|||
protected drawOn() { |
|||
this.backgroundShape.removeClass('tb-shadow'); |
|||
this.centerGroup.hide(); |
|||
this.onCenterGroup.show(); |
|||
this.innerShadow.show(); |
|||
} |
|||
|
|||
protected onPressStart() { |
|||
this.pressedTimeline.finish(); |
|||
const pressedScale = 0.75; |
|||
if (!this.value) { |
|||
this.backgroundShape.removeClass('tb-shadow'); |
|||
} |
|||
powerButtonAnimation(this.centerGroup).transform({scale: pressedScale}); |
|||
powerButtonAnimation(this.onCenterGroup).transform({scale: pressedScale}); |
|||
this.pressedShadow.animate(8, 0.4); |
|||
} |
|||
|
|||
protected onPressEnd() { |
|||
this.pressedTimeline.finish(); |
|||
powerButtonAnimation(this.centerGroup).transform({scale: 1}); |
|||
powerButtonAnimation(this.onCenterGroup).transform({scale: 1}); |
|||
this.pressedShadow.animateRestore().after(() => { |
|||
if (!this.value) { |
|||
this.backgroundShape.addClass('tb-shadow'); |
|||
} |
|||
}); |
|||
} |
|||
} |
|||
|
|||
class OutlinedVolumePowerButtonShape extends PowerButtonShape { |
|||
private outerBorder: Circle; |
|||
private outerBorderMask: Circle; |
|||
private outerBorderGradient: Gradient; |
|||
private innerBorder: Circle; |
|||
private innerBorderMask: Circle; |
|||
private offLabelShape: Text; |
|||
private onCircleShape: Circle; |
|||
private onLabelShape: Text; |
|||
private pressedShadow: InnerShadowCircle; |
|||
private pressedTimeline: Timeline; |
|||
private centerGroup: G; |
|||
private onCenterGroup: G; |
|||
|
|||
protected drawShape() { |
|||
this.outerBorder = this.svgShape.circle(powerButtonShapeSize).center(cx, cy) |
|||
.fill({opacity: 0}).stroke({width: 0}); |
|||
this.outerBorderMask = this.svgShape.circle(powerButtonShapeSize - 20).center(cx, cy); |
|||
this.createMask(this.outerBorder, [this.outerBorderMask]); |
|||
this.outerBorderGradient = this.svgShape.gradient('linear', (add) => { |
|||
add.stop(0, '#CCCCCC', 1); |
|||
add.stop(1, '#FFFFFF', 1); |
|||
}).from(0.268, 0.92).to(0.832, 0.1188); |
|||
this.innerBorder = this.svgShape.circle(powerButtonShapeSize - 20).center(cx, cy) |
|||
.fill({opacity: 0}).stroke({width: 0}); |
|||
this.innerBorderMask = this.svgShape.circle(powerButtonShapeSize - 30).center(cx, cy); |
|||
this.createMask(this.innerBorder, [this.innerBorderMask]); |
|||
this.centerGroup = this.svgShape.group(); |
|||
this.offLabelShape = this.createOffLabel('800').addTo(this.centerGroup); |
|||
this.onCenterGroup = this.svgShape.group(); |
|||
this.onCircleShape = this.svgShape.circle(powerButtonShapeSize - 30).center(cx, cy) |
|||
.addTo(this.onCenterGroup); |
|||
this.onLabelShape = this.createOnLabel('800'); |
|||
this.createMask(this.onCircleShape, [this.onLabelShape]); |
|||
this.pressedShadow = new InnerShadowCircle(this.svgShape, powerButtonShapeSize - 30, cx, cy, 0, 0); |
|||
this.backgroundShape.addClass('tb-small-shadow'); |
|||
|
|||
this.pressedTimeline = new Timeline(); |
|||
this.centerGroup.timeline(this.pressedTimeline); |
|||
this.onCenterGroup.timeline(this.pressedTimeline); |
|||
this.onLabelShape.timeline(this.pressedTimeline); |
|||
this.pressedShadow.timeline(this.pressedTimeline); |
|||
} |
|||
|
|||
protected drawColorState(mainColor: PowerButtonColor){ |
|||
if (this.disabled) { |
|||
this.outerBorder.attr({ fill: '#000000', 'fill-opacity': 0.03}); |
|||
} else { |
|||
this.outerBorder.fill(this.outerBorderGradient); |
|||
this.outerBorder.attr({ 'fill-opacity': 1 }); |
|||
} |
|||
this.innerBorder.attr({fill: mainColor.hex, 'fill-opacity': mainColor.opacity}); |
|||
this.offLabelShape.attr({ fill: mainColor.hex, 'fill-opacity': mainColor.opacity}); |
|||
this.onCircleShape.attr({ fill: mainColor.hex, 'fill-opacity': mainColor.opacity}); |
|||
} |
|||
|
|||
protected drawOff() { |
|||
this.onCenterGroup.hide(); |
|||
this.centerGroup.show(); |
|||
this.innerBorder.show(); |
|||
} |
|||
|
|||
protected drawOn() { |
|||
this.innerBorder.hide(); |
|||
this.centerGroup.hide(); |
|||
this.onCenterGroup.show(); |
|||
} |
|||
|
|||
protected onPressStart() { |
|||
this.pressedTimeline.finish(); |
|||
const pressedScale = 0.75; |
|||
powerButtonAnimation(this.centerGroup).transform({scale: pressedScale}); |
|||
powerButtonAnimation(this.onCenterGroup).transform({scale: 0.98}); |
|||
powerButtonAnimation(this.onLabelShape).transform({scale: pressedScale / 0.98}); |
|||
this.pressedShadow.animate(6, 0.6); |
|||
} |
|||
|
|||
protected onPressEnd() { |
|||
this.pressedTimeline.finish(); |
|||
powerButtonAnimation(this.centerGroup).transform({scale: 1}); |
|||
powerButtonAnimation(this.onCenterGroup).transform({scale: 1}); |
|||
powerButtonAnimation(this.onLabelShape).transform({scale: 1}); |
|||
this.pressedShadow.animateRestore(); |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,59 @@ |
|||
<!-- |
|||
|
|||
Copyright © 2016-2024 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. |
|||
|
|||
--> |
|||
<div class="tb-slider-panel" [style.pointer-events]="ctx.isEdit ? 'none' : 'all'" [style]="backgroundStyle$ | async"> |
|||
<div class="tb-slider-overlay" [style]="overlayStyle"></div> |
|||
<div *ngIf="showWidgetTitlePanel" class="tb-slider-title-panel"> |
|||
<ng-container *ngTemplateOutlet="widgetTitlePanel"></ng-container> |
|||
</div> |
|||
<div #sliderContent class="tb-slider-content"> |
|||
<div #sliderValueContainer class="tb-slider-value-container" *ngIf="showValue" > |
|||
<div #sliderValue class="tb-slider-value" [style]="valueStyle">{{ valueText }}</div> |
|||
</div> |
|||
<div class="tb-slider-container" [class.tb-min-height]="!showValue"> |
|||
<div #leftSliderIconContainer *ngIf="showLeftRightIcon" > |
|||
<tb-icon #leftSliderIcon [style]="leftIconStyle" |
|||
[style.color]="(disabled || (loading$ | async)) ? settings.mainColorDisabled : settings.leftIconColor">{{ leftIcon }}</tb-icon> |
|||
</div> |
|||
<div class="tb-slider-column"> |
|||
<mat-slider class="tb-slider" |
|||
[disabled]="disabled || (loading$ | async)" |
|||
[displayWith]="sliderValueText" |
|||
[showTickMarks]="settings.showTickMarks" |
|||
[step]="sliderStep" |
|||
[min]="settings.tickMin" |
|||
[max]="settings.tickMax" |
|||
discrete> |
|||
<input matSliderThumb [(ngModel)]="value" (valueChange)="onSliderChange()"> |
|||
</mat-slider> |
|||
<div *ngIf="showTicks" class="tb-slider-ticks" [style]="ticksStyle"> |
|||
<div #sliderTickMinContainer> |
|||
<div #sliderTickMin>{{ settings.tickMin }}</div> |
|||
</div> |
|||
<div #sliderTickMaxContainer> |
|||
<div #sliderTickMax>{{ settings.tickMax }}</div> |
|||
</div> |
|||
</div> |
|||
</div> |
|||
<div #rightSliderIconContainer *ngIf="showLeftRightIcon" > |
|||
<tb-icon #rightSliderIcon [style]="rightIconStyle" |
|||
[style.color]="(disabled || (loading$ | async)) ? settings.mainColorDisabled : settings.rightIconColor">{{ rightIcon }}</tb-icon> |
|||
</div> |
|||
</div> |
|||
</div> |
|||
<mat-progress-bar class="tb-action-widget-progress" style="height: 4px;" color="accent" mode="indeterminate" *ngIf="loading$ | async"></mat-progress-bar> |
|||
</div> |
|||
@ -0,0 +1,135 @@ |
|||
/** |
|||
* Copyright © 2016-2024 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. |
|||
*/ |
|||
$mainColor: var(--tb-slider-main-color, #5469FF); |
|||
$hoverRippleColor: var(--tb-slider-hover-ripple-color, rgba(84, 105, 255, 0.05)); |
|||
$focusRippleColor: var(--tb-slider-focus-ripple-color, rgba(84, 105, 255, 0.2)); |
|||
$backgroundColor: var(--tb-slider-background-color, #CCD2FF); |
|||
$tickMarksColor: var(--tb-slider-tick-marks-color, #5469FF); |
|||
|
|||
$mainColorDisabled: var(--tb-slider-main-color-disabled, #9BA2B0); |
|||
$backgroundColorDisabled: var(--tb-slider-background-color-disabled, #D5D7E5); |
|||
|
|||
.tb-slider-panel { |
|||
|
|||
.mat-mdc-slider.mat-primary.tb-slider { |
|||
--mdc-slider-active-track-color: #{$mainColor}; |
|||
--mdc-slider-handle-color: #{$mainColor}; |
|||
--mdc-slider-focus-handle-color: #{$mainColor}; |
|||
--mdc-slider-hover-handle-color: #{$mainColor}; |
|||
|
|||
--mdc-slider-with-tick-marks-inactive-container-color: #{$tickMarksColor}; |
|||
--mat-mdc-slider-ripple-color: #{$mainColor}; |
|||
|
|||
--mat-mdc-slider-hover-ripple-color: #{$hoverRippleColor}; |
|||
--mat-mdc-slider-focus-ripple-color: #{$focusRippleColor}; |
|||
|
|||
--mdc-slider-inactive-track-color: #{$backgroundColor}; |
|||
|
|||
--mdc-slider-disabled-active-track-color: #{$mainColorDisabled}; |
|||
--mdc-slider-disabled-handle-color: #{$mainColorDisabled}; |
|||
|
|||
--mdc-slider-disabled-inactive-track-color: #{$backgroundColorDisabled}; |
|||
--mdc-slider-with-tick-marks-disabled-container-color: #{$mainColorDisabled}; |
|||
|
|||
--mdc-slider-handle-width: 16px; |
|||
--mdc-slider-handle-height: 16px; |
|||
} |
|||
|
|||
width: 100%; |
|||
height: 100%; |
|||
position: relative; |
|||
display: flex; |
|||
flex-direction: column; |
|||
padding: 20px 24px 24px 24px; |
|||
gap: 8px; |
|||
> div:not(.tb-slider-overlay), > tb-icon { |
|||
z-index: 1; |
|||
} |
|||
.tb-slider-overlay { |
|||
position: absolute; |
|||
inset: 12px; |
|||
} |
|||
div.tb-slider-title-panel { |
|||
z-index: 2; |
|||
} |
|||
.tb-slider-content { |
|||
flex: 1; |
|||
min-height: 0; |
|||
display: flex; |
|||
position: relative; |
|||
flex-direction: column; |
|||
align-items: center; |
|||
justify-content: center; |
|||
gap: 12px; |
|||
.tb-slider-value-container { |
|||
min-height: 0; |
|||
} |
|||
.tb-slider-value { |
|||
white-space: nowrap; |
|||
} |
|||
.tb-slider-container { |
|||
align-self: stretch; |
|||
display: flex; |
|||
flex-direction: row; |
|||
align-items: flex-start; |
|||
gap: 8px; |
|||
&.tb-min-height { |
|||
height: 6px; |
|||
} |
|||
.tb-slider-column { |
|||
flex: 1; |
|||
display: flex; |
|||
flex-direction: column; |
|||
gap: 4px; |
|||
.mat-mdc-slider.tb-slider { |
|||
margin: 0; |
|||
height: 6px; |
|||
min-height: 6px; |
|||
min-width: 0; |
|||
&.mdc-slider--disabled { |
|||
opacity: 1; |
|||
} |
|||
.mdc-slider__track--inactive { |
|||
opacity: 1; |
|||
} |
|||
.mdc-slider__tick-marks { |
|||
.mdc-slider__tick-mark--active { |
|||
display: none; |
|||
} |
|||
.mdc-slider__tick-mark--inactive { |
|||
opacity: 1; |
|||
} |
|||
} |
|||
.mdc-slider__thumb.mat-mdc-slider-visual-thumb { |
|||
top: -21px; |
|||
.mat-ripple { |
|||
overflow: visible; |
|||
} |
|||
} |
|||
.mdc-slider__value-indicator-text { |
|||
white-space: nowrap; |
|||
} |
|||
} |
|||
.tb-slider-ticks { |
|||
display: flex; |
|||
flex-direction: row; |
|||
align-items: flex-start; |
|||
justify-content: space-between; |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,347 @@ |
|||
///
|
|||
/// Copyright © 2016-2024 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.
|
|||
///
|
|||
|
|||
import { |
|||
AfterViewInit, |
|||
ChangeDetectorRef, |
|||
Component, |
|||
ElementRef, |
|||
OnDestroy, |
|||
OnInit, |
|||
Renderer2, |
|||
ViewChild, |
|||
ViewEncapsulation |
|||
} from '@angular/core'; |
|||
import { BasicActionWidgetComponent, ValueSetter } from '@home/components/widget/lib/action/action-widget.models'; |
|||
import { |
|||
backgroundStyle, |
|||
ComponentStyle, |
|||
iconStyle, |
|||
overlayStyle, |
|||
textStyle |
|||
} from '@shared/models/widget-settings.models'; |
|||
import { Observable } from 'rxjs'; |
|||
import { ResizeObserver } from '@juggle/resize-observer'; |
|||
import { ImagePipe } from '@shared/pipe/image.pipe'; |
|||
import { DomSanitizer } from '@angular/platform-browser'; |
|||
import { ValueType } from '@shared/models/constants'; |
|||
import { UtilsService } from '@core/services/utils.service'; |
|||
import { |
|||
SliderLayout, |
|||
sliderWidgetDefaultSettings, |
|||
SliderWidgetSettings |
|||
} from '@home/components/widget/lib/rpc/slider-widget.models'; |
|||
import { formatValue, isDefinedAndNotNull, isNumeric } from '@core/utils'; |
|||
import { WidgetComponent } from '@home/components/widget/widget.component'; |
|||
import tinycolor from 'tinycolor2'; |
|||
|
|||
@Component({ |
|||
selector: 'tb-slider-widget', |
|||
templateUrl: './slider-widget.component.html', |
|||
styleUrls: ['../action/action-widget.scss', './slider-widget.component.scss'], |
|||
encapsulation: ViewEncapsulation.None |
|||
}) |
|||
export class SliderWidgetComponent extends |
|||
BasicActionWidgetComponent implements OnInit, AfterViewInit, OnDestroy { |
|||
|
|||
@ViewChild('sliderContent', {static: false}) |
|||
sliderContent: ElementRef<HTMLElement>; |
|||
|
|||
@ViewChild('sliderValueContainer', {static: false}) |
|||
sliderValueContainer: ElementRef<HTMLElement>; |
|||
|
|||
@ViewChild('sliderValue', {static: false}) |
|||
sliderValue: ElementRef<HTMLElement>; |
|||
|
|||
@ViewChild('sliderTickMinContainer', {static: false}) |
|||
sliderTickMinContainer: ElementRef<HTMLElement>; |
|||
|
|||
@ViewChild('sliderTickMin', {static: false}) |
|||
sliderTickMin: ElementRef<HTMLElement>; |
|||
|
|||
@ViewChild('sliderTickMaxContainer', {static: false}) |
|||
sliderTickMaxContainer: ElementRef<HTMLElement>; |
|||
|
|||
@ViewChild('sliderTickMax', {static: false}) |
|||
sliderTickMax: ElementRef<HTMLElement>; |
|||
|
|||
@ViewChild('leftSliderIconContainer', {static: false, read: ElementRef}) |
|||
leftSliderIconContainer: ElementRef<HTMLElement>; |
|||
|
|||
@ViewChild('leftSliderIcon', {static: false, read: ElementRef}) |
|||
leftSliderIcon: ElementRef<HTMLElement>; |
|||
|
|||
@ViewChild('rightSliderIconContainer', {static: false, read: ElementRef}) |
|||
rightSliderIconContainer: ElementRef<HTMLElement>; |
|||
|
|||
@ViewChild('rightSliderIcon', {static: false, read: ElementRef}) |
|||
rightSliderIcon: ElementRef<HTMLElement>; |
|||
|
|||
settings: SliderWidgetSettings; |
|||
|
|||
backgroundStyle$: Observable<ComponentStyle>; |
|||
overlayStyle: ComponentStyle = {}; |
|||
|
|||
value: number = null; |
|||
private prevValue: number = null; |
|||
|
|||
disabled = false; |
|||
|
|||
layout: SliderLayout; |
|||
|
|||
showValue = true; |
|||
valueText = 'N/A'; |
|||
valueStyle: ComponentStyle = {}; |
|||
|
|||
showLeftRightIcon = false; |
|||
leftIcon = ''; |
|||
leftIconStyle: ComponentStyle = {}; |
|||
rightIcon = ''; |
|||
rightIconStyle: ComponentStyle = {}; |
|||
|
|||
showTicks = true; |
|||
ticksStyle: ComponentStyle = {}; |
|||
|
|||
sliderStep: number = undefined; |
|||
|
|||
autoScale = false; |
|||
|
|||
showWidgetTitlePanel = this.widgetComponent.dashboardWidget.showWidgetTitlePanel; |
|||
|
|||
sliderValueText = this._sliderValueText.bind(this); |
|||
|
|||
private panelResize$: ResizeObserver; |
|||
|
|||
private valueSetter: ValueSetter<number>; |
|||
|
|||
private sliderCssClass: string; |
|||
|
|||
constructor(protected imagePipe: ImagePipe, |
|||
protected sanitizer: DomSanitizer, |
|||
private renderer: Renderer2, |
|||
private utils: UtilsService, |
|||
private widgetComponent: WidgetComponent, |
|||
protected cd: ChangeDetectorRef, |
|||
private elementRef: ElementRef) { |
|||
super(cd); |
|||
} |
|||
|
|||
ngOnInit(): void { |
|||
super.ngOnInit(); |
|||
this.settings = {...sliderWidgetDefaultSettings, ...this.ctx.settings}; |
|||
|
|||
this.backgroundStyle$ = backgroundStyle(this.settings.background, this.imagePipe, this.sanitizer); |
|||
this.overlayStyle = overlayStyle(this.settings.background.overlay); |
|||
|
|||
this.layout = this.settings.layout; |
|||
|
|||
this.autoScale = this.settings.autoScale; |
|||
|
|||
this.showValue = this.layout !== SliderLayout.simplified && this.settings.showValue; |
|||
this.valueStyle = textStyle(this.settings.valueFont); |
|||
this.valueStyle.color = this.settings.valueColor; |
|||
|
|||
this.showLeftRightIcon = this.layout === SliderLayout.extended; |
|||
if (this.showLeftRightIcon) { |
|||
this.leftIcon = this.settings.leftIcon; |
|||
this.leftIconStyle = iconStyle(this.settings.leftIconSize, this.settings.leftIconSizeUnit ); |
|||
this.rightIcon = this.settings.rightIcon; |
|||
this.rightIconStyle = iconStyle(this.settings.rightIconSize, this.settings.rightIconSizeUnit ); |
|||
if (!this.autoScale) { |
|||
const leftIconMargin = this.settings.leftIconSize / 2 + (this.settings.leftIconSizeUnit || 'px'); |
|||
this.leftIconStyle.marginTop = `calc(-${leftIconMargin} + 3px)`; |
|||
const rightIconMargin = this.settings.rightIconSize / 2 + (this.settings.rightIconSizeUnit || 'px'); |
|||
this.rightIconStyle.marginTop = `calc(-${rightIconMargin} + 3px)`; |
|||
} |
|||
} |
|||
|
|||
this.showTicks = this.settings.showTicks; |
|||
if (this.showTicks) { |
|||
this.ticksStyle = textStyle(this.settings.ticksFont); |
|||
this.ticksStyle.color = this.settings.ticksColor; |
|||
} |
|||
|
|||
if (this.settings.showTickMarks) { |
|||
const range = this.settings.tickMax - this.settings.tickMin; |
|||
this.sliderStep = range / (this.settings.tickMarksCount - 1); |
|||
} |
|||
|
|||
const mainColorInstance = tinycolor(this.settings.mainColor); |
|||
const hoverRippleColor = mainColorInstance.clone().setAlpha(mainColorInstance.getAlpha() * 0.05).toRgbString(); |
|||
const focusRippleColor = mainColorInstance.clone().setAlpha(mainColorInstance.getAlpha() * 0.2).toRgbString(); |
|||
|
|||
const sliderVariablesCss = `.tb-slider-panel {\n`+ |
|||
`--tb-slider-main-color: ${this.settings.mainColor};\n`+ |
|||
`--tb-slider-background-color: ${this.settings.backgroundColor};\n`+ |
|||
`--tb-slider-hover-ripple-color: ${hoverRippleColor};\n`+ |
|||
`--tb-slider-focus-ripple-color: ${focusRippleColor};\n`+ |
|||
`--tb-slider-tick-marks-color: ${this.settings.tickMarksColor};\n`+ |
|||
`--tb-slider-main-color-disabled: ${this.settings.mainColorDisabled};\n`+ |
|||
`--tb-slider-background-disabled: ${this.settings.backgroundColorDisabled};\n`+ |
|||
`}`; |
|||
this.sliderCssClass = |
|||
this.utils.applyCssToElement(this.renderer, this.elementRef.nativeElement, 'tb-slider', sliderVariablesCss); |
|||
|
|||
const getInitialStateSettings = |
|||
{...this.settings.initialState, actionLabel: this.ctx.translate.instant('widgets.slider.initial-value')}; |
|||
this.createValueGetter(getInitialStateSettings, ValueType.INTEGER, { |
|||
next: (value) => this.onValue(value) |
|||
}); |
|||
|
|||
const disabledStateSettings = |
|||
{...this.settings.disabledState, actionLabel: this.ctx.translate.instant('widgets.rpc-state.disabled-state')}; |
|||
this.createValueGetter(disabledStateSettings, ValueType.BOOLEAN, { |
|||
next: (value) => this.onDisabled(value) |
|||
}); |
|||
|
|||
const valueChangeSettings = {...this.settings.valueChange, |
|||
actionLabel: this.ctx.translate.instant('widgets.slider.on-value-change')}; |
|||
this.valueSetter = this.createValueSetter(valueChangeSettings); |
|||
} |
|||
|
|||
ngAfterViewInit(): void { |
|||
if (this.autoScale) { |
|||
this.panelResize$ = new ResizeObserver(() => { |
|||
this.onResize(); |
|||
}); |
|||
this.panelResize$.observe(this.sliderContent.nativeElement); |
|||
if (this.showValue) { |
|||
this.panelResize$.observe(this.sliderValueContainer.nativeElement); |
|||
} |
|||
this.onResize(); |
|||
} |
|||
super.ngAfterViewInit(); |
|||
} |
|||
|
|||
ngOnDestroy() { |
|||
if (this.panelResize$) { |
|||
this.panelResize$.disconnect(); |
|||
} |
|||
if (this.sliderCssClass) { |
|||
this.utils.clearCssElement(this.renderer, this.sliderCssClass); |
|||
} |
|||
super.ngOnDestroy(); |
|||
} |
|||
|
|||
public onInit() { |
|||
super.onInit(); |
|||
const borderRadius = this.ctx.$widgetElement.css('borderRadius'); |
|||
this.overlayStyle = {...this.overlayStyle, ...{borderRadius}}; |
|||
this.cd.detectChanges(); |
|||
} |
|||
|
|||
public onSliderChange() { |
|||
this.updateValueText(); |
|||
if (!this.ctx.isEdit && !this.ctx.isPreview) { |
|||
const prevValue = this.prevValue; |
|||
const targetValue = this.value; |
|||
this.updateValue(this.valueSetter, targetValue, { |
|||
next: () => this.onValue(targetValue), |
|||
error: () => this.onValue(prevValue) |
|||
}); |
|||
} |
|||
} |
|||
|
|||
private _sliderValueText(value: number): string { |
|||
return formatValue(value, this.settings.valueDecimals, this.settings.valueUnits, false); |
|||
} |
|||
|
|||
private onValue(value: number): void { |
|||
this.value = value; |
|||
this.prevValue = value; |
|||
this.updateValueText(); |
|||
this.cd.markForCheck(); |
|||
} |
|||
|
|||
private updateValueText() { |
|||
if (isDefinedAndNotNull(this.value) && isNumeric(this.value)) { |
|||
this.valueText = formatValue(this.value, this.settings.valueDecimals, this.settings.valueUnits, false); |
|||
} else { |
|||
this.valueText = 'N/A'; |
|||
} |
|||
} |
|||
|
|||
private onDisabled(value: boolean): void { |
|||
this.disabled = !!value; |
|||
this.cd.markForCheck(); |
|||
} |
|||
|
|||
private onResize() { |
|||
const panelWidth = this.sliderContent.nativeElement.getBoundingClientRect().width; |
|||
const panelHeight = this.sliderContent.nativeElement.getBoundingClientRect().height; |
|||
|
|||
if (this.showValue) { |
|||
this.resetScale(this.sliderValueContainer.nativeElement, this.sliderValue.nativeElement); |
|||
} |
|||
|
|||
if (this.showLeftRightIcon) { |
|||
this.resetScale(this.leftSliderIconContainer.nativeElement, this.leftSliderIcon.nativeElement); |
|||
this.resetScale(this.rightSliderIconContainer.nativeElement, this.rightSliderIcon.nativeElement); |
|||
} |
|||
|
|||
if (this.showTicks) { |
|||
this.resetScale(this.sliderTickMinContainer.nativeElement, this.sliderTickMin.nativeElement); |
|||
this.resetScale(this.sliderTickMaxContainer.nativeElement, this.sliderTickMax.nativeElement); |
|||
} |
|||
|
|||
let minAspect = 0.2; |
|||
let avgContentHeight = 35; |
|||
if (this.showTicks) { |
|||
minAspect += 0.1; |
|||
avgContentHeight += 20; |
|||
} |
|||
if (this.showValue) { |
|||
minAspect += 0.1; |
|||
avgContentHeight += 50; |
|||
} |
|||
const aspect = Math.min(panelHeight / panelWidth, minAspect); |
|||
const targetHeight = panelWidth * aspect; |
|||
const scale = targetHeight / avgContentHeight; |
|||
|
|||
if (this.showValue) { |
|||
this.updateScale(this.sliderValueContainer.nativeElement, this.sliderValue.nativeElement, scale); |
|||
} |
|||
if (this.showLeftRightIcon) { |
|||
const leftIconContainerRect = this.leftSliderIconContainer.nativeElement.getBoundingClientRect(); |
|||
const leftIconContainerMarginTop = -(leftIconContainerRect.width * scale) / 2 + 3; |
|||
this.renderer.setStyle(this.leftSliderIconContainer.nativeElement, 'marginTop', `${leftIconContainerMarginTop}px`); |
|||
this.updateScale(this.leftSliderIconContainer.nativeElement, this.leftSliderIcon.nativeElement, scale, true); |
|||
const rightIconContainerRect = this.rightSliderIconContainer.nativeElement.getBoundingClientRect(); |
|||
const rightIconContainerMarginTop = -(rightIconContainerRect.width * scale) / 2 + 3; |
|||
this.renderer.setStyle(this.rightSliderIconContainer.nativeElement, 'marginTop', `${rightIconContainerMarginTop}px`); |
|||
this.updateScale(this.rightSliderIconContainer.nativeElement, this.rightSliderIcon.nativeElement, scale, true); |
|||
} |
|||
if (this.showTicks) { |
|||
this.updateScale(this.sliderTickMinContainer.nativeElement, this.sliderTickMin.nativeElement, scale); |
|||
this.updateScale(this.sliderTickMaxContainer.nativeElement, this.sliderTickMax.nativeElement, scale); |
|||
} |
|||
} |
|||
|
|||
private resetScale(container: HTMLElement, element: HTMLElement): void { |
|||
this.renderer.setStyle(container, 'width', ''); |
|||
this.renderer.setStyle(container, 'height', ''); |
|||
this.renderer.setStyle(element, 'transform', ''); |
|||
} |
|||
|
|||
private updateScale(container: HTMLElement, element: HTMLElement, scale: number, sameHeight = false): void { |
|||
const rect = container.getBoundingClientRect(); |
|||
this.renderer.setStyle(container, 'width', `${rect.width * scale}px`); |
|||
this.renderer.setStyle(container, 'height', `${(sameHeight ? rect.width : rect.height) * scale}px`); |
|||
this.renderer.setStyle(element, 'transform', `scale(${scale})`); |
|||
this.renderer.setStyle(element, 'transform-origin', 'left top'); |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,196 @@ |
|||
///
|
|||
/// Copyright © 2016-2024 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.
|
|||
///
|
|||
|
|||
import { |
|||
DataToValueType, |
|||
GetValueAction, |
|||
GetValueSettings, |
|||
SetValueAction, |
|||
SetValueSettings, |
|||
ValueToDataType |
|||
} from '@shared/models/action-widget-settings.models'; |
|||
import { BackgroundSettings, BackgroundType, cssUnit, Font } from '@shared/models/widget-settings.models'; |
|||
import { AttributeScope } from '@shared/models/telemetry/telemetry.models'; |
|||
|
|||
export enum SliderLayout { |
|||
default = 'default', |
|||
extended = 'extended', |
|||
simplified = 'simplified' |
|||
} |
|||
|
|||
export const sliderLayouts = Object.keys(SliderLayout) as SliderLayout[]; |
|||
|
|||
export const sliderLayoutTranslations = new Map<SliderLayout, string>( |
|||
[ |
|||
[SliderLayout.default, 'widgets.slider.layout-default'], |
|||
[SliderLayout.extended, 'widgets.slider.layout-extended'], |
|||
[SliderLayout.simplified, 'widgets.slider.layout-simplified'] |
|||
] |
|||
); |
|||
|
|||
export const sliderLayoutImages = new Map<SliderLayout, string>( |
|||
[ |
|||
[SliderLayout.default, 'assets/widget/slider/default-layout.svg'], |
|||
[SliderLayout.extended, 'assets/widget/slider/extended-layout.svg'], |
|||
[SliderLayout.simplified, 'assets/widget/slider/simplified-layout.svg'] |
|||
] |
|||
); |
|||
|
|||
export interface SliderWidgetSettings { |
|||
initialState: GetValueSettings<number>; |
|||
disabledState: GetValueSettings<boolean>; |
|||
valueChange: SetValueSettings; |
|||
layout: SliderLayout; |
|||
autoScale: boolean; |
|||
showValue: boolean; |
|||
valueUnits: string; |
|||
valueDecimals: number; |
|||
valueFont: Font; |
|||
valueColor: string; |
|||
showTicks: boolean; |
|||
tickMin: number; |
|||
tickMax: number; |
|||
ticksFont: Font; |
|||
ticksColor: string; |
|||
showTickMarks: boolean; |
|||
tickMarksCount: number; |
|||
tickMarksColor: string; |
|||
mainColor: string; |
|||
backgroundColor: string; |
|||
mainColorDisabled: string; |
|||
backgroundColorDisabled: string; |
|||
leftIcon: string; |
|||
leftIconSize: number; |
|||
leftIconSizeUnit: cssUnit; |
|||
leftIconColor: string; |
|||
rightIcon: string; |
|||
rightIconSize: number; |
|||
rightIconSizeUnit: cssUnit; |
|||
rightIconColor: string; |
|||
background: BackgroundSettings; |
|||
} |
|||
|
|||
export const sliderWidgetDefaultSettings: SliderWidgetSettings = { |
|||
initialState: { |
|||
action: GetValueAction.EXECUTE_RPC, |
|||
defaultValue: 0, |
|||
executeRpc: { |
|||
method: 'getState', |
|||
requestTimeout: 5000, |
|||
requestPersistent: false, |
|||
persistentPollingInterval: 1000 |
|||
}, |
|||
getAttribute: { |
|||
key: 'state', |
|||
scope: null |
|||
}, |
|||
getTimeSeries: { |
|||
key: 'state' |
|||
}, |
|||
dataToValue: { |
|||
type: DataToValueType.NONE, |
|||
compareToValue: true, |
|||
dataToValueFunction: '/* Should return integer value */\nreturn data;' |
|||
} |
|||
}, |
|||
disabledState: { |
|||
action: GetValueAction.DO_NOTHING, |
|||
defaultValue: false, |
|||
getAttribute: { |
|||
key: 'state', |
|||
scope: null |
|||
}, |
|||
getTimeSeries: { |
|||
key: 'state' |
|||
}, |
|||
dataToValue: { |
|||
type: DataToValueType.NONE, |
|||
compareToValue: true, |
|||
dataToValueFunction: '/* Should return boolean value */\nreturn data;' |
|||
} |
|||
}, |
|||
valueChange: { |
|||
action: SetValueAction.EXECUTE_RPC, |
|||
executeRpc: { |
|||
method: 'setState', |
|||
requestTimeout: 5000, |
|||
requestPersistent: false, |
|||
persistentPollingInterval: 1000 |
|||
}, |
|||
setAttribute: { |
|||
key: 'state', |
|||
scope: AttributeScope.SHARED_SCOPE |
|||
}, |
|||
putTimeSeries: { |
|||
key: 'state' |
|||
}, |
|||
valueToData: { |
|||
type: ValueToDataType.VALUE, |
|||
constantValue: 0, |
|||
valueToDataFunction: '/* Convert input integer value to RPC parameters or attribute/time-series value */\nreturn value;' |
|||
} |
|||
}, |
|||
layout: SliderLayout.default, |
|||
autoScale: true, |
|||
showValue: true, |
|||
valueUnits: '%', |
|||
valueDecimals: 0, |
|||
valueFont: { |
|||
family: 'Roboto', |
|||
size: 36, |
|||
sizeUnit: 'px', |
|||
style: 'normal', |
|||
weight: '500', |
|||
lineHeight: '36px' |
|||
}, |
|||
valueColor: 'rgba(0, 0, 0, 0.87)', |
|||
showTicks: true, |
|||
tickMin: 0, |
|||
tickMax: 100, |
|||
ticksFont: { |
|||
family: 'Roboto', |
|||
size: 11, |
|||
sizeUnit: 'px', |
|||
style: 'normal', |
|||
weight: '400', |
|||
lineHeight: '16px' |
|||
}, |
|||
ticksColor: 'rgba(0,0,0,0.54)', |
|||
showTickMarks: true, |
|||
tickMarksCount: 11, |
|||
tickMarksColor: '#5469FF', |
|||
mainColor: '#5469FF', |
|||
backgroundColor: '#CCD2FF', |
|||
mainColorDisabled: '#9BA2B0', |
|||
backgroundColorDisabled: '#D5D7E5', |
|||
leftIcon: 'lightbulb', |
|||
leftIconSize: 24, |
|||
leftIconSizeUnit: 'px', |
|||
leftIconColor: '#5469FF', |
|||
rightIcon: 'mdi:lightbulb-on', |
|||
rightIconSize: 24, |
|||
rightIconSizeUnit: 'px', |
|||
rightIconColor: '#5469FF', |
|||
background: { |
|||
type: BackgroundType.color, |
|||
color: '#fff', |
|||
overlay: { |
|||
enabled: false, |
|||
color: 'rgba(255,255,255,0.72)', |
|||
blur: 3 |
|||
} |
|||
} |
|||
}; |
|||
@ -0,0 +1,142 @@ |
|||
<!-- |
|||
|
|||
Copyright © 2016-2024 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. |
|||
|
|||
--> |
|||
<ng-container [formGroup]="powerButtonWidgetSettingsForm"> |
|||
<div class="tb-form-panel"> |
|||
<div class="tb-form-panel-title" translate>widgets.power-button.behavior</div> |
|||
<div class="tb-form-row"> |
|||
<div class="fixed-title-width" tb-hint-tooltip-icon="{{'widgets.rpc-state.initial-state-hint' | translate}}" translate>widgets.rpc-state.initial-state</div> |
|||
<tb-get-value-action-settings fxFlex |
|||
panelTitle="widgets.rpc-state.initial-state" |
|||
[valueType]="valueType.BOOLEAN" |
|||
trueLabel="widgets.rpc-state.on" |
|||
falseLabel="widgets.rpc-state.off" |
|||
stateLabel="widgets.rpc-state.on" |
|||
[aliasController]="aliasController" |
|||
[targetDevice]="targetDevice" |
|||
[widgetType]="widgetType" |
|||
formControlName="initialState"></tb-get-value-action-settings> |
|||
</div> |
|||
<div class="tb-form-row space-between"> |
|||
<div class="fixed-title-width" tb-hint-tooltip-icon="{{'widgets.power-button.power-on-hint' | translate}}" translate>widgets.power-button.power-on</div> |
|||
<tb-set-value-action-settings fxFlex |
|||
panelTitle="widgets.power-button.power-on " |
|||
[aliasController]="aliasController" |
|||
[targetDevice]="targetDevice" |
|||
[widgetType]="widgetType" |
|||
formControlName="onUpdateState"></tb-set-value-action-settings> |
|||
</div> |
|||
<div class="tb-form-row space-between"> |
|||
<div class="fixed-title-width" tb-hint-tooltip-icon="{{'widgets.power-button.power-off-hint' | translate}}" translate>widgets.power-button.power-off</div> |
|||
<tb-set-value-action-settings fxFlex |
|||
panelTitle="widgets.power-button.power-off" |
|||
[aliasController]="aliasController" |
|||
[targetDevice]="targetDevice" |
|||
[widgetType]="widgetType" |
|||
formControlName="offUpdateState"></tb-set-value-action-settings> |
|||
</div> |
|||
<div class="tb-form-row"> |
|||
<div class="fixed-title-width" tb-hint-tooltip-icon="{{'widgets.rpc-state.disabled-state-hint' | translate}}" translate>widgets.rpc-state.disabled-state</div> |
|||
<tb-get-value-action-settings fxFlex |
|||
panelTitle="widgets.rpc-state.disabled-state" |
|||
[valueType]="valueType.BOOLEAN" |
|||
stateLabel="widgets.rpc-state.disabled" |
|||
[aliasController]="aliasController" |
|||
[targetDevice]="targetDevice" |
|||
[widgetType]="widgetType" |
|||
formControlName="disabledState"></tb-get-value-action-settings> |
|||
</div> |
|||
</div> |
|||
<div class="tb-form-panel"> |
|||
<div class="tb-form-panel-title" translate>widget-config.card-style</div> |
|||
<tb-image-cards-select rowHeight="1:1" |
|||
[cols]="{columns: 3, |
|||
breakpoints: { |
|||
'lt-sm': 1, |
|||
'lt-md': 2 |
|||
}}" |
|||
label="{{ 'widgets.power-button.layout' | translate }}" formControlName="layout"> |
|||
<tb-image-cards-select-option *ngFor="let layout of powerButtonLayouts" |
|||
[value]="layout" |
|||
[image]="powerButtonLayoutImageMap.get(layout)"> |
|||
{{ powerButtonLayoutTranslationMap.get(layout) | translate }} |
|||
</tb-image-cards-select-option> |
|||
</tb-image-cards-select> |
|||
<div class="tb-form-row space-between"> |
|||
<div>{{ 'widgets.background.background' | translate }}</div> |
|||
<tb-background-settings formControlName="background"> |
|||
</tb-background-settings> |
|||
</div> |
|||
</div> |
|||
<div class="tb-form-panel"> |
|||
<div class="tb-form-panel-title" translate>widgets.power-button.button</div> |
|||
<div class="tb-form-row space-between column-xs"> |
|||
<div>{{ 'widgets.power-button.power-on-colors' | translate }}</div> |
|||
<div fxLayout="row" fxLayoutAlign="start center" fxLayoutGap="12px"> |
|||
<div fxLayout="row" fxLayoutAlign="start center" fxLayoutGap="8px"> |
|||
<div translate>widgets.power-button.main</div> |
|||
<tb-color-input asBoxInput |
|||
formControlName="mainColorOn"> |
|||
</tb-color-input> |
|||
</div> |
|||
<mat-divider vertical></mat-divider> |
|||
<div fxLayout="row" fxLayoutAlign="start center" fxLayoutGap="8px"> |
|||
<div translate>widgets.power-button.background</div> |
|||
<tb-color-input asBoxInput |
|||
formControlName="backgroundColorOn"> |
|||
</tb-color-input> |
|||
</div> |
|||
</div> |
|||
</div> |
|||
<div class="tb-form-row space-between column-xs"> |
|||
<div>{{ 'widgets.power-button.power-off-colors' | translate }}</div> |
|||
<div fxLayout="row" fxLayoutAlign="start center" fxLayoutGap="12px"> |
|||
<div fxLayout="row" fxLayoutAlign="start center" fxLayoutGap="8px"> |
|||
<div translate>widgets.power-button.main</div> |
|||
<tb-color-input asBoxInput |
|||
formControlName="mainColorOff"> |
|||
</tb-color-input> |
|||
</div> |
|||
<mat-divider vertical></mat-divider> |
|||
<div fxLayout="row" fxLayoutAlign="start center" fxLayoutGap="8px"> |
|||
<div translate>widgets.power-button.background</div> |
|||
<tb-color-input asBoxInput |
|||
formControlName="backgroundColorOff"> |
|||
</tb-color-input> |
|||
</div> |
|||
</div> |
|||
</div> |
|||
<div class="tb-form-row space-between column-xs"> |
|||
<div>{{ 'widgets.power-button.disabled-colors' | translate }}</div> |
|||
<div fxLayout="row" fxLayoutAlign="start center" fxLayoutGap="12px"> |
|||
<div fxLayout="row" fxLayoutAlign="start center" fxLayoutGap="8px"> |
|||
<div translate>widgets.power-button.main</div> |
|||
<tb-color-input asBoxInput |
|||
formControlName="mainColorDisabled"> |
|||
</tb-color-input> |
|||
</div> |
|||
<mat-divider vertical></mat-divider> |
|||
<div fxLayout="row" fxLayoutAlign="start center" fxLayoutGap="8px"> |
|||
<div translate>widgets.power-button.background</div> |
|||
<tb-color-input asBoxInput |
|||
formControlName="backgroundColorDisabled"> |
|||
</tb-color-input> |
|||
</div> |
|||
</div> |
|||
</div> |
|||
</div> |
|||
</ng-container> |
|||
@ -0,0 +1,88 @@ |
|||
///
|
|||
/// Copyright © 2016-2024 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.
|
|||
///
|
|||
|
|||
import { Component } from '@angular/core'; |
|||
import { TargetDevice, WidgetSettings, WidgetSettingsComponent, widgetType } from '@shared/models/widget.models'; |
|||
import { UntypedFormBuilder, UntypedFormGroup } from '@angular/forms'; |
|||
import { Store } from '@ngrx/store'; |
|||
import { AppState } from '@core/core.state'; |
|||
import { ValueType } from '@shared/models/constants'; |
|||
import { |
|||
powerButtonDefaultSettings, |
|||
powerButtonLayoutImages, |
|||
powerButtonLayouts, |
|||
powerButtonLayoutTranslations |
|||
} from '@home/components/widget/lib/rpc/power-button-widget.models'; |
|||
|
|||
@Component({ |
|||
selector: 'tb-power-button-widget-settings', |
|||
templateUrl: './power-button-widget-settings.component.html', |
|||
styleUrls: ['./../widget-settings.scss'] |
|||
}) |
|||
export class PowerButtonWidgetSettingsComponent extends WidgetSettingsComponent { |
|||
|
|||
get targetDevice(): TargetDevice { |
|||
return this.widgetConfig?.config?.targetDevice; |
|||
} |
|||
|
|||
get widgetType(): widgetType { |
|||
return this.widgetConfig?.widgetType; |
|||
} |
|||
|
|||
powerButtonLayouts = powerButtonLayouts; |
|||
|
|||
powerButtonLayoutTranslationMap = powerButtonLayoutTranslations; |
|||
powerButtonLayoutImageMap = powerButtonLayoutImages; |
|||
|
|||
valueType = ValueType; |
|||
|
|||
powerButtonWidgetSettingsForm: UntypedFormGroup; |
|||
|
|||
constructor(protected store: Store<AppState>, |
|||
private fb: UntypedFormBuilder) { |
|||
super(store); |
|||
} |
|||
|
|||
protected settingsForm(): UntypedFormGroup { |
|||
return this.powerButtonWidgetSettingsForm; |
|||
} |
|||
|
|||
protected defaultSettings(): WidgetSettings { |
|||
return {...powerButtonDefaultSettings}; |
|||
} |
|||
|
|||
protected onSettingsSet(settings: WidgetSettings) { |
|||
this.powerButtonWidgetSettingsForm = this.fb.group({ |
|||
initialState: [settings.initialState, []], |
|||
onUpdateState: [settings.onUpdateState, []], |
|||
offUpdateState: [settings.offUpdateState, []], |
|||
disabledState: [settings.disabledState, []], |
|||
|
|||
layout: [settings.layout, []], |
|||
|
|||
mainColorOn: [settings.mainColorOn, []], |
|||
backgroundColorOn: [settings.backgroundColorOn, []], |
|||
|
|||
mainColorOff: [settings.mainColorOff, []], |
|||
backgroundColorOff: [settings.backgroundColorOff, []], |
|||
|
|||
mainColorDisabled: [settings.mainColorDisabled, []], |
|||
backgroundColorDisabled: [settings.backgroundColorDisabled, []], |
|||
|
|||
background: [settings.background, []] |
|||
}); |
|||
} |
|||
} |
|||
@ -0,0 +1,216 @@ |
|||
<!-- |
|||
|
|||
Copyright © 2016-2024 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. |
|||
|
|||
--> |
|||
<ng-container [formGroup]="sliderWidgetSettingsForm"> |
|||
<div class="tb-form-panel"> |
|||
<div class="tb-form-panel-title" translate>widgets.slider.behavior</div> |
|||
<div class="tb-form-row"> |
|||
<div class="fixed-title-width" tb-hint-tooltip-icon="{{'widgets.slider.initial-value-hint' | translate}}" translate>widgets.slider.initial-value</div> |
|||
<tb-get-value-action-settings fxFlex |
|||
panelTitle="widgets.slider.initial-value" |
|||
[valueType]="valueType.DOUBLE" |
|||
[aliasController]="aliasController" |
|||
[targetDevice]="targetDevice" |
|||
[widgetType]="widgetType" |
|||
formControlName="initialState"></tb-get-value-action-settings> |
|||
</div> |
|||
<div class="tb-form-row space-between"> |
|||
<div class="fixed-title-width" tb-hint-tooltip-icon="{{'widgets.slider.on-value-change-hint' | translate}}" translate>widgets.slider.on-value-change</div> |
|||
<tb-set-value-action-settings fxFlex |
|||
panelTitle="widgets.slider.on-value-change" |
|||
[valueType]="valueType.DOUBLE" |
|||
[aliasController]="aliasController" |
|||
[targetDevice]="targetDevice" |
|||
[widgetType]="widgetType" |
|||
formControlName="valueChange"></tb-set-value-action-settings> |
|||
</div> |
|||
<div class="tb-form-row"> |
|||
<div class="fixed-title-width" tb-hint-tooltip-icon="{{'widgets.rpc-state.disabled-state-hint' | translate}}" translate>widgets.rpc-state.disabled-state</div> |
|||
<tb-get-value-action-settings fxFlex |
|||
panelTitle="widgets.rpc-state.disabled-state" |
|||
[valueType]="valueType.BOOLEAN" |
|||
stateLabel="widgets.rpc-state.disabled" |
|||
[aliasController]="aliasController" |
|||
[targetDevice]="targetDevice" |
|||
[widgetType]="widgetType" |
|||
formControlName="disabledState"></tb-get-value-action-settings> |
|||
</div> |
|||
</div> |
|||
<div class="tb-form-panel"> |
|||
<div class="tb-form-panel-title" translate>widget-config.card-style</div> |
|||
<tb-image-cards-select rowHeight="2:1" |
|||
[cols]="{columns: 3, |
|||
breakpoints: { |
|||
'lt-sm': 1, |
|||
'lt-md': 2 |
|||
}}" |
|||
label="{{ 'widgets.slider.layout' | translate }}" formControlName="layout"> |
|||
<tb-image-cards-select-option *ngFor="let layout of sliderLayouts" |
|||
[value]="layout" |
|||
[image]="sliderLayoutImageMap.get(layout)"> |
|||
{{ sliderLayoutTranslationMap.get(layout) | translate }} |
|||
</tb-image-cards-select-option> |
|||
</tb-image-cards-select> |
|||
<div class="tb-form-row"> |
|||
<mat-slide-toggle class="mat-slide" formControlName="autoScale"> |
|||
{{ 'widgets.slider.auto-scale' | translate }} |
|||
</mat-slide-toggle> |
|||
</div> |
|||
<div class="tb-form-row space-between"> |
|||
<div>{{ 'widgets.background.background' | translate }}</div> |
|||
<tb-background-settings formControlName="background"> |
|||
</tb-background-settings> |
|||
</div> |
|||
</div> |
|||
<div class="tb-form-panel"> |
|||
<div class="tb-form-panel-title" translate>widgets.slider.slider</div> |
|||
<div *ngIf="sliderWidgetSettingsForm.get('layout').value !== sliderLayout.simplified" class="tb-form-row column-xs"> |
|||
<mat-slide-toggle class="mat-slide fixed-title-width" formControlName="showValue"> |
|||
{{ 'widgets.slider.value' | translate }} |
|||
</mat-slide-toggle> |
|||
<div fxFlex fxLayout="row" fxLayoutAlign="start center" fxLayoutGap="8px"> |
|||
<tb-unit-input class="flex" formControlName="valueUnits"></tb-unit-input> |
|||
<mat-form-field appearance="outline" class="flex number" subscriptSizing="dynamic"> |
|||
<input matInput formControlName="valueDecimals" type="number" min="0" max="15" step="1" placeholder="{{ 'widget-config.set' | translate }}"> |
|||
<div matSuffix fxHide.lt-md translate>widget-config.decimals-suffix</div> |
|||
</mat-form-field> |
|||
<tb-font-settings formControlName="valueFont" |
|||
[previewText]="valuePreviewFn"> |
|||
</tb-font-settings> |
|||
<tb-color-input asBoxInput |
|||
colorClearButton |
|||
formControlName="valueColor"> |
|||
</tb-color-input> |
|||
</div> |
|||
</div> |
|||
<div class="tb-form-row space-between column-xs"> |
|||
<div>{{ 'widgets.slider.range' | translate }}</div> |
|||
<div fxLayout="row" fxLayoutAlign="start center" fxLayoutGap="8px"> |
|||
<div class="tb-small-label" translate>widgets.slider.min</div> |
|||
<mat-form-field appearance="outline" class="number" subscriptSizing="dynamic"> |
|||
<input matInput formControlName="tickMin" type="number" placeholder="{{ 'widget-config.set' | translate }}"> |
|||
</mat-form-field> |
|||
<div class="tb-small-label" translate>widgets.slider.max</div> |
|||
<mat-form-field appearance="outline" class="number" subscriptSizing="dynamic"> |
|||
<input matInput formControlName="tickMax" type="number" placeholder="{{ 'widget-config.set' | translate }}"> |
|||
</mat-form-field> |
|||
</div> |
|||
</div> |
|||
<div class="tb-form-row space-between"> |
|||
<mat-slide-toggle class="mat-slide" formControlName="showTicks"> |
|||
{{ 'widgets.slider.range-ticks' | translate }} |
|||
</mat-slide-toggle> |
|||
<div fxLayout="row" fxLayoutAlign="start center" fxLayoutGap="8px"> |
|||
<tb-font-settings formControlName="ticksFont" |
|||
previewText="100"> |
|||
</tb-font-settings> |
|||
<tb-color-input asBoxInput |
|||
colorClearButton |
|||
formControlName="ticksColor"> |
|||
</tb-color-input> |
|||
</div> |
|||
</div> |
|||
<div class="tb-form-row space-between"> |
|||
<mat-slide-toggle class="mat-slide" formControlName="showTickMarks"> |
|||
{{ 'widgets.slider.tick-marks' | translate }} |
|||
</mat-slide-toggle> |
|||
<div fxLayout="row" fxLayoutAlign="start center" fxLayoutGap="8px"> |
|||
<mat-form-field appearance="outline" class="number" subscriptSizing="dynamic"> |
|||
<input matInput formControlName="tickMarksCount" type="number" min="2" |
|||
step="1" placeholder="{{ 'widget-config.set' | translate }}"> |
|||
</mat-form-field> |
|||
<tb-color-input asBoxInput |
|||
formControlName="tickMarksColor"> |
|||
</tb-color-input> |
|||
</div> |
|||
</div> |
|||
<div class="tb-form-row space-between column-xs"> |
|||
<div>{{ 'widgets.slider.colors' | translate }}</div> |
|||
<div fxLayout="row" fxLayoutAlign="start center" fxLayoutGap="12px"> |
|||
<div fxLayout="row" fxLayoutAlign="start center" fxLayoutGap="8px"> |
|||
<div translate>widgets.slider.main</div> |
|||
<tb-color-input asBoxInput |
|||
formControlName="mainColor"> |
|||
</tb-color-input> |
|||
</div> |
|||
<mat-divider vertical></mat-divider> |
|||
<div fxLayout="row" fxLayoutAlign="start center" fxLayoutGap="8px"> |
|||
<div translate>widgets.slider.background</div> |
|||
<tb-color-input asBoxInput |
|||
formControlName="backgroundColor"> |
|||
</tb-color-input> |
|||
</div> |
|||
</div> |
|||
</div> |
|||
<div class="tb-form-row space-between column-xs"> |
|||
<div>{{ 'widgets.rpc-state.disabled-state' | translate }}</div> |
|||
<div fxLayout="row" fxLayoutAlign="start center" fxLayoutGap="12px"> |
|||
<div fxLayout="row" fxLayoutAlign="start center" fxLayoutGap="8px"> |
|||
<div translate>widgets.slider.main</div> |
|||
<tb-color-input asBoxInput |
|||
formControlName="mainColorDisabled"> |
|||
</tb-color-input> |
|||
</div> |
|||
<mat-divider vertical></mat-divider> |
|||
<div fxLayout="row" fxLayoutAlign="start center" fxLayoutGap="8px"> |
|||
<div translate>widgets.slider.background</div> |
|||
<tb-color-input asBoxInput |
|||
formControlName="backgroundColorDisabled"> |
|||
</tb-color-input> |
|||
</div> |
|||
</div> |
|||
</div> |
|||
<div *ngIf="sliderWidgetSettingsForm.get('layout').value === sliderLayout.extended" |
|||
class="tb-form-row column-xs"> |
|||
<div class="fixed-title-width"> |
|||
{{ 'widgets.slider.left-icon' | translate }} |
|||
</div> |
|||
<div fxFlex fxLayout="row" fxLayoutAlign="start center" fxLayoutGap="8px"> |
|||
<mat-form-field appearance="outline" class="flex number" subscriptSizing="dynamic"> |
|||
<input matInput type="number" min="0" formControlName="leftIconSize" placeholder="{{ 'widget-config.set' | translate }}"> |
|||
</mat-form-field> |
|||
<tb-css-unit-select fxFlex formControlName="leftIconSizeUnit"></tb-css-unit-select> |
|||
<tb-material-icon-select asBoxInput |
|||
[color]="sliderWidgetSettingsForm.get('leftIconColor').value" |
|||
formControlName="leftIcon"> |
|||
</tb-material-icon-select> |
|||
<tb-color-input asBoxInput |
|||
formControlName="leftIconColor"> |
|||
</tb-color-input> |
|||
</div> |
|||
</div> |
|||
<div *ngIf="sliderWidgetSettingsForm.get('layout').value === sliderLayout.extended" |
|||
class="tb-form-row column-xs"> |
|||
<div class="fixed-title-width"> |
|||
{{ 'widgets.slider.right-icon' | translate }} |
|||
</div> |
|||
<div fxFlex fxLayout="row" fxLayoutAlign="start center" fxLayoutGap="8px"> |
|||
<mat-form-field appearance="outline" class="flex number" subscriptSizing="dynamic"> |
|||
<input matInput type="number" min="0" formControlName="rightIconSize" placeholder="{{ 'widget-config.set' | translate }}"> |
|||
</mat-form-field> |
|||
<tb-css-unit-select fxFlex formControlName="rightIconSizeUnit"></tb-css-unit-select> |
|||
<tb-material-icon-select asBoxInput |
|||
[color]="sliderWidgetSettingsForm.get('rightIconColor').value" |
|||
formControlName="rightIcon"> |
|||
</tb-material-icon-select> |
|||
<tb-color-input asBoxInput |
|||
formControlName="rightIconColor"> |
|||
</tb-color-input> |
|||
</div> |
|||
</div> |
|||
</div> |
|||
</ng-container> |
|||
@ -0,0 +1,186 @@ |
|||
///
|
|||
/// Copyright © 2016-2024 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.
|
|||
///
|
|||
|
|||
import { Component } from '@angular/core'; |
|||
import { TargetDevice, WidgetSettings, WidgetSettingsComponent, widgetType } from '@shared/models/widget.models'; |
|||
import { UntypedFormBuilder, UntypedFormGroup, Validators } from '@angular/forms'; |
|||
import { Store } from '@ngrx/store'; |
|||
import { AppState } from '@core/core.state'; |
|||
import { ValueType } from '@shared/models/constants'; |
|||
import { |
|||
SliderLayout, |
|||
sliderLayoutImages, |
|||
sliderLayouts, |
|||
sliderLayoutTranslations, |
|||
sliderWidgetDefaultSettings |
|||
} from '@home/components/widget/lib/rpc/slider-widget.models'; |
|||
import { formatValue } from '@core/utils'; |
|||
|
|||
@Component({ |
|||
selector: 'tb-slider-widget-settings', |
|||
templateUrl: './slider-widget-settings.component.html', |
|||
styleUrls: ['./../widget-settings.scss'] |
|||
}) |
|||
export class SliderWidgetSettingsComponent extends WidgetSettingsComponent { |
|||
|
|||
get targetDevice(): TargetDevice { |
|||
return this.widgetConfig?.config?.targetDevice; |
|||
} |
|||
|
|||
get widgetType(): widgetType { |
|||
return this.widgetConfig?.widgetType; |
|||
} |
|||
|
|||
sliderLayout = SliderLayout; |
|||
|
|||
sliderLayouts = sliderLayouts; |
|||
|
|||
sliderLayoutTranslationMap = sliderLayoutTranslations; |
|||
sliderLayoutImageMap = sliderLayoutImages; |
|||
|
|||
valueType = ValueType; |
|||
|
|||
sliderWidgetSettingsForm: UntypedFormGroup; |
|||
|
|||
valuePreviewFn = this._valuePreviewFn.bind(this); |
|||
|
|||
constructor(protected store: Store<AppState>, |
|||
private fb: UntypedFormBuilder) { |
|||
super(store); |
|||
} |
|||
|
|||
protected settingsForm(): UntypedFormGroup { |
|||
return this.sliderWidgetSettingsForm; |
|||
} |
|||
|
|||
protected defaultSettings(): WidgetSettings { |
|||
return {...sliderWidgetDefaultSettings}; |
|||
} |
|||
|
|||
protected onSettingsSet(settings: WidgetSettings) { |
|||
this.sliderWidgetSettingsForm = this.fb.group({ |
|||
initialState: [settings.initialState, []], |
|||
valueChange: [settings.valueChange, []], |
|||
disabledState: [settings.disabledState, []], |
|||
|
|||
layout: [settings.layout, []], |
|||
autoScale: [settings.autoScale, []], |
|||
|
|||
showValue: [settings.showValue, []], |
|||
valueUnits: [settings.valueUnits, []], |
|||
valueDecimals: [settings.valueDecimals, []], |
|||
valueFont: [settings.valueFont, []], |
|||
valueColor: [settings.valueColor, []], |
|||
|
|||
tickMin: [settings.tickMin, []], |
|||
tickMax: [settings.tickMax, []], |
|||
|
|||
showTicks: [settings.showTicks, []], |
|||
ticksFont: [settings.ticksFont, []], |
|||
ticksColor: [settings.ticksColor, []], |
|||
|
|||
showTickMarks: [settings.showTickMarks, []], |
|||
tickMarksCount: [settings.tickMarksCount, [Validators.min(2)]], |
|||
tickMarksColor: [settings.tickMarksColor, []], |
|||
|
|||
mainColor: [settings.mainColor, []], |
|||
backgroundColor: [settings.backgroundColor, []], |
|||
|
|||
mainColorDisabled: [settings.mainColorDisabled, []], |
|||
backgroundColorDisabled: [settings.backgroundColorDisabled, []], |
|||
|
|||
leftIconSize: [settings.leftIconSize, [Validators.min(0)]], |
|||
leftIconSizeUnit: [settings.leftIconSizeUnit, []], |
|||
leftIcon: [settings.leftIcon, []], |
|||
leftIconColor: [settings.leftIconColor, []], |
|||
|
|||
rightIconSize: [settings.rightIconSize, [Validators.min(0)]], |
|||
rightIconSizeUnit: [settings.rightIconSizeUnit, []], |
|||
rightIcon: [settings.rightIcon, []], |
|||
rightIconColor: [settings.rightIconColor, []], |
|||
|
|||
background: [settings.background, []], |
|||
}); |
|||
} |
|||
|
|||
protected validatorTriggers(): string[] { |
|||
return ['showValue', 'showTicks', 'showTickMarks', 'layout']; |
|||
} |
|||
|
|||
protected updateValidators(_emitEvent: boolean): void { |
|||
const showValue: boolean = this.sliderWidgetSettingsForm.get('showValue').value; |
|||
const showTicks: boolean = this.sliderWidgetSettingsForm.get('showTicks').value; |
|||
const showTickMarks: boolean = this.sliderWidgetSettingsForm.get('showTickMarks').value; |
|||
const layout: SliderLayout = this.sliderWidgetSettingsForm.get('layout').value; |
|||
|
|||
const valueEnabled = layout !== SliderLayout.simplified; |
|||
const leftRightIconsEnabled = layout === SliderLayout.extended; |
|||
|
|||
if (valueEnabled && showValue) { |
|||
this.sliderWidgetSettingsForm.get('valueUnits').enable(); |
|||
this.sliderWidgetSettingsForm.get('valueDecimals').enable(); |
|||
this.sliderWidgetSettingsForm.get('valueFont').enable(); |
|||
this.sliderWidgetSettingsForm.get('valueColor').enable(); |
|||
} else { |
|||
this.sliderWidgetSettingsForm.get('valueUnits').disable(); |
|||
this.sliderWidgetSettingsForm.get('valueDecimals').disable(); |
|||
this.sliderWidgetSettingsForm.get('valueFont').disable(); |
|||
this.sliderWidgetSettingsForm.get('valueColor').disable(); |
|||
} |
|||
|
|||
if (showTicks) { |
|||
this.sliderWidgetSettingsForm.get('ticksFont').enable(); |
|||
this.sliderWidgetSettingsForm.get('ticksColor').enable(); |
|||
} else { |
|||
this.sliderWidgetSettingsForm.get('ticksFont').disable(); |
|||
this.sliderWidgetSettingsForm.get('ticksColor').disable(); |
|||
} |
|||
|
|||
if (showTickMarks) { |
|||
this.sliderWidgetSettingsForm.get('tickMarksCount').enable(); |
|||
this.sliderWidgetSettingsForm.get('tickMarksColor').enable(); |
|||
} else { |
|||
this.sliderWidgetSettingsForm.get('tickMarksCount').disable(); |
|||
this.sliderWidgetSettingsForm.get('tickMarksColor').disable(); |
|||
} |
|||
|
|||
if (leftRightIconsEnabled) { |
|||
this.sliderWidgetSettingsForm.get('leftIconSize').enable(); |
|||
this.sliderWidgetSettingsForm.get('leftIconSizeUnit').enable(); |
|||
this.sliderWidgetSettingsForm.get('leftIcon').enable(); |
|||
this.sliderWidgetSettingsForm.get('leftIconColor').enable(); |
|||
this.sliderWidgetSettingsForm.get('rightIconSize').enable(); |
|||
this.sliderWidgetSettingsForm.get('rightIconSizeUnit').enable(); |
|||
this.sliderWidgetSettingsForm.get('rightIcon').enable(); |
|||
this.sliderWidgetSettingsForm.get('rightIconColor').enable(); |
|||
} else { |
|||
this.sliderWidgetSettingsForm.get('leftIconSize').disable(); |
|||
this.sliderWidgetSettingsForm.get('leftIconSizeUnit').disable(); |
|||
this.sliderWidgetSettingsForm.get('leftIcon').disable(); |
|||
this.sliderWidgetSettingsForm.get('leftIconColor').disable(); |
|||
this.sliderWidgetSettingsForm.get('rightIconSize').disable(); |
|||
this.sliderWidgetSettingsForm.get('rightIconSizeUnit').disable(); |
|||
this.sliderWidgetSettingsForm.get('rightIcon').disable(); |
|||
this.sliderWidgetSettingsForm.get('rightIconColor').disable(); |
|||
} |
|||
} |
|||
|
|||
private _valuePreviewFn(): string { |
|||
const units: string = this.sliderWidgetSettingsForm.get('valueUnits').value; |
|||
const decimals: number = this.sliderWidgetSettingsForm.get('valueDecimals').value; |
|||
return formatValue(48, decimals, units, false); |
|||
} |
|||
} |
|||
Some files were not shown because too many files changed in this diff
Loading…
Reference in new issue