misc_pterodactyl-panel/public/js/laroute.js

196 lines
43 KiB
JavaScript
Raw Normal View History

(function () {
var laroute = (function () {
var routes = {
absolute: false,
rootUrl: 'http://pterodactyl.local',
2018-10-14 01:31:33 +00:00
routes : [{"host":null,"methods":["GET","HEAD"],"uri":"_debugbar\/open","name":"debugbar.openhandler","action":"Barryvdh\Debugbar\Controllers\OpenHandlerController@handle"},{"host":null,"methods":["GET","HEAD"],"uri":"_debugbar\/clockwork\/{id}","name":"debugbar.clockwork","action":"Barryvdh\Debugbar\Controllers\OpenHandlerController@clockwork"},{"host":null,"methods":["GET","HEAD"],"uri":"_debugbar\/assets\/stylesheets","name":"debugbar.assets.css","action":"Barryvdh\Debugbar\Controllers\AssetController@css"},{"host":null,"methods":["GET","HEAD"],"uri":"_debugbar\/assets\/javascript","name":"debugbar.assets.js","action":"Barryvdh\Debugbar\Controllers\AssetController@js"},{"host":null,"methods":["DELETE"],"uri":"_debugbar\/cache\/{key}\/{tags?}","name":"debugbar.cache.delete","action":"Barryvdh\Debugbar\Controllers\CacheController@delete"},{"host":null,"methods":["GET","HEAD"],"uri":"\/","name":"index","action":"Pterodactyl\Http\Controllers\Base\IndexController@getIndex"},{"host":null,"methods":["GET","HEAD"],"uri":"status\/{server}","name":"index.status","action":"Pterodactyl\Http\Controllers\Base\IndexController@status"},{"host":null,"methods":["GET","HEAD"],"uri":"account","name":"account","action":"Pterodactyl\Http\Controllers\Base\AccountController@index"},{"host":null,"methods":["POST"],"uri":"account","name":null,"action":"Pterodactyl\Http\Controllers\Base\AccountController@update"},{"host":null,"methods":["GET","HEAD"],"uri":"account\/api","name":"account.api","action":"Pterodactyl\Http\Controllers\Base\ClientApiController@index"},{"host":null,"methods":["GET","HEAD"],"uri":"account\/api\/new","name":"account.api.new","action":"Pterodactyl\Http\Controllers\Base\ClientApiController@create"},{"host":null,"methods":["POST"],"uri":"account\/api\/new","name":null,"action":"Pterodactyl\Http\Controllers\Base\ClientApiController@store"},{"host":null,"methods":["DELETE"],"uri":"account\/api\/revoke\/{identifier}","name":"account.api.revoke","action":"Pterodactyl\Http\Controllers\Base\ClientApiController@delete"},{"host":null,"methods":["GET","HEAD"],"uri":"account\/security","name":"account.security","action":"Pterodactyl\Http\Controllers\Base\SecurityController@index"},{"host":null,"methods":["GET","HEAD"],"uri":"account\/security\/revoke\/{id}","name":"account.security.revoke","action":"Pterodactyl\Http\Controllers\Base\SecurityController@revoke"},{"host":null,"methods":["PUT"],"uri":"account\/security\/totp","name":"account.security.totp","action":"Pterodactyl\Http\Controllers\Base\SecurityController@generateTotp"},{"host":null,"methods":["POST"],"uri":"account\/security\/totp","name":"account.security.totp.set","action":"Pterodactyl\Http\Controllers\Base\SecurityController@setTotp"},{"host":null,"methods":["DELETE"],"uri":"account\/security\/totp","name":"account.security.totp.disable","action":"Pterodactyl\Http\Controllers\Base\SecurityController@disableTotp"},{"host":null,"methods":["GET","HEAD"],"uri":"admin","name":"admin.index","action":"Pterodactyl\Http\Controllers\Admin\BaseController@index"},{"host":null,"methods":["GET","HEAD"],"uri":"admin\/statistics","name":"admin.statistics","action":"Pterodactyl\Http\Controllers\Admin\StatisticsController@index"},{"host":null,"methods":["GET","HEAD"],"uri":"admin\/api","name":"admin.api.index","action":"Pterodactyl\Http\Controllers\Admin\ApiController@index"},{"host":null,"methods":["GET","HEAD"],"uri":"admin\/api\/new","name":"admin.api.new","action":"Pterodactyl\Http\Controllers\Admin\ApiController@create"},{"host":null,"methods":["POST"],"uri":"admin\/api\/new","name":null,"action":"Pterodactyl\Http\Controllers\Admin\ApiController@store"},{"host":null,"methods":["DELETE"],"uri":"admin\/api\/revoke\/{identifier}","name":"admin.api.delete","action":"Pterodactyl\Http\Controllers\Admin\ApiController@delete"},{"host":null,"methods":["GET","HEAD"],"uri":"admin\/locations","name":"admin.locations","action":"Pterodactyl\Http\Controllers\Admin\LocationController@index"},{"host":null,"methods":["GET","HEAD"],"uri":"admin\/locations\/view\/{location}","name":"admin.
prefix: '',
route : function (name, parameters, route) {
route = route || this.getByName(name);
if ( ! route ) {
return undefined;
}
return this.toRoute(route, parameters);
},
url: function (url, parameters) {
parameters = parameters || [];
var uri = url + '/' + parameters.join('/');
return this.getCorrectUrl(uri);
},
toRoute : function (route, parameters) {
var uri = this.replaceNamedParameters(route.uri, parameters);
var qs = this.getRouteQueryString(parameters);
2017-04-15 21:18:12 +00:00
if (this.absolute && this.isOtherHost(route)){
return "//" + route.host + "/" + uri + qs;
}
return this.getCorrectUrl(uri + qs);
},
2017-04-15 21:18:12 +00:00
isOtherHost: function (route){
return route.host && route.host != window.location.hostname;
},
replaceNamedParameters : function (uri, parameters) {
uri = uri.replace(/\{(.*?)\??\}/g, function(match, key) {
if (parameters.hasOwnProperty(key)) {
var value = parameters[key];
delete parameters[key];
return value;
} else {
return match;
}
});
// Strip out any optional parameters that were not given
uri = uri.replace(/\/\{.*?\?\}/g, '');
return uri;
},
getRouteQueryString : function (parameters) {
var qs = [];
for (var key in parameters) {
if (parameters.hasOwnProperty(key)) {
qs.push(key + '=' + parameters[key]);
}
}
if (qs.length < 1) {
return '';
}
return '?' + qs.join('&');
},
getByName : function (name) {
for (var key in this.routes) {
if (this.routes.hasOwnProperty(key) && this.routes[key].name === name) {
return this.routes[key];
}
}
},
getByAction : function(action) {
for (var key in this.routes) {
if (this.routes.hasOwnProperty(key) && this.routes[key].action === action) {
return this.routes[key];
}
}
},
getCorrectUrl: function (uri) {
var url = this.prefix + '/' + uri.replace(/^\/?/, '');
2017-04-15 21:18:12 +00:00
if ( ! this.absolute) {
return url;
2017-04-15 21:18:12 +00:00
}
return this.rootUrl.replace('/\/?$/', '') + url;
}
};
var getLinkAttributes = function(attributes) {
if ( ! attributes) {
return '';
}
var attrs = [];
for (var key in attributes) {
if (attributes.hasOwnProperty(key)) {
attrs.push(key + '="' + attributes[key] + '"');
}
}
return attrs.join(' ');
};
var getHtmlLink = function (url, title, attributes) {
title = title || url;
attributes = getLinkAttributes(attributes);
return '<a href="' + url + '" ' + attributes + '>' + title + '</a>';
};
return {
// Generate a url for a given controller action.
// Router.action('HomeController@getIndex', [params = {}])
action : function (name, parameters) {
parameters = parameters || {};
return routes.route(name, parameters, routes.getByAction(name));
},
// Generate a url for a given named route.
// Router.route('routeName', [params = {}])
route : function (route, parameters) {
parameters = parameters || {};
return routes.route(route, parameters);
},
// Generate a fully qualified URL to the given path.
// Router.route('url', [params = {}])
url : function (route, parameters) {
parameters = parameters || {};
return routes.url(route, parameters);
},
// Generate a html link to the given url.
// Router.link_to('foo/bar', [title = url], [attributes = {}])
link_to : function (url, title, attributes) {
url = this.url(url);
return getHtmlLink(url, title, attributes);
},
// Generate a html link to the given route.
// Router.link_to_route('route.name', [title=url], [parameters = {}], [attributes = {}])
link_to_route : function (route, title, parameters, attributes) {
var url = this.route(route, parameters);
return getHtmlLink(url, title, attributes);
},
// Generate a html link to the given controller action.
// Router.link_to_action('HomeController@getIndex', [title=url], [parameters = {}], [attributes = {}])
link_to_action : function(action, title, parameters, attributes) {
var url = this.action(action, parameters);
return getHtmlLink(url, title, attributes);
}
};
}).call(this);
/**
* Expose the class either via AMD, CommonJS or the global object
*/
if (typeof define === 'function' && define.amd) {
define(function () {
return laroute;
});
}
else if (typeof module === 'object' && module.exports){
module.exports = laroute;
}
else {
window.Router = laroute;
}
}).call(this);