mirror of
https://github.com/OpenBankProject/API-Manager.git
synced 2026-02-06 13:16:52 +00:00
feature/added the apiCollection menu
This commit is contained in:
parent
a13b11ca55
commit
72b8557e88
0
apimanager/apicollections/__init__.py
Normal file
0
apimanager/apicollections/__init__.py
Normal file
10
apimanager/apicollections/apps.py
Normal file
10
apimanager/apicollections/apps.py
Normal file
@ -0,0 +1,10 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
App config for config app
|
||||
"""
|
||||
|
||||
from django.apps import AppConfig
|
||||
|
||||
class ApiCollectionsConfig(AppConfig):
|
||||
"""Config for apicollections"""
|
||||
name = 'apicollections'
|
||||
13
apimanager/apicollections/forms.py
Normal file
13
apimanager/apicollections/forms.py
Normal file
@ -0,0 +1,13 @@
|
||||
from django import forms
|
||||
|
||||
|
||||
class ApiCollectionsForm(forms.Form):
|
||||
api_collections_body = forms.CharField(
|
||||
label='API Collections Body',
|
||||
widget=forms.Textarea(
|
||||
attrs={
|
||||
'class': 'form-control',
|
||||
}
|
||||
),
|
||||
required=False
|
||||
)
|
||||
@ -0,0 +1,30 @@
|
||||
$(document).ready(function($) {
|
||||
$('.runner button.forSave').click(function(e) {
|
||||
e.preventDefault();
|
||||
var t = $(this);
|
||||
var runner = t.parent().parent().parent();
|
||||
var api_collection_body = $(runner).find('.api-collection-body').val();
|
||||
|
||||
$('.runner button.forSave').attr("disabled","disabled");
|
||||
$('.runner button.forDelete').attr("disabled","disabled");
|
||||
$.post('save/apicollection', {
|
||||
'api-collection-body': api_collection_body,
|
||||
}, function (response) {
|
||||
location.reload();
|
||||
});
|
||||
});
|
||||
|
||||
$('.runner button.forDelete').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();
|
||||
});
|
||||
});
|
||||
});
|
||||
@ -0,0 +1,60 @@
|
||||
{% extends 'base.html' %}
|
||||
{% load static %}
|
||||
{% block page_title %}{{ block.super }} / API Collections{% endblock page_title %}
|
||||
|
||||
{% block content %}
|
||||
<h1>API Collections</h1>
|
||||
<div class="row">
|
||||
<div class="col-xs-12 col-sm-2">
|
||||
<label class="form-group">API COLLECTION ID:</label> <br>
|
||||
</div>
|
||||
<div class="col-xs-12 col-sm-2">
|
||||
<label class="form-group">COLLECTION Name:</label> <br>
|
||||
</div>
|
||||
<div class="col-xs-12 col-sm-8">
|
||||
<label class="form-group">Details:</label> <br>
|
||||
</div>
|
||||
</div>
|
||||
<form method="post">
|
||||
{% csrf_token %}
|
||||
{% for api_collection in api_collections %}
|
||||
<div class="runner">
|
||||
<div class="row">
|
||||
<div class="col-xs-12 col-sm-2">
|
||||
<div class="form-group" cols="1" rows="1">
|
||||
<div class="api_collection_id">{{ api_collection.api_collection_id }}</div></div>
|
||||
</div>
|
||||
<div class="col-xs-12 col-sm-2">
|
||||
<div class="form-group" cols="1" rows="1">
|
||||
<div class="api_collection_name">{{ api_collection.api_collection_name }}</div></div>
|
||||
</div>
|
||||
<div class="col-xs-12 col-sm-6">
|
||||
<textarea cols="40" rows="1" class="form-control api-collection-body">{{api_collection}}</textarea>
|
||||
</div>
|
||||
{% if forloop.counter0 == 0 %}
|
||||
<div class="col-sm-12 col-sm-2">
|
||||
<div class="form-group">
|
||||
<button class="btn btn-primary btn-green forSave">Create </button><span style="display: none;margin-left: 5px;background-color:#00cc00">saved.</span>
|
||||
</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">Delete</button>
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
<div class="col-sm-12 col-sm-12">
|
||||
<div id="jsoneditor{{forloop.counter0}}" style="display: none" ></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endfor %}
|
||||
</form>
|
||||
{% endblock %}
|
||||
|
||||
|
||||
{% block extrajs %}
|
||||
<script type="text/javascript" src="{% static 'apicollections/js/apicollections.js' %}"></script>
|
||||
{% endblock extrajs %}
|
||||
18
apimanager/apicollections/urls.py
Normal file
18
apimanager/apicollections/urls.py
Normal file
@ -0,0 +1,18 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
URLs for config app
|
||||
"""
|
||||
|
||||
from django.conf.urls import url
|
||||
|
||||
from apicollections.views import IndexView, apicollections_save, apicollections_delete
|
||||
|
||||
urlpatterns = [
|
||||
url(r'^$',
|
||||
IndexView.as_view(),
|
||||
name='apicollections-index'),
|
||||
url(r'save/apicollection', apicollections_save,
|
||||
name='apicollection-save'),
|
||||
url(r'delete/apicollection', apicollections_delete,
|
||||
name='apicollection-delete')
|
||||
]
|
||||
71
apimanager/apicollections/views.py
Normal file
71
apimanager/apicollections/views.py
Normal file
@ -0,0 +1,71 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
Views of config app
|
||||
"""
|
||||
|
||||
import json
|
||||
from django.contrib.auth.mixins import LoginRequiredMixin
|
||||
from django.views.generic import FormView
|
||||
from obp.api import API, APIError
|
||||
from base.utils import exception_handle, error_once_only
|
||||
from .forms import ApiCollectionsForm
|
||||
from django.urls import reverse_lazy
|
||||
from django.views.decorators.csrf import csrf_exempt
|
||||
|
||||
|
||||
class IndexView(LoginRequiredMixin, FormView):
|
||||
"""Index view for config"""
|
||||
template_name = "apicollections/index.html"
|
||||
form_class = ApiCollectionsForm
|
||||
success_url = reverse_lazy('apicollections-index')
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super(IndexView, self).get_context_data(**kwargs)
|
||||
api = API(self.request.session.get('obp'))
|
||||
urlpath = '/my/api-collections'
|
||||
api_collections =[]
|
||||
try:
|
||||
response = api.get(urlpath)
|
||||
if 'code' in response and response['code'] >= 400:
|
||||
error_once_only(self.request, response['message'])
|
||||
else:
|
||||
api_collections=response['api_collections']
|
||||
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. "
|
||||
"Details: " + str(err)))
|
||||
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": "Testing",
|
||||
"is_sharable": True,
|
||||
"description":"This is for testing"
|
||||
}
|
||||
api_collections.insert(0,json.dumps(default_api_endpoint))
|
||||
|
||||
context.update({
|
||||
'api_collections': api_collections
|
||||
})
|
||||
return context
|
||||
|
||||
@exception_handle
|
||||
@csrf_exempt
|
||||
def apicollections_save(request):
|
||||
api_collection_body = request.POST.get('api-collection-body')
|
||||
api = API(request.session.get('obp'))
|
||||
urlpath = '/my/api-collections'
|
||||
result = api.post(urlpath, payload =json.loads( api_collection_body))
|
||||
return result
|
||||
|
||||
|
||||
@exception_handle
|
||||
@csrf_exempt
|
||||
def apicollections_delete(request):
|
||||
api_collection_id = request.POST.get('api_collection_id')
|
||||
|
||||
api = API(request.session.get('obp'))
|
||||
urlpath = '/my/api-collections/{}'.format(api_collection_id)
|
||||
result = api.delete(urlpath)
|
||||
return result
|
||||
@ -58,7 +58,8 @@ INSTALLED_APPS = [
|
||||
'config',
|
||||
'webui',
|
||||
'methodrouting',
|
||||
'dynamicendpoints'
|
||||
'dynamicendpoints',
|
||||
'apicollections'
|
||||
]
|
||||
|
||||
MIDDLEWARE = [
|
||||
|
||||
@ -40,4 +40,5 @@ urlpatterns = [
|
||||
url(r'^webui/', include('webui.urls')),
|
||||
url(r'^methodrouting/', include('methodrouting.urls')),
|
||||
url(r'^dynamicendpoints/', include('dynamicendpoints.urls')),
|
||||
url(r'^apicollections/', include('apicollections.urls')),
|
||||
]
|
||||
|
||||
@ -70,13 +70,15 @@
|
||||
{% url "webui-index" as webui_props_index_url %}
|
||||
{% url "methodrouting-index" as methodrouting_index_url %}
|
||||
{% url "dynamicendpoints-index" as dynamic_endpoints_index_url %}
|
||||
{% url "apicollections-index" as api_collections_index_url %}
|
||||
<li class="dropdown{% if config_index_url in request.path %} active{% endif %}">
|
||||
<a href="#" data-toggle="dropdown" class="dropdown-toggle">Configurations</a>
|
||||
<ul class="dropdown-menu">
|
||||
<li{% if config_index_url in request.path %} class="active"{% endif %}><a href="{{ config_index_url }}">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 }}">Webui Props</a></li><hr class="dropdown-hr">
|
||||
<li{% if methodrouting_index_url in request.path %} class="active"{% endif %}><a href="{{ methodrouting_index_url }}">Method Routings</a></li><hr class="dropdown-hr">
|
||||
<li{% if dynamic_endpoints_index_url in request.path %} class="active"{% endif %}><a href="{{ dynamic_endpoints_index_url }}">Dynamic Endpoints</a></li>
|
||||
<li{% if dynamic_endpoints_index_url in request.path %} class="active"{% endif %}><a href="{{ dynamic_endpoints_index_url }}">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 }}">My Api Collections</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user