From b2191d12193de6ea6ff841fbd829a38d568e5927 Mon Sep 17 00:00:00 2001 From: Alex Cabal Date: Wed, 18 Dec 2024 14:20:28 -0600 Subject: [PATCH] Allow editing of projects --- config/apache/rewrites/projects.conf | 5 +++ lib/Ebook.php | 10 +++++ lib/Project.php | 10 +++++ lib/User.php | 10 +++++ templates/EbookMetadata.php | 22 +++++++--- templates/EbookPlaceholderForm.php | 31 +++++++------ templates/EbookProjects.php | 7 ++- templates/ProjectForm.php | 5 ++- templates/ProjectsTable.php | 9 ++++ www/css/project.css | 1 - www/ebook-placeholders/edit.php | 22 +++++----- www/ebook-placeholders/get.php | 18 ++++---- www/ebook-placeholders/post.php | 32 ++------------ www/projects/edit.php | 65 ++++++++++++++++++++++++++++ www/projects/post.php | 17 +++++++- www/users/get.php | 2 +- 16 files changed, 191 insertions(+), 75 deletions(-) create mode 100644 www/projects/edit.php diff --git a/config/apache/rewrites/projects.conf b/config/apache/rewrites/projects.conf index ddbcbbf0..f868fa25 100644 --- a/config/apache/rewrites/projects.conf +++ b/config/apache/rewrites/projects.conf @@ -1 +1,6 @@ RewriteRule ^/ebooks/([^\.]+?)/projects/new$ /projects/new.php?ebook-url-path=$1 + +RewriteRule ^/projects/([\d]+)/edit$ /projects/edit.php?project-id=$1 + +RewriteCond expr "tolower(%{REQUEST_METHOD}) =~ /^post$/" +RewriteRule ^/projects/([\d]+)$ /projects/post.php?project-id=$1 [L] diff --git a/lib/Ebook.php b/lib/Ebook.php index 10fa7283..8d8a4b49 100644 --- a/lib/Ebook.php +++ b/lib/Ebook.php @@ -36,6 +36,7 @@ use function Safe\shell_exec; * @property string $ReadingTime * @property string $AuthorsHtml * @property string $AuthorsUrl This is a single URL even if there are multiple authors; for example, `/ebooks/karl-marx_friedrich-engels/`. + * @property string $AuthorsString * @property string $ContributorsHtml * @property string $TitleWithCreditsHtml * @property string $TextUrl @@ -115,6 +116,7 @@ class Ebook{ protected string $_ReadingTime; protected string $_AuthorsHtml; protected string $_AuthorsUrl; + protected string $_AuthorsString; protected string $_ContributorsHtml; protected string $_TitleWithCreditsHtml; protected string $_TextUrl; @@ -538,6 +540,14 @@ class Ebook{ return $this->_AuthorsUrl; } + protected function GetAuthorsString(): string{ + if(!isset($this->_AuthorsString)){ + $this->_AuthorsString = strip_tags(Ebook::GenerateContributorList($this->Authors, false)); + } + + return $this->_AuthorsString; + } + protected function GetContributorsHtml(): string{ if(!isset($this->_ContributorsHtml)){ $this->_ContributorsHtml = ''; diff --git a/lib/Project.php b/lib/Project.php index 53a3bac6..df4e0e7d 100644 --- a/lib/Project.php +++ b/lib/Project.php @@ -16,6 +16,7 @@ use Safe\DateTimeImmutable; * @property User $Manager * @property User $Reviewer * @property string $Url + * @property string $EditUrl * @property DateTimeImmutable $LastActivityTimestamp The timestamp of the latest activity, whether it's a commit, a discussion post, or simply the started timestamp. * @property array $Reminders * @property ?string $VcsUrlDomain @@ -46,6 +47,7 @@ class Project{ protected User $_Manager; protected User $_Reviewer; protected string $_Url; + protected string $_EditUrl; protected DateTimeImmutable $_LastActivityTimestamp; /** @var array $_Reminders */ protected array $_Reminders; @@ -115,6 +117,14 @@ class Project{ return $this->_Url; } + protected function GetEditUrl(): string{ + if(!isset($this->_EditUrl)){ + $this->_EditUrl = $this->Url . '/edit'; + } + + return $this->_EditUrl; + } + protected function GetLastActivityTimestamp(): DateTimeImmutable{ if(!isset($this->_LastActivityTimestamp)){ $dates = [ diff --git a/lib/User.php b/lib/User.php index 778ca0c8..042e2720 100644 --- a/lib/User.php +++ b/lib/User.php @@ -9,6 +9,7 @@ use function Safe\preg_match; * @property bool $IsRegistered A user is "registered" if they have an entry in the `Benefits` table; a password is required to log in. * @property Benefits $Benefits * @property string $Url + * @property string $EditUrl * @property ?Patron $Patron * @property ?NewsletterSubscription $NewsletterSubscription * @property ?Payment $LastPayment @@ -32,6 +33,7 @@ class User{ protected ?Payment $_LastPayment; protected Benefits $_Benefits; protected string $_Url; + protected string $_EditUrl; protected ?Patron $_Patron; protected ?NewsletterSubscription $_NewsletterSubscription; protected string $_DisplayName; @@ -91,6 +93,14 @@ class User{ return $this->_Url; } + protected function GetEditUrl(): string{ + if(!isset($this->_EditUrl)){ + $this->_EditUrl = $this->Url . '/edit'; + } + + return $this->_EditUrl; + } + /** * @return array */ diff --git a/templates/EbookMetadata.php b/templates/EbookMetadata.php index 5a3941ad..bc6c6d16 100644 --- a/templates/EbookMetadata.php +++ b/templates/EbookMetadata.php @@ -2,6 +2,8 @@ /** * @var Ebook $ebook */ + +$showPlaceholderMetadata = $showPlaceholderMetadata ?? false; ?>

Metadata

@@ -11,7 +13,16 @@ Ebook ID: EbookId ?> - IsPlaceholder() && $ebook->EbookPlaceholder !== null){ ?> + + +
+ +IsPlaceholder() && $ebook->EbookPlaceholder !== null){ ?> +
+

Placeholder metadata

+

Edit placeholder

+ + @@ -26,7 +37,8 @@ - - -
Is wanted: EbookPlaceholder->IsWanted){ ?>☑Difficulty: EbookPlaceholder->Difficulty->value ?? '') ?>
-
+ + + + + diff --git a/templates/EbookPlaceholderForm.php b/templates/EbookPlaceholderForm.php index 981fe959..a6913ea6 100644 --- a/templates/EbookPlaceholderForm.php +++ b/templates/EbookPlaceholderForm.php @@ -1,5 +1,6 @@
Contributors @@ -189,21 +190,23 @@ $ebook = $ebook ?? new Ebook();
-
- Project - -
- $ebook->ProjectInProgress, 'areFieldsRequired' => false]) ?> + +
+ Project + +
+ $ebook->ProjectInProgress, 'areFieldsRequired' => false]) ?> +
-
+
Wanted list