2019-01-02 04:24:12 -06:00
|
|
|
/////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// pgAdmin 4 - PostgreSQL Tools
|
|
|
|
//
|
2023-01-02 00:23:55 -06:00
|
|
|
// Copyright (C) 2013 - 2023, The pgAdmin Development Team
|
2019-01-02 04:24:12 -06:00
|
|
|
// This software is released under the PostgreSQL Licence
|
|
|
|
//
|
|
|
|
//////////////////////////////////////////////////////////////
|
|
|
|
|
2018-01-12 01:29:51 -06:00
|
|
|
define(['pgadmin.browser.endpoints'], function(endpoints) {
|
2017-06-12 01:31:22 -05:00
|
|
|
/***
|
|
|
|
* This method behaves as a drop-in replacement for flask url_for function.
|
|
|
|
* It uses the exposed URLs file under the hood, and replace the substitions provided by the modules.
|
|
|
|
*
|
|
|
|
* ex.
|
|
|
|
* url_for("help.static", {filename: "server_dialog.html"}) will produce the
|
|
|
|
* output string '/help/help/server_dialog.html' from the url ->
|
|
|
|
* '/help/help/<path:filename>'.
|
|
|
|
*
|
|
|
|
* @param {String} text
|
|
|
|
* @param {Object} substitutions
|
|
|
|
*/
|
|
|
|
return function url_for(endpoint, substitutions) {
|
|
|
|
|
2022-09-08 07:38:58 -05:00
|
|
|
let rawURL = endpoints[endpoint];
|
2017-06-12 01:31:22 -05:00
|
|
|
|
|
|
|
// captures things of the form <path:substitutionName>
|
2022-09-08 07:38:58 -05:00
|
|
|
let substitutionGroupsRegExp = /([<])([^:^>]*:)?([^>]+)([>])/g,
|
2018-01-12 01:29:51 -06:00
|
|
|
interpolated = rawURL;
|
2017-06-12 01:31:22 -05:00
|
|
|
|
|
|
|
if (!rawURL)
|
|
|
|
return rawURL;
|
|
|
|
|
|
|
|
interpolated = interpolated.replace(
|
|
|
|
substitutionGroupsRegExp,
|
2018-01-12 01:29:51 -06:00
|
|
|
function(_origin, _1, _2, substitutionName) {
|
2017-06-12 01:31:22 -05:00
|
|
|
if (substitutionName in substitutions) {
|
|
|
|
return substitutions[substitutionName];
|
|
|
|
}
|
|
|
|
return _origin;
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
return interpolated;
|
|
|
|
};
|
|
|
|
|
|
|
|
});
|