Permalink
Browse files

Client stuff stable

  • Loading branch information...
1 parent fe540b3 commit 77351c7e179d30f47fe63ae3498dc43576b5c43b @dncrews dncrews committed Oct 19, 2013
View
@@ -0,0 +1,11 @@
+
+build: components index.js
+ @component build --dev
+
+components: component.json
+ @component install --dev
+
+clean:
+ rm -fr build components template.js
+
+.PHONY: clean
View
5 app.js
@@ -7,10 +7,11 @@ var app = express();
app.use(express.bodyParser());
app.use(express.static(__dirname + '/assets'));
+app.use(express.static(__dirname + '/build'));
-app.get('/sample', function(req, res, next) {
+app.get('/sample/:type', function(req, res, next) {
console.log(req.headers);
- res.send('I DID IT I\'M SO AWESOME');
+ res.send('I DID IT I\'M SO AWESOME! (' + req.params.type + ')');
});
app.listen(process.env.PORT || 5000, function() {
View
@@ -4,18 +4,22 @@
<link rel="stylesheet" href="vendor/bootstrap-3.0.0/css/bootstrap-theme.min.css">
</head>
<body>
- <div class="container" data-ng-controller="SuperagentController">
- <span data-ng-superagent='{
- "x-request-id" : "654654654",
- "locale" : "es",
- "fsSessionId" : "987456321"
- }'></span>
- <button class="btn btn-success" data-ng-click="doIt()">Click ME</button>
+ <div class="container" data-ng-controller="ngSuperagentController" data-superagent-init>
+ <button class="btn btn-success" data-ng-click="fireWithoutInit()">Go ngManual</button>
+ <button class="btn btn-success" data-ng-click="fireWithInit()">Go ngDirective</button>
<h1 data-ng-bind="text"></h1>
</div>
+ <div class="container" data-ng-controller="fsSuperagentController">
+ <button class="btn btn-success" data-ng-click="fireWithFS()">Go FS</button>
+ </div>
+
+ <script src="vendor/angular-1.0.8.min.js"></script>
+ <script src="build.js"></script>
+ <script src="js/my_app.js"></script>
+ <!--
<script src="vendor/superagent.js"></script>
<script src="vendor/superagent-defaults.js"></script>
- <script src="vendor/angular-1.0.8.min.js"></script>
<script src="js/app.js"></script>
+ -->
</body>
</html>
View
@@ -0,0 +1,71 @@
+
+console.error('here', window.angular);
+(function(ng, fsSuperagent) {
+ "use strict";
+
+ var module = ng.module('ngSuperagent', []);
+
+ fsSuperagent.angular(module);
+
+ module.controller('fsSuperagentController', [
+ "$scope",
+
+ function($scope) {
+ $scope.fireWithFS = function() {
+ var FS = {
+ superagent : fsSuperagent.obj()
+ };
+ FS.superagent
+ .get('/sample/fs')
+ .end(function(err, response) {
+ if (err) return console.error('err', err);
+ alert(response.text);
+ });
+ };
+ }
+ ]);
+
+ module.controller('ngSuperagentController', [
+ "$scope",
+ "$superagent",
+ "myService",
+
+ function($scope, $superagent, service) {
+ $scope.text = 'ready';
+ $scope.fireWithInit = function() {
+ service.makeCall(function(response) {
+ $scope.text = response.text;
+ });
+ };
+ $scope.fireWithoutInit = function() {
+ $superagent
+ .get('/sample/setScope')
+ .$setScope($scope)
+ .end(function(err, response) {
+ if (err) return console.error('err', err);
+ $scope.text = response.text;
+ });
+ };
+ }
+ ]);
+
+ module.factory('myService', [
+ '$superagent',
+
+ function($superagent) {
+ function makeCall(next) {
+ $superagent
+ .get('/sample/directive')
+ .end(function(err, response) {
+ if (err) return console.error('err', err);
+ next(response);
+ });
+ }
+ return {
+ makeCall : makeCall
+ };
+ }
+ ]);
+
+
+})(window.angular, window.fsSuperagent);
View
@@ -0,0 +1,4 @@
+#/usr/bin/env bash
+
+# NODE_ENV=test `pwd`/node_modules/.bin/mocha --require blanket --reporter json-cov test/server/
+NODE_ENV=test `pwd`/node_modules/.bin/mocha --reporter spec test/server/
View
@@ -0,0 +1,23 @@
+{
+ "name": "fs-superagent",
+ "repo": "fs-webdev/fs-superagent",
+ "description": "FamilySearch Superagent",
+ "version": "0.0.1",
+ "keywords": [],
+ "dependencies": {
+ "visionmedia/debug": "*",
+ "component/url": "*",
+ "CamShaft/superagent-defaults": "*"
+ },
+ "development": {},
+ "license": "MIT",
+ "main": "lib/client/index.js",
+ "scripts": [
+ "lib/client/helpers/readCookies.js",
+ "lib/client/helpers/readHeaders.js",
+ "lib/fs-superagent.js",
+ "lib/client/ng-fs-superagent.js",
+ "lib/client/obj-fs-superagent.js",
+ "lib/client/index.js"
+ ]
+}
View
@@ -0,0 +1,5 @@
+if ('undefined' === typeof window) {
+ module.exports = require('./lib/fs-superagent');
+} else {
+ module.exports = require('./lib/client');
+}
@@ -0,0 +1,19 @@
+/*global console:false,module:false,require:false,document:false,window:false,XMLHttpRequest:false */
+'use strict';
+
+var cookies;
+
+module.exports = function readCookies() {
+ if (cookies) return cookies;
+ var c, C, i;
+
+ c = document.cookie.split('; ');
+ cookies = {};
+
+ for(i=c.length-1; i>=0; i--){
+ C = c[i].split('=');
+ cookies[C[0]] = C[1];
+ }
+
+ return cookies;
+};
@@ -0,0 +1,18 @@
+// I'm not sure this does what I wanted it to do.
+// These things are handled elsewhere (HAProxy, accept-language, etc)
+
+
+/*global console:false,module:false,require:false,document:false,window:false,XMLHttpRequest:false */
+'use strict';
+
+var headers;
+
+module.exports = function readHeaders() {
+ if (headers) return headers;
+ var req;
+ req = new XMLHttpRequest();
+ req.open('GET', document.location, false);
+ req.send(null);
+ headers = req.getAllResponseHeaders().toLowerCase();
+ return headers;
+};
View
@@ -0,0 +1,7 @@
+/*global console:false,module:false,require:false,document:false,window:false,XMLHttpRequest:false */
+'use strict';
+
+module.exports = {
+ 'angular' : require('./ng-fs-superagent'),
+ 'obj' : require('./obj-fs-superagent')
+};
@@ -0,0 +1,54 @@
+/*global console:false,module:false,require:false,document:false,window:false,XMLHttpRequest:false */
+'use strict';
+
+var fsSuperagent = require('../fs-superagent')
+ , readCookies = require('./helpers/readCookies');
+ // , readHeaders = require('./helpers/readHeaders');
+
+module.exports = function(app) {
+
+ /**
+ * Optional $superagent init directive
+ */
+ app.directive('superagentInit', [
+ '$superagent',
+
+ function($superagent) {
+ return {
+ restrict: 'EA',
+ link: function(scope) {
+ $superagent.on('request', function(request) {
+ request.handleEnd(function(cb, params) {
+ scope.$apply(function() {
+ cb.apply(null, params);
+ });
+ });
+ });
+ }
+ };
+ }
+ ]);
+
+ /**
+ * $superagent "Service"
+ */
+ app.factory('$superagent', [
+
+ function() {
+ return fsSuperagent({
+ // headers: readHeaders(),
+ cookies: readCookies()
+ })
+ .on('request', function(request) {
+ request.$setScope = function(scope) {
+ request.handleEnd(function(cb, params) {
+ scope.$apply(function() {
+ cb.apply(null, params);
+ });
+ });
+ return request;
+ };
+ });
+ }
+ ]);
+};
@@ -0,0 +1,13 @@
+/*global console:false,module:false,require:false,document:false,window:false,XMLHttpRequest:false */
+'use strict';
+
+var fsSuperagent = require('../fs-superagent')
+ , readCookies = require('./helpers/readCookies');
+ // , readHeaders = require('./helpers/readHeaders');
+
+module.exports = function() {
+ return fsSuperagent({
+ // headers: readHeaders(),
+ cookies: readCookies()
+ });
+};
Oops, something went wrong.

0 comments on commit 77351c7

Please sign in to comment.