mirror of
https://github.com/OpenBankProject/API-Manager.git
synced 2026-02-06 11:16:50 +00:00
/feature add Connector Method
This commit is contained in:
parent
2f39d2b1d2
commit
29be9d5efc
@ -78,9 +78,7 @@ class ExportCsvView(LoginRequiredMixin, View):
|
||||
def get(self, request, *args, **kwargs):
|
||||
api = API(self.request.session.get('obp'))
|
||||
try:
|
||||
print("Helooooooo")
|
||||
self.bankids = self.get_banks()
|
||||
print("Worlddddddd", )
|
||||
atms_list = []
|
||||
for bank_id in self.bankids:
|
||||
urlpath = '/banks/{}/atms'.format(bank_id)
|
||||
|
||||
@ -97,7 +97,7 @@
|
||||
<li{% if config_index_url in request.path %} class="active"{% endif %}><a href="{{ config_index_url }}">{% trans "Config" %}</a></li><hr class="dropdown-hr">
|
||||
<li{% if webui_props_index_url in request.path %} class="active"{% endif %}><a href="{{ webui_props_index_url }}">{% trans "Webui Props" %}</a></li><hr class="dropdown-hr">
|
||||
<li{% if methodrouting_index_url in request.path %} class="active"{% endif %}><a href="{{ methodrouting_index_url }}">{% trans "Method Routings" %}</a></li><hr class="dropdown-hr">
|
||||
<li{% if connectormethod_url in request.path %} class="active"{% endif %}><a href="{{ connectormethod_url }}">{% trans "Connector Method" %}</a></li><hr class="dropdown-hr">
|
||||
<li{% if connectormethod_url in request.path %} class="active"{% endif %}><a href="{{ connectormethod_url }}">{% trans "Connector Methods" %}</a></li><hr class="dropdown-hr">
|
||||
<li{% if dynamic_endpoints_index_url in request.path %} class="active"{% endif %}><a href="{{ dynamic_endpoints_index_url }}">{% trans "Dynamic Endpoints" %}</a></li><hr class="dropdown-hr">
|
||||
<li{% if api_collections_index_url in request.path %} class="active"{% endif %}><a href="{{ api_collections_index_url }}">{% trans "My API Collections" %}</a></li>
|
||||
</ul>
|
||||
|
||||
@ -1,14 +1,9 @@
|
||||
"""
|
||||
Forms of ATMs app
|
||||
"""
|
||||
|
||||
from django import forms
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
import random
|
||||
|
||||
|
||||
class ConnectorMethodForm(forms.Form):
|
||||
api_collections_body = forms.CharField(
|
||||
label='API Collections Body',
|
||||
connector_method_body = forms.CharField(
|
||||
label='Connector Method Body',
|
||||
widget=forms.Textarea(
|
||||
attrs={
|
||||
'class': 'form-control',
|
||||
@ -17,54 +12,3 @@ class ConnectorMethodForm(forms.Form):
|
||||
required=False
|
||||
)
|
||||
|
||||
class ConnectorMethodEndpointForm(forms.Form):
|
||||
operation_id = forms.CharField(
|
||||
label='Operation Id',
|
||||
widget=forms.TextInput(
|
||||
attrs={
|
||||
'class': 'form-control',
|
||||
}
|
||||
),
|
||||
required=True
|
||||
)
|
||||
class CreateConnectorMethodForm(forms.Form):
|
||||
connector_method_id = forms.CharField(
|
||||
label=_('Connector Method Id'),
|
||||
widget=forms.TextInput(
|
||||
attrs={
|
||||
'placeholder': 'connector_method_id-{}'.format(random.randint(1,1000)),
|
||||
'class': 'form-control',
|
||||
}
|
||||
),
|
||||
initial='connector_method_id-{}'.format(random.randint(1,1000)),
|
||||
)
|
||||
method_name = forms.CharField(
|
||||
label=_('Method Name'),
|
||||
widget=forms.TextInput(
|
||||
attrs={
|
||||
'placeholder': _('Method Name'),
|
||||
'class': 'form-control',
|
||||
}
|
||||
),
|
||||
required=True
|
||||
)
|
||||
programming_lang = forms.CharField(
|
||||
label=_('Programming Language'),
|
||||
widget=forms.TextInput(
|
||||
attrs={
|
||||
'placeholder': _('Programming Lang'),
|
||||
'class': 'form-control',
|
||||
}
|
||||
),
|
||||
required=True
|
||||
)
|
||||
method_body = forms.CharField(
|
||||
label=_('Method Body'),
|
||||
widget=forms.TextInput(
|
||||
attrs={
|
||||
'placeholder': _('Method Body'),
|
||||
'class': 'form-control',
|
||||
}
|
||||
),
|
||||
required=True
|
||||
)
|
||||
@ -1,34 +1,40 @@
|
||||
console.log("good bye bye")
|
||||
$(document).ready(function($) {
|
||||
$('.runner button.forSave').click(function(e) {
|
||||
e.preventDefault();
|
||||
var t = $(this);
|
||||
var runner = t.parent().parent().parent();
|
||||
var api_collection_name = $(runner).find('.api_collection_name').val();
|
||||
var api_collection_is_sharable = $(runner).find('.api_collection_is_sharable').val();
|
||||
var api_collection_description = $(runner).find('.api_collection_description').val();
|
||||
|
||||
$('.runner button.forSave').attr("disabled","disabled");
|
||||
$('.runner button.forDelete').attr("disabled","disabled");
|
||||
$.post('save/apicollection', {
|
||||
'api_collection_name': api_collection_name,
|
||||
'api_collection_is_sharable': api_collection_is_sharable,
|
||||
'api_collection_description': api_collection_description,
|
||||
}, function (response) {
|
||||
location.reload();
|
||||
});
|
||||
var connector_method_name = $(runner).find('.connector_method_name').val();
|
||||
var connector_method_programming_lang = $(runner).find('.connector_method_programming_lang').val();
|
||||
var connector_method_body = $(runner).find('.connector_method_body').val();
|
||||
|
||||
$('.runner button.forSave').attr("disabled", "disabled");
|
||||
$('.runner button.forDelete').attr("disabled", "disabled");
|
||||
$.post('save/connectormethod', {
|
||||
'connector_method_name': connector_method_name,
|
||||
'connector_method_programming_lang': connector_method_programming_lang,
|
||||
'connector_method_body': connector_method_body,
|
||||
}, function(response) {
|
||||
location.reload();
|
||||
});
|
||||
});
|
||||
|
||||
$('.runner button.forDelete').click(function(e) {
|
||||
e.preventDefault();
|
||||
$('.runner button.forUpdate').click(function(e) {
|
||||
e.preventDefault();
|
||||
var t = $(this);
|
||||
var runner = t.parent().parent().parent();
|
||||
var api_collection_id = $(runner).find('.api_collection_id').html();
|
||||
$('.runner button.forSave').attr("disabled","disabled");
|
||||
$('.runner button.forDelete').attr("disabled","disabled");
|
||||
$.post('delete/apicollection', {
|
||||
'api_collection_id': api_collection_id
|
||||
}, function (response) {
|
||||
location.reload();
|
||||
});
|
||||
var connector_method_id = $(runner).find('.connector_method_id').html();
|
||||
var connector_method_programming_lang_update = $(runner).find('.connector_method_programming_lang_update').val();
|
||||
var connector_method_body_update = $(runner).find('.connector_method_body_update').val();
|
||||
|
||||
$('.runner button.forSave').attr("disabled", "disabled");
|
||||
$('.runner button.forUpdate').attr("disabled", "disabled");
|
||||
$.post('update/connectormethod', {
|
||||
'connector_method_id': connector_method_id,
|
||||
'connector_method_programming_lang_update': connector_method_programming_lang_update,
|
||||
'connector_method_body_update': connector_method_body_update,
|
||||
}, function(response) {
|
||||
location.reload();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
@ -1,43 +1,45 @@
|
||||
{% extends 'base.html' %}
|
||||
{% load static %}
|
||||
{% load static i18n %}
|
||||
{% block page_title %}{{ block.super }} / Connector Methods{% endblock page_title %}
|
||||
|
||||
{% block content %}
|
||||
<div id="api-collection-detail">
|
||||
<h2>Add Endpoint to API Collection</h2>
|
||||
<form class="form" action="" method="post">
|
||||
{% csrf_token %}
|
||||
<div class="row">
|
||||
<div class="col-xs-12 col-md-4">
|
||||
<div class="form-group">
|
||||
{{ form.operation_id.label_tag}}
|
||||
{{ form.operation_id }}
|
||||
</div>
|
||||
<input type="text" class="hidden" name="api-collection-id" value={{ connector_method_id }} >
|
||||
<button type="submit" class="btn btn-primary btn-green">Add</button>
|
||||
<h1>{% trans "Connector Methods" %}</h1>
|
||||
<div class="row">
|
||||
<div class="col-xs-12 col-sm-2">
|
||||
<label class="form-group">{% trans "Method Name" %}:</label> <br>
|
||||
</div>
|
||||
<div class="col-xs-12 col-sm-2">
|
||||
<label class="form-group">{% trans "Programming Language" %}:</label> <br>
|
||||
</div>
|
||||
</div>
|
||||
<form method="post">
|
||||
{% csrf_token %}
|
||||
{% for connectormethod in connectormethods %}
|
||||
{% url 'connector_detail' connectormethod.connector_method_id as url_connector_detail %}
|
||||
<div class="runner">
|
||||
<div class="row">
|
||||
{% if connectormethod.connector_method_id %}
|
||||
<div class="col-xs-12 col-sm-2">
|
||||
<div class="form-group" cols="1" rows="1">
|
||||
<div>{{ connectormethod.programming_lang }}</div>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<h2>Endpoints</h2>
|
||||
<div class="table-responsive">
|
||||
<table class="table table-striped" aria-describedby="api collection">
|
||||
<thead>
|
||||
<th scope="col">Operation Ids</th>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for connector_method in connector_method_endpoint %}
|
||||
<tr>
|
||||
<td>{{ connector_method.operation_id }}</td>
|
||||
<td>
|
||||
<form action="{% url 'delete-api-collection-endpoint' api_collection_endpoint.api_collection_id api_collection_endpoint.operation_id %}"
|
||||
method="post">
|
||||
{% csrf_token %}
|
||||
<button type="submit" class="btn btn-primary btn-red">Delete</button>
|
||||
</form>
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
<div class="col-xs-12 col-sm-4">
|
||||
<div cols="40" rows="1" class="form-control" style="overflow:scroll; padding:0px, 0px, 0px, 2px; height:50px;">{{connectormethod.method_body}}</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% if forloop.counter0 > 0 %}
|
||||
<div class="col-sm-12 col-sm-2">
|
||||
<div class="form-group">
|
||||
<button class="btn btn-primary btn-red forDelete">{% trans "Update" %}</button>
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
{% endfor %}
|
||||
</form>
|
||||
{% endblock %}
|
||||
{% block extrajs %}
|
||||
<script type="text/javascript" src="{% static 'connectormethod/js/connectormethod.js' %}"></script>
|
||||
{% endblock extrajs %}
|
||||
|
||||
@ -4,6 +4,7 @@
|
||||
|
||||
{% block content %}
|
||||
<h1>{% trans "Connector Methods" %}</h1>
|
||||
<h5><a href="https://plugins.jetbrains.com/plugin/16603-obp-push">Get OBP Push (IntelliJ Plugin)</a></h5>
|
||||
<div class="row">
|
||||
<div class="col-xs-12 col-sm-2">
|
||||
<label class="form-group">{% trans "Connector Method id" %}:</label> <br>
|
||||
@ -26,7 +27,7 @@
|
||||
<div class="row">
|
||||
<div class="col-xs-12 col-sm-2">
|
||||
<div class="form-group" cols="1" rows="1">
|
||||
<a class="api_collection_id" href="{{ url_collection_detail }}">{{ connectormethod.connector_method_id }}</a></div>
|
||||
<a class="connector_method_id" href="#">{{ connectormethod.connector_method_id }}</a></div>
|
||||
</div>
|
||||
{% if connectormethod.connector_method_id %}
|
||||
<div class="col-xs-12 col-sm-2">
|
||||
@ -35,29 +36,35 @@
|
||||
</div>
|
||||
<div class="col-xs-12 col-sm-2">
|
||||
<div class="form-group" cols="1" rows="1">
|
||||
<div>{{ connectormethod.programming_lang }}</div>
|
||||
<div>
|
||||
<select class="connector_method_programming_lang_update form-control">
|
||||
<option value="{{ connectormethod.programming_lang }}" selected="selected" hidden>{{ connectormethod.programming_lang }}</option>
|
||||
<option value="Scala">Scala</option>
|
||||
<option value="Java">Java</option>
|
||||
<option value="JavaScript">JavaScript</option>
|
||||
</select></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-xs-12 col-sm-4">
|
||||
<div cols="40" rows="1" class="form-control" style="overflow:scroll; padding:0px, 0px, 0px, 2px; height:50px;">{{connectormethod.method_body}}</div>
|
||||
<textarea cols="40" rows="1" class="form-control connector_method_body_update" style="margin: 0px -2px 0px 0px; height: 138px; width: 100%;">{{connectormethod.method_body}}</textarea>
|
||||
</div>
|
||||
{% else %}
|
||||
<div class="col-xs-12 col-sm-2">
|
||||
<div class="form-group" cols="1" rows="1">
|
||||
<input class="api_collection_name" value="Method Name">
|
||||
<input class="connector_method_name" value="Method Name">
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-xs-12 col-sm-2">
|
||||
<div class="form-group" cols="1" rows="1">
|
||||
<select class="api_collection_is_sharable form-control">
|
||||
<option value="True">Scala</option>
|
||||
<option value="False">Java</option>
|
||||
<option value="False">JavaScript</option>
|
||||
<select class="connector_method_programming_lang form-control">
|
||||
<option value="Scala">Scala</option>
|
||||
<option value="Java">Java</option>
|
||||
<option value="JavaScript">JavaScript</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-xs-12 col-sm-4">
|
||||
<textarea cols="40" rows="1" class="form-control api_collection_description">{% trans "Enter Your Method Body" %}</textarea>
|
||||
<textarea cols="40" rows="1" class="form-control connector_method_body">{% trans "Enter Your Method Body" %}</textarea>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% if forloop.counter0 == 0 %}
|
||||
@ -70,7 +77,7 @@
|
||||
{% if forloop.counter0 > 0 %}
|
||||
<div class="col-sm-12 col-sm-2">
|
||||
<div class="form-group">
|
||||
<button class="btn btn-primary btn-red forDelete">{% trans "Update" %}</button>
|
||||
<button class="btn btn-primary btn-red forUpdate">{% trans "Update" %}</button>
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
@ -82,5 +89,46 @@
|
||||
|
||||
|
||||
{% block extrajs %}
|
||||
<script type="text/javascript" src="{% static 'apicollections/js/apicollections.js' %}"></script>
|
||||
<script>console.log("Hello World")
|
||||
$(document).ready(function($) {
|
||||
$('.runner button.forSave').click(function(e) {
|
||||
e.preventDefault();
|
||||
var t = $(this);
|
||||
var runner = t.parent().parent().parent();
|
||||
var connector_method_name = $(runner).find('.connector_method_name').val();
|
||||
var connector_method_programming_lang = $(runner).find('.connector_method_programming_lang').val();
|
||||
var connector_method_body = $(runner).find('.connector_method_body').val();
|
||||
|
||||
$('.runner button.forSave').attr("disabled", "disabled");
|
||||
$('.runner button.forDelete').attr("disabled", "disabled");
|
||||
$.post('save/connectormethod', {
|
||||
'connector_method_name': connector_method_name,
|
||||
'connector_method_programming_lang': connector_method_programming_lang,
|
||||
'connector_method_body': connector_method_body,
|
||||
}, function(response) {
|
||||
location.reload();
|
||||
});
|
||||
});
|
||||
|
||||
$('.runner button.forUpdate').click(function(e) {
|
||||
e.preventDefault();
|
||||
var t = $(this);
|
||||
var runner = t.parent().parent().parent();
|
||||
var connector_method_id = $(runner).find('.connector_method_id').html();
|
||||
var connector_method_programming_lang_update = $(runner).find('.connector_method_programming_lang_update').val();
|
||||
var connector_method_body_update = $(runner).find('.connector_method_body_update').val();
|
||||
|
||||
$('.runner button.forSave').attr("disabled", "disabled");
|
||||
$('.runner button.forUpdate').attr("disabled", "disabled");
|
||||
$.post('update/connectormethod', {
|
||||
'connector_method_id': connector_method_id,
|
||||
'connector_method_programming_lang_update': connector_method_programming_lang_update,
|
||||
'connector_method_body_update': connector_method_body_update,
|
||||
}, function(response) {
|
||||
location.reload();
|
||||
});
|
||||
});
|
||||
});
|
||||
</script>
|
||||
<script type="text/javascript" src="{% static 'connectormethod/js/connectormethod.js' %}"></script>
|
||||
{% endblock extrajs %}
|
||||
|
||||
@ -5,7 +5,7 @@ URLs for config app
|
||||
|
||||
from django.conf.urls import url
|
||||
|
||||
from connectormethod.views import IndexView, connectormethod_save, DetailView
|
||||
from connectormethod.views import IndexView, connectormethod_save, connectormethod_update
|
||||
|
||||
urlpatterns = [
|
||||
url(r'^$',
|
||||
@ -13,13 +13,6 @@ urlpatterns = [
|
||||
name='connectormethod'),
|
||||
url(r'save/connectormethod', connectormethod_save,
|
||||
name='connectormethod-save'),
|
||||
url(r'^my-connectormethod-ids/(?P<connectormethod_id>[\w\@\.\+-]+)$',
|
||||
DetailView.as_view(),
|
||||
name='connector_detail'),
|
||||
url(r'^update/connectormethod', connectormethod_update,
|
||||
name='connectormethod-update')
|
||||
]
|
||||
"""url(r'^my-connectormethod-ids/(?P<connectormethod-id>[\w\@\.\+-]+)$',
|
||||
DetailView.as_view(),
|
||||
name='my-api-collection-detail'),
|
||||
url(r'^delete/api-collections/(?P<api_collection_id>[\w-]+)/api-collection-endpoint/(?P<operation_id>[\w\@\.\+-]+)$',
|
||||
DeleteCollectionEndpointView.as_view(),
|
||||
name='delete-api-collection-endpoint'),"""
|
||||
@ -6,60 +6,20 @@ Views of config app
|
||||
import json
|
||||
from django.contrib import messages
|
||||
from django.contrib.auth.mixins import LoginRequiredMixin
|
||||
from django.http import HttpResponseRedirect
|
||||
from django.http import HttpResponseRedirect, HttpResponse
|
||||
from django.views.generic import FormView
|
||||
from obp.api import API, APIError
|
||||
from django.urls import reverse, reverse_lazy
|
||||
from base.utils import exception_handle, error_once_only
|
||||
from .forms import ConnectorMethodForm, ConnectorMethodEndpointForm
|
||||
from .forms import ConnectorMethodForm
|
||||
from django.views.decorators.csrf import csrf_exempt
|
||||
|
||||
|
||||
class IndexView(LoginRequiredMixin, FormView):
|
||||
"""Index view for Connector Methods"""
|
||||
template_name = "connectormethod/index.html"
|
||||
"""Index view for config"""
|
||||
template_name = r"connectormethod/index.html"
|
||||
form_class = ConnectorMethodForm
|
||||
success_url = reverse_lazy('connectormethod-index')
|
||||
def dispatch(self, request, *args, **kwargs):
|
||||
self.api = API(request.session.get('obp'))
|
||||
return super(IndexView, self).dispatch(request, *args, **kwargs)
|
||||
|
||||
def get_form(self, *args, **kwargs):
|
||||
form = super(IndexView, self).get_form(*args, **kwargs)
|
||||
# Cannot add api in constructor: super complains about unknown kwarg
|
||||
form.api = self.api
|
||||
fields = form.fields
|
||||
try:
|
||||
fields['is_accessible'].choices = [('',_('Choose...')),(Scala, Scala), (Java, Java), (JavaScript, JavaScript)]
|
||||
except APIError as err:
|
||||
messages.error(self.request, err)
|
||||
except Exception as err:
|
||||
messages.error(self.request, err)
|
||||
|
||||
return form
|
||||
def form_valid(self, form):
|
||||
try:
|
||||
data = form.cleaned_data
|
||||
urlpath = '/management/connector-methods'
|
||||
payload ={
|
||||
"connector_method_id": data["connector_method_id"],
|
||||
"method_name": data["method_name"],
|
||||
"programming_lang": data["programming_lang"] if data["programming_lang"]!="" else "false",
|
||||
"method_body": data["method_body"],
|
||||
}
|
||||
result = self.api.post(urlpath, payload=payload)
|
||||
except APIError as err:
|
||||
messages.error(self.request, "Unknown Error")
|
||||
return super(IndexView, self).form_invalid(form)
|
||||
except Exception as err:
|
||||
messages.error(self.request, "Unknown Error")
|
||||
return super(IndexView, self).form_invalid(form)
|
||||
if 'code' in result and result['code']>=400:
|
||||
messages.error(self.request, result['message'])
|
||||
return super(IndexView, self).form_valid(form)
|
||||
msg = 'Connector Method has been created successfully!'
|
||||
messages.success(self.request, msg)
|
||||
return super(IndexView, self).form_valid(form)
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super(IndexView, self).get_context_data(**kwargs)
|
||||
@ -72,74 +32,6 @@ class IndexView(LoginRequiredMixin, FormView):
|
||||
error_once_only(self.request, response['message'])
|
||||
else:
|
||||
connectormethod=response['connector_methods']
|
||||
except APIError as err:
|
||||
messages.error(self.request, err)
|
||||
#error_once_only(self.request, Exception("OBP-API server is not running or do not response properly. "
|
||||
# "Please check OBP-API server. "
|
||||
# "Details: " + str(err)))
|
||||
except BaseException as err:
|
||||
messages.error(self.request, 'KeyError: {}'.format(err))
|
||||
#error_once_only(self.request, (Exception("Unknown Error. Details:" + str(err))))
|
||||
else:
|
||||
# set the default endpoint there, the first item will be the new endpoint.
|
||||
default_api_endpoint = {
|
||||
"connectormethod": "method_name",
|
||||
"is_sharable": True,
|
||||
"description":"Describe the purpose of the collection"
|
||||
}
|
||||
connectormethod.insert(0,json.dumps(default_api_endpoint))
|
||||
|
||||
context.update({
|
||||
'connectormethods': connectormethod
|
||||
})
|
||||
return context
|
||||
|
||||
class DetailView(LoginRequiredMixin, FormView):
|
||||
"""Index view for config"""
|
||||
template_name = "connectormethod/detail.html"
|
||||
form_class = ConnectorMethodEndpointForm
|
||||
success_url = reverse_lazy('connector_detail')
|
||||
|
||||
def form_valid(self, form):
|
||||
"""Posts api collection endpoint data to API"""
|
||||
try:
|
||||
data = form.cleaned_data
|
||||
api = API(self.request.session.get('obp'))
|
||||
connectormethod_id = super(DetailView, self).get_context_data()['view'].kwargs['connectormethod_id']
|
||||
|
||||
urlpath = '/my/api-collection-ids/{}/api-collection-endpoints'.format(api_collection_id)
|
||||
payload = {
|
||||
'operation_id': data['operation_id']
|
||||
}
|
||||
api_collection_endpoint = api.post(urlpath, payload=payload)
|
||||
except APIError as err:
|
||||
messages.error(self.request, err)
|
||||
return super(DetailView, self).form_invalid(form)
|
||||
except:
|
||||
messages.error(self.request, 'Unknown Error')
|
||||
return super(DetailView, self).form_invalid(form)
|
||||
if 'code' in api_collection_endpoint and api_collection_endpoint['code']>=400:
|
||||
messages.error(self.request, api_collection_endpoint['message'])
|
||||
return super(DetailView, self).form_invalid(form)
|
||||
else:
|
||||
msg = 'Operation Id {} has been added.'.format(data['operation_id'])
|
||||
messages.success(self.request, msg)
|
||||
self.success_url = self.request.path
|
||||
return super(DetailView, self).form_valid(form)
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super(DetailView, self).get_context_data(**kwargs)
|
||||
connectormethod_id = context['view'].kwargs['connectormethod_id']
|
||||
|
||||
api = API(self.request.session.get('obp'))
|
||||
urlpath = '/my/api-collection-ids/{}/api-collection-endpoints'.format(api_collection_id)
|
||||
api_collection_endpoints =[]
|
||||
try:
|
||||
response = api.get(urlpath)
|
||||
if 'code' in response and response['code'] >= 400:
|
||||
error_once_only(self.request, response['message'])
|
||||
else:
|
||||
api_collection_endpoints=response['api_collection_endpoints']
|
||||
except APIError as err:
|
||||
error_once_only(self.request, Exception("OBP-API server is not running or do not response properly. "
|
||||
"Please check OBP-API server. "
|
||||
@ -147,43 +39,28 @@ class DetailView(LoginRequiredMixin, FormView):
|
||||
except BaseException as err:
|
||||
error_once_only(self.request, (Exception("Unknown Error. Details:" + str(err))))
|
||||
else:
|
||||
# set the default endpoint there, the first item will be the new endpoint.
|
||||
default_api_endpoint = {
|
||||
"api_collection_name": "Customer",
|
||||
"is_sharable": "True",
|
||||
"description":"Describe the purpose of the collection"
|
||||
}
|
||||
connectormethod.insert(0,json.dumps(default_api_endpoint))
|
||||
|
||||
context.update({
|
||||
'api_collection_endpoints': api_collection_endpoints,
|
||||
'api_collection_id': api_collection_id
|
||||
'connectormethods': connectormethod
|
||||
})
|
||||
return context
|
||||
|
||||
class DeleteCollectionEndpointView(LoginRequiredMixin, FormView):
|
||||
"""View to delete an api collection endpoint"""
|
||||
def post(self, request, *args, **kwargs):
|
||||
"""Deletes api collection endpoint from API"""
|
||||
api = API(self.request.session.get('obp'))
|
||||
try:
|
||||
urlpath = '/my/api-collections-ids/{}/api-collection-endpoints/{}'\
|
||||
.format(kwargs['api_collection_id'],kwargs['operation_id'])
|
||||
result = api.delete(urlpath)
|
||||
if result is not None and 'code' in result and result['code']>=400:
|
||||
messages.error(request, result['message'])
|
||||
else:
|
||||
msg = 'Operation Id {} has been deleted.'.format(kwargs['operation_id'])
|
||||
messages.success(request, msg)
|
||||
except APIError as err:
|
||||
messages.error(request, err)
|
||||
except:
|
||||
messages.error(self.request, 'Unknown Error')
|
||||
|
||||
redirect_url = reverse('my-api-collection-detail',kwargs={"api_collection_id":kwargs['api_collection_id']})
|
||||
return HttpResponseRedirect(redirect_url)
|
||||
|
||||
@exception_handle
|
||||
@csrf_exempt
|
||||
def connectormethod_save(request):
|
||||
api = API(request.session.get('obp'))
|
||||
urlpath = '/my/connectormethod'
|
||||
urlpath = '/management/connector-methods'
|
||||
payload = {
|
||||
'api_collection_name': request.POST.get('api_collection_name').strip(),
|
||||
'is_sharable': bool(request.POST.get('api_collection_is_sharable')),
|
||||
'description': request.POST.get('api_collection_description').strip()
|
||||
'method_name': request.POST.get('connector_method_name').strip(),
|
||||
'programming_lang': request.POST.get('connector_method_programming_lang'),
|
||||
'method_body': request.POST.get('connector_method_body').strip()
|
||||
}
|
||||
result = api.post(urlpath, payload = payload)
|
||||
return result
|
||||
@ -191,10 +68,14 @@ def connectormethod_save(request):
|
||||
|
||||
@exception_handle
|
||||
@csrf_exempt
|
||||
def apicollections_delete(request):
|
||||
api_collection_id = request.POST.get('api_collection_id').strip()
|
||||
|
||||
def connectormethod_update(request):
|
||||
connector_method_id = request.POST.get('connector_method_id').strip()
|
||||
urlpath = '/management/connector-methods/{}'.format(connector_method_id)
|
||||
api = API(request.session.get('obp'))
|
||||
urlpath = '/my/api-collections/{}'.format(api_collection_id)
|
||||
result = api.delete(urlpath)
|
||||
payload = {
|
||||
'programming_lang': request.POST.get('connector_method_programming_lang_update'),
|
||||
'method_body': request.POST.get('connector_method_body_update').strip()
|
||||
}
|
||||
result = HttpResponse(content_type = 'application/json')
|
||||
result = api.put(urlpath, payload=payload)
|
||||
return result
|
||||
|
||||
@ -53,6 +53,7 @@ $(document).ready(function($) {
|
||||
$.post('/webui/save/method', {
|
||||
'web_ui_props_name': web_ui_props_name,
|
||||
'web_ui_props_value': web_ui_props_value,
|
||||
alert(web_ui_props_value, "Value of webui")
|
||||
}, function (response) {
|
||||
location.reload();
|
||||
});
|
||||
|
||||
@ -56,6 +56,90 @@
|
||||
{% endblock %}
|
||||
|
||||
{% block extrajs %}
|
||||
<script>
|
||||
$(document).ready(function($) {
|
||||
$('.runner button.forSave').click(function(e) {
|
||||
e.preventDefault();
|
||||
var t = $(this);
|
||||
var runner = t.parent().parent().parent();
|
||||
|
||||
var web_ui_props_name = $(runner).find('.web_ui_props_name').text();
|
||||
var web_ui_props_value = $(runner).find('.web_ui_props_value').val();
|
||||
|
||||
var webui = $('#webui');
|
||||
if(web_ui_props_value.trim() === '') {
|
||||
$('<div class="alert alert-dismissible alert-danger dynamic-message" role="alert">\n' +
|
||||
'<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>\n' +
|
||||
'Web UI Props Value should not be empty!' +
|
||||
'</div>'
|
||||
).insertBefore(webui);
|
||||
return;
|
||||
}
|
||||
$('.runner button.forSave').attr("disabled","disabled");
|
||||
$('.runner button.forDelete').attr("disabled","disabled");
|
||||
$.post('/webui/save/method', {
|
||||
'web_ui_props_name': web_ui_props_name,
|
||||
'web_ui_props_value': web_ui_props_value,
|
||||
},
|
||||
alert("Value from Save button", web_ui_props_value)
|
||||
function (response) {
|
||||
location.reload();
|
||||
});
|
||||
});
|
||||
|
||||
$('.runner button.forDelete').click(function(e) {
|
||||
e.preventDefault();
|
||||
var t = $(this);
|
||||
var runner = t.parent().parent().parent();
|
||||
var web_ui_props_name = $(runner).find('.web_ui_props_name').text();
|
||||
var textArea = runner.find('.web_ui_props_value');
|
||||
var props_id = $(runner).find('.web_ui_props_id');
|
||||
var web_ui_props_id = props_id.val();
|
||||
var webui = $('#webui');
|
||||
/*
|
||||
t.attr("disabled","disabled").toggleClass("disabled");
|
||||
t.next().attr("disabled","disabled").toggleClass("disabled");
|
||||
|
||||
$.ajax({
|
||||
type: 'POST',
|
||||
url: '/webui/delete/method',
|
||||
data: {'web_ui_props_id': web_ui_props_id,
|
||||
'web_ui_props_name': web_ui_props_name,
|
||||
'csrfmiddlewaretoken': window.CSRF
|
||||
},
|
||||
success: function (response) {
|
||||
t.removeAttr("disabled").toggleClass("disabled");
|
||||
t.next().removeAttr("disabled").toggleClass("disabled");
|
||||
textArea.val(response['default_value']);
|
||||
props_id.val('default');
|
||||
$('<div class="alert alert-dismissible alert-success dynamic-message" role="alert">\n' +
|
||||
'<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>Success!</div>'
|
||||
).insertBefore(webui);
|
||||
},
|
||||
error: function (response) {
|
||||
var errors = response.responseJSON ? response.responseJSON['errors'] : [response.responseText];
|
||||
errors.forEach(function(e){
|
||||
$('<div class="alert alert-dismissible alert-danger dynamic-message" role="alert">\n' +
|
||||
'<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>\n' +
|
||||
e +
|
||||
'</div>'
|
||||
).insertBefore(webui);
|
||||
});
|
||||
t.removeAttr("disabled").toggleClass("disabled");
|
||||
t.next().removeAttr("disabled").toggleClass("disabled")
|
||||
}
|
||||
});
|
||||
*/
|
||||
$('.runner button.forSave').attr("disabled","disabled");
|
||||
$('.runner button.forDelete').attr("disabled","disabled");
|
||||
$.post('/webui/delete/method', {
|
||||
'web_ui_props_id': web_ui_props_id
|
||||
}, function (response) {
|
||||
location.reload();
|
||||
});
|
||||
});
|
||||
});
|
||||
</script>
|
||||
<script type="text/javascript" src="{% static 'webui/js/webui.js' %}"></script>
|
||||
|
||||
{% endblock extrajs %}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user