|
| 1 | +<template lang="pug"> |
| 2 | +div |
| 3 | + h5 {{ type_title }} |
| 4 | + div(v-if="type == 'top_apps'") |
| 5 | + aw-summary(:fields="top_apps", |
| 6 | + :namefunc="e => e.data.app", |
| 7 | + :colorfunc="e => e.data.app", |
| 8 | + with_limit) |
| 9 | + div(v-if="type == 'top_titles'") |
| 10 | + aw-summary(:fields="top_titles", |
| 11 | + :namefunc="e => e.data.title", |
| 12 | + :colorfunc="e => e.data.app", |
| 13 | + with_limit) |
| 14 | + div(v-if="type == 'top_domains'") |
| 15 | + aw-summary(:fields="top_domains", |
| 16 | + :namefunc="e => e.data.$domain", |
| 17 | + :colorfunc="e => e.data.$domain", |
| 18 | + with_limit) |
| 19 | + div(v-if="type == 'top_urls'") |
| 20 | + aw-summary(:fields="top_urls", |
| 21 | + :namefunc="e => e.data.url", |
| 22 | + :colorfunc="e => e.data.$domain", |
| 23 | + with_limit) |
| 24 | + div(v-if="type == 'top_editor_files'") |
| 25 | + aw-summary(:fields="$store.state.activity_daily.editor.top_files", |
| 26 | + :namefunc="top_editor_files_namefunc", |
| 27 | + :colorfunc="e => e.data.language", |
| 28 | + with_limit) |
| 29 | + div(v-if="type == 'top_editor_languages'") |
| 30 | + aw-summary(:fields="$store.state.activity_daily.editor.top_languages", |
| 31 | + :namefunc="e => e.data.language", |
| 32 | + :colorfunc="e => e.data.language", |
| 33 | + with_limit) |
| 34 | + div(v-if="type == 'top_editor_projects'") |
| 35 | + aw-summary(:fields="$store.state.activity_daily.editor.top_projects", |
| 36 | + :namefunc="top_editor_projects_namefunc", |
| 37 | + :colorfunc="e => e.data.language", |
| 38 | + with_limit) |
| 39 | + div(v-if="type == 'top_categories'") |
| 40 | + aw-summary(:fields="top_categories", |
| 41 | + :namefunc="e => e.data['$category'].join(' > ')", |
| 42 | + :colorfunc="e => e.data['$category'].join(' > ')", |
| 43 | + with_limit) |
| 44 | + div(v-if="type == 'category_tree'") |
| 45 | + aw-categorytree(:events="top_categories") |
| 46 | + div(v-if="type == 'category_sunburst'") |
| 47 | + aw-sunburst-categories(:data="top_categories_hierarchy", style="height: 20em") |
| 48 | + |
| 49 | + b-dropdown.vis-style-dropdown-btn(size="sm" variant="outline-secondary") |
| 50 | + template(v-slot:button-content) |
| 51 | + icon(name="cog") |
| 52 | + b-dropdown-item(v-for="t in types" :key="t" variant="outline-secondary" @click="$emit('onTypeChange', id, t)" v-bind:disabled="!get_type_available(t)") |
| 53 | + | {{ get_type_title(t) }} |
| 54 | +</template> |
| 55 | + |
| 56 | +<style scoped lang="scss"> |
| 57 | +.vis-style-dropdown-btn { |
| 58 | + position: absolute; |
| 59 | + bottom: 0; |
| 60 | + right: 0.5em; |
| 61 | +
|
| 62 | + background-color: #fff; |
| 63 | +} |
| 64 | +</style> |
| 65 | + |
| 66 | +<script> |
| 67 | +// TODO: Move this somewhere else |
| 68 | +import { build_category_hierarchy } from '~/util/classes'; |
| 69 | +function pick_subname_as_name(c) { |
| 70 | + c.name = c.subname; |
| 71 | + c.children = c.children.map(pick_subname_as_name); |
| 72 | + return c; |
| 73 | +} |
| 74 | +
|
| 75 | +export default { |
| 76 | + name: 'aw-selectable-vis', |
| 77 | + props: { |
| 78 | + id: Number, |
| 79 | + type: String, |
| 80 | + }, |
| 81 | + data: function() { |
| 82 | + return { |
| 83 | + types: [ |
| 84 | + 'top_apps', |
| 85 | + 'top_titles', |
| 86 | + 'top_domains', |
| 87 | + 'top_urls', |
| 88 | + 'top_categories', |
| 89 | + 'category_tree', |
| 90 | + 'category_sunburst', |
| 91 | + 'top_editor_files', |
| 92 | + 'top_editor_languages', |
| 93 | + 'top_editor_projects', |
| 94 | + ], |
| 95 | + // TODO: Move this function somewhere else |
| 96 | + top_editor_files_namefunc: e => { |
| 97 | + let f = e.data.file || ''; |
| 98 | + f = f.split('/'); |
| 99 | + f = f[f.length - 1]; |
| 100 | + return f; |
| 101 | + }, |
| 102 | + // TODO: Move this function somewhere else |
| 103 | + top_editor_projects_namefunc: e => { |
| 104 | + let f = e.data.project || ''; |
| 105 | + f = f.split('/'); |
| 106 | + f = f[f.length - 1]; |
| 107 | + return f; |
| 108 | + }, |
| 109 | + }; |
| 110 | + }, |
| 111 | + computed: { |
| 112 | + top_apps: function() { |
| 113 | + return this.$store.state.activity_daily.window.top_apps; |
| 114 | + }, |
| 115 | + top_titles: function() { |
| 116 | + return this.$store.state.activity_daily.window.top_titles; |
| 117 | + }, |
| 118 | + top_domains: function() { |
| 119 | + return this.$store.state.activity_daily.browser.top_domains; |
| 120 | + }, |
| 121 | + top_urls: function() { |
| 122 | + return this.$store.state.activity_daily.browser.top_urls; |
| 123 | + }, |
| 124 | + top_categories: function() { |
| 125 | + return this.$store.state.activity_daily.category.top; |
| 126 | + }, |
| 127 | + top_categories_hierarchy: function() { |
| 128 | + if (this.top_categories) { |
| 129 | + const categories = this.top_categories.map(c => { |
| 130 | + return { name: c.data.$category, size: c.duration }; |
| 131 | + }); |
| 132 | +
|
| 133 | + return { |
| 134 | + name: 'All', |
| 135 | + children: build_category_hierarchy(categories).map(c => pick_subname_as_name(c)), |
| 136 | + }; |
| 137 | + } else { |
| 138 | + return null; |
| 139 | + } |
| 140 | + }, |
| 141 | + type_title: function() { |
| 142 | + return this.get_type_title(this.type); |
| 143 | + }, |
| 144 | + }, |
| 145 | + methods: { |
| 146 | + get_type_available: function(type) { |
| 147 | + if (type === 'top_apps' || type === 'top_titles') { |
| 148 | + return this.$store.state.activity_daily.window.available; |
| 149 | + } else if (type === 'top_domains' || type === 'top_urls') { |
| 150 | + return this.$store.state.activity_daily.browser.available; |
| 151 | + } else if ( |
| 152 | + type === 'top_editor_files' || |
| 153 | + type === 'top_editor_languages' || |
| 154 | + type === 'top_editor_projects' |
| 155 | + ) { |
| 156 | + return this.$store.state.activity_daily.editor.available; |
| 157 | + } else if ( |
| 158 | + type === 'top_categories' || |
| 159 | + type === 'category_tree' || |
| 160 | + type === 'category_sunburst' |
| 161 | + ) { |
| 162 | + return this.$store.state.activity_daily.category.available; |
| 163 | + } else { |
| 164 | + console.error('Unknown type available: ', type); |
| 165 | + return false; |
| 166 | + } |
| 167 | + }, |
| 168 | + get_type_title: function(type) { |
| 169 | + if (type === 'top_apps') { |
| 170 | + return 'Top Applications'; |
| 171 | + } else if (type === 'top_titles') { |
| 172 | + return 'Top Window Titles'; |
| 173 | + } else if (type === 'top_domains') { |
| 174 | + return 'Top Browser Domains'; |
| 175 | + } else if (type === 'top_urls') { |
| 176 | + return 'Top Browser URLs'; |
| 177 | + } else if (type === 'top_editor_files') { |
| 178 | + return 'Top Editor Files'; |
| 179 | + } else if (type === 'top_editor_languages') { |
| 180 | + return 'Top Editor Languages'; |
| 181 | + } else if (type === 'top_editor_projects') { |
| 182 | + return 'Top Editor Projects'; |
| 183 | + } else if (type === 'top_categories') { |
| 184 | + return 'Top Categories'; |
| 185 | + } else if (type === 'category_tree') { |
| 186 | + return 'Category Tree'; |
| 187 | + } else if (type === 'category_sunburst') { |
| 188 | + return 'Category Sunburst'; |
| 189 | + } else { |
| 190 | + console.error('Unknown type: ', type); |
| 191 | + return 'Unknown'; |
| 192 | + } |
| 193 | + }, |
| 194 | + }, |
| 195 | +}; |
| 196 | +</script> |
0 commit comments