mirror of
https://github.com/OpenBankProject/API-Manager.git
synced 2026-02-06 18:56:48 +00:00
fixed the webui function
This commit is contained in:
parent
0b3c9cc94d
commit
96e44c7ca0
@ -1,37 +1,13 @@
|
||||
$(document).ready(function($) {
|
||||
function syntaxHighlight(json) {
|
||||
if (typeof json != 'string') {
|
||||
json = JSON.stringify(json, undefined, 2);
|
||||
}
|
||||
json = json.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>');
|
||||
return json.replace(/("(\\u[a-zA-Z0-9]{4}|\\[^u]|[^\\"])*"(\s*:)?|\b(true|false|null)\b|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?)/g, function (match) {
|
||||
var cls = 'number';
|
||||
if (/^"/.test(match)) {
|
||||
if (/:$/.test(match)) {
|
||||
cls = 'key';
|
||||
} else {
|
||||
cls = 'string';
|
||||
}
|
||||
} else if (/true|false/.test(match)) {
|
||||
cls = 'boolean';
|
||||
} else if (/null/.test(match)) {
|
||||
cls = 'null';
|
||||
}
|
||||
return '<span class="' + cls + '">' + match + '</span>';
|
||||
});
|
||||
}
|
||||
|
||||
$('#config-json').html((syntaxHighlight(ConfigJson)));
|
||||
|
||||
$('.runner button.forSave').click(function() {
|
||||
var t = $(this);
|
||||
var runner = $(this).parent().parent().parent();
|
||||
method = $(runner).find('#id_webui_props_key').innerHTML;
|
||||
value = $(runner).find('textarea[name="webui_props_value"]').val();
|
||||
webui_props_name = $(runner).find('.webui_props_name').text();
|
||||
webui_props_value = $(runner).find('.webui_props_value').val();
|
||||
|
||||
$.post('/webui/save/method', {
|
||||
'method': method,
|
||||
'value': value,
|
||||
'webui_props_name': webui_props_name,
|
||||
'webui_props_value': webui_props_value,
|
||||
'csrfmiddlewaretoken': window.CSRF
|
||||
}, function (response) {
|
||||
t.next().show().fadeOut(1000);
|
||||
|
||||
@ -4,62 +4,63 @@
|
||||
{% block page_title %}{{ block.super }} / Users{% endblock page_title %}
|
||||
|
||||
{% block content %}
|
||||
<div id="webui">
|
||||
<div id="webui_list">
|
||||
<h1>WEBUI</h1>
|
||||
<div id="webui">
|
||||
<div id="webui_list">
|
||||
<h1>WEBUI</h1>
|
||||
|
||||
{# <form method="post" action="{% url 'webui:webui-index' %}">#}
|
||||
<form method="post">
|
||||
{% csrf_token %}
|
||||
{% if form.non_field_errors %}
|
||||
<div class="alert alert-danger">
|
||||
{{ form.non_field_errors }}
|
||||
</div>
|
||||
{% endif %}
|
||||
<form method="post">
|
||||
{% csrf_token %}
|
||||
{% if form.non_field_errors %}
|
||||
<div class="alert alert-danger">
|
||||
{{ form.non_field_errors }}
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
<div class="row">
|
||||
<div class="col-xs-12 col-sm-4">
|
||||
<label class="form-group" >Web UI Props Name:</label> <br>
|
||||
</div>
|
||||
<div class="col-xs-12 col-sm-4">
|
||||
<label class="form-group" >Web UI Props Value:</label> <br>
|
||||
</div>
|
||||
<div class="col-sm-12 col-sm-4">
|
||||
<label class="form-group" >Save Value:</label> <br>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{% for webui_prop in webui_props %}
|
||||
<div class="runner">
|
||||
<div class="row">
|
||||
<div class="row">
|
||||
<div class="col-xs-12 col-sm-4">
|
||||
<div class="form-group" name="webui_props_value" cols="20" rows="1" id="id_webui_props_key"><strong>{{ webui_prop.name }}</strong></div>
|
||||
<label class="form-group">Web UI Props Name:</label> <br>
|
||||
</div>
|
||||
<div class="col-xs-12 col-sm-4">
|
||||
<div class="form-group">
|
||||
<textarea name="webui_props_value" cols="40" rows="1" class="form-control" id="id_webui_props_value">{{ webui_prop.value }}</textarea>
|
||||
</div>
|
||||
<label class="form-group">Web UI Props Value:</label> <br>
|
||||
</div>
|
||||
<div class="col-sm-12 col-sm-4">
|
||||
<div class="form-group">
|
||||
<button class="btn btn-primary btn-green" id="forSave">Save</button>
|
||||
<label class="form-group">Save Value:</label> <br>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{% for webui_prop in webui_props %}
|
||||
<div class="runner">
|
||||
<div class="row">
|
||||
<div class="col-xs-12 col-sm-4">
|
||||
<div class="form-group" cols="20" rows="1"><strong
|
||||
class="webui_props_name">{{ webui_prop.name }}</strong></div>
|
||||
</div>
|
||||
<div class="col-xs-12 col-sm-4">
|
||||
<div class="form-group">
|
||||
<textarea class="form-control webui_props_value" cols="40"
|
||||
rows="1">{{ webui_prop.value }}</textarea>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-sm-12 col-sm-4">
|
||||
<div class="form-group">
|
||||
<button class="btn btn-primary btn-green forSave">Save</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endfor %}
|
||||
{% endfor %}
|
||||
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
||||
{% block extrajs %}
|
||||
<script type="text/javascript" src="{% static 'webui/js/webui.js' %}"></script>
|
||||
<script type="text/javascript" src="{% static 'webui/js/webui.js' %}"></script>
|
||||
|
||||
{% endblock extrajs %}
|
||||
|
||||
|
||||
{% block extracss %}
|
||||
<link href="{% static 'webui/css/webui.css' %}" rel="stylesheet">
|
||||
<link href="{% static 'webui/css/webui.css' %}" rel="stylesheet">
|
||||
{% endblock extracss %}
|
||||
|
||||
@ -12,6 +12,7 @@ from obp.api import API, APIError
|
||||
from django.http import JsonResponse
|
||||
from .forms import WebuiForm
|
||||
from django.urls import reverse_lazy
|
||||
from django.views.decorators.csrf import csrf_exempt
|
||||
|
||||
def error_once_only(request, err):
|
||||
"""
|
||||
@ -36,7 +37,6 @@ class IndexView(LoginRequiredMixin, FormView):
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super(IndexView, self).get_context_data(**kwargs)
|
||||
webui_props = []
|
||||
api = API(self.request.session.get('obp'))
|
||||
urlpath = '/management/webui_props?active=true'
|
||||
|
||||
@ -49,64 +49,44 @@ class IndexView(LoginRequiredMixin, FormView):
|
||||
except BaseException as err:
|
||||
messages.error(self.request, (Exception("Unknown Error. Details:" + str(err))))
|
||||
else:
|
||||
webui_props = response["webui_props"]
|
||||
context.update({'webui_props': webui_props})
|
||||
# Here is response of getWebuiProps.
|
||||
# {
|
||||
# "webui_props": [
|
||||
# {
|
||||
# "name": "webui_header_logo_left_url ",
|
||||
# "value": " /media/images/logo.png",
|
||||
# "web_ui_props_id": "default"
|
||||
# }
|
||||
# ]
|
||||
# }
|
||||
context.update(response)
|
||||
return context
|
||||
|
||||
def get_form(self, *args, **kwargs):
|
||||
form = super(IndexView, self).get_form(*args, **kwargs)
|
||||
return form
|
||||
|
||||
def form_valid(self, form):
|
||||
try:
|
||||
# TODO, need to be fixed later.
|
||||
data = form.cleaned_data
|
||||
urlpath = '/management/webui_props'
|
||||
payload = {
|
||||
"name" : "1",
|
||||
"value" : "2"
|
||||
}
|
||||
result = self.api.post(urlpath, payload=payload)
|
||||
except APIError as err:
|
||||
error_once_only(self.request, APIError(Exception("OBP-API server is not running or do not response properly. "
|
||||
"Please check OBP-API server. Details: " + str(err))))
|
||||
return super(IndexView, self).form_invalid(form)
|
||||
except Exception as err:
|
||||
error_once_only(self.request, "Unknown Error. Details: "+ str(err))
|
||||
return super(IndexView, self).form_invalid(form)
|
||||
if 'code' in result and result['code']>=400:
|
||||
error_once_only(self.request, result['message'])
|
||||
return super(IndexView, self).form_valid(form)
|
||||
msg = 'Submission successfully!'
|
||||
messages.success(self.request, msg)
|
||||
return super(IndexView, self).form_valid(form)
|
||||
|
||||
@csrf_exempt
|
||||
def webui_save(request):
|
||||
operation_id = request.POST.get('operation_id')
|
||||
json_body = request.POST.get('json_body', '')
|
||||
profile_id = request.POST.get('profile_id')
|
||||
order = request.POST.get('order')
|
||||
urlpath = request.POST.get('urlpath')
|
||||
replica_id = request.POST.get('replica_id')
|
||||
remark = request.POST.get('remark')
|
||||
webui_props_name = request.POST.get('webui_props_name')
|
||||
webui_props_value = request.POST.get('webui_props_value')
|
||||
|
||||
#if not re.match("^{.*}$", json_body):
|
||||
# json_body = "{{{}}}".format(json_body)
|
||||
|
||||
data = {
|
||||
'operation_id' : operation_id,
|
||||
'json_body': json_body,
|
||||
'profile_id': profile_id,
|
||||
'order': order,
|
||||
'urlpath': urlpath,
|
||||
'remark':remark,
|
||||
'is_deleted':0
|
||||
payload = {
|
||||
'name': webui_props_name,
|
||||
'value': webui_props_value
|
||||
}
|
||||
|
||||
profile_list = ProfileOperation.objects.update_or_create(
|
||||
operation_id=operation_id,
|
||||
profile_id=profile_id,
|
||||
replica_id=replica_id,
|
||||
defaults=data
|
||||
)
|
||||
api = API(request.session.get('obp'))
|
||||
try:
|
||||
urlpath = '/management/webui_props'
|
||||
result = api.post(urlpath, payload=payload)
|
||||
except APIError as err:
|
||||
error_once_only(request, APIError(Exception("OBP-API server is not running or do not response properly. "
|
||||
"Please check OBP-API server. Details: " + str(err))))
|
||||
except Exception as err:
|
||||
error_once_only(request, "Unknown Error. Details: " + str(err))
|
||||
if 'code' in result and result['code'] >= 400:
|
||||
error_once_only(request, result['message'])
|
||||
msg = 'Submission successfully!'
|
||||
messages.success(request, msg)
|
||||
return JsonResponse({'state': True})
|
||||
Loading…
Reference in New Issue
Block a user