Skip to content

Commit

Permalink
Merge pull request #473 from cisagov/feature/CSET-199
Browse files Browse the repository at this point in the history
Navigation redesign
  • Loading branch information
jekuipers authored Sep 2, 2020
2 parents f09a2ce + 6d0ca1a commit e563eee
Show file tree
Hide file tree
Showing 104 changed files with 1,884 additions and 982 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,10 @@ join aa in db.ASSESSMENTS on ii.Id equals aa.Assessment_Id
assessment.CreatedDate = Utilities.UtcToLocal(result.aa.AssessmentCreatedDate);
assessment.LastModifiedDate = Utilities.UtcToLocal((DateTime)result.aa.LastAccessedDate);

assessment.UseStandard = result.aa.UseStandard;
assessment.UseMaturity = result.aa.UseMaturity;
assessment.UseDiagram = result.aa.UseDiagram;

bool defaultAcet = (app_code == "ACET");
assessment.IsAcetOnly = result.ii.IsAcetOnly != null ? result.ii.IsAcetOnly : defaultAcet;

Expand Down Expand Up @@ -228,6 +232,11 @@ public int SaveAssessmentDetail(int assessmentId, AssessmentDetail assessment)
dbAssessment.AssessmentCreatorId = assessment.CreatorId;
dbAssessment.Assessment_Date = assessment.AssessmentDate ?? DateTime.Now;
dbAssessment.LastAccessedDate = assessment.LastModifiedDate;

dbAssessment.UseDiagram = assessment.UseDiagram;
dbAssessment.UseMaturity = assessment.UseMaturity;
dbAssessment.UseStandard = assessment.UseStandard;

dbAssessment.Charter = string.IsNullOrEmpty(assessment.Charter) ? string.Empty : assessment.Charter.PadLeft(5, '0');
dbAssessment.CreditUnionName = assessment.CreditUnion;
dbAssessment.Assets = assessment.Assets;
Expand Down Expand Up @@ -477,10 +486,6 @@ public ASSESSMENTS GetAssessmentById(int assessmentId)
return db.ASSESSMENTS.FirstOrDefault(a => a.Assessment_Id == assessmentId);
}
}




}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ private void AddResponseComponentOverride(QuestionResponse resp, CSET_Context co
}


resp.QuestionGroups.AddRange(groupList);
resp.CategoryContainers[0].QuestionGroups.AddRange(groupList);
resp.QuestionCount += list.Count;
resp.DefaultComponentsCount = list.Count;
}
Expand Down Expand Up @@ -472,11 +472,22 @@ private void AddResponse(QuestionResponse resp, CSET_Context context, List<Answe
}


resp.QuestionGroups.AddRange(groupList);
var container = new CategoryContainer()
{
DisplayText = listname
};
container.QuestionGroups.AddRange(groupList);
resp.CategoryContainers.Add(container);
resp.QuestionCount += list.Count;
resp.DefaultComponentsCount = list.Count;
}


