-
Notifications
You must be signed in to change notification settings - Fork 154
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f578b6e
commit e4ab98d
Showing
13 changed files
with
277 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<div id="chatContainer" class="chat-container" [ngClass]="{'show': !isShow}"> | ||
<div class="modal" (click)="toggle()"></div> | ||
<div class="drawer-panel"> | ||
<div id="dragBox" [hidden]="!isShow"> | ||
<div | ||
[matTooltip]="('Setting' | translate)" | ||
matTooltipPosition="before" | ||
class="drag-setting" | ||
[hidden]="!isShowSetting" | ||
(click)="onOpenDrawer()" | ||
> | ||
<i class="fa fa-cog"></i> | ||
</div> | ||
<div class="drag-button"> | ||
<img src="assets/icons/robot-assistant.png" alt="" /> | ||
</div> | ||
</div> | ||
<div class="content"> | ||
<iframe | ||
[src]="iframeURL | safeUrl" | ||
title="chat" | ||
height="100%" | ||
width="100%" | ||
></iframe> | ||
</div> | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
.chat-container { | ||
overflow: hidden; | ||
.content { | ||
height: 100%; | ||
iframe { | ||
border: none; | ||
} | ||
} | ||
} | ||
|
||
.drawer-panel { | ||
position: fixed; | ||
top: 0; | ||
right: 0; | ||
width: 100%; | ||
width: 440px; | ||
min-width: 260px; | ||
height: 100vh; | ||
user-select: none; | ||
border-radius: 10px 0 0 10px; | ||
transition: transform .25s cubic-bezier(.7, .3, .1, 1); | ||
box-shadow: 0 0 8px 4px #00000014; | ||
transform: translate(100%); | ||
background: #FFFFFF; | ||
z-index: 1200; | ||
} | ||
|
||
#dragBox { | ||
position: absolute; | ||
top: 30%; | ||
left: -48px; | ||
} | ||
|
||
.drag-button { | ||
// position: absolute; | ||
// top: 30%; | ||
// left: -48px; | ||
width: 48px; | ||
height: 45px; | ||
line-height: 45px; | ||
box-sizing: border-box; | ||
text-align: center; | ||
font-size: 24px; | ||
border-radius: 20px 0 0 20px; | ||
z-index: 0; | ||
pointer-events: auto; | ||
color: #fff; | ||
background-color: #FFFFFF; | ||
box-shadow: 0 0 8px 4px #00000014; | ||
cursor: pointer; | ||
|
||
&:hover { | ||
left: -50px !important; | ||
width: 50px !important; | ||
transform: translateZ(0) scale(1.06); | ||
transform-style: preserve-3d; | ||
backface-visibility: hidden; | ||
} | ||
i { | ||
font-size: 20px; | ||
line-height: 45px; | ||
} | ||
img { | ||
width: 22px; | ||
height: 22px; | ||
transform: translateY(10%); | ||
margin-left: 3px; | ||
} | ||
} | ||
|
||
.drag-setting { | ||
width: 36px; | ||
height: 36px; | ||
line-height: 38px; | ||
margin-bottom: 10px; | ||
text-align: center; | ||
border-radius: 50%; | ||
cursor: pointer; | ||
transform: translateX(20%); | ||
background-color: #FFFFFF; | ||
border: 1px solid transparent; | ||
transition: border-color 0.3s ease; | ||
&:hover { | ||
background-color: #f0f1f5; | ||
border-color: #1d271f; | ||
} | ||
i { | ||
font-size: 18px; | ||
} | ||
} | ||
|
||
.show { | ||
transition: all .3s cubic-bezier(.7, .3, .1, 1); | ||
} | ||
|
||
.show .modal { | ||
position: fixed; | ||
top: 0; | ||
width: 100%; | ||
height: 100%; | ||
z-index: 999; | ||
opacity: 1; | ||
} | ||
|
||
.show .drawer-panel { | ||
transform: translate(0); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
import {OnInit, OnDestroy, Component} from '@angular/core'; | ||
import {ViewService} from '@app/services'; | ||
import {View} from '@app/model'; | ||
|
||
@Component({ | ||
selector: 'elements-chat', | ||
templateUrl: './chat.component.html', | ||
styleUrls: ['./chat.component.scss'], | ||
}) | ||
|
||
export class ElementChatComponent implements OnInit, OnDestroy { | ||
isShow = true; | ||
element: any; | ||
iframeURL: String; | ||
currentView: View; | ||
|
||
constructor( | ||
public viewSrv: ViewService | ||
) {} | ||
|
||
get isShowSetting() { | ||
const componentType = ['koko', 'lion']; | ||
return ( | ||
this.currentView.hasOwnProperty('connectMethod') | ||
&& componentType.includes(this.currentView.connectMethod.component) | ||
); | ||
} | ||
|
||
ngOnInit() { | ||
this.viewSrv.currentView$.subscribe((state: View) => { | ||
this.currentView = state; | ||
}); | ||
this.iframeURL = '/ui/#/chat/chat-ai'; | ||
this.init(); | ||
this.insertToBody(); | ||
} | ||
|
||
ngOnDestroy() { | ||
this.element.remove(); | ||
this.viewSrv.currentView$.unsubscribe(); | ||
} | ||
|
||
init() { | ||
const clientOffset: any = {}; | ||
const dragBox = document.getElementById('dragBox'); | ||
const dragSetting = document.querySelector('.drag-setting'); | ||
dragBox.addEventListener('mousedown', (event) => { | ||
event.stopPropagation(); | ||
const offsetX = dragBox.getBoundingClientRect().left; | ||
const offsetY = dragBox.getBoundingClientRect().top; | ||
const innerX = event.clientX - offsetX; | ||
const innerY = event.clientY - offsetY; | ||
|
||
clientOffset.clientX = event.clientX; | ||
clientOffset.clientY = event.clientY; | ||
document.onmousemove = function(ev: any) { | ||
dragBox.style.left = ev.clientX - innerX + 'px'; | ||
dragBox.style.top = ev.clientY - innerY + 'px'; | ||
const dragDivTop = window.innerHeight - dragBox.getBoundingClientRect().height; | ||
const dragDivLeft = window.innerWidth - dragBox.getBoundingClientRect().width; | ||
dragBox.style.left = dragDivLeft + 'px'; | ||
dragBox.style.left = '-48px'; | ||
if (dragBox.getBoundingClientRect().top <= 0) { | ||
dragBox.style.top = '0px'; | ||
} | ||
if (dragBox.getBoundingClientRect().top >= dragDivTop) { | ||
dragBox.style.top = dragDivTop + 'px'; | ||
} | ||
ev.preventDefault(); | ||
ev.stopPropagation(); | ||
}; | ||
document.onmouseup = function() { | ||
document.onmousemove = null; | ||
document.onmouseup = null; | ||
}; | ||
}, false); | ||
dragBox.addEventListener('mouseup', (event) => { | ||
const clientX = event.clientX; | ||
const clientY = event.clientY; | ||
if ( | ||
this.isDifferenceWithinThreshold(clientX, clientOffset.clientX) | ||
&& this.isDifferenceWithinThreshold(clientY, clientOffset.clientY) | ||
&& event.target !== dragSetting | ||
&& this.isDescendant(event.target, dragSetting) | ||
) { | ||
this.isShow = !this.isShow; | ||
} | ||
}); | ||
} | ||
|
||
isDescendant(element, ancestor) { | ||
if (element.parentNode === ancestor) { | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
insertToBody() { | ||
this.element = document.getElementById('chatContainer'); | ||
const body = document.querySelector('body'); | ||
body.insertBefore(this.element, body.firstChild); | ||
} | ||
|
||
onOpenDrawer() { | ||
window.postMessage({name: 'OPEN'}, '*'); | ||
Check failure Code scanning / SonarCloud Origins should be verified during cross-origin communications High
Specify a target origin for this message. See more on SonarCloud
|
||
} | ||
|
||
isDifferenceWithinThreshold(num1, num2, threshold = 5) { | ||
const difference = Math.abs(num1 - num2); | ||
return difference <= threshold; | ||
} | ||
|
||
toggle() { | ||
this.isShow = !this.isShow; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -57,3 +57,5 @@ | |
</div> | ||
</as-split-area> | ||
</as-split> | ||
|
||
<elements-chat *ngIf="chatAiEnabled"></elements-chat> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.