30 changed files with 628 additions and 96 deletions
@ -0,0 +1,111 @@ |
|||
<!-- |
|||
|
|||
Copyright © 2016-2023 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-container"> |
|||
<label class="tb-title" *ngIf="label" [ngClass]="{'tb-error': !disabled && (required && !imageUrls.length), 'tb-required': !disabled && required}">{{label}}</label> |
|||
<div class="images-container" dndDropzone [dndHorizontal]="true" dndEffectAllowed="move" |
|||
[dndDisableIf]="disabled" (dndDrop)="imageDrop($event)" |
|||
fxLayout="row" fxLayoutGap="8px" [ngClass]="{'no-images': !imageUrls.length}"> |
|||
<div dndPlaceholderRef class="image-card image-dnd-placeholder"></div> |
|||
<div *ngFor="let imageUrl of imageUrls; let $index = index;" |
|||
(dndStart)="imageDragStart($index)" |
|||
(dndEnd)="imageDragEnd()" |
|||
[dndDraggable]="imageUrl" |
|||
[dndDisableIf]="disabled" |
|||
dndEffectAllowed="move" |
|||
[ngClass]="{'image-dragging': dragIndex === $index}" |
|||
class="image-card" fxLayout="column"> |
|||
<span class="image-title">{{ 'image-input.images' | translate }} [{{ $index }}]</span> |
|||
<div class="image-content-container" fxLayout="row"> |
|||
<div dndHandle *ngIf="!disabled" class="tb-image-action-container tb-drag-handle"> |
|||
<mat-icon color="primary">drag_indicator</mat-icon> |
|||
</div> |
|||
<div class="tb-image-preview-container"> |
|||
<img class="tb-image-preview" [src]="imageUrl | image: {preview: true} | async" /> |
|||
</div> |
|||
<div *ngIf="!disabled" class="tb-image-action-container"> |
|||
<button mat-icon-button color="primary" |
|||
type="button" |
|||
(click)="clearImage($index)" |
|||
matTooltip="{{ 'action.remove' | translate }}" |
|||
matTooltipPosition="above"> |
|||
<mat-icon>close</mat-icon> |
|||
</button> |
|||
</div> |
|||
</div> |
|||
</div> |
|||
<div class="no-images-prompt" *ngIf="!imageUrls.length">{{ 'image-input.no-images' | translate }}</div> |
|||
</div> |
|||
<div *ngIf="!disabled" class="tb-image-select-container"> |
|||
<div class="tb-image-container" *ngIf="linkType === ImageLinkType.external"> |
|||
<img *ngIf="externalLinkControl.value; else noImage" class="tb-image-preview" [src]="externalLinkControl.value | image | async"> |
|||
</div> |
|||
<div *ngIf="linkType === ImageLinkType.external" class="tb-image-info-container"> |
|||
<div class="tb-external-image-container"> |
|||
<div class="tb-external-link-label"> |
|||
{{ 'image.image-link' | translate }} |
|||
</div> |
|||
<div class="tb-external-link-input-container"> |
|||
<mat-form-field class="tb-inline-field" appearance="outline" subscriptSizing="dynamic"> |
|||
<input matInput [formControl]="externalLinkControl" placeholder="{{ 'widget-config.set' | translate }}"> |
|||
</mat-form-field> |
|||
<button class="tb-image-decline-btn" |
|||
type="button" |
|||
mat-icon-button |
|||
matTooltip="{{ 'action.decline' | translate }}" |
|||
matTooltipPosition="above" |
|||
(click)="declineLink($event)"> |
|||
<mat-icon>close</mat-icon> |
|||
</button> |
|||
<button class="tb-image-apply-btn" |
|||
type="button" |
|||
[disabled]="!externalLinkControl.value" |
|||
color="primary" |
|||
mat-icon-button |
|||
matTooltip="{{ 'action.apply' | translate }}" |
|||
matTooltipPosition="above" |
|||
(click)="applyLink($event)"> |
|||
<mat-icon>check</mat-icon> |
|||
</button> |
|||
</div> |
|||
</div> |
|||
</div> |
|||
<div *ngIf="linkType === ImageLinkType.none" class="tb-image-select-buttons-container"> |
|||
<button #browseGalleryButton |
|||
mat-stroked-button |
|||
type="button" |
|||
color="primary" |
|||
class="tb-image-select-button" |
|||
(click)="toggleGallery($event, browseGalleryButton)"> |
|||
<tb-icon matButtonIcon>filter</tb-icon> |
|||
<span translate>image.browse-from-gallery</span> |
|||
</button> |
|||
<button mat-stroked-button |
|||
type="button" |
|||
color="primary" |
|||
class="tb-image-select-button" |
|||
(click)="setLink($event)"> |
|||
<tb-icon matButtonIcon>link</tb-icon> |
|||
<span translate>image.set-link</span> |
|||
</button> |
|||
</div> |
|||
</div> |
|||
</div> |
|||
|
|||
<ng-template #noImage> |
|||
<div class="tb-no-image">{{ 'image.no-image-selected' | translate }}</div> |
|||
</ng-template> |
|||
@ -0,0 +1,225 @@ |
|||
/** |
|||
* Copyright © 2016-2023 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 "../../../../../scss/constants"; |
|||
|
|||
$imagesContainerHeight: 106px !default; |
|||
$selectContainerHeight: 96px !default; |
|||
$previewSize: 64px !default; |
|||
|
|||
.image-card { |
|||
margin-bottom: 8px; |
|||
&.image-dnd-placeholder { |
|||
height: 82px; |
|||
width: 146px; |
|||
border: 2px dashed rgba(0, 0, 0, 0.2); |
|||
background: rgba(0, 0, 0, 0.1); |
|||
border-radius: 4px; |
|||
} |
|||
&.image-dragging { |
|||
display: none !important; |
|||
} |
|||
.image-title { |
|||
font-size: 11px; |
|||
font-weight: 400; |
|||
line-height: 14px; |
|||
color: rgba(0, 0, 0, 0.6); |
|||
padding-bottom: 4px; |
|||
} |
|||
|
|||
.image-content-container { |
|||
background: #FFFFFF; |
|||
border: 1px solid rgba(0, 0, 0, 0.2); |
|||
border-radius: 4px; |
|||
height: $previewSize; |
|||
} |
|||
|
|||
.tb-image-preview { |
|||
width: auto; |
|||
max-width: $previewSize - 2px; |
|||
height: auto; |
|||
max-height: $previewSize - 2px; |
|||
} |
|||
|
|||
.tb-image-preview-container { |
|||
position: relative; |
|||
width: $previewSize; |
|||
height: $previewSize; |
|||
margin-top: -1px; |
|||
margin-bottom: -1px; |
|||
border: 1px solid rgba(0, 0, 0, 0.54); |
|||
|
|||
.tb-image-preview { |
|||
position: absolute; |
|||
top: 50%; |
|||
left: 50%; |
|||
transform: translate(-50%, -50%); |
|||
} |
|||
} |
|||
|
|||
.tb-image-action-container { |
|||
position: relative; |
|||
height: $previewSize - 2px; |
|||
display: flex; |
|||
align-items: center; |
|||
justify-content: center; |
|||
min-width: 40px; |
|||
} |
|||
} |
|||
|
|||
:host { |
|||
.tb-container { |
|||
margin-top: 0; |
|||
padding: 0 0 16px; |
|||
display: flex; |
|||
flex-direction: column; |
|||
gap: 8px; |
|||
label.tb-title { |
|||
display: block; |
|||
padding-bottom: 0; |
|||
} |
|||
} |
|||
|
|||
.images-container { |
|||
padding: 12px 12px 4px; |
|||
background: rgba(0, 0, 0, 0.03); |
|||
border-radius: 4px; |
|||
flex-wrap: wrap; |
|||
margin-bottom: 8px; |
|||
&.no-images { |
|||
height: $imagesContainerHeight; |
|||
padding-bottom: 12px; |
|||
align-items: center; |
|||
justify-content: center; |
|||
} |
|||
} |
|||
|
|||
.no-images-prompt { |
|||
font-size: 18px; |
|||
color: rgba(0, 0, 0, 0.54); |
|||
} |
|||
|
|||
.tb-image-select-container { |
|||
width: 100%; |
|||
height: $selectContainerHeight; |
|||
border-radius: 4px; |
|||
border: 1px solid rgba(0, 0, 0, 0.12); |
|||
display: flex; |
|||
align-items: center; |
|||
|
|||
.tb-image-container { |
|||
width: $selectContainerHeight - 1px; |
|||
height: $selectContainerHeight - 2px; |
|||
display: flex; |
|||
justify-content: center; |
|||
align-items: center; |
|||
border-radius: 4px; |
|||
border-right: 1px solid rgba(0, 0, 0, 0.12); |
|||
background: #fff; |
|||
overflow: hidden; |
|||
|
|||
.tb-image-preview { |
|||
width: auto; |
|||
max-width: $selectContainerHeight - 2px; |
|||
height: auto; |
|||
max-height: $selectContainerHeight - 2px; |
|||
} |
|||
|
|||
.tb-no-image { |
|||
text-align: center; |
|||
color: rgba(0, 0, 0, 0.38); |
|||
font-size: 12px; |
|||
font-style: normal; |
|||
font-weight: 400; |
|||
line-height: 16px; |
|||
letter-spacing: 0.4px; |
|||
} |
|||
} |
|||
|
|||
.tb-image-info-container { |
|||
display: flex; |
|||
flex: 1; |
|||
align-self: stretch; |
|||
padding: 0 8px; |
|||
justify-content: flex-end; |
|||
align-items: center; |
|||
gap: 4px; |
|||
|
|||
.tb-external-image-container { |
|||
display: flex; |
|||
flex: 1; |
|||
align-self: stretch; |
|||
padding: 16px 8px 0 16px; |
|||
flex-direction: column; |
|||
align-items: flex-start; |
|||
gap: 4px; |
|||
.tb-external-link-label { |
|||
color: rgba(0, 0, 0, 0.54); |
|||
font-size: 12px; |
|||
font-style: normal; |
|||
font-weight: 400; |
|||
line-height: 16px; |
|||
letter-spacing: 0.4px; |
|||
} |
|||
.tb-external-link-input-container { |
|||
display: flex; |
|||
justify-content: flex-end; |
|||
align-items: center; |
|||
gap: 4px; |
|||
align-self: stretch; |
|||
.tb-inline-field { |
|||
width: 100%; |
|||
} |
|||
.tb-image-decline-btn { |
|||
color: rgba(0,0,0,0.38); |
|||
} |
|||
} |
|||
} |
|||
|
|||
} |
|||
|
|||
.tb-image-select-buttons-container { |
|||
display: flex; |
|||
flex: 1; |
|||
align-self: stretch; |
|||
padding: 8px; |
|||
gap: 8px; |
|||
justify-content: center; |
|||
align-items: flex-start; |
|||
.tb-image-select-button { |
|||
width: 100%; |
|||
height: 100%; |
|||
align-self: stretch; |
|||
display: flex; |
|||
flex-direction: column; |
|||
justify-content: center; |
|||
align-items: center; |
|||
gap: 4px; |
|||
padding: 8px; |
|||
line-height: normal; |
|||
font-size: 12px; |
|||
@media #{$mat-gt-xs} { |
|||
padding: 16px; |
|||
} |
|||
.mat-icon { |
|||
width: 24px; |
|||
height: 24px; |
|||
font-size: 24px; |
|||
margin: 0; |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,180 @@ |
|||
///
|
|||
/// Copyright © 2016-2023 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 { ChangeDetectorRef, Component, forwardRef, Input, OnDestroy, Renderer2, ViewContainerRef } from '@angular/core'; |
|||
import { PageComponent } from '@shared/components/page.component'; |
|||
import { Store } from '@ngrx/store'; |
|||
import { AppState } from '@core/core.state'; |
|||
import { ControlValueAccessor, FormControl, NG_VALUE_ACCESSOR, } from '@angular/forms'; |
|||
import { moveItemInArray } from '@angular/cdk/drag-drop'; |
|||
import { DndDropEvent } from 'ngx-drag-drop'; |
|||
import { isUndefined } from '@core/utils'; |
|||
import { coerceBoolean } from '@shared/decorators/coercion'; |
|||
import { ImageLinkType } from '@home/components/image/gallery-image-input.component'; |
|||
import { TbPopoverService } from '@shared/components/popover.service'; |
|||
import { MatButton } from '@angular/material/button'; |
|||
import { ImageGalleryComponent } from '@home/components/image/image-gallery.component'; |
|||
|
|||
@Component({ |
|||
selector: 'tb-multiple-gallery-image-input', |
|||
templateUrl: './multiple-gallery-image-input.component.html', |
|||
styleUrls: ['./multiple-gallery-image-input.component.scss'], |
|||
providers: [ |
|||
{ |
|||
provide: NG_VALUE_ACCESSOR, |
|||
useExisting: forwardRef(() => MultipleGalleryImageInputComponent), |
|||
multi: true |
|||
} |
|||
] |
|||
}) |
|||
export class MultipleGalleryImageInputComponent extends PageComponent implements OnDestroy, ControlValueAccessor { |
|||
|
|||
@Input() |
|||
label: string; |
|||
|
|||
@Input() |
|||
@coerceBoolean() |
|||
required = false; |
|||
|
|||
@Input() |
|||
disabled: boolean; |
|||
|
|||
imageUrls: string[]; |
|||
|
|||
ImageLinkType = ImageLinkType; |
|||
|
|||
linkType: ImageLinkType = ImageLinkType.none; |
|||
|
|||
externalLinkControl = new FormControl(null); |
|||
|
|||
dragIndex: number; |
|||
|
|||
private propagateChange = null; |
|||
|
|||
constructor(protected store: Store<AppState>, |
|||
private cd: ChangeDetectorRef, |
|||
private renderer: Renderer2, |
|||
private viewContainerRef: ViewContainerRef, |
|||
private popoverService: TbPopoverService) { |
|||
super(store); |
|||
} |
|||
|
|||
ngOnDestroy() { |
|||
} |
|||
|
|||
registerOnChange(fn: any): void { |
|||
this.propagateChange = fn; |
|||
} |
|||
|
|||
registerOnTouched(fn: any): void { |
|||
} |
|||
|
|||
setDisabledState(isDisabled: boolean): void { |
|||
this.disabled = isDisabled; |
|||
} |
|||
|
|||
writeValue(value: string[]): void { |
|||
this.reset(); |
|||
this.imageUrls = value || []; |
|||
} |
|||
|
|||
private updateModel() { |
|||
this.cd.markForCheck(); |
|||
this.propagateChange(this.imageUrls); |
|||
} |
|||
|
|||
private reset() { |
|||
this.linkType = ImageLinkType.none; |
|||
this.externalLinkControl.setValue(null, {emitEvent: false}); |
|||
} |
|||
|
|||
clearImage(index: number) { |
|||
this.imageUrls.splice(index, 1); |
|||
this.updateModel(); |
|||
} |
|||
|
|||
setLink($event: Event) { |
|||
if ($event) { |
|||
$event.stopPropagation(); |
|||
} |
|||
this.linkType = ImageLinkType.external; |
|||
} |
|||
|
|||
declineLink($event: Event) { |
|||
if ($event) { |
|||
$event.stopPropagation(); |
|||
} |
|||
this.reset(); |
|||
} |
|||
|
|||
applyLink($event: Event) { |
|||
if ($event) { |
|||
$event.stopPropagation(); |
|||
} |
|||
this.imageUrls.push(this.externalLinkControl.value); |
|||
this.reset(); |
|||
this.updateModel(); |
|||
} |
|||
|
|||
toggleGallery($event: Event, browseGalleryButton: MatButton) { |
|||
if ($event) { |
|||
$event.stopPropagation(); |
|||
} |
|||
const trigger = browseGalleryButton._elementRef.nativeElement; |
|||
if (this.popoverService.hasPopover(trigger)) { |
|||
this.popoverService.hidePopover(trigger); |
|||
} else { |
|||
const ctx: any = { |
|||
pageMode: false, |
|||
popoverMode: true, |
|||
mode: 'grid', |
|||
selectionMode: true |
|||
}; |
|||
const imageGalleryPopover = this.popoverService.displayPopover(trigger, this.renderer, |
|||
this.viewContainerRef, ImageGalleryComponent, 'top', true, null, |
|||
ctx, |
|||
{}, |
|||
{}, {}, true); |
|||
imageGalleryPopover.tbComponentRef.instance.imageSelected.subscribe((image) => { |
|||
imageGalleryPopover.hide(); |
|||
this.imageUrls.push(image.link); |
|||
this.updateModel(); |
|||
}); |
|||
} |
|||
} |
|||
|
|||
imageDragStart(index: number) { |
|||
setTimeout(() => { |
|||
this.dragIndex = index; |
|||
this.cd.markForCheck(); |
|||
}); |
|||
} |
|||
|
|||
imageDragEnd() { |
|||
this.dragIndex = -1; |
|||
this.cd.markForCheck(); |
|||
} |
|||
|
|||
imageDrop(event: DndDropEvent) { |
|||
let index = event.index; |
|||
if (isUndefined(index)) { |
|||
index = this.imageUrls.length; |
|||
} |
|||
moveItemInArray(this.imageUrls, this.dragIndex, index); |
|||
this.dragIndex = -1; |
|||
this.updateModel(); |
|||
} |
|||
} |
|||
Loading…
Reference in new issue