tabs.vue 3.41 KB
Newer Older
Johannes Edmeier committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
<!--
  - Copyright 2014-2018 the original author or 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.
  -->

<template>
18
  <section id="instance-tabs" class="hero instance-tabs">
19
    <div class="hero-foot">
20 21 22 23 24 25 26
      <div class="container instance-tabs__tabs">

        <div class="instance-tabs__name"
             :class="{ 'is-active' : isStuck }">
          <h1 class="title is-5" v-if="instance" v-text="instance.registration.name"/>
          <h1 class="subtitle is-6" v-if="instance"><strong v-text="instance.id"/> (of <span
            v-text="application.instances.length"/>)</h1>
Johannes Edmeier committed
27
        </div>
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43

        <nav class="instance-tabs__tabs tabs is-boxed">
          <ul>
            <li v-if="instance" v-for="view in activeViews" :key="view.name"
                :class="{'is-active' : $route.name === view.name}">
              <a v-if="view.href" :href="view.href({ 'instanceId' : instance.id })"
                 target="_blank">
                <component :is="view.handle"/>
              </a>
              <router-link v-else
                           :to="{ name: view.name, params: { 'instanceId' : instance.id } }">
                <component :is="view.handle"/>
              </router-link>
            </li>
          </ul>
        </nav>
44 45 46
      </div>
    </div>
  </section>
Johannes Edmeier committed
47 48 49
</template>

<script>
50
  import Application from '@/services/application';
51 52
  import Instance from '@/services/instance';

Johannes Edmeier committed
53
  export default {
54
    props: {
55 56 57 58
      views: {
        type: Array,
        default: () => []
      },
59 60 61 62
      instance: {
        type: Instance,
        default: null
      },
63 64 65
      application: {
        type: Application,
        default: null
66 67
      }
    },
Johannes Edmeier committed
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
    data: () => ({
      isStuck: false
    }),
    computed: {
      activeViews() {
        if (!this.instance || !this.views) {
          return [];
        }

        return this.views.filter(
          view => typeof view.isActive === 'undefined' || view.isActive({instance: this.instance})
        );
      }
    },
    methods: {
      onScroll() {
        this.isStuck = this.$el.getBoundingClientRect().top <= 52;
      }
    },
    mounted() {
      window.addEventListener('scroll', this.onScroll);
    },
    beforeDestroy() {
      window.removeEventListener('scroll', this.onScroll);
    },
  }
</script>

<style lang="scss">
97
  @import "~@/assets/css/utilities";
Johannes Edmeier committed
98

99 100 101 102 103
  .instance-tabs {
    z-index: 29;
    position: sticky;
    top: $navbar-height-px;
    overflow: hidden;
Johannes Edmeier committed
104

105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
    &__tabs {
      display: flex;
      align-items: flex-end;

      & ul {
        flex: 1 1 100%;
        overflow: hidden;
      }

      & li {
        flex-shrink: 1;
        text-overflow: ellipsis;
        overflow: hidden;
      }
    }

121 122 123 124 125
    &__name {
      transition: all $easing $speed;
      will-change: transform;
      transform: translateY(41px);
      visibility: hidden;
Johannes Edmeier committed
126

127 128 129 130
      &.is-active {
        transform: translateY(0px);
        visibility: visible;
      }
Johannes Edmeier committed
131
    }
132
  }
Johannes Edmeier committed
133
</style>