Skip to content

Commit

Permalink
SLC2 release (#113)
Browse files Browse the repository at this point in the history
* test: update tests

* wip: crud costs for products

* wip: slc2 earnings calculations

* fix: default cost to £0

* tweak: deleted commented out code

* tweak: costs table styling

* style: costs table links / edit button

* feature: costs table search + upload table search tweak

* style: modal cancel button margin

* Prepping SLC2 for release (#111)

* wip: notifications and audit

* style: audit table

* style: audit table bottom margin

* wip: make earnings optional for upload class

---------

Co-authored-by: rjbirkin <[email protected]>

* wip: add escape key functionality to modals

* wip: add escape key functionality to modals

* wip: work between frames

---------

Co-authored-by: rjbirkin <[email protected]>
  • Loading branch information
g105b and richardbirkin authored Oct 11, 2023
1 parent e0a705c commit 25e8cef
Show file tree
Hide file tree
Showing 89 changed files with 1,580 additions and 391 deletions.
1 change: 1 addition & 0 deletions asset/icon/bell-solid.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 23 additions & 0 deletions behat.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
default:
autoload:
'': "%paths.base%/test/behat/Context"

suites:
default:
serverAddress: 0.0.0.0
serverPort: 8080
paths:
- "%paths.base%/test/behat"
contexts:
- \Behat\MinkExtension\Context\MinkContext:
- \SHIFT\Trackshift\BehatContext\ServerContext:
- \SHIFT\Trackshift\BehatContext\AuthContext:
- \SHIFT\Trackshift\BehatContext\PageContext:
- \SHIFT\Trackshift\BehatContext\UploadContext:
- \SHIFT\Trackshift\BehatContext\AnotherContext:

extensions:
Behat\MinkExtension:
base_url: http://localhost:8080
goutte: ~
files_path: "%paths.base%/test/files/"
43 changes: 43 additions & 0 deletions build.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"asset/**/*": {
"require": {
"vendor/bin/sync": ">=1.3.0"
},
"execute": {
"command": "vendor/bin/sync",
"arguments": ["./asset", "./www/asset", "--symlink"]
}
},

"data/cache/art/*": {
"require": {
"vendor/bin/sync": ">=1.3.0"
},
"execute": {
"command": "vendor/bin/sync",
"arguments": ["./data/cache/art", "./www/data/cache/art", "--symlink"]
}
},

"script/**/*.es6": {
"require": {
"node": "*",
"babel": "*",
"webpack": "*"
},
"execute": {
"command": "webpack",
"arguments": ["--entry","./script/script.es6", "--output-path", "./www", "--output-filename", "script.js", "--devtool", "source-map", "--mode", "development"]
}
},

"style/**/*.scss": {
"require": {
"sass": "*"
},
"execute": {
"command": "sass",
"arguments": ["./style/style.scss", "www/style.css"]
}
}
}
38 changes: 38 additions & 0 deletions class/Artist/ArtistRepository.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php
namespace SHIFT\Trackshift\Artist;

use Gt\Database\Result\Row;
use SHIFT\Trackshift\Auth\User;
use SHIFT\Trackshift\Repository\Repository;

readonly class ArtistRepository extends Repository {
/** return array<Artist> */
public function getAll(User $user):array {
$artistArray = [];

foreach($this->db->fetchAll("getAllForUser", $user->id) as $row) {
array_push(
$artistArray,
$this->rowToArtist($row),
);
}

return $artistArray;
}

public function getById(string $id):?Artist {
return $this->rowToArtist($this->db->fetch("getById", $id));
}


private function rowToArtist(?Row $row):?Artist {
if(!$row) {
return null;
}

return new Artist(
$row->getString("id"),
$row->getString("name"),
);
}
}
43 changes: 43 additions & 0 deletions class/Audit/AuditItem.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php
namespace SHIFT\Trackshift\Audit;

use DateTime;
use Gt\DomTemplate\BindGetter;
use Gt\Ulid\Ulid;
use SHIFT\Trackshift\Auth\User;
use SHIFT\Trackshift\Repository\Entity;

readonly class AuditItem extends Entity {
public function __construct(
public string $id,
public User $user,
public bool $isNotification,
public ?string $type = null,
public ?string $description = null,
public ?string $valueId = null,
public ?string $valueField = null,
public ?string $valueFrom = null,
public ?string $valueTo = null,
) {}

#[BindGetter]
public function getHtml():string {
[$typeName, $id] = explode("_", $this->valueId);
$typeName = ucfirst(strtolower($typeName));

$descriptionOrId = $this->description ?: $id;

return match($this->type) {
"create" => "Created new $typeName ($descriptionOrId)",
"update" => "Updated $typeName ($descriptionOrId)",
"delete" => "Deleted $typeName ($descriptionOrId)",
default => "Something happened...",
};
}

#[BindGetter]
public function getTimestamp():string {
$ulid = new Ulid(init: $this->id);
return (new DateTime("@" . round($ulid->getTimestamp() / 1000)))->format("jS M Y");
}
}
105 changes: 105 additions & 0 deletions class/Audit/AuditRepository.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
<?php
namespace SHIFT\Trackshift\Audit;

use Gt\Database\Result\Row;
use Gt\Ulid\Ulid;
use SHIFT\Trackshift\Auth\User;
use SHIFT\Trackshift\Repository\Repository;

readonly class AuditRepository extends Repository {
public function create(User $user, string $newId, ?string $description = null):void {
$this->db->insert("insertCreation", [
"id" => new Ulid("audit"),
"userId" => $user->id,
"valueId" => $newId,
"description" => $description,
]);
}

public function delete(User $user, string $deletedId, ?string $description = null):void {
$this->db->insert("insertDeletion", [
"id" => new Ulid("audit"),
"userId" => $user->id,
"valueId" => $deletedId,
"description" => $description,
]);
}

/** @return array<AuditItem,NotificationItem> */
public function getAll(User $user):array {
$auditItemArray = [];

foreach($this->db->fetchAll("getAll", $user->id) as $row) {
array_push(
$auditItemArray,
$this->rowToAuditItem($row, $user),
);
}

return $auditItemArray;
}

private function rowToAuditItem(?Row $row, ?User $user = null):?AuditItem {
if(!$row) {
return null;
}

return new AuditItem(
$row->getString("id"),
$user,
$row->getBool("isNotification"),
$row->getString("type"),
$row->getString("description"),
$row->getString("valueId"),
$row->getString("valueField"),
$row->getString("valueFrom"),
$row->getString("valueTo"),
);
}

public function update(
User $user,
string $id,
object $from,
object $to,
?string $description = null,
):void {
$diff = $this->getDiff($from, $to);

foreach($diff as $field => $fromTo) {
$fromToDescription = "$field: $fromTo";
[$from, $to] = explode("->", $fromTo);
if($description) {
$fromToDescription .= " - $description";
}

$this->db->insert("insertUpdate", [
"id" => new Ulid("audit"),
"userId" => $user->id,
"valueId" => $id,
"valueField" => $field,
"valueFrom" => $from,
"valueTo" => $to,
"description" => $fromToDescription,
]);
}
}

/** @return array<string, string> key = property name, value = "$oldValue -> $newValue" */
private function getDiff(object $from, object $to):array {
$fromVars = get_object_vars($from);
$toVars = get_object_vars($to);

$diff = [];

foreach($fromVars as $key => $value) {
if($toVars[$key] != $value) {
$diff[$key] = "$value -> $toVars[$key]";
}
}

return $diff;
}


}
13 changes: 13 additions & 0 deletions class/Audit/NotificationItem.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php
namespace SHIFT\Trackshift\Audit;

use DateTime;
use SHIFT\Trackshift\Audit\AuditItem;
use SHIFT\Trackshift\Auth\User;

readonly class NotificationItem {
public function __construct(
public string $html,
public DateTime $timestamp,
) {}
}
4 changes: 2 additions & 2 deletions class/Auth/UserRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ public function getLoggedInUser():?User {
}

public function createNewUser():User {
$user = new User(new Ulid());
$this->uploadDb->insert("create", $user->id);
$user = new User(new Ulid("user"));
$this->db->insert("create", $user->id);
return $user;
}

Expand Down
26 changes: 26 additions & 0 deletions class/Cost/Cost.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php
namespace SHIFT\Trackshift\Cost;

use DateTime;
use Gt\DomTemplate\BindGetter;
use Gt\Ulid\Ulid;
use SHIFT\Trackshift\Product\Product;
use SHIFT\Trackshift\Repository\Entity;
use SHIFT\Trackshift\Royalty\Money;

readonly class Cost extends Entity {
public function __construct(
public string $id,
public Product $product,
public string $description,
public Money $amount,
) {}

#[BindGetter]
public function getAddedOn():string {
$ulid = new Ulid(init: $this->id);
$timestamp = $ulid->getTimestamp() / 1000;
$dateTime = new DateTime("@$timestamp");
return $dateTime->format("jS M Y g:ia");
}
}
Loading

0 comments on commit 25e8cef

Please sign in to comment.