Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
['name' => 'board#clone', 'url' => '/boards/{boardId}/clone', 'verb' => 'POST'],
['name' => 'board#transferOwner', 'url' => '/boards/{boardId}/transferOwner', 'verb' => 'PUT'],
['name' => 'board#export', 'url' => '/boards/{boardId}/export', 'verb' => 'GET'],
['name' => 'board#import', 'url' => '/boards/import', 'verb' => 'POST'],

// stacks
['name' => 'stack#index', 'url' => '/stacks/{boardId}', 'verb' => 'GET'],
Expand Down
78 changes: 78 additions & 0 deletions cypress/e2e/boardFeatures.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,3 +129,81 @@ describe('Board cloning', function() {
})
})
})

describe('Board export', function() {
before(function() {
cy.createUser(user)
})

it('Exports a board as JSON', function() {
const boardName = 'Export JSON board'
const board = sampleBoard(boardName)
cy.createExampleBoard({ user, board }).then((board) => {
const boardId = board.id
cy.visit(`/apps/deck/board/${boardId}`)
cy.get('.app-navigation__list .app-navigation-entry:contains("' + boardName + '")')
.parent()
.find('button[aria-label="Actions"]')
.click()
cy.get('button:contains("Export board")')
.click()
cy.get('.modal-container .checkbox-radio-switch__text:contains("Export as JSON")')
.click()
cy.get('.modal-container button:contains("Export")')
.click()

const downloadsFolder = Cypress.config('downloadsFolder')
cy.readFile(`${downloadsFolder}/${boardName}.json`)
})
})

it('Exports a board as CSV', function() {
const boardName = 'Export CSV board'
const board = sampleBoard(boardName)
cy.createExampleBoard({ user, board }).then((board) => {
const boardId = board.id
cy.visit(`/apps/deck/board/${boardId}`)
cy.get('.app-navigation__list .app-navigation-entry:contains("' + boardName + '")')
.parent()
.find('button[aria-label="Actions"]')
.click()
cy.get('button:contains("Export board")')
.click()
cy.get('.modal-container .checkbox-radio-switch__text:contains("Export as CSV")')
.click()
cy.get('.modal-container button:contains("Export")')
.click()

const downloadsFolder = Cypress.config('downloadsFolder')
cy.readFile(`${downloadsFolder}/${boardName}.csv`)
})
})
})

