1
0
mirror of https://github.com/beestat/app.git synced 2025-07-09 03:04:07 -04:00

Fixed #208 - Can't link Patreon account if you've closed the banner.

Made it possible from the beestat menu; also added a link to the support page on the documentation and reworded some stuff.
This commit is contained in:
Jon Ziebell 2019-12-31 08:23:12 -05:00
parent 08403cedc6
commit edb55c8e2a
4 changed files with 159 additions and 151 deletions

View File

@ -41,7 +41,7 @@ beestat.component.card.patreon.prototype.decorate_top_right_ = function(parent)
.set_text_color('#fff') .set_text_color('#fff')
.set_background_hover_color(beestat.style.color.green.light) .set_background_hover_color(beestat.style.color.green.light)
.addEventListener('click', function() { .addEventListener('click', function() {
(new beestat.component.modal.patreon_hide()).render(); (new beestat.component.modal.enjoy_beestat()).render();
}) })
.render(parent); .render(parent);
}; };

View File

@ -153,6 +153,13 @@ beestat.component.header.prototype.decorate_ = function(parent) {
(new beestat.component.modal.download_data()).render(); (new beestat.component.modal.download_data()).render();
})); }));
menu.add_menu_item(new beestat.component.menu_item()
.set_text('Link Patreon')
.set_icon('patreon')
.set_callback(function() {
(new beestat.component.modal.enjoy_beestat()).render();
}));
menu.add_menu_item(new beestat.component.menu_item() menu.add_menu_item(new beestat.component.menu_item()
.set_text('Log Out') .set_text('Log Out')
.set_icon('exit_to_app') .set_icon('exit_to_app')

View File

@ -1,149 +1,150 @@
/** /**
* Options for hiding the patreon card. * Options for hiding the patreon card.
*/ */
beestat.component.modal.patreon_hide = function() { beestat.component.modal.enjoy_beestat = function() {
beestat.component.modal.apply(this, arguments); beestat.component.modal.apply(this, arguments);
}; };
beestat.extend(beestat.component.modal.patreon_hide, beestat.component.modal); beestat.extend(beestat.component.modal.enjoy_beestat, beestat.component.modal);
beestat.component.modal.patreon_hide.poll_interval_ = 5000; beestat.component.modal.enjoy_beestat.poll_interval_ = 5000;
/** /**
* Decorate * Decorate
* *
* @param {rocket.Elements} parent * @param {rocket.Elements} parent
*/ */
beestat.component.modal.patreon_hide.prototype.decorate_contents_ = function(parent) { beestat.component.modal.enjoy_beestat.prototype.decorate_contents_ = function(parent) {
switch (this.is_active_patron_()) { switch (this.is_active_patron_()) {
case false: case false:
parent.appendChild($.createElement('p').innerText('Your Patreon account is connected but you\'re not currently a supporter. If you recently became a supporter it could take up to 24 hours to update.')); parent.appendChild($.createElement('p').innerText('Your Patreon account is connected but you\'re not currently a supporter. If you recently became a supporter it could take up to 24 hours to update.'));
break; break;
case null: case null:
parent.appendChild($.createElement('p').innerText('Hey there! If you didn\'t notice, beestat doesn\'t run ads, cost money, or sell your data. If you find beestat useful, please consider supporting the project. Your contribution helps pay for servers, storage, and other cool things. Thanks!')); parent.appendChild($.createElement('p').innerHTML('If you didn\'t notice, beestat doesn\'t run ads, charge money, or sell your data. If you find beestat useful, <strong>please consider supporting the project on <a href="https://patreon.com/beestat" target="_blank" class="inverted">Patreon</a>.</strong> Your contribution helps pay for servers, storage, and other cool things. Thanks!'));
break; parent.appendChild($.createElement('p').innerHTML('Not into Patreon? <a href="https://www.notion.so/beestat/Support-Beestat-bf7f099eb8de486bad51aa6245c00891" target="_blank" class="inverted">Here are some other ways to help</a>.'));
} break;
}; }
};
/**
* Get the title. /**
* * Get the title.
* @return {string} The title. *
*/ * @return {string} The title.
beestat.component.modal.patreon_hide.prototype.get_title_ = function() { */
return 'Don\'t want to see this anymore?'; beestat.component.modal.enjoy_beestat.prototype.get_title_ = function() {
}; return 'Enjoy beestat?';
};
/**
* Close the modal but run some special code first to make sure any running /**
* interval gets stopped. * Close the modal but run some special code first to make sure any running
*/ * interval gets stopped.
beestat.component.modal.patreon_hide.prototype.dispose = function() { */
if (this.is_polling_ === true) { beestat.component.modal.enjoy_beestat.prototype.dispose = function() {
beestat.remove_poll_interval(beestat.component.modal.patreon_hide.poll_interval_); if (this.is_polling_ === true) {
beestat.dispatcher.removeEventListener('poll.patreon_hide'); beestat.remove_poll_interval(beestat.component.modal.enjoy_beestat.poll_interval_);
} beestat.dispatcher.removeEventListener('poll.enjoy_beestat');
}
beestat.component.modal.prototype.dispose.apply(this, arguments);
}; beestat.component.modal.prototype.dispose.apply(this, arguments);
};
/**
* Hide the Patreon card for some amount of time. /**
* * Hide the Patreon card for some amount of time.
* @param {number} amount How long. *
* @param {string} unit The unit (day, month, etc). * @param {number} amount How long.
*/ * @param {string} unit The unit (day, month, etc).
beestat.component.modal.patreon_hide.prototype.hide_patreon_card_for_ = function(amount, unit) { */
beestat.setting( beestat.component.modal.enjoy_beestat.prototype.hide_patreon_card_for_ = function(amount, unit) {
'patreon_hide_until', beestat.setting(
moment().utc() 'patreon_hide_until',
.add(amount, unit) moment().utc()
.format('YYYY-MM-DD HH:mm:ss') .add(amount, unit)
); .format('YYYY-MM-DD HH:mm:ss')
beestat.cards.patreon.dispose(); );
}; beestat.cards.patreon.dispose();
};
/**
* Determine whether or not the current user is an active Patron. /**
* * Determine whether or not the current user is an active Patron.
* @return {boolean} true if yes, false if no, null if not connected. *
*/ * @return {boolean} true if yes, false if no, null if not connected.
beestat.component.modal.patreon_hide.prototype.is_active_patron_ = function() { */
var user = beestat.get_user(); beestat.component.modal.enjoy_beestat.prototype.is_active_patron_ = function() {
if (user.patreon_status !== null) { var user = beestat.get_user();
return (user.patreon_status.patron_status === 'active_patron'); if (user.patreon_status !== null) {
} return (user.patreon_status.patron_status === 'active_patron');
return null; }
}; return null;
};
/**
* Get the buttons on the modal. /**
* * Get the buttons on the modal.
* @return {[beestat.component.button]} The buttons. *
*/ * @return {[beestat.component.button]} The buttons.
beestat.component.modal.patreon_hide.prototype.get_buttons_ = function() { */
var self = this; beestat.component.modal.enjoy_beestat.prototype.get_buttons_ = function() {
var self = this;
var hide = new beestat.component.button()
.set_background_color('#fff') var hide = new beestat.component.button()
.set_text_color(beestat.style.color.gray.base) .set_background_color('#fff')
.set_text_hover_color(beestat.style.color.bluegray.base) .set_text_color(beestat.style.color.gray.base)
.set_text('Hide for one month') .set_text_hover_color(beestat.style.color.bluegray.base)
.addEventListener('click', function() { .set_text('Hide for one month')
self.hide_patreon_card_for_(1, 'month'); .addEventListener('click', function() {
self.dispose(); self.hide_patreon_card_for_(1, 'month');
}); self.dispose();
});
if (self.is_active_patron_() === null) {
var link = new beestat.component.button() if (self.is_active_patron_() === null) {
.set_text('Link Patreon to hide forever') var link = new beestat.component.button()
.set_background_color(beestat.style.color.green.base) .set_text('Link Patreon')
.set_background_hover_color(beestat.style.color.green.light) .set_background_color(beestat.style.color.green.base)
.set_text_color('#fff') .set_background_hover_color(beestat.style.color.green.light)
.addEventListener('click', function() { .set_text_color('#fff')
this .addEventListener('click', function() {
.set_background_color(beestat.style.color.gray.base) this
.set_background_hover_color() .set_background_color(beestat.style.color.gray.base)
.set_text('Waiting for Patreon...') .set_background_hover_color()
.removeEventListener('click'); .set_text('Waiting for Patreon...')
.removeEventListener('click');
beestat.add_poll_interval(beestat.component.modal.patreon_hide.poll_interval_);
self.is_polling_ = true; beestat.add_poll_interval(beestat.component.modal.enjoy_beestat.poll_interval_);
self.is_polling_ = true;
beestat.dispatcher.addEventListener('poll.patreon_hide', function() {
switch (self.is_active_patron_()) { beestat.dispatcher.addEventListener('poll.enjoy_beestat', function() {
case true: switch (self.is_active_patron_()) {
// Connected and is Patron case true:
beestat.cards.patreon.dispose(); // Connected and is Patron
self.dispose(); beestat.cards.patreon.dispose();
break; self.dispose();
case false: break;
// Connected but isn't Patron case false:
self.hide_patreon_card_for_(3, 'day'); // Connected but isn't Patron
self.dispose(); self.hide_patreon_card_for_(3, 'day');
break; self.dispose();
} break;
}); }
});
window.open('../api/?resource=patreon&method=authorize&arguments={}&api_key=ER9Dz8t05qUdui0cvfWi5GiVVyHP6OB8KPuSisP2');
}); window.open('../api/?resource=patreon&method=authorize&arguments={}&api_key=ER9Dz8t05qUdui0cvfWi5GiVVyHP6OB8KPuSisP2');
});
return [
hide, return [
link hide,
]; link
} ];
}
var ok = new beestat.component.button()
.set_background_color(beestat.style.color.green.base) var ok = new beestat.component.button()
.set_background_hover_color(beestat.style.color.green.light) .set_background_color(beestat.style.color.green.base)
.set_text_color('#fff') .set_background_hover_color(beestat.style.color.green.light)
.set_text('OK') .set_text_color('#fff')
.addEventListener('click', function() { .set_text('OK')
self.dispose(); .addEventListener('click', function() {
}); self.dispose();
});
return [
hide, return [
ok hide,
]; ok
}; ];
};

View File

@ -86,7 +86,7 @@ if($setting->get('environment') === 'dev' || $setting->get('environment') === 'd
echo '<script src="/js/component/modal/help_system.js"></script>' . PHP_EOL; echo '<script src="/js/component/modal/help_system.js"></script>' . PHP_EOL;
echo '<script src="/js/component/modal/help_comparison_settings.js"></script>' . PHP_EOL; echo '<script src="/js/component/modal/help_comparison_settings.js"></script>' . PHP_EOL;
echo '<script src="/js/component/modal/help_temperature_profiles.js"></script>' . PHP_EOL; echo '<script src="/js/component/modal/help_temperature_profiles.js"></script>' . PHP_EOL;
echo '<script src="/js/component/modal/patreon_hide.js"></script>' . PHP_EOL; echo '<script src="/js/component/modal/enjoy_beestat.js"></script>' . PHP_EOL;
echo '<script src="/js/component/modal/runtime_detail_custom.js"></script>' . PHP_EOL; echo '<script src="/js/component/modal/runtime_detail_custom.js"></script>' . PHP_EOL;
echo '<script src="/js/component/modal/thermostat_info.js"></script>' . PHP_EOL; echo '<script src="/js/component/modal/thermostat_info.js"></script>' . PHP_EOL;
echo '<script src="/js/component/modal/help_score.js"></script>' . PHP_EOL; echo '<script src="/js/component/modal/help_score.js"></script>' . PHP_EOL;