Skip to content

Commit

Permalink
SW-2542 fix analytics settings (#1707)
Browse files Browse the repository at this point in the history
* Undo tab required change
* Fix analytics settings

Co-authored-by: Josef-MrBeam <[email protected]>
  • Loading branch information
irlaec and Josef-MrBeam authored Mar 14, 2023
1 parent 689d463 commit 4da9c34
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 7 deletions.
2 changes: 1 addition & 1 deletion octoprint_mrbeam/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -995,7 +995,7 @@ def get_template_configs(self):
name=gettext("Better Together"),
template="settings/analytics_settings.jinja2",
suffix="_analytics",
custom_bindings=False,
custom_bindings=True,
),
dict(
type="settings",
Expand Down
36 changes: 35 additions & 1 deletion octoprint_mrbeam/static/js/app/view-models/analytics.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ $(function () {

function AnalyticsViewModel(params) {
let self = this;

const CONSENT_TO_ANALYTICS = "agree";
const DO_NOT_CONSENT_TO_ANALYTICS = "disagree";
window.mrbeam.viewModels["analyticsViewModel"] = self;
self.settings = params[0];

Expand All @@ -58,6 +61,9 @@ $(function () {

// Do not use before onStartupComplete!
self.analyticsEnabled = ko.observable(false);
self.analyticsRadioBtnValue = ko.observable(
DO_NOT_CONSENT_TO_ANALYTICS
);
self.isStartupComplete = false;
self.error_sqeuence = 0;

Expand Down Expand Up @@ -117,6 +123,13 @@ $(function () {

self.onAllBound = function () {
self._updateAnalyticsEnabledValue();

$("input[type=radio][name=analytics_consent]").on(
"change",
function () {
self.changeAnalyticsConsent(this.value);
}
);
/* This is commented out to stop console logging for the time being
if (console.everything) {
Expand Down Expand Up @@ -164,6 +177,27 @@ $(function () {
self.analyticsEnabled(
self.settings.settings.plugins.mrbeam.analyticsEnabled()
);

if (self.analyticsEnabled()) {
self.analyticsRadioBtnValue(CONSENT_TO_ANALYTICS);
} else {
self.analyticsRadioBtnValue(DO_NOT_CONSENT_TO_ANALYTICS);
}
};

self.changeAnalyticsConsent = function (newValue) {
if (newValue === CONSENT_TO_ANALYTICS) {
self.settings.settings.plugins.mrbeam.analyticsEnabled(true);
} else {
self.settings.settings.plugins.mrbeam.analyticsEnabled(false);
}

self.settings.saveData(undefined, function (newSettings) {
console.log(
"Analytics consent change",
newSettings.plugins.mrbeam.analyticsEnabled
);
});
};

self._handleClick = function (e) {
Expand Down Expand Up @@ -249,6 +283,6 @@ $(function () {
["settingsViewModel"],

// e.g. #settings_plugin_mrbeam, #tab_plugin_mrbeam, ...
[],
["#settings_analytics"],
]);
});
6 changes: 3 additions & 3 deletions octoprint_mrbeam/templates/settings/analytics_settings.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{# Wording changes must be done in both templates: wizard_analytics.jinja and analytics_settings.jinja !! #}
{# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! #}

<div class="get-better-together">
<div class="get-better-together" id="settings_analytics">
<div class="row">
<div class="span12">
<img class="hide" loading="lazy" src="{{ url_for('plugin.mrbeam.static', filename='img/getting-better-together.png') }}">
Expand All @@ -26,9 +26,9 @@
<div class="row-fluid">
<div class="span6">
<div id="analytics_initial_consent_radio">
<label><input type="radio" name="analytics_init_consent" value="agree" data-bind="checked: analyticsInitialConsent">
<label><input type="radio" name="analytics_consent" value="agree" data-bind="checked: analyticsRadioBtnValue()">
<strong>{{ _('Yes, contribute') }}</strong></label>
<label><input type="radio" name="analytics_init_consent" value="disagree" data-bind="checked: analyticsInitialConsent">
<label><input type="radio" name="analytics_consent" value="disagree" data-bind="checked: analyticsRadioBtnValue()">
{{ _('No, not at the moment') }}</label>
</div>
</div>
Expand Down
40 changes: 39 additions & 1 deletion octoprint_mrbeam/templates/wizard/wizard_analytics.jinja2
Original file line number Diff line number Diff line change
@@ -1,4 +1,42 @@
{# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! #}
{# Wording changes must be done in both templates: wizard_analytics.jinja and analytics_settings.jinja !! #}
{# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! #}
{% include "settings/analytics_settings.jinja2" %}
<div class="get-better-together">
<div class="row">
<div class="span12">
<img class="hide" loading="lazy" src="{{ url_for('plugin.mrbeam.static', filename='img/getting-better-together.png') }}">
<h4>{{ _('Better together') }}</h4>
<ul>
<li>
<p>
{{ _('We know that your Mr Beam is important to you, and we want to make it even better. That\'s why we\'re asking for your help in improving it by sharing optional diagnostic and usage data. These data would allow us to better understand your needs and preferences, leading to faster identification and resolution of issues, and ultimately, improved features and functionality.') }}
<br>
<br>
{{ _('We understand that your privacy is crucial, and we want to assure you that none of the data collected includes your personal information such as your name, login details, designs, or any other private content. You are in full control, and you can change your mind at any time by going to <strong>"Settings > Better together"</strong>.') }}
</p>
</li>
<li>
<i class="fa fa-heart-o" aria-hidden="true"></i>
<p>
{{ _('Join us and shape the future of Mr Beam Products. Together, we can make them even more amazing!"') }}
</p>
</li>
<li>
<div class="row-fluid">
<div class="span6">
<div id="analytics_initial_consent_radio">
<label><input type="radio" name="analytics_init_consent" value="agree" data-bind="checked: analyticsInitialConsent">
<strong>{{ _('Yes, contribute') }}</strong></label>
<label><input type="radio" name="analytics_init_consent" value="disagree" data-bind="checked: analyticsInitialConsent">
{{ _('No, not at the moment') }}</label>
</div>
</div>
<div class="span6">
<div class="privacy-policy"><a target="_blank" href="{{ url_for('plugin.mrbeam.static', filename='docs/MrBeamAnalytics-PrivacyPolicy_en.pdf') }}">{{ _('Privacy policy') }}</a></div>
</div>
</div>
</li>
</ul>
</div>
</div>
</div>
2 changes: 1 addition & 1 deletion octoprint_mrbeam/wizard_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ def _welcome_wizard_config(self):
wizard_analytics=dict(
type="wizard",
name=gettext("Better together"),
required=True,
required=self._is_analytics_wizard_required(),
mandatory=False,
suffix="_analytics",
template="wizard/wizard_analytics.jinja2",
Expand Down

0 comments on commit 4da9c34

Please sign in to comment.