Skip to content

Commit

Permalink
Revert "feat: Filter Storage Mode Responses by Submission Id (#71)"
Browse files Browse the repository at this point in the history
This reverts commit eaef2eb.
  • Loading branch information
mantariksh committed Aug 14, 2020
1 parent e081673 commit ffe4218
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 81 deletions.
39 changes: 5 additions & 34 deletions src/app/controllers/encrypt-submissions.server.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,44 +202,15 @@ exports.saveResponseToDb = function (req, res, next) {
*/
exports.getMetadata = function (req, res) {
let pageSize = 10
let { page, submissionId } = req.query || {}
let { page } = req.query || {}
let numToSkip = parseInt(page - 1 || 0) * pageSize

let matchClause = {
form: req.form._id,
submissionType: 'encryptSubmission',
}

if (submissionId) {
if (mongoose.Types.ObjectId.isValid(submissionId)) {
matchClause._id = mongoose.Types.ObjectId(submissionId)
Submission.findOne(matchClause, { created: 1 }).exec((err, result) => {
if (err) {
logger.error(getRequestIp(req), req.url, req.headers, err)
return res.status(HttpStatus.INTERNAL_SERVER_ERROR).send({
message: errorHandler.getMongoErrorMessage(err),
})
}
if (!result) {
return res.status(HttpStatus.OK).send({ metadata: [], count: 0 })
}
let entry = {
number: 1,
refNo: result._id,
submissionTime: moment(result.created)
.tz('Asia/Singapore')
.format('Do MMM YYYY, h:mm:ss a'),
}
return res.status(HttpStatus.OK).send({ metadata: [entry], count: 1 })
})
} else {
return res.status(HttpStatus.OK).send({ metadata: [], count: 0 })
}
}

Submission.aggregate([
{
$match: matchClause,
$match: {
form: req.form._id,
submissionType: 'encryptSubmission',
},
},
{
$sort: { created: -1 },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ function ViewResponsesController(
vm.isEncryptResponseMode = vm.myform.responseMode === responseModeEnum.ENCRYPT
vm.encryptionKey = null // will be set to an instance of EncryptionKey when form is unlocked successfully
vm.csvDownloading = false // whether CSV export is in progress
vm.filterBySubmissionRefId = '' // whether to filter submissions by a specific ID
vm.filterBySubmissionRefIdTextbox = ''

// Three views:
// 1 - Unlock view for verifying form password
Expand Down Expand Up @@ -238,15 +236,12 @@ function ViewResponsesController(
}
})

vm.filterBySubmissionChanged = function () {
vm.filterBySubmissionRefId = vm.filterBySubmissionRefIdTextbox
vm.tableParams.reload()
}

// Called by child directive unlockResponsesForm after key is verified to get responses
vm.loadResponses = function () {
vm.loadResponses = function (formPassword) {
vm.formPassword = formPassword
vm.currentView = 2
vm.loading = true

vm.tableParams = new NgTableParams(
{
page: 1, // show first page
Expand All @@ -257,7 +252,6 @@ function ViewResponsesController(
let { page } = params.url()
return Submissions.getMetadata({
formId: vm.myform._id,
filterBySubmissionRefId: vm.filterBySubmissionRefId,
page,
})
.then((data) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@

<!-- Storage Mode -->
<div ng-if="!vm.loading && vm.isEncryptResponseMode">
<div
ng-if="vm.currentView === 1 && vm.responsesCount === 0 && vm.filterBySubmissionRefId === ''"
>
<div ng-if="vm.responsesCount === 0">
<div class="flex-column">
<img
id="no-responses"
Expand Down Expand Up @@ -66,28 +64,17 @@
>
</verify-secret-key-directive>
</div>
<div ng-if="vm.currentView === 2">
<div ng-if="vm.responsesCount > 0 && vm.currentView === 2">
<div class="flex-row">
<div class="col-md-12 response-stats">
<div class="response-stats">
<span class="stats-text">
<span
><span class="stats">{{vm.responsesCount}}</span> response(s) to
date</span
>
</span>
</div>
</div>
<div class="flex-row">
<div class="col-md-6">
<input
class="input-custom input-medium"
ng-model="vm.filterBySubmissionRefIdTextbox"
ng-change="vm.filterBySubmissionChanged()"
ng-model-options="{ debounce: 200 }"
placeholder="Filter by Submission Ref No."
/>
</div>
<div class="datepicker-export-container col-md-6">
<div class="datepicker-export-container">
<date-range-picker-directive
class="datepicker-container"
ng-model="vm.datePicker.date"
Expand All @@ -100,7 +87,7 @@
</div>
</div>
<div class="row">
<div ng-if="vm.responsesCount > 0" class="col-md-12">
<div class="col-md-12">
<table class="table" ng-table="vm.tableParams" show-filter="false">
<tr ng-repeat="row in $data" ng-click="vm.rowOnClick($index)">
<td
Expand All @@ -123,21 +110,6 @@
</tr>
</table>
</div>
<div
ng-if="vm.responsesCount === 0 && vm.filterBySubmissionRefId !== ''"
>
<div class="flex-column">
<img
ng-src="/public/modules/core/img/error-illustration.svg"
id="no-responses"
/>
<div class="title">No results found</div>
<div class="subtitle">
Did you enter the right reference number? We can't seem to find
the response.
</div>
</div>
</div>
</div>
</div>
<div
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,14 +143,10 @@ function SubmissionsFactory(
},
getMetadata: function (params) {
const deferred = $q.defer()
let resUrl = `${fixParamsToUrl(params, submitAdminUrl)}/metadata?page=${
const resUrl = `${fixParamsToUrl(params, submitAdminUrl)}/metadata?page=${
params.page
}`

if (params.filterBySubmissionRefId) {
resUrl += `&submissionId=${params.filterBySubmissionRefId}`
}

$http.get(resUrl).then(
function (response) {
deferred.resolve(response.data)
Expand Down

0 comments on commit ffe4218

Please sign in to comment.