You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
77 lines
2.8 KiB
77 lines
2.8 KiB
// Cards module - everything related to cards should go here (database install is automatic for AO server so no feature module) |
|
import { getCardByName, createCard, prioritizeCard } from '../ao-lib/api.js' |
|
import { headerStyle } from './styles.js' |
|
import { prioritiesMenu } from './priority.js' |
|
import { subcardsMenu } from './hand.js' |
|
import { aoEnv } from '../ao-lib/settings.js' |
|
import { promptMenu, askQuestionText } from './welcome.js' |
|
import { tagsMenu } from './tags.js' |
|
|
|
// The card menu is complex and so has been split into this separate file |
|
export async function cardMenu() { |
|
const cardChoices = [ |
|
{ title: 'Top priorities', value: 'priorities', short: 'priorities' }, // hand? (7) (add #s in parens) |
|
{ title: 'Cards in hand', value: 'subcards', short: 'hand' }, // (current) deck? (60) |
|
{ title: 'Tags', value: 'tags', short: 'tags' }, // magically abstracting hierarchical nametags |
|
//{ title: 'Browse full deck', value: 'search', short: 'browse' }, // archive? (10,000) // will become search-as-you-type for card |
|
'Back to AO Menu' |
|
] |
|
const answer = await promptMenu(cardChoices, 'My Deck') |
|
switch(answer) { |
|
case 'priorities': |
|
while(await prioritiesMenu()) {} |
|
break |
|
case 'subcards': |
|
let previousAnswer |
|
do { |
|
previousAnswer = await subcardsMenu(undefined, previousAnswer) // undefined taskId defaults to member card |
|
} while(previousAnswer !== false) {} |
|
break |
|
case 'tags': |
|
while(await tagsMenu()) {} |
|
break |
|
case 'browse': |
|
while(await browseMenu()) {} |
|
break |
|
default: |
|
return false |
|
} |
|
return true |
|
} |
|
|
|
async function browseMenu() { |
|
console.log('Not yet implemented') |
|
} |
|
|
|
// Ask the user to create a card, checks if it already exists, and then creates it if it doesn't |
|
export async function createCardInteractive(prioritized = false) { |
|
const memberId = aoEnv('AO_CLI_SESSION_MEMBERID') |
|
if(!memberId) { |
|
console.log('Not logged in.') |
|
return false |
|
} |
|
const answer = await askQuestionText('New card or Enter to end:') |
|
if(answer === false || answer.trim().length <= 0) { |
|
return false |
|
} |
|
// Check if the card alerady exists |
|
const fetchedCards = await getCardByName(answer, false) |
|
if(fetchedCards && fetchedCards.length >= 1) { |
|
if(fetchedCards.length >= 2) { |
|
console.log('More than one copy of this card was found. This should not happen.') |
|
} |
|
if(prioritized) { |
|
console.log('Card already exists, prioritizing.') |
|
const prioritizeResult = await prioritizeCard(fetchedCards[0].taskId, memberId) |
|
if(!prioritizeResult.ok) { |
|
console.log('May have failed to prioritize card:', prioritizeResult) |
|
} |
|
} else { |
|
// todo: subtask the card |
|
} |
|
return answer |
|
} |
|
console.log('card does not exist yet. creating...', answer) |
|
const result = await createCard(answer, false, prioritized) |
|
return answer |
|
}
|
|
|