Images.san 5.0 KB
Newer Older
B
BingBlog 已提交
1 2 3 4 5 6 7 8 9 10 11 12
<template>
    <div class="visual-dl-scalar-container">
        <div class="visual-dl-scalar-left">
            <div class="visual-dl-scalar-config-container">
                <ui-config
                    runsItems="{{runsItems}}"
                    config="{=config=}"
                ></ui-config>
            </div>
        </div>
        <div class="visual-dl-scalar-right">
            <ui-chart-page
B
BingBlog 已提交
13
                config="{{filteredConfig}}"
B
BingBlog 已提交
14 15 16 17 18 19
                runsItems="{{runsItems}}"
                tagList="{{filteredTagsList}}"
                title="Tags matching {{config.groupNameReg}}"
            ></ui-chart-page>
            <ui-chart-page
                san-for="item in groupedTags"
B
BingBlog 已提交
20
                config="{{filteredConfig}}"
B
BingBlog 已提交
21 22 23 24 25 26 27 28 29 30 31 32
                runsItems="{{runsItems}}"
                tagList="{{item.tags}}"
                title="{{item.group}}"
            ></ui-chart-page>
        </div>
    </div>
</template>

<script>
import {getPluginImagesTags, getRuns} from '../service';
import config from './ui/config';
import chartPage from './ui/chartPage';
B
BingBlog 已提交
33
import {debounce, flatten, uniq, isArray} from 'lodash';
B
BingBlog 已提交
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
export default {
    components: {
        'ui-config': config,
        'ui-chart-page': chartPage
    },
    computed: {
        runsItems() {
            let runsArray = this.data.get('runsArray') || [];
            return runsArray.map(item => {
                return {
                    name: item,
                    value: item
                };
            });
        },
        tagsList() {
            let tags = this.data.get('tags');

            let runs = Object.keys(tags);
            let tagsArray = runs.map(run => Object.keys(tags[run]));
            let allUniqTags = uniq(flatten(tagsArray));

            // get the data for every chart
            return allUniqTags.map(tag => {
                let tagList = runs.map(run => {
                    return {
                        run,
                        tag: tags[run][tag]
                    };
                });
                return {
                    tagList,
                    tag,
                    group: tag.split('/')[0]
                };
            });
        },
        groupedTags() {
            let tagsList = this.data.get('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);
                }
            });

            // to array
            let groups = Object.keys(groupData);
            return groups.map(group => {
                return {
                    group,
                    tags: groupData[group]
                };
            });
B
BingBlog 已提交
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
        },
        filteredConfig() {
            let tansformArr = ['isActualImageSize'];
            let config = this.data.get('config') || {};
            console.log(config);
            let filteredConfig = {};
            Object.keys(config).forEach(key => {
                let val = config[key];
                if (tansformArr.indexOf(key) > -1) {
                    filteredConfig[key] = isArray(val) && val[0] === 'yes';
                }
                else {
                    filteredConfig[key] = val;
                }
            });
            return filteredConfig;
B
BingBlog 已提交
110 111 112 113 114 115 116 117
        }
    },
    initData() {
        return {
            runsArray: [],
            tags: [],
            config: {
                groupNameReg: '.*',
B
BingBlog 已提交
118 119
                isActualImageSize: [],
                runs: []
B
BingBlog 已提交
120 121 122 123 124 125 126 127 128 129 130 131 132
            }
        };
    },
    inited() {
        getPluginImagesTags().then(({errno, data}) => {
            this.data.set('tags', data);

            // filter when inited
            let groupNameReg = this.data.get('config.groupNameReg');
            this.filterTagsList(groupNameReg);
        });
        getRuns().then(({errno, data}) => {
            this.data.set('runsArray', data);
B
BingBlog 已提交
133
            this.data.set('config.runs', data);
B
BingBlog 已提交
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169
        });

        // need debounce, can't use computed
        this.watch('config.groupNameReg', debounce(this.filterTagsList, 300));
    },

    filterTagsList(groupNameReg) {
        let tagsList = this.data.get('tagsList') || [];
        let regExp = new RegExp(groupNameReg);
        let filtedTagsList = tagsList.filter(item => regExp.test(item.tag));
        this.data.set('filteredTagsList', filtedTagsList);
    }
};

</script>

<style lang="stylus">

@import '../style/variables';

+prefix-classes('visual-dl-scalar-')
    .container
        padding-left 300px
        position relative
        .left
            width 280px
            min-height 300px
            border solid 1px #e4e4e4
            position absolute
            left 0
        .right
            width 100%
            border solid 1px #e4e4e4
            min-height 300px
            padding 20px
</style>