Skip to content

Commit 0b1ef77

Browse files
authored
Merge pull request #1497 from apinf/feature/api-settings-export-fixes
feature/api-settings-export-fixes
2 parents 95d0127 + 8e810a6 commit 0b1ef77

File tree

23 files changed

+310
-184
lines changed

23 files changed

+310
-184
lines changed

apis/client/export/export.html

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,36 @@
1-
<template name="viewApiBackendExport">
1+
<template name="apiExport">
22
<div class="panel panel-default">
33
<div class="panel-heading">
44
<h2 class="panel-title">
5-
{{_ "view_ApiBackend_Export_Title"}}
5+
{{_ "apiExport_title"}}
66
</h2>
77
</div>
88
<div class="panel-body">
9-
<a class="btn btn-lg btn-success" id="exportJSONConfig">{{_ "view_ApiBackend_ExportJson"}}</a>
10-
<a class="btn btn-lg btn-success" id="exportYAMLConfig">{{_ "view_ApiBackend_ExportYaml"}}</a>
9+
<h3>
10+
{{_ "apiExport_api_title"}}
11+
</h3>
12+
<p>
13+
{{_ "apiExport_api_description"}}
14+
</p>
15+
<a class="btn btn-success" id="exportJSONConfig">
16+
{{_ "apiExport_json_button"}}
17+
</a>
18+
<a class="btn btn-success" id="exportYAMLConfig">
19+
{{_ "apiExport_yaml_button"}}
20+
</a>
21+
<hr class="panel-hr" />
22+
<h3>
23+
{{_ "apiExport_proxy_title"}}
24+
</h3>
25+
<p>
26+
{{_ "apiExport_proxy_description"}}
27+
</p>
28+
<a class="btn btn-success" id="exportJSONProxyConfig">
29+
{{_ "apiExport_json_button"}}
30+
</a>
31+
<a class="btn btn-success" id="exportYAMLProxyConfig">
32+
{{_ "apiExport_yaml_button"}}
33+
</a>
1134
</div>
1235
</div>
1336
</template>

apis/client/export/export.js

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,20 @@
1+
import { Template } from 'meteor/templating';
2+
import { ProxyBackends } from '/proxy_backends/collection';
3+
14
import jsyaml from 'js-yaml';
25

