Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added dialog to hide columns #67

Merged
merged 2 commits into from
Mar 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions frontend/components/ColumnDialog.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<template>
<v-dialog v-model="showDialog" max-width="400px" @keydown.esc="closeDialog">
<v-card>
<v-card-title> Hidden Columns </v-card-title>
<v-card-text>
<v-form ref="formRef">
<v-list-item v-for="c in activeColumns" :key="c.value">
<v-list-item-content>
<v-list-item-title> {{ c.text }} </v-list-item-title>
</v-list-item-content>
<v-list-item-action>
<v-checkbox v-model="hiddenColumnsBuffer" :value="c.value" />
</v-list-item-action>
</v-list-item>
</v-form>
</v-card-text>
</v-card>
</v-dialog>
</template>

<script lang="ts">
import {
computed,
defineComponent,
PropType,
ref,
useStore,
watch,
} from "@nuxtjs/composition-api";
import { accessorType } from "../store";

export default defineComponent({
props: {
value: Boolean,
activeColumns: {
type: Array as PropType<Array<{ text: string; value: string }>>,
required: true,
},
},

setup(props, ctx) {
const store = useStore<typeof accessorType>();

const showDialog = computed({
get: () => props.value,
set: (val) => ctx.emit("input", val),
});

const closeDialog = () => {
showDialog.value = false;
};
const hiddenColumnsBuffer = ref([...store.state.hiddenColumns]);
watch(hiddenColumnsBuffer, (v) => {
store.dispatch("updateHiddenColumns", v);
});

return {
hiddenColumnsBuffer,
showDialog,
closeDialog,
};
},
});
</script>
26 changes: 23 additions & 3 deletions frontend/components/TaskList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
@yes="confirmation.handler"
/>
<TaskDialog v-model="showTaskDialog" :task="currentTask || undefined" />

<ColumnDialog v-model="showColumnDialog" :active-columns="headers"/>
<v-row class="px-4 pt-4">
<v-btn-toggle v-model="status" mandatory background-color="rgba(0, 0, 0, 0)">
<v-row class="pa-3">
Expand Down Expand Up @@ -40,7 +40,7 @@
<v-row class="px-4 pt-4">
<v-data-table
:items="classifiedTasks[status]"
:headers="headers"
:headers="filteredHeaders"
show-select
item-key="uuid"
:item-class="rowClass"
Expand Down Expand Up @@ -110,6 +110,16 @@
>
<v-icon>mdi-plus</v-icon>
</v-btn>
<v-btn
class="primary ml-1"
fab
dark
small
title="Configure Columns"
@click="showColumnDialog = true"
>
<v-icon>mdi-cogs</v-icon>
</v-btn>
</div>
</v-row>
</template>
Expand Down Expand Up @@ -193,6 +203,7 @@ import { Task } from 'taskwarrior-lib';
import _ from 'lodash';
import TaskDialog from '../components/TaskDialog.vue';
import ConfirmationDialog from '../components/ConfirmationDialog.vue';
import ColumnDialog from '../components/ColumnDialog.vue';
import moment from 'moment';
import urlRegex from 'url-regex-safe';
import normalizeUrl from 'normalize-url';
Expand Down Expand Up @@ -293,6 +304,12 @@ export default defineComponent({
{ text: 'Actions', value: 'actions', sortable: false }
]);

const filteredHeaders = computed(()=>
headers.value.filter((v)=> !store.state.hiddenColumns.includes(v.value))
)

const showColumnDialog = ref(false);

const tempTasks: { [key: string]: ComputedRef<Task[]> } = {};
for (const status of allStatus) {
tempTasks[status] = computed((): Task[] => props.tasks?.filter(task => {
Expand Down Expand Up @@ -393,6 +410,7 @@ export default defineComponent({
linkify,
refresh,
headers,
filteredHeaders,
classifiedTasks,
status,
allStatus,
Expand All @@ -406,12 +424,14 @@ export default defineComponent({
restoreTasks,
showTaskDialog,
showConfirmationDialog,
showColumnDialog,
confirmation,
displayDate,
rowClass,

TaskDialog,
ConfirmationDialog
ConfirmationDialog,
ColumnDialog,
};
}
});
Expand Down
1 change: 1 addition & 0 deletions frontend/layouts/default.vue
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export default defineComponent({
const context = useContext();
const store = useStore<typeof accessorType>();
store.dispatch('fetchSettings');
store.dispatch('fetchHiddenColumns');

context.$vuetify.theme.dark = store.state.settings.dark;

Expand Down
19 changes: 18 additions & 1 deletion frontend/store/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ export const state = () => ({
dark: false,
autoRefresh: '5', // in minutes
autoSync: '0' // in minutes
}
},
hiddenColumns: [] as string[]
});

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

setHiddenColumns(state, hiddenColumns) {
state.hiddenColumns = hiddenColumns
},

setNotification(state, notification) {
state.notification = notification;
// Show notification
Expand All @@ -58,6 +63,18 @@ export const actions: ActionTree<RootState, RootState> = {
localStorage.setItem('settings', JSON.stringify(settings));
},

fetchHiddenColumns(context) {
const columns = localStorage.getItem('hiddenColumns');
if (columns) {
context.commit('setHiddenColumns', JSON.parse(columns));
}
},

updateHiddenColumns(context, columns) {
context.commit('setHiddenColumns', columns);
localStorage.setItem('hiddenColumns', JSON.stringify(columns));
},

async fetchTasks(context) {
const tasks: Task[] = await this.$axios.$get('/api/tasks');
context.commit('setTasks', tasks);
Expand Down