Skip to content

Commit ed37580

Browse files
refactor: Split Settings into multiple views
1 parent ebfedf7 commit ed37580

File tree

6 files changed

+119
-68
lines changed

6 files changed

+119
-68
lines changed

src/components/CategoryEditTree.vue

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
<template lang="pug">
22
div
3-
div.row.py-2.cls
3+
div.row.py-2.class
44
div.col-8.col-md-4
55
span(:style="{ marginLeft: (2 * depth) + 'em'}")
6-
//| {{ cls.name.join(" ➤ ")}}
7-
| #[span(v-if="depth > 0")] {{ cls.name.slice(depth).join(" ➤ ")}}
6+
//| {{ _class.name.join(" ➤ ")}}
7+
| #[span(v-if="depth > 0")] {{ _class.name.slice(depth).join(" ➤ ")}}
88
div.col-4.col-md-8
99
//span.d-none.d-sm-inline.d-md-none(:style="{ marginLeft: (2 * depth) + 'em'}")
1010
span.d-none.d-md-inline
11-
span(v-if="cls.rule.type === 'regex'") Rule ({{cls.rule.type}}): #[code {{cls.rule.regex}}]
11+
span(v-if="_class.rule.type === 'regex'") Rule ({{_class.rule.type}}): #[code {{_class.rule.regex}}]
1212
span(v-else, style="color: #888") No rule
1313
span.float-right
1414
b-btn.ml-1(size="sm", variant="outline-secondary", @click="showEditModal()" style="border: 0;" pill)
1515
icon(name="edit")
16-
b-btn.ml-1(size="sm", variant="outline-success", @click="addSubclass(cls)" style="border: 0;" pill)
16+
b-btn.ml-1(size="sm", variant="outline-success", @click="addSubclass(_class)" style="border: 0;" pill)
1717
icon(name="plus")
1818
div
19-
div.pa-2(v-for="child in cls.children", style="background: rgba(0, 0, 0, 0);", v-show="expanded")
20-
CategoryEditTree(:cls="child", :depth="depth+1")
19+
div.pa-2(v-for="child in _class.children", style="background: rgba(0, 0, 0, 0);", v-show="expanded")
20+
CategoryEditTree(:_class="child", :depth="depth+1")
2121

2222
b-modal(id="edit" ref="edit" title="Edit category" @show="resetModal" @hidden="resetModal" @ok="handleOk")
2323
div.my-1
@@ -41,7 +41,7 @@ div
4141
hr
4242

