Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Revert "feat: Filter Storage Mode Responses by Submission Id" #358

Merged
merged 1 commit into from
Sep 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 5 additions & 39 deletions src/app/controllers/encrypt-submissions.server.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ const {
getProcessedResponses,
} = require('../modules/submission/submission.service')

const HttpStatus = require('http-status-codes')

/**
* Extracts relevant fields, injects questions, verifies visibility of field and validates answers
* to produce req.body.parsedResponses
Expand Down Expand Up @@ -225,47 +223,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)
// Reading from primary to avoid any contention issues with bulk queries on secondary servers
Submission.findOne(matchClause, { created: 1 })
.read('primary')
.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 @@ -40,12 +40,7 @@ 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.attachmentDownloadUrls = new Map()
vm.filterBySubmissionRefId = '' // whether to filter submissions by a specific ID
vm.filterBySubmissionRefIdTextbox = ''
vm.filterBySubmissionRefIdMatcher = /^[0-9A-Fa-f]{24}$/
vm.filterBySubmissionShowFilterBox = false

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

vm.filterBySubmissionChanged = function () {
// We only reload the table if the text box has changed. This prevents excessive
// requests being sent by users clicking on the "Filter" button repeatedly.
if (
vm.filterBySubmissionRefIdTextbox !== '' &&
vm.filterBySubmissionRefId !== vm.filterBySubmissionRefIdTextbox
) {
vm.filterBySubmissionRefId = vm.filterBySubmissionRefIdTextbox
vm.tableParams.reload()
}
}

vm.filterBySubmissionReset = function () {
vm.filterBySubmissionShowFilterBox = false
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 @@ -356,7 +334,6 @@ function ViewResponsesController(
let { page } = params.url()
return Submissions.getMetadata({
formId: vm.myform._id,
filterBySubmissionRefId: vm.filterBySubmissionRefId,
page,
})
.then((data) => {
Expand Down
1 change: 1 addition & 0 deletions src/public/modules/forms/admin/css/export-button.css
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
display: flex;
justify-content: center;
align-items: center;
min-width: 164px;
margin-left: auto;
}

Expand Down
22 changes: 1 addition & 21 deletions src/public/modules/forms/admin/css/view-responses.css
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,7 @@
}

#responses-tab .response-stats {
white-space: nowrap;
min-width: 240px;
width: 100%;
}

#responses-tab .datepicker-export-container {
Expand Down Expand Up @@ -716,22 +715,3 @@
padding-left: 16px !important;
border: solid 1px #ccc;
}

#filter-by-submission-reset-link {
padding-top: 13px;
padding-left: 13px;
white-space: nowrap;
cursor: pointer;
}

#filter-by-submission-filter-link {
padding-top: 13px;
padding-left: 5px;
white-space: nowrap;
cursor: pointer;
}

#filter-by-submission-filter-textbox-container {
display: flex;
min-width: 240px;
}
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 @@ -64,43 +62,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-3 response-stats">
<div class="response-stats">
<span class="stats-text">
<span
><span class="stats">{{vm.responsesCount}}</span> response(s) to
date</span
>
<a
id="filter-by-submission-filter-link"
ng-show="!vm.filterBySubmissionShowFilterBox"
ng-click="vm.filterBySubmissionShowFilterBox = true"
>
<i class="bx bx-search"></i>
</a>
</span>
</div>
<div
class="col-md-6"
ng-show="vm.filterBySubmissionShowFilterBox"
id="filter-by-submission-filter-textbox-container"
>
<input
class="input-custom input-medium"
ng-model="vm.filterBySubmissionRefIdTextbox"
ng-change="vm.filterBySubmissionChanged()"
ng-model-options="{ debounce: 150 }"
placeholder="Search by reference no."
/>
<span
id="filter-by-submission-reset-link"
ng-show="vm.filterBySubmissionRefId !== ''"
>
<a ng-click="vm.filterBySubmissionReset()">View&nbsp;All</a>
</span>
</div>
<div class="datepicker-export-container col-md-3">
<div class="datepicker-export-container">
<date-range-picker-directive
class="datepicker-container"
ng-model="vm.datePicker.date"
Expand All @@ -112,11 +84,8 @@
></export-button-component>
</div>
</div>
<div class="flex-row" ng-show="vm.filterBySubmissionShowFilterBox">
<div class="col-md-5"></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 @@ -139,21 +108,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 @@ -146,14 +146,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