Skip to content

Commit

Permalink
feat: filter timesheet by status
Browse files Browse the repository at this point in the history
  • Loading branch information
YejunWu168 committed Jul 2, 2021
1 parent 9d176f9 commit 065f851
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 3 deletions.
43 changes: 41 additions & 2 deletions pages/timesheets/index.vue
Original file line number Diff line number Diff line change
@@ -1,12 +1,27 @@
<template>
<div class="page-wrapper">
<div class="content-wrapper my-5">
<div class="my-5 content-wrapper">
<b-form-group
label="Filter by:"
label-for="filter-select"
label-class="font-weight-bold"
class="filter"
>
<b-form-select id="filter-select" v-model="selected" :options="options" class="filter__select">
<template #first>
<b-form-select-option :value="null">
All
</b-form-select-option>
</template>
</b-form-select>
</b-form-group>
<b-table
class="mt-3 app-table timesheet-table"
responsive
:items="tableData.items"
:fields="tableData.fields"
:sort-compare="sortCompare"
:filter="filter"
sort-by="id"
no-sort-reset
>
Expand Down Expand Up @@ -44,13 +59,15 @@

<script lang="ts">
import {
ref,
computed,
defineComponent,
useRouter,
useStore,
} from "@nuxtjs/composition-api";
import { recordStatus } from "~/helpers/record-status";
import { TimesheetStatus } from "~/types/enums.ts";
export default defineComponent({
middleware: ["isAdmin"],
Expand All @@ -62,6 +79,15 @@ export default defineComponent({
setup() {
const store = useStore<RootStoreState>();
const options = Object.entries(TimesheetStatus).map(([value, text]) => ({
value,
text,
})).sort((a, b) => a.text.localeCompare(b.text))
const selected = ref(null);
const getSelected = computed(() => selected.value);
const weeksBefore = 6;
const weeksAfter = 2;
Expand All @@ -88,8 +114,11 @@ export default defineComponent({
return a.name.localeCompare(b.name);
}
};
return {
options,
selected,
filter: getSelected,
recordStatus,
openEmployeeTimesheetPage,
tableData,
Expand All @@ -100,6 +129,16 @@ export default defineComponent({
</script>

<style lang="scss">
.filter {
&__select {
text-transform: capitalize;
}
@media (min-width: 576px) {
width: 25%;
}
}
.timesheet-table > .table.b-table > thead > tr > .table-b-table-default,
.timesheet-table > .table.b-table > thead > tr > th {
background: var(--color-primary);
Expand Down
7 changes: 7 additions & 0 deletions types/enums.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export enum TimesheetStatus {
NEW = "new",
PENDING = "pending",
APPROVED = "approved",
DENIED = "denied",
EMPTY = "empty",
}
1 change: 0 additions & 1 deletion types/timesheets.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ declare enum TimesheetStatus {
DENIED = "denied",
EMPTY = "empty",
}

interface TimesheetEmployee extends Employee {
status: TimesheetStatus;
pendingTimeRecords: TimeRecord[];
Expand Down

0 comments on commit 065f851

Please sign in to comment.