diff --git a/app/Filament/RelationManagers/RevisionsRelationManager.php b/app/Filament/RelationManagers/RevisionsRelationManager.php index b99a3ac..f699ad3 100644 --- a/app/Filament/RelationManagers/RevisionsRelationManager.php +++ b/app/Filament/RelationManagers/RevisionsRelationManager.php @@ -51,6 +51,7 @@ class RevisionsRelationManager extends RelationManager ->color(fn (string $state) => match ($state) { 'published' => 'success', 'unpublished' => 'warning', + 'scheduled' => 'info', 'created' => 'info', 'deleted', 'erased' => 'danger', default => 'gray', @@ -77,7 +78,7 @@ class RevisionsRelationManager extends RelationManager ->filters([ SelectFilter::make('event') ->label(__('panel.revisions.fields.event')) - ->options(fn () => collect(['created', 'updated', 'published', 'unpublished', 'deleted', 'restored', 'erased']) + ->options(fn () => collect(['created', 'updated', 'published', 'scheduled', 'unpublished', 'deleted', 'restored', 'erased']) ->mapWithKeys(fn (string $e) => [$e => __("panel.revisions.events.{$e}")]) ->all()), ]) diff --git a/app/Models/Concerns/HasRevisions.php b/app/Models/Concerns/HasRevisions.php index 5cd0b34..c686acb 100644 --- a/app/Models/Concerns/HasRevisions.php +++ b/app/Models/Concerns/HasRevisions.php @@ -131,11 +131,23 @@ trait HasRevisions // Ask the model itself: "published" means different things to a page // with a status and a project with only a date. - if (method_exists($this, 'isPublishedNow')) { - return $this->isPublishedNow() ? 'published' : 'unpublished'; + if (! method_exists($this, 'isPublishedNow')) { + return 'updated'; } - return 'updated'; + // Before and after, because the change is what has a name: going live, + // coming off, or being given a date — which is neither, and which a + // history that only asked "is it live now?" called "unpublished". + $before = (clone $this)->setRawAttributes($this->getRawOriginal()); + $now = $this->isPublishedNow(); + $was = $before->isPublishedNow(); + + return match (true) { + $now && ! $was => 'published', + ! $now && $was => 'unpublished', + ! $now && method_exists($this, 'isScheduled') && $this->isScheduled() => 'scheduled', + default => 'updated', + }; } protected function revisionValue(mixed $value): mixed diff --git a/lang/ca/panel.php b/lang/ca/panel.php index 7ae84ee..7bd3b87 100644 --- a/lang/ca/panel.php +++ b/lang/ca/panel.php @@ -622,6 +622,7 @@ return [ 'updated' => 'Editat', 'published' => 'Publicat', 'unpublished' => 'Despublicat', + 'scheduled' => 'Programat', 'deleted' => 'Esborrat', 'restored' => 'Recuperat', 'erased' => 'Eliminat del tot', diff --git a/lang/en/panel.php b/lang/en/panel.php index 14af941..b3cf80e 100644 --- a/lang/en/panel.php +++ b/lang/en/panel.php @@ -620,6 +620,7 @@ return [ 'updated' => 'Edited', 'published' => 'Published', 'unpublished' => 'Unpublished', + 'scheduled' => 'Scheduled', 'deleted' => 'Deleted', 'restored' => 'Recovered', 'erased' => 'Erased for good', diff --git a/lang/es/panel.php b/lang/es/panel.php index 3dd0d0e..5d87756 100644 --- a/lang/es/panel.php +++ b/lang/es/panel.php @@ -622,6 +622,7 @@ return [ 'updated' => 'Editado', 'published' => 'Publicado', 'unpublished' => 'Despublicado', + 'scheduled' => 'Programado', 'deleted' => 'Borrado', 'restored' => 'Recuperado', 'erased' => 'Eliminado del todo', diff --git a/public/openapi.yaml b/public/openapi.yaml index 6eacb08..1037567 100644 --- a/public/openapi.yaml +++ b/public/openapi.yaml @@ -2795,7 +2795,7 @@ paths: - $ref: "#/components/parameters/PerPage" - name: event in: query - description: "`created`, `updated`, `published`, `unpublished`, `deleted`, `restored` or `erased`." + description: "`created`, `updated`, `published`, `scheduled`, `unpublished`, `deleted`, `restored` or `erased`." schema: { type: string } responses: "200": @@ -2818,7 +2818,7 @@ paths: - $ref: "#/components/parameters/PerPage" - name: event in: query - description: "`created`, `updated`, `published`, `unpublished`, `deleted`, `restored` or `erased`." + description: "`created`, `updated`, `published`, `scheduled`, `unpublished`, `deleted`, `restored` or `erased`." schema: { type: string } responses: "200": @@ -2841,7 +2841,7 @@ paths: - $ref: "#/components/parameters/PerPage" - name: event in: query - description: "`created`, `updated`, `published`, `unpublished`, `deleted`, `restored` or `erased`." + description: "`created`, `updated`, `published`, `scheduled`, `unpublished`, `deleted`, `restored` or `erased`." schema: { type: string } responses: "200": @@ -2864,7 +2864,7 @@ paths: - $ref: "#/components/parameters/PerPage" - name: event in: query - description: "`created`, `updated`, `published`, `unpublished`, `deleted`, `restored` or `erased`." + description: "`created`, `updated`, `published`, `scheduled`, `unpublished`, `deleted`, `restored` or `erased`." schema: { type: string } responses: "200": @@ -2887,7 +2887,7 @@ paths: - $ref: "#/components/parameters/PerPage" - name: event in: query - description: "`created`, `updated`, `published`, `unpublished`, `deleted`, `restored` or `erased`." + description: "`created`, `updated`, `published`, `scheduled`, `unpublished`, `deleted`, `restored` or `erased`." schema: { type: string } responses: "200": @@ -2910,7 +2910,7 @@ paths: - $ref: "#/components/parameters/PerPage" - name: event in: query - description: "`created`, `updated`, `published`, `unpublished`, `deleted`, `restored` or `erased`." + description: "`created`, `updated`, `published`, `scheduled`, `unpublished`, `deleted`, `restored` or `erased`." schema: { type: string } responses: "200": @@ -2933,7 +2933,7 @@ paths: - $ref: "#/components/parameters/PerPage" - name: event in: query - description: "`created`, `updated`, `published`, `unpublished`, `deleted`, `restored` or `erased`." + description: "`created`, `updated`, `published`, `scheduled`, `unpublished`, `deleted`, `restored` or `erased`." schema: { type: string } responses: "200": @@ -2956,7 +2956,7 @@ paths: - $ref: "#/components/parameters/PerPage" - name: event in: query - description: "`created`, `updated`, `published`, `unpublished`, `deleted`, `restored` or `erased`." + description: "`created`, `updated`, `published`, `scheduled`, `unpublished`, `deleted`, `restored` or `erased`." schema: { type: string } responses: "200": @@ -2979,7 +2979,7 @@ paths: - $ref: "#/components/parameters/PerPage" - name: event in: query - description: "`created`, `updated`, `published`, `unpublished`, `deleted`, `restored` or `erased`." + description: "`created`, `updated`, `published`, `scheduled`, `unpublished`, `deleted`, `restored` or `erased`." schema: { type: string } responses: "200": @@ -3002,7 +3002,7 @@ paths: - $ref: "#/components/parameters/PerPage" - name: event in: query - description: "`created`, `updated`, `published`, `unpublished`, `deleted`, `restored` or `erased`." + description: "`created`, `updated`, `published`, `scheduled`, `unpublished`, `deleted`, `restored` or `erased`." schema: { type: string } responses: "200": @@ -5710,7 +5710,7 @@ components: type: object properties: id: { type: integer } - event: { type: string, enum: [created, updated, published, unpublished, deleted, restored, erased] } + event: { type: string, enum: [created, updated, published, scheduled, unpublished, deleted, restored, erased] } author: type: object properties: diff --git a/tests/Feature/Api/ReviewAndHistoryApiTest.php b/tests/Feature/Api/ReviewAndHistoryApiTest.php index d9338f9..8ba9e0f 100644 --- a/tests/Feature/Api/ReviewAndHistoryApiTest.php +++ b/tests/Feature/Api/ReviewAndHistoryApiTest.php @@ -158,6 +158,10 @@ class ReviewAndHistoryApiTest extends TestCase ->assertJsonPath('data.awaiting_review', false) ->assertJsonPath('data.published_at', $at->toIso8601String()); + // A date in the future is neither live nor taken down, and the + // history says so. + $this->assertSame('scheduled', $project->revisions()->first()->event); + $this->postJson("/api/v1/projects/{$project->id}/unpublish") ->assertOk() ->assertJsonPath('data.published_at', null);