logic for top-priority habit entries
This commit is contained in:
@@ -1,8 +1,9 @@
|
||||
(defNew [&prop &mut :EntryType type
|
||||
&prop &mut :Array<EntryLabel> labels])
|
||||
&prop &mut :Array<EntryLabel> labels
|
||||
&prop &mut :Bool topPriority])
|
||||
|
||||
(method toString []
|
||||
"$(case type
|
||||
"$?(when topPriority "! ")$(case type
|
||||
((Daily days lastDayDone)
|
||||
(+
|
||||
(.join (for day days
|
||||
|
@@ -41,6 +41,8 @@
|
||||
path (parts.join " ")]
|
||||
(objectWith path startingPoints puzzleWidth puzzleHeight piecesPerPoint skipped))))
|
||||
((Some line)
|
||||
(let [topPriority (line.startsWith "! ")]
|
||||
(when topPriority (set line (line.substr 2)))
|
||||
(.push
|
||||
(case lastHeader
|
||||
("DAILY" dailyEntries)
|
||||
@@ -109,7 +111,8 @@
|
||||
(for l (line.split "/")
|
||||
(object
|
||||
label (StringTools.trim (StringTools.replace l "|" ""))
|
||||
points (count (l.split "") ->c (= c "|")))))))
|
||||
points (count (l.split "") ->c (= c "|"))))
|
||||
topPriority))))
|
||||
(otherwise (break))))))
|
||||
|
||||
(method :Array<Entry> allEntries []
|
||||
@@ -166,7 +169,7 @@
|
||||
(function isNotDeleted [:Entry e]
|
||||
!(isDeleted e))
|
||||
|
||||
(function isActive [:Entry e]
|
||||
(function _isActive [:Entry e]
|
||||
(when (isDeleted e)
|
||||
(return false))
|
||||
(case e.type
|
||||
@@ -196,22 +199,47 @@
|
||||
(Todo (= 0 .points (activeLabel e)))
|
||||
(otherwise true)))
|
||||
|
||||
(method :Array<Entry> activeDailyEntries []
|
||||
(filter dailyEntries isActive))
|
||||
// Check if an entry is active PRE-top priority filtering
|
||||
(method :Array<Entry> _activeDailyEntries []
|
||||
(filter dailyEntries _isActive))
|
||||
|
||||
(method :Array<Entry> activeMonthlyEntries []
|
||||
(filter monthlyEntries isActive))
|
||||
(method :Array<Entry> _activeMonthlyEntries []
|
||||
(filter monthlyEntries _isActive))
|
||||
|
||||
(method :Array<Entry> activeIntervalEntries []
|
||||
(filter intervalEntries isActive))
|
||||
(method :Array<Entry> _activeIntervalEntries []
|
||||
(filter intervalEntries _isActive))
|
||||
|
||||
(method :Array<Entry> activeBonusEntries []
|
||||
(filter bonusEntries isActive))
|
||||
(method :Array<Entry> _activeBonusEntries []
|
||||
(filter bonusEntries _isActive))
|
||||
|
||||
(method :Array<Entry> activeTodoEntries []
|
||||
(filter todoEntries isActive))
|
||||
(method :Array<Entry> _activeTodoEntries []
|
||||
(filter todoEntries _isActive))
|
||||
|
||||
(method addEntry [:EntryType type :Array<String> labels]
|
||||
(method :Array<Entry> _allActiveEntries []
|
||||
(cast (concat
|
||||
(_activeDailyEntries)
|
||||
(_activeMonthlyEntries)
|
||||
(_activeIntervalEntries)
|
||||
(_activeBonusEntries)
|
||||
(_activeTodoEntries))))
|
||||
|
||||
(method :Bool topPriorityIsActive []
|
||||
(apply or (for e (_allActiveEntries) e.topPriority)))
|
||||
|
||||
(defMacro topPriority [name]
|
||||
`(method :Array<Entry> ,name []
|
||||
(let [_active (,(ReaderExp.Symbol (+ "_" (symbolNameValue name))))]
|
||||
(if (topPriorityIsActive)
|
||||
(filter _active ->e e.topPriority)
|
||||
_active))))
|
||||
|
||||
(topPriority activeDailyEntries)
|
||||
(topPriority activeMonthlyEntries)
|
||||
(topPriority activeIntervalEntries)
|
||||
(topPriority activeBonusEntries)
|
||||
(topPriority activeTodoEntries)
|
||||
|
||||
(method addEntry [:EntryType type :Array<String> labels :Bool topPriority]
|
||||
(.push (case type
|
||||
(Todo todoEntries)
|
||||
(Bonus bonusEntries)
|
||||
@@ -219,7 +247,7 @@
|
||||
((Daily _ _) dailyEntries)
|
||||
((Monthly _ _) monthlyEntries)
|
||||
(otherwise (throw "")))
|
||||
(new Entry type (for label labels (objectWith [points 0] label))))
|
||||
(new Entry type (for label labels (objectWith [points 0] label)) topPriority))
|
||||
(save))
|
||||
|
||||
(method deleteEntry [:Entry e]
|
||||
|
@@ -837,7 +837,7 @@
|
||||
(labelsAdding.push entryNameText.text))
|
||||
(unless labelsAdding
|
||||
(return))
|
||||
(model.addEntry typeAdding labelsAdding)
|
||||
(model.addEntry typeAdding labelsAdding false) // TODO allow choosing priority!
|
||||
(refreshModel)
|
||||
(entryNameText.kill)
|
||||
(set entryNameText null)
|
||||
|
Reference in New Issue
Block a user