11import { DocumentationFiles } from '/documentation/collection/collection' ;
22
3- Template . documentation . onCreated ( function ( ) {
3+ Template . documentation . onCreated ( function ( ) {
44 const instance = this ;
55
66 // Run subscription in autorun
77 instance . autorun ( ( ) => {
8-
98 // Get current documentation file Id
109 const documentationFileId = Template . currentData ( ) . apiBackend . documentationFileId ;
1110
@@ -14,15 +13,17 @@ Template.documentation.onCreated(function(){
1413 instance . subscribe ( 'singleDocumentationFile' , documentationFileId ) ;
1514 }
1615 } ) ;
16+
17+ // Subscribe to code generator settings
18+ instance . subscribe ( 'singleSetting' , 'sdkCodeGenerator' ) ;
1719} ) ;
1820
1921Template . documentation . onRendered ( function ( ) {
2022 $ ( '[data-toggle="popover"]' ) . popover ( ) ;
2123} ) ;
2224
2325Template . documentation . helpers ( {
24- uploadedDocumentationLink : function ( ) {
25-
26+ uploadedDocumentationLink ( ) {
2627 const currentDocumentationFileId = this . apiBackend . documentationFileId ;
2728
2829 // Convert to Mongo ObjectID
@@ -37,36 +38,58 @@ Template.documentation.helpers({
3738 const currentDocumentationFileId = currentDocumentationFile . _id ;
3839
3940 // Get documentation file URL
40- return Meteor . absoluteUrl ( ) . slice ( 0 , - 1 ) + DocumentationFiles . baseURL + " /id/" + currentDocumentationFileId ;
41+ return Meteor . absoluteUrl ( ) . slice ( 0 , - 1 ) + DocumentationFiles . baseURL + ' /id/' + currentDocumentationFileId ;
4142 }
4243 } ,
43- documentationLink : function ( ) {
44+ documentationLink ( ) {
4445 // get documentation link
4546 const documentationLink = this . apiBackend . documentation_link ;
4647 // check if exists
4748 if ( documentationLink ) {
48- return documentationLink
49+ return documentationLink ;
4950 }
5051 } ,
51- documentationExists : function ( ) {
52+ documentationExists ( ) {
5253 const currentApiBackend = this . apiBackend ;
5354 if ( currentApiBackend . documentationFileId ) {
5455 return true ;
5556 }
57+ } ,
58+ codegenServerExists ( ) {
59+ // Get template instance
60+ const instance = Template . instance ( ) ;
61+
62+ // Get documentation file
63+ const apiDocumentation = this . apiBackend . documentationFileId ;
64+
65+ // Get settings
66+ const settings = Settings . findOne ( ) ;
67+
68+ // Check documentation exists, generator is enabled and host setting exists
69+ if ( settings && apiDocumentation && settings . sdkCodeGenerator . host && settings . sdkCodeGenerator . enabled ) {
70+ // Get code generator host
71+ instance . codegenServer = settings . sdkCodeGenerator . host ;
72+
73+ // Generator is enabled and has host setting, return true
74+ return true ;
75+ }
5676 }
77+
5778} ) ;
5879
5980Template . documentation . events ( {
6081 'click #manage-api-documentation' ( event , instance ) {
6182 // Get reference to API backend
62- const apiBackend = instance . data . apiBackend
83+ const apiBackend = instance . data . apiBackend ;
6384 // Show the manage API documentation form
64- Modal . show ( 'manageApiDocumentationModal' , { apiBackend } )
85+ Modal . show ( 'manageApiDocumentationModal' , { apiBackend } ) ;
6586 } ,
6687 'click #sdk-code-generator' ( event , instance ) {
6788 // Get reference to API backend
6889 const apiBackend = instance . data . apiBackend ;
90+ // Get reference to Code Generator host
91+ const host = instance . codegenServer ;
6992 // Show the SDK Code generator form
70- Modal . show ( 'sdkCodeGeneratorModal' , { apiBackend } ) ;
93+ Modal . show ( 'sdkCodeGeneratorModal' , { apiBackend, host } ) ;
7194 }
7295} ) ;
0 commit comments