Skip to content

Commit

Permalink
Pull request finos#337: CTCTOWALTZ-2996 survey template revoke open s…
Browse files Browse the repository at this point in the history
…urvey actions 6879

Merge in WALTZ/waltz from WALTZ/waltz-jws:CTCTOWALTZ-2996-survey-template-revoke-open-survey-actions-6879 to db-feature/waltz-6879-allow-admin-to-withdraw-all-active-instacnes-for-run

* commit '4bc6fc558b001ef7bdbf696ba70bda6cff626a88':
  Add withdraw all open surveys for template button
  Making buttons fill space
  Allow survey run admin or template admin to withdraw all open surveys from a run
  Add search to survey template list
  • Loading branch information
jessica-woodland-scott-db authored and db-waltz committed Jan 10, 2024
2 parents 3dcf19a + 4bc6fc5 commit 0429ed5
Show file tree
Hide file tree
Showing 8 changed files with 223 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,20 @@ public Set<SurveyInstance> findForSurveyRun(long surveyRunId) {
}


public Set<SurveyInstance> findForSurveyRun(long surveyRunId, SurveyInstanceStatus... statuses) {
Set<String> statusStrings = Arrays.stream(statuses).map(s -> s.name()).collect(toSet());

return dsl.select(si.fields())
.select(ENTITY_NAME_FIELD)
.select(EXTERNAL_ID_FIELD)
.from(si)
.where(si.SURVEY_RUN_ID.eq(surveyRunId))
.and(IS_ORIGINAL_INSTANCE_CONDITION)
.and(si.STATUS.in(statusStrings))
.fetchSet(TO_DOMAIN_MAPPER);
}


public Set<SurveyInstance> findForSurveyTemplate(long templateId, SurveyInstanceStatus... statuses) {
Set<String> statusStrings = Arrays.stream(statuses).map(s -> s.name()).collect(toSet());

Expand Down
28 changes: 27 additions & 1 deletion waltz-ng/client/survey/services/survey-instance-store.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,20 @@ function store($http, baseApiUrl) {
.then(result => result.data);
};

const withdrawOpenSurveysForRun = (surveyRunId) => {
return $http
.post(`${base}/run/${surveyRunId}/withdraw-open`)
.then(result => result.data);
};


const withdrawOpenSurveysForTemplate = (surveyTemplateId) => {
return $http
.post(`${base}/template/${surveyTemplateId}/withdraw-open`)
.then(result => result.data);
};


return {
getById,
getPermissions,
Expand All @@ -170,7 +184,9 @@ function store($http, baseApiUrl) {
addOwner,
deleteOwner,
markApproved,
reportProblemWithQuestionResponse
reportProblemWithQuestionResponse,
withdrawOpenSurveysForRun,
withdrawOpenSurveysForTemplate
};
}

Expand Down Expand Up @@ -294,6 +310,16 @@ export const SurveyInstanceStore_API = {
serviceName,
serviceFnName: "reportProblemWithQuestionResponse",
description: "creates change log entry for survey instance"
},
withdrawOpenSurveysForRun: {
serviceName,
serviceFnName: "withdrawOpenSurveysForRun",
description: "withdraws all open (in progress / not started) survey instances in a run"
},
withdrawOpenSurveysForTemplate: {
serviceName,
serviceFnName: "withdrawOpenSurveysForTemplate",
description: "withdraws all open (in progress / not started) survey instances for this template"
}
};

Expand Down
9 changes: 9 additions & 0 deletions waltz-ng/client/survey/survey-template-list.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,15 @@
</a>
</waltz-section-actions>

<waltz-search-control on-query="ctrl.doSearch"
min-characters='2'
delay="200"
placeholder-text="Search Survey Templates">
</waltz-search-control>

<br>
<br>

<div ng-repeat="group in ctrl.groupedTemplates track by group.key">
<br ng-if="!$first">
<h4>
Expand Down
25 changes: 20 additions & 5 deletions waltz-ng/client/survey/survey-template-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
import _ from "lodash";
import {nest} from "d3-collection";
import {ascending} from "d3-array";
import template from './survey-template-list.html';
import template from "./survey-template-list.html";
import {termSearch} from "../common";


