From ed3929dfe7bcf4505c3a639f27be27fd155310c6 Mon Sep 17 00:00:00 2001
From: Ralph Bean <rbean@redhat.com>
Date: Mar 15 2016 14:30:18 +0000
Subject: [PATCH 1/4] Allow feed entries to expand/collapse if they are conglomerates.


---

diff --git a/hubs/widgets/feed.py b/hubs/widgets/feed.py
index 19b1c27..492fdbd 100644
--- a/hubs/widgets/feed.py
+++ b/hubs/widgets/feed.py
@@ -43,17 +43,75 @@ template = jinja2.Template("""
       <div class="media-body">
         <h4 class="media-heading">{{match['markup']}}</h4>
         {{match['human_time']}}
+        {% if match['msg_ids'] | length > 1 %}
+            <div class="pull-right">
+                <a id="expand-{{match['dom_id']}}" href="javascript:expand_feed_entries('{{match['dom_id']}}');">
+                    <span class="glyphicon glyphicon-chevron-down"></span>
+                    expand
+                </a>
+                <a id="collapse-{{match['dom_id']}}" href="javascript:collapse_feed_entries('{{match['dom_id']}}');" class="hidden">
+                    <span class="glyphicon glyphicon-chevron-up"></span>
+                    collapse
+                </a>
+            </div>
+            <ul id="content-{{match['dom_id']}}" class="hidden list-unstyled">
+                {% for idx, constituent in match['msg_ids'].items() %}
+                <li>
+                    {{ constituent['markup'] }}
+                    {% if constituent['link'] %}
+                    <a href="{{constituent['link']}}" target="_blank">
+                        <span class="glyphicon glyphicon-new-window"></span>
+                    </a>
+                    {% endif %}
+                </li>
+                {% endfor %}
+            </ul>
+        {% endif %}
       </div>
     </div>
   </div>
 </div>
 {% endfor %}
+<script>
+var expand_feed_entries = function(idx) {
+    $("#expand-" + idx).addClass('hidden');
+    $("#collapse-" + idx).removeClass('hidden');
+    $("#content-" + idx).removeClass('hidden');
+}
+var collapse_feed_entries = function(idx) {
+    $("#expand-" + idx).removeClass('hidden');
+    $("#collapse-" + idx).addClass('hidden');
+    $("#content-" + idx).addClass('hidden');
+}
+</script>
 """)
 
 # No chrome around the feed.
 #from hubs.widgets.chrome import panel
 #chrome = panel()
 
