Skip to content

Commit ea5536e

Browse files
committed
Bugfix: failed to query by host only.
1 parent 1163dac commit ea5536e

File tree

9 files changed

+158
-27
lines changed

9 files changed

+158
-27
lines changed

src/app/App.vue

Lines changed: 40 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,32 @@
33
<el-container>
44
<el-aside>
55
<el-menu :default-active="$route.path">
6-
<el-menu-item v-for="({title,route,icon}) in menu"
6+
<template v-for="({title,route,icon,children}) in menu">
7+
<el-submenu v-if="children&&children.length"
78
:key="title"
8-
:index="route"
9-
@click="openMenu(route, title)">
10-
<i :class="`el-icon-${icon}`"></i>
11-
<span slot="title">
12-
{{ $t(title) }}
13-
</span>
14-
</el-menu-item>
9+
:index='route'>
10+
<template slot="title">
11+
<i :class="`el-icon-${icon}`" />
12+
<span> {{ $t(title) }}</span>
13+
</template>
14+
<el-menu-item v-for="child in children"
15+
:key="title+'-'+child.title"
16+
:index="child.route"
17+
@click="openMenu(child.route, child.title)">
18+
<i :class="`el-icon-${child.icon}`"></i>
19+
<span slot="title"> {{ $t(child.title) }} </span>
20+
</el-menu-item>
21+
</el-submenu>
22+
<el-menu-item v-else
23+
:key="title"
24+
:index="route"
25+
@click="openMenu(route, title)">
26+
<i :class="`el-icon-${icon}`"></i>
27+
<span slot="title">
28+
{{ $t(title) }}
29+
</span>
30+
</el-menu-item>
31+
</template>
1532
</el-menu>
1633
</el-aside>
1734
<el-container class="app-container">
@@ -27,9 +44,20 @@ export default {
2744
return {
2845
menu: [
2946
{
30-
title: 'menu.record',
31-
route: '/record',
32-
icon: 's-platform'
47+
title: 'menu.data',
48+
icon: 's-platform',
49+
route: '/data',
50+
children: [
51+
{
52+
title: 'menu.dataReport',
53+
route: '/data/report',
54+
icon: 'date'
55+
}, {
56+
title: 'menu.dataHistory',
57+
route: '/data/history',
58+
icon: 'stopwatch'
59+
}
60+
]
3361
}, {
3462
title: 'menu.setting',
3563
route: '/setting',
@@ -39,7 +67,7 @@ export default {
3967
}
4068
},
4169
created () {
42-
document.title = this.$t('menu.record')
70+
document.title = this.$t('menu.data')
4371
},
4472
methods: {
4573
openMenu (route, title) {
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<template>
2+
<div class="content-container">
3+
<div class="filter-container">
4+
<el-select placeholder="ceshi"
5+
v-model="trenderDomain"
6+
multiple
7+
filterable
8+
remote
9+
:remote-method="queryDomainHandler"
10+
:loading="trenderSearching">
11+
<el-option v-for="option in trenderDomainOptions"
12+
:key="option"
13+
:label="option"
14+
:value="option" />
15+
</el-select>
16+
</div>
17+
</div>
18+
</template>
19+
<script>
20+
import timerService from '../../../service/timer-service'
21+
export default {
22+
name: 'Trender',
23+
data () {
24+
return {
25+
trenderDomain: '',
26+
trenderSearching: false,
27+
trenderDomainOptions: []
28+
}
29+
},
30+
methods: {
31+
queryDomainHandler (query) {
32+
if (!query) {
33+
this.trenderDomainOptions = []
34+
} else {
35+
this.trenderSearching = true
36+
timerService.listDomains(query, domains => {
37+
this.trenderDomainOptions = domains
38+
this.trenderSearching = false
39+
})
40+
}
41+
}
42+
}
43+
}
44+
</script>

src/app/element.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
Main, Menu, MenuItem, Message, MessageBox,
99
Option,
1010
Pagination, Popconfirm,
11-
Switch,
11+
Select, Submenu, Switch,
1212
Table, TableColumn, TabPane, Tabs, Tag
1313
} from 'element-ui'
1414

@@ -60,6 +60,10 @@ Vue.use(Popconfirm)
6060
import 'element-ui/lib/theme-chalk/popconfirm.css'
6161
import 'element-ui/lib/theme-chalk/popover.css'
6262

63+
Vue.use(Select)
64+
import 'element-ui/lib/theme-chalk/select.css'
65+
Vue.use(Submenu)
66+
import 'element-ui/lib/theme-chalk/submenu.css'
6367
Vue.use(Switch)
6468
import 'element-ui/lib/theme-chalk/switch.css'
6569

src/app/main.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,14 @@ import './element'
44
import i18n from '../common/vue-i18n'
55
import router from './router'
66
import './styles/index.scss'
7+
import { openLog, closeLog } from '../common/logger'
8+
9+
/**
10+
* Manually open and close the log
11+
*
12+
* @since 0.0.8
13+
*/
14+
window.timer = { openLog, closeLog }
715

816
new Vue({
917
el: '#app',

src/app/router.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,18 @@ Vue.use(VueRouter)
66
const routes = [
77
{
88
path: '/',
9-
redirect: '/record'
9+
redirect: '/data'
1010
}, {
11-
path: '/record',
12-
component: () => import('./components/Record'),
11+
path: '/data',
12+
redirect: '/data/report',
13+
},
14+
// Needn't nested router
15+
{
16+
path: '/data/report',
17+
component: () => import('./components/Record')
18+
}, {
19+
path: '/data/history',
20+
component: () => import('./components/Trender')
1321
}, {
1422
path: '/setting',
1523
component: () => import('./components/Setting'),

src/common/logger.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,15 @@ export function log(...args: any) {
1212
/**
1313
* @since 0.0.4
1414
*/
15-
export function openLog() {
15+
export function openLog(): string {
1616
OPEN_LOG = true
17+
return 'Opened the log manually.'
18+
}
19+
20+
/**
21+
* @since 0.0.8
22+
*/
23+
export function closeLog(): string {
24+
OPEN_LOG = false
25+
return 'Closed the log manually.'
1726
}

src/database/timer-database.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,12 @@ class TimeDatabase {
192192

193193
}
194194

195+
/**
196+
* Select without page
197+
*
198+
* @param callback callback
199+
* @param param param
200+
*/
195201
public select(callback: (result: Row[]) => void, param?: QueryParam) {
196202
log("selectByPage:{param}", param)
197203
param = param || new QueryParam()
@@ -240,9 +246,10 @@ class TimeDatabase {
240246
private filterBefore(date: string, host: string, val: WastePerDay, param: QueryParam) {
241247
const paramDate = param.date
242248
const paramHost = (param.host || '').trim()
243-
if (paramDate !== undefined) {
244-
if (paramHost && !host.includes(paramHost)) return false
245249

250+
if (paramHost && !host.includes(paramHost)) return false
251+
252+
if (paramDate !== undefined) {
246253
if (paramDate instanceof Date) {
247254
const paramDateStr = formatTime(paramDate as Date, DATE_FORMAT)
248255
if (paramDateStr !== date) {

src/locale/components/menu.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
11
module.exports = {
22
zh_CN: {
3-
record: '我的数据',
3+
data: '我的数据',
4+
dataReport: '报表明细',
5+
dataHistory: '历史趋势',
46
setting: '扩展选项'
57
},
68
en: {
7-
record: 'My Records',
9+
data: 'My datas',
10+
dataReport: 'Report',
11+
dataHistory: 'Historical trend',
812
setting: 'Options'
913
},
1014
ja: {
11-
record: '私のデータ',
12-
setting: '拡張設定'
15+
data: '私のデータ',
16+
dataReport: '報告する',
17+
dataHistory: '歴史的傾向',
18+
setting: '拡張設定',
1319
}
1420
}

src/service/timer-service.ts

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import timeDatabase from '../database/timer-database'
1+
import timerDatabase, { QueryParam } from '../database/timer-database'
22
import whitelistDatabase from '../database/whitelist-database'
33

44
/**
@@ -8,20 +8,37 @@ import whitelistDatabase from '../database/whitelist-database'
88
class TimeService {
99

1010
public addTotal(url: string, start: number) {
11-
this.notInWhitelistThen(url, () => timeDatabase.addTotal(url, start))
11+
this.notInWhitelistThen(url, () => timerDatabase.addTotal(url, start))
1212
}
1313

1414
public addFocusAndTotal(url: string, focusStart: number, runStart: number) {
15-
this.notInWhitelistThen(url, () => timeDatabase.addFocusAndTotal(url, focusStart, runStart))
15+
this.notInWhitelistThen(url, () => timerDatabase.addFocusAndTotal(url, focusStart, runStart))
1616
}
1717

1818
public addOneTime(url: string) {
19-
this.notInWhitelistThen(url, () => timeDatabase.addOneTime(url))
19+
this.notInWhitelistThen(url, () => timerDatabase.addOneTime(url))
2020
}
2121

2222
private notInWhitelistThen(url: string, hook: () => void) {
2323
!!url && whitelistDatabase.includes(url, include => !include && hook())
2424
}
25+
26+
/**
27+
* Query domain names
28+
*
29+
* @param fuzzyQuery the part of domain name
30+
* @param callback callback
31+
* @since 0.0.8
32+
*/
33+
public listDomains(fuzzyQuery: string, callback: (domains: Set<string>) => void) {
34+
const param: QueryParam = new QueryParam()
35+
param.host = fuzzyQuery
36+
timerDatabase.select(rows => {
37+
const result: Set<string> = new Set()
38+
rows.forEach(row => result.add(row.host))
39+
callback(result)
40+
}, param)
41+
}
2542
}
2643

2744
export default new TimeService()

0 commit comments

Comments
 (0)