From a52f6182e59394e765ced94d37187e694b0b1121 Mon Sep 17 00:00:00 2001 From: Bryan Hankins Date: Mon, 9 Jan 2017 21:33:54 -0600 Subject: [PATCH 1/6] boiler plate --- app.js | 3 +++ index.html | 15 +++++++++++++++ 2 files changed, 18 insertions(+) create mode 100644 app.js create mode 100644 index.html diff --git a/app.js b/app.js new file mode 100644 index 0000000..d663bbb --- /dev/null +++ b/app.js @@ -0,0 +1,3 @@ +;(function(){ + var app = angular.module('myApp', []) +})(); \ No newline at end of file diff --git a/index.html b/index.html new file mode 100644 index 0000000..3693f05 --- /dev/null +++ b/index.html @@ -0,0 +1,15 @@ + + + + + OMG + + + + + + +1+1 = {{1+1}} + + + \ No newline at end of file From 95809daae4d74a495d9eb7fca2314492bf8094e1 Mon Sep 17 00:00:00 2001 From: Bryan Hankins Date: Mon, 9 Jan 2017 22:19:39 -0600 Subject: [PATCH 2/6] angular working --- index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.html b/index.html index 3693f05..1132495 100644 --- a/index.html +++ b/index.html @@ -8,7 +8,7 @@ - + 1+1 = {{1+1}} From a32889604ba5a1673201e07107079666252df5b4 Mon Sep 17 00:00:00 2001 From: Bryan Hankins Date: Tue, 10 Jan 2017 21:38:19 -0600 Subject: [PATCH 3/6] add factory controller and service --- app.js | 29 ++++++++++++++++++++++++++++- index.html | 27 ++++++++++++++++++++++----- 2 files changed, 50 insertions(+), 6 deletions(-) diff --git a/app.js b/app.js index d663bbb..fc8232b 100644 --- a/app.js +++ b/app.js @@ -1,3 +1,30 @@ ;(function(){ - var app = angular.module('myApp', []) + const app = angular.module('fetchApp', []); + + debugger + + app.controller('MainController', function($scope, requestService, Response){ + $scope.responses = []; + $scope.url='http://httpstat.us/200'; + $scope.fetch = () => { + requestService.get($scope.url).then((success) => { + const response = new Response(success); + debugger + $scope.responses.push({statusCode: success.status}); + },(error) => { + debugger + }); + }; + }); + + app.service('requestService', function($http){ + this.get = (url) => $http.get(url); + }); + + app.factory('Response', function(){ + const Response = function(ResponseData){ + this.statusCode = ResponseData.status; + }; + return Response; + }); })(); \ No newline at end of file diff --git a/index.html b/index.html index 1132495..8306bd4 100644 --- a/index.html +++ b/index.html @@ -1,15 +1,32 @@ - + - OMG + OMG app - -1+1 = {{1+1}} - + +{{message}} +
+
+ + + +
    +
  • + {{response.statusCode}} +
  • +
