2021-10-06 21:03:29 +03:00
|
|
|
///
|
|
|
|
|
/// Copyright © 2016-2021 The Thingsboard Authors
|
|
|
|
|
///
|
|
|
|
|
/// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
/// you may not use this file except in compliance with the License.
|
|
|
|
|
/// You may obtain a copy of the License at
|
|
|
|
|
///
|
|
|
|
|
/// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
///
|
|
|
|
|
/// Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
/// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
/// See the License for the specific language governing permissions and
|
|
|
|
|
/// limitations under the License.
|
|
|
|
|
///
|
|
|
|
|
|
2021-10-13 20:35:10 +03:00
|
|
|
import {
|
|
|
|
|
Component,
|
|
|
|
|
ElementRef,
|
2021-10-18 13:10:11 +03:00
|
|
|
Input, OnChanges,
|
2021-10-13 20:35:10 +03:00
|
|
|
OnDestroy,
|
2021-10-18 13:10:11 +03:00
|
|
|
Renderer2, SimpleChanges,
|
2021-10-13 20:35:10 +03:00
|
|
|
ViewChild,
|
|
|
|
|
ViewContainerRef,
|
|
|
|
|
ViewEncapsulation
|
|
|
|
|
} from '@angular/core';
|
|
|
|
|
import { TbPopoverService } from '@shared/components/popover.service';
|
|
|
|
|
import { PopoverPlacement } from '@shared/components/popover.models';
|
2021-10-18 13:10:11 +03:00
|
|
|
import { DomSanitizer, SafeHtml } from '@angular/platform-browser';
|
|
|
|
|
import { isDefinedAndNotNull } from '@core/utils';
|
2021-10-06 21:03:29 +03:00
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
|
// tslint:disable-next-line:component-selector
|
|
|
|
|
selector: '[tb-help-popup]',
|
|
|
|
|
templateUrl: './help-popup.component.html',
|
|
|
|
|
styleUrls: ['./help-popup.component.scss'],
|
|
|
|
|
encapsulation: ViewEncapsulation.None
|
|
|
|
|
})
|
2021-10-18 13:10:11 +03:00
|
|
|
export class HelpPopupComponent implements OnChanges, OnDestroy {
|
2021-10-06 21:03:29 +03:00
|
|
|
|
2021-10-13 20:35:10 +03:00
|
|
|
@ViewChild('toggleHelpButton', {read: ElementRef, static: false}) toggleHelpButton: ElementRef;
|
2021-10-18 13:10:11 +03:00
|
|
|
@ViewChild('toggleHelpTextButton', {read: ElementRef, static: false}) toggleHelpTextButton: ElementRef;
|
2021-10-13 20:35:10 +03:00
|
|
|
|
2021-10-06 21:03:29 +03:00
|
|
|
// tslint:disable-next-line:no-input-rename
|
|
|
|
|
@Input('tb-help-popup') helpId: string;
|
|
|
|
|
|
2021-10-13 20:35:10 +03:00
|
|
|
// tslint:disable-next-line:no-input-rename
|
|
|
|
|
@Input('trigger-text') triggerText: string;
|
|
|
|
|
|
2021-10-18 13:10:11 +03:00
|
|
|
// tslint:disable-next-line:no-input-rename
|
|
|
|
|
@Input('trigger-style') triggerStyle: string;
|
|
|
|
|
|
2021-10-13 20:35:10 +03:00
|
|
|
// tslint:disable-next-line:no-input-rename
|
|
|
|
|
@Input('tb-help-popup-placement') helpPopupPlacement: PopoverPlacement;
|
|
|
|
|
|
|
|
|
|
// tslint:disable-next-line:no-input-rename
|
|
|
|
|
@Input('tb-help-popup-style') helpPopupStyle: { [klass: string]: any } = {};
|
|
|
|
|
|
2021-10-06 21:03:29 +03:00
|
|
|
popoverVisible = false;
|
|
|
|
|
popoverReady = true;
|
|
|
|
|
|
2021-10-18 13:10:11 +03:00
|
|
|
triggerSafeHtml: SafeHtml = null;
|
|
|
|
|
textMode = false;
|
|
|
|
|
|
2021-10-13 20:35:10 +03:00
|
|
|
constructor(private viewContainerRef: ViewContainerRef,
|
2021-10-18 13:10:11 +03:00
|
|
|
private element: ElementRef<HTMLElement>,
|
|
|
|
|
private sanitizer: DomSanitizer,
|
2021-10-06 21:03:29 +03:00
|
|
|
private renderer: Renderer2,
|
2021-10-18 13:10:11 +03:00
|
|
|
private popoverService: TbPopoverService) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ngOnChanges(changes: SimpleChanges): void {
|
|
|
|
|
if (isDefinedAndNotNull(this.triggerText)) {
|
|
|
|
|
this.triggerSafeHtml = this.sanitizer.bypassSecurityTrustHtml(this.triggerText);
|
|
|
|
|
} else {
|
|
|
|
|
this.triggerSafeHtml = null;
|
|
|
|
|
}
|
|
|
|
|
this.textMode = this.triggerSafeHtml != null;
|
|
|
|
|
}
|
2021-10-06 21:03:29 +03:00
|
|
|
|
|
|
|
|
toggleHelp() {
|
2021-10-18 13:10:11 +03:00
|
|
|
const trigger = this.textMode ? this.toggleHelpTextButton.nativeElement : this.toggleHelpButton.nativeElement;
|
2021-10-13 20:35:10 +03:00
|
|
|
this.popoverService.toggleHelpPopover(trigger, this.renderer, this.viewContainerRef,
|
2021-10-06 21:03:29 +03:00
|
|
|
this.helpId,
|
2021-10-13 20:35:10 +03:00
|
|
|
'',
|
2021-10-06 21:03:29 +03:00
|
|
|
(visible) => {
|
|
|
|
|
this.popoverVisible = visible;
|
|
|
|
|
}, (ready => {
|
|
|
|
|
this.popoverReady = ready;
|
2021-10-13 20:35:10 +03:00
|
|
|
}),
|
|
|
|
|
this.helpPopupPlacement,
|
|
|
|
|
{},
|
|
|
|
|
this.helpPopupStyle);
|
2021-10-06 21:03:29 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ngOnDestroy(): void {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|