Skip to content

Commit 35926f1

Browse files
authored
Merge pull request #67 from corrodedHash/hideColumns
Added dialog to hide columns
2 parents 3f5a9d6 + 32aa290 commit 35926f1

File tree

4 files changed

+106
-4
lines changed

4 files changed

+106
-4
lines changed
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<template>
2+
<v-dialog v-model="showDialog" max-width="400px" @keydown.esc="closeDialog">
3+
<v-card>
4+
<v-card-title> Hidden Columns </v-card-title>
5+
<v-card-text>
6+
<v-form ref="formRef">
7+
<v-list-item v-for="c in activeColumns" :key="c.value">
8+
<v-list-item-content>
9+
<v-list-item-title> {{ c.text }} </v-list-item-title>
10+
</v-list-item-content>
11+
<v-list-item-action>
12+
<v-checkbox v-model="hiddenColumnsBuffer" :value="c.value" />
13+
</v-list-item-action>
14+
</v-list-item>
15+
</v-form>
16+
</v-card-text>
17+
</v-card>
18+
</v-dialog>
19+
</template>
20+
21+
<script lang="ts">
22+
import {
23+
computed,
24+
defineComponent,
25+
PropType,
26+
ref,
27+
useStore,
28+
watch,
29+
} from "@nuxtjs/composition-api";
30+
import { accessorType } from "../store";
31+
32+
export default defineComponent({
33+
props: {
34+
value: Boolean,
35+
activeColumns: {
36+
type: Array as PropType<Array<{ text: string; value: string }>>,
37+
required: true,
38+
},
39+
},
40+
41+
setup(props, ctx) {
42+
const store = useStore<typeof accessorType>();
43+
44+
const showDialog = computed({
45+
get: () => props.value,
46+
set: (val) => ctx.emit("input", val),
47+
});
48+
49+
const closeDialog = () => {
50+
showDialog.value = false;
51+
};
52+
const hiddenColumnsBuffer = ref([...store.state.hiddenColumns]);
53+
watch(hiddenColumnsBuffer, (v) => {
54+
store.dispatch("updateHiddenColumns", v);
55+
});
56+
57+
return {
58+
hiddenColumnsBuffer,
59+
showDialog,
60+
closeDialog,
61+
};
62+
},
63+
});
64+
</script>

frontend/components/TaskList.vue

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
@yes="confirmation.handler"
88
/>
99
<TaskDialog v-model="showTaskDialog" :task="currentTask || undefined" />
10-
10+
<ColumnDialog v-model="showColumnDialog" :active-columns="headers"/>
1111
<v-row class="px-4 pt-4">
1212
<v-btn-toggle v-model="status" mandatory background-color="rgba(0, 0, 0, 0)">
1313
<v-row class="pa-3">
@@ -40,7 +40,7 @@
4040
<v-row class="px-4 pt-4">
4141
<v-data-table
4242
:items="classifiedTasks[status]"
43-
:headers="headers"
43+
:headers="filteredHeaders"
4444
show-select
4545
item-key="uuid"
4646
:item-class="rowClass"
@@ -110,6 +110,16 @@
110110
>
111111
<v-icon>mdi-plus</v-icon>
112112
</v-btn>
113+
<v-btn
114+
class="primary ml-1"
115+
fab
116+
dark
117+
small
118+
title="Configure Columns"
119+
@click="showColumnDialog = true"
120+
>
121+
<v-icon>mdi-cogs</v-icon>
122+
</v-btn>
113123
</div>
114124
</v-row>
115125
</template>
@@ -193,6 +203,7 @@ import { Task } from 'taskwarrior-lib';
193203
import _ from 'lodash';
194204
import TaskDialog from '../components/TaskDialog.vue';
195205
import ConfirmationDialog from '../components/ConfirmationDialog.vue';
206+
import ColumnDialog from '../components/ColumnDialog.vue';
196207
import moment from 'moment';
197208
import urlRegex from 'url-regex-safe';
198209
import normalizeUrl from 'normalize-url';
@@ -293,6 +304,12 @@ export default defineComponent({
293304
{ text: 'Actions', value: 'actions', sortable: false }
294305
]);
295306
307+
const filteredHeaders = computed(()=>
308+
headers.value.filter((v)=> !store.state.hiddenColumns.includes(v.value))
309+
)
310+
311+
const showColumnDialog = ref(false);
312+
296313
const tempTasks: { [key: string]: ComputedRef<Task[]> } = {};
297314
for (const status of allStatus) {
298315
tempTasks[status] = computed((): Task[] => props.tasks?.filter(task => {
@@ -393,6 +410,7 @@ export default defineComponent({
393410
linkify,
394411
refresh,
395412
headers,
413+
filteredHeaders,
396414
classifiedTasks,
397415
status,
398416
allStatus,
@@ -406,12 +424,14 @@ export default defineComponent({
406424
restoreTasks,
407425
showTaskDialog,
408426
showConfirmationDialog,
427+
showColumnDialog,
409428
confirmation,
410429
displayDate,
411430
rowClass,
412431
413432
TaskDialog,
414-
ConfirmationDialog
433+
ConfirmationDialog,
434+
ColumnDialog,
415435
};
416436
}
417437
});

frontend/layouts/default.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ export default defineComponent({
6060
const context = useContext();
6161
const store = useStore<typeof accessorType>();
6262
store.dispatch('fetchSettings');
63+
store.dispatch('fetchHiddenColumns');
6364
6465
context.$vuetify.theme.dark = store.state.settings.dark;
6566

frontend/store/index.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ export const state = () => ({
1313
dark: false,
1414
autoRefresh: '5', // in minutes
1515
autoSync: '0' // in minutes
16-
}
16+
},
17+
hiddenColumns: [] as string[]
1718
});
1819

1920
export type RootState = ReturnType<typeof state>;
@@ -34,6 +35,10 @@ export const mutations: MutationTree<RootState> = {
3435
state.tasks = tasks;
3536
},
3637

38+
setHiddenColumns(state, hiddenColumns) {
39+
state.hiddenColumns = hiddenColumns
40+
},
41+
3742
setNotification(state, notification) {
3843
state.notification = notification;
3944
// Show notification
@@ -58,6 +63,18 @@ export const actions: ActionTree<RootState, RootState> = {
5863
localStorage.setItem('settings', JSON.stringify(settings));
5964
},
6065

66+
fetchHiddenColumns(context) {
67+
const columns = localStorage.getItem('hiddenColumns');
68+
if (columns) {
69+
context.commit('setHiddenColumns', JSON.parse(columns));
70+
}
71+
},
72+
73+
updateHiddenColumns(context, columns) {
74+
context.commit('setHiddenColumns', columns);
75+
localStorage.setItem('hiddenColumns', JSON.stringify(columns));
76+
},
77+
6178
async fetchTasks(context) {
6279
const tasks: Task[] = await this.$axios.$get('/api/tasks');
6380
context.commit('setTasks', tasks);

0 commit comments

Comments
 (0)