+
+
+ + \ No newline at end of file From b25e950cb33a03aedc867c00f835e48a5462374f Mon Sep 17 00:00:00 2001 From: Bryan Hankins Date: Tue, 10 Jan 2017 22:30:00 -0600 Subject: [PATCH 4/6] break apart services controller and factories --- MainController.js | 16 ++++++++++++++++ app.js | 30 ++---------------------------- index.html | 4 ++++ requestService.js | 6 ++++++ responseFactory.js | 9 +++++++++ 5 files changed, 37 insertions(+), 28 deletions(-) create mode 100644 MainController.js create mode 100644 requestService.js create mode 100644 responseFactory.js diff --git a/MainController.js b/MainController.js new file mode 100644 index 0000000..090a0c5 --- /dev/null +++ b/MainController.js @@ -0,0 +1,16 @@ +;(function () { + angular.module('fetchApp').controller('MainController', function ($scope, requestService, Response) { + $scope.responses = []; + $scope.url = "http://httpstat.us/200"; + + $scope.fetch = () => { + requestService.get($scope.url).then((success) => { + const response = new Response(success); + $scope.responses.push(response); + }, (error) => { + debugger + //do something else + }); + }; + }); +})(); \ No newline at end of file diff --git a/app.js b/app.js index fc8232b..5c3e9b2 100644 --- a/app.js +++ b/app.js @@ -1,30 +1,4 @@ -;(function(){ - const app = angular.module('fetchApp', []); - debugger - - app.controller('MainController', function($scope, requestService, Response){ - $scope.responses = []; - $scope.url='http://httpstat.us/200'; - $scope.fetch = () => { - requestService.get($scope.url).then((success) => { - const response = new Response(success); - debugger - $scope.responses.push({statusCode: success.status}); - },(error) => { - debugger - }); - }; - }); - - app.service('requestService', function($http){ - this.get = (url) => $http.get(url); - }); - - app.factory('Response', function(){ - const Response = function(ResponseData){ - this.statusCode = ResponseData.status; - }; - return Response; - }); +;(function () { + const app = angular.module('fetchApp', []); })(); \ No newline at end of file diff --git a/index.html b/index.html index 8306bd4..ccead20 100644 --- a/index.html +++ b/index.html @@ -28,5 +28,9 @@ + + + + \ No newline at end of file diff --git a/requestService.js b/requestService.js new file mode 100644 index 0000000..b406bad --- /dev/null +++ b/requestService.js @@ -0,0 +1,6 @@ + +;(function () { + angular.module('fetchApp').service('requestService', function ($http) { + this.get = (url) => $http.get(url); + }); +})(); \ No newline at end of file diff --git a/responseFactory.js b/responseFactory.js new file mode 100644 index 0000000..4e9a0f5 --- /dev/null +++ b/responseFactory.js @@ -0,0 +1,9 @@ +;(function () { + angular.module('fetchApp').factory('Response', function () { + const Response = function (responseData) { + this.statusCode = responseData.status; + }; + + return Response; + }); +})(); \ No newline at end of file From d6de89b8c50ea99eae56e27e50bc6637e487c935 Mon Sep 17 00:00:00 2001 From: Bryan Hankins Date: Wed, 11 Jan 2017 20:00:37 -0600 Subject: [PATCH 5/6] add select menu functionality --- MainController.js | 35 ++++++++++++++++++++++++++++------- index.html | 22 +++++++++++++--------- requestService.js | 13 +++++++++---- responseFactory.js | 5 ++++- 4 files changed, 54 insertions(+), 21 deletions(-) diff --git a/MainController.js b/MainController.js index 090a0c5..13579f5 100644 --- a/MainController.js +++ b/MainController.js @@ -2,15 +2,36 @@ angular.module('fetchApp').controller('MainController', function ($scope, requestService, Response) { $scope.responses = []; $scope.url = "http://httpstat.us/200"; + + $scope.fetch = () => { - requestService.get($scope.url).then((success) => { - const response = new Response(success); - $scope.responses.push(response); - }, (error) => { - debugger - //do something else - }); + const initialDate = (new Date()).getTime(); + if($scope.method == "GET"){ + requestService.get($scope.url).then((success) => { + const receiveDate = (new Date()).getTime(); + const response = new Response(success); + const responseTime = receiveDate - initialDate; + response.responseTime = responseTime; + console.log(responseTime); + $scope.responses.push(response); + }, (error) => { + debugger + }); + } else if($scope.method == "POST"){ + requestService.post($scope.url).then((success) => { + const receiveDate = (new Date()).getTime(); + const response = new Response(success); + const responseTime = receiveDate - initialDate; + response.responseTime = responseTime; + $scope.responses.push(response); + }, (error) => { + debugger + }); + } }; + + + }); })(); \ No newline at end of file diff --git a/index.html b/index.html index ccead20..b6470ba 100644 --- a/index.html +++ b/index.html @@ -9,19 +9,23 @@ -{{message}} + {{message}}
- - + + + < -
    -
  • - {{response.statusCode}} +
      +
    • + {{response.statusCode}} + {{response.methodName}} + {{response.urlName}} + {{response.size}}
@@ -30,7 +34,7 @@ - - + + \ No newline at end of file diff --git a/requestService.js b/requestService.js index b406bad..ab7c6dd 100644 --- a/requestService.js +++ b/requestService.js @@ -1,6 +1,11 @@ ;(function () { - angular.module('fetchApp').service('requestService', function ($http) { - this.get = (url) => $http.get(url); - }); -})(); \ No newline at end of file + angular.module('fetchApp').service('requestService', function ($http) { + this.get = url => $http.get(url); + this.post = url => $http.post(url); +}); +})(); + + + // this.get = function (url) { + // return $http.get(url); \ No newline at end of file diff --git a/responseFactory.js b/responseFactory.js index 4e9a0f5..2bfbe18 100644 --- a/responseFactory.js +++ b/responseFactory.js @@ -2,8 +2,11 @@ angular.module('fetchApp').factory('Response', function () { const Response = function (responseData) { this.statusCode = responseData.status; + this.methodName = responseData.config.method; + this.urlName = responseData.config.url; + this.size = (responseData.data.length)/1000; + console.log(responseData); }; - return Response; }); })(); \ No newline at end of file From cad4913ace2bf1569f90004d91259d7cae9a7a10 Mon Sep 17 00:00:00 2001 From: Bryan Hankins Date: Fri, 13 Jan 2017 18:55:21 -0600 Subject: [PATCH 6/6] stuck --- MainController.js | 20 ++++++++++++++++++++ index.html | 1 + requestService.js | 2 ++ responseFactory.js | 1 + 4 files changed, 24 insertions(+) diff --git a/MainController.js b/MainController.js index 13579f5..e13a0d8 100644 --- a/MainController.js +++ b/MainController.js @@ -28,6 +28,26 @@ }, (error) => { debugger }); + } else if($scope.method == "HEAD"){ + requestService.head($scope.url).then((success) => { + const receiveDate = (new Date()).getTime(); + const response = new Response(success); + const responseTime = receiveDate - initialDate; + response.responseTime = responseTime; + $scope.responses.push(response); + }, (error) => { + debugger + }); + } else if($scope.method == "OPTIONS"){ + requestService.options($scope.url).then((success) => { + const receiveDate = (new Date()).getTime(); + const response = new Response(success); + const responseTime = receiveDate - initialDate; + response.responseTime = responseTime; + $scope.responses.push(response); + }, (error) => { + debugger + }); } }; diff --git a/index.html b/index.html index b6470ba..5852d90 100644 --- a/index.html +++ b/index.html @@ -26,6 +26,7 @@ {{response.methodName}} {{response.urlName}} {{response.size}} + {{response.bites}}
diff --git a/requestService.js b/requestService.js index ab7c6dd..f86df11 100644 --- a/requestService.js +++ b/requestService.js @@ -3,6 +3,8 @@ angular.module('fetchApp').service('requestService', function ($http) { this.get = url => $http.get(url); this.post = url => $http.post(url); + this.head = url => $http.head(url); + this.options = url => $http.options(url); }); })(); diff --git a/responseFactory.js b/responseFactory.js index 2bfbe18..c633d6c 100644 --- a/responseFactory.js +++ b/responseFactory.js @@ -5,6 +5,7 @@ this.methodName = responseData.config.method; this.urlName = responseData.config.url; this.size = (responseData.data.length)/1000; + this.bites = responseData.size; console.log(responseData); }; return Response;