focalboard/webapp/src/archiver.ts

86 lines
2.7 KiB
TypeScript
Raw Normal View History

2020-10-20 21:50:53 +02:00
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import {IAppWindow} from './types'
Migrate webapp global state to redux (#737) * Migrating workspace tree to redux * More changes for use the redux store for boads and views * Taking into account the templates on websocket event updates * Fixing bug on boardTree maintenance * Websocket client now connects once and subscribe/desubscribe on the fly * Including usage of the new websocket client * More work around migrating to redux * WIP * WIP * WIP * WIP * WIP * WIP * Fixing some things * WIP * WIP * Another small fix * Restoring filtering, sorting and grouping * Fixing some other bugs * Add search text reducer * Fixing another drag and drop problem * Improve store names and api * Fixing small bgus * Some small fixes * fixing login * Fixing register page * Some other improvements * Removing unneeded old files * Removing the need of userCache * Fixing comments and fixing content ordering * Fixing sort * Fixing some TODOs * Fixing tests * Fixing snapshot * Fixing cypress tests * Fix eslint * Fixing server tests * Updating the add cards actions * Fixing some tiny navigation problems * Mocking the api calls to pass the tests * Migrating a new test to redux * Adding the card right after the insert of the block (not wait for ws event) * Showing the ws disconnect banner only after 5 seconds of disconnection * Fixing share view * Fix eslint * Fixing problem with sort/groupby modifications * Fixing some details on redirections and templates creation * Fixing small bugs around undo * Fix update properties on click outside the dialog * Improving the column resize look and feel * Removing the class based objects from the store (now they are all plain objects * Fix eslint * Fixing tests * Removing unneeded code
2021-08-02 17:46:00 +02:00
import {Block} from './blocks/block'
import {Board} from './blocks/board'
2020-10-20 21:52:56 +02:00
import mutator from './mutator'
import {Utils} from './utils'
2020-10-08 18:21:27 +02:00
declare let window: IAppWindow
2020-10-08 18:21:27 +02:00
class Archiver {
Migrate webapp global state to redux (#737) * Migrating workspace tree to redux * More changes for use the redux store for boads and views * Taking into account the templates on websocket event updates * Fixing bug on boardTree maintenance * Websocket client now connects once and subscribe/desubscribe on the fly * Including usage of the new websocket client * More work around migrating to redux * WIP * WIP * WIP * WIP * WIP * WIP * Fixing some things * WIP * WIP * Another small fix * Restoring filtering, sorting and grouping * Fixing some other bugs * Add search text reducer * Fixing another drag and drop problem * Improve store names and api * Fixing small bgus * Some small fixes * fixing login * Fixing register page * Some other improvements * Removing unneeded old files * Removing the need of userCache * Fixing comments and fixing content ordering * Fixing sort * Fixing some TODOs * Fixing tests * Fixing snapshot * Fixing cypress tests * Fix eslint * Fixing server tests * Updating the add cards actions * Fixing some tiny navigation problems * Mocking the api calls to pass the tests * Migrating a new test to redux * Adding the card right after the insert of the block (not wait for ws event) * Showing the ws disconnect banner only after 5 seconds of disconnection * Fixing share view * Fix eslint * Fixing problem with sort/groupby modifications * Fixing some details on redirections and templates creation * Fixing small bugs around undo * Fix update properties on click outside the dialog * Improving the column resize look and feel * Removing the class based objects from the store (now they are all plain objects * Fix eslint * Fixing tests * Removing unneeded code
2021-08-02 17:46:00 +02:00
static async exportBoardArchive(board: Board): Promise<void> {
this.exportArchive(mutator.exportArchive(board.id))
2020-10-20 21:50:53 +02:00
}
2020-10-20 22:36:54 +02:00
static async exportFullArchive(): Promise<void> {
this.exportArchive(mutator.exportArchive())
2020-10-20 21:50:53 +02:00
}
private static exportArchive(prom: Promise<Response>): void {
// TODO: don't download whole archive before presenting SaveAs dialog.
prom.then((response) => {
response.blob().
then((blob) => {
const link = document.createElement('a')
link.style.display = 'none'
2020-10-20 21:50:53 +02:00
const date = new Date()
const filename = `archive-${date.getFullYear()}-${date.getMonth() + 1}-${date.getDate()}.focalboard`
2020-10-20 21:50:53 +02:00
const file = new Blob([blob], {type: 'application/octet-stream'})
link.href = URL.createObjectURL(file)
link.download = filename
document.body.appendChild(link) // FireFox support
2020-10-20 21:50:53 +02:00
link.click()
2020-10-20 21:50:53 +02:00
// TODO: Review if this is needed in the future, this is to fix the problem with linux webview links
if (window.openInNewBrowser) {
window.openInNewBrowser(link.href)
}
// TODO: Remove or reuse link and revolkObjectURL to avoid memory leak
})
})
2020-10-20 21:50:53 +02:00
}
private static async importArchiveFromFile(file: File): Promise<void> {
const response = await mutator.importFullArchive(file)
if (response.status !== 200) {
Utils.log('ERROR importing archive: ' + response.text())
}
2021-03-02 22:21:55 +01:00
}
Migrate webapp global state to redux (#737) * Migrating workspace tree to redux * More changes for use the redux store for boads and views * Taking into account the templates on websocket event updates * Fixing bug on boardTree maintenance * Websocket client now connects once and subscribe/desubscribe on the fly * Including usage of the new websocket client * More work around migrating to redux * WIP * WIP * WIP * WIP * WIP * WIP * Fixing some things * WIP * WIP * Another small fix * Restoring filtering, sorting and grouping * Fixing some other bugs * Add search text reducer * Fixing another drag and drop problem * Improve store names and api * Fixing small bgus * Some small fixes * fixing login * Fixing register page * Some other improvements * Removing unneeded old files * Removing the need of userCache * Fixing comments and fixing content ordering * Fixing sort * Fixing some TODOs * Fixing tests * Fixing snapshot * Fixing cypress tests * Fix eslint * Fixing server tests * Updating the add cards actions * Fixing some tiny navigation problems * Mocking the api calls to pass the tests * Migrating a new test to redux * Adding the card right after the insert of the block (not wait for ws event) * Showing the ws disconnect banner only after 5 seconds of disconnection * Fixing share view * Fix eslint * Fixing problem with sort/groupby modifications * Fixing some details on redirections and templates creation * Fixing small bugs around undo * Fix update properties on click outside the dialog * Improving the column resize look and feel * Removing the class based objects from the store (now they are all plain objects * Fix eslint * Fixing tests * Removing unneeded code
2021-08-02 17:46:00 +02:00
static isValidBlock(block: Block): boolean {
2021-03-03 00:35:44 +01:00
if (!block.id || !block.rootId) {
return false
}
return true
}
2020-10-20 21:50:53 +02:00
static importFullArchive(onComplete?: () => void): void {
const input = document.createElement('input')
2020-10-20 21:52:56 +02:00
input.type = 'file'
input.accept = '.boardarchive'
2020-10-20 21:50:53 +02:00
input.onchange = async () => {
2020-11-13 02:24:24 +01:00
const file = input.files && input.files[0]
2021-03-02 22:21:55 +01:00
if (file) {
await Archiver.importArchiveFromFile(file)
2021-03-02 22:21:55 +01:00
}
2020-10-20 21:50:53 +02:00
onComplete?.()
2020-10-20 21:52:56 +02:00
}
2020-10-20 21:50:53 +02:00
2020-10-20 21:52:56 +02:00
input.style.display = 'none'
2020-10-20 21:50:53 +02:00
document.body.appendChild(input)
input.click()
// TODO: Remove or reuse input
}
2020-10-08 18:21:27 +02:00
}
2020-10-20 21:50:53 +02:00
export {Archiver}