All files Interaction.vue

83.72% Statements 36/43
77.55% Branches 38/49
85.71% Functions 18/21
83.72% Lines 36/43

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152                                                    6x 6x 6x 6x 6x 6x 6x 6x         13x                   13x     11x     11x     13x           13x 26x           13x     13x 13x     13x 13x     13x     10x     3x 3x 3x     13x     13x     13x           10x           13x     13x       13x 13x     9x     13x       13x                                              
<template>
  <div class="interaction sync inline-block"
       v-on:click.stop="onClick"
       v-on:mouseover.stop="mouseOver"
       v-on:mouseout.stop="mouseOut"
       :data-to="to"
       data-type="interaction"
       :data-signature="signature"
       :class="{'right-to-left': rightToLeft, 'highlight': isCurrent, 'self': isSelf, 'hover': hover }"
       :style="{width: interactionWidth + 'px', left: left + 'px', transform: 'translateX(' + translateX + 'px)'}">
    <div v-if="showStarter && isRootBlock"
         :style="{transform: 'translateX(' + translateX * (-1) + 'px)'}"
         class="occurrence source"></div>
    <comment v-if="comment" :comment="comment"/>
    <component v-bind:is="invocation"
               class="text-center"
             :content="signature"
             :assignee="assignee"
             :rtl="rightToLeft"
             type="sync"></component>
    <occurrence :context="message" :participant="isSelf? from : to" :selfCallIndent="passOnOffset"/>
    <message class="return" v-if="assignee && !isSelf" :content="assignee" :rtl="!rightToLeft" type="return"/>
  </div>
</template>
 
<script type="text/babel">
  import Comment from '../Comment.vue'
  import Occurrence from '../Occurrence.vue'
  import Message from '../Message'
  import {mapGetters} from "vuex";
  import SelfInvocation from '../SelfInvocation'
  import {CodeRange} from '@/parser/CodeRange'
  import {ProgContext} from '@/parser'
  import Hoverable  from '@/components/mixin/hoverable/Hoverable'
 
  export default {
    name: 'interaction',
    data() {
      return {
        hover: false
      }
    },
    props: ['context', 'comment', 'selfCallIndent'],
    mixins: [Hoverable],
    computed: {
      // add tracker to the mapGetters
      ...mapGetters(['participants', 'distance2', 'cursor', 'onElementClick']),
      message: function () {
        return this.context?.message()
      },
      providedFrom: function() {
        return this.context?.message()?.ProvidedFrom()
      },
      from: function() {
        return this.providedFrom || this.origin
      },
      outOfBand: function() {
        return !!this.providedFrom && (this.providedFrom !== this.origin)
      },
      assignee: function () {
        function safeCodeGetter (context) {
          return (context && context.getTextWithoutQuotes()) || ''
        }
        let assignment = this.message?.messageBody().assignment()
E        if (!assignment) return ''
        let assignee = safeCodeGetter(assignment.assignee())
        const type = safeCodeGetter(assignment.type())
        return assignee + (type ? ':' + type : '')
      },
      signature: function () {
        return this.message?.SignatureText()
      },
      left: function() {
        const indent = this.selfCallIndent || 0
        return indent * (-1)
      },
      translateX: function() {
        const indent = this.selfCallIndent || 0
        const fragmentOff = 0 || 0
        // ** Starting point is always the center of 'origin' **
        // Normal flow
        if(!this.rightToLeft && !this.outOfBand) {
          // + indent because we always start from the center of origin
          // starting point is moved back to the center of origin by 'left'
          return indent + fragmentOff
        }
 
        const moveTo = !this.rightToLeft ? this.providedFrom : this.to
        const dist = this.distance2(this.origin, moveTo)
        return dist + fragmentOff
      },
      rightToLeft: function () {
        return this.distance2(this.from, this.to) < 0
      },
      isCurrent: function () {
        return this.message?.isCurrent(this.cursor);
      },
      showStarter() {
        return this.participants.Starter().name !== '_STARTER_'
      },
      isRootBlock() {
        return this.context?.parentCtx?.parentCtx instanceof ProgContext
      },
      origin: function() {
        return this.context?.Origin()
      },
      passOnOffset: function() {
        // selfCallIndent is introduced for sync self interaction. Each time we enter a self sync interaction the selfCallIndent
        // increases by 6px (half of the width of an execution bar). However, we set the selfCallIndent back to 0 when
        // it enters a non-self sync interaction.
        return this.isSelf ? (this.selfCallIndent || 0) + 6 : 0
      },
      interactionWidth: function () {
I        if (this.context && this.isSelf) {
          return 0
        }
 
        let safeOffset = this.outOfBand ? 0: (this.selfCallIndent || 0)
        return Math.abs(this.distance2(this.from, this.to) - safeOffset)
      },
      to: function () {
        return this.context?.message()?.Owner()
      },
      isSelf: function() {
        return this.to === this.from
      },
      invocation: function () {
        // return 'Message'
        return this.isSelf ? 'SelfInvocation' : 'Message'
      }
    },
    methods: {
      onClick() {
        this.onElementClick(CodeRange.from(this.context))
      },
    },
    components: {
      Message,
      SelfInvocation,
      Comment,
      Occurrence
    }
  }
</script>
<style scoped>
  .occurrence.source {
    position: absolute;
    height: calc(100% + 16px);
    left: -12px;
  }
</style>