Feat: Highlight cards with important labels
Signed-off-by: Kostiantyn Miakshyn <molodchick@gmail.com>
This commit is contained in:
@@ -50,10 +50,12 @@ class LabelApiController extends ApiController {
|
||||
*
|
||||
* @params $title
|
||||
* @params $color
|
||||
* @param array<string, scalar> $customSettings
|
||||
*
|
||||
* Create a new label
|
||||
*/
|
||||
public function create($title, $color) {
|
||||
$label = $this->labelService->create($title, $color, $this->request->getParam('boardId'));
|
||||
public function create($title, $color, array $customSettings = []) {
|
||||
$label = $this->labelService->create($title, $color, $this->request->getParam('boardId'), $customSettings);
|
||||
return new DataResponse($label, HTTP::STATUS_OK);
|
||||
}
|
||||
|
||||
@@ -64,10 +66,12 @@ class LabelApiController extends ApiController {
|
||||
*
|
||||
* @params $title
|
||||
* @params $color
|
||||
* @param array<string, scalar> $customSettings
|
||||
*
|
||||
* Update a specific label
|
||||
*/
|
||||
public function update($title, $color) {
|
||||
$label = $this->labelService->update($this->request->getParam('labelId'), $title, $color);
|
||||
public function update($title, $color, array $customSettings = []) {
|
||||
$label = $this->labelService->update($this->request->getParam('labelId'), $title, $color, $customSettings);
|
||||
return new DataResponse($label, HTTP::STATUS_OK);
|
||||
}
|
||||
|
||||
|
||||
@@ -25,10 +25,11 @@ class LabelController extends Controller {
|
||||
* @param $title
|
||||
* @param $color
|
||||
* @param $boardId
|
||||
* @param array<string, scalar> $customSettings
|
||||
* @return \OCP\AppFramework\Db\Entity
|
||||
*/
|
||||
public function create($title, $color, $boardId) {
|
||||
return $this->labelService->create($title, $color, $boardId);
|
||||
public function create($title, $color, $boardId, array $customSettings = []) {
|
||||
return $this->labelService->create($title, $color, $boardId, $customSettings);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -36,10 +37,11 @@ class LabelController extends Controller {
|
||||
* @param $id
|
||||
* @param $title
|
||||
* @param $color
|
||||
* @param array<string, scalar> $customSettings
|
||||
* @return \OCP\AppFramework\Db\Entity
|
||||
*/
|
||||
public function update($id, $title, $color) {
|
||||
return $this->labelService->update($id, $title, $color);
|
||||
public function update($id, $title, $color, array $customSettings = []) {
|
||||
return $this->labelService->update($id, $title, $color, $customSettings);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -9,6 +9,8 @@ namespace OCA\Deck\Db;
|
||||
|
||||
/**
|
||||
* @method getTitle(): string
|
||||
* @method getCustomSettings(): string
|
||||
* @method setCustomSettings(string $customSettings)
|
||||
*/
|
||||
class Label extends RelationalEntity {
|
||||
protected $title;
|
||||
@@ -16,15 +18,32 @@ class Label extends RelationalEntity {
|
||||
protected $boardId;
|
||||
protected $cardId;
|
||||
protected $lastModified;
|
||||
protected $customSettings;
|
||||
|
||||
public function __construct() {
|
||||
$this->addType('id', 'integer');
|
||||
$this->addType('boardId', 'integer');
|
||||
$this->addType('cardId', 'integer');
|
||||
$this->addType('lastModified', 'integer');
|
||||
$this->addType('customSettings', 'string');
|
||||
}
|
||||
|
||||
public function getETag() {
|
||||
return md5((string)$this->getLastModified());
|
||||
}
|
||||
|
||||
public function getCustomSettingsArray(): array {
|
||||
return $this->customSettings ? json_decode($this->customSettings, true) : [];
|
||||
}
|
||||
|
||||
public function setCustomSettingsArray(array $customSettings): void {
|
||||
$this->setCustomSettings(json_encode($customSettings ?: new \stdClass()));
|
||||
}
|
||||
|
||||
public function jsonSerialize(): array {
|
||||
$data = parent::jsonSerialize();
|
||||
$data['customSettings'] = $this->getCustomSettingsArray() ?: new \stdClass();
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
||||
32
lib/Migration/Version20000Date20250907000000.php
Normal file
32
lib/Migration/Version20000Date20250907000000.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* SPDX-FileCopyrightText: 2022 Nextcloud GmbH and Nextcloud contributors
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace OCA\Deck\Migration;
|
||||
|
||||
use Closure;
|
||||
use OCP\DB\ISchemaWrapper;
|
||||
use OCP\DB\Types;
|
||||
use OCP\Migration\IOutput;
|
||||
use OCP\Migration\SimpleMigrationStep;
|
||||
|
||||
class Version20000Date20250907000000 extends SimpleMigrationStep {
|
||||
public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper {
|
||||
/** @var ISchemaWrapper $schema */
|
||||
$schema = $schemaClosure();
|
||||
|
||||
$table = $schema->getTable('deck_labels');
|
||||
if (!$table->hasColumn('custom_settings')) {
|
||||
$table->addColumn('custom_settings', Types::JSON, [
|
||||
'notnull' => false,
|
||||
]);
|
||||
}
|
||||
|
||||
return $schema;
|
||||
}
|
||||
}
|
||||
@@ -340,7 +340,7 @@ class CardService {
|
||||
// clone labels that are assigned to card but don't exist in new board
|
||||
if (empty($filteredLabels)) {
|
||||
if ($this->permissionService->getPermissions($boardId)[Acl::PERMISSION_MANAGE] === true) {
|
||||
$newLabel = $this->labelService->create($label->getTitle(), $label->getColor(), $board->getId());
|
||||
$newLabel = $this->labelService->create($label->getTitle(), $label->getColor(), $board->getId(), $label->getCustomSettingsArray());
|
||||
$boardLabels[] = $label;
|
||||
$this->assignLabel($card->getId(), $newLabel->getId());
|
||||
}
|
||||
|
||||
@@ -62,6 +62,7 @@ class LabelService {
|
||||
* @param $title
|
||||
* @param $color
|
||||
* @param $boardId
|
||||
* @param array<string, scalar> $customSettings
|
||||
* @return \OCP\AppFramework\Db\Entity
|
||||
* @throws StatusException
|
||||
* @throws \OCA\Deck\NoPermissionException
|
||||
@@ -69,7 +70,7 @@ class LabelService {
|
||||
* @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException
|
||||
* @throws BadRequestException
|
||||
*/
|
||||
public function create($title, $color, $boardId) {
|
||||
public function create($title, $color, $boardId, array $customSettings = []) {
|
||||
$this->labelServiceValidator->check(compact('title', 'color', 'boardId'));
|
||||
|
||||
$this->permissionService->checkPermission(null, $boardId, Acl::PERMISSION_MANAGE);
|
||||
@@ -89,6 +90,7 @@ class LabelService {
|
||||
$label->setTitle($title);
|
||||
$label->setColor($color);
|
||||
$label->setBoardId($boardId);
|
||||
$label->setCustomSettingsArray($customSettings);
|
||||
$this->changeHelper->boardChanged($boardId);
|
||||
return $this->labelMapper->insert($label);
|
||||
}
|
||||
@@ -99,7 +101,7 @@ class LabelService {
|
||||
$originLabel = $this->find($labelId);
|
||||
$filteredValues = array_values(array_filter($boardLabels, fn ($item) => $item->getTitle() === $originLabel->getTitle()));
|
||||
if (empty($filteredValues)) {
|
||||
$label = $this->create($originLabel->getTitle(), $originLabel->getColor(), $targetBoardId);
|
||||
$label = $this->create($originLabel->getTitle(), $originLabel->getColor(), $targetBoardId, $originLabel->getCustomSettingsArray());
|
||||
return $label;
|
||||
}
|
||||
return $originLabel;
|
||||
@@ -130,6 +132,7 @@ class LabelService {
|
||||
* @param $id
|
||||
* @param $title
|
||||
* @param $color
|
||||
* @param array<string, scalar> $customSettings
|
||||
* @return \OCP\AppFramework\Db\Entity
|
||||
* @throws StatusException
|
||||
* @throws \OCA\Deck\NoPermissionException
|
||||
@@ -137,7 +140,7 @@ class LabelService {
|
||||
* @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException
|
||||
* @throws BadRequestException
|
||||
*/
|
||||
public function update($id, $title, $color) {
|
||||
public function update($id, $title, $color, array $customSettings = []) {
|
||||
$this->labelServiceValidator->check(compact('title', 'color', 'id'));
|
||||
|
||||
$this->permissionService->checkPermission($this->labelMapper, $id, Acl::PERMISSION_MANAGE);
|
||||
@@ -161,6 +164,7 @@ class LabelService {
|
||||
|
||||
$label->setTitle($title);
|
||||
$label->setColor($color);
|
||||
$label->setCustomSettingsArray($customSettings);
|
||||
$this->changeHelper->boardChanged($label->getBoardId());
|
||||
return $this->labelMapper->update($label);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user