Skip to content

Commit df5a625

Browse files
Merge pull request #201 from ActivityWatch/dev/period-link-subview-fix
Subview is now kept when changing date in Activity view
2 parents 9247aed + f31c75c commit df5a625

File tree

3 files changed

+23
-16
lines changed

3 files changed

+23
-16
lines changed

src/views/activity/Activity.vue

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ div
3434
span.d-none.d-md-inline
3535
| Refresh
3636

37-
aw-periodusage(:periodusage_arr="periodusage", :link_prefix="link_prefix")
37+
aw-periodusage(:periodusage_arr="periodusage", @update="setDate")
3838

3939
ul.row.nav.nav-tabs.mt-3.pl-3
4040
li.nav-item
@@ -224,13 +224,18 @@ export default {
224224
return 'day';
225225
}
226226
},
227+
227228
setDate: function(date, periodLength) {
229+
// periodLength is an optional argument, default to this.periodLength
230+
if (!periodLength) {
231+
periodLength = this.periodLength;
232+
}
228233
const new_period_length_moment = this.periodLengthConvertMoment(periodLength);
229234
const new_date = moment(date)
230235
.startOf(new_period_length_moment)
231236
.format('YYYY-MM-DD');
232237
console.log(new_date, periodLength);
233-
this.$router.push(`/activity/${this.host}/${periodLength}/${new_date}`);
238+
this.$router.push(`/activity/${this.host}/${periodLength}/${new_date}/${this.subview}`);
234239
},
235240
236241
refresh: async function(force) {

src/visualizations/PeriodUsage.vue

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,24 @@ import periodusage from './periodusage.js';
2121
2222
export default {
2323
name: 'aw-periodusage',
24-
props: ['periodusage_arr', 'link_prefix'],
24+
props: {
25+
periodusage_arr: {
26+
type: Array,
27+
},
28+
},
2529
watch: {
2630
periodusage_arr: function() {
27-
periodusage.update(this.$el, this.periodusage_arr, this.link_prefix);
31+
periodusage.update(this.$el, this.periodusage_arr, this.onPeriodClicked);
2832
},
2933
},
3034
mounted: function() {
3135
periodusage.create(this.$el);
3236
periodusage.set_status(this.$el, 'Loading...');
3337
},
38+
methods: {
39+
onPeriodClicked: function(period) {
40+
this.$emit('update', period);
41+
},
42+
},
3443
};
3544
</script>

src/visualizations/periodusage.js

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,16 @@ const diagramcolor = '#aaa';
3030
const diagramcolor_selected = '#fc5';
3131
const diagramcolor_focused = '#adf';
3232

33-
function update(svg_elem, usage_arr, link_prefix) {
33+
function update(svg_elem, usage_arr, onPeriodClicked) {
3434
const dateformat = 'YYYY-MM-DD';
3535

3636
// No apps, sets status to "No data"
3737
if (usage_arr.length <= 0) {
3838
set_status(svg_elem, 'No data');
39-
return svg;
39+
return;
4040
}
4141
svg_elem.innerHTML = '';
42-
var svg = d3.select(svg_elem);
42+
const svg = d3.select(svg_elem);
4343

4444
function get_usage_time(day_events) {
4545
const day_event = _.head(_.filter(day_events, e => e.data.status == 'not-afk'));
@@ -101,7 +101,6 @@ function update(svg_elem, usage_arr, link_prefix) {
101101
.attr('height', height + offset + '%')
102102
.attr('color', color)
103103
.attr('date', date)
104-
.attr('data', link_prefix)
105104
.style('fill', color)
106105
.on('mouseover', () => {
107106
rect.style('fill', diagramcolor_focused);
@@ -110,14 +109,8 @@ function update(svg_elem, usage_arr, link_prefix) {
110109
const a = n[j];
111110
rect.style('fill', a.getAttribute('color'));
112111
})
113-
.on('click', function(d, j, n) {
114-
const me = n[j];
115-
const date = d3.select(me).attr('date');
116-
const link_prefix = d3.select(me).attr('data');
117-
const url = `/#${link_prefix}/${date}`;
118-
/* Not the vue-way, but works */
119-
window.location.assign(url);
120-
/* Hardcoding click behavior also isn't optimal I guess */
112+
.on('click', function() {
113+
onPeriodClicked(date);
121114
});
122115
rect
123116
.append('title')

0 commit comments

Comments
 (0)