4343
div.my-1
44-
b-btn(variant="danger", @click="removeClass(cls); $refs.edit.hide()")
44+
b-btn(variant="danger", @click="removeClass(_class); $refs.edit.hide()")
4545
icon(name="trash")
4646
| Remove category
4747
</template>
@@ -57,7 +57,7 @@ import 'vue-awesome/icons/edit';
5757
export default {
5858
name: 'CategoryEditTree',
5959
props: {
60-
cls: Object,
60+
_class: Object,
6161
depth: {
6262
type: Number,
6363
default: 0,
@@ -97,11 +97,11 @@ export default {
9797
rule: { type: 'regex', regex: 'FILL ME' },
9898
});
9999
},
100-
removeClass: function(cls) {
100+
removeClass: function(_class) {
101101
// TODO: Show a confirmation dialog
102102
// TODO: Remove children as well?
103103
// TODO: Move button to edit modal?
104-
this.$store.commit('settings/removeClass', cls);
104+
this.$store.commit('settings/removeClass', _class);
105105
},
106106
showEditModal() {
107107
this.$refs.edit.show();
@@ -137,10 +137,10 @@ export default {
137137
},
138138
resetModal() {
139139
this.editing = {
140-
id: this.cls.id,
141-
name: this.cls.subname,
142-
rule: _.cloneDeep(this.cls.rule),
143-
parent: this.cls.parent ? this.cls.parent : [],
140+
id: this._class.id,
141+
name: this._class.subname,
142+
rule: _.cloneDeep(this._class.rule),
143+
parent: this._class.parent ? this._class.parent : [],
144144
};
145145
//console.log(this.editing);
146146
},
@@ -149,7 +149,7 @@ export default {
149149
</script>
150150

151151
<style scoped lang="scss">
152-
.row.cls:hover {
152+
.row.class:hover {
153153
background-color: #eee;
154154
boder-radius: 5px;
155155
}

src/route.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const Bucket = () => import('./views/Bucket.vue');
1515
const QueryExplorer = () => import('./views/QueryExplorer.vue');
1616
const Timeline = () => import('./views/Timeline.vue');
1717
const Log = () => import('./views/Log.vue');
18-
const Settings = () => import('./views/Settings.vue');
18+
const Settings = () => import('./views/settings/Settings.vue');
1919
const Stopwatch = () => import('./views/Stopwatch.vue');
2020
const Dev = () => import('./views/Dev.vue');
2121

Lines changed: 4 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,5 @@
11
<template lang="pug">
22
div
3-
h3 Settings
4-
5-
b-alert(variant="warning", show) #[b Note:] These settings are only saved in your browser and will not remain if you switch browser. We are working on getting this fixed.
6-
7-
hr
8-
9-
div.row
10-
div.col-sm-9
11-
h5.mb-0 Start of day
12-
small
13-
| The time at which days "start", since humans don't always go to bed before midnight. Set to 04:00 by default.
14-
div.col-sm-3
15-
input.form-control(type="time" :value="startOfDay" @change="setStartOfDay($event.target.value)")
16-
17-
hr
18-
19-
div.row
20-
div.col-sm-9
21-
h5.mb-0 Duration default value
22-
small
23-
| The default duration used for 'show last' in the timeline view
24-
div.col-sm-3
25-
select(id="durationDefaultValue" :value="durationDefaultValue", @change="setDurationDefault($event.target.value)")
26-
option(:value="15*60") 15min
27-
option(:value="30*60") 30min
28-
option(:value="60*60") 1h
29-
option(:value="2*60*60") 2h
30-
option(:value="4*60*60") 4h
31-
option(:value="6*60*60") 6h
32-
option(:value="12*60*60") 12h
33-
option(:value="24*60*60") 24h
34-
hr
35-
363
h5.d-inline-block
374
div Categorization
385
div.float-right
@@ -49,8 +16,8 @@ div
4916
| Save
5017
b-btn.ml-2(@click="resetClasses", variant="warning" size="sm")
5118
| Discard
52-
div(v-for="cls in classes_hierarchy")
53-
CategoryEditTree(:cls="cls")
19+
div(v-for="_class in classes_hierarchy")
20+
CategoryEditTree(:_class="_class")
5421

5522
div.row
5623
div.col-sm-12
@@ -60,34 +27,23 @@ div
6027
b-btn.float-right(@click="saveClasses", variant="success" :disabled="!classes_unsaved_changes")
6128
| Save
6229
</template>
63-
6430
<script>
65-
import CategoryEditTree from '~/components/CategoryEditTree.vue';
6631
import { mapState, mapGetters } from 'vuex';
32+
import CategoryEditTree from '~/components/CategoryEditTree.vue';
6733
6834
export default {
69-
name: 'Settings',
35+
name: 'CategorizationSettings',
7036
components: {
7137
CategoryEditTree,
7238
},
73-
data: () => {
74-
return {
75-
startOfDay: '',
76-
durationDefaultValue: localStorage.durationDefault || 60 * 60,
77-
};
78-
},
7939
computed: {
8040
...mapGetters('settings', ['classes_hierarchy']),
8141
...mapState('settings', ['classes_unsaved_changes']),
8242
},
8343
mounted() {
84-
this.startOfDay = localStorage.startOfDay;
8544
this.$store.dispatch('settings/load');
8645
},
8746
methods: {
88-
setStartOfDay: function(time_minutes) {
89-
localStorage.startOfDay = time_minutes;
90-
},
9147
addClass: function() {
9248
this.$store.commit('settings/addClass', {
9349
name: ['New class'],
@@ -103,9 +59,6 @@ export default {
10359
restoreDefaultClasses: async function() {
10460
await this.$store.commit('settings/restoreDefaultClasses');
10561
},
106-
setDurationDefault: function(duration) {
107-
localStorage.durationDefault = duration;
108-
},
10962
},
11063
};
11164
</script>
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<template lang="pug">
2+
div.row
3+
div.col-sm-9
4+
h5.mb-0 Start of day
5+
small
6+
| The time at which days "start", since humans don't always go to bed before midnight. Set to 04:00 by default.
7+
div.col-sm-3
8+
input.form-control(type="time" :value="startOfDay" @change="setStartOfDay($event.target.value)")
9+
</template>
10+
<script>
11+
export default {
12+
name: 'DaystartSettings',
13+
data: () => {
14+
return {
15+
startOfDay: '',
16+
};
17+
},
18+
mounted() {
19+
this.startOfDay = localStorage.startOfDay;
20+
},
21+
methods: {
22+
setStartOfDay: function(time_minutes) {
23+
localStorage.startOfDay = time_minutes;
24+
console.log('Set start of day to ' + time_minutes);
25+
},
26+
},
27+
};
28+
</script>

src/views/settings/Settings.vue

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<template lang="pug">
2+
div
3+
h3 Settings
4+
5+
b-alert(variant="warning", show) #[b Note:] These settings are only saved in your browser and will not remain if you switch browser. We are working on getting this fixed.
6+
7+
hr
8+
9+
DaystartSettings
10+
11+
hr
12+
13+
TimelineDurationSettings
14+
15+
hr
16+
17+
CategorizationSettings
18+
19+
</template>
20+
21+
<script>
22+
import DaystartSettings from '~/views/settings/DaystartSettings.vue';
23+
import TimelineDurationSettings from '~/views/settings/TimelineDurationSettings.vue';
24+
import CategorizationSettings from '~/views/settings/CategorizationSettings.vue';
25+
26+
export default {
27+
name: 'Settings',
28+
components: {
29+
DaystartSettings,
30+
TimelineDurationSettings,
31+
CategorizationSettings,
32+
},
33+
};
34+
</script>
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<template lang="pug">
2+
div.row
3+
div.col-sm-9
4+
h5.mb-0 Duration default value
5+
small
6+
| The default duration used for 'show last' in the timeline view
7+
div.col-sm-3
8+
select(id="durationDefaultValue" :value="durationDefaultValue", @change="setDurationDefault($event.target.value)")
9+
option(:value="15*60") 15min
10+
option(:value="30*60") 30min
11+
option(:value="60*60") 1h
12+
option(:value="2*60*60") 2h
13+
option(:value="4*60*60") 4h
14+
option(:value="6*60*60") 6h
15+
option(:value="12*60*60") 12h
16+
option(:value="24*60*60") 24h
17+
</template>
18+
<script>
19+
export default {
20+
name: 'TimelineDurationSettings',
21+
data: () => {
22+
return {
23+
durationDefaultValue: localStorage.durationDefault || 60 * 60,
24+
};
25+
},
26+
mounted() {
27+
this.startOfDay = localStorage.startOfDay;
28+
},
29+
methods: {
30+
setDurationDefault: function(duration) {
31+
localStorage.durationDefault = duration;
32+
console.log('Set default timeline duration to ' + duration);
33+
},
34+
},
35+
};
36+
</script>

0 commit comments

Comments
 (0)