Skip to content

Commit

Permalink
Update to v1.0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
kid1194 committed Sep 25, 2022
1 parent 1de1982 commit 6da1702
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 32 deletions.
29 changes: 17 additions & 12 deletions active_users/api/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

import frappe
from frappe.utils import cint, has_common, now, add_to_date
from frappe.model.document import Document


_SETTINGS_CACHE_KEY = "active_users_settings"
Expand Down Expand Up @@ -76,21 +75,27 @@ def get_users(user_types):
user_types = ["System User"]

tp = [0, -20, 0]
sess_expiry = frappe.db.get_value("System Settings", None, "session_expiry")
sys_settings = frappe.get_single("System Settings")

sess_expiry = sys_settings.session_expiry
if not sess_expiry or not isinstance(sess_expiry, str):
sess_expiry = frappe.db.get_value("System Settings", None, "session_expiry_mobile")
sess_expiry = sys_settings.session_expiry_mobile
if not sess_expiry or not isinstance(sess_expiry, str):
sess_expiry = ""

try:
if sess_expiry and isinstance(sess_expiry, str):
sess_expiry = sess_expiry.split(":")
if sess_expiry and not isinstance(sess_expiry, list):
sess_expiry = [sess_expiry]
if sess_expiry and isinstance(sess_expiry, list):
for i in range(len(sess_expiry)):
tpv = cint(sess_expiry[i])
if tpv:
tp[i] = -abs(tpv)
if sess_expiry:
sess_list = sess_expiry.split(":")
if sess_list and not isinstance(sess_list, list):
sess_list = [sess_list]
if sess_list and isinstance(sess_list, list):
for i, v in enumerate(sess_list):
if v and isinstance(v, str):
tpv = cint(v)
if tpv:
tp[i] = -abs(tpv)
else:
return {"error": True, "message": "The system session expiry value is invalid."}
except Exception:
return {"error": True, "message": "Unable to parse the system session expiry value."}

Expand Down
41 changes: 21 additions & 20 deletions active_users/public/js/active_users.bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ frappe.ActiveUsers = class ActiveUsers {
return;
}
this.is_online = frappe.is_online ? frappe.is_online() : false;
this._on_online = null;
this._on_offline = null;

var me = this;
$(window).on('online', function() {
Expand All @@ -34,7 +32,19 @@ frappe.ActiveUsers = class ActiveUsers {
this.settings = {};
this.data = [];

this.setup_app();
this.setup();
}
destroy() {
this.clear_sync();
if (this.$loading) this.$loading.hide();
if (this.$reload) this.$reload.off('click').hide();
if (this.$app) this.$app.remove();
this.data = this._on_online = this._on_offline = this._syncing = null;
this.$app = this.$body = this.$loading = this.$footer = this.$reload = null;
}
error(msg) {
this.destroy();
frappe.throw(__(msg));
}
request(method, args, callback, type) {
var me = this;
Expand All @@ -52,30 +62,25 @@ frappe.ActiveUsers = class ActiveUsers {
p.then(function(res) {
if (res && $.isPlainObject(res)) res = res.message || res;
if (!$.isPlainObject(res)) {
me.$loading.hide();
me.clear_sync();
frappe.throw(__('Active Users plugin received invalid ' + type + '.'));
me.error('Active Users plugin received invalid ' + type + '.');
return;
}
if (res.error) {
me.$loading.hide();
me.clear_sync();
frappe.throw(__(res.message));
me.error(res.message);
return;
}
callback.call(me, res);
});
} catch(e) {
this.$loading.hide();
this.clear_sync();
(console.error || console.log)('[Active Users]: ' + __('An error has occurred while sending a request.'), e);
this.error('An error has occurred while sending a request.');
(console.error || console.log)('[Active Users]', e);
}

return p;
}
setup_app() {
setup() {
if (!this.is_online) {
this._on_online = this.setup_app;
this._on_online = this.setup;
return;
}

Expand Down Expand Up @@ -159,6 +164,8 @@ frappe.ActiveUsers = class ActiveUsers {

this.setup_manual_sync();

if (frappe.ActiveUsers._ready) return;
frappe.ActiveUsers._ready = true;
frappe.dom.eval(`
(function(){window.$clamp=function(c,d){function s(a,b){n.getComputedStyle||(n.getComputedStyle=function(a,b){this.el=a;this.getPropertyValue=function(b){var c=/(\-([a-z]){1})/g;"float"==b&&(b="styleFloat");c.test(b)&&(b=b.replace(c,function(a,b,c){return c.toUpperCase()}));return a.currentStyle&&a.currentStyle[b]?a.currentStyle[b]:null};return this});return n.getComputedStyle(a,null).getPropertyValue(b)}function t(a){a=a||c.clientHeight;var b=u(c);return Math.max(Math.floor(a/b),0)}function x(a){return u(c)*
a}function u(a){var b=s(a,"line-height");"normal"==b&&(b=1.2*parseInt(s(a,"font-size")));return parseInt(b)}function l(a){if(a.lastChild.children&&0<a.lastChild.children.length)return l(Array.prototype.slice.call(a.children).pop());if(a.lastChild&&a.lastChild.nodeValue&&""!=a.lastChild.nodeValue&&a.lastChild.nodeValue!=b.truncationChar)return a.lastChild;a.lastChild.parentNode.removeChild(a.lastChild);return l(c)}function p(a,d){if(d){var e=a.nodeValue.replace(b.truncationChar,"");f||(h=0<k.length?
Expand Down Expand Up @@ -235,12 +242,6 @@ h=k[0],f,q;"auto"==g?g=t():v&&(g=t(parseInt(g)));var w;z&&b.useNativeClamp?(e.ov
});
this.$footer.html(__('Total') + ': ' + this.data.length);
}
destory() {
this.clear_sync();
if (this.settings.allow_manual_refresh) this.$reload.off('click');
this.$app.remove();
this.data = this.$app = this.$body = this.$loading = this.$footer = this.$reload = null;
}
};

frappe._active_users.start = function() {
Expand Down

0 comments on commit 6da1702

Please sign in to comment.