diff --git a/extensions/package-manager/extend.php b/extensions/package-manager/extend.php index 85a491f66..e2496d380 100755 --- a/extensions/package-manager/extend.php +++ b/extensions/package-manager/extend.php @@ -10,6 +10,7 @@ namespace Flarum\ExtensionManager; use Flarum\Extend; +use Flarum\ExtensionManager\Api\Resource\TaskResource; use Flarum\Foundation\Paths; use Flarum\Frontend\Document; use Illuminate\Contracts\Queue\Queue; @@ -25,9 +26,10 @@ return [ ->post('/extension-manager/minor-update', 'extension-manager.minor-update', Api\Controller\MinorUpdateController::class) ->post('/extension-manager/major-update', 'extension-manager.major-update', Api\Controller\MajorUpdateController::class) ->post('/extension-manager/global-update', 'extension-manager.global-update', Api\Controller\GlobalUpdateController::class) - ->get('/extension-manager-tasks', 'extension-manager.tasks.index', Api\Controller\ListTasksController::class) ->post('/extension-manager/composer', 'extension-manager.composer', Api\Controller\ConfigureComposerController::class), + (new Extend\ApiResource(TaskResource::class)), + (new Extend\Frontend('admin')) ->css(__DIR__.'/less/admin.less') ->js(__DIR__.'/js/dist/admin.js') diff --git a/extensions/package-manager/src/Api/Controller/ListTasksController.php b/extensions/package-manager/src/Api/Controller/ListTasksController.php deleted file mode 100644 index ab27fe9d1..000000000 --- a/extensions/package-manager/src/Api/Controller/ListTasksController.php +++ /dev/null @@ -1,58 +0,0 @@ -assertAdmin(); - - $limit = $this->extractLimit($request); - $offset = $this->extractOffset($request); - - $results = Task::query() - ->latest('id') - ->offset($offset) - ->limit($limit) - ->get(); - - $total = Task::query()->count(); - - $document->addMeta('total', (string) $total); - - $document->addPaginationLinks( - $this->url->to('api')->route('extension-manager.tasks.index'), - $request->getQueryParams(), - $offset, - $limit, - $total - ); - - return $results; - } -} diff --git a/extensions/package-manager/src/Api/Resource/TaskResource.php b/extensions/package-manager/src/Api/Resource/TaskResource.php new file mode 100644 index 000000000..1a25d3869 --- /dev/null +++ b/extensions/package-manager/src/Api/Resource/TaskResource.php @@ -0,0 +1,53 @@ +defaultSort('-createdAt') + ->paginate(), + ]; + } + + public function fields(): array + { + return [ + Schema\Str::make('status'), + Schema\Str::make('operation'), + Schema\Str::make('command'), + Schema\Str::make('package'), + Schema\Str::make('output'), + Schema\DateTime::make('createdAt'), + Schema\DateTime::make('startedAt'), + Schema\DateTime::make('finishedAt'), + Schema\Number::make('peakMemoryUsed'), + ]; + } + + public function sorts(): array + { + return [ + SortColumn::make('createdAt'), + ]; + } +} diff --git a/extensions/package-manager/src/Api/Serializer/TaskSerializer.php b/extensions/package-manager/src/Api/Serializer/TaskSerializer.php deleted file mode 100644 index 3781fca9a..000000000 --- a/extensions/package-manager/src/Api/Serializer/TaskSerializer.php +++ /dev/null @@ -1,50 +0,0 @@ - $model->status, - 'operation' => $model->operation, - 'command' => $model->command, - 'package' => $model->package, - 'output' => $model->output, - 'guessedCause' => $model->guessed_cause, - 'createdAt' => $model->created_at, - 'startedAt' => $model->started_at, - 'finishedAt' => $model->finished_at, - 'peakMemoryUsed' => $model->peak_memory_used, - ]; - } -} diff --git a/extensions/package-manager/src/Task/TaskRepository.php b/extensions/package-manager/src/Task/TaskRepository.php deleted file mode 100644 index dfe54e76c..000000000 --- a/extensions/package-manager/src/Task/TaskRepository.php +++ /dev/null @@ -1,34 +0,0 @@ -