From 78c111be54de2a15ff6701a207171b8675fc9834 Mon Sep 17 00:00:00 2001 From: Toastie <toastie@toastiet0ast.com> Date: Tue, 4 Feb 2025 19:30:12 +1300 Subject: [PATCH] Add option to merge answers for summary --- Interviews/Interview.cs | 15 +++++++++++++-- Interviews/interview_template.schema.json | 5 +++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/Interviews/Interview.cs b/Interviews/Interview.cs index 97a8aaa..9776239 100644 --- a/Interviews/Interview.cs +++ b/Interviews/Interview.cs @@ -134,6 +134,10 @@ public class InterviewStep [JsonProperty("step-references")] public Dictionary<string, ReferencedInterviewStep> references = new(); + // If set will merge answers with the delimiter, otherwise will overwrite + [JsonProperty("answer-delimiter")] + public string answerDelimiter; + // Possible questions to ask next, an error message, or the end of the interview. [JsonProperty("steps")] public Dictionary<string, InterviewStep> steps = new(); @@ -203,8 +207,14 @@ public class InterviewStep if (!string.IsNullOrWhiteSpace(summaryField) && !string.IsNullOrWhiteSpace(answer)) { - // TODO: Add option to merge answers - summary[summaryField] = answer; + if (answerDelimiter != null && summary.Contains(summaryField)) + { + summary[summaryField] += answerDelimiter + answer; + } + else + { + summary[summaryField] = answer; + } } // This will always contain exactly one or zero children. @@ -305,6 +315,7 @@ public class InterviewStep } } + // TODO: Warning for answer-delimiter if there is no summary-field // TODO: Add url button here when implemented if (messageType is MessageType.REFERENCE_END) { diff --git a/Interviews/interview_template.schema.json b/Interviews/interview_template.schema.json index 0440bbf..7a57d0a 100644 --- a/Interviews/interview_template.schema.json +++ b/Interviews/interview_template.schema.json @@ -191,6 +191,11 @@ "type": "boolean", "title": "Add Summary", "description": "This adds a summary field to the end of the message." + }, + "answer-delimiter": { + "type": "string", + "title": "Answer Delimiter", + "description": "If the user has already answered a question with the same summary-field as this step the answer will be merged with the existing answer using this delimiter. If this is not set the old answer will be replaced by the new one." } }, "required": [ "message-type" ],