Skip to content

Commit 78a693a

Browse files
Greg Bowlerrichardbirkin
andauthored
Slc4 account name (#130)
* docs: move setup guide to wiki * fix: associate cost to user rather than product * test: assert unknown uploads * feature: notification when file is not understood for #62 * tweak: don't notify for new audits * wip: split editor UI * ui: split editor ui * wip: split classes * wip: split percentage ui complete * wip: split percentage ui complete * test: update qa * asset: plus minus icons * feature: splits and profits in product table closes #105 closes #101 * style: splits list + editor * bug fix: profit sum * style: splits list border and margin * test: assertions for profit/balance * test: test profit calculations * ci: wip behat on github actions * wip: authwave * feature: login via authwave closes #119 * feature: refactor upload manager * build: use new releases on all repos * test: improve tests * feature: account name - new settings panel closes #121 --------- Co-authored-by: rjbirkin <[email protected]>
1 parent 44fdfd9 commit 78a693a

File tree

16 files changed

+142
-11
lines changed

16 files changed

+142
-11
lines changed

class/Auth/Settings.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
namespace SHIFT\Trackshift\Auth;
3+
4+
class Settings {
5+
/** @var array<string, string> */
6+
private array $kvp = [];
7+
8+
public function set(string $key, string $value):void {
9+
$this->kvp[$key] = $value;
10+
}
11+
12+
public function get(string $key):?string {
13+
return $this->kvp[$key] ?? null;
14+
}
15+
16+
public function getKvp():array {
17+
return $this->kvp;
18+
}
19+
}

class/Auth/UserRepository.php

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,32 @@ public function getLatestNotificationCheckTime(User $user):?DateTimeInterface {
6666
return $this->db->fetchDateTime("getLastNotificationCheckTime", $user->id);
6767
}
6868

69+
public function getUserSettings(User $user):Settings {
70+
$settings = new Settings();
71+
72+
foreach($this->db->fetchAll("getSettings", $user->id) as $row) {
73+
$settings->set(
74+
$row->getString("key"),
75+
$row->getString("value"),
76+
);
77+
}
78+
79+
return $settings;
80+
}
81+
82+
public function setUserSettings(User $user, Settings $settings):void {
83+
$this->db->delete("removeUserSettings", $user->id);
84+
85+
foreach($settings->getKvp() as $key => $value) {
86+
$this->db->insert("setUserSetting", [
87+
"userId" => $user->id,
88+
"key" => $key,
89+
"value" => $value,
90+
]);
91+
}
92+
}
93+
94+
6995
private function rowToUser(?Row $row):?User {
7096
if(!$row) {
7197
return null;
@@ -80,6 +106,4 @@ public function associateAuthwave(User $user, AuthwaveUser $authwaveUser):void {
80106
"authwaveId" => $authwaveUser->id,
81107
]);
82108
}
83-
84-
85109
}

class/ServiceLoader.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use SHIFT\Spotify\SpotifyClient;
1010
use SHIFT\Trackshift\Artist\ArtistRepository;
1111
use SHIFT\Trackshift\Audit\AuditRepository;
12+
use SHIFT\Trackshift\Auth\Settings;
1213
use SHIFT\Trackshift\Auth\User;
1314
use SHIFT\Trackshift\Auth\UserRepository;
1415
use SHIFT\Trackshift\Content\ContentRepository;
@@ -126,4 +127,10 @@ public function loadAuthenticator():Authenticator {
126127
$session->getStore(UserRepository::SESSION_AUTHENTICATOR_STORE_KEY, true),
127128
);
128129
}
130+
131+
public function loadSettings():Settings {
132+
$userRepo = $this->container->get(UserRepository::class);
133+
$user = $this->container->get(User::class);
134+
return $userRepo->getUserSettings($user);
135+
}
129136
}

class/Split/SplitRepository.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,22 +20,22 @@ public function __construct(
2020
}
2121

