-
Notifications
You must be signed in to change notification settings - Fork 33
Expand file tree
/
Copy pathmanage.js
More file actions
127 lines (109 loc) · 3.77 KB
/
manage.js
File metadata and controls
127 lines (109 loc) · 3.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
import { DocumentationFiles } from '/documentation/collection/collection';
import { Apis } from '/apis/collection';
import { Settings } from '/settings/collection';
Template.manageApiDocumentationModal.onCreated(function () {
const instance = this;
// Initialize help texts
const helpTexts = {
'documentation_link': {
message: TAPi18n.__('manageApiDocumentationModal_hints_documentation_link'),
options: {
placement: 'left',
},
},
'uploadApiDocumentation': {
message: TAPi18n.__('manageApiDocumentationModal_hints_uploadApiDocumentation'),
options: {
placement: 'left',
},
},
'documentation_editor_create_file': {
message: TAPi18n.__('manageApiDocumentationModal_hints_createApiDocumentation'),
options: {
placement: 'left',
},
},
};
InlineHelp.initHelp(helpTexts);
instance.autorun(function () {
const api = Apis.findOne(instance.data.api._id);
// Save apibackend id
Session.set('api', api);
});
// Subscribe to documentation editor settings
instance.subscribe('singleSetting', 'apiDocumentationEditor');
});
Template.manageApiDocumentationModal.onDestroyed(function () {
// Unset session
Session.set('api', undefined);
});
Template.manageApiDocumentationModal.events({
'click .delete-documentation': function (event, instance) {
// Show confirmation dialog to user
const confirmation = confirm(TAPi18n.__('manageApiDocumentationModal_DeletedFile_ConfirmationMessage'));
// Check if user clicked "OK"
if (confirmation === true) {
// Get currentApiBackend documentationFileId
const documentationFileId = this.api.documentationFileId;
// Convert to Mongo ObjectID
const objectId = new Mongo.Collection.ObjectID(documentationFileId);
// Remove documentation object
DocumentationFiles.remove(objectId);
// Remove documenation file id field
Apis.update(instance.data.api._id, { $unset: { documentationFileId: '' } });
sAlert.success(TAPi18n.__('manageApiDocumentationModal_DeletedFile_Message'));
}
},
'click #save-documentation-link': function (event, instance) {
// Hide modal
Modal.hide('manageApiDocumentationModal');
},
'click #open-api-editor': function (event, instance) {
// Hide modal
Modal.hide('manageApiDocumentationModal');
},
});
Template.manageApiDocumentationModal.helpers({
documentationFile () {
const api = Session.get('api');
const documentationFileId = api.documentationFileId;
// Convert to Mongo ObjectID
const objectId = new Mongo.Collection.ObjectID(documentationFileId);
// Get documentation file Object
const documentationFile = DocumentationFiles.findOne(objectId);
// Check if documentation file is available
if (documentationFile) {
return documentationFile;
}
},
apiDocumentationEditorIsEnabled () {
// Get settings
const settings = Settings.findOne();
// Check settings exists, editor is enabled and host setting exists
if (
settings &&
settings.apiDocumentationEditor &&
settings.apiDocumentationEditor.enabled &&
settings.apiDocumentationEditor.host) {
// Editor is enabled and has host setting, return true
return true;
} else {
// Otherwise return false
return false;
}
},
apisCollection () {
// Return a reference to Apis collection, for AutoForm
return Apis;
},
// Return list of all try-out methods, which is used in Swagger Options
supportedSubmitMethods () {
return [
{label: 'GET', value: 'get'},
{label: 'POST', value: 'post'},
{label: 'DELETE', value: 'delete'},
{label: 'PATCH', value: 'patch'},
{label: 'PUT', value: 'put'}
]
},
});