+def apply_markup(match):
+    markup = match['subtitle']
+    for username in match['usernames']:
+        args = (username, '<a href="{url}">@{username}</a>'.format(
+            url=flask.url_for('hub', name=username),
+            username=username,
+        ))
+        markup = markup.replace(*args)
+        # TODO -- have to add these to conglomerate first
+        #match['long_form'] = match['long_form'].replace(*args)
+
+    for package in match['packages']:
+        args = (package, '<a href="{url}">{package}</a>'.format(
+            url='https://apps.fedoraproject.org/packages/' + package,
+            package=package,
+        ))
+        markup = markup.replace(*args)
+        # TODO -- have to add these to conglomerate first
+        #match['long_form'] = match['long_form'].replace(*args)
+
+    return markup
+
 
 @argument(name="username",
           default=None,
@@ -113,25 +171,9 @@ def data(session, widget, username, fmn_context):
 
     # Apply some html markup to the subtitles for extra fanciness.
     for match in matches:
-        match['markup'] = match['subtitle']
-        for username in match['usernames']:
-            args = (username, '<a href="{url}">@{username}</a>'.format(
-                url=flask.url_for('hub', name=username),
-                username=username,
-            ))
-            match['markup'] = match['markup'].replace(*args)
-            # TODO -- have to add these to conglomerate first
-            #match['long_form'] = match['long_form'].replace(*args)
-
-        for package in match['packages']:
-            args = (package, '<a href="{url}">{package}</a>'.format(
-                url='https://apps.fedoraproject.org/packages/' + package,
-                package=package,
-            ))
-            match['markup'] = match['markup'].replace(*args)
-            # TODO -- have to add these to conglomerate first
-            #match['long_form'] = match['long_form'].replace(*args)
-
+        match['markup'] = apply_markup(match)
+        for idx, constituent in match['msg_ids'].items():
+            constituent['markup'] = apply_markup(constituent)
 
     return dict(
         matches=matches,

From ec5a01985fdb72604b86845f7a54459132c885ee Mon Sep 17 00:00:00 2001
From: Ralph Bean <rbean@redhat.com>
Date: Mar 15 2016 14:43:11 +0000
Subject: [PATCH 2/4] Drop print statement.


---

diff --git a/hubs/widgets/feed.py b/hubs/widgets/feed.py
index 492fdbd..f777965 100644
--- a/hubs/widgets/feed.py
+++ b/hubs/widgets/feed.py
@@ -125,7 +125,6 @@ def data(session, widget, username, fmn_context):
     openid = '%s.id.fedoraproject.org' % username
     url = '/'.join([fmn_url, 'api', openid, fmn_context])
     log.info("Getting FMN preferences from %s" % url)
-    print(url)
     response = requests.get(url)
     messages = []
     matches = []

From 8c44c6287edd0cbafc62d42f856c8f47bb4badaa Mon Sep 17 00:00:00 2001
From: Ralph Bean <rbean@redhat.com>
Date: Mar 15 2016 16:51:50 +0000
Subject: [PATCH 3/4] Move js functions out into their own file.


---

diff --git a/hubs/templates/hubs.html b/hubs/templates/hubs.html
index 1e87956..5d09b04 100644
--- a/hubs/templates/hubs.html
+++ b/hubs/templates/hubs.html
@@ -143,6 +143,7 @@
 
 <script src="{{ url_for('static', filename='js/jquery-1.10.2.min.js') }}"></script>
 <script src="{{ url_for('static', filename='bootstrap/js/bootstrap.min.js') }}"></script>
+<script src="{{ url_for('static', filename='js/utils.js') }}"></script>
 <script>
 var widgets = [{% for widget in hub.widgets %}'{{ widget.idx }}',{% endfor %}];
 $.each(widgets, function(i, widget) {
diff --git a/hubs/widgets/feed.py b/hubs/widgets/feed.py
index f777965..e7cd4da 100644
--- a/hubs/widgets/feed.py
+++ b/hubs/widgets/feed.py
@@ -72,18 +72,6 @@ template = jinja2.Template("""
   </div>
 </div>
 {% endfor %}
-<script>
-var expand_feed_entries = function(idx) {
-    $("#expand-" + idx).addClass('hidden');
-    $("#collapse-" + idx).removeClass('hidden');
-    $("#content-" + idx).removeClass('hidden');
-}
-var collapse_feed_entries = function(idx) {
-    $("#expand-" + idx).removeClass('hidden');
-    $("#collapse-" + idx).addClass('hidden');
-    $("#content-" + idx).addClass('hidden');
-}
-</script>
 """)
 
 # No chrome around the feed.

From 810381335c903fefd8bd0d6a4d59bcc4122028fc Mon Sep 17 00:00:00 2001
From: Ralph Bean <rbean@redhat.com>
Date: Mar 15 2016 17:04:31 +0000
Subject: [PATCH 4/4] Add forgotten file, because threebean doesn't know how to git.


---

diff --git a/hubs/static/js/utils.js b/hubs/static/js/utils.js
new file mode 100644
index 0000000..1e97046
--- /dev/null
+++ b/hubs/static/js/utils.js
@@ -0,0 +1,12 @@
+// These two functions are used by the feed widget to expand and collapse
+// entries.
+var expand_feed_entries = function(idx) {
+    $("#expand-" + idx).addClass('hidden');
+    $("#collapse-" + idx).removeClass('hidden');
+    $("#content-" + idx).removeClass('hidden');
+}
+var collapse_feed_entries = function(idx) {
+    $("#expand-" + idx).removeClass('hidden');
+    $("#collapse-" + idx).addClass('hidden');
+    $("#content-" + idx).addClass('hidden');
+}

