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

feat: refresh storage mode responses when navigating to data / responses tab #210

Closed
wants to merge 3 commits into from
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,12 @@ function AdminFormController(
FormApi,
) {

// Track active main tab
$scope.activeMainTab = 'Build'
$scope.setActiveMainTab = (value) => {
$scope.activeMainTab = value
}

// Banner message on form builder routes
$scope.bannerContent = $window.siteBannerContent || $window.adminBannerContent

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,21 +255,29 @@ function ViewResponsesController(
}
}

vm.setSubmissionsCount = function() {
Submissions.count({
formId: vm.myform._id,
})
.then((responsesCount) => {
vm.responsesCount = responsesCount
$timeout(() => {
vm.loading = false
}, 200)
})
.catch((error) => {
console.error(error)
})
}

// When this route is initialized, call the responses count function
// Trigger refresh when user navigates to responses subtab
// It is necessary to watch $parent for vm.activeResultsTab as
// a different object with the same name (vm) already exists in $scope
$scope.$parent.$watch('vm.activeResultsTab', (newValue) => {
if (newValue === 'responses' && vm.loading) {
Submissions.count({
formId: vm.myform._id,
})
.then((responsesCount) => {
vm.responsesCount = responsesCount
$timeout(() => {
vm.loading = false
}, 200)
})
.catch((error) => {
console.error(error)
})
if (newValue === 'responses') {
vm.setSubmissionsCount()
vm.refreshResponses()
}
})

Expand Down Expand Up @@ -322,6 +330,32 @@ function ViewResponsesController(
}
}

// Refresh responses if responses have already been unlocked, and
// user navigates to Data tab or Responses subtab
vm.refreshResponses = function() {
if (vm.encryptionKey) {
vm.loadResponses()
}
}


// Trigger refresh when user navigates to Data tab

$scope.$watch(
'activeMainTab',
(newValue) => {
if (newValue === 'results') vm.refreshResponses()
},
)

// Trigger refresh of response count for unlocked responses when user navigates to Data tab

$scope.$watch('activeMainTab', (newValue) => {
if (newValue === 'results') {
vm.setSubmissionsCount()
}
})

// Triggers the download progress modal after SHOW_PROGRESS_DELAY_MS has
// passed and is still downloading after export button click.
let timeoutPromise
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,11 @@
<uib-tabset type="pills">
<div id="admin-tab-bar">
<div id="admin-tabs-container" drag-scroll="true">
<uib-tab ng-repeat="viewTab in viewTabs" heading="{{viewTab.title}}">
<uib-tab
ng-repeat="viewTab in viewTabs"
heading="{{viewTab.title}}"
select="setActiveMainTab(viewTab.route)"
>
<div ui-view="{{viewTab.route}}"></div>
</uib-tab>
</div>
Expand Down