/// <summary>
///
/// </summary>
/// <param name="s"></param>
/// <returns></returns>
public static string FormatLineBreaks(string s)
{
return s.Replace("\r\n", "<br/>").Replace("\r", "<br/>").Replace("\n", "<br/>");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ from c in db.FINDING.Where(x => x.Answer_Id == a.Answer_Id).DefaultIfEmpty()
public List<AnalyticsQuestionAnswer> GetAnalyticQuestionAnswers(QuestionResponse questionResponse)
{
List<AnalyticsQuestionAnswer> analyticQuestionAnswers = new List<AnalyticsQuestionAnswer>();
foreach (var questionGroup in questionResponse.QuestionGroups)
foreach (var questionGroup in questionResponse.CategoryContainers[0].QuestionGroups)
{
foreach (var subCategory in questionGroup.SubCategories)
{
Expand Down Expand Up @@ -281,13 +281,24 @@ private QuestionResponse BuildResponse()

QuestionResponse resp = new QuestionResponse
{
QuestionGroups = groupList,
CategoryContainers = new List<CategoryContainer>(),
ApplicationMode = this.applicationMode
};

// create the container for Standard Questions
var standardQuestionsNode = new CategoryContainer
{
DisplayText = "Standard Questions",
QuestionGroups = groupList
};
resp.CategoryContainers.Add(standardQuestionsNode);


resp.QuestionCount = this.NumberOfQuestions();
resp.RequirementCount = new RequirementsManager(this._assessmentId).NumberOfRequirements();


// Include any component defaults or overrides into the response
BuildComponentsResponse(resp);
return resp;
}
Expand All @@ -296,10 +307,19 @@ public QuestionResponse GetOverrideListOnly()
{
QuestionResponse resp = new QuestionResponse
{
QuestionGroups = new List<QuestionGroup>(),
CategoryContainers = new List<CategoryContainer>(),
ApplicationMode = this.applicationMode
};

// Create the Component Overrides node
var componentOverridesContainer = new CategoryContainer()
{
DisplayText = "Component Overrides"
};
componentOverridesContainer.QuestionGroups = new List<QuestionGroup>();
resp.CategoryContainers.Add(componentOverridesContainer);


resp.QuestionCount = 0;
resp.RequirementCount = 0;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
using CSETWeb_Api.BusinessLogic.Models;
using CSETWeb_Api.BusinessLogic.BusinessManagers.Analysis;
using Microsoft.EntityFrameworkCore;
using Newtonsoft.Json;
using Microsoft.EntityFrameworkCore.Internal;

namespace CSETWeb_Api.BusinessManagers
{
Expand Down Expand Up @@ -101,14 +103,149 @@ from b in db.VIEW_QUESTIONS_STATUS.Where(x => x.Answer_Id == a.Answer_Id).Defaul


/// <summary>
/// Construct a response containing the applicable requirement questions with their answers.
///
/// </summary>
/// <param name="requirements"></param>
/// <param name="answers"></param>
/// <param name="domains"></param>
/// <returns></returns>
private QuestionResponse BuildResponse(List<RequirementPlus> requirements,
List<FullAnswer> answers, List<DomainAssessmentFactor> domains)
{
var response = new QuestionResponse
{
CategoryContainers = new List<CategoryContainer>()
};

// build a container for each domain
foreach (var d in domains.Select(d => d.DomainName).Distinct())
{
response.CategoryContainers.Add(new CategoryContainer()
{
DisplayText = d,
DomainText = d,
IsDomain = true
});
}

// add the categories/assessment factor names to the domains
foreach (var d in domains)
{
response.CategoryContainers.Where(c => c.DomainText == d.DomainName).First()
.QuestionGroups.Add(new QuestionGroup()
{
GroupHeadingText = d.AssessmentFactorName
});
}

var json = JsonConvert.SerializeObject(requirements);

foreach (var req in requirements)
{
var dbR = req.Requirement;

// Make sure there are no leading or trailing spaces - it will affect the tree structure that is built
dbR.Standard_Category = dbR.Standard_Category ?? dbR.Standard_Category.Trim();
dbR.Standard_Sub_Category = dbR.Standard_Sub_Category ?? dbR.Standard_Sub_Category.Trim();

// If the Standard_Sub_Category is null (like CSC_V6), default it to the Standard_Category
if (dbR.Standard_Sub_Category == null)
{
dbR.Standard_Sub_Category = dbR.Standard_Category;
}

// drop into the domain
var targetDomainCategory = response.CategoryContainers.SelectMany(cc => cc.QuestionGroups).Where(qg => qg.GroupHeadingText == dbR.Standard_Category).FirstOrDefault();
if (targetDomainCategory != null)
{
var targetSubcat = targetDomainCategory.SubCategories.Where(sc => sc.SubCategoryHeadingText == dbR.Standard_Sub_Category).FirstOrDefault();
if (targetSubcat == null)
{
targetSubcat = new QuestionSubCategory()
{
SubCategoryId = 0,
SubCategoryHeadingText = dbR.Standard_Sub_Category,
// GroupHeadingId = g.GroupHeadingId
};

targetDomainCategory.SubCategories.Add(targetSubcat);
}




FullAnswer answer = answers.Where(x => x.a.Question_Or_Requirement_Id == dbR.Requirement_Id).FirstOrDefault();

var qa = new QuestionAnswer()
{
DisplayNumber = dbR.Requirement_Title,
QuestionId = dbR.Requirement_Id,
QuestionText = dbR.Requirement_Text.Replace("\r\n", "<br/>").Replace("\n", "<br/>").Replace("\r", "<br/>"),
Answer = answer?.a.Answer_Text,
AltAnswerText = answer?.a.Alternate_Justification,
Comment = answer?.a.Comment,
Feedback = answer?.a.Feedback,
MarkForReview = answer?.a.Mark_For_Review ?? false,
Reviewed = answer?.a.Reviewed ?? false,
MaturityLevel = ReqMaturityLevel(dbR.Requirement_Id),
SetName = req.SetName,
Is_Component = answer?.a.Is_Component ?? false,
Is_Requirement = answer?.a.Is_Requirement ?? true
};
if (answer != null)
{
TinyMapper.Map<VIEW_QUESTIONS_STATUS, QuestionAnswer>(answer.b, qa);
}

qa.ParmSubs = GetTokensForRequirement(qa.QuestionId, (answer != null) ? answer.a.Answer_Id : 0);

targetSubcat.Questions.Add(qa);
}
}

return response;
}


private CategoryContainer BuildDomainResponse(DomainAssessmentFactor domain)
{
var d = new CategoryContainer()
{
DisplayText = domain.DomainName,
IsDomain = true,
AssessmentFactorName = domain.AssessmentFactorName,
DomainText = "dummy domain text"
};

return d;
}


private QuestionGroup BuildCategoryResponse()
{
return new QuestionGroup();
}


private QuestionSubCategory BuildSubcategoryResponse()
{
return new QuestionSubCategory();
}


/// <summary>
/// Construct a response containing the applicable requirement questions with their answers.
/// </summary>
/// <param name="requirements"></param>
/// <param name="answers"></param>
/// <returns></returns>
private QuestionResponse BuildResponseOLD(List<RequirementPlus> requirements,
List<FullAnswer> answers, List<DomainAssessmentFactor> domains)
{


var xxyz = domains;

List<QuestionGroup> groupList = new List<QuestionGroup>();
QuestionGroup g = new QuestionGroup();
QuestionSubCategory sg = new QuestionSubCategory();
Expand Down Expand Up @@ -143,11 +280,11 @@ private QuestionResponse BuildResponse(List<RequirementPlus> requirements,
StandardShortName = dbRPlus.SetShortName,
};

if (domains.Any(x => x.AssessmentFactorName == g.GroupHeadingText))
{
g.DomainName = domains.FirstOrDefault(x => x.AssessmentFactorName == g.GroupHeadingText)
.DomainName;
}
//if (domains.Any(x => x.AssessmentFactorName == g.GroupHeadingText))
//{
// g.DomainName = domains.FirstOrDefault(x => x.AssessmentFactorName == g.GroupHeadingText)
// .DomainName;
//}

groupList.Add(g);

Expand Down Expand Up @@ -200,10 +337,20 @@ private QuestionResponse BuildResponse(List<RequirementPlus> requirements,

QuestionResponse resp = new QuestionResponse
{
QuestionGroups = groupList,
CategoryContainers = new List<CategoryContainer>(),
ApplicationMode = this.applicationMode
};

// we have one 'dummy' domain
var domain = new CategoryContainer()
{
DisplayText = "dummy"
};
domain.QuestionGroups = groupList;
resp.CategoryContainers.Add(domain);



resp.QuestionCount = new QuestionsManager(this._assessmentId).NumberOfQuestions();
resp.RequirementCount = this.NumberOfRequirements();

Expand Down Expand Up @@ -612,6 +759,11 @@ internal class DomainAssessmentFactor
{
public string DomainName;
public string AssessmentFactorName;

public override string ToString()
{
return string.Format("DomainName: {0}, AssessmentFactorName: {1}", this.DomainName, this.AssessmentFactorName);
}
}

internal class ParameterAssessment
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ public class AssessmentDetail
public string Assets;
public bool? IsAcetOnly;

// Selected features of the assessment
public bool UseStandard;
public bool UseMaturity;
public bool UseDiagram;

/// <summary>
/// The last time the Assessment was altered.
/// </summary>
Expand Down
Loading

0 comments on commit e563eee

Please sign in to comment.