Skip to content

Commit

Permalink
v1.0.11
Browse files Browse the repository at this point in the history
  • Loading branch information
sganis committed Oct 4, 2023
1 parent ed56144 commit bfb4e2e
Show file tree
Hide file tree
Showing 9 changed files with 100 additions and 57 deletions.
19 changes: 0 additions & 19 deletions frontend/dist/assets/index-a2eb4064.js

This file was deleted.

20 changes: 20 additions & 0 deletions frontend/dist/assets/index-c243a6f3.js

Large diffs are not rendered by default.

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions frontend/dist/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
<link rel="icon" type="image/svg+xml" href="favicon.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Pyme</title>
<script type="module" crossorigin src="/assets/index-a2eb4064.js"></script>
<link rel="stylesheet" href="/assets/index-01748d3a.css">
<script type="module" crossorigin src="/assets/index-c243a6f3.js"></script>
<link rel="stylesheet" href="/assets/index-e625af75.css">
</head>
<body>
<div id="app"></div>
Expand Down
2 changes: 1 addition & 1 deletion frontend/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "client",
"private": true,
"version": "1.0.10",
"version": "1.0.11",
"type": "module",
"scripts": {
"dev": "vite",
Expand Down
62 changes: 41 additions & 21 deletions frontend/src/lib/ItemTable.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,14 @@
export let sortCol;
export let sortDesc;
export let items;
export let offset;
export let limit;
export let total;
export let showToolbar;
$:page = offset/limit + 1;
$:total_pages = Math.ceil(total/limit);
let searchText;
const searchLater = () => {
Expand All @@ -26,8 +32,8 @@
const showModify = (o) => {
dispatch('showModify', o);
}
const showRemove = (o) => {
dispatch('showRemove', o);
const goToPage = (page) => {
dispatch('goToPage', page);
}
</script>
Expand Down Expand Up @@ -60,13 +66,14 @@
New
</button>
</div>
<br>
{/if}

<div class="row">


<div class="row mt-3">
<div class="table-responsive">
<table class="table table-hover table-sm">
<thead class="table-success">
<thead class="table-warning">
<tr>
{#each table.columns as col, i}
<th on:click={()=>sort(col)} role="button" class="text-nowrap">
Expand All @@ -82,38 +89,51 @@
<tbody>
{#each items as o, i}
<tr class="clickable" on:click={()=>showModify(o)}>
{#each table.columns as col}
<td>{ o[col] || ""}</td>
{#each table.columns as col, index}
{#if col === 'paid' && o[col] }
<td><i class="bi-check2"/></td>
{:else}
<td>{ o[col] || ""}</td>
{/if}
{/each}
<!-- <td class="text-nowrap text-end">
<button class="btn btn-light btn-sm btn-width-sm" type="button"
on:click={() => showModify(o)}>
<i class="bi-pencil"/>
</button>
<button class="btn btn-light btn-sm btn-width-sm" type="button"
on:click={() => showRemove(o)}>
<i class="bi-trash3"/>
</button>
</td> -->
</tr>
{/each}
</tbody>
</table>
</div>
</div>

<div>Total: {items.length}</div>

<div class="d-flex flex-row justify-content-end gap-3">
{#if total_pages}
{#if page > 1}
<a href="#/" on:click={()=>goToPage(1)} class="page"><i class="bi-chevron-double-left"/></a>
<a href="#/" on:click={()=>goToPage(page - 1)} class="page"><i class="bi-chevron-left"/></a>
{:else}
<i class="bi-chevron-double-left link-disabled" />
<i class="bi-chevron-left link-disabled" />
{/if}
Page {page}/{total_pages}
{#if page + 1 <= total_pages}
<a href="#/" on:click={()=>goToPage(page + 1)} class="page"><i class="bi-chevron-right"/></a>
<a href="#/" on:click={()=>goToPage(total_pages)} class="page"><i class="bi-chevron-double-right"/></a>
{:else}
<i class="bi-chevron-right link-disabled" />
<i class="bi-chevron-double-right link-disabled" />
{/if}
{/if}
</div>


<style>
.btn-width-sm {
width: 32px;
}
.bi-app {
content: "\2122";
color: transparent !important;
}
.clickable {
cursor: pointer;
}
.link-disabled {
color: lightgray;
}
</style>
6 changes: 4 additions & 2 deletions frontend/src/lib/itemManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ import { push } from "svelte-spa-router";
import { working, state, apierror } from "./store";

export default class ItemManager {
constructor(url, sortcol, sortdesc) {
constructor(url, sortcol, sortdesc, limit, offset) {
this.url = url;
this.sortCol = sortcol;
this.sortDesc = sortdesc;
this.limit = limit;
this.offset = offset;
this.searchText = "";
this.result = [];
this.error = "";
Expand All @@ -17,7 +19,7 @@ export default class ItemManager {
working.set(true);
apierror.set("");
this.error = "";
let query = `q=${this.searchText}&sortcol=${this.sortCol}&desc=${this.sortDesc}`;
let query = `q=${this.searchText}&sortcol=${this.sortCol}&desc=${this.sortDesc}&limit=${this.limit}&offset=${this.offset}`;

const r = await fetch(`${this.url}?${query}`, {
headers: {
Expand Down
41 changes: 30 additions & 11 deletions frontend/src/routes/Home.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
let title = "Orders";
let table = {
header : ['Date','Cust','Total', 'Paid'],
columns : ['date','customer','price','paid'],
header : ['ID','Date','Cust','Total', 'Paid'],
columns : ['id','date','customer','price','paid'],
}
let itemInit = {
date: today,
Expand All @@ -43,7 +43,11 @@
}
let order = {...itemInit}
let items = [];
let result = {
items : [],
offset : 0,
};
let limit = 10;
let error = '';
let timer;
const waitTime = 500;
Expand All @@ -52,15 +56,15 @@
console.log('mouning home, state:', JSON.stringify($state));
console.log(url);
if (manager===undefined)
manager = new ItemManager(url, sortCol, sortDesc);
manager = new ItemManager(url, sortCol, sortDesc, limit, 0);
await manager.search();
error = manager.error;
items = manager.result;
result = manager.result;
});
const refresh = async () => {
await manager.search();
error = manager.error;
items = manager.result;
result = manager.result;
}
const searchLater = async (e) => {
const searchText = e.detail;
Expand All @@ -69,12 +73,12 @@
if (e.key == "Enter") {
await manager.search();
error = manager.error;
items = manager.result;
result = manager.result;
} else {
timer = setTimeout(async () => {
await manager.search();
error = manager.error;
items = manager.result;
result = manager.result;
}, waitTime);
}
}
Expand All @@ -90,7 +94,7 @@
sortDesc = manager.sortDesc;
await manager.search();
error = manager.error;
items = manager.result;
result = manager.result;
}
const showCreate = () => {
order = {...itemInit};
Expand All @@ -117,6 +121,17 @@
isModal = true;
error = '';
}
const goToPage = async (e) => {
let page = e.detail;
if (page < 1) page = 1;
let offset = (page-1)*limit;
//console.log('goto page:', page, offset);
manager.offset = offset;
await manager.search();
error = manager.error;
result = manager.result;
}
</script>

Expand All @@ -135,7 +150,10 @@
<ItemsTable
{title}
{showToolbar}
{items}
items={result.items}
{limit}
offset={result.offset}
total={result.total}
{table}
{sortCol}
{sortDesc}
Expand All @@ -144,7 +162,8 @@
on:searchLater={searchLater}
on:showCreate={showCreate}
on:showRemove={showRemove}
on:showModify={showModify} />
on:showModify={showModify}
on:goToPage={goToPage} />


<style>
Expand Down
1 change: 1 addition & 0 deletions frontend/src/routes/Order.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@
delay="200"
bind:selectedItem={order.customer}
bind:text={currentCustomer}
disabled={$working}
create={true}
createText={"Item doesn't exist, create one?"}
onCreate={handleCreate} />
Expand Down

0 comments on commit bfb4e2e

Please sign in to comment.