Skip to content

Commit

Permalink
tests 0.1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
jgclark committed Sep 22, 2024
1 parent 30ff97c commit 24968e8
Show file tree
Hide file tree
Showing 5 changed files with 21,163 additions and 43 deletions.
25 changes: 19 additions & 6 deletions helpers/note.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import { displayTitle, type headingLevelType } from '@helpers/general'
import { toNPLocaleDateString } from '@helpers/NPdateTime'
import { findEndOfActivePartOfNote, findStartOfActivePartOfNote } from '@helpers/paragraph'
import { sortListBy } from '@helpers/sorting'
import { isOpen } from '@helpers/utils'
import { isOpen, isClosed, isDone, isScheduled } from '@helpers/utils'

// const pluginJson = 'helpers/note.js'

Expand Down Expand Up @@ -66,8 +66,9 @@ export function getNoteContextAsSuffix(filename: string, dateStyle: string): str
* Print summary of note details to log
* @author @eduardmet
* @param {TNote} note
* @param {boolean} alsoShowParagraphs?
*/
export function printNote(note: TNote): void {
export function printNote(note: TNote, alsoShowParagraphs: boolean = true): void {
if (note == null) {
logDebug('note/printNote()', 'No Note found!')
return
Expand All @@ -76,18 +77,30 @@ export function printNote(note: TNote): void {
if (note.type === 'Notes') {
logInfo(
'note/printNote',
`title: ${note.title ?? ''}\n\tfilename: ${note.filename ?? ''}\n\tcreated: ${String(note.createdDate) ?? ''}\n\tchanged: ${String(note.changedDate) ?? ''}\n\tparagraphs: ${
`title: ${note.title ?? ''}\n- filename: ${note.filename ?? ''}\n- created: ${String(note.createdDate) ?? ''}\n- changed: ${String(note.changedDate) ?? ''}\n- paragraphs: ${
note.paragraphs.length
}\n\thashtags: ${note.hashtags?.join(',') ?? ''}\n\tmentions: ${note.mentions?.join(',') ?? ''}`,
}\n- hashtags: ${note.hashtags?.join(', ') ?? ''}\n- mentions: ${note.mentions?.join(', ') ?? ''}`,
)
} else {
logInfo(
'note/printNote',
`filename: ${note.filename ?? ''}\n\tcreated: ${String(note.createdDate) ?? ''}\n\tchanged: ${String(note.changedDate) ?? ''}\n\tparagraphs: ${
`filename: ${note.filename ?? ''}\n- created: ${String(note.createdDate) ?? ''}\n- changed: ${String(note.changedDate) ?? ''}\n- paragraphs: ${
note.paragraphs.length
}\n\thashtags: ${note.hashtags?.join(',') ?? ''}\n\tmentions: ${note.mentions?.join(',') ?? ''}`,
}\n- hashtags: ${note.hashtags?.join(', ') ?? ''}\n- mentions: ${note.mentions?.join(', ') ?? ''}`,
)
}
if (note.paragraphs.length > 0) {
const open = note.paragraphs.filter((p) => isOpen(p)).length
const done = note.paragraphs.filter((p) => isDone(p)).length
const closed = note.paragraphs.filter((p) => isClosed(p)).length
const scheduled = note.paragraphs.filter((p) => isScheduled(p)).length
console.log(
`- open: ${String(open)}\n- done: ${String(done)}\n- closed: ${String(closed)}\n- scheduled: ${String(scheduled)}`
)
if (alsoShowParagraphs) {
note.paragraphs.map((p) => console.log(`- ${p.lineIndex}: ${p.type} ${p.rawContent}`))
}
}
}

/**
Expand Down
83 changes: 46 additions & 37 deletions helpers/userInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -669,43 +669,52 @@ export async function chooseNote(
currentNoteFirst?: boolean = false,
allowNewNoteCreation?: boolean = false,
): Promise<TNote | null> {
let noteList = []
const projectNotes = DataStore.projectNotes
const calendarNotes = DataStore.calendarNotes
if (includeProjectNotes) {
noteList = noteList.concat(projectNotes)
}
if (includeCalendarNotes) {
noteList = noteList.concat(calendarNotes)
}
const noteListFiltered = noteList.filter((note) => {
// filter out notes that are in folders to ignore
let isInIgnoredFolder = false
foldersToIgnore.forEach((folder) => {
if (note.filename.includes(`${folder}/`)) {
isInIgnoredFolder = true
}
try {
let noteList: Array<TNote> = []
const projectNotes = DataStore.projectNotes
const calendarNotes = DataStore.calendarNotes
if (includeProjectNotes) {
noteList = noteList.concat(projectNotes)
}
if (includeCalendarNotes) {
noteList = noteList.concat(calendarNotes)
}
const noteListFiltered = noteList.filter((note) => {
// filter out notes that are in folders to ignore
let isInIgnoredFolder = false
foldersToIgnore.forEach((folder) => {
if (note.filename.includes(`${folder}/`)) {
isInIgnoredFolder = true
}
})
isInIgnoredFolder = isInIgnoredFolder || !/(\.md|\.txt)$/i.test(note.filename) //do not include non-markdown files
return !isInIgnoredFolder
})
isInIgnoredFolder = isInIgnoredFolder || !/(\.md|\.txt)$/i.test(note.filename) //do not include non-markdown files
return !isInIgnoredFolder
})
const sortedNoteListFiltered = noteListFiltered.sort((first, second) => second.changedDate - first.changedDate) // most recent first
const opts = sortedNoteListFiltered.map((note) => {
return displayTitleWithRelDate(note)
})
const { note } = Editor
if (allowNewNoteCreation) {
opts.unshift('[New note]')
sortedNoteListFiltered.unshift('[New note]') // just keep the indexes matching
}
if (currentNoteFirst && note) {
sortedNoteListFiltered.unshift(note)
opts.unshift(`[Current note: "${displayTitleWithRelDate(Editor)}"]`)
}
const { index } = await CommandBar.showOptions(opts, promptText)
let noteToReturn = sortedNoteListFiltered[index]
if (noteToReturn === '[New note]') {
noteToReturn = await createNewNote()
// $FlowIgnore[unsafe-arithmetic]
const sortedNoteListFiltered = noteListFiltered.sort((first, second) => second.changedDate - first.changedDate) // most recent first
const opts = sortedNoteListFiltered.map((note) => {
return displayTitleWithRelDate(note)
})
const { note } = Editor
if (allowNewNoteCreation) {
opts.unshift('[New note]')
}
if (currentNoteFirst && note) {
sortedNoteListFiltered.unshift(note)
opts.unshift(`[Current note: "${displayTitleWithRelDate(Editor)}"]`)
}
const { index, value } = await CommandBar.showOptions(opts, promptText)
if (allowNewNoteCreation) {
if (index === 0) {
return await createNewNote()
} else {
return sortedNoteListFiltered[index - 1]
}
} else {
return sortedNoteListFiltered[index]
}
} catch (error) {
logError('userInput / chooseNote', error.message)
return null
}
return noteToReturn ?? null
}
37 changes: 37 additions & 0 deletions jgclark.tests/plugin.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"noteplan.minAppVersion": "3.3.2",
"macOS.minVersion": "10.13.0",
"plugin.id": "jgclark.tests",
"plugin.name": "❓API Tests",
"plugin.description": "(Unpublished) API Tests by JGC",
"plugin.icon": "",
"plugin.author": "jgclark",
"plugin.url": "",
"plugin.version": "0.1.1",
"plugin.dependencies": [],
"plugin.script": "script.js",
"plugin.isRemote": "false",
"plugin.commands": [
{
"name": "test:invokePluginCommandByName",
"description": "invokePluginCommandByName",
"jsFunction": "invokePluginCommandByName"
},
{
"name": "test:note info",
"description": "log details of a note the user requests",
"jsFunction": "logNoteInfo"
},
{
"name": "test:current note info",
"description": "log details of the currently open note",
"jsFunction": "logCurrentNoteInfo"
},
{
"name": "test:show start active",
"description": "show first active line in the editor",
"jsFunction": "showStartActive"
}
],
"plugin.settings": []
}
Loading

0 comments on commit 24968e8

Please sign in to comment.