From 5fa601828904bfad7af3499b5c251989f589ae47 Mon Sep 17 00:00:00 2001 From: Aurélien Bompard Date: Feb 06 2017 23:29:15 +0000 Subject: [PATCH 1/3] Improve the widget-loading system Avoid passing Python variables to Javascript, this is error-prone. --- diff --git a/hubs/static/js/utils.js b/hubs/static/js/utils.js index 01f2382..3474786 100644 --- a/hubs/static/js/utils.js +++ b/hubs/static/js/utils.js @@ -12,23 +12,23 @@ var collapse_feed_entries = function(idx) { } // Load widgets - function setup_widgets(base_url, widgets) { - console.log(base_url, widgets); - $.each(widgets, function(i, widget) { - $.ajax({ - url: base_url + widget, - dataType: 'html', - success: function(html) { - $('#widget-' + widget).html(html); - setTimeout(function() { - $('#widget-' + widget + ' .panel').toggleClass('panel-visible'); - }, 100); - }, - error: function() { - $('#widget-' + widget).html('Got an error retrieving this widget. Sorry :('); - console.log('error'); - console.trace(); - }, - }); - }); - } +function setup_widgets() { + $("div.widget[data-url]").each(function() { + var element=$(this); + $.ajax({ + url: element.attr("data-url"), + dataType: 'html', + success: function(html) { + element.html(html); + setTimeout(function() { + element.find('.panel').toggleClass('panel-visible'); + }, 100); + }, + error: function() { + element.html('Got an error retrieving this widget. Sorry :('); + console.log('error'); + console.trace(); + }, + }); + }); +} diff --git a/hubs/templates/hubs.html b/hubs/templates/hubs.html index fed9ae6..390949d 100644 --- a/hubs/templates/hubs.html +++ b/hubs/templates/hubs.html @@ -155,11 +155,7 @@ {% endif %} -
- {% for widget in hub.left_widgets %} -
- {% endfor %} -
+ {% include "includes/left_widgets.html" %}
@@ -177,11 +173,7 @@
{% endif %} -
- {% for widget in hub.right_widgets %} -
- {% endfor %} -
+ {% include "includes/right_widgets.html" %} @@ -339,10 +331,7 @@ function visit_counter() { $(function() { visit_counter() - setup_widgets( - {{ url_for("hub", name=hub.name) }}, - {{ hub.widgets_idx|tojson }} - ); + setup_widgets(); setup_edit_btns(); {% if edit -%} diff --git a/hubs/templates/includes/_rightpanel.html b/hubs/templates/includes/_rightpanel.html deleted file mode 100644 index 2a9f511..0000000 --- a/hubs/templates/includes/_rightpanel.html +++ /dev/null @@ -1,5 +0,0 @@ -
- {% for widget in hub.right_widgets %} -
- {% endfor %} -
diff --git a/hubs/templates/includes/left_widgets.html b/hubs/templates/includes/left_widgets.html new file mode 100644 index 0000000..b0326e9 --- /dev/null +++ b/hubs/templates/includes/left_widgets.html @@ -0,0 +1,7 @@ +
+{% for widget in hub.left_widgets %} +
+{% endfor %} +
diff --git a/hubs/templates/includes/right_widgets.html b/hubs/templates/includes/right_widgets.html new file mode 100644 index 0000000..d9b487a --- /dev/null +++ b/hubs/templates/includes/right_widgets.html @@ -0,0 +1,7 @@ +
+ {% for widget in hub.right_widgets %} +
+ {% endfor %} +
diff --git a/hubs/templates/stream.html b/hubs/templates/stream.html index 278b076..128ff25 100644 --- a/hubs/templates/stream.html +++ b/hubs/templates/stream.html @@ -31,7 +31,7 @@
- {% include "includes/_rightpanel.html" %} + {% include "includes/right_widgets.html" %}
@@ -45,7 +45,7 @@
- {% include "includes/_rightpanel.html" %} + {% include "includes/right_widgets.html" %}
@@ -60,7 +60,7 @@ {% include "includes/_messages.html" %}
- {% include "includes/_rightpanel.html" %} + {% include "includes/right_widgets.html" %}
@@ -75,7 +75,7 @@
- {% include "includes/_rightpanel.html" %} + {% include "includes/right_widgets.html" %}
@@ -145,10 +145,7 @@ }); } $(function() { - setup_widgets( - {{ url_for("hub", name=hub.name) }}, - {{ hub.widgets_idx|tojson }} - ); + setup_widgets(); setup_feeds(); }); From 37a6eec05064b1e7575b5044af7438f2fedc6d5d Mon Sep 17 00:00:00 2001 From: Aurélien Bompard Date: Feb 06 2017 23:29:15 +0000 Subject: [PATCH 2/3] Fix the stream page to not load the widgets 4 times --- diff --git a/hubs/templates/stream.html b/hubs/templates/stream.html index 128ff25..8586d2a 100644 --- a/hubs/templates/stream.html +++ b/hubs/templates/stream.html @@ -6,81 +6,54 @@

My Stream

Notifications, actions, and other things of interest to me

- - -
-
-
-
-
- {% include "includes/_searchstream.html" %} -
-
-
- {% include "includes/right_widgets.html" %} -
-
-
-
+
+
-
-
-
+ + + +
+
{% include "includes/_searchstream.html" %} -
-
-
-
- {% include "includes/right_widgets.html" %} -
+
-
-
-
-
-
+
+ {% include "includes/_searchstream.html" %} +
+
+
{% include "includes/_searchstream.html" %}
-
-
- {% include "includes/_messages.html" %} -
-
- {% include "includes/right_widgets.html" %} -
+
+ {% include "includes/_messages.html" %}
-
-
-
-
-
-
+
{% include "includes/_searchstream.html" %} -
-
-
-
- {% include "includes/right_widgets.html" %} -
+
+ +
+ {% include "includes/right_widgets.html" %} +
+