An interactive command-line interface (CLI) tool to help you install, use, and administer an AO instance.
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.

71 lines
2.5 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 './api.js'
import { headerStyle } from './styles.js'
import { prioritiesMenu } from './priority.js'
import { aoEnv } from './settings.js'
import { promptMenu, askQuestionText } from './welcome.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: 'Browse full deck', value: 'browse', short: 'browse' }, // archive? (10,000)
'Back to AO Menu'
]
const answer = await promptMenu(cardChoices, 'My Deck')
switch(answer.card_menu) {
case 'priorities':
while(await prioritiesMenu()) {}
break
case 'subcards':
while(await subcardsMenu()) {}
break
case 'browse':
while(await browseMenu()) {}
break
default:
return false
}
return true
}
async function subcardsMenu() {
console.log('Not yet implemented')
}
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 = true) {
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.new_card_text.trim().length <= 0) {
return false
}
// Check if the card alerady exists
const fetchedCards = await getCardByName(answer.new_card_text, 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)
}
}
return false
}
console.log('card does not exist yet. creating...', answer.new_card_text)
const result = await createCard(answer.new_card_text, false, true)
return answer.new_card_text
}