Skip to content
Merged

Dev #880

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,10 @@ public class QuestionDto : ExtensibleEntityDto<Guid>
{
return JsonSerializer.Deserialize<CustomFieldDefinition>(Definition ?? "{}")?.Required.ToString();
}

public uint? GetRowsValue()
{
return JsonSerializer.Deserialize<TextAreaDefinition>(Definition ?? "{}")?.Rows;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ public static string ConvertInputType(this CustomFieldType type)
QuestionType.Number => JsonSerializer.Deserialize<NumericDefinition>(definition),
QuestionType.YesNo => JsonSerializer.Deserialize<QuestionYesNoDefinition>(definition),
QuestionType.SelectList => JsonSerializer.Deserialize<QuestionSelectListDefinition>(definition),
QuestionType.TextArea => JsonSerializer.Deserialize<TextAreaDefinition>(definition),
_ => null,
};
}
Expand Down Expand Up @@ -138,5 +139,10 @@ public static bool GetIsDynamic(this CustomFieldDefinition field)
{
return DefinitionResolver.ResolveIsDynamic(field);
}

public static uint? GetRowsOrZero(this CustomFieldDefinition field)
{
return DefinitionResolver.ResolveRows(field) ?? 0;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ public enum QuestionType
Text = 2,
YesNo = 6,
SelectList = 12,
TextArea = 14
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public static class ValueResolver
QuestionType.Number => ResolveNumber(currentValue),
QuestionType.YesNo => JsonSerializer.Deserialize<YesNoValue>(currentValue)?.Value,
QuestionType.SelectList => JsonSerializer.Deserialize<SelectListValue>(currentValue)?.Value,
QuestionType.TextArea => JsonSerializer.Deserialize<TextAreaValue>(currentValue)?.Value,
_ => throw new NotImplementedException()
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ public static string Resolve(QuestionType type, object? definition)
QuestionType.Text => JsonSerializer.Serialize(new TextDefinition()),
QuestionType.YesNo => JsonSerializer.Serialize(new QuestionYesNoDefinition()),
QuestionType.SelectList => JsonSerializer.Serialize(new QuestionSelectListDefinition()),
QuestionType.TextArea => JsonSerializer.Serialize(new TextAreaDefinition()),
_ => throw new NotImplementedException(),
};
}
Expand All @@ -102,6 +103,7 @@ public static string Resolve(QuestionType type, object? definition)
QuestionType.Text => JsonSerializer.Serialize((TextDefinition)definition),
QuestionType.YesNo => JsonSerializer.Serialize((QuestionYesNoDefinition)definition),
QuestionType.SelectList => JsonSerializer.Serialize((QuestionSelectListDefinition)definition),
QuestionType.TextArea => JsonSerializer.Serialize((TextAreaDefinition)definition),
_ => throw new NotImplementedException(),
};
}
Expand All @@ -113,6 +115,7 @@ public static string Resolve(QuestionType type, object? definition)
QuestionType.Text => JsonSerializer.Serialize(element.ToString()),
QuestionType.YesNo => JsonSerializer.Serialize(element.ToString()),
QuestionType.SelectList => JsonSerializer.Serialize(element.ToString()),
QuestionType.TextArea => JsonSerializer.Serialize(element.ToString()),
_ => throw new NotImplementedException(),
};
}
Expand All @@ -124,6 +127,7 @@ public static string Resolve(QuestionType type, object? definition)
QuestionType.Text => JsonSerializer.Serialize(definition),
QuestionType.YesNo => JsonSerializer.Serialize(definition),
QuestionType.SelectList => JsonSerializer.Serialize(definition),
QuestionType.TextArea => JsonSerializer.Serialize(definition),
_ => throw new NotImplementedException(),
};
}
Expand Down Expand Up @@ -202,5 +206,14 @@ public static bool ResolveIsDynamic(CustomFieldDefinition field)
_ => false
};
}

