@ -3,6 +3,7 @@ import inquirer from 'inquirer'
import { headerStyle } from './styles.js'
import { headerStyle } from './styles.js'
import { aoEnv } from './settings.js'
import { aoEnv } from './settings.js'
import { getCard , prioritizeCard , completeCard , uncheckCard , refocusCard } from './api.js'
import { getCard , prioritizeCard , completeCard , uncheckCard , refocusCard } from './api.js'
import { createCardInteractive } from './cards.js'
// Prints the text (.name) of the first card prioritized in the logged-in users member card
// Prints the text (.name) of the first card prioritized in the logged-in users member card
export async function getTopPriorityText ( ) {
export async function getTopPriorityText ( ) {
@ -46,9 +47,17 @@ export async function prioritiesMenu(taskId = null) {
return false
return false
}
}
const card = fetchedCards [ 0 ]
const card = fetchedCards [ 0 ]
cons t priorityCards = fetchedCards . slice ( 1 ) // First card is member card itself
le t priorityCards = fetchedCards . slice ( 1 ) // First card is member card itself
let priorities = card . priorities . slice ( )
let priorities = card . priorities . slice ( )
priorities . reverse ( )
priorities . reverse ( )
// Fix order - incoming card order is absolute order on server, not order within this card
priorityCards = priorities . map ( ( priorityTaskId , i ) => {
const priorityCard = priorityCards . find ( p => p . taskId === priorityTaskId )
if ( ! priorityCard ) {
return 'Missing card, repair your database'
}
return priorityCard
} )
console . log ( 'You have' , priorityCards . length , 'priorities:' )
console . log ( 'You have' , priorityCards . length , 'priorities:' )
prioritiesChoices = priorities . map ( ( priorityTaskId , i ) => {
prioritiesChoices = priorities . map ( ( priorityTaskId , i ) => {
const priorityCard = priorityCards . find ( p => p . taskId === priorityTaskId )
const priorityCard = priorityCards . find ( p => p . taskId === priorityTaskId )
@ -61,6 +70,19 @@ export async function prioritiesMenu(taskId = null) {
short : priorityCard . name . substring ( 0 , 70 ) + priorityCard . name . length >= 70 ? '...' : ''
short : priorityCard . name . substring ( 0 , 70 ) + priorityCard . name . length >= 70 ? '...' : ''
}
}
} )
} )
let firstIndexEchelonDecreases
let firstEchelon = priorityCards . length >= 1 ? priorityCards [ 0 ] . echelon : null
if ( firstEchelon ) {
priorityCards . some ( ( pc , i ) => {
if ( ! pc . echelon || pc . echelon !== firstEchelon ) {
firstIndexEchelonDecreases = i
return true
}
} )
if ( ! isNaN ( firstIndexEchelonDecreases ) ) {
prioritiesChoices . splice ( firstIndexEchelonDecreases , 0 , new inquirer . Separator ( '───' ) )
}
}
prioritiesChoices . push (
prioritiesChoices . push (
{ name : 'Create priority' , value : 'create_here' , short : 'new priority' } ,
{ name : 'Create priority' , value : 'create_here' , short : 'new priority' } ,
{ name : 'Back to Deck' , value : false , short : 'back' }
{ name : 'Back to Deck' , value : false , short : 'back' }
@ -68,11 +90,11 @@ export async function prioritiesMenu(taskId = null) {
let answer
let answer
try {
try {
answer = await inquirer . prompt ( {
answer = await inquirer . prompt ( {
name : 'priorities_menu' ,
name : 'priorities_menu' ,
type : 'rawlist' ,
type : 'rawlist' ,
message : 'Please choose:' ,
message : 'Please choose:' ,
choices : prioritiesChoices ,
choices : prioritiesChoices ,
loop : false
loop : false
} )
} )
} catch ( error ) {
} catch ( error ) {
if ( error === 'EVENT_INTERRUPTED' ) {
if ( error === 'EVENT_INTERRUPTED' ) {
@ -86,7 +108,6 @@ export async function prioritiesMenu(taskId = null) {
case 'create_here' :
case 'create_here' :
let previousCardCreatedText
let previousCardCreatedText
do {
do {
console . log ( 'previousCardCreatedText is' , previousCardCreatedText )
previousCardCreatedText = await createCardInteractive ( )
previousCardCreatedText = await createCardInteractive ( )
} while ( previousCardCreatedText != '\n' )
} while ( previousCardCreatedText != '\n' )
return true
return true
@ -98,7 +119,7 @@ export async function prioritiesMenu(taskId = null) {
const chosenTaskId = chosenTask . taskId
const chosenTaskId = chosenTask . taskId
let previousAnswer
let previousAnswer
do {
do {
previousAnswer = await priorityCardMenu ( chosenTask , answer . priorities _menu . index )
previousAnswer = await priorityCardMenu ( chosenTask , answer . priorities _menu . index , priorityCards )
if ( previousAnswer ) {
if ( previousAnswer ) {
const fetchedCards = await getCard ( chosenTaskId , false )
const fetchedCards = await getCard ( chosenTaskId , false )
if ( ! fetchedCards || fetchedCards . length < 1 ) {
if ( ! fetchedCards || fetchedCards . length < 1 ) {
@ -114,7 +135,7 @@ export async function prioritiesMenu(taskId = null) {
// Short action-oriented menu for cards in the priorities list
// Short action-oriented menu for cards in the priorities list
// Index is the position of the card in the list that it is in, used for fencepost case to display upboat contextually
// Index is the position of the card in the list that it is in, used for fencepost case to display upboat contextually
async function priorityCardMenu ( card , index ) {
async function priorityCardMenu ( card , index , allPriorities ) {
if ( ! card ) {
if ( ! card ) {
console . log ( 'priorityCardMenu: card is required.' )
console . log ( 'priorityCardMenu: card is required.' )
return false
return false
@ -161,7 +182,49 @@ async function priorityCardMenu(card, index) {
}
}
break
break
case 'upboat' :
case 'upboat' :
await prioritizeCard ( taskId , memberId )
console . log ( 'upboat' )
let firstEchelonScore
let newEchelonScore
let newPosition = 0
console . log ( 'upboat2' )
console . log ( 'card is' , card )
//console.log(allPriorities)
breakHere :
for ( let i = 0 ; i < allPriorities . length ; i ++ ) {
console . log ( 'upboat3' )
const priority = allPriorities [ i ]
console . log ( 'priority is' , priority )
if ( i === 0 ) {
console . log ( 'upboat3.1' )
firstEchelonScore = priority . echelon
console . log ( 'upboat3.11115' , priority . name , priority . echelon , typeof priority . echelon )
if ( isNaN ( firstEchelonScore ) ) {
console . log ( 'upboat3.2' )
newEchelonScore = 1
break breakHere
}
if ( ! card . echelon || card . echelon < priority . echelon ) {
console . log ( 'upboat3.3' )
newEchelonScore = priority . echelon
} else if ( card . echelon && priority . echelon && card . echelon === priority . echelon ) {
console . log ( 'upboat3.4' )
newEchelonScore = priority . echelon + 1
break breakHere
} else if ( card . echelon && priority . echelon && card . echelon > priority . echelon ) {
console . log ( 'upboat3.5' )
break breakHere
}
}
console . log ( 'upboat4' )
if ( priority . echelon !== firstEchelonScore ) {
newPosition = i
break breakHere
}
console . log ( 'upboat5' )
}
console . log ( 'upboat6' )
console . log ( 'newPosition is' , newPosition , 'and newEchelonScore is' , newEchelonScore )
await prioritizeCard ( taskId , memberId , newPosition , newEchelonScore )
return false
return false
case 'downboat' :
case 'downboat' :
await refocusCard ( taskId , memberId )
await refocusCard ( taskId , memberId )
@ -171,5 +234,6 @@ async function priorityCardMenu(card, index) {
default :
default :
return false
return false
}
}
console . log ( 'broken' )
return true
return true
}
}