(norganizer) web status filter master
authorBen Doumenc <bdoumenc@gmail.com>
Wed, 29 Jul 2020 06:21:53 +0000 (08:21 +0200)
committerBen Doumenc <bdoumenc@gmail.com>
Wed, 29 Jul 2020 06:21:53 +0000 (08:21 +0200)
norganizer/public/css/norganizer.css
norganizer/src/core.nim
norganizer/src/web/index.nim

index 6647763..4788cba 100644 (file)
@@ -7,7 +7,7 @@ div .n-tags-selected {
     font-style: italic;
 }
 
-button.n-tag  {
+button.n-filter {
     margin: 5px;
 }
 
index f45ab52..318faf6 100644 (file)
@@ -21,6 +21,12 @@ type
     EXPIRED = "Expired"
     UNKNOWN = "Unknown"
 
+proc toEnum*(status: string): EntryStatus =
+  for e in EntryStatus.ACTIVE..EntryStatus.UNKNOWN:
+    if status == $e:
+      return e
+  return EntryStatus.UNKNOWN
+
 type
   Entry* = ref object
     uuid*: string
@@ -142,12 +148,20 @@ proc tags*(store: EntryStore, tags: seq[string]): seq[Entry] =
 proc allTags*(store: EntryStore): seq[string] = 
   var tags = newSeq[string]()
   for entry in store.entries:
-    tags = tags & entry.tags
+    # tags = tags & entry.tags
+    tags.add(entry.tags)
   tags = sequtils.deduplicate(tags)
   tags.sort()
   return tags
 
 
+proc allStatuses*(store: EntryStore): seq[EntryStatus] = 
+  var statuses = newSeq[EntryStatus]()
+  for entry in store.entries:
+    statuses.add(entry.status)
+  statuses = sequtils.deduplicate(statuses)
+  statuses.sort()
+  return statuses
 
 when isMainModule:
   echo("In entries module!")
index 63b070c..0ac9698 100644 (file)
@@ -38,6 +38,10 @@ proc onTagClicked(tag: string) =
     state.tagFilter.add(tag)
   state.entries = state.store.tags(state.tagFilter)
 
+proc onStatusClicked(status: string) =
+  state.statusFilter = toEnum(status)
+  state.entries = state.store.status(state.statusFilter)
+
 proc createDom(router: RouterData): VNode =
   if state.store.entries.len() == 0:
     ajaxGet("/store", @[], onStoreRetrived)
@@ -53,17 +57,31 @@ proc createDom(router: RouterData): VNode =
       tdiv(class = "container n-tags"):
         let
           tags = state.store.allTags()
+          statuses = state.store.allStatuses()
         for tag in tags:
           var class = ""
           if tag in state.tagFilter:
             class = "button-outline"
           else:
             class = "button"
-          button(class=class & " n-tag"):
+          button(class=class & " n-filter"):
             proc onclick(ev: Event; n: VNode) =
               onTagClicked($n[0].text)
             text tag
 
+      tdiv(class = "container n-tags"):
+        for status in statuses:
+          var class = ""
+          if status == state.statusFilter:
+            class = "button-outline"
+          else:
+            class = "button"
+          button(class=class & " n-filter"):
+            proc onclick(ev: Event; n: VNode) =
+              onStatusClicked($n[0].text)
+            text $status
+
+
       tdiv(class = "container n-tags-selected"):
         text "Tags: " & join(state.tagFilter, ", ")
       tdiv(class = "container n-entries"):