From 3eafb413a48cde60dea8a7355ee621c6acca952f Mon Sep 17 00:00:00 2001 From: Doog <157747121+doogongithub@users.noreply.github.com> Date: Wed, 21 Feb 2024 22:07:27 -0500 Subject: first commit --- fe/src/lib/Card.svelte | 22 ++++++++++++++++++++++ fe/src/lib/Counter.svelte | 10 ++++++++++ fe/src/lib/Table.svelte | 41 +++++++++++++++++++++++++++++++++++++++++ fe/src/lib/errors.ts | 7 +++++++ fe/src/lib/utils.ts | 9 +++++++++ 5 files changed, 89 insertions(+) create mode 100644 fe/src/lib/Card.svelte create mode 100644 fe/src/lib/Counter.svelte create mode 100644 fe/src/lib/Table.svelte create mode 100644 fe/src/lib/errors.ts create mode 100644 fe/src/lib/utils.ts (limited to 'fe/src/lib') diff --git a/fe/src/lib/Card.svelte b/fe/src/lib/Card.svelte new file mode 100644 index 0000000..feb5bcc --- /dev/null +++ b/fe/src/lib/Card.svelte @@ -0,0 +1,22 @@ + + +
+ {#if title} +

{title}

+ {/if} + +
+ + diff --git a/fe/src/lib/Counter.svelte b/fe/src/lib/Counter.svelte new file mode 100644 index 0000000..979b4df --- /dev/null +++ b/fe/src/lib/Counter.svelte @@ -0,0 +1,10 @@ + + + diff --git a/fe/src/lib/Table.svelte b/fe/src/lib/Table.svelte new file mode 100644 index 0000000..2df9f8c --- /dev/null +++ b/fe/src/lib/Table.svelte @@ -0,0 +1,41 @@ + + + {#if title} +

{title}

+ {/if} + {#if !noheader} + + + + + + {/if} + + + + + + {#if !nofooter} + + + + + + + + {/if} +
+ Data Header +
Data
Table Footer
+ diff --git a/fe/src/lib/errors.ts b/fe/src/lib/errors.ts new file mode 100644 index 0000000..0663d63 --- /dev/null +++ b/fe/src/lib/errors.ts @@ -0,0 +1,7 @@ +export class UnauthorizedError extends Error { + constructor (message?: string , options?: ErrorOptions) { + super(message, options); + } +} + + diff --git a/fe/src/lib/utils.ts b/fe/src/lib/utils.ts new file mode 100644 index 0000000..c5501ae --- /dev/null +++ b/fe/src/lib/utils.ts @@ -0,0 +1,9 @@ +export function processFormInput(form) { + const formData = new FormData(form); + const data = {}; + for (let field of formData) { + const [key, value] = field; + data[key] = value; + } + return data; +} -- cgit v1.1 From e37c73e33a4aaf7fb8d25b5af03627f20bcda19f Mon Sep 17 00:00:00 2001 From: Doog <157747121+doogongithub@users.noreply.github.com> Date: Sat, 24 Feb 2024 20:08:35 -0500 Subject: add gitignore --- fe/src/lib/DataView.svelte | 67 +++++++++++++++++++++++++++++++++++++++++++++ fe/src/lib/Layout.svelte | 57 ++++++++++++++++++++++++++++++++++++++ fe/src/lib/LoginForm.svelte | 64 +++++++++++++++++++++++++++++++++++++++++++ fe/src/lib/Table.svelte | 61 +++++++++++++++++++++++++++++++++++------ 4 files changed, 241 insertions(+), 8 deletions(-) create mode 100644 fe/src/lib/DataView.svelte create mode 100644 fe/src/lib/Layout.svelte create mode 100644 fe/src/lib/LoginForm.svelte (limited to 'fe/src/lib') diff --git a/fe/src/lib/DataView.svelte b/fe/src/lib/DataView.svelte new file mode 100644 index 0000000..cd7b042 --- /dev/null +++ b/fe/src/lib/DataView.svelte @@ -0,0 +1,67 @@ + +
+ + +
+ + + +
+
+ + {#await json then data} + + {:catch error} +

{error}

+ {/await} + + diff --git a/fe/src/lib/Layout.svelte b/fe/src/lib/Layout.svelte new file mode 100644 index 0000000..f349632 --- /dev/null +++ b/fe/src/lib/Layout.svelte @@ -0,0 +1,57 @@ + + +
+ {#if $authenticated} + + {/if} +
+ +
+
+ + diff --git a/fe/src/lib/LoginForm.svelte b/fe/src/lib/LoginForm.svelte new file mode 100644 index 0000000..22c0faf --- /dev/null +++ b/fe/src/lib/LoginForm.svelte @@ -0,0 +1,64 @@ + + + +
+
+ + +
+
+ + +
+ {#if error} +

{error}

+ {/if} + + +
diff --git a/fe/src/lib/Table.svelte b/fe/src/lib/Table.svelte index 2df9f8c..5572280 100644 --- a/fe/src/lib/Table.svelte +++ b/fe/src/lib/Table.svelte @@ -1,8 +1,38 @@
{#if title} @@ -11,16 +41,27 @@ {#if !noheader} - + {#each getDataKeys(data) as header} + + {/each} {/if} + {#if data} + {#each data as row} - + {#each getRow(row) as datum} + + + {/each} + {/each} + {:else} + + There is not data. + + {/if} {#if !nofooter} @@ -38,4 +79,8 @@ table { margin: 8px; border: solid 1px black; } + +th { + text-transform: capitalize; +} -- cgit v1.1 From 9f9a33cbf55d38987a66b709284d2bb4ffea0fe9 Mon Sep 17 00:00:00 2001 From: Doog <157747121+doogongithub@users.noreply.github.com> Date: Thu, 29 Feb 2024 20:13:48 -0500 Subject: modify api, build additional FE components, add types --- fe/src/lib/DataView.svelte | 67 ++++++++++++++++++++++++++++++++++++--- fe/src/lib/LoginForm.svelte | 16 ++++++---- fe/src/lib/PreferencesForm.svelte | 45 ++++++++++++++++++++++++++ fe/src/lib/Table.svelte | 19 +++++++++++ 4 files changed, 136 insertions(+), 11 deletions(-) create mode 100644 fe/src/lib/PreferencesForm.svelte (limited to 'fe/src/lib') diff --git a/fe/src/lib/DataView.svelte b/fe/src/lib/DataView.svelte index cd7b042..dc8acae 100644 --- a/fe/src/lib/DataView.svelte +++ b/fe/src/lib/DataView.svelte @@ -1,11 +1,24 @@
+ +

Add Water

- - +
+ + +
+
+ + +
+
@@ -65,3 +112,15 @@ onMount(() => { {/await}
+ + diff --git a/fe/src/lib/LoginForm.svelte b/fe/src/lib/LoginForm.svelte index 22c0faf..499a457 100644 --- a/fe/src/lib/LoginForm.svelte +++ b/fe/src/lib/LoginForm.svelte @@ -1,8 +1,8 @@ + +

User Preferences

+
+
+ + +
+
+ + +
+ + +
+ diff --git a/fe/src/lib/Table.svelte b/fe/src/lib/Table.svelte index 5572280..4b81800 100644 --- a/fe/src/lib/Table.svelte +++ b/fe/src/lib/Table.svelte @@ -30,6 +30,11 @@ function formatDatum([key, value]: any[]) { const parsedDate = new Date(value); return formatter.format(parsedDate); } + + if (key === 'user') { + return value['name']; + } + return value; } @@ -78,9 +83,23 @@ table { padding: 16px; margin: 8px; border: solid 1px black; + border-collapse: collapse; } th { text-transform: capitalize; } + +thead tr { + background: rgba(0,0,23, 0.34); +} + +tbody tr:nth-child(odd) { + background: rgba(0,0,23,0.14); +} + +th, td { + padding: 1em; + border: 1px solid rgba(0,0,0, 1); +} -- cgit v1.1 From afeffe31bd7d0f8333627a972e1d32e64a325b5b Mon Sep 17 00:00:00 2001 From: Zach Berwaldt Date: Fri, 1 Mar 2024 18:17:42 -0500 Subject: reformat fe --- fe/src/lib/Card.svelte | 14 +-- fe/src/lib/Counter.svelte | 10 --- fe/src/lib/DataView.svelte | 177 +++++++++++++++++++------------------- fe/src/lib/Layout.svelte | 77 +++++++++-------- fe/src/lib/LoginForm.svelte | 105 +++++++++++++--------- fe/src/lib/PreferencesForm.svelte | 32 ++++--- fe/src/lib/Table.svelte | 138 ++++++++++++++--------------- fe/src/lib/errors.ts | 6 +- fe/src/lib/utils.ts | 16 ++-- 9 files changed, 296 insertions(+), 279 deletions(-) delete mode 100644 fe/src/lib/Counter.svelte (limited to 'fe/src/lib') diff --git a/fe/src/lib/Card.svelte b/fe/src/lib/Card.svelte index feb5bcc..0835940 100644 --- a/fe/src/lib/Card.svelte +++ b/fe/src/lib/Card.svelte @@ -1,16 +1,16 @@
- {#if title} -

{title}

- {/if} - + {#if title} +

{title}

+ {/if} +
diff --git a/fe/src/lib/Counter.svelte b/fe/src/lib/Counter.svelte deleted file mode 100644 index 979b4df..0000000 --- a/fe/src/lib/Counter.svelte +++ /dev/null @@ -1,10 +0,0 @@ - - - diff --git a/fe/src/lib/DataView.svelte b/fe/src/lib/DataView.svelte index dc8acae..1458c9a 100644 --- a/fe/src/lib/DataView.svelte +++ b/fe/src/lib/DataView.svelte @@ -1,126 +1,123 @@ - +
- - - -

Add Water

-
-
- - -
-
- - -
- - - -
- - {#await json then data} -
- Data Header - {header}
Data{formatDatum(datum)}
- {:catch error} -

{error}

- {/await} - + + +

Add Water

+
+
+ + +
+
+ + +
+ + + +
+ + {#await json then data} +
+ {:catch error} +

{error}

+ {/await} + diff --git a/fe/src/lib/Layout.svelte b/fe/src/lib/Layout.svelte index f349632..94ce84d 100644 --- a/fe/src/lib/Layout.svelte +++ b/fe/src/lib/Layout.svelte @@ -1,57 +1,62 @@
- {#if $authenticated} + {#if $authenticated} - {/if} -
- -
+ + {/if} +
+ +
diff --git a/fe/src/lib/LoginForm.svelte b/fe/src/lib/LoginForm.svelte index 499a457..bf6d9ad 100644 --- a/fe/src/lib/LoginForm.svelte +++ b/fe/src/lib/LoginForm.svelte @@ -1,66 +1,85 @@ - -
-
- - -
-
- - -
- {#if error} -

{error}

- {/if} - - +
+
+ + +
+
+ + +
+ {#if error} +

{error}

+ {/if} + +
diff --git a/fe/src/lib/PreferencesForm.svelte b/fe/src/lib/PreferencesForm.svelte index 781866c..95e04c1 100644 --- a/fe/src/lib/PreferencesForm.svelte +++ b/fe/src/lib/PreferencesForm.svelte @@ -1,7 +1,8 @@ - +

User Preferences

- - + +
- - + +
@@ -42,4 +43,9 @@ dialog { background: white; color: black; } + +input[type="color"] { + width: 100%; + height: 100%; +} diff --git a/fe/src/lib/Table.svelte b/fe/src/lib/Table.svelte index 4b81800..3a66e0d 100644 --- a/fe/src/lib/Table.svelte +++ b/fe/src/lib/Table.svelte @@ -1,105 +1,105 @@ +
- {#if title} + {#if title}

{title}

- {/if} - {#if !noheader} + {/if} + {#if !noheader && data} - - {#each getDataKeys(data) as header} - - {/each} - + + {#each getDataKeys(data) as header} + + {/each} + - {/if} - - {#if data} - {#each data as row} + {/if} + + {#if data} + {#each data as row} - {#each getRow(row) as datum} - + {#each getRow(row) as datum} - {/each} + {/each} - {/each} - {:else} - - There is not data. - - {/if} - - {#if !nofooter} + {/each} + {:else} + There is not data. + {/if} + + {#if !nofooter} - + - + - + - {/if} + {/if}
{header}
{header}
{formatDatum(datum)}
Table FooterTable Footer
+ diff --git a/fe/src/lib/errors.ts b/fe/src/lib/errors.ts index 0663d63..d44bec5 100644 --- a/fe/src/lib/errors.ts +++ b/fe/src/lib/errors.ts @@ -1,7 +1,7 @@ export class UnauthorizedError extends Error { - constructor (message?: string , options?: ErrorOptions) { - super(message, options); - } + constructor(message?: string, options?: ErrorOptions) { + super(message, options); + } } diff --git a/fe/src/lib/utils.ts b/fe/src/lib/utils.ts index c5501ae..22d4e9a 100644 --- a/fe/src/lib/utils.ts +++ b/fe/src/lib/utils.ts @@ -1,9 +1,9 @@ -export function processFormInput(form) { - const formData = new FormData(form); - const data = {}; - for (let field of formData) { - const [key, value] = field; - data[key] = value; - } - return data; +export function processFormInput(form: HTMLFormElement) { + const formData = new FormData(form); + const data: Record = {}; + for (let field of formData) { + const [key, value] = field; + data[key] = value; + } + return data; } -- cgit v1.1 From 74ec025991f6acde6383e448974738e857758ebb Mon Sep 17 00:00:00 2001 From: Zach Berwaldt Date: Fri, 1 Mar 2024 18:50:51 -0500 Subject: Add dependencies, refine dataview --- fe/src/lib/DataView.svelte | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) (limited to 'fe/src/lib') diff --git a/fe/src/lib/DataView.svelte b/fe/src/lib/DataView.svelte index 1458c9a..00ee21a 100644 --- a/fe/src/lib/DataView.svelte +++ b/fe/src/lib/DataView.svelte @@ -1,12 +1,16 @@ @@ -102,6 +126,7 @@ + {#await json then data} {:catch error} -- cgit v1.1 From d8b0f1335078d53d95a4212b1a4d4b0b28016702 Mon Sep 17 00:00:00 2001 From: Zach Berwaldt Date: Fri, 1 Mar 2024 20:12:21 -0500 Subject: feat(DataView): Add functionality to add water statistic This commit adds functionality to add water statistics to the DataView component. It includes the following changes: - Remove unused imports and variables - Move the 'handleClick' function logic to a new 'AddForm' component - Create the 'AddForm' component which displays a dialog with input fields for date and quantity and allows the user to add a new water statistic - Dispatch events on form submit and dialog close in the 'AddForm' component - Call the 'fetchData' function on successful submission of a new statistic - Update chart data to display sample data New component: - AddForm.svelte: A form component to add a new water statistic Note: This commit message exceeds the 50-character limit in the subject line, but adheres to the other specified requirements. --- fe/src/lib/DataView.svelte | 206 +++++++++++++++------------------------- fe/src/lib/forms/AddForm.svelte | 74 +++++++++++++++ 2 files changed, 148 insertions(+), 132 deletions(-) create mode 100644 fe/src/lib/forms/AddForm.svelte (limited to 'fe/src/lib') diff --git a/fe/src/lib/DataView.svelte b/fe/src/lib/DataView.svelte index 00ee21a..7f368c6 100644 --- a/fe/src/lib/DataView.svelte +++ b/fe/src/lib/DataView.svelte @@ -1,148 +1,90 @@
- - -

Add Water

-
-
- - -
-
- - -
- - - -
- - - {#await json then data} -
- {:catch error} -

{error}

- {/await} - + + + + {#await json then data} +
+ {:catch error} +

{error}

+ {/await} + diff --git a/fe/src/lib/forms/AddForm.svelte b/fe/src/lib/forms/AddForm.svelte new file mode 100644 index 0000000..f22e5f4 --- /dev/null +++ b/fe/src/lib/forms/AddForm.svelte @@ -0,0 +1,74 @@ + + + +

Add Water

+
+
+ + +
+
+ + +
+ + + +
\ No newline at end of file -- cgit v1.1 From 326f186d67017f87e631a1fbcdf3f184cbc42d7d Mon Sep 17 00:00:00 2001 From: Zach Berwaldt Date: Fri, 1 Mar 2024 20:26:42 -0500 Subject: feat: Add last seven days labels to chart In the `DataView.svelte` component, the last seven days are now included as labels in the chart. This allows users to easily visualize data for the past week. The `getLastSevenDays` function generates an array of string values representing the dates in ISO format. This array is assigned to the `lastSevenDays` variable, which is then used as the labels in the chart's dataset. --- fe/src/lib/DataView.svelte | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) (limited to 'fe/src/lib') diff --git a/fe/src/lib/DataView.svelte b/fe/src/lib/DataView.svelte index 7f368c6..5182a85 100644 --- a/fe/src/lib/DataView.svelte +++ b/fe/src/lib/DataView.svelte @@ -12,6 +12,8 @@ let canvasRef: HTMLCanvasElement; let chart: any; + let lastSevenDays: string[]; + async function fetchData() { const res = await fetch("http://localhost:8080/api/v1/stats/", { method: "GET", @@ -26,6 +28,16 @@ } } + function getLastSevenDays() { + const result = []; + for (let i = 0; i < 7; i++) { + let d = new Date(); + d.setDate(d.getDate() - i); + result.push(d.toISOString().substring(0, 10)); + } + return result; + } + function handleClick() { open = true; } @@ -41,14 +53,21 @@ onMount(() => { fetchData(); + lastSevenDays = getLastSevenDays(); chart = new Chart(canvasRef, { type: "bar", data: { - labels: ["one", "two"], + labels: lastSevenDays, datasets: [ { - label: "Water", - data: [1, 2], + label: "Zach", + data: [1, 2, 8, 2, 5, 5, 1], + backgroundColor: "rgba(255, 192, 192, 0.2)", + borderColor: "rgba(75, 192, 192, 1)", + borderWidth: 1 + }, { + label: "Parker", + data: [6, 1, 1, 4, 3, 5, 1], backgroundColor: "rgba(75, 192, 192, 0.2)", borderColor: "rgba(75, 192, 192, 1)", borderWidth: 1 @@ -66,8 +85,8 @@
- + {#await json then data}
{:catch error} -- cgit v1.1 From cf2113e77edabf8e3a632c7b76c769752039ba88 Mon Sep 17 00:00:00 2001 From: Zach Berwaldt Date: Sat, 2 Mar 2024 16:52:55 -0500 Subject: feat: Add API logging Add logging to the API to keep track of specific requests and headers. Also added CORS middleware to handle OPTIONS requests. --- The commit adds logging functionality to the API and includes a middleware function to handle CORS OPTIONS requests. This will allow us to track specific requests and headers received by the API. [API/main.go](/api/main.go): - Added import for the 'log' package - Added logging statements to print the request headers and "_I am here_" message - Removed unnecessary newlines and comments [fe/src/app.css](/fe/src/app.css): - Added a new style for button hover effects [fe/src/lib/Card.svelte](/fe/src/lib/Card.svelte): - Added a new `height` prop to the Card component [fe/src/lib/Column.svelte](/fe/src/lib/Column.svelte): - Added a new CSS class for column layout - Set the width and gap using CSS variables [fe/src/lib/DataView.svelte](/fe/src/lib/DataView.svelte): - Updated the 'fetchData' function to also fetch 'totals' and 'userStats' data - Added canvas references and chart variables for bar and line charts - Added a new 'getLastSevenDays' function to calculate the labels for the charts - Updated the 'onMount' function to initialize the bar and line charts using the canvas references and data - Updated the 'onDestroy' function to destroy the bar and line charts - Added a new 'addFormOpen' store and imported it - Added a new 'onClick' handler for the Add button to open the AddForm modal - Updated the layout and added Card components to display the bar and line charts and the JSON data - Added a new 'fetchTotals' function to fetch data for the 'totals' section - Added a new 'fetchStatsForUser' function to fetch data for the 'userStats' section [fe/src/lib/Layout.svelte](/fe/src/lib/Layout.svelte): - Added a new 'preferenceFormOpen' variable and initialized it to 'false' - Added a new 'showPreferencesDialog' function to set 'preferenceFormOpen' to 'true' - Added a new 'closePreferenceDialog' function to set 'preferenceFormOpen' to 'false' - Added a new 'showAddDialog' function to open the AddForm modal --- fe/src/lib/Card.svelte | 30 ++++---- fe/src/lib/Column.svelte | 13 ++++ fe/src/lib/DataView.svelte | 129 +++++++++++++++++++++++++++------- fe/src/lib/Layout.svelte | 116 ++++++++++++++++-------------- fe/src/lib/Table.svelte | 172 ++++++++++++++++++++++++--------------------- 5 files changed, 286 insertions(+), 174 deletions(-) create mode 100644 fe/src/lib/Column.svelte (limited to 'fe/src/lib') diff --git a/fe/src/lib/Card.svelte b/fe/src/lib/Card.svelte index 0835940..d7cd900 100644 --- a/fe/src/lib/Card.svelte +++ b/fe/src/lib/Card.svelte @@ -1,22 +1,24 @@
- {#if title} -

{title}

- {/if} - + {#if title} +

{title}

+ {/if} +
diff --git a/fe/src/lib/Column.svelte b/fe/src/lib/Column.svelte new file mode 100644 index 0000000..f036073 --- /dev/null +++ b/fe/src/lib/Column.svelte @@ -0,0 +1,13 @@ +
+ +
+ + \ No newline at end of file diff --git a/fe/src/lib/DataView.svelte b/fe/src/lib/DataView.svelte index 5182a85..2b1b8b9 100644 --- a/fe/src/lib/DataView.svelte +++ b/fe/src/lib/DataView.svelte @@ -1,16 +1,21 @@ -
- - - - {#await json then data} -
- {:catch error} -

{error}

- {/await} - - + + + + + + + + + + + + + {#await json then data} +
+ {:catch error} +

{error}

+ {/await} + + + + {#await totals then data} + {JSON.stringify(data)} + {:catch error} +

{error}

+ {/await} +
+ + + diff --git a/fe/src/lib/Table.svelte b/fe/src/lib/Table.svelte index 3a66e0d..d1cd7da 100644 --- a/fe/src/lib/Table.svelte +++ b/fe/src/lib/Table.svelte @@ -1,105 +1,113 @@
- {#if title} -

{title}

- {/if} - {#if !noheader && data} - - - {#each getDataKeys(data) as header} - - {/each} - - - {/if} - - {#if data} - {#each data as row} + {#if title} +

{title}

+ {/if} + {#if !noheader && data} + - {#each getRow(row) as datum} - - {/each} + {#each getDataKeys(data) as header} + + {/each} - {/each} + + {/if} + + {#if data} + {#each limitedData as row} + + {#each getRow(row) as datum} + + {/each} + + {/each} {:else} - There is not data. + There is not data. + {/if} + + {#if !nofooter} + + + + + + + {/if} - - {#if !nofooter} - - - - - - - - {/if}
{header}
{formatDatum(datum)}{header}
{formatDatum(datum)}
Table Footer
Table Footer
-- cgit v1.1 From 5fa57845052655883120ba4d19a85d8756fb8d8c Mon Sep 17 00:00:00 2001 From: Zach Berwaldt Date: Wed, 6 Mar 2024 21:53:07 -0500 Subject: [FEAT] Refactor API main file and models This commit refactors the `main.go` file in the API directory, as well as the related models in the `models.go` file. The changes include: - Reordering imports and removing unnecessary imports - Fixing error messages to be more descriptive - Handling database connections more efficiently with deferred closures - Handling errors and returning appropriate error responses - Adding proper JSON bindings for POST requests - Adding new views in the database scripts for aggregated statistics and daily user statistics No changes were made to imports and requires. --- fe/src/lib/DataView.svelte | 130 +++++++++++++++++++++------------------- fe/src/lib/forms/AddForm.svelte | 13 ++-- 2 files changed, 77 insertions(+), 66 deletions(-) (limited to 'fe/src/lib') diff --git a/fe/src/lib/DataView.svelte b/fe/src/lib/DataView.svelte index 2b1b8b9..7d62a43 100644 --- a/fe/src/lib/DataView.svelte +++ b/fe/src/lib/DataView.svelte @@ -9,8 +9,6 @@ import AddForm from "./forms/AddForm.svelte"; let json: Promise; - let totals: Promise; - let userStats: Promise; let barCanvasRef: HTMLCanvasElement; let lineCanvasRef: HTMLCanvasElement; @@ -18,6 +16,10 @@ let lineChart: any; let lastSevenDays: string[]; + let lastSevenDaysData: number[]; + + let userTotalsLabels: string[]; + let userTotalsData: number[]; async function fetchData() { const res = await fetch("http://localhost:8080/api/v1/stats/", { @@ -33,24 +35,27 @@ } } - async function fetchTotals() { + async function fetchDailyUserStatistics() { const res = await fetch("http://localhost:8080/api/v1/stats/totals/", { - method: 'GET', - mode: 'no-cors', + method: "GET", headers: { Authorization: `Bearer ${$token}` } }); if (res.ok) { - totals = res.json(); + const json = await res.json(); + let labels = json.map(d => d.name); + let data = json.map(d => d.total); + return [labels, data]; } else { throw new Error("There was a problem with your request"); } + } - async function fetchStatsForUser() { - const res = await fetch("http://localhost:8080/api/v1/stats/user/1aa668f3-7527-4a67-9c24-fdf307542eeb", { + async function fetchWeeklyTotals() { + const res = await fetch("http://localhost:8080/api/v1/stats/weekly/", { method: "GET", headers: { Authorization: `Bearer ${$token}` @@ -58,22 +63,15 @@ }); if (res.ok) { - userStats = res.json(); + const json = await res.json(); + let labels = json.map(d => d.date); + let data = json.map(d => d.total); + return [labels, data]; } else { throw new Error("There was a problem with your request"); } } - function getLastSevenDays() { - const result = []; - for (let i = 0; i < 7; i++) { - let d = new Date(); - d.setDate(d.getDate() - i); - result.push(d.toISOString().substring(0, 10)); - } - return result; - } - function closeDialog() { addFormOpen.set(false); } @@ -81,61 +79,79 @@ function onStatisticAdd() { closeDialog(); fetchData(); + fetchWeeklyTotals().then(updateWeeklyTotalsChart).catch(err => console.error(err)); + fetchDailyUserStatistics().then(updateDailyUserTotalsChart).catch(err => console.error(err)); } - onMount(() => { - fetchData(); -// fetchTotals(); - fetchStatsForUser(); - lastSevenDays = getLastSevenDays(); - barChart = new Chart(barCanvasRef, { - type: "bar", + function setupWeeklyTotalsChart(result) { + [lastSevenDays, lastSevenDaysData] = result; + lineChart = new Chart(lineCanvasRef, { + type: "line", data: { labels: lastSevenDays, datasets: [ { - label: "Zach", - data: [1, 2, 8, 2, 5, 5, 1], - backgroundColor: "rgba(255, 192, 192, 0.2)", - borderColor: "rgba(75, 192, 192, 1)", - borderWidth: 1 - }, { - label: "Parker", - data: [6, 1, 1, 4, 3, 5, 1], - backgroundColor: "rgba(75, 192, 192, 0.2)", - borderColor: "rgba(75, 192, 192, 1)", - borderWidth: 1 + label: "Totals", + data: lastSevenDaysData, + backgroundColor: "rgba(255, 192, 192, 0.2)" } ] }, options: { - responsive: true + responsive: true, + plugins: { + legend: { + display: false + } + } } }); - lineChart = new Chart(lineCanvasRef, { - type: "line", + } + + function setupDailyUserTotalsChart(result) { + [userTotalsLabels, userTotalsData] = result; + + barChart = new Chart(barCanvasRef, { + type: "bar", data: { - labels: lastSevenDays, + labels: userTotalsLabels, datasets: [ { - label: "Zach", - data: [1, 2, 8, 2, 5, 5, 1], - backgroundColor: "rgba(255, 192, 192, 0.2)", - borderColor: "rgba(75, 192, 192, 1)", - borderWidth: 1 - }, { - label: "Parker", - data: [6, 1, 1, 4, 3, 5, 1], - backgroundColor: "rgba(75, 192, 192, 0.2)", - borderColor: "rgba(75, 192, 192, 1)", - borderWidth: 1 + data: userTotalsData, + backgroundColor: [ + "#330000", + "rgba(100, 200, 192, 0.2)" + ] } ] }, options: { - responsive: true + responsive: true, + plugins: { + legend: { + display: false + } + } } }); + } + + function updateWeeklyTotalsChart(result) { + [,lastSevenDaysData] = result; + lineChart.data.datasets[0].data = lastSevenDaysData; + lineChart.update(); + } + + function updateDailyUserTotalsChart(result) { + [,userTotalsData] = result; + barChart.data.datasets[0].data = userTotalsData; + barChart.update(); + } + + onMount(() => { + fetchData(); + fetchWeeklyTotals().then(setupWeeklyTotalsChart); + fetchDailyUserStatistics().then(setupDailyUserTotalsChart); }); onDestroy(() => { @@ -164,14 +180,6 @@

{error}

{/await} - - - {#await totals then data} - {JSON.stringify(data)} - {:catch error} -

{error}

- {/await} -
diff --git a/fe/src/lib/forms/AddForm.svelte b/fe/src/lib/forms/AddForm.svelte index f22e5f4..4520b1b 100644 --- a/fe/src/lib/forms/AddForm.svelte +++ b/fe/src/lib/forms/AddForm.svelte @@ -34,20 +34,23 @@ dispatch("close"); } - async function handleSubmitStat() { - const response = await fetch("http://localhost:8080/api/v1/stats/", { + async function handleSubmitStat() + { + const { date, quantity } = statistic; + await fetch("http://localhost:8080/api/v1/stats/", { method: "POST", headers: { Authorization: `Bearer ${$token}` }, body: JSON.stringify({ - date: new Date(), - user_id: 1, - quantity: 3 + date: new Date(date), + user_id: 2, + quantity }) }); dispatch("submit"); } + -- cgit v1.1 From 8fab2d03bce82e4dee798ebffb1e93c557f62a4b Mon Sep 17 00:00:00 2001 From: Zach Berwaldt Date: Thu, 7 Mar 2024 23:16:22 -0500 Subject: feat: Update authentication route and add comments to exported members - The authentication route in the API has been updated to use a new router setup function. - Comments have been added to all exported members of the `auth.go` module in the internal controllers package. --- fe/src/lib/DataView.svelte | 53 ++++++++++++++++++++++++++++++++++++++++------ fe/src/lib/Table.svelte | 13 ++++++------ 2 files changed, 54 insertions(+), 12 deletions(-) (limited to 'fe/src/lib') diff --git a/fe/src/lib/DataView.svelte b/fe/src/lib/DataView.svelte index 7d62a43..0a6b81b 100644 --- a/fe/src/lib/DataView.svelte +++ b/fe/src/lib/DataView.svelte @@ -1,5 +1,6 @@ - - + + - + diff --git a/fe/src/lib/Table.svelte b/fe/src/lib/Table.svelte index d1cd7da..621157e 100644 --- a/fe/src/lib/Table.svelte +++ b/fe/src/lib/Table.svelte @@ -5,6 +5,10 @@ export let omit: string[] = ["id"]; export let title: string | undefined = undefined; + export let sortBy: string = 'date'; + + type SortComparator = (a, b) => number + function getDataKeys(data: any[]): string[] { if (!data || data.length === 0) return []; return Object.keys(data[0]) @@ -16,11 +20,8 @@ return Object.entries(row).filter((r) => !omit.includes(r[0])); } - - let limitedData: Array = []; - - if (data && (data as any[]).length > 0) { - limitedData = (data as any[]).slice(0, 4); + function sort(arr: Array>, fn: SortComparator = (a , b) => new Date(b[sortBy]) - new Date(a[sortBy])) { + return arr.sort(fn) } const formatter = new Intl.DateTimeFormat("en", { @@ -62,7 +63,7 @@ {/if} {#if data} - {#each limitedData as row} + {#each sort(data) as row} {#each getRow(row) as datum} {formatDatum(datum)} -- cgit v1.1 From 9cae9c1d2a0b4f7fa72f3075541b9ffafe1a7275 Mon Sep 17 00:00:00 2001 From: Zach Berwaldt Date: Fri, 15 Mar 2024 18:49:43 -0400 Subject: Add routes for preference, clean up and add types --- fe/src/lib/Card.svelte | 1 - fe/src/lib/Chart.svelte | 63 +++++++++++++++++ fe/src/lib/DataView.svelte | 40 ++++------- fe/src/lib/Layout.svelte | 8 ++- fe/src/lib/LoginForm.svelte | 2 +- fe/src/lib/PreferencesForm.svelte | 145 ++++++++++++++++++++++++++++---------- fe/src/lib/errors.ts | 6 +- fe/src/lib/utils.ts | 2 +- 8 files changed, 193 insertions(+), 74 deletions(-) create mode 100644 fe/src/lib/Chart.svelte (limited to 'fe/src/lib') diff --git a/fe/src/lib/Card.svelte b/fe/src/lib/Card.svelte index d7cd900..cd1e02c 100644 --- a/fe/src/lib/Card.svelte +++ b/fe/src/lib/Card.svelte @@ -1,6 +1,5 @@
diff --git a/fe/src/lib/Chart.svelte b/fe/src/lib/Chart.svelte new file mode 100644 index 0000000..b19d932 --- /dev/null +++ b/fe/src/lib/Chart.svelte @@ -0,0 +1,63 @@ + + + \ No newline at end of file diff --git a/fe/src/lib/DataView.svelte b/fe/src/lib/DataView.svelte index 0a6b81b..5e81a5a 100644 --- a/fe/src/lib/DataView.svelte +++ b/fe/src/lib/DataView.svelte @@ -1,10 +1,11 @@ + -

User Preferences

-
-
- - -
-
- - -
- -
+

User Preferences

+
+
+ + +
+
+ + +
+ + +
+ diff --git a/fe/src/lib/errors.ts b/fe/src/lib/errors.ts index d44bec5..81f7145 100644 --- a/fe/src/lib/errors.ts +++ b/fe/src/lib/errors.ts @@ -1,7 +1,5 @@ export class UnauthorizedError extends Error { - constructor(message?: string, options?: ErrorOptions) { - super(message, options); + constructor(message?: string) { + super(message); } } - - diff --git a/fe/src/lib/utils.ts b/fe/src/lib/utils.ts index 22d4e9a..e78556c 100644 --- a/fe/src/lib/utils.ts +++ b/fe/src/lib/utils.ts @@ -1,5 +1,5 @@ export function processFormInput(form: HTMLFormElement) { - const formData = new FormData(form); + const formData: FormData = new FormData(form); const data: Record = {}; for (let field of formData) { const [key, value] = field; -- cgit v1.1 From c4e5776f9e174fe6bf91721649c0541a9fb310ae Mon Sep 17 00:00:00 2001 From: Zach Berwaldt Date: Fri, 15 Mar 2024 21:41:12 -0400 Subject: add env samples, move files --- fe/src/lib/errors.ts | 5 ----- fe/src/lib/utils.ts | 9 --------- 2 files changed, 14 deletions(-) delete mode 100644 fe/src/lib/errors.ts delete mode 100644 fe/src/lib/utils.ts (limited to 'fe/src/lib') diff --git a/fe/src/lib/errors.ts b/fe/src/lib/errors.ts deleted file mode 100644 index 81f7145..0000000 --- a/fe/src/lib/errors.ts +++ /dev/null @@ -1,5 +0,0 @@ -export class UnauthorizedError extends Error { - constructor(message?: string) { - super(message); - } -} diff --git a/fe/src/lib/utils.ts b/fe/src/lib/utils.ts deleted file mode 100644 index e78556c..0000000 --- a/fe/src/lib/utils.ts +++ /dev/null @@ -1,9 +0,0 @@ -export function processFormInput(form: HTMLFormElement) { - const formData: FormData = new FormData(form); - const data: Record = {}; - for (let field of formData) { - const [key, value] = field; - data[key] = value; - } - return data; -} -- cgit v1.1 From fd1332a3df191577e91c6d846a8b5db1747099fd Mon Sep 17 00:00:00 2001 From: Zach Berwaldt Date: Fri, 15 Mar 2024 22:00:10 -0400 Subject: cleanup --- fe/src/lib/DataView.svelte | 7 ++++--- fe/src/lib/LoginForm.svelte | 3 ++- fe/src/lib/PreferencesForm.svelte | 15 ++++++++------- fe/src/lib/forms/AddForm.svelte | 3 ++- 4 files changed, 16 insertions(+), 12 deletions(-) (limited to 'fe/src/lib') diff --git a/fe/src/lib/DataView.svelte b/fe/src/lib/DataView.svelte index 5e81a5a..ffc2fe8 100644 --- a/fe/src/lib/DataView.svelte +++ b/fe/src/lib/DataView.svelte @@ -9,6 +9,7 @@ import Card from "./Card.svelte"; import Column from "./Column.svelte"; import AddForm from "./forms/AddForm.svelte"; + import { apiURL } from "../utils"; let json: Promise; @@ -24,7 +25,7 @@ let userTotalsData: number[]; async function fetchData() { - const res = await fetch("http://localhost:8080/api/v1/stats/", { + const res = await fetch(apiURL("stats"), { method: "GET", headers: { Authorization: `Bearer ${$token}` @@ -38,7 +39,7 @@ } async function fetchDailyUserStatistics() { - const res = await fetch("http://localhost:8080/api/v1/stats/daily/", { + const res = await fetch(apiURL("stats/daily"), { method: "GET", headers: { Authorization: `Bearer ${$token}` @@ -57,7 +58,7 @@ } async function fetchWeeklyTotals() { - const res = await fetch("http://localhost:8080/api/v1/stats/weekly/", { + const res = await fetch(apiURL("stats/weekly"), { method: "GET", headers: { Authorization: `Bearer ${$token}` diff --git a/fe/src/lib/LoginForm.svelte b/fe/src/lib/LoginForm.svelte index 8c3c288..cf5febf 100644 --- a/fe/src/lib/LoginForm.svelte +++ b/fe/src/lib/LoginForm.svelte @@ -1,6 +1,7 @@