Skip to content

Commit

Permalink
fix: edit costs
Browse files Browse the repository at this point in the history
for #200
  • Loading branch information
g105b committed Feb 17, 2025
1 parent ba5f7e9 commit 2802fab
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 16 deletions.
5 changes: 5 additions & 0 deletions class/Cost/Cost.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,9 @@ public function getAddedOn():string {
public function getDateFormatted():string {
return $this->date->format("jS M Y");
}

#[BindGetter]
public function getDateValue():string {
return $this->date->format("Y-m-d");
}
}
4 changes: 2 additions & 2 deletions page/_component/cost-editor.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<form method="post" onchange="this.submit()">
<label>
<span>Artist</span>
<select name="artist" required data-bind:value="@name">
<select name="artist" required data-bind:value="@name" data-rebind>
<option></option>
<option data-list data-bind:text="name" data-bind:value="id">Artist</option>
</select>
Expand All @@ -28,7 +28,7 @@
</label>
<label>
<span>Date</span>
<input name="date" required type="date" data-bind:value="@name" autocomplete="off" />
<input name="date" required type="date" data-bind:value="dateValue" autocomplete="off" />
</label>

<div class="actions">
Expand Down
8 changes: 5 additions & 3 deletions page/_component/cost-editor.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ function go(
$document->querySelector("select[name=artist]"),
);

$artistId = $input->getString("artist");
$id = $dynamicPath->get("cost");
$artistId = $input->getString("artist");
$cost = null;

if($id === "_new") {
Expand All @@ -42,7 +42,9 @@ function go(
else {
$cost = $costRepository->getById($id);
$binder->bindData($cost);
$artistId = $cost->product->artist->id;
if(!$artistId) {
$artistId = $cost->product->artist->id;
}
}

if($artistId) {
Expand All @@ -58,7 +60,7 @@ function go(
}
}

$binder->bindKeyValue("date", date("Y-m-d"));
$binder->bindKeyValue("dateValue", date("Y-m-d"));
}

function do_set_artist(Input $input, Response $response, Uri $uri):void {
Expand Down
2 changes: 1 addition & 1 deletion page/_component/cost-table.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
</tr>
</thead>
<tbody>
<tr data-list data-bind:data-id="id">
<tr data-list data-bind:data-cost-id="id">
<td data-bind:text="product.artist.name">Artist Name</td>
<td data-bind:text="product.title">Product Title</td>
<td class="currency" data-bind:text="amount">0.00</td>
Expand Down
9 changes: 9 additions & 0 deletions page/_component/cost-table.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
use Gt\Dom\HTMLDocument;
use Gt\DomTemplate\Binder;
use Gt\Http\Response;
use Gt\Input\Input;
Expand All @@ -8,9 +9,17 @@
function go(
CostRepository $costRepository,
User $user,
Input $input,
HTMLDocument $document,
Binder $binder,
):void {
$binder->bindList($costRepository->getAll($user));

if($updatedId = $input->getString("updated")) {
if($updatedElement = $document->querySelector("[data-cost-id='$updatedId']")) {
$updatedElement->classList->add("new");
}
}
}

function do_delete(
Expand Down
2 changes: 1 addition & 1 deletion query/Cost/getAllForUser.sql
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ where
Cost.userId = ?

order by
Artist.name, Product.title
Cost.date, Artist.name, Product.title
5 changes: 5 additions & 0 deletions script/page/_common.es6
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,9 @@ Page.go(function() {
Modal.init();
LiveUpdate.init();
Currency.init();

let newElement = document.querySelector(".new");
if(newElement) {
newElement.scrollIntoView({behavior: "smooth"})
}
});
9 changes: 0 additions & 9 deletions style/component/upload-table.scss
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,5 @@ upload-table {
}

}

&.new {
@keyframes highlight-new {
from {
background-color: #81df6a;
}
}
animation: highlight-new 2s forwards 1;
}
}
}
9 changes: 9 additions & 0 deletions style/decorator/data-table.scss
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,13 @@
}
}
}

.new {
@keyframes highlight-new {
from {
background-color: #81df6a;
}
}
animation: highlight-new 2s forwards 1;
}
}

0 comments on commit 2802fab

Please sign in to comment.