Skip to content

Commit

Permalink
Added pull from database
Browse files Browse the repository at this point in the history
  • Loading branch information
bryanjonker-illinois committed Jul 11, 2024
1 parent 31dcb81 commit d402ab8
Show file tree
Hide file tree
Showing 13 changed files with 111 additions and 16 deletions.
3 changes: 3 additions & 0 deletions Danielson.Data/Danielson.Data.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Azure.Identity" Version="1.12.0" />
<PackageReference Include="Dapper" Version="2.1.35" />
<PackageReference Include="Microsoft.AspNetCore.Components" Version="8.0.5" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.4" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="8.0.4" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.4" />
<PackageReference Include="System.Formats.Asn1" Version="8.0.1" />
</ItemGroup>

<ItemGroup>
Expand Down
4 changes: 3 additions & 1 deletion Danielson.Data/DataAccess/FormAccess.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ namespace Danielson.Data.DataAccess {
public class FormAccess(FormRepository formRepository) {
private readonly FormRepository _formRepository = formRepository;

public async Task<Form> GetForm(int id) => await _formRepository.ReadAsync(f => f.Forms.Include(form => form.ComponentAnswers).Include(form => form.DomainAnswers).FirstOrDefault(form => form.Id == id)) ?? new();
public async Task<int> Create(Form form) => await _formRepository.CreateAsync(form);

public async Task<Form> GetForm(int id) => await _formRepository.ReadAsync(f => f.Forms.Include(form => form.ComponentAnswers).Include(form => form.DomainAnswers).FirstOrDefault(form => form.AssignmentId == id)) ?? new();

public async Task<int> Save(ComponentAnswer componentAnswer) => componentAnswer.Id > 0
? await _formRepository.UpdateAsync(componentAnswer)
Expand Down
2 changes: 2 additions & 0 deletions Danielson.Data/DataAccess/FormTemplateAccess.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ public class FormTemplateAccess(FormRepository formRepository) {

public async Task<List<string>> GetFinalAnswerOptions(int? id) => id.HasValue ? (await _formRepository.ReadAsync(f => f.FormTemplates.FirstOrDefault(f => f.Id == id)?.FinalAnswerOptions) ?? "").Split('\n').Select(c => c.Trim(' ', '.')).ToList() ?? [] : [];

public async Task<List<string>> GetFinalAnswerOptions(string lookupString) => (await _formRepository.ReadAsync(f => f.FormTemplates.FirstOrDefault(f => f.InternalLookupString == lookupString)?.FinalAnswerOptions) ?? "").Split('\n').Select(c => c.Trim(' ', '.')).ToList() ?? [];

public async Task<int> Save(FormTemplate formTemplate) => formTemplate.Id > 0 ? await _formRepository.UpdateAsync(formTemplate) : await _formRepository.CreateAsync(formTemplate);
}
}
18 changes: 18 additions & 0 deletions Danielson.Data/PortalTranslator/FormExport.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using Dapper;
using Microsoft.Data.SqlClient;

namespace Danielson.Data.PortalTranslator {

public class FormExport {
private readonly string _connectionString;

public FormExport(string? connectionString) {
_connectionString = connectionString ?? "";
}

public FormExportInformation Get(int id) {
using var connection = new SqlConnection(_connectionString);
return connection.QuerySingle<FormExportInformation>("[danielson].usp_get_evaluation @evaluation_id", new { evaluation_id = id });
}
}
}
13 changes: 12 additions & 1 deletion Danielson.Data/PortalTranslator/FormExportInformation.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
namespace Danielson.Data.PortalTranslator {

public class FormExportInformation {
public string EvaluatedBy { get; set; } = "";
public string EvaluatedBy => $"{EvaluatorFirstName} {EvaluatorLastName}";
public string EvaluatorFirstName { get; set; } = "";
public string EvaluatorLastName { get; set; } = "";
public string FormTemplateInternalLookupString { get; set; } = "";
public bool IsMidterm { get; set; }
public string PlacementType { get; set; } = "";
public string Position { get; set; } = "";
public string Semester { get; set; } = "";
public bool ShowComponents { get; set; }
public bool ShowNotObserved { get; set; }
public bool ShowQuantitativeAnswer { get; set; }
public string StudentName { get; set; } = "";
public string Title { get; set; } = "";
}
}
17 changes: 16 additions & 1 deletion Danielson/Components/Controls/DomainReview.razor
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
<p class="title">@component.ComponentTitle</p>
<div class="table">
<div>
<div>@component.QuantitativeScore</div>
@if (component.QuantitativeScore >= 0)
{
<div>@component.QuantitativeScore</div>
}
<div>@component.QualitativeScore</div>
</div>
<div>
Expand All @@ -14,6 +17,18 @@
</div>
</div>
}
@if (!AreAllCompnentsAnswered)
{
<div class="danielson-answer">
<p class="title-alert">Not all components have been answered</p>
<ul>
@foreach (var componentTitle in ComponentsNotChosen)
{
<li>@componentTitle</li>
}
</ul>
</div>
}
<div class="danielson-answer">
<p class="title">Strengths</p>
<p>@DomainAnswer.Strengths</p>
Expand Down
5 changes: 5 additions & 0 deletions Danielson/Components/Controls/DomainReview.razor.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Danielson.Data.DataModels;
using Danielson.Data.Domains;
using Microsoft.AspNetCore.Components;

