-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 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
1 parent
e0a705c
commit 25e8cef
Showing
89 changed files
with
1,580 additions
and
391 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
) {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
} | ||
} |
Oops, something went wrong.