Skip to content

Commit 02a37cc

Browse files
authored
Merge pull request #219 from billangli/dev/timeline-input-button
2 parents 50b3258 + 050f700 commit 02a37cc

3 files changed

Lines changed: 49 additions & 34 deletions

File tree

src/components/InputTimeInterval.vue

Lines changed: 42 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,24 @@
11
<template lang="pug">
22
div
33
div
4+
b-alert(v-if="mode == 'range' && invalidDaterange", variant="warning", show)
5+
| The selected date range is invalid. The second date must be greater than the first date.
6+
b-alert(v-if="mode == 'range' && daterangeTooLong", variant="warning", show)
7+
| The selected date range is too long. The maximum is {{ maxDuration/(24*60*60) }} days.
8+
49
table
510
tr
611
th.pr-2
712
label(for="mode") Interval mode:
813
td
9-
select(id="mode" v-model="mode")
14+
select(id="mode", v-model="mode")
1015
option(value='last_duration') Last duration
1116
option(value='range') Date range
1217
tr(v-if="mode == 'last_duration'")
1318
th.pr-2
1419
label(for="duration") Show last:
1520
td
16-
select(id="duration" :value="duration", @change="valueChanged")
21+
select(id="duration", v-model="duration", @change="valueChanged")
1722
option(:value="15*60") 15min
1823
option(:value="30*60") 30min
1924
option(:value="60*60") 1h
@@ -25,27 +30,36 @@ div
2530
tr(v-if="mode == 'range'")
2631
th.pr-2 Range:
2732
td
28-
input(type="date", v-model="start", @input="valueChanged")
29-
input(type="date", v-model="end", @input="valueChanged")
33+
input(type="date", v-model="start")
34+
input(type="date", v-model="end")
35+
button(
36+
class="btn btn-outline-dark btn-sm",
37+
type="button",
38+
:disabled="mode == 'range' && (invalidDaterange || emptyDaterange || daterangeTooLong)",
39+
@click="valueChanged"
40+
) Update
3041

3142
</template>
3243

3344
<style scoped lang="scss"></style>
3445

3546
<script>
3647
import moment from 'moment';
37-
3848
export default {
3949
name: 'input-timeinterval',
4050
props: {
41-
duration: {
51+
defaultDuration: {
4252
type: Number,
4353
default: 60 * 60,
4454
},
55+
maxDuration: {
56+
type: Number,
57+
default: null,
58+
},
4559
},
46-
data: () => {
60+
data() {
4761
return {
48-
now: moment(),
62+
duration: JSON.parse(JSON.stringify(this.defaultDuration)), // Make a copy of defaultDuration
4963
mode: 'last_duration',
5064
start: null,
5165
end: null,
@@ -57,24 +71,31 @@ export default {
5771
if (this.mode == 'range' && this.start && this.end) {
5872
return [moment(this.start), moment(this.end)];
5973
} else {
60-
return [moment(this.now).subtract(this.duration, 'seconds'), moment(this.now)];
61-
}
62-
},
63-
set(newValue) {
64-
if (!isNaN(newValue)) {
65-
// Set new now and duration
66-
this.now = moment();
67-
this.duration = newValue;
68-
} else {
69-
// Not required for mode='range', start and end set directly through v-model
74+
return [moment().subtract(this.duration, 'seconds'), moment()];
7075
}
7176
},
7277
},
78+
emptyDaterange() {
79+
return !(this.start && this.end);
80+
},
81+
invalidDaterange() {
82+
return moment(this.start) >= moment(this.end);
83+
},
84+
daterangeTooLong() {
85+
return moment(this.start).add(this.maxDuration, 'seconds').isBefore(moment(this.end));
86+
},
87+
},
88+
mounted() {
89+
this.valueChanged();
7390
},
7491
methods: {
75-
valueChanged(e) {
76-
this.value = e.target.value;
77-
this.$emit('input', this.value);
92+
valueChanged() {
93+
if (
94+
this.mode == 'last_duration' ||
95+
(!this.emptyDaterange && !this.invalidDaterange && !this.daterangeTooLong)
96+
) {
97+
this.$emit('input', this.value);
98+
}
7899
},
79100
},
80101
};

src/views/Bucket.vue

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,14 @@ div
2424
th Eventcount:
2525
td {{ eventcount }}
2626

27-
input-timeinterval(v-model="daterange")
27+
input-timeinterval(v-model="daterange", :maxDuration="maxDuration")
2828

2929
vis-timeline(:buckets="[bucket_with_events]", :showRowLabels="false")
3030

3131
aw-eventlist(:bucket_id="id", @save="updateEvent", :events="events")
3232
</template>
3333

3434
<script>
35-
import moment from 'moment';
36-
3735
export default {
3836
name: 'Bucket',
3937
props: {
@@ -44,7 +42,8 @@ export default {
4442
bucket_with_events: { events: [] },
4543
events: [],
4644
eventcount: '?',
47-
daterange: [moment().subtract(1, 'hour'), moment()],
45+
daterange: null,
46+
maxDuration: 31 * 24 * 60 * 60,
4847
};
4948
},
5049
computed: {
@@ -59,7 +58,6 @@ export default {
5958
},
6059
mounted: async function () {
6160
await this.$store.dispatch('buckets/ensureBuckets');
62-
await this.getEvents(this.id);
6361
await this.getEventCount(this.id);
6462
},
6563
methods: {

src/views/Timeline.vue

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
div
33
h2 Timeline
44

5-
input-timeinterval(v-model="daterange", v-bind:duration="timeintervalDefaultDuration")
5+
input-timeinterval(v-model="daterange", :defaultDuration="timeintervalDefaultDuration", :maxDuration="maxDuration")
66

77
div(v-show="buckets !== null")
88
div
@@ -17,16 +17,15 @@ div
1717
</template>
1818

1919
<script>
20-
import moment from 'moment';
2120
import _ from 'lodash';
22-
2321
export default {
2422
name: 'Timeline',
25-
data: () => {
23+
data() {
2624
return {
2725
buckets: null,
28-
daterange: [moment().subtract(1, 'hour'), moment()],
26+
daterange: null,
2927
timeintervalDefaultDuration: localStorage.durationDefault,
28+
maxDuration: 31 * 24 * 60 * 60,
3029
};
3130
},
3231
computed: {
@@ -39,9 +38,6 @@ export default {
3938
this.getBuckets();
4039
},
4140
},
42-
mounted: function () {
43-
this.getBuckets();
44-
},
4541
methods: {
4642
getBuckets: async function () {
4743
this.buckets = await this.$store.dispatch('buckets/getBucketsWithEvents', {

0 commit comments

Comments
 (0)