namespace Danielson.Components.Controls {
Expand All @@ -14,12 +15,16 @@ public partial class DomainReview {
[Parameter]
public string Title { get; set; } = default!;

protected bool AreAllCompnentsAnswered => ComponentsNotChosen.Count == 0;
protected List<ComponentAnswer> ComponentAnswers { get; set; } = default!;

protected List<string> ComponentsNotChosen { get; set; } = default!;

protected DomainAnswer DomainAnswer { get; set; } = default!;

protected override void OnInitialized() {
ComponentAnswers = Form.ComponentAnswers.Where(ca => ca.DomainItem == DomainEnum).OrderBy(ca => ca.ComponentOrder).ToList() ?? [];
ComponentsNotChosen = DomainList.Domains.First(d => d.DomainEnum == DomainEnum).Components.Where(c => !ComponentAnswers.Select(ca => ca.ComponentOrder).Contains(c.ComponentOrder)).Select(c => c.Title).ToList();
DomainAnswer = Form.GetDomainAnswer(DomainEnum);
}
}
Expand Down
4 changes: 2 additions & 2 deletions Danielson/Components/Pages/Form/Domain.razor
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
{
<div class="danielson-name">
<h1>@FormExportInformation.Title</h1>
<FormHeader FormId="CurrentForm.Id" IsMidterm="CurrentForm.IsMidterm" EvaluatedBy="@FormExportInformation.EvaluatedBy" EvaluationDate="@CurrentForm.DateEvaluatedString"
<FormHeader FormId="CurrentForm.AssignmentId" IsMidterm="CurrentForm.IsMidterm" EvaluatedBy="@FormExportInformation.EvaluatedBy" EvaluationDate="@CurrentForm.DateEvaluatedString"
FormType="@CurrentForm.Title" Semester="@CurrentForm.SemesterDate" OnChangeCallback="ChangeFormType"></FormHeader>
</div>
}
Expand All @@ -29,7 +29,7 @@
{
@foreach (var component in DomainObject.Components)
{
<ComponentItem Component="component" FormId="FormId" FormTemplateCode="@CurrentForm.FormTemplateInternalLookupString" ShowNotObserved="@(CurrentForm.ShowNotObserved && CurrentForm.IsMidterm)" ShowQuantitativeAnswer="@CurrentForm.ShowQuantitativeAnswer" ComponentAnswer="@CurrentForm.GetComponentAnswer(DomainObject.DomainEnum, component.ComponentOrder)" OnChangeCallback="AddComponentAnswerToForm"></ComponentItem>
<ComponentItem Component="component" FormId="CurrentForm.Id" FormTemplateCode="@CurrentForm.FormTemplateInternalLookupString" ShowNotObserved="@(CurrentForm.ShowNotObserved && CurrentForm.IsMidterm)" ShowQuantitativeAnswer="@CurrentForm.ShowQuantitativeAnswer" ComponentAnswer="@CurrentForm.GetComponentAnswer(DomainObject.DomainEnum, component.ComponentOrder)" OnChangeCallback="AddComponentAnswerToForm"></ComponentItem>
}
}
<DomainItem DomainAnswer="@CurrentForm.GetDomainAnswer(DomainObject.DomainEnum)" OnChangeCallback="AddDomainAnswerToForm"></DomainItem>
Expand Down
44 changes: 35 additions & 9 deletions Danielson/Components/Pages/Form/Domain.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Danielson.Data.Domains;
using Danielson.Data.PortalTranslator;
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Authorization;
using Microsoft.JSInterop;

namespace Danielson.Components.Pages.Form {
Expand All @@ -11,17 +12,25 @@ public partial class Domain {
public Data.DataModels.Form CurrentForm { get; set; } = default!;

public DomainObject DomainObject { get; set; } = default!;

public List<string> FinalAnswers { get; set; } = default!;

public FormExportInformation FormExportInformation { get; set; } = default!;

[Parameter]
public int FormId { get; set; }

public bool ShowFinal { get; set; }

[Inject]
protected AuthenticationStateProvider AuthenticationStateProvider { get; set; } = default!;

[Inject]
protected FormAccess ComponentAnswerHandler { get; set; } = default!;

[Inject]
protected FormExport FormExport { get; set; } = default!;

[Inject]
protected FormTemplateAccess FormTemplateAccess { get; set; } = default!;

Expand Down Expand Up @@ -109,16 +118,33 @@ protected override async Task OnInitializedAsync() {
DomainObject = DomainList.Domains.First();
ShowFinal = false;

CurrentForm = await ComponentAnswerHandler.GetForm(FormId);
FinalAnswers = await FormTemplateAccess.GetFinalAnswerOptions(CurrentForm.Id);

//TODO Add export pull
FormExportInformation = new FormExportInformation {
EvaluatedBy = "Talbott, Susan",
Title = "CI-410: Acello, Grace"
};
//TODO Add authentication
var email = (await AuthenticationStateProvider.GetAuthenticationStateAsync()).User.Identity?.Name;
FormExportInformation = FormExport.Get(FormId);

CurrentForm = await ComponentAnswerHandler.GetForm(FormId);
if (CurrentForm.Id == 0) {
CurrentForm = new Data.DataModels.Form {
AssignmentId = FormId,
FormTemplateInternalLookupString = FormExportInformation.FormTemplateInternalLookupString,
IsMidterm = FormExportInformation.IsMidterm,
Email = email ?? "-------------",
PlacementType = FormExportInformation.PlacementType,
Position = FormExportInformation.Position,
SemesterDate = FormExportInformation.Semester,
ShowComponents = FormExportInformation.ShowComponents,
ShowNotObserved = FormExportInformation.ShowNotObserved,
ShowQuantitativeAnswer = FormExportInformation.ShowQuantitativeAnswer,
Student = FormExportInformation.StudentName,
Title = FormExportInformation.Title,
IsActive = true,
LastUpdated = DateTime.Now
};
_ = await ComponentAnswerHandler.Create(CurrentForm);
} else if (CurrentForm.Email != email) {
throw new Exception("Emails do not match");
}
FinalAnswers = await FormTemplateAccess.GetFinalAnswerOptions(FormExportInformation.FormTemplateInternalLookupString);
StateHasChanged();
await base.OnInitializedAsync();
}

Expand Down
2 changes: 1 addition & 1 deletion Danielson/Components/Pages/Home.razor
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Welcome to your new app.

<h2>Testing accessing a form</h2>

<p><a href="/Form/Domain/1">Form ID #1</a> (for testing purposes only)</p>
<p><a href="/Form/Domain/34295">Form ID #34295</a> (for testing purposes only)</p>

@if (FormTemplates != null)
{
Expand Down
2 changes: 1 addition & 1 deletion Danielson/Components/Pages/LoginManager.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public partial class LoginManager {
protected override async Task OnInitializedAsync() {
if (!string.IsNullOrWhiteSpace(GuidString)) {
var (newResult, role, studentId) = await ((CustomAuthenticationStateProvider) CustomAuthenticationStateProvider).PullManually(Guid.Parse(GuidString));
var appUser = new ApplicationUser { Email = newResult.Email, UserName = newResult.UserName };
var appUser = new ApplicationUser { Email = newResult.Email, UserName = newResult.Email };
await SignInManager.SignInWithClaimsAsync(appUser, true, [new(ClaimTypes.Role, role), new(ClaimConstants.StudentId, studentId)]);
NavigationManager.NavigateTo("/");
}
Expand Down
2 changes: 2 additions & 0 deletions Danielson/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Danielson.Data.Data;
using Danielson.Data.DataAccess;
using Danielson.Data.Login;
using Danielson.Data.PortalTranslator;
using Microsoft.AspNetCore.Components.Authorization;
using Microsoft.AspNetCore.Identity;
using Microsoft.EntityFrameworkCore;
Expand All @@ -25,6 +26,7 @@
builder.Services.AddScoped(s => new UserAccess(s.GetService<FormRepository>(), builder.Configuration["Testing"]));
builder.Services.AddScoped<FormTemplateAccess>();
builder.Services.AddScoped<FormAccess>();
builder.Services.AddScoped(s => new FormExport(builder.Configuration.GetConnectionString("AppConnection")));

builder.Services.AddAuthentication(options => {
options.DefaultScheme = IdentityConstants.ApplicationScheme;
Expand Down
11 changes: 11 additions & 0 deletions Danielson/wwwroot/app.css
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,17 @@ fieldset {
margin-bottom: 0;
}

.danielson-answer .title-alert {
font-size: 22px;
font-style: normal;
font-weight: 700;
line-height: 28px;
padding: 10px;
background-color: var(--il-altgeld);
color: white;
margin-bottom: 0;
}

.danielson-answer .table {
display: flex;
margin: 10px 10px 30px 10px;
Expand Down

0 comments on commit d402ab8

Please sign in to comment.