-
Notifications
You must be signed in to change notification settings - Fork 159
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updated to endpoints and changed to localstorage
- Loading branch information
johc
committed
Nov 15, 2023
1 parent
18e5ec6
commit 840d760
Showing
5 changed files
with
33 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 22 additions & 20 deletions
42
flask_monitoringdashboard/frontend/js/controllers/surveyController.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,52 @@ | ||
export function SurveyController($scope, $http, $sce) { | ||
$scope.surveyShow = false; | ||
$scope.surveyCompleted = false; // New flag for survey completion | ||
$scope.surveyVariationIndex = 0; | ||
$scope.surveyCompleted = false; | ||
|
||
// Fetch local storage variation index | ||
const storedIndex = localStorage.getItem('surveyVariationIndex'); | ||
$scope.surveyVariationIndex = storedIndex && !isNaN(parseInt(storedIndex)) ? parseInt(storedIndex) : 0; | ||
|
||
// Variations of the survey prompt | ||
$scope.surveyVariations = [ | ||
'Please take a moment to <a href="https://forms.gle/kWD5mqcibS2V5f3Y6" target="_blank">fill out our survey</a>.', | ||
'Your feedback is valuable! <a href="https://forms.gle/kWD5mqcibS2V5f3Y6" target="_blank">Take our quick survey.</a>', | ||
'We value your opinion! Click <a href="https://forms.gle/kWD5mqcibS2V5f3Y6" target="_blank">here</a> to share your thoughts.', | ||
'Help us improve! Participate in our <a href="https://forms.gle/kWD5mqcibS2V5f3Y6" target="_blank">short survey</a>.' | ||
]; | ||
|
||
// Mark as trusted HTML | ||
$scope.surveyVariations = $scope.surveyVariations.map(variation => | ||
$sce.trustAsHtml(variation) | ||
); | ||
|
||
|
||
$scope.fetchSurveyStatus = function () { | ||
$http.post('/dashboard/survey_status') | ||
// Fetches the survey from database | ||
$scope.fetchSurveyFilled = function () { | ||
$http.post('/dashboard/get_is_survey_filled') | ||
.then(function (response) { | ||
$scope.surveyVariationIndex = response.data.surveyVariationIndex; | ||
$scope.surveyCompleted = response.data.surveyCompleted; | ||
$scope.surveyShow = !$scope.surveyCompleted && ($scope.surveyVariationIndex < $scope.surveyVariations.length); | ||
$scope.surveyCompleted = response.data.is_survey_filled; | ||
}, function (error) { | ||
console.error('Error fetching survey status:', error); | ||
}); | ||
$scope.surveyShow = !$scope.surveyCompleted && ($scope.surveyVariationIndex < $scope.surveyVariations.length); | ||
}; | ||
$scope.fetchSurveyStatus(); | ||
$scope.fetchSurveyFilled(); | ||
|
||
// Increment surveyVariation in localStorage | ||
$scope.closeSurvey = function () { | ||
if (!$scope.surveyCompleted) { | ||
$scope.surveyVariationIndex++; | ||
$http.post('/dashboard/survey_status', { surveyVariationIndex: $scope.surveyVariationIndex }) | ||
.then(function (response) { | ||
$scope.surveyShow = false; | ||
}, function (error) { | ||
console.error('Error:', error); | ||
}); | ||
localStorage.setItem('surveyVariationIndex', $scope.surveyVariationIndex.toString()); | ||
} | ||
}; | ||
|
||
$scope.surveyClicked = function () { | ||
$http.post('/dashboard/survey_clicked') | ||
// Mark survey as filled in database | ||
$scope.surveyFilled = function () { | ||
$http.post('/dashboard/survey_has_been_filled') | ||
.then(function (response) { | ||
$scope.surveyCompleted = true; | ||
$scope.surveyShow = false; | ||
}, function (error) { | ||
console.error('Error:', error); | ||
}); | ||
$scope.surveyCompleted = true; | ||
$scope.surveyShow = false; | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.