Skip to content

Commit

Permalink
Merge pull request #6214 from davidwatkins73/waltz-6210-template-names
Browse files Browse the repository at this point in the history
Survey lists show template name
  • Loading branch information
jessica-woodland-scott-db authored Sep 5, 2022
2 parents ed3658e + 02ce00c commit 4732c61
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@
<slot name="pre-header"/>
<table class="table table-condensed small">
<tbody>
<tr>
<td width="50%">Template Name</td>
<td width="50%">{survey.surveyTemplateRef?.name}</td>
</tr>
<tr>
<td width="50%">Run Name</td>
<td width="50%">{survey.surveyRun?.name}</td>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,9 @@
ng-if="surveys.length > 0">
<thead>
<tr>
<th>Title</th>
<th>Name</th>
<th>Template Name</th>
<th>Run Name</th>
<th>Instance Name</th>
<th ng-if="$ctrl.visibility.showSurveySubject">Subject</th>
<th>Status</th>
<th>Issued On</th>
Expand All @@ -86,6 +87,9 @@
</thead>
<tbody>
<tr ng-repeat="row in surveys | orderBy:'surveyRun.name'">
<td>
<span ng-bind="row.surveyTemplate.name"></span>
</td>
<td>
<a ng-bind="row.surveyRun.name"
class="clickable"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,23 +39,34 @@ const initialState = {
};


function mkTableData(surveyRuns = [], surveyInstances = []) {
function mkTableData(surveyRuns = [], surveyInstances = [], templates = []) {
const runsById = _.keyBy(surveyRuns, "id");

const surveys = _.map(surveyInstances, instance => {
return {
"surveyInstance": instance,
"surveyRun": runsById[instance.surveyRunId],
"surveyEntity": instance.surveyEntity
}
});
const templatesById = _.keyBy(templates, "id");

const surveys = _.map(
surveyInstances,
instance => {
const run = runsById[instance.surveyRunId];
const template = run
? templatesById[run.surveyTemplateId]
: null;

return {
"surveyInstance": instance,
"surveyRun": run,
"surveyEntity": instance.surveyEntity,
"surveyTemplate": template
};
});

const now = moment();
const grouped = _.groupBy(surveys, s => {
const subMoment = moment(s.surveyInstance.submittedAt);
return s.surveyInstance.status == "WITHDRAWN" || now.diff(subMoment, "months") >= 12 ? "ARCHIVE" : "CURRENT"
});
return grouped;

return _.groupBy(
surveys,
s => {
const subMoment = moment(s.surveyInstance.submittedAt);
return s.surveyInstance.status === "WITHDRAWN" || now.diff(subMoment, "months") >= 12 ? "ARCHIVE" : "CURRENT"
});
}


Expand All @@ -78,6 +89,10 @@ function controller($q, serviceBroker) {
let runsPromise;
let instancesPromise;

const templatePromise = serviceBroker.loadAppData(
CORE_API.SurveyTemplateStore.findAll,
[]);

if (vm.parentEntityRef.kind === 'PERSON') {
runsPromise = serviceBroker.loadViewData(
CORE_API.SurveyRunStore.findForRecipientId,
Expand All @@ -102,9 +117,9 @@ function controller($q, serviceBroker) {

vm.visibility.showSurveySubject = ! isSurveyTargetKind(vm.parentEntityRef.kind);

$q.all([runsPromise, instancesPromise])
.then(([runsResult, instancesResult]) =>
vm.surveys = mkTableData(runsResult.data, instancesResult.data));
$q.all([runsPromise, instancesPromise, templatePromise])
.then(([runsResult, instancesResult, templateResult]) =>
vm.surveys = mkTableData(runsResult.data, instancesResult.data, templateResult.data));
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,10 @@
<table class="table table-condensed">
<thead>
<tr>
<th width="30%">Survey Name</th>
<th width="30%"
style="text-align: left">
Survey Name
</th>
{#each tableHeaders as header}
<th width={`${70 / tableHeaders.length}%`}
class={header.headerClass}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,10 @@
<table class="table table-condensed">
<thead>
<tr>
<th width="30%">Survey Name</th>
<th width="30%"
style="text-align: left">
Survey Name
</th>
{#each tableHeaders as header}
<th width={`${60 / tableHeaders.length}%`}
class={header.headerClass}
Expand Down
2 changes: 1 addition & 1 deletion waltz-ng/client/survey/services/survey-template-store.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ function store($http, baseUrl) {
};

const findAll = () => {
return $http.get(`${BASE}`)
return $http.get(BASE)
.then(result => result.data);
};

Expand Down

0 comments on commit 4732c61

Please sign in to comment.