Skip to content

Commit

Permalink
Adding multiple comments if a comment exceeds Deck 1000char limit.
Browse files Browse the repository at this point in the history
Notify user that the request is being worked on.
Better error handling.
Attachments added in card description rather than as a comment.
Using Toast for progress messages.
  • Loading branch information
lucianpricop committed May 25, 2022
1 parent 10f7b2e commit a6f53e3
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 21 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
## 1.0.2 – 2022-05-25
Adding multiple comments if a comment exceeds Deck 1000char limit.
Notify user that the request is being worked on.
Better error handling.
Attachments added in card description rather than as a comment.
Using Toast for progress messages.

## 1.0.1 – 2022-05-24
Fixed issues where title was longer than 255chars
Upgraded version support to NC23 and NC24
2 changes: 1 addition & 1 deletion appinfo/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<name>Deck Import From Trello</name>
<summary>nextcloud app that allows Deck import from Trello export to JSON file</summary>
<description><![CDATA[nextcloud app that allows Deck import from Trello export to JSON file]]></description>
<version>1.0.1</version>
<version>1.0.2</version>
<licence>agpl</licence>
<author mail="[email protected]" homepage="https://newro.co">newroco</author>
<namespace>DeckImportFromTrello</namespace>
Expand Down
13 changes: 10 additions & 3 deletions js/deckimportfromtrello.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,25 @@

function importFile($file) {
var data = {
id: $file.attr('data-id'),
fileId: $file.attr('data-id'),
};
OCP.Toast.info('Board import started.');

$.ajax({
url: url,
type: "post",
data: data,
success: function (data) {
//
if(data.boardUrl){
OCP.Toast.info('<a href="' + data.boardUrl + '">Board was imported successfully</a>',{'isHTML':true});
}
},
error: function (jqXHR, textStatus, errorThrown) {
alert('Something went wrong');
let message = '';
if(jqXHR.responseJSON && jqXHR.responseJSON.message){
message = jqXHR.responseJSON.message;
}
OCP.Toast.error('Something went wrong: ' + message);
},
});
}
Expand Down
26 changes: 13 additions & 13 deletions lib/Controller/PageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use Httpful\Request;
use OCA\Deck\Service\BoardService;
use OCA\DeckImportFromTrello\Activity\FileImportEvent;
use OCA\DeckImportFromTrello\Db\File;
use OCA\DeckImportFromTrello\Activity\EventHandler;
use OCA\DeckImportFromTrello\Services\DeckImportFromTrelloService;
use OCA\DeckImportFromTrello\Services\UserService;
use OCP\AppFramework\Http\JSONResponse;
Expand All @@ -14,10 +14,12 @@
use OCP\IServerContainer;
use OCP\AppFramework\Controller;
use OCP\AppFramework\App;
use OCP\Files\File;

class PageController extends Controller
{
private $userId;
private $eventHandler;
protected $storage;
protected $server;
/**
Expand All @@ -30,15 +32,18 @@ public function __construct(
$AppName,
IRequest $request,
IServerContainer $server,
DeckImportFromTrelloService $deckImportFromTrelloService,
IRootFolder $storage,
EventHandler $eventHandler,
DeckImportFromTrelloService $deckImportFromTrelloService,

$UserId
) {
parent::__construct($AppName, $request);

$this->server = $server;
$this->userId = $UserId;
$this->storage = $storage;
$this->eventHandler = $eventHandler;
$this->deckImportFromTrelloService = $deckImportFromTrelloService;
}

Expand All @@ -47,9 +52,9 @@ public function __construct(
* @param $id
* @return JSONResponse
*/
public function store($id)
public function store($fileId)
{
if (!$id) {
if (!$fileId) {
return new JSONResponse([
'message' => 'File required.',
], 403);
Expand All @@ -59,10 +64,10 @@ public function store($id)

try {
// Read file contents
$files = $userFolder->getById((int)$id);
$files = $userFolder->getById((int)$fileId);
$file = $files[0];

if ( ! $file instanceof \OCP\Files\File) {
if ( ! $file instanceof File) {
throw new StorageException('Can not read from folder');
}

Expand All @@ -71,11 +76,6 @@ public function store($id)
$contents = $file->getContent();

$board = $this->deckImportFromTrelloService->parseJsonAndImport($contents);

// $boardUrl = ($this->server->getURLGenerator())->linkToRouteAbsolute('deck.board.read', [
// 'boardId' => $board->getId()
// ]);

$boardUrl = ($this->server->getURLGenerator())->linkToRouteAbsolute('deck.board.index');
$boardUrl = str_replace('/boards', '/#/board/' . $board->getId(), $boardUrl);

Expand All @@ -86,11 +86,11 @@ public function store($id)
UserService::getUser()
);

$eventHandler = (new App('deckimportfromtrello'))->getContainer()->query('OCA\DeckImportFromTrello\Activity\EventHandler');
$eventHandler->handle($fileImportedEvent);
$this->eventHandler->handle($fileImportedEvent);

return new JSONResponse([
'content' => 'Success',
'boardUrl' => $boardUrl
]);
} catch (\Exception $exception) {
return new JSONResponse([
Expand Down
26 changes: 22 additions & 4 deletions lib/Services/DeckImportFromTrelloService.php
Original file line number Diff line number Diff line change
Expand Up @@ -208,15 +208,15 @@ private function parseCards($cards, $checklists)
$dueDate = $card['due'];

if (count($card['idMembers'])) {
$description .= "\n Card was assigned to ";
$description .= "\n\n Card was assigned to ";

foreach ($card['idMembers'] as $key => $member) {
$card['idMembers'][$key] = $this->members[$member];
}

$description .= implode(',',$card['idMembers']);

$description .= "\n";
$description .= "\n\n";
}

if (count($card['idChecklists'])) {
Expand All @@ -233,14 +233,25 @@ private function parseCards($cards, $checklists)
}
}

if (count($card['attachments'])) {

$description .= "\n\nTrello Attachments: \n";

foreach ($card['attachments'] as $attachment) {
if (!$attachment['isUpload']) {
continue;
}
$description .= " - " . $attachment['name'] . " (" . $attachment['url'] . ")\n";
}
}

$order = $card['idShort'];

$cardId = $this->createCard($title, $newStackID, $order, $description, $dueDate);

$this->cards[$id] = $cardId;

// $this->createAttachments($card, $cardId);
$this->addAttachmentsAsComments($card, $cardId);
}
}

Expand Down Expand Up @@ -373,7 +384,14 @@ private function createCard($title, $stackID, $order, $description, $duedate = n
*/
private function createComment(int $cardId, string $message, int $parentId)
{
return $this->commentService->create($cardId, $message, $parentId);
while(mb_strlen($message) > 1000){
$subComment = mb_substr($message,0,1000);
$this->commentService->create($cardId, $subComment, $parentId);
$message = mb_substr($message,1000);
}
if(mb_strlen($message) > 0){
$this->commentService->create($cardId, $message, $parentId);
}
}

protected function addAttachmentsAsComments(array $card, int $cardId)
Expand Down

0 comments on commit a6f53e3

Please sign in to comment.