Skip to content

Commit

Permalink
Updated to endpoints and changed to localstorage
Browse files Browse the repository at this point in the history
  • Loading branch information
johc committed Nov 15, 2023
1 parent 18e5ec6 commit 840d760
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -96,16 +96,16 @@ export function ConfigurationController($scope, $http, menuService, endpointServ
$scope.telemetryConsent;

$scope.fetchTelemetryConsent = function () {
$http.post(`/dashboard/get_telemetry_answered`)
$http.post(`/dashboard/get_is_telemetry_answered`)
.then(function (response) {
$scope.telemetryConsent = response.data.get_telemetry_answered;
$scope.telemetryConsent = response.data;
}, function (error) {
console.error('Error fetching telemetry consent:', error);
});
};

$scope.handleTelemetry = function (consent) {
$http.post('/dashboard/telemetry/accept_telemetry', { 'consent': consent })
$http.post('/dashboard/telemetry/accept_telemetry_consent', { 'consent': consent })
.then(function (response) {
}, function (error) {
console.error('Error updating telemetry consent:', error);
Expand Down
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;
};
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
export function TelemetryController($scope, $http) {
$scope.telemetryShow = false;
$scope.telemetryShow = true;
$scope.followUpShow = false;

$scope.fetchTelemetryConsent = function () {
$http.post(`/dashboard/get_telemetry_answered`)
$http.post(`/dashboard/get_is_telemetry_answered`)
.then(function (response) {
$scope.telemetryShow = !response.data.get_telemetry_answered;
$scope.telemetryShow = !response.data.is_telemetry_answered;
}, function (error) {
console.error('Error fetching telemetry consent:', error);
});
Expand All @@ -16,7 +16,7 @@ export function TelemetryController($scope, $http) {
$scope.telemetryShow = false;
$scope.followUpShow = !consent;

$http.post('/dashboard/telemetry/accept_telemetry', { 'consent': consent })
$http.post('/dashboard/telemetry/accept_telemetry_consent', { 'consent': consent })
.then(function (response) {
$scope.telemetryShow = false;
}, function (error) {
Expand Down
Loading

0 comments on commit 840d760

Please sign in to comment.