function processTemplates(templates = []) {
Expand All @@ -36,7 +37,7 @@ function loadOwners(holder, personStore, templates = []) {

const personIds = _
.chain(templates)
.map('ownerId')
.map("ownerId")
.uniq()
.value();

Expand All @@ -56,22 +57,36 @@ function controller(personStore, surveyTemplateStore) {
surveyTemplateStore
.findByOwner()
.then(ts => {
vm.templates = ts;
vm.groupedTemplates = processTemplates(ts);
loadOwners(vm, personStore, ts)
});

vm.doSearch = (qry) => {
const templates = _.isEmpty(qry)
? vm.templates
: termSearch(
vm.templates,
qry,
[
"name",
"description",
"externalId"
]);
vm.groupedTemplates = processTemplates(templates);
}
}


controller.$inject = [
'PersonStore',
'SurveyTemplateStore'
"PersonStore",
"SurveyTemplateStore"
];


const page = {
controller,
controllerAs: 'ctrl',
controllerAs: "ctrl",
template
};

Expand Down
7 changes: 7 additions & 0 deletions waltz-ng/client/survey/survey-template-view.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@
ui-sref="main.survey.template.edit ({id: ctrl.template.id })">
Edit
</a>
<button class="btn btn-warning btn-xs"
waltz-has-role="SURVEY_ADMIN"
ng-disabled="!ctrl.hasOpenSurveys"
ng-if="ctrl.template.status === 'OBSOLETE'"
ng-click="ctrl.withdrawOpenSurveysForTemplate(ctrl.template)">
Withdraw all Open Surveys
</button>
<a class="btn btn-primary btn-xs"
waltz-has-role="SURVEY_TEMPLATE_ADMIN"
ng-click="ctrl.cloneTemplate()">
Expand Down
55 changes: 46 additions & 9 deletions waltz-ng/client/survey/survey-template-view.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,15 +105,20 @@ function mkColumnDefs() {
width: "8%",
cellTemplate:
`
<div class="ui-grid-cell-contents">
<a ng-click="grid.appScope.deleteRun(row.entity.surveyRun)"
ng-if="row.entity.isRunOwnedByLoggedInUser"
uib-popover="Delete this Survey Run"
popover-placement="left"
popover-trigger="mouseenter"
class="btn btn-xs btn-danger waltz-visibility-child-30">
<waltz-icon name="trash-o"></waltz-icon>
</a>
<div class="ui-grid-cell-contents" style="padding: 2px; display: flex; gap: 5px">
<button ng-click="grid.appScope.withdrawOpenSurveys(row.entity.surveyRun)"
ng-disabled="!row.entity.hasOpenSurveys"
ng-if="row.entity.isRunOwnedByLoggedInUser || row.entity.hasAdminRights"
title="Withdraw all open instances ('Not Started' and 'In Progress')"
class="btn btn-xs btn-warning waltz-visibility-child-30 small">
<waltz-icon name="wpforms"></waltz-icon>
</button>
<button ng-click="grid.appScope.deleteRun(row.entity.surveyRun)"
ng-if="row.entity.isRunOwnedByLoggedInUser || row.entity.isTemplateOwnerOrAdmin"
title="Delete this Survey Run"
class="btn btn-xs btn-danger waltz-visibility-child-30">
<waltz-icon name="trash-o"></waltz-icon>
</button>
</div>
`
}
Expand Down Expand Up @@ -178,10 +183,14 @@ function controller($q,
d.isRunOwnedByLoggedInUser = d.owner
? (_.toLower(d.owner.email) === _.toLower(user.userName))
: false;
d.hasAdminRights = userIsTemplateOwner || userIsAdmin || userHasIssuanceRights
d.hasOpenSurveys = stats.inProgressCount > 0 || stats.notStartedCount > 0
return d;
})
.partition(d => d.surveyRun.status !== "DRAFT")
.value();

vm.hasOpenSurveys = _.some(vm.issuedAndCompleted, d => d.hasOpenSurveys);
});
};

Expand Down Expand Up @@ -269,6 +278,34 @@ function controller($q,
});
}
}

vm.withdrawOpenSurveys = (surveyRun) => {
if(confirm(`Are you sure you want withdraw all open surveys for this survey run: ${surveyRun.name}?`)){
serviceBroker
.execute(CORE_API.SurveyInstanceStore.withdrawOpenSurveysForRun, [surveyRun.id])
.then(r => {
toasts.warning(`${r.data} 'Not started' and 'In progress' survey runs have been withdrawn`);
loadRuns();
})
.catch(e => {
displayError("Could not withdraw open survey runs", e);
});
}
}

vm.withdrawOpenSurveysForTemplate = (surveyTemplate) => {
if(confirm(`Are you sure you want withdraw all open surveys for this template: ${surveyTemplate.name}?`)){
serviceBroker
.execute(CORE_API.SurveyInstanceStore.withdrawOpenSurveysForTemplate, [surveyTemplate.id])
.then(r => {
toasts.warning(`${r.data} 'Not started' and 'In progress' survey runs have been withdrawn`);
loadRuns();
})
.catch(e => {
displayError("Could not withdraw open survey runs", e);
});
}
}
}


Expand Down
Loading

0 comments on commit 0429ed5

Please sign in to comment.