Skip to content

Commit

Permalink
added setActionIntentInIntent
Browse files Browse the repository at this point in the history
  • Loading branch information
dariodepa75 committed Nov 3, 2023
1 parent 153ecd2 commit c571020
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Intent } from 'src/app/models/intent-model';
import { ActionIntentConnected } from 'src/app/models/action-model';
import { IntentService } from '../../../../../services/intent.service';
import { Subscription } from 'rxjs/internal/Subscription';
import { TYPE_UPDATE_ACTION, ACTIONS_LIST } from '../../../../../utils';
import { TYPE_UPDATE_ACTION, ACTIONS_LIST, TYPE_ACTION } from '../../../../../utils';
import { LoggerService } from 'src/chat21-core/providers/abstract/logger.service';
import { LoggerInstance } from 'src/chat21-core/providers/logger/loggerInstance';

Expand Down Expand Up @@ -40,7 +40,7 @@ export class CdsActionIntentComponent implements OnInit {
}

ngOnInit(): void {
// console.log("[CDS-ACTION-INTENT] elementSelected: ", this.action, this.intentSelected)
console.log("[CDS-ACTION-INTENT] elementSelected: ", this.action, this.intentSelected)
this.subscriptionChangedConnector = this.intentService.isChangedConnector$.subscribe((connector: any) => {
// console.log('[CDS-ACTION-INTENT] - subcribe to isChangedConnector$ >>', connector);
this.connector = connector;
Expand Down Expand Up @@ -83,9 +83,10 @@ export class CdsActionIntentComponent implements OnInit {


private updateConnector(){
this.logger.log('[CDS-ACTION-INTENT] 1- updateConnector :: ',this.action.intentName);
this.isConnected = this.action.intentName?true:false;
// console.log('[CDS-ACTION-INTENT] 1- updateConnector :: ',this.action);
try {
if(!this.action.intentName)this.isConnected = false;
else this.isConnected = true;
const array = this.connector.fromId.split("/");
const idAction= array[1];
// console.log('[CDS-ACTION-INTENT] 2 - updateConnector :: ', idAction, this.action._tdActionId, this.connector);
Expand All @@ -95,7 +96,7 @@ export class CdsActionIntentComponent implements OnInit {
this.action.intentName = null;
this.isConnected = false;
} else {
this.logger.log('[CDS-ACTION-INTENT] connettore creato - PALLINO PIENO :: ', this.connector);
console.log('[CDS-ACTION-INTENT] connettore creato - PALLINO PIENO :: ', this.connector);
this.isConnected = true;
this.action.intentName = "#"+this.connector.toId;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
<cds-action-intent class="panel-response"
[isStart]="isStart"
[intentSelected]="intent"
[action]="listOfActions[0]"
[action]="startAction"
(updateAndSaveAction)="onUpdateAndSaveAction($event)">
</cds-action-intent>
</div>
Expand Down Expand Up @@ -124,12 +124,12 @@
(updateAndSaveAction)="onUpdateAndSaveAction($event)">
</cds-action-reply>

<cds-action-intent *ngSwitchCase="TYPE_ACTION.INTENT"
<!-- <cds-action-intent *ngSwitchCase="TYPE_ACTION.INTENT"
class="panel-response"
[intentSelected]="intent"
[action]="action"
(updateAndSaveAction)="onUpdateAndSaveAction($event)">
</cds-action-intent>
</cds-action-intent> -->

<cds-action-email *ngSwitchCase="TYPE_ACTION.EMAIL"
class="panel-response"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Component, OnInit, Input, Output, EventEmitter, SimpleChanges, ViewChild, ElementRef, OnChanges, OnDestroy } from '@angular/core';
import { Form, Intent } from 'src/app/models/intent-model';
import { Action } from 'src/app/models/action-model';
import { Action, ActionIntentConnected } from 'src/app/models/action-model';
import { Subject, Subscription } from 'rxjs';

import { ACTIONS_LIST, TYPE_ACTION, TYPE_INTENT_NAME, checkInternalIntent, patchActionId } from '../../../utils';
Expand Down Expand Up @@ -87,7 +87,7 @@ export class CdsIntentComponent implements OnInit, OnDestroy, OnChanges {
webHookTooltipText: string;
isInternalIntent: boolean = false;

actionIntent: Action;
actionIntent: ActionIntentConnected;

private logger: LoggerService = LoggerInstance.getInstance()
constructor(
Expand Down Expand Up @@ -119,9 +119,10 @@ export class CdsIntentComponent implements OnInit, OnDestroy, OnChanges {
delete intent['attributesChanged'];
} else { // if(this.intent.actions.length !== intent.actions.length && intent.actions.length>0)
this.logger.log("[CDS-INTENT] aggiorno le actions dell'intent");
this.listOfActions = this.intent.actions;
// AGGIORNO I CONNETTORI
// this.intentService.updateIntent(this.intent); /// DEVO ELIMINARE UPDATE DA QUI!!!!!
// this.listOfActions = this.intent.actions;
this.listOfActions = this.intent.actions.filter(function(obj) {
return obj._tdActionType !== TYPE_ACTION.INTENT;
});
}

//UPDATE QUESTIONS
Expand Down Expand Up @@ -175,8 +176,10 @@ export class CdsIntentComponent implements OnInit, OnDestroy, OnChanges {

ngOnInit(): void {
console.log('CdsPanelIntentComponent ngAfterViewInit-->', this.intent);
this.setIntentSelected();


if (this.intent.actions && this.intent.actions.length === 1 && this.intent.actions[0]._tdActionType === TYPE_ACTION.INTENT && this.intent.intent_display_name === 'start') {
console.log('CdsPanelIntentComponent START-->',this.intent.actions[0]);
this.startAction = this.intent.actions[0];
if (!this.startAction._tdActionId) {
this.startAction = patchActionId(this.intent.actions[0]);
Expand All @@ -188,13 +191,31 @@ export class CdsIntentComponent implements OnInit, OnDestroy, OnChanges {
// //** center stage on 'start' intent */
// let startElement = document.getElementById(this.intent.intent_id)
// this.stageService.centerStageOnHorizontalPosition(startElement)
} else {
this.setIntentSelected();
}


this.setActionIntentInIntent();
this.isInternalIntent = checkInternalIntent(this.intent)
this.actionIntent = this.intentService.createNewAction(TYPE_ACTION.INTENT);
this.addEventListener();
}

private setActionIntentInIntent(){
let actionIntent = this.intentService.createNewAction(TYPE_ACTION.INTENT);
this.intent.actions = this.intent.actions.map(function(action) {
if(action._tdActionType === TYPE_ACTION.INTENT){
actionIntent = action;
}
return action;
});
this.actionIntent = actionIntent;
if(this.actionIntent.intentName){
const fromId = this.intent.intent_id+'/'+this.actionIntent._tdActionId;
const toId = this.actionIntent.intentName.replace("#", "");
this.connectorService.createConnectorFromId(fromId, toId, false, false); //Sync
}
}

ngOnChanges(changes: SimpleChanges): void {
// Fixed bug where an empty intent's action placeholder remains visible if an action is dragged from the left action menu
this.logger.log('[CDS-INTENT] hideActionPlaceholderOfActionPanel (dragged from sx panel) ', this.hideActionPlaceholderOfActionPanel)
Expand All @@ -204,14 +225,12 @@ export class CdsIntentComponent implements OnInit, OnDestroy, OnChanges {
if (addActionPlaceholderEl !== null) {
addActionPlaceholderEl.style.opacity = '0';
}

} else if (this.hideActionPlaceholderOfActionPanel === true) {
const addActionPlaceholderEl = <HTMLElement>document.querySelector('.add--action-placeholder');
this.logger.log('[CDS-INTENT] HERE 2 !!!! addActionPlaceholderEl ', addActionPlaceholderEl);
if (addActionPlaceholderEl !== null) {
addActionPlaceholderEl.style.opacity = '1';
}

}
}

Expand Down Expand Up @@ -645,10 +664,28 @@ export class CdsIntentComponent implements OnInit, OnDestroy, OnChanges {
replaceItemInArrayForKey('_tdActionId', this.intent.actions, action);
}
}
console.log('[CDS-INTENT] onUpdateAndSaveAction:::: ', object, this.intent, this.intent.actions);
this.setActionIntentInListOfActions();
// console.log('[CDS-INTENT] onUpdateAndSaveAction:::: ', object, this.intent, this.intent.actions);
this.intentService.onUpdateIntentWithTimeout(this.intent, 0, true, connector);
}



private setActionIntentInListOfActions(){
let actionIntent = this.actionIntent;
let addIntentAction = true;
this.intent.actions = this.intent.actions.map(function(action) {
if(action._tdActionType === TYPE_ACTION.INTENT){
addIntentAction = false;
return actionIntent;
}
return action;
});
if (addIntentAction) {
this.intent.actions.push(this.actionIntent);
}
}

openActionMenu(intent: any, calleBy: string) {
this.logger.log('[CDS-INTENT] openActionMenu > intent ', intent)
this.logger.log('[CDS-INTENT] openActionMenu > calleBy ', calleBy)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ export class ConnectorService {
// this.logger.log('[CONNECTOR-SERV] intent_display_name', intent.intent_display_name);
if(action.intentName && action.intentName !== ''){
const idConnectorFrom = intent.intent_id+'/'+action._tdActionId;
const idConnectorTo = action.intentName.replace("#", ""); ;
const idConnectorTo = action.intentName.replace("#", "");
this.logger.log('[CONNECTOR-SERV] -> CREATE CONNECTOR', idConnectorFrom, idConnectorTo);
this.createConnectorFromId(idConnectorFrom, idConnectorTo);
}
Expand Down
1 change: 0 additions & 1 deletion src/assets/js/tiledesk-stage.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,6 @@ export class TiledeskStage {
event.preventDefault();
pos_mouse_x = event.clientX;
pos_mouse_y = event.clientY;

const custom_event = new CustomEvent("start-dragging", {
detail: {
element: element
Expand Down

0 comments on commit c571020

Please sign in to comment.