mirror of
https://github.com/pgadmin-org/pgadmin4.git
synced 2025-02-25 18:55:31 -06:00
Using client-side 'url_for' implementation in the module - bgprocess
(background-processes).
This commit is contained in:
@@ -12,7 +12,6 @@ A blueprint module providing utility functions for the notify the user about
|
||||
the long running background-processes.
|
||||
"""
|
||||
from flask import url_for
|
||||
from flask_babel import gettext as _
|
||||
from flask_security import login_required
|
||||
from pgadmin.utils import PgAdminModule
|
||||
from pgadmin.utils.ajax import make_response, gone, success_return
|
||||
@@ -40,14 +39,15 @@ class BGProcessModule(PgAdminModule):
|
||||
]
|
||||
return stylesheets
|
||||
|
||||
def get_own_messages(self):
|
||||
def get_exposed_url_endpoints(self):
|
||||
"""
|
||||
Returns:
|
||||
dict: the i18n messages used by this module
|
||||
list: URL endpoints for bgprocess
|
||||
"""
|
||||
return {
|
||||
'bgprocess.index': url_for("bgprocess.index")
|
||||
}
|
||||
return [
|
||||
'bgprocess.status', 'bgprocess.detailed_status',
|
||||
'bgprocess.acknowledge', 'bgprocess.list'
|
||||
]
|
||||
|
||||
|
||||
# Initialise the module
|
||||
@@ -56,14 +56,16 @@ blueprint = BGProcessModule(
|
||||
)
|
||||
|
||||
|
||||
@blueprint.route('/', methods=['GET'])
|
||||
@blueprint.route('/', methods=['GET'], endpoint='list')
|
||||
@login_required
|
||||
def index():
|
||||
return make_response(response=BatchProcess.list())
|
||||
|
||||
|
||||
@blueprint.route('/<pid>', methods=['GET'])
|
||||
@blueprint.route('/<pid>/<int:out>/<int:err>/', methods=['GET'])
|
||||
@blueprint.route('/<pid>', methods=['GET'], endpoint='status')
|
||||
@blueprint.route(
|
||||
'/<pid>/<int:out>/<int:err>/', methods=['GET'], endpoint='detailed_status'
|
||||
)
|
||||
@login_required
|
||||
def status(pid, out=-1, err=-1):
|
||||
"""
|
||||
@@ -87,7 +89,7 @@ def status(pid, out=-1, err=-1):
|
||||
return gone(errormsg=str(lerr))
|
||||
|
||||
|
||||
@blueprint.route('/<pid>', methods=['PUT'])
|
||||
@blueprint.route('/<pid>', methods=['PUT'], endpoint='acknowledge')
|
||||
@login_required
|
||||
def acknowledge(pid):
|
||||
"""
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
define([
|
||||
'pgadmin', 'sources/gettext', 'underscore', 'underscore.string', 'jquery', 'pgadmin.browser',
|
||||
'alertify', 'pgadmin.browser.messages'
|
||||
], function(pgAdmin, gettext, _, S, $, pgBrowser, alertify, pgMessages) {
|
||||
'pgadmin', 'sources/gettext', 'sources/url_for', 'underscore',
|
||||
'underscore.string', 'jquery', 'pgadmin.browser', 'alertify',
|
||||
'pgadmin.browser.messages'
|
||||
], function(
|
||||
pgAdmin, gettext, url_for, _, S, $, pgBrowser, alertify, pgMessages
|
||||
) {
|
||||
|
||||
pgBrowser.BackgroundProcessObsorver = pgBrowser.BackgroundProcessObsorver || {};
|
||||
|
||||
@@ -70,20 +73,24 @@ define([
|
||||
);
|
||||
},
|
||||
|
||||
url: function(type) {
|
||||
var url = S('%s%s').sprintf(pgMessages['bgprocess.index'], this.id).value();
|
||||
|
||||
bgprocess_url: function(type) {
|
||||
switch (type) {
|
||||
case 'status':
|
||||
if (this.details && this.out != -1 && this.err != -1) {
|
||||
url = S('%s/%s/%s/').sprintf(
|
||||
url, this.out, this.err
|
||||
).value();
|
||||
return url_for(
|
||||
'bgprocess.detailed_status', {
|
||||
'pid': this.id,
|
||||
'out': this.out,
|
||||
'err': this.err
|
||||
}
|
||||
);
|
||||
}
|
||||
break;
|
||||
return url_for('bgprocess.status', {'pid': this.id});
|
||||
case 'acknowledge':
|
||||
return url_for('bgprocess.acknowledge', {'pid': this.id});
|
||||
default:
|
||||
return url_for('bgprocess.list');
|
||||
}
|
||||
|
||||
return url;
|
||||
},
|
||||
|
||||
update: function(data) {
|
||||
@@ -203,7 +210,7 @@ define([
|
||||
$.ajax({
|
||||
typs: 'GET',
|
||||
timeout: 30000,
|
||||
url: self.url('status'),
|
||||
url: self.bgprocess_url('status'),
|
||||
cache: false,
|
||||
async: true,
|
||||
contentType: "application/json",
|
||||
@@ -388,7 +395,7 @@ define([
|
||||
$.ajax({
|
||||
type: 'PUT',
|
||||
timeout: 30000,
|
||||
url: self.url('acknowledge'),
|
||||
url: self.bgprocess_url('acknowledge'),
|
||||
cache: false,
|
||||
async: true,
|
||||
contentType: "application/json",
|
||||
@@ -436,7 +443,7 @@ define([
|
||||
$.ajax({
|
||||
typs: 'GET',
|
||||
timeout: 30000,
|
||||
url: pgMessages['bgprocess.index'],
|
||||
url: url_for('bgprocess.list'),
|
||||
cache: false,
|
||||
async: true,
|
||||
contentType: "application/json",
|
||||
|
||||
Reference in New Issue
Block a user