From 29be9d5efc40faba7b20129acdab7a825e11f17f Mon Sep 17 00:00:00 2001 From: Reena-cell Date: Mon, 15 Aug 2022 11:02:46 +0200 Subject: [PATCH] /feature add Connector Method --- apimanager/atmdetail/views.py | 2 - apimanager/base/templates/base.html | 2 +- apimanager/connectormethod/forms.py | 62 +------ .../connectormethod/js/connectormethod.js | 54 +++--- .../templates/connectormethod/detail.html | 74 ++++---- .../templates/connectormethod/index.html | 70 +++++-- apimanager/connectormethod/urls.py | 13 +- apimanager/connectormethod/views.py | 171 +++--------------- apimanager/webui/static/webui/js/webui.js | 1 + apimanager/webui/templates/webui/index.html | 84 +++++++++ 10 files changed, 245 insertions(+), 288 deletions(-) diff --git a/apimanager/atmdetail/views.py b/apimanager/atmdetail/views.py index 221edf1..a91db9a 100644 --- a/apimanager/atmdetail/views.py +++ b/apimanager/atmdetail/views.py @@ -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) diff --git a/apimanager/base/templates/base.html b/apimanager/base/templates/base.html index 65742e8..8a1c591 100644 --- a/apimanager/base/templates/base.html +++ b/apimanager/base/templates/base.html @@ -97,7 +97,7 @@ {% trans "Config" %} {% trans "Webui Props" %} {% trans "Method Routings" %} - {% trans "Connector Method" %} + {% trans "Connector Methods" %} {% trans "Dynamic Endpoints" %} {% trans "My API Collections" %} diff --git a/apimanager/connectormethod/forms.py b/apimanager/connectormethod/forms.py index eb99744..3c7366d 100644 --- a/apimanager/connectormethod/forms.py +++ b/apimanager/connectormethod/forms.py @@ -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 - ) \ No newline at end of file diff --git a/apimanager/connectormethod/static/connectormethod/js/connectormethod.js b/apimanager/connectormethod/static/connectormethod/js/connectormethod.js index d0d9d94..81990f2 100644 --- a/apimanager/connectormethod/static/connectormethod/js/connectormethod.js +++ b/apimanager/connectormethod/static/connectormethod/js/connectormethod.js @@ -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(); + }); }); -}); +}); \ No newline at end of file diff --git a/apimanager/connectormethod/templates/connectormethod/detail.html b/apimanager/connectormethod/templates/connectormethod/detail.html index c461dbb..49563f5 100644 --- a/apimanager/connectormethod/templates/connectormethod/detail.html +++ b/apimanager/connectormethod/templates/connectormethod/detail.html @@ -1,43 +1,45 @@ {% extends 'base.html' %} -{% load static %} +{% load static i18n %} +{% block page_title %}{{ block.super }} / Connector Methods{% endblock page_title %} + {% block content %} -
-

Add Endpoint to API Collection

-
- {% csrf_token %} -
-
-
- {{ form.operation_id.label_tag}} - {{ form.operation_id }} -
- - +

{% trans "Connector Methods" %}

+
+
+
+
+
+
+
+
+ + {% csrf_token %} + {% for connectormethod in connectormethods %} + {% url 'connector_detail' connectormethod.connector_method_id as url_connector_detail %} +
+
+ {% if connectormethod.connector_method_id %} +
+
+
{{ connectormethod.programming_lang }}
- - -

Endpoints

-
- - - - - - {% for connector_method in connector_method_endpoint %} - - - - - {% endfor %} - -
Operation Ids
{{ connector_method.operation_id }} -
- {% csrf_token %} - -
-
+
+
{{connectormethod.method_body}}
+
+ {% endif %} + {% if forloop.counter0 > 0 %} +
+
+ +
+
+ {% endif %}
+ {% endfor %} + {% endblock %} +{% block extrajs %} + +{% endblock extrajs %} diff --git a/apimanager/connectormethod/templates/connectormethod/index.html b/apimanager/connectormethod/templates/connectormethod/index.html index 552b4b3..d4ca245 100644 --- a/apimanager/connectormethod/templates/connectormethod/index.html +++ b/apimanager/connectormethod/templates/connectormethod/index.html @@ -4,6 +4,7 @@ {% block content %}

{% trans "Connector Methods" %}

+
Get OBP Push (IntelliJ Plugin)

@@ -26,7 +27,7 @@ {% if connectormethod.connector_method_id %}
@@ -35,29 +36,35 @@
-
{{ connectormethod.programming_lang }}
+
+
-
{{connectormethod.method_body}}
+
{% else %}
- +
- + + +
- +
{% endif %} {% if forloop.counter0 == 0 %} @@ -70,7 +77,7 @@ {% if forloop.counter0 > 0 %}
- +
{% endif %} @@ -82,5 +89,46 @@ {% block extrajs %} - + + {% endblock extrajs %} diff --git a/apimanager/connectormethod/urls.py b/apimanager/connectormethod/urls.py index 51a7737..66d432f 100644 --- a/apimanager/connectormethod/urls.py +++ b/apimanager/connectormethod/urls.py @@ -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[\w\@\.\+-]+)$', - DetailView.as_view(), - name='connector_detail'), + url(r'^update/connectormethod', connectormethod_update, + name='connectormethod-update') ] -"""url(r'^my-connectormethod-ids/(?P[\w\@\.\+-]+)$', - DetailView.as_view(), - name='my-api-collection-detail'), - url(r'^delete/api-collections/(?P[\w-]+)/api-collection-endpoint/(?P[\w\@\.\+-]+)$', - DeleteCollectionEndpointView.as_view(), - name='delete-api-collection-endpoint'),""" \ No newline at end of file diff --git a/apimanager/connectormethod/views.py b/apimanager/connectormethod/views.py index 9e44559..fd69fd2 100644 --- a/apimanager/connectormethod/views.py +++ b/apimanager/connectormethod/views.py @@ -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 diff --git a/apimanager/webui/static/webui/js/webui.js b/apimanager/webui/static/webui/js/webui.js index b3e1f25..0a3374a 100644 --- a/apimanager/webui/static/webui/js/webui.js +++ b/apimanager/webui/static/webui/js/webui.js @@ -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(); }); diff --git a/apimanager/webui/templates/webui/index.html b/apimanager/webui/templates/webui/index.html index 5f0723e..4f3bf5f 100644 --- a/apimanager/webui/templates/webui/index.html +++ b/apimanager/webui/templates/webui/index.html @@ -56,6 +56,90 @@ {% endblock %} {% block extrajs %} + {% endblock extrajs %}