describe('Board import', function() {
before(function () {
cy.createUser(user)
})
beforeEach(function() {
cy.login(user)
cy.visit('/apps/deck')
})

it('Imports a board from JSON', function() {
cy.get('#app-navigation-vue .app-navigation__list .app-navigation-entry:contains("Import board")')
.should('be.visible')
.click()

// Upload a JSON file
cy.get('input[type="file"]')
.selectFile([
{
contents: 'cypress/fixtures/import-board.json',
fileName: 'import-board.json',
},
], { force: true })

cy.get('.app-navigation__list .app-navigation-entry:contains("Imported board")')
.should('be.visible')
})
})
102 changes: 102 additions & 0 deletions cypress/fixtures/import-board.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
{
"boards": [
{
"id": 70,
"title": "Imported board",
"owner": "unvjrmwuag",
"color": "00ff00",
"archived": false,
"labels": [
{
"id": 293,
"title": "Finished",
"color": "31CC7C",
"boardId": 70,
"cardId": null,
"lastModified": 0,
"ETag": "cfcd208495d565ef66e7dff9f98764da"
},
{
"id": 294,
"title": "To review",
"color": "317CCC",
"boardId": 70,
"cardId": null,
"lastModified": 0,
"ETag": "cfcd208495d565ef66e7dff9f98764da"
},
{
"id": 295,
"title": "Action needed",
"color": "FF7A66",
"boardId": 70,
"cardId": null,
"lastModified": 0,
"ETag": "cfcd208495d565ef66e7dff9f98764da"
},
{
"id": 296,
"title": "Later",
"color": "F1DB50",
"boardId": 70,
"cardId": null,
"lastModified": 0,
"ETag": "cfcd208495d565ef66e7dff9f98764da"
}
],
"acl": [],
"permissions": [],
"users": [],
"stacks": {
"114": {
"id": 114,
"title": "TestList",
"boardId": 70,
"deletedAt": 0,
"lastModified": 1743495533,
"cards": [
{
"id": 124,
"title": "Hello world",
"description": "# Hello world",
"descriptionPrev": null,
"stackId": 114,
"type": "plain",
"lastModified": 1743495533,
"lastEditor": null,
"createdAt": 1743495533,
"labels": [],
"assignedUsers": null,
"attachments": null,
"attachmentCount": null,
"owner": {
"primaryKey": "unvjrmwuag",
"uid": "unvjrmwuag",
"displayname": "unvjrmwuag",
"type": 0
},
"order": 999,
"archived": false,
"done": null,
"duedate": null,
"notified": false,
"deletedAt": 0,
"commentsUnread": 0,
"commentsCount": 0,
"relatedStack": null,
"relatedBoard": null,
"ETag": "aa85bb973089e7fbc0bbf122e926c23f"
}
],
"order": 0,
"ETag": "aa85bb973089e7fbc0bbf122e926c23f"
}
},
"activeSessions": [],
"deletedAt": 0,
"lastModified": 1743495533,
"settings": [],
"ETag": "aa85bb973089e7fbc0bbf122e926c23f"
}
]
}
62 changes: 62 additions & 0 deletions lib/Controller/BoardController.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@
use OCA\Deck\Db\Acl;
use OCA\Deck\Db\Board;
use OCA\Deck\Service\BoardService;
use OCA\Deck\Service\Importer\BoardImportService;
use OCA\Deck\Service\PermissionService;
use OCP\AppFramework\ApiController;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\DataResponse;
use OCP\IL10N;
use OCP\IRequest;

