From 57ffdb6189c3091d4bb80fec9a1ec3d1dfb18228 Mon Sep 17 00:00:00 2001 From: Nat Quayle Nelson Date: Thu, 28 Dec 2023 19:50:03 -0700 Subject: [PATCH] Up/down ranking component. Close #4 --- src/nat/ArchiveController.kiss | 7 +++++++ src/nat/Lib.kiss | 20 +++++++++++++++++++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/nat/ArchiveController.kiss b/src/nat/ArchiveController.kiss index 5fa4a7d..23e113b 100644 --- a/src/nat/ArchiveController.kiss +++ b/src/nat/ArchiveController.kiss @@ -669,4 +669,11 @@ args))) []) + (defCommand RateUp [es (SelectedEntries 1 null) reason (Text null)] + (for e es + (addUpDownRating archive e true reason))) + + (defCommand RateDown [es (SelectedEntries 1 null) reason (Text null)] + (for e es + (addUpDownRating archive e false reason))) ) diff --git a/src/nat/Lib.kiss b/src/nat/Lib.kiss index 0ad4b83..8e399fe 100644 --- a/src/nat/Lib.kiss +++ b/src/nat/Lib.kiss @@ -172,4 +172,22 @@ (function isEntry [o] (let [fields (Reflect.fields o)] (and (= fields.length 3) - (apply and (for f ["id" "components" "files"] (contains fields f)))))) \ No newline at end of file + (apply and (for f ["id" "components" "files"] (contains fields f)))))) + +(function addUpDownRating [:nat.Archive archive :nat.Entry e :Bool up &opt :String reason] + (unless (hasComponent e UpDownRank) + (addComponent archive e UpDownRank (object up 0 down 0 upReasons [] downReasons []))) + + (withWritableComponents archive e [rank UpDownRank] + (if up + { + (+= rank.up 1) + (when reason + (rank.upReasons.push reason)) + } + { + (+= rank.down 1) + (when reason + (rank.downReasons.push reason)) + })) + e) \ No newline at end of file