You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@streams.apache.org by ds...@apache.org on 2013/10/23 20:28:39 UTC

svn commit: r1535100 [1/3] - in /incubator/streams/trunk/streams-web/src/main/webapp: ./ demo/ demo/css/ demo/js/

Author: dsullivan
Date: Wed Oct 23 18:28:38 2013
New Revision: 1535100

URL: http://svn.apache.org/r1535100
Log:
committing a patch from Carol Hansen

Added:
    incubator/streams/trunk/streams-web/src/main/webapp/demo/activityDemo.html
    incubator/streams/trunk/streams-web/src/main/webapp/demo/css/
    incubator/streams/trunk/streams-web/src/main/webapp/demo/css/activityStyles.css
    incubator/streams/trunk/streams-web/src/main/webapp/demo/js/activityDemo.js
    incubator/streams/trunk/streams-web/src/main/webapp/demo/js/handlebars.js
Modified:
    incubator/streams/trunk/streams-web/src/main/webapp/demo/js/publisher.js
    incubator/streams/trunk/streams-web/src/main/webapp/demo/js/subscriber.js
    incubator/streams/trunk/streams-web/src/main/webapp/demo/publisher.html
    incubator/streams/trunk/streams-web/src/main/webapp/demo/subscriber.html
    incubator/streams/trunk/streams-web/src/main/webapp/index.html

Added: incubator/streams/trunk/streams-web/src/main/webapp/demo/activityDemo.html
URL: http://svn.apache.org/viewvc/incubator/streams/trunk/streams-web/src/main/webapp/demo/activityDemo.html?rev=1535100&view=auto
==============================================================================
--- incubator/streams/trunk/streams-web/src/main/webapp/demo/activityDemo.html (added)
+++ incubator/streams/trunk/streams-web/src/main/webapp/demo/activityDemo.html Wed Oct 23 18:28:38 2013
@@ -0,0 +1,26 @@
+<!DOCTYPE HTML>
+<html xmlns="http://www.w3.org/1999/html">
+<head>
+    <script type="text/javascript" src="http://code.jquery.com/jquery-1.10.2.min.js"></script>
+    <script type="text/javascript" src="js/handlebars.js"></script>
+    <script type="text/javascript" src="js/activityDemo.js"></script>
+    <link rel="stylesheet" type="text/css" href="css/activityStyles.css" />
+    <title>Activity Streams Demo</title>
+</head>
+<body>
+    <label>View Streams for the following tag:</label><br>
+    <textarea id="tag" rows="2"></textarea><br>
+    <button type="button" onclick="activityDemo.getActivitiesForGivenTag()">Get Activities</button><br><br>
+
+    <div id="activityStream"></div>
+    <script type="text/x-handlebars-template" id='activity-template'>
+        <!--Iterates through each activity in the array that was returned from Streams-->
+        {{#each this}}
+        <div class='activity'>
+            <div class='actor'>{{actor.id}}   {{verb}}   {{published}}</div>
+        </div>
+        {{/each}}
+    </script>
+
+</body>
+</html>

Added: incubator/streams/trunk/streams-web/src/main/webapp/demo/css/activityStyles.css
URL: http://svn.apache.org/viewvc/incubator/streams/trunk/streams-web/src/main/webapp/demo/css/activityStyles.css?rev=1535100&view=auto
==============================================================================
--- incubator/streams/trunk/streams-web/src/main/webapp/demo/css/activityStyles.css (added)
+++ incubator/streams/trunk/streams-web/src/main/webapp/demo/css/activityStyles.css Wed Oct 23 18:28:38 2013
@@ -0,0 +1,9 @@
+.activity {
+    -moz-box-shadow:    3px 3px 5px 6px #ccc;
+    -webkit-box-shadow: 3px 3px 5px 6px #ccc;
+    box-shadow:         3px 3px 5px 6px #ccc;
+    padding: .3em .7em .3em .7em;
+    width: 300px;
+    margin-top: 25px;
+    margin-bottom: 25px; }
+.actor { text-align: left; }

Added: incubator/streams/trunk/streams-web/src/main/webapp/demo/js/activityDemo.js
URL: http://svn.apache.org/viewvc/incubator/streams/trunk/streams-web/src/main/webapp/demo/js/activityDemo.js?rev=1535100&view=auto
==============================================================================
--- incubator/streams/trunk/streams-web/src/main/webapp/demo/js/activityDemo.js (added)
+++ incubator/streams/trunk/streams-web/src/main/webapp/demo/js/activityDemo.js Wed Oct 23 18:28:38 2013
@@ -0,0 +1,66 @@
+var activityDemo = activityDemo || (function(){
+    var subscriberURL = "";
+    var registerUrl = "/streams-web/apps/subscriber/register";
+    var activityStream = "";
+
+    var getActivitiesForGivenTag = function(){
+
+        registerSubscriber();
+    };
+
+    // Registers a new subscriber and sets the subscriber's filter(s)
+    // based on tag entered by the user on the demo webpage
+    var registerSubscriber = function(){
+        var tag = $("#tag").val();
+        console.log("tag = " + tag);
+        var registrationObject =
+        {
+            "authToken": "token",
+            "@class":"org.apache.streams.osgi.components.activitysubscriber.impl.ActivityStreamsSubscriptionImpl",
+            "filters": [
+                tag
+            ]
+        };
+
+        $.ajax({
+            url:registerUrl,
+            contentType: 'application/json',
+            type:"POST",
+            data:JSON.stringify(registrationObject),
+            success:function(data){
+                console.log(data);
+                subscriberURL = data;
+                getActivitiesStream();
+            }
+        })
+    };
+
+    // Gets activities streams array
+    var getActivitiesStream = function(){
+        if(!subscriberURL){
+            alert("Please enter a subscriber url first");
+        }
+
+        $.ajax({
+            contentType: "application/json",
+            type:"GET",
+            url: subscriberURL,
+            success:function(data){
+                setTemplate(data);
+            }
+        })
+    };
+
+    // Applies the array returned from Streams to the html template to be displayed
+    var setTemplate = function(activityStreamData){
+        var source   = $("#activity-template").html();
+        var template = Handlebars.compile(source);
+        var html = template(activityStreamData);
+        $("#activityStream").html(html);
+    };
+
+    return {
+            getActivitiesForGivenTag: getActivitiesForGivenTag
+        }
+
+})();