class BoardController extends ApiController {
Expand All @@ -22,6 +24,8 @@ public function __construct(
IRequest $request,
private BoardService $boardService,
private PermissionService $permissionService,
private BoardImportService $boardImportService,
private IL10N $l10n,
private $userId,
) {
parent::__construct($appName, $request);
Expand Down Expand Up @@ -163,4 +167,62 @@ public function transferOwner(int $boardId, string $newOwner): DataResponse {
public function export($boardId) {
return $this->boardService->export($boardId);
}

/**
* @NoAdminRequired
*/
public function import(): DataResponse {
$file = $this->request->getUploadedFile('file');
$error = null;
$phpFileUploadErrors = [
UPLOAD_ERR_OK => $this->l10n->t('The file was uploaded'),
UPLOAD_ERR_INI_SIZE => $this->l10n->t('The uploaded file exceeds the upload_max_filesize directive in php.ini'),
UPLOAD_ERR_FORM_SIZE => $this->l10n->t('The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form'),
UPLOAD_ERR_PARTIAL => $this->l10n->t('The file was only partially uploaded'),
UPLOAD_ERR_NO_FILE => $this->l10n->t('No file was uploaded'),
UPLOAD_ERR_NO_TMP_DIR => $this->l10n->t('Missing a temporary folder'),
UPLOAD_ERR_CANT_WRITE => $this->l10n->t('Could not write file to disk'),
UPLOAD_ERR_EXTENSION => $this->l10n->t('A PHP extension stopped the file upload'),
];

if (empty($file)) {
$error = $this->l10n->t('No file uploaded or file size exceeds maximum of %s', [\OCP\Util::humanFileSize(\OCP\Util::uploadLimit())]);
}
if (!empty($file) && array_key_exists('error', $file) && $file['error'] !== UPLOAD_ERR_OK) {
$error = $phpFileUploadErrors[$file['error']];
}
if (!empty($file) && $file['error'] === UPLOAD_ERR_OK && !in_array($file['type'], ['application/json', 'text/plain'])) {
$error = $this->l10n->t('Invalid file type. Only JSON files are allowed.');
}
if ($error !== null) {
return new DataResponse([
'status' => 'error',
'message' => $error,
], Http::STATUS_BAD_REQUEST);
}

try {
$fileContent = file_get_contents($file['tmp_name']);
$this->boardImportService->setSystem('DeckJson');
$config = new \stdClass();
$config->owner = $this->userId;
$this->boardImportService->setConfigInstance($config);
$this->boardImportService->setData(json_decode($fileContent));
$this->boardImportService->import();
$importedBoard = $this->boardImportService->getBoard();
$board = $this->boardService->find($importedBoard->getId());

return new DataResponse($board, Http::STATUS_OK);
} catch (\TypeError $e) {
return new DataResponse([
'status' => 'error',
'message' => $this->l10n->t('Invalid JSON data'),
], Http::STATUS_BAD_REQUEST);
} catch (\Exception $e) {
return new DataResponse([
'status' => 'error',
'message' => $this->l10n->t('Failed to import board'),
], Http::STATUS_BAD_REQUEST);
}
}
}
3 changes: 3 additions & 0 deletions src/components/navigation/AppNavigation.vue
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
</template>
</AppNavigationBoardCategory>
<AppNavigationAddBoard v-if="canCreate" />
<AppNavigationImportBoard v-if="canCreate" />
</template>
<template #footer>
<NcAppNavigationSettings :name="t('deck', 'Deck settings')">
Expand Down Expand Up @@ -116,6 +117,7 @@ import DeckIcon from './../icons/DeckIcon.vue'
import ShareVariantIcon from 'vue-material-design-icons/Share.vue'
import HelpModal from './../modals/HelpModal.vue'
import { subscribe } from '@nextcloud/event-bus'
import AppNavigationImportBoard from './AppNavigationImportBoard.vue'

const canCreateState = loadState('deck', 'canCreate')

Expand All @@ -127,6 +129,7 @@ export default {
NcButton,
AppNavigationAddBoard,
AppNavigationBoardCategory,
AppNavigationImportBoard,
NcSelect,
NcAppNavigationItem,
ArchiveIcon,
Expand Down
19 changes: 18 additions & 1 deletion src/components/navigation/AppNavigationBoard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
<template #icon>
<NcAppNavigationIconBullet :color="board.color" />
<BoardCloneModal v-if="cloneModalOpen" :board-title="board.title" @close="onCloseCloneModal" />
<BoardExportModal v-if="exportModalOpen"
:board-title="board.title"
@export="onExportBoard"
@close="onCloseExportBoard" />
</template>

<template #counter>
Expand Down Expand Up @@ -161,6 +165,8 @@ import { emit } from '@nextcloud/event-bus'

import isTouchDevice from '../../mixins/isTouchDevice.js'
import BoardCloneModal from './BoardCloneModal.vue'
import BoardExportModal from './BoardExportModal.vue'
import { showLoading } from '@nextcloud/dialogs'

const canCreateState = loadState('deck', 'canCreate')

Expand All @@ -179,6 +185,7 @@ export default {
CloseIcon,
CheckIcon,
BoardCloneModal,
BoardExportModal,
},
directives: {
ClickOutside,
Expand Down Expand Up @@ -207,6 +214,7 @@ export default {
updateDueSetting: null,
canCreate: canCreateState,
cloneModalOpen: false,
exportModalOpen: false,
}
},
computed: {
Expand Down Expand Up @@ -346,7 +354,16 @@ export default {
this.updateDueSetting = null
},
actionExport() {
this.boardApi.exportBoard(this.board)
this.exportModalOpen = true
},
async onExportBoard(format) {
this.exportModalOpen = false
const loadingToast = showLoading(t('deck', 'Exporting board...'))
await this.boardApi.exportBoard(this.board, format)
loadingToast.hideToast()
},
onCloseExportBoard() {
this.exportModalOpen = false
},
onNavigate() {
if (this.isTouchDevice) {
Expand Down
Loading
Loading