Skip to content

Commit 56c90fe

Browse files
committed
Merge pull request #660 from apinf/feature/unify-api-forms
Feature/unify api forms
2 parents 7f7b755 + aeedab2 commit 56c90fe

File tree

9 files changed

+104
-104
lines changed

9 files changed

+104
-104
lines changed

client/views/api_backends/apiBackends.js

Lines changed: 0 additions & 14 deletions
This file was deleted.
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
Template.apiBackendForm.helpers({
2+
'formType': function () {
3+
// Get reference to current Router
4+
var router = Router.current();
5+
6+
// Check for '_id' parameter in route
7+
if (router.params._id) {
8+
// Updating existing API Backend
9+
return 'update';
10+
} else {
11+
// Editing new API Backend
12+
return 'insert';
13+
}
14+
},
15+
'apiBackend': function () {
16+
// Get the current Router
17+
var router = Router.current();
18+
19+
// Check router for _id parameter
20+
if (router.params._id) {
21+
// Get the API Backend ID
22+
var apiBackendId = router.params._id;
23+
24+
// Get the API Backend
25+
var apiBackend = ApiBackends.findOne(apiBackendId);
26+
27+
return apiBackend;
28+
}
29+
},
30+
'editMode': function () {
31+
// Get the current Router
32+
var router = Router.current();
33+
34+
// Check router for _id parameter
35+
if (router.params._id) {
36+
return true;
37+
} else {
38+
return false;
39+
}
40+
}
41+
});
42+
43+
Template.apiBackendForm.created = function () {
44+
// Get reference to current Router
45+
var router = Router.current();
46+
47+
// Get the API Backend ID from Router
48+
var apiBackendId = router.params._id;
49+
50+
if (apiBackendId) {
51+
// Subscription to apiBackends collection
52+
this.subscribe('apiBackend', apiBackendId);
53+
}
54+
};
55+
56+
57+
Template.apiBackendForm.rendered = function () {
58+
// Hides blocks on template load
59+
$('#global-request-block, #sub-url-block, #advanced-block, #advanced-rewriting-block, #documentation-block').collapse({
60+
hide: true
61+
});
62+
63+
// Toggles icon on hide and show events
64+
$('#global-request-block, #sub-url-block, #advanced-block, #advanced-rewriting-block, #documentation-block').on('shown.bs.collapse', function () {
65+
$(this).prev().find(".fa").removeClass("fa-chevron-right").addClass("fa-chevron-down");
66+
});
67+
$('#global-request-block, #sub-url-block, #advanced-block, #advanced-rewriting-block, #documentation-block').on('hidden.bs.collapse', function () {
68+
$(this).prev().find(".fa").removeClass("fa-chevron-down").addClass("fa-chevron-right");
69+
});
70+
}

