mirror of
https://github.com/BoostIo/Boostnote
synced 2025-12-14 02:06:29 +00:00
export tag
This commit is contained in:
@@ -26,6 +26,8 @@ import { confirmDeleteNote } from 'browser/lib/confirmDeleteNote'
|
|||||||
import ColorPicker from 'browser/components/ColorPicker'
|
import ColorPicker from 'browser/components/ColorPicker'
|
||||||
import { every, sortBy } from 'lodash'
|
import { every, sortBy } from 'lodash'
|
||||||
|
|
||||||
|
const { dialog } = remote
|
||||||
|
|
||||||
function matchActiveTags(tags, activeTags) {
|
function matchActiveTags(tags, activeTags) {
|
||||||
return every(activeTags, v => tags.indexOf(v) >= 0)
|
return every(activeTags, v => tags.indexOf(v) >= 0)
|
||||||
}
|
}
|
||||||
@@ -63,15 +65,12 @@ class SideNav extends React.Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
deleteTag(tag) {
|
deleteTag(tag) {
|
||||||
const selectedButton = remote.dialog.showMessageBox(
|
const selectedButton = dialog.showMessageBox(remote.getCurrentWindow(), {
|
||||||
remote.getCurrentWindow(),
|
|
||||||
{
|
|
||||||
type: 'warning',
|
type: 'warning',
|
||||||
message: i18n.__('Confirm tag deletion'),
|
message: i18n.__('Confirm tag deletion'),
|
||||||
detail: i18n.__('This will permanently remove this tag.'),
|
detail: i18n.__('This will permanently remove this tag.'),
|
||||||
buttons: [i18n.__('Confirm'), i18n.__('Cancel')]
|
buttons: [i18n.__('Confirm'), i18n.__('Cancel')]
|
||||||
}
|
})
|
||||||
)
|
|
||||||
|
|
||||||
if (selectedButton === 0) {
|
if (selectedButton === 0) {
|
||||||
const {
|
const {
|
||||||
@@ -155,28 +154,80 @@ class SideNav extends React.Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
handleTagContextMenu(e, tag) {
|
handleTagContextMenu(e, tag) {
|
||||||
const menu = []
|
context.popup([
|
||||||
|
{
|
||||||
menu.push({
|
label: i18n.__('Rename Tag'),
|
||||||
label: i18n.__('Delete Tag'),
|
click: this.handleRenameTagClick.bind(this, tag)
|
||||||
click: this.deleteTag.bind(this, tag)
|
},
|
||||||
})
|
{
|
||||||
|
|
||||||
menu.push({
|
|
||||||
label: i18n.__('Customize Color'),
|
label: i18n.__('Customize Color'),
|
||||||
click: this.displayColorPicker.bind(
|
click: this.displayColorPicker.bind(
|
||||||
this,
|
this,
|
||||||
tag,
|
tag,
|
||||||
e.target.getBoundingClientRect()
|
e.target.getBoundingClientRect()
|
||||||
)
|
)
|
||||||
})
|
},
|
||||||
|
{
|
||||||
|
type: 'separator'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: i18n.__('Export Tag'),
|
||||||
|
submenu: [
|
||||||
|
{
|
||||||
|
label: i18n.__('Export as Plain Text (.txt)'),
|
||||||
|
click: e => this.handleExportTagClick(e, tag, 'txt')
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: i18n.__('Export as Markdown (.md)'),
|
||||||
|
click: e => this.handleExportTagClick(e, tag, 'md')
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: i18n.__('Export as HTML (.html)'),
|
||||||
|
click: e => this.handleExportTagClick(e, tag, 'html')
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: i18n.__('Export as PDF (.pdf)'),
|
||||||
|
click: e => this.handleExportTagClick(e, tag, 'pdf')
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'separator'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: i18n.__('Delete Tag'),
|
||||||
|
click: this.deleteTag.bind(this, tag)
|
||||||
|
}
|
||||||
|
])
|
||||||
|
}
|
||||||
|
|
||||||
menu.push({
|
handleExportTagClick(e, tag, fileType) {
|
||||||
label: i18n.__('Rename Tag'),
|
const options = {
|
||||||
click: this.handleRenameTagClick.bind(this, tag)
|
properties: ['openDirectory', 'createDirectory'],
|
||||||
|
buttonLabel: i18n.__('Select directory'),
|
||||||
|
title: i18n.__('Select a folder to export the files to'),
|
||||||
|
multiSelections: false
|
||||||
|
}
|
||||||
|
dialog.showOpenDialog(remote.getCurrentWindow(), options, paths => {
|
||||||
|
if (paths && paths.length === 1) {
|
||||||
|
const { data, config } = this.props
|
||||||
|
dataApi
|
||||||
|
.exportTag(data, tag, fileType, paths[0], config)
|
||||||
|
.then(data => {
|
||||||
|
dialog.showMessageBox(remote.getCurrentWindow(), {
|
||||||
|
type: 'info',
|
||||||
|
message: `Exported to ${paths[0]}`
|
||||||
|
})
|
||||||
|
})
|
||||||
|
.catch(error => {
|
||||||
|
dialog.showErrorBox(
|
||||||
|
'Export error',
|
||||||
|
error ? error.message || error : 'Unexpected error during export'
|
||||||
|
)
|
||||||
|
throw error
|
||||||
|
})
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
context.popup(menu)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
dismissColorPicker() {
|
dismissColorPicker() {
|
||||||
|
|||||||
30
browser/main/lib/dataApi/exportTag.js
Normal file
30
browser/main/lib/dataApi/exportTag.js
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
import exportNoteAs from './exportNoteAs'
|
||||||
|
import filenamify from 'filenamify'
|
||||||
|
import path from 'path'
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {Object} data
|
||||||
|
* @param {String} tag
|
||||||
|
* @param {String} fileType
|
||||||
|
* @param {String} exportDir
|
||||||
|
* @param {Object} config
|
||||||
|
*/
|
||||||
|
|
||||||
|
function exportTag(data, tag, fileType, exportDir, config) {
|
||||||
|
const notes = data.noteMap
|
||||||
|
.map(note => note)
|
||||||
|
.filter(note => note.tags.indexOf(tag) !== -1)
|
||||||
|
|
||||||
|
return Promise.all(
|
||||||
|
notes.map(note => {
|
||||||
|
const filename = path.join(
|
||||||
|
exportDir,
|
||||||
|
`${filenamify(note.title, { replacement: '_' })}.${fileType}`
|
||||||
|
)
|
||||||
|
|
||||||
|
return exportNoteAs(note, filename, fileType, config)
|
||||||
|
})
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = exportTag
|
||||||
@@ -21,6 +21,7 @@ const dataApi = {
|
|||||||
deleteSnippet: require('./deleteSnippet'),
|
deleteSnippet: require('./deleteSnippet'),
|
||||||
updateSnippet: require('./updateSnippet'),
|
updateSnippet: require('./updateSnippet'),
|
||||||
fetchSnippet: require('./fetchSnippet'),
|
fetchSnippet: require('./fetchSnippet'),
|
||||||
|
exportTag: require('./exportTag'),
|
||||||
|
|
||||||
_migrateFromV6Storage: require('./migrateFromV6Storage'),
|
_migrateFromV6Storage: require('./migrateFromV6Storage'),
|
||||||
_resolveStorageData: require('./resolveStorageData'),
|
_resolveStorageData: require('./resolveStorageData'),
|
||||||
|
|||||||
Reference in New Issue
Block a user