public static uint? ResolveRows(CustomFieldDefinition field)
{
return field switch
{
TextAreaDefinition textArea => textArea.Rows,
_ => null,
};
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Newtonsoft.Json;
using System.Text.Json.Serialization;
using System.Text.Json.Serialization;

namespace Unity.Flex.Worksheets.Definitions
{
Expand All @@ -11,7 +10,7 @@ public class TextAreaDefinition : CustomFieldDefinition
[JsonPropertyName("maxLength")]
public uint MaxLength { get; set; } = uint.MaxValue;

[JsonProperty("rows")]
[JsonPropertyName("rows")]
public uint Rows { get; set; } = uint.MinValue;

public TextAreaDefinition() : base()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
onchange="typeSelectionChanged(this)">
</abp-select>
</abp-row>

<div id="definition-editor">
@await Component.InvokeAsync(typeof(CustomFieldDefinitionWidget), new { type = Model.FieldType, definition = Model.Definition })
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
@using Unity.Flex.Web.Views.Shared.Components.NumericDefinitionWidget;
@using Unity.Flex.Web.Views.Shared.Components.QuestionYesNoDefinitionWidget;
@using Unity.Flex.Web.Views.Shared.Components.QuestionSelectListDefinitionWidget;
@using Unity.Flex.Web.Views.Shared.Components.TextAreaDefinitionWidget
@using Unity.Flex.Web.Views.Shared.Components.TextDefinitionWidget;
@using Unity.Flex;

Expand Down Expand Up @@ -29,6 +30,11 @@
@await Component.InvokeAsync(typeof(QuestionSelectListDefinitionWidget), new { Model.Definition })
</abp-row>
break;
case Unity.Flex.Scoresheets.QuestionType.TextArea:
<abp-row class"m-0 p-0">
@await Component.InvokeAsync(typeof(TextAreaDefinitionWidget), new { Model.Definition })
</abp-row>
break;
default:
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public class QuestionDefinitionWidget : AbpViewComponent
QuestionType.Text => (CustomFieldDefinition?)TextDefinitionWidget.TextDefinitionWidget.ParseFormValues(form),
QuestionType.YesNo => (CustomFieldDefinition?)QuestionYesNoDefinitionWidget.QuestionYesNoDefinitionWidget.ParseFormValues(form),
QuestionType.SelectList => (CustomFieldDefinition?)QuestionSelectListDefinitionWidget.QuestionSelectListDefinitionWidget.ParseFormValues(form),
QuestionType.TextArea => (CustomFieldDefinition?)TextAreaDefinitionWidget.TextAreaDefinitionWidget.ParseFormValues(form),
_ => null,
};
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
@using Unity.Flex.Web.Views.Shared.Components.QuestionTextAreaWidget;

@model QuestionTextAreaViewModel;

<div class="mb-3">
<label for="answer-text-@Model.QuestionId" class="form-label">Answer</label>
<textarea rows="@Model.Rows"
required="@Model.Required"
class="form-control answer-text-input"
minlength="@Model.MinLength"
maxlength="@Model.MaxLength"
disabled="@Model.IsDisabled"
id="answer-text-@Model.QuestionId"
name="Answers[@Model.QuestionId]"
data-original-value="@Model.Answer"
oninput="handleInputChange('@Model.QuestionId','answer-text-','save-text-','discard-text-')">@Model.Answer</textarea>
<span id="error-message-@Model.QuestionId" class="text-danger field-validation-error"></span>
</div>
<div class="btn-group">
<button type="button" class="btn btn-primary" disabled="@Model.IsDisabled" disabled id="save-text-@Model.QuestionId" onclick="saveChanges('@Model.QuestionId','answer-text-','save-text-',2,'discard-text-')">SAVE CHANGES</button>
<button type="button" class="btn btn-secondary" disabled="@Model.IsDisabled" id="discard-text-@Model.QuestionId" onclick="discardChanges('@Model.QuestionId','answer-text-','save-text-','discard-text-')">DISCARD CHANGES</button>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System;

namespace Unity.Flex.Web.Views.Shared.Components.QuestionTextAreaWidget
{
public class QuestionTextAreaViewModel : RequiredFieldViewModel
{
public Guid QuestionId { get; set; }
public bool IsDisabled { get; set; }
public string Answer { get; set; } = string.Empty;
public string? MinLength { get; set; }
public string? MaxLength { get; set; }
public uint? Rows { get; set; } = 1;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using Microsoft.AspNetCore.Mvc;
using System.Threading.Tasks;
using Volo.Abp.AspNetCore.Mvc.UI.Widgets;
using Volo.Abp.AspNetCore.Mvc;
using System;

namespace Unity.Flex.Web.Views.Shared.Components.QuestionTextAreaWidget
{
[Widget(
RefreshUrl = "Widgets/QuestionTextArea/Refresh",
AutoInitialize = true)]
public class QuestionTextAreaWidget : AbpViewComponent
{
public async Task<IViewComponentResult> InvokeAsync(Guid questionId,
bool isDisabled,
string? answer,
string? minLength,
string? maxLength,
uint? rows = 1,
bool required = false)
{
return View(await Task.FromResult(new QuestionTextAreaViewModel()
{
QuestionId = questionId,
IsDisabled = isDisabled,
Answer = answer ?? string.Empty,
MinLength = minLength,
MaxLength = maxLength,
Required = required,
Rows = rows
}));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using System;
using Volo.Abp.AspNetCore.Mvc;

namespace Unity.Flex.Web.Views.Shared.Components.QuestionTextAreaWidget
{
[ApiExplorerSettings(IgnoreApi = true)]
[Route("GrantApplications/Widgets/QuestionTextArea")]
public class QuestionTextAreaWidgetController : AbpController
{
[HttpGet]
[Route("Refresh")]
public IActionResult Refresh(Guid questionId, bool isDisabled, string? answer, int? minLength, int? maxLength)
{
// Check if the model state is valid
if (!ModelState.IsValid)
{
Logger.LogWarning("Invalid model state for QuestionTextAreaWidgetController:Refresh");
return ViewComponent(typeof(QuestionTextAreaWidget));
}

// If the model state is valid, render the view component
return ViewComponent(typeof(QuestionTextAreaWidget), new { questionId, isDisabled, answer, minLength, maxLength });
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,21 @@
</div>
@foreach (var question in sec.Fields)
{
<div class="list-group-item row question-item" data-type="question" data-id="@question.Id" data-scoresheetid="@scoresheet.Id" data-questiontype="@question.Type" data-min="@question.GetMin()" data-max="@question.GetMax()" data-minlength="@question.GetMinLength()" data-maxlength="@question.GetMaxLength()" data-yesvalue="@question.GetYesValue()" data-novalue="@question.GetNoValue()" data-questiondesc="@question.Description" data-definition="@question.Definition" data-required="@question.GetIsRequiredValue()">
<div class="list-group-item row question-item"
data-type="question"
data-id="@question.Id"
data-scoresheetid="@scoresheet.Id"
data-questiontype="@question.Type"
data-min="@question.GetMin()"
data-max="@question.GetMax()"
data-minlength="@question.GetMinLength()"
data-maxlength="@question.GetMaxLength()"
data-yesvalue="@question.GetYesValue()"
data-novalue="@question.GetNoValue()"
data-questiondesc="@question.Description"
data-definition="@question.Definition"
data-rows="@question.GetRowsValue()"
data-required="@question.GetIsRequiredValue()">
<div class="col">
<i class="fl fl-draggable"></i>
<span class="p-2">@question.Label</span>
Expand Down
Loading