mirror of
https://github.com/mattermost/focalboard.git
synced 2025-05-31 22:24:57 +02:00
fixed asana import
This commit is contained in:
parent
2d356c696b
commit
9f2cf6730e
@ -5,6 +5,7 @@ import minimist from 'minimist'
|
|||||||
import {exit} from 'process'
|
import {exit} from 'process'
|
||||||
import {ArchiveUtils} from '../util/archive'
|
import {ArchiveUtils} from '../util/archive'
|
||||||
import {Block} from '../../webapp/src/blocks/block'
|
import {Block} from '../../webapp/src/blocks/block'
|
||||||
|
import {Board} from '../../webapp/src/blocks/board'
|
||||||
import {IPropertyOption, IPropertyTemplate, createBoard} from '../../webapp/src/blocks/board'
|
import {IPropertyOption, IPropertyTemplate, createBoard} from '../../webapp/src/blocks/board'
|
||||||
import {createBoardView} from '../../webapp/src/blocks/boardView'
|
import {createBoardView} from '../../webapp/src/blocks/boardView'
|
||||||
import {createCard} from '../../webapp/src/blocks/card'
|
import {createCard} from '../../webapp/src/blocks/card'
|
||||||
@ -49,11 +50,11 @@ function main() {
|
|||||||
const input = JSON.parse(inputData) as Asana
|
const input = JSON.parse(inputData) as Asana
|
||||||
|
|
||||||
// Convert
|
// Convert
|
||||||
const blocks = convert(input)
|
const [boards, blocks] = convert(input)
|
||||||
|
|
||||||
// Save output
|
// Save output
|
||||||
// TODO: Stream output
|
// TODO: Stream output
|
||||||
const outputData = ArchiveUtils.buildBlockArchive(blocks)
|
const outputData = ArchiveUtils.buildBlockArchive(boards, blocks)
|
||||||
fs.writeFileSync(outputFile, outputData)
|
fs.writeFileSync(outputFile, outputData)
|
||||||
|
|
||||||
console.log(`Exported to ${outputFile}`)
|
console.log(`Exported to ${outputFile}`)
|
||||||
@ -88,22 +89,22 @@ function getSections(input: Asana, projectId: string): Workspace[] {
|
|||||||
return [...sectionMap.values()]
|
return [...sectionMap.values()]
|
||||||
}
|
}
|
||||||
|
|
||||||
function convert(input: Asana): Block[] {
|
function convert(input: Asana): [Board[], Block[]] {
|
||||||
const projects = getProjects(input)
|
const projects = getProjects(input)
|
||||||
if (projects.length < 1) {
|
if (projects.length < 1) {
|
||||||
console.error('No projects found')
|
console.error('No projects found')
|
||||||
return []
|
return [[],[]]
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Handle multiple projects
|
// TODO: Handle multiple projects
|
||||||
const project = projects[0]
|
const project = projects[0]
|
||||||
|
|
||||||
|
const boards: Board[] = []
|
||||||
const blocks: Block[] = []
|
const blocks: Block[] = []
|
||||||
|
|
||||||
// Board
|
// Board
|
||||||
const board = createBoard()
|
const board = createBoard()
|
||||||
console.log(`Board: ${project.name}`)
|
console.log(`Board: ${project.name}`)
|
||||||
board.rootId = board.id
|
|
||||||
board.title = project.name
|
board.title = project.name
|
||||||
|
|
||||||
// Convert sections (columns) to a Select property
|
// Convert sections (columns) to a Select property
|
||||||
@ -130,14 +131,14 @@ function convert(input: Asana): Block[] {
|
|||||||
options
|
options
|
||||||
}
|
}
|
||||||
board.cardProperties = [cardProperty]
|
board.cardProperties = [cardProperty]
|
||||||
blocks.push(board)
|
boards.push(board)
|
||||||
|
|
||||||
// Board view
|
// Board view
|
||||||
const view = createBoardView()
|
const view = createBoardView()
|
||||||
view.title = 'Board View'
|
view.title = 'Board View'
|
||||||
view.fields.viewType = 'board'
|
view.fields.viewType = 'board'
|
||||||
view.rootId = board.id
|
|
||||||
view.parentId = board.id
|
view.parentId = board.id
|
||||||
|
view.boardId = board.id
|
||||||
blocks.push(view)
|
blocks.push(view)
|
||||||
|
|
||||||
// Cards
|
// Cards
|
||||||
@ -146,7 +147,7 @@ function convert(input: Asana): Block[] {
|
|||||||
|
|
||||||
const outCard = createCard()
|
const outCard = createCard()
|
||||||
outCard.title = card.name
|
outCard.title = card.name
|
||||||
outCard.rootId = board.id
|
outCard.boardId = board.id
|
||||||
outCard.parentId = board.id
|
outCard.parentId = board.id
|
||||||
|
|
||||||
// Map lists to Select property options
|
// Map lists to Select property options
|
||||||
@ -168,8 +169,8 @@ function convert(input: Asana): Block[] {
|
|||||||
// console.log(`\t${card.notes}`)
|
// console.log(`\t${card.notes}`)
|
||||||
const text = createTextBlock()
|
const text = createTextBlock()
|
||||||
text.title = card.notes
|
text.title = card.notes
|
||||||
text.rootId = board.id
|
|
||||||
text.parentId = outCard.id
|
text.parentId = outCard.id
|
||||||
|
text.boardId = board.id
|
||||||
blocks.push(text)
|
blocks.push(text)
|
||||||
|
|
||||||
outCard.fields.contentOrder = [text.id]
|
outCard.fields.contentOrder = [text.id]
|
||||||
@ -179,7 +180,7 @@ function convert(input: Asana): Block[] {
|
|||||||
console.log('')
|
console.log('')
|
||||||
console.log(`Found ${input.data.length} card(s).`)
|
console.log(`Found ${input.data.length} card(s).`)
|
||||||
|
|
||||||
return blocks
|
return [boards, blocks]
|
||||||
}
|
}
|
||||||
|
|
||||||
function showHelp() {
|
function showHelp() {
|
||||||
|
@ -1,25 +1,31 @@
|
|||||||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||||
// See LICENSE.txt for license information.
|
// See LICENSE.txt for license information.
|
||||||
import {Block} from '../../webapp/src/blocks/block'
|
import {Block} from '../../webapp/src/blocks/block'
|
||||||
|
import {Board} from '../../webapp/src/blocks/board'
|
||||||
|
|
||||||
interface ArchiveHeader {
|
interface ArchiveHeader {
|
||||||
version: number
|
version: number
|
||||||
date: number
|
date: number
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// This schema allows the expansion of additional line types in the future
|
||||||
interface ArchiveLine {
|
interface ArchiveLine {
|
||||||
type: string,
|
type: string,
|
||||||
data: unknown,
|
data: unknown,
|
||||||
}
|
}
|
||||||
|
|
||||||
// This schema allows the expansion of additional line types in the future
|
|
||||||
interface BlockArchiveLine extends ArchiveLine {
|
interface BlockArchiveLine extends ArchiveLine {
|
||||||
type: 'block',
|
type: 'block',
|
||||||
data: Block
|
data: Block
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface BoardArchiveLine extends ArchiveLine {
|
||||||
|
type: 'board',
|
||||||
|
data: Board
|
||||||
|
}
|
||||||
|
|
||||||
class ArchiveUtils {
|
class ArchiveUtils {
|
||||||
static buildBlockArchive(blocks: readonly Block[]): string {
|
static buildBlockArchive(boards: readonly Board[], blocks: readonly Block[]): string {
|
||||||
const header: ArchiveHeader = {
|
const header: ArchiveHeader = {
|
||||||
version: 1,
|
version: 1,
|
||||||
date: Date.now(),
|
date: Date.now(),
|
||||||
@ -27,6 +33,17 @@ class ArchiveUtils {
|
|||||||
|
|
||||||
const headerString = JSON.stringify(header)
|
const headerString = JSON.stringify(header)
|
||||||
let content = headerString + '\n'
|
let content = headerString + '\n'
|
||||||
|
|
||||||
|
for (const board of boards) {
|
||||||
|
const line: BoardArchiveLine = {
|
||||||
|
type: 'board',
|
||||||
|
data: board,
|
||||||
|
}
|
||||||
|
const lineString = JSON.stringify(line)
|
||||||
|
content += lineString
|
||||||
|
content += '\n'
|
||||||
|
}
|
||||||
|
|
||||||
for (const block of blocks) {
|
for (const block of blocks) {
|
||||||
const line: BlockArchiveLine = {
|
const line: BlockArchiveLine = {
|
||||||
type: 'block',
|
type: 'block',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user