pathfinder-ui
Advanced tools
Comparing version 0.1.136 to 0.1.137
var app = angular.module('pathfinderApp',['ui.router', 'ngMaterial']) | ||
var app = angular.module('pathfinderApp',['ngMaterial', 'ngMdIcons']) | ||
.config(function($mdThemingProvider){ | ||
@@ -4,0 +4,0 @@ $mdThemingProvider.theme('default') |
app.controller('MainController', function($scope, RequestFactory){ | ||
$scope.request = {}; | ||
$scope.request.method = 'GET' | ||
$scope.request.url = '/hero' | ||
$scope.sendReq = function(){ | ||
RequestFactory.reqRoute($scope.request).then(function(respDetails){ | ||
console.log("respDetails", respDetails) | ||
}) | ||
/* | ||
{ | ||
method: string, | ||
url: string, | ||
params: {obj}, | ||
data: {obj}, | ||
headers: {} | ||
} | ||
*/ | ||
$scope.setParams = RequestFactory.setParams | ||
$scope.populateData = RequestFactory.populateData | ||
// $scope.$on('nodeClick', function(event) { | ||
// console.log("i'm clicking"); | ||
// console.log("event", event); | ||
// event.stopProgation(); | ||
// $scope.$broadcast('nodeClick'); | ||
// }) | ||
// $scope.setParams() //this is for testing until tree is hooked up to this controller | ||
}) |
@@ -1,8 +0,26 @@ | ||
app.controller('TabBtnsController', function($scope, $state){ | ||
app.controller('TabBtnsController', function($scope, HistoryFactory, RequestFactory){ | ||
//Put the state name of the tabs in the array below. | ||
$scope.tabs = [{name:"The first tab", directive:'tab1'}, | ||
{name:"The second tab", directive:'tab2'}, | ||
{name:"The third tab", directive:'tab3'}, | ||
{name:"The fourth tab", directive:'tab4'}] | ||
}) | ||
$scope.tabs = [ | ||
{name:"The first tab", directive:'tab1'}, | ||
{name:"Request History", directive:'history'}, | ||
{name:"The third tab", directive:'tab3'}, | ||
{name:"The fourth tab", directive:'tab4'} | ||
]; | ||
$scope.selectedIndex = 0; | ||
$scope.populatePriorReq = function(item) { | ||
$scope.selectedIndex = 0; | ||
RequestFactory.populateData(item); | ||
}; | ||
$scope.switchTab = function(tab){ | ||
$scope.selectedIndex = tab; | ||
} | ||
$scope.$on('nodeClick', function(event) { | ||
console.log("got click"); | ||
}) | ||
}); |
@@ -15,15 +15,3 @@ app.directive('tab1', function () { | ||
app.directive('tab2', function () { | ||
return { | ||
restrict: 'E', | ||
scope: true, | ||
templateUrl: 'js/directives/tab2.html', | ||
link: function (scope) { | ||
} | ||
}; | ||
}); | ||
app.directive('tab3', function () { | ||
@@ -30,0 +18,0 @@ |
app.factory('RequestFactory', function($http){ | ||
var currNode = { | ||
url: "", | ||
method: "", | ||
params: {}, | ||
urlParams: [], // array of objects (key-value pairs) | ||
headers: {}, | ||
data: {} | ||
} | ||
var addToHeaders = function(key, value) { | ||
currNode.headers[key] = value; | ||
console.log("currentRequest headers", currNode.headers); | ||
} | ||
var getHeaders = function() { | ||
return currNode.headers; | ||
} | ||
var populateData = function(node){ | ||
currNode = { | ||
url: "", | ||
method: "", | ||
params: {}, | ||
urlParams: [], | ||
headers: {} | ||
} | ||
currNode.method = node.method; | ||
currNode.url = node.url; | ||
currNode.params = node.params || {} | ||
if(Object.keys(currNode.params).length == 0) setParams(); | ||
currNode.urlParams = node.urlParams || [] | ||
} | ||
var setParams = function(){ | ||
currNode.url.split("/").forEach(function(item){ | ||
if(item[0] === ":"){ | ||
currNode.params[item.slice(1)] = null; | ||
} | ||
}) | ||
} | ||
var getUrl = function(){ | ||
var urlFinal = currNode.url.split("/").map(function(item){ | ||
if(item[0] === ":"){ | ||
var val = currNode.params[item.slice(1)] | ||
// | ||
if(val === null){ | ||
return item | ||
} else{ | ||
return val | ||
} | ||
} else{ | ||
return item | ||
} | ||
}) | ||
.join("/") | ||
if(currNode.urlParams.length){ | ||
var query = [] | ||
currNode.urlParams.forEach(function(obj){ | ||
if(obj.key.length){ | ||
var pair = obj.key + "=" + obj.val; | ||
query.push(pair); | ||
} | ||
}) | ||
if(query.length){ | ||
urlFinal += "?" + query.join("&"); | ||
} | ||
} | ||
return urlFinal | ||
} | ||
var addUrlParam = function(){ | ||
currNode.urlParams.push({key: "", | ||
val: ""}) | ||
} | ||
var getUrlParams = function(){ | ||
return currNode.urlParams | ||
} | ||
var getParams = function(){ | ||
return currNode.params | ||
} | ||
var responseDetails = {} | ||
return { | ||
setParams: setParams, | ||
getCurrNode: function(){ | ||
return currNode; | ||
}, | ||
currNode: currNode, | ||
populateData: populateData, | ||
addUrlParam: addUrlParam, | ||
getUrl: getUrl, | ||
getUrlParams: getUrlParams, | ||
getParams: getParams, | ||
getHeaders: getHeaders, | ||
addToHeaders: addToHeaders, | ||
getResponse: function(){ | ||
return responseDetails | ||
}, | ||
getMethod: function(){ | ||
return currNode.method; | ||
}, | ||
reqRoute: function(reqObj){ | ||
return $http(reqObj) | ||
.success(function(data, status, headers, config){ | ||
var details = {} | ||
details.data = data | ||
details.status = status | ||
details.headers = headers | ||
details.config = config | ||
return details | ||
return $http(reqObj).then( | ||
function(response){ | ||
responseDetails = response | ||
return response | ||
}, | ||
function(response){ | ||
responseDetails = response | ||
return response | ||
}) | ||
.error(function(data, status, headers, config){ | ||
var details = {} | ||
details.data = data | ||
details.status = status | ||
details.headers = headers | ||
details.config = config | ||
return details | ||
}) | ||
} | ||
} | ||
}) |
@@ -6,15 +6,21 @@ var example = require('./example'); | ||
function pathfinderUI (app){ | ||
var packageJsonPath = process.cwd() + '/package.json'; | ||
var packageJsonName = require(packageJsonPath).name; | ||
pfroute.request.RESTroutes = generateRouteTree(app); | ||
pfroute.request.RESTroutes = { | ||
routes: generateRouteTree(app), | ||
appId: packageJsonName | ||
}; | ||
// console.log(generateRouteTree(app).children[3].children[0].children[0].children); | ||
function generateRouteTree(app) { | ||
var routeObj = {}; // create tree object | ||
var topLevelRouteStack = app._router.stack; | ||
var routes = retrieveRoutes(topLevelRouteStack); | ||
routeObj["name"] = "APP"; | ||
routeObj["children"] = routes; | ||
var routeObj = { | ||
url: packageJsonName, | ||
children: retrieveRoutes(topLevelRouteStack) | ||
}; | ||
return routeObj; | ||
@@ -24,47 +30,52 @@ } | ||
function retrieveRoutes (topLevelRouteStack, parentPath) { | ||
var allRoutes = []; | ||
var pPath = ""; | ||
if(parentPath) pPath = parentPath; // saving so we can get child route's full path | ||
console.log('this is the parentPath', parentPath) | ||
if(parentPath) { | ||
if (parentPath === '/'){ | ||
parentPath = ''; | ||
} | ||
pPath = parentPath; | ||
} | ||
var routesArray = topLevelRouteStack.filter(function(stack){ // filter out unwanted middleware | ||
var routesArray = topLevelRouteStack.filter(function(stack){ // filter out middleware | ||
return stack.route || stack.handle.stack; | ||
}); | ||
routesArray.forEach(function(e){ | ||
routesArray.map(function(e){ | ||
var parentName; | ||
if (e.route){ // if no subrouter, just direct route | ||
var route = { url: pPath + e.route.path, method: e.route.stack[0].method }; | ||
allRoutes.push(route); | ||
if (e.route){ // if no subrouter, just direct route | ||
} else if (e.handle.stack) { // if subrouter exists | ||
parentName = '/'; | ||
if (e.regexp.test('/')){ | ||
parentName = '/'; | ||
} | ||
else { | ||
//console.log('regex: ', e.regexp.source.match(/\w+/ig).join("/")) | ||
parentName = e.regexp.source.match(/\w+/ig).join("/"); | ||
} | ||
var route = { name: pPath + e.route.path, method: e.route.stack[0].method }; | ||
allRoutes.push(route); | ||
var parentPath = pPath + "/" +parentName; | ||
if (parentName === '/') parentPath = pPath; | ||
var route = { | ||
url: parentName | ||
}; | ||
} else if (e.handle.stack) { // if subrouter exists | ||
var parentName = ''; | ||
if (e.regexp.test('/')){ | ||
parentName = '/'; | ||
} | ||
else { | ||
parentName = e.regexp.toString().slice(0, -1).match(/\w+/ig).join("/"); | ||
} | ||
route.children = retrieveRoutes(e.handle.stack, parentPath); | ||
allRoutes.push(route); | ||
} else { | ||
console.log("missed a case"); | ||
} | ||
var parentPath = pPath + "/" + parentName; | ||
var route = {}; | ||
route["name"] = parentName; | ||
route["children"] = []; | ||
}); | ||
var subRouterStack = e.handle.stack; // if route is in the handle's stack, retrieve those routes | ||
return allRoutes; | ||
route["children"] = retrieveRoutes(subRouterStack, parentPath); | ||
allRoutes.push(route); | ||
} else { | ||
console.log("missed a case"); // for edge cases | ||
} | ||
}); | ||
return allRoutes; | ||
} | ||
} | ||
} | ||
pathfinderUI.router = pfroute; |
@@ -13,5 +13,18 @@ // Created By: Sangmin Lee | ||
pfrouter.get('/data', function(req, res){ | ||
res.send(req.RESTroutes); | ||
console.log("REQ RESTroutes", req.RESTroutes.children); | ||
res.json(req.RESTroutes); | ||
}); | ||
// pfrouter.get('/oauth2/callback', function(req, res) { // can handle any provider | ||
// console.log("hit oauth route"); | ||
// passport.authenticate(), | ||
// function(req, res) { | ||
// console.log("req.user", req.user); | ||
// res.send("hit oAuth callback, req.user: ", req.user); | ||
// }; | ||
// }); | ||
module.exports = pfrouter; |
{ | ||
"name": "pathfinder-ui", | ||
"version": "0.1.136", | ||
"version": "0.1.137", | ||
"private": false, | ||
@@ -26,8 +26,5 @@ "preferGlobal": false, | ||
"dependencies": { | ||
"angular": "^1.4.1", | ||
"angular-animate": "^1.4.1", | ||
"angular-aria": "^1.4.1", | ||
"angular-material": "^0.10.0", | ||
"angular-ui-router": "^0.2.15", | ||
"express": "^4.13.0" | ||
"express": "^4.13.0", | ||
"lodash": "^3.10.0" | ||
}, | ||
@@ -34,0 +31,0 @@ "repository": { |
@@ -5,27 +5,32 @@ Pathfinder-UI | ||
THIS IS IN ALPHA STAGE. NOT YET FULLY FUNCTIONAL | ||
Pathfinder-UI is a tool that allows you to visualize and test the routes in an express application. | ||
A library that allows developers to visually test their routes. | ||
TEST TEST TEST TEST | ||
## Installation | ||
```bash | ||
npm install pathfinder-ui --save | ||
``` | ||
## Usage | ||
```js | ||
var pfUI = require('pathfinder-ui') | ||
``` | ||
Blah blah blah blah ipsum lorsomething dolor darmok and jalad at tanagra | ||
This line attaches the Pathfinder interface to your express app. | ||
Place it before your routes/routers/middlewares | ||
```js | ||
app.use('yourCustomPath', pfUI.router) | ||
``` | ||
This function grabs your express routes and passes the data to our angular app | ||
Place this line after all of your routes/routers/middlewares. | ||
```js | ||
pfUI(app); | ||
``` | ||
You access the interface by going to localhost:PORT/yourCustomPath | ||
## Tests | ||
Blah blah blah blah ipsum lorsomething dolor darmok and jalad at tanagra | ||
## Contributing | ||
Blah blah blah blah ipsum lorsomething dolor darmok and jalad at tanagra. | ||
## Release History | ||
* 0.0.0 some version title stuff |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
3
34
36
71633
880
1
1
+ Addedlodash@^3.10.0
+ Addedlodash@3.10.1(transitive)
- Removedangular@^1.4.1
- Removedangular-animate@^1.4.1
- Removedangular-aria@^1.4.1
- Removedangular-material@^0.10.0
- Removedangular-animate@1.8.3(transitive)
- Removedangular-aria@1.8.3(transitive)
- Removedangular-material@0.10.1(transitive)