@@ -27,7 +27,7 @@ import { openMonthParas, refMonthParas, tagParasFromNote } from './demoData'
2727import { getTagSectionDetails } from './react/components/Section/sectionHelpers'
2828import { removeInvalidTagSections } from './perspectiveHelpers'
2929import { getNestedValue , setNestedValue } from '@helpers/dataManipulation'
30- import { getDateStringFromCalendarFilename , getNPMonthStr , getNPQuarterStr } from '@helpers/dateTime'
30+ import { getDateStringFromCalendarFilename , getNPMonthStr , getNPQuarterStr , getNPYearStr } from '@helpers/dateTime'
3131import { clo , JSP , logDebug , logError , logInfo , logTimer , logWarn , timer } from '@helpers/dev'
3232import { getHeadingsFromNote } from '@helpers/NPnote'
3333// import { sortListBy } from '@helpers/sorting'
@@ -90,6 +90,7 @@ export async function getSomeSectionsData(
9090 if ( sectionCodesToGet . includes ( 'W' ) && config . showWeekSection ) sections . push ( ...getThisWeekSectionData ( config , useDemoData , useEditorWherePossible ) )
9191 if ( sectionCodesToGet . includes ( 'M' ) && config . showMonthSection ) sections . push ( ...getThisMonthSectionData ( config , useDemoData , useEditorWherePossible ) )
9292 if ( sectionCodesToGet . includes ( 'Q' ) && config . showQuarterSection ) sections . push ( ...getThisQuarterSectionData ( config , useDemoData , useEditorWherePossible ) )
93+ if ( sectionCodesToGet . includes ( 'Y' ) && config . showYearSection ) sections . push ( ...getThisYearSectionData ( config , useDemoData , useEditorWherePossible ) )
9394 // moderately quick to generate
9495 if ( sectionCodesToGet . includes ( 'PROJ' ) && config . showProjectSection ) {
9596 logInfo ( 'getSomeSectionsData' , `🔹 Getting Project section data as part of ${ sectionCodesToGet . toString ( ) } ` )
@@ -559,9 +560,194 @@ export function getThisQuarterSectionData(config: TDashboardSettings, useDemoDat
559560 }
560561}
561562
562- //----------------------------------------------------------------
563- // Note: If we want to do yearly in the future then the icon is
564- // fa-calendar-days (same as quarter). This would be section #6
563+ /**
564+ * Get open items from this Year's note
565+ * @param {TDashboardSettings } config
566+ * @param {boolean } useDemoData?
567+ * @param {boolean } useEditorWherePossible?
568+ * @returns {TSection } data
569+ */
570+ export function getThisYearSectionData ( config : TDashboardSettings , useDemoData : boolean = false , useEditorWherePossible : boolean ) : Array < TSection > {
571+ try {
572+ const thisSectionCode = 'Y'
573+ const sections : Array < TSection > = [ ]
574+ let items : Array < TSectionItem > = [ ]
575+ let itemCount = 0
576+ const today = new moment ( ) . toDate ( ) // use moment instead of `new Date` to ensure we get a date in the local timezone
577+ const dateStr = getNPYearStr ( today )
578+ const NPSettings = getNotePlanSettings ( )
579+ const currentYearlyNote = DataStore . calendarNoteByDate ( today , 'year' )
580+ const thisFilename = `${ dateStr } .${ NPSettings . defaultFileExtension } `
581+ let sortedOrCombinedParas : Array < TParagraphForDashboard > = [ ]
582+ let sortedRefParas : Array < TParagraphForDashboard > = [ ]
583+ logDebug ( 'getDataForDashboard' , `---------- Gathering Year's ${ useDemoData ? 'DEMO' : '' } items for section ${ thisSectionCode } ------------` )
584+ const startTime = new Date ( ) // for timing only
585+
586+ if ( useDemoData ) {
587+ // Deliberately no demo data defined
588+ } else {
589+ if ( currentYearlyNote ) {
590+ // Get list of open tasks/checklists from this yearly note (if it exists)
591+ ; [ sortedOrCombinedParas , sortedRefParas ] = getOpenItemParasForTimePeriod ( dateStr , 'year' , config , useEditorWherePossible )
592+
593+ // Iterate and write items for first (or combined) section
594+ items = createSectionOpenItemsFromParas ( sortedOrCombinedParas , thisSectionCode )
595+ itemCount += items . length
596+
597+ // logDebug('getDataForDashboard', `- finished finding Yearly items from ${dateStr} after ${timer(startTime)}`)
598+ } else {
599+ logDebug ( 'getDataForDashboard ', `No Yearly note found for filename '${ thisFilename } '` )
600+ }
601+ }
602+ const nextPeriodNote = DataStore . calendarNoteByDate ( new moment ( ) . add ( 1 , 'year ') . toDate ( ) , 'year ')
603+ const nextPeriodFilename = nextPeriodNote ?. filename ?? ''
604+ const doneCountData = getNumCompletedTasksFromNote ( thisFilename )
605+
606+ // Set up formFields for the 'add buttons' (applied in Section.jsx)
607+ const formFieldsBase : Array < TSettingItem > = [{ type : 'input' , label : 'Task:' , key : 'text' , focus : true } ]
608+ const thisYearHeadings: Array< string > = currentYearlyNote ? getHeadingsFromNote(currentYearlyNote, false, true, true, true) : []
609+ const nextYearHeadings: Array< string > = nextPeriodNote ? getHeadingsFromNote(nextPeriodNote, false, true, true, true) : []
610+ // Set the default heading to add to, unless it's '< < carry forward > > ', in which case we 'll use an empty string
611+ const defaultHeadingToAddTo : string = config . newTaskSectionHeading !== '<< carry forward >> ' ? config . newTaskSectionHeading : ''
612+ const thisYearFormFields : Array < TSettingItem > = formFieldsBase.concat(
613+ thisYearHeadings.length
614+ ? // $FlowIgnore[incompatible-type]
615+ [
616+ {
617+ type : 'dropdown-select' ,
618+ label : 'Under Heading:' ,
619+ key : 'heading' ,
620+ // $FlowFixMe[incompatible-type]
621+ options : thisYearHeadings ,
622+ noWrapOptions : true ,
623+ value : defaultHeadingToAddTo ,
624+ } ,
625+ ]
626+ : [],
627+ )
628+ const nextYearFormFields: Array< TSettingItem > = formFieldsBase.concat(
629+ nextYearHeadings.length
630+ ? // $FlowIgnore[incompatible-type]
631+ [
632+ {
633+ type : 'dropdown-select' ,
634+ label : 'Under Heading:' ,
635+ key : 'heading' ,
636+ // $FlowFixMe[incompatible-type]
637+ options : nextYearHeadings ,
638+ noWrapOptions : true ,
639+ value : defaultHeadingToAddTo ,
640+ } ,
641+ ]
642+ : [],
643+ )
644+
645+ let sectionDescription = `{ countWithLimit } from ${ dateStr } `
646+ if (config?.FFlag_ShowSectionTimings) sectionDescription += ` [${ timer ( startTime ) } ]`
647+
648+ const section: TSection = {
649+ ID : thisSectionCode ,
650+ name : 'This Year' ,
651+ showSettingName : 'showYearSection' ,
652+ sectionCode : thisSectionCode ,
653+ description : sectionDescription ,
654+ FAIconClass : 'fa-regular fa-calendar-days' ,
655+ sectionTitleColorPart : 'sidebarYearly' ,
656+ sectionFilename : thisFilename ,
657+ sectionItems : items ,
658+ generatedDate : new Date ( ) ,
659+ doneCounts : doneCountData ,
660+ totalCount : items . length ,
661+ actionButtons : [
662+ {
663+ actionName : 'addTask' ,
664+ actionPluginID : `${ pluginJson [ 'plugin.id' ] } ` ,
665+ tooltip : "Add a new task to this year's note" ,
666+ display : '<i class= "fa-regular fa-fw fa-circle-plus sidebarYearly" ></i> ' ,
667+ actionParam : thisFilename ,
668+ postActionRefresh : [ 'Y' ] ,
669+ formFields : thisYearFormFields ,
670+ submitOnEnter : true ,
671+ submitButtonText : 'Add & Close' ,
672+ } ,
673+ {
674+ actionName : 'addChecklist' ,
675+ actionPluginID : `${ pluginJson [ 'plugin.id' ] } ` ,
676+ tooltip : "Add a checklist item to this year's note" ,
677+ display : '<i class= "fa-regular fa-fw fa-square-plus sidebarYearly" ></i> ' ,
678+ actionParam : thisFilename ,
679+ postActionRefresh : [ 'Y' ] ,
680+ formFields : thisYearFormFields ,
681+ submitOnEnter : true ,
682+ submitButtonText : 'Add & Close' ,
683+ } ,
684+ {
685+ actionName : 'addTask' ,
686+ actionPluginID : `${ pluginJson [ 'plugin.id' ] } ` ,
687+ tooltip : "Add a new task to next year's note" ,
688+ display : '<i class= "fa-regular fa-fw fa-circle-arrow-right sidebarYearly" ></i> ' ,
689+ actionParam : nextPeriodFilename ,
690+ formFields : nextYearFormFields ,
691+ submitOnEnter : true ,
692+ submitButtonText : 'Add & Close' ,
693+ } ,
694+ {
695+ actionName : 'addChecklist' ,
696+ actionPluginID : `${ pluginJson [ 'plugin.id' ] } ` ,
697+ tooltip : "Add a checklist item to next year's note" ,
698+ display : '<i class= "fa-regular fa-fw fa-square-arrow-right sidebarYearly" ></i> ' ,
699+ actionParam : nextPeriodFilename ,
700+ formFields : nextYearFormFields ,
701+ submitOnEnter : true ,
702+ submitButtonText : 'Add & Close' ,
703+ } ,
704+ ] ,
705+ isReferenced : false ,
706+ }
707+ sections.push(section)
708+
709+ // If we want this separated from the referenced items, then form a second section
710+ if (config.separateSectionForReferencedNotes) {
711+ let items : Array < TSectionItem > = [ ]
712+ const referencedSectionCode = `${ thisSectionCode } _REF`
713+ if ( useDemoData ) {
714+ // No demo data
715+ } else {
716+ // Get list of open tasks/checklists from current yearly note (if it exists)
717+ if ( sortedRefParas . length > 0 ) {
718+ // Iterate and write items for this section
719+ items = createSectionOpenItemsFromParas ( sortedRefParas , referencedSectionCode )
720+ itemCount += items . length
721+ }
722+ }
723+
724+ // Add separate section (if there are any items found)
725+ const section : TSection = {
726+ ID : referencedSectionCode ,
727+ name : '>This Year' ,
728+ showSettingName : 'showYearSection' ,
729+ sectionCode : thisSectionCode ,
730+ description : `{count} scheduled to ${ dateStr } ` ,
731+ FAIconClass : 'fa-regular fa-calendar-days' ,
732+ sectionTitleColorPart : 'sidebarYearly' ,
733+ sectionFilename : thisFilename ,
734+ sectionItems : items ,
735+ totalCount : items . length ,
736+ generatedDate : new Date ( ) ,
737+ actionButtons : [ ] ,
738+ isReferenced : true ,
739+ }
740+ sections . push ( section )
741+ }
742+
743+ logDebug('getDataForDashboard', `- found ${ itemCount } yearly items from ${ dateStr } in ${ timer ( startTime ) } `)
744+ return sections
745+ } catch ( error ) {
746+ logError ( 'getDataForDashboard/year' , `ERROR: ${ error . message } ` )
747+ return [ ]
748+ }
749+ }
750+
565751//----------------------------------------------------------------
566752
567753/**
0 commit comments