AppMenu.vue 4.7 KB
Newer Older
J
Jeff Wang 已提交
1
<template>
2 3 4 5 6 7
  <div>
    <div class="visual-dl-app-menu">
      <v-toolbar
        color="primary"
        dark>
        <v-toolbar-title class="appbar-menu-title"/>
8

9
        <v-toolbar-items>
10 11 12 13 14 15 16 17 18
        <v-menu
          open-on-hover
          offset-y
          :close-on-content-click="false">
          <v-btn
            slot="activator"
            depressed
            @mouseover="runsSelectorOpen = true"
            @mouseout="runsSelectorOpen = false"
N
Nicky Chan 已提交
19
            :ripple="false"
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
            :color="runsSelectorOpen ? 'dark_primary' : 'primary'"
            :class="runsSelectorOpen ? 'runs-selected-menu-open' : 'runs-selected-menu'"
            > <span class="runs-selected-text">Runs: {{ runs.length == 0 ? 'None selected' : runs.join(', ') }} </span>
            <v-icon>arrow_drop_down</v-icon>
          </v-btn>
          <v-list dense>
            <v-list-tile
              v-for="(item, index) in availableRuns"
              :key="index"
              @mouseover="runsSelectorOpen = true"
              @mouseout="runsSelectorOpen = false">
              <v-list-tile-action>
                <v-checkbox
                  :value="item"
                  :key="item"
                  :label="item"
                  v-model="runs" />
              </v-list-tile-action>
            </v-list-tile>
          </v-list>
        </v-menu>

42 43 44 45 46
          <v-btn
            v-for="item in items"
            :key="item.name"
            flat
            dark
N
Nicky Chan 已提交
47
            :class="selected.toLowerCase() === item.name.toLowerCase() ? 'menu-item-selected': 'menu-item'"
48 49 50 51
            @click="handleItemClick(item)"
          >{{ item.title }}</v-btn>
        </v-toolbar-items>
      </v-toolbar>
J
Jeff Wang 已提交
52
    </div>
53
  </div>
J
Jeff Wang 已提交
54 55 56
</template>

<script>
57 58
import {getRuns} from '../../service';

J
Jeff Wang 已提交
59
export default {
J
Jeff Wang 已提交
60 61 62 63 64 65
  props: {
    initialRoute: {
      type: String,
      required: true,
    },
  },
J
Jeff Wang 已提交
66 67 68
  name: 'AppMenu',
  data() {
    return {
69
      runsSelectorOpen: false,
70 71
      availableRuns: [],
      runs: [],
J
Jeff Wang 已提交
72 73 74 75 76 77 78
      selected: this.initialRoute,
      items: [
        {
          url: '/scalars',
          title: 'SCALARS',
          name: 'scalars',
        },
79 80 81 82 83
        {
          url: '/histograms',
          title: 'HISTOGRAMS',
          name: 'histograms',
        },
J
Jeff Wang 已提交
84 85 86 87 88 89 90 91 92 93 94
        {
          url: '/images',
          title: 'IMAGES',
          name: 'images',
        },
        {
          url: '/audio',
          title: 'AUDIO',
          name: 'audio',
        },
        {
95 96 97
          url: '/texts',
          title: 'TEXTS',
          name: 'texts',
J
Jeff Wang 已提交
98 99 100 101 102 103
        },
        {
          url: '/graphs',
          title: 'GRAPHS',
          name: 'graphs',
        },
J
Jeff Wang 已提交
104 105 106 107 108
        {
          url: '/HighDimensional',
          title: 'HighDimensional',
          name: 'HighDimensional',
        },
J
Jeff Wang 已提交
109 110 111
      ],
    };
  },
112
  created() {
N
Nicky Chan 已提交
113
    this.runs = this.$route.query.runs; //maintain runs state after refresh
114 115
    getRuns().then(({errno, data}) => {
      this.availableRuns = data;
N
Nicky Chan 已提交
116 117 118
      if (!this.runs) this.runs = data;
      //use replace here instead of push so that user cannot go back to empty run state
      this.$router.replace( { path: this.initialRoute, query: { runs: this.runs }});
119 120 121 122
    });
  },
  watch: {
    runs: function(val) {
N
Nicky Chan 已提交
123 124 125
        if (this.runs) {
          this.$router.push( {query: { runs: this.runs }});
        }
126
    },
N
Nicky Chan 已提交
127 128 129 130
    '$route' (to, from) { //this will get called when back button is hit that changes path or query
       this.runs = this.$route.query.runs;
       this.selected = this.$route.name;
    }
131
  },
J
Jeff Wang 已提交
132 133 134
  methods: {
    handleItemClick: function(item) {
      this.selected = item.name;
135
      this.$router.push( { path: item.url, query: { runs: this.runs }});
136
    },
J
Jeff Wang 已提交
137
  },
138
};
J
Jeff Wang 已提交
139 140
</script>

141
<style lang="stylus">
J
Jeff Wang 已提交
142 143 144 145 146
@import '~style/variables';

.visual-dl-app-menu
    .appbar-menu-title
        flex none
147
        margin-right 10px
N
Nicky Chan 已提交
148 149 150
        background url('../../assets/ic_logo.svg') no-repeat
        width 180px
        height 24px
J
Jeff Wang 已提交
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167

    .menu-item
        font-size 16px
        background none
        padding 0 10px
        color #fff
        opacity 0.6
        display flex
        flex-direction row
        font-weight bold

    .menu-item:hover
        opacity 1

    .menu-item-selected
        @extends .visual-dl-app-menu .menu-item
        opacity 1
168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192

    .runs-selected-menu
        font-size 16px
        text-transform none
        opacity 0.75

    .runs-selected-menu-open
        @extends .visual-dl-app-menu .runs-selected-menu
        opacity 1

    .runs-selected-text
        text-align left
        padding-right 6px
        overflow hidden
        text-overflow ellipsis
        max-width 200px

.theme--light .input-group:not(.input-group--error) label
    color #000

.input-group label
    overflow visible



J
Jeff Wang 已提交
193
</style>