client/views/api_backends/api_backends.html renamed to client/views/api_backends/api_backend_form/api_backend_form.html

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1-
<template name="apiBackends">
1+
<template name="apiBackendForm">
22
<div class="api-backends-content">
3-
<h1>{{_ "apiBackends-Title"}}</h1>
4-
{{#autoForm collection="ApiBackends" doc=this id="apiBackends" type="insert"}}
3+
{{#unless editMode}}
4+
<h1>{{_ "apiBackends-Add-API-Title"}}</h1>
5+
{{else}}
6+
<h1>{{_ "apiBackends-Edit-API-Title"}}</h1>
7+
{{/unless}}
8+
{{#autoForm collection="ApiBackends" doc=apiBackend id="apiBackendForm" type=formType}}
59
{{>showHelp 'api_name'}}
610
{{> afQuickField name='name'}}
711
<span class="help-block">{{_ "apiBackends-Title-Help"}}</span>

client/views/api_backends/api_backends.less renamed to client/views/api_backends/api_backend_form/api_backend_form.less

File renamed without changes.

client/views/api_backends/autoform.js renamed to client/views/api_backends/api_backend_form/autoform.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
AutoForm.hooks({
2-
apiBackends: {
2+
apiBackendForm: {
33
beginSubmit: function () {
44
// Disable form elements while submitting form
55
$('[data-schema-key], button').attr("disabled", "disabled");
@@ -57,7 +57,10 @@ AutoForm.hooks({
5757
});
5858
}
5959
},
60-
onSuccess: function (formType, apiBackendId) {
60+
onSuccess: function (formType) {
61+
// Get API Backend ID from form
62+
var apiBackendId = this.docId;
63+
6164
//Redirect to the just created API Backend page
6265
Router.go('viewApiBackend', {_id: apiBackendId});
6366
}

client/views/api_backends/edit_api_backend/edit_api_backend.html

Lines changed: 0 additions & 60 deletions
This file was deleted.

client/views/api_backends/view_api_backend/view_api_backend.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ Template.viewApiBackend.created = function() {
5353

5454
// updates layout with success status
5555
$('#apiState').addClass('alert-success').html("API is operating normally.");
56-
console.log(status.responseContext)
5756

5857
}else{
5958

i18n/en.i18n.json

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
"home-MainTitle": "APINF - API Management Platform",
2828
"home-SecondaryTitle": "Building a bridge between API owners and users.",
2929
"Dashboard": "Go to dashboard",
30-
30+
3131
/*Body*/
3232
"feature-Section-Heading1": "Are you an API user?",
3333
"feature-Title1": "Discover APIs",
@@ -113,7 +113,8 @@
113113
"view-ApiBackend-ExportYaml": "Export .yaml",
114114

115115
/*Api Backends*/
116-
"apiBackends-Title": "Add API",
116+
"apiBackends-Add-API-Title": "Add API",
117+
"apiBackends-Edit-API-Title": "Edit API",
117118
"apiBackends-Title-Help": "API's name",
118119
"apiBackends-Backend-Title": "Backend",
119120
"apiBackends-Backend-Help": "Define the server where the API is hosted. Multiple servers can be defined to perform load balancing.",
@@ -154,11 +155,11 @@
154155
/*Charts*/
155156
/*Error messages*/
156157
"esData-notFound": "There are no API usage statistics available.",
157-
158+
158159
/*Bar chart*/
159160
"overviewChart-Title": "Overview chart",
160161
"moveChart-Title": "Chart",
161-
162+
162163
/*Filter*/
163164
"filterData-Title": "Filter",
164165
"filterData-Month": "Month:",
@@ -179,10 +180,10 @@
179180
"filterData-SelectedOf": "selected out of",
180181
"filterData-Records": "records",
181182
"filterData-Reset": "Reset All",
182-
183+
183184
/*Map*/
184185
"map-Title": "Map",
185-
186+
186187
/*Data Table*/
187188
"dataTable-Title": "Table",
188189
"dataTable-TimeStamp": "Time stamp",

lib/router/main.js

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,24 @@
1+
Router.route("/api/new", function () {
2+
this.layout("masterLayout");
3+
this.render("apiBackendForm");
4+
}, {
5+
name: "apiBackends"
6+
});
7+
8+
Router.route("/api/:_id/edit", function () {
9+
this.render("apiBackendForm");
10+
this.layout("masterLayout");
11+
}, {
12+
name: "editApiBackend"
13+
});
14+
15+
116
Router.map(function() {
217
this.route("home", {
318
path: "/",
419
layoutTemplate: "homeLayout"
520
});
621

7-
this.route("apiBackends", {
8-
path: "/apibackends",
9-
layoutTemplate: "masterLayout"
10-
});
11-
1222
this.route("catalogue", {
1323
path: "/catalogue",
1424
layoutTemplate: "masterLayout"
@@ -56,19 +66,6 @@ Router.map(function() {
5666
render: "feedbacklist"
5767
});
5868

59-
this.route("editApiBackend", {
60-
path: "/api/:_id/edit",
61-
waitOn: function() {
62-
return this.subscribe('apiBackend', this.params._id);
63-
},
64-
data: function () {
65-
var apiBackend = ApiBackends.findOne({_id: this.params._id});
66-
return { apiBackend: apiBackend }
67-
},
68-
layoutTemplate: "masterLayout",
69-
render: "editApiBackend"
70-
});
71-
7269
this.route("viewApiBackend", {
7370
path: "/api/:_id/",
7471
name: "viewApiBackend",

0 commit comments

Comments
 (0)