2222
/** @return array<Split> */
23-
public function getAll(User $user, bool $withRemainder = false):array {
23+
public function getAll(User $user, ?string $remainderName = null):array {
2424
$splitList = [];
2525

2626
$resultSet = $this->db->fetchAll("getAll", $user->id);
2727
foreach($resultSet as $row) {
2828
array_push(
2929
$splitList,
30-
$this->rowToSplit($row, withRemainderSplitPercentage: $withRemainder),
30+
$this->rowToSplit($row, remainderName: $remainderName),
3131
);
3232
}
3333

3434
return $splitList;
3535
}
3636

3737
/** @return array<SplitPercentage> */
38-
public function getSplitPercentageList(User $user, string $splitId, bool $withRemainderSplitPercentage = false):array {
38+
public function getSplitPercentageList(User $user, string $splitId, ?string $remainderName = null):array {
3939
$resultSet = $this->db->fetchAll("getSplitPercentageList", $splitId, $user->id);
4040

4141
$splitPercentageList = [];
@@ -46,8 +46,8 @@ public function getSplitPercentageList(User $user, string $splitId, bool $withRe
4646
);
4747
}
4848

49-
if($withRemainderSplitPercentage) {
50-
array_push($splitPercentageList, new RemainderSplitPercentage($splitPercentageList));
49+
if($remainderName) {
50+
array_push($splitPercentageList, new RemainderSplitPercentage($splitPercentageList, $remainderName));
5151
}
5252
return $splitPercentageList;
5353
}
@@ -94,7 +94,7 @@ public function delete(string $splitId, User $user):void {
9494
$this->db->delete("delete", $splitId, $user->id);
9595
}
9696

97-
private function rowToSplit(?Row $row, ?User $user = null, bool $withRemainderSplitPercentage = false):?Split {
97+
private function rowToSplit(?Row $row, ?User $user = null, ?string $remainderName = null):?Split {
9898
if(!$row) {
9999
return null;
100100
}
@@ -103,7 +103,7 @@ private function rowToSplit(?Row $row, ?User $user = null, bool $withRemainderSp
103103
$user = $user ?? $this->userRepository->getById($row->getString("userId"));
104104
$product = $this->productRepository->getById($row->getString("productId"));
105105

106-
$splitPercentageList = $this->getSplitPercentageList($user, $id, $withRemainderSplitPercentage);
106+
$splitPercentageList = $this->getSplitPercentageList($user, $id, $remainderName);
107107

108108
return new Split(
109109
$id,

page/_component/account-tabs.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,7 @@
1111
<li>
1212
<a href="/account/splits/">Splits</a>
1313
</li>
14+
<li>
15+
<a href="/account/settings/">Settings</a>
16+
</li>
1417
</ul>

page/_component/user-settings.html

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<form method="post">
2+
<label>
3+
<span>Account name</span>
4+
<input name="account_name" data-bind:value="@name" />
5+
</label>
6+
7+
<div class="actions">
8+
<button name="do" value="save">Save</button>
9+
</div>
10+
</form>

page/account/settings.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<account-tabs />
2+
<user-settings />

page/account/settings.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
use Gt\Dom\HTMLDocument;
3+
use Gt\DomTemplate\Binder;
4+
use Gt\Input\Input;
5+
use SHIFT\Trackshift\Auth\Settings;
6+
use SHIFT\Trackshift\Auth\User;
7+
use SHIFT\Trackshift\Auth\UserRepository;
8+
9+
function go(HTMLDocument $document, Binder $binder, Settings $settings):void {
10+
$kvp = $settings->getKvp();
11+
12+
foreach($document->querySelectorAll("user-settings form input") as $input) {
13+
if(isset($kvp[$input->name])) {
14+
$binder->bindKeyValue($input->name, $kvp[$input->name]);
15+
}
16+
}
17+
}
18+
19+
function do_save(Input $input, User $user, UserRepository $userRepository, Settings $settings):void {
20+
foreach($input as $key => $value) {
21+
$settings->set($key, $value);
22+
}
23+
24+
$userRepository->setUserSettings($user, $settings);
25+
}

page/account/splits/@split.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Gt\Ulid\Ulid;
1010
use SHIFT\Trackshift\Artist\ArtistRepository;
1111
use SHIFT\Trackshift\Audit\AuditRepository;
12+
use SHIFT\Trackshift\Auth\Settings;
1213
use SHIFT\Trackshift\Auth\User;
1314
use SHIFT\Trackshift\Product\ProductRepository;
1415
use SHIFT\Trackshift\Split\EmptySplitPercentage;
@@ -24,6 +25,7 @@ function go(
2425
ArtistRepository $artistRepository,
2526
ProductRepository $productRepository,
2627
SplitRepository $splitRepository,
28+
Settings $settings,
2729
User $user,
2830
):void {
2931
$artistId = $input->getString("artist");
@@ -66,7 +68,7 @@ function go(
6668
$percentageList = $splitRepository->getSplitPercentageList($user, $id);
6769
}
6870
array_push($percentageList, new EmptySplitPercentage($productId));
69-
array_push($percentageList, new RemainderSplitPercentage($percentageList));
71+
array_push($percentageList, new RemainderSplitPercentage($percentageList, $settings->get("account_name") ?? "You"));
7072

7173
$binder->bindList(
7274
$percentageList,

page/account/splits/index.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
<?php
22
use Gt\DomTemplate\Binder;
3+
use SHIFT\Trackshift\Auth\Settings;
34
use SHIFT\Trackshift\Auth\User;
45
use SHIFT\Trackshift\Split\SplitRepository;
56

67
function go(
78
SplitRepository $splitRepository,
89
User $user,
10+
Settings $settings,
911
Binder $binder,
1012
):void {
11-
$splits = $splitRepository->getAll($user, true);
13+
$splits = $splitRepository->getAll($user, $settings->get("account_name") ?? "You");
1214
$binder->bindList($splits);
1315
}

0 commit comments

Comments
 (0)