Audio.vue 3.9 KB
Newer Older
1
<template>
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
  <div class="visual-dl-page-container">
    <div class="visual-dl-page-left">
      <ui-audio-container
        :expand="true"
        :config="filteredConfig"
        :runs-items="runsItems"
        :tag-list="filteredTagsList"
        :title="'Tags matching ' + config.groupNameReg"
      />
      <ui-audio-container
        v-for="item in groupedTags"
        :key="item.group"
        :config="filteredConfig"
        :runs-items="runsItems"
        :tag-list="item.tags"
        :title="item.group"
      />
19
    </div>
20 21 22 23 24 25 26 27 28
    <div class="visual-dl-page-right">
      <div class="visual-dl-page-config-container">
        <ui-config
          :runs-items="runsItems"
          :config="config"
        />
      </div>
    </div>
  </div>
29 30 31 32 33
</template>

<script>

import {getPluginAudioTags, getRuns} from '../service';
34
import {flatten, uniq} from 'lodash';
35 36
import autoAdjustHeight from '../common/util/autoAdjustHeight';

37
import Config from './ui/Config';
38 39 40
import AudioPanelContainer from './ui/AudioPanelContainer';

export default {
J
Jeff Wang 已提交
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
  name: 'Images',
  components: {
    'ui-config': Config,
    'ui-audio-container': AudioPanelContainer,
  },
  data() {
    return {
      runsArray: [],
      tags: [],
      config: {
        groupNameReg: '.*',
        isActualImageSize: false,
        runs: [],
        running: true,
      },
      filteredTagsList: [],
    };
  },
  computed: {
    runsItems() {
      let runsArray = this.runsArray || [];
      return runsArray.map((item) => {
63
        return {
J
Jeff Wang 已提交
64 65
          name: item,
          value: item,
66
        };
J
Jeff Wang 已提交
67
      });
68
    },
J
Jeff Wang 已提交
69 70
    tagsList() {
      let tags = this.tags;
71

J
Jeff Wang 已提交
72 73 74
      let runs = Object.keys(tags);
      let tagsArray = runs.map((run) => Object.keys(tags[run]));
      let allUniqTags = uniq(flatten(tagsArray));
75

J
Jeff Wang 已提交
76 77 78 79 80 81 82 83 84 85 86 87 88 89
      // get the data for every chart
      return allUniqTags.map((tag) => {
        let tagList = runs.map((run) => {
          return {
            run,
            tag: tags[run][tag],
          };
        }).filter((item) => item.tag !== undefined);
        return {
          tagList,
          tag,
          group: tag.split('/')[0],
        };
      });
90
    },
J
Jeff Wang 已提交
91 92 93 94 95 96 97 98 99 100 101 102 103
    groupedTags() {
      let tagsList = this.tagsList || [];
      // put data in group
      let groupData = {};
      tagsList.forEach((item) => {
        let group = item.group;
        if (groupData[group] === undefined) {
          groupData[group] = [];
          groupData[group].push(item);
        } else {
          groupData[group].push(item);
        }
      });
104

J
Jeff Wang 已提交
105 106 107 108 109 110 111 112
      // to array
      let groups = Object.keys(groupData);
      return groups.map((group) => {
        return {
          group,
          tags: groupData[group],
        };
      });
113
    },
J
Jeff Wang 已提交
114 115 116 117 118 119 120 121
    filteredConfig() {
      let config = this.config || {};
      let filteredConfig = {};
      Object.keys(config).forEach((key) => {
        let val = config[key];
        filteredConfig[key] = val;
      });
      return filteredConfig;
122
    },
J
Jeff Wang 已提交
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143
  },
  created() {
    getPluginAudioTags().then(({errno, data}) => {
      this.tags = data;

      // filter when inited
      let groupNameReg = this.config.groupNameReg;
      this.filterTagsList(groupNameReg);
    });

    getRuns().then(({errno, data}) => {
      this.runsArray = data;
      this.config.runs = data;
    });
  },
  mounted() {
    autoAdjustHeight();
  },
  watch: {
    'config.groupNameReg': function(val) {
      this.throttledFilterTagsList();
144
    },
J
Jeff Wang 已提交
145 146 147 148 149 150 151 152 153 154
  },
  methods: {
    filterTagsList(groupNameReg) {
      if (!groupNameReg) {
        this.filteredTagsList = [];
        return;
      }
      let tagsList = this.tagsList || [];
      let regExp = new RegExp(groupNameReg);
      this.filteredTagsList = tagsList.filter((item) => regExp.test(item.tag));
155
    },
J
Jeff Wang 已提交
156 157 158 159 160 161
    throttledFilterTagsList: _.debounce(
      function() {
        this.filterTagsList(this.config.groupNameReg);
      }, 300
    ),
  },
162 163 164 165 166 167 168
};

</script>

<style lang="stylus">

</style>