Export Board

Signed-off-by: David Loe <d.loewens24@gmail.com>
This commit is contained in:
David Loe
2021-05-10 15:03:35 +02:00
committed by Julius Härtl
parent d3cad6adf0
commit 88a9fe2161
15 changed files with 153 additions and 27 deletions

View File

@@ -213,7 +213,7 @@ export default {
confirmClasses: 'error',
cancel: t('deck', 'Cancel'),
},
async (result) => {
async(result) => {
if (result) {
try {
this.isLoading = true

View File

@@ -225,7 +225,7 @@ export default {
},
shareFromFiles() {
picker.pick()
.then(async (path) => {
.then(async(path) => {
console.debug(`path ${path} selected for sharing`)
if (!path.startsWith('/')) {
throw new Error(t('files', 'Invalid path selected'))

View File

@@ -259,7 +259,7 @@ export default {
updateDescription() {
this.descriptionLastEdit = Date.now()
clearTimeout(this.descriptionSaveTimeout)
this.descriptionSaveTimeout = setTimeout(async () => {
this.descriptionSaveTimeout = setTimeout(async() => {
await this.saveDescription()
}, 2500)
},

View File

@@ -72,6 +72,13 @@
{{ t('deck', 'Archive board') }}
</NcActionButton>
<NcActionButton v-if="!board.archived && board.acl.length === 0" :icon="board.settings['notify-due'] === 'off' ? 'icon-sound' : 'icon-sound-off'" @click="board.settings['notify-due'] === 'off' ? updateSetting('notify-due', 'all') : updateSetting('notify-due', 'off')" />
<NcActionButton v-if="canManage && !board.archived"
icon="icon-download"
:close-after-click="true"
@click="actionExport">
{{ t('deck', 'Export board') }}
</NcActionButton>
<NcActionButton v-if="!board.archived && board.acl.length === 0" :icon="board.settings['notify-due'] === 'off' ? 'icon-sound' : 'icon-sound-off'" @click="board.settings['notify-due'] === 'off' ? updateSetting('notify-due', 'all') : updateSetting('notify-due', 'off')">
{{ board.settings['notify-due'] === 'off' ? t('deck', 'Turn on due date reminders') : t('deck', 'Turn off due date reminders') }}
</NcActionButton>
@@ -314,6 +321,9 @@ export default {
this.isDueSubmenuActive = false
this.updateDueSetting = null
},
actionExport() {
this.boardApi.exportBoard(this.board)
},
},
}
</script>

View File

@@ -71,7 +71,7 @@ const createCancelToken = () => axios.CancelToken.source()
function search({ query, cursor }) {
const cancelToken = createCancelToken()
const request = async () => axios.get(generateOcsUrl('apps/deck/api/v1.0/search'), {
const request = async() => axios.get(generateOcsUrl('apps/deck/api/v1.0/search'), {
cancelToken: cancelToken.token,
params: {
term: query,

View File

@@ -48,7 +48,7 @@ export default {
bodyFormData.append('cardId', this.cardId)
bodyFormData.append('type', type)
bodyFormData.append('file', file)
await queue.add(async () => {
await queue.add(async() => {
try {
await this.$store.dispatch('createAttachment', {
cardId: this.cardId,

View File

@@ -38,7 +38,7 @@ export class BoardApi {
* Updates a board.
*
* @param {Board} board the board object to update
* @return {Promise}
* @returns {Promise}
*/
updateBoard(board) {
return axios.put(this.url(`/boards/${board.id}`), board)
@@ -63,7 +63,7 @@ export class BoardApi {
* @property {string} color
* @param {BoardCreateObject} boardData The board data to send.
* color the hexadecimal color value formated /[0-9A-F]{6}/i
* @return {Promise}
* @returns {Promise}
*/
createBoard(boardData) {
return axios.post(this.url('/boards'), boardData)
@@ -149,6 +149,71 @@ export class BoardApi {
}
}
exportBoard(board) {
return axios.get(this.url(`/boards/${board.id}/export`))
.then(
(response) => {
const fields = { title: t('deck', 'Card title'), description: t('deck', 'Description'), stackId: t('deck', 'List name'), labels: t('deck', 'Tags'), duedate: t('deck', 'Due date'), createdAt: t('deck', 'Created'), lastModified: t('deck', 'Modified') }
let row = ''
Object.keys(fields).forEach(field => {
row += '"' + fields[field] + '"' + '\t'
})
row = row.slice(0, -1)
let CSV = row + '\r\n'
response.data.stacks.forEach(stack => {
stack.cards.forEach(card => {
row = ''
Object.keys(fields).forEach(field => {
if (field === 'createdAt' || field === 'lastModified') {
const date = new Date(Number(card[field]) * 1000)
row += '"' + date.toLocaleDateString() + '"' + '\t'
} else if (field === 'stackId') {
row += '"' + stack.title + '"' + '\t'
} else if (field === 'labels') {
row += '"'
card[field].forEach(label => {
row += label.title + ', '
})
if (card[field].length > 0) {
row = row.slice(0, -1)
}
row += '"' + '\t'
} else {
row += '"' + card[field] + '"' + '\t'
}
})
row = row.slice(0, -1)
CSV += row + '\r\n'
})
})
let charCode = []
const byteArray = []
byteArray.push(255, 254)
for (let i = 0; i < CSV.length; ++i) {
charCode = CSV.charCodeAt(i)
byteArray.push(charCode & 0xff)
byteArray.push(charCode / 256 >>> 0)
}
const blob = new Blob([new Uint8Array(byteArray)], { type: 'text/csv;charset=UTF-16LE;' })
const blobUrl = URL.createObjectURL(blob)
const a = document.createElement('a')
a.href = blobUrl // 'data:' + data
a.download = response.data.title + '.csv'
a.click()
a.remove()
return Promise.resolve()
},
(err) => {
return Promise.reject(err)
}
)
.catch((err) => {
return Promise.reject(err)
})
}
// Label API Calls
deleteLabel(id) {
return axios.delete(this.url(`/labels/${id}`))

View File

@@ -78,7 +78,7 @@ export class StackApi {
/**
* @param {Stack} stack stack object to create
* @return {Promise}
* @returns {Promise}
*/
createStack(stack) {
return axios.post(this.url('/stacks'), stack)

View File

@@ -378,7 +378,7 @@ export default new Vuex.Store({
* @param commit.commit
* @param commit
* @param board The board to update.
* @return {Promise<void>}
* @returns {Promise<void>}
*/
async updateBoard({ commit }, board) {
const storedBoard = await apiClient.updateBoard(board)

View File

@@ -46,7 +46,7 @@ export default {
ComponentVM.$destroy()
reject(new Error('Canceled'))
})
ComponentVM.$root.$on('select', async (id) => {
ComponentVM.$root.$on('select', async(id) => {
const result = await createShare({
path: self.fileInfo.path + '/' + self.fileInfo.name,
shareType: 12,