2019-06-23 03:35:23 -07:00
< template >
< div class = "item" >
< div v-if ="item.options" class="options" >
< div v-if ="item.options.length" class="headline clickable" @click="extended=!extended" >
< div class = "options-toggle" v-if ="extendAll !== true" >
< font -awesome -icon v -if = " extended " icon = "angle-down" / >
< font -awesome -icon v -else icon = "angle-right" / >
< / div >
< div class = "option-title" :title ="item.key" >
{ { item . name } }
< el -dropdown trigger = "click" @ click.stop @ command = "optionSelected($event, item)" v-if ="allowParentSelect === true" >
< span class = "el-dropdown-link clickable" @ click.stop >
2021-12-15 04:16:53 -08:00
< font -awesome -icon icon = "dot-circle" :title ="$locale.baseText('variableSelectorItem.selectItem')" / >
2019-06-23 03:35:23 -07:00
< / span >
< el -dropdown -menu slot = "dropdown" >
< el -dropdown -item :command ="operation.command" v-for ="operation in itemAddOperations" :key="operation.command" > {{ operation.displayName }} < / el -dropdown -item >
< / e l - d r o p d o w n - m e n u >
< / e l - d r o p d o w n >
< / div >
< / div >
< div v-if ="item.options && (extended === true || extendAll === true)" >
< variable -selector -item v-for ="option in item.options" :item="option" :key="option.key" :extendAll="extendAll" :allowParentSelect="option.allowParentSelect" class="sub-level" @itemSelected="forwardItemSelected" > < / variable -selector -item >
< / div >
< / div >
< div v -else class = "value clickable" @click ="selectItem(item)" >
< div class = "item-title" :title ="item.key" >
{ { item . name } } :
< font -awesome -icon icon = "dot-circle" title = "Select Item" / >
< / div >
2021-12-15 04:16:53 -08:00
< div class = "item-value" > { { item . value !== undefined ? item . value : $locale . baseText ( 'variableSelectorItem.empty' ) } } < / div >
2019-06-23 03:35:23 -07:00
< / div >
< / div >
< / template >
< script lang = "ts" >
import Vue from 'vue' ;
import {
IVariableSelectorOption ,
IVariableItemSelected ,
} from '@/Interface' ;
2021-12-07 07:14:40 -08:00
export default Vue . extend ( {
2019-06-23 03:35:23 -07:00
name : 'VariableSelectorItem' ,
props : [
'allowParentSelect' ,
'extendAll' ,
'item' ,
] ,
computed : {
itemAddOperations ( ) {
const returnOptions = [
{
command : 'raw' ,
displayName : 'Raw value' ,
} ,
] ;
if ( this . item . dataType === 'array' ) {
returnOptions . push ( {
command : 'arrayLength' ,
displayName : 'Length' ,
} ) ;
returnOptions . push ( {
command : 'arrayValues' ,
displayName : 'Values' ,
} ) ;
} else if ( this . item . dataType === 'object' ) {
returnOptions . push ( {
command : 'objectKeys' ,
displayName : 'Keys' ,
} ) ;
returnOptions . push ( {
command : 'objectValues' ,
displayName : 'Values' ,
} ) ;
}
return returnOptions ;
} ,
} ,
data ( ) {
return {
extended : false ,
} ;
} ,
methods : {
optionSelected ( command : string , item : IVariableSelectorOption ) {
// By default it is raw
let variable = item . key ;
if ( command === 'arrayValues' ) {
variable = ` ${ item . key } .join(', ') ` ;
} else if ( command === 'arrayLength' ) {
variable = ` ${ item . key } .length ` ;
} else if ( command === 'objectKeys' ) {
variable = ` Object.keys( ${ item . key } ).join(', ') ` ;
} else if ( command === 'objectValues' ) {
variable = ` Object.values( ${ item . key } ).join(', ') ` ;
}
this . $emit ( 'itemSelected' , { variable } ) ;
} ,
selectItem ( item : IVariableSelectorOption ) {
this . $emit ( 'itemSelected' , { variable : item . key } ) ;
} ,
forwardItemSelected ( eventData : IVariableItemSelected ) {
this . $emit ( 'itemSelected' , eventData ) ;
} ,
} ,
} ) ;
< / script >
< style scoped lang = "scss" >
. option - title {
position : relative ;
display : inline - block ;
font - size : 0.9 em ;
font - weight : 600 ;
padding : 0.2 em 1 em 0.2 em 0.4 em ;
}
. item - title {
font - weight : 600 ;
font - size : 0.8 em ;
white - space : nowrap ;
2021-08-29 04:36:17 -07:00
overflow : hidden ;
2019-06-23 03:35:23 -07:00
text - overflow : ellipsis ;
}
. headline {
position : relative ;
margin : 2 px ;
margin - top : 10 px ;
color : $ -- color - primary ;
}
. options - toggle {
position : relative ;
top : 1 px ;
margin : 0 3 px 0 8 px ;
display : inline ;
}
. value {
margin : 0.2 em ;
padding : 0.1 em 0.3 em ;
}
. item - value {
font - size : 0.6 em ;
overflow - x : auto ;
}
. sub - level {
padding - left : 20 px ;
}
< / style >