3-
Template.viewApiBackendExport.events({
6+
Template.apiExport.onCreated(function () {
7+
// Get reference to template instance
8+
const instance = this;
9+
10+
// Get the API Backend ID from data context
11+
const apiId = instance.data.api._id;
12+
13+
// Subscribe to proxy settings for this API
14+
instance.subscribe('apiProxySettings', apiId);
15+
});
16+
17+
Template.apiExport.events({
418
'click #exportJSONConfig': function (event, instance) {
519
// Get API Backend from database collection
620
const api = instance.data.api;
@@ -24,6 +38,38 @@ Template.viewApiBackendExport.events({
2438
// creates file object with content type of YAML
2539
const file = new Blob([yaml], { type: 'application/x-yaml;charset=utf-8' });
2640

41+
// forces "save As" function allow user download file
42+
saveAs(file, 'apiConfig.yaml');
43+
},
44+
'click #exportJSONProxyConfig': function (event, instance) {
45+
// Get the API Backend ID from data context
46+
const apiId = instance.data.api._id;
47+
48+
// Find proxy backends by API id
49+
const proxy = ProxyBackends.findOne({ apiId });
50+
51+
// converts JSON object to JSON string and adds indentation
52+
const json = JSON.stringify(proxy, null, '\t');
53+
54+
// creates file object with content type of JSON
55+
const file = new Blob([json], { type: 'application/json;charset=utf-8' });
56+
57+
// forces "save As" function allow user download file
58+
saveAs(file, 'apiProxyConfig.json');
59+
},
60+
'click #exportYAMLProxyConfig': function (event, instance) {
61+
// Get the API Backend ID from data context
62+
const apiId = instance.data.api._id;
63+
64+
// Find proxy backends by API id
65+
const proxy = ProxyBackends.findOne({ apiId });
66+
67+
// converts from json to yaml
68+
const yaml = jsyaml.safeDump(proxy);
69+
70+
// creates file object with content type of YAML
71+
const file = new Blob([yaml], { type: 'application/x-yaml;charset=utf-8' });
72+
2773
// forces "save As" function allow user download file
2874
saveAs(file, 'apiConfig.yaml');
2975
},

apis/client/lib/router.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ Router.route('/api/:_id/', function () {
2222
// Ensure current user is authorized to view backend
2323
Meteor.call('currentUserCanViewApi', apiBackendId, function (error, userIsAuthorized) {
2424
if (userIsAuthorized) {
25-
route.render('viewApiBackend');
25+
route.render('viewApi');
2626
route.layout('masterLayout');
2727
} else {
2828
Router.go('notAuthorized');

apis/client/view/details/details.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
<template name="viewApiBackendDetails">
1+
<template name="apiDetails">
22
<div class="panel panel-default">
33
<div class="panel-heading">
44
<h2 class="panel-title clearfix">
5-
{{_ "view_ApiBackend_Details_Title"}}
5+
{{_ "viewApi_Details_Title"}}
66
</h2>
77
</div>
88
<div class="panel-body">
99
<div class="row">
1010
<div class="col-lg-12 api-details-block">
1111
{{ # if api.description }}
1212
<h3>
13-
{{_ "viewApiBackendDetails_description_headingText" }}
13+
{{_ "apiDetails_description_headingText" }}
1414
</h3>
1515
<p>
1616
{{ api.description }}
@@ -20,7 +20,7 @@ <h3>
2020

2121
{{# if url }}
2222
<h3>
23-
{{_ "viewApiBackendDetails_baseUrl_headingText" }}
23+
{{_ "apiDetails_baseUrl_headingText" }}
2424
</h3>
2525
<div class="input-group">
2626
<input

apis/client/view/details/details.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import Clipboard from 'clipboard';
22

3-
Template.viewApiBackendDetails.onRendered(function () {
3+
Template.apiDetails.onRendered(function () {
44
// Initialize Clipboard copy button
55
const copyButton = new Clipboard('#copyApiUrl');
66

@@ -18,7 +18,7 @@ Template.viewApiBackendDetails.onRendered(function () {
1818
});
1919
});
2020

21-
Template.viewApiBackendDetails.helpers({
21+
Template.apiDetails.helpers({
2222
url () {
2323
// Get reference to template instance
2424
const instance = Template.instance();

apis/client/view/header/header.html

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<template name="viewApiBackendPageHeader">
1+
<template name="viewApiPageHeader">
22
<div class="page-head-topblock">
33
<div class="container">
44
<!-- Header -->
@@ -7,7 +7,7 @@
77
{{> viewApiLogo }}
88
<h1 class="api-name">
99
{{ api.name }}
10-
{{> viewApiBackendStatus api=api width="0.4" }}
10+
{{> viewApiStatus api=api width="0.4" }}
1111
</h1>
1212
<ul class="list-inline view-api-meta-details">
1313
<li>
@@ -45,59 +45,59 @@ <h1 class="api-name">
4545
<li class="active">
4646
<a href="#api-details" data-toggle="tab">
4747
<i class="fa fa-info-circle"></i>
48-
{{_ "viewApiBackendNavigationMenu_details" }}
48+
{{_ "viewApiNavigationMenu_details" }}
4949
</a>
5050
</li>
5151
<li>
5252
<a href="#api-documentation" data-toggle="tab">
5353
<i class="fa fa-file-text"></i>
54-
{{_ "viewApiBackendNavigationMenu_documentation" }}
54+
{{_ "viewApiNavigationMenu_documentation" }}
5555
</a>
5656
</li>
5757
<li>
5858
<a href="#api-metadata" data-toggle="tab">
5959
<i class="fa fa-book"></i>
60-
{{_ "viewApiBackendNavigationMenu_metadata" }}
60+
{{_ "viewApiNavigationMenu_metadata" }}
6161
</a>
6262
</li>
6363
<li>
6464
<a href="#api-feedback" data-toggle="tab">
6565
<i class="fa fa-comments-o"></i>
66-
{{_ "viewApiBackendNavigationMenu_feedback" }}
66+
{{_ "viewApiNavigationMenu_feedback" }}
6767
</a>
6868
</li>
6969
<li>
7070
<a href="#api-backlog" data-toggle="tab">
7171
<i class="fa fa-check-square-o"></i>
72-
{{_ "viewApiBackendNavigationMenu_backlog" }}
72+
{{_ "viewApiNavigationMenu_backlog" }}
7373
</a>
7474
</li>
75+
{{ # if currentUser }}
76+
{{ # if api.currentUserCanEdit }}
7577
<li>
76-
<a href="#api-export" data-toggle="tab">
78+
<a href="#api-backend-export" data-toggle="tab">
7779
<i class="fa fa-cloud-download"></i>
78-
{{_ "viewApiBackendNavigationMenu_export" }}
80+
{{_ "viewApiNavigationMenu_export" }}
7981
</a>
8082
</li>
8183

82-
{{# if api.currentUserCanEdit }}
8384
<li>
8485
<a href="#api-settings" data-toggle="tab">
8586
<i class="fa fa-cog"></i>
86-
{{_ "viewApiBackendNavigationMenu_settings" }}
87+
{{_ "viewApiNavigationMenu_settings" }}
8788
</a>
8889
</li>
8990

9091
{{# if proxyIsConfigured }}
9192
<li>
9293
<a href="#api-proxy" data-toggle="tab">
9394
<i class="fa fa-sitemap"></i>
94-
{{_ "viewApiBackendNavigationMenu_proxy" }}
95+
{{_ "viewApiNavigationMenu_proxy" }}
9596
</a>
9697
</li>
9798
{{/ if }}
98-
9999
{{ / if }}
100-
100+
{{ / if }}
101101
</ul>
102102
</div>
103103
</div>

apis/client/view/settings/settings.html

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
<template name="viewApiBackendSettings">
1+
<template name="apiSettings">
22
<div class="panel panel-default">
33
<div class="panel-heading">
44
<h2 class="panel-title">
5-
{{_ "viewApiBackendSettings_panelTitleAbout" }}
5+
{{_ "apiSettings_panelTitleAbout" }}
66
</h2>
77
</div>
88
<div class="panel-body">
99
<h3>
10-
{{_ "viewApiBackendSettings_uploadLogo_heading" }}
10+
{{_ "apiSettings_uploadLogo_heading" }}
1111
</h3>
1212
<p>
13-
{{_ "viewApiBackendSettings_uploadLogoText" }}
13+
{{_ "apiSettings_uploadLogoText" }}
1414
</p>
1515
{{> uploadApiLogo api=api }}
1616
<hr class="panel-hr" />
@@ -20,7 +20,7 @@ <h3>
2020
{{> afQuickField name='url'}}
2121
<div id="form-buttons">
2222
<button type="submit" class="btn btn-success" id="save-settings">
23-
{{_ "viewApiBackendSettigs_saveButton_text" }}
23+
{{_ "viewApiSettigs_saveButton_text" }}
2424
</button>
2525
</div>
2626
{{/autoForm}}
@@ -29,19 +29,19 @@ <h3>
2929
<div class="panel panel-danger">
3030
<div class="panel-heading">
3131
<h2 class="panel-title">
32-
{{_ "viewApiBackendSettings_panelTitleManage" }}
32+
{{_ "apiSettings_panelTitleManage" }}
3333
</h2>
3434
</div>
3535
<div class="panel-body">
36-
<h3>{{_ "viewApiBackendSettings_deleteApiTitle" }}</h3>
36+
<h3>{{_ "apiSettings_deleteApiTitle" }}</h3>
3737
<p>
38-
{{_ "viewApiBackendSettings_deleteApiText" }}
38+
{{_ "apiSettings_deleteApiText" }}
3939
</p>
4040
<a
4141
href="#"
4242
class="btn btn-danger"
4343
id="deleteModal">
44-
{{_ "viewApiBackendDetails_deleteButton"}}
44+
{{_ "apiDetails_deleteButton"}}
4545
</a>
4646
</div>
4747
</div>

apis/client/view/settings/settings.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Apis } from '/apis/collection';
22

3-
Template.viewApiBackendSettings.events({
3+
Template.apiSettings.events({
44
// event handler to execute when delete API button is clicked
55
'click #deleteModal': function () {
66
const apiId = this.api._id;
@@ -13,7 +13,7 @@ Template.viewApiBackendSettings.events({
1313
},
1414
});
1515

16-
Template.viewApiBackendSettings.helpers({
16+
Template.apiSettings.helpers({
1717
formCollection () {
1818
return Apis;
1919
},

apis/client/view/status/status.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<template name="viewApiBackendStatus" >
1+
<template name="viewApiStatus" >
22
<div
33
class="api-status-indicator-{{api._id}} api-status-color"
44
data-toggle="tooltip"

apis/client/view/status/status.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Meteor imports
22
import { Template } from 'meteor/templating';
33

4-
Template.viewApiBackendStatus.onCreated(function () {
4+
Template.viewApiStatus.onCreated(function () {
55
// Create reference to instance
66
const instance = this;
77

@@ -35,28 +35,28 @@ Template.viewApiBackendStatus.onCreated(function () {
3535
if (success.test(status.code)) {
3636
className = 'status-success';
3737
statusText = `
38-
${TAPi18n.__('viewApiBackendStatus_statusMessage_Success')}
38+
${TAPi18n.__('viewApiStatus_statusMessage_Success')}
3939
`;
4040
} else if (redirect.test(status.code)) {
4141
className = 'status-success';
4242
statusText = `
43-
${TAPi18n.__('viewApiBackendStatus_statusMessage_ErrorCodeText')}
43+
${TAPi18n.__('viewApiStatus_statusMessage_ErrorCodeText')}
4444
${status.code}.
45-
${TAPi18n.__('viewApiBackendStatus_statusMessage_RedirectError')}
45+
${TAPi18n.__('viewApiStatus_statusMessage_RedirectError')}
4646
`;
4747
} else if (clientErr.test(status.code)) {
4848
className = 'status-warning';
4949
statusText = `
50-
${TAPi18n.__('viewApiBackendStatus_statusMessage_ErrorCodeText')}
50+
${TAPi18n.__('viewApiStatus_statusMessage_ErrorCodeText')}
5151
${status.code}.
52-
${TAPi18n.__('viewApiBackendStatus_statusMessage_ClientError')}
52+
${TAPi18n.__('viewApiStatus_statusMessage_ClientError')}
5353
`;
5454
} else if (serverErr.test(status.code)) {
5555
className = 'alert-danger';
5656
statusText = `
57-
${TAPi18n.__('viewApiBackendStatus_statusMessage_ErrorCodeText')}
57+
${TAPi18n.__('viewApiStatus_statusMessage_ErrorCodeText')}
5858
${status.code}.
59-
${TAPi18n.__('viewApiBackendStatus_statusMessage_ServerError')}
59+
${TAPi18n.__('viewApiStatus_statusMessage_ServerError')}
6060
`;
6161
}
6262

@@ -67,7 +67,7 @@ Template.viewApiBackendStatus.onCreated(function () {
6767
};
6868
});
6969

70-
Template.viewApiBackendStatus.onRendered(function () {
70+
Template.viewApiStatus.onRendered(function () {
7171
// Get reference to template instance
7272
const instance = this;
7373

0 commit comments

Comments
 (0)