-
Notifications
You must be signed in to change notification settings - Fork 35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding apiDocumentationEditor to collection and settings page. #794
Conversation
Added apiDocumentationEditor.Host as a String to settings collection
changed label in settings collection
… value is empty. added apiDocumentationEditor field to config.example.json
Please review @apinf/developers |
@@ -6,10 +6,15 @@ Template.sidebar.helpers({ | |||
var backendsCount = ApiBackends.find({managerIds: currentUserId}).count(); | |||
// return true if user has backends | |||
return backendsCount > 0; | |||
}, | |||
apiDoc_notEmpty : function() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While this works, it can be slightly more semantic. I.e. it can be more descriptive:
"If api documentation editor is enabled"
apiDocumentationEditorIsEnabled: function () {}
And then in the template:
{{# if apiDocumentationEditorIsEnabled }}
...
{{/ if }}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't this about whether the apidochost setting being set or not?
Am Dienstag, 26. Januar 2016 schrieb Brylie Christopher Oxley :
In client/layouts/master_layout/sidebar/sidebar.js
https://github.com/apinf/api-umbrella-dashboard/pull/794#discussion_r50813653
:@@ -6,10 +6,15 @@ Template.sidebar.helpers({
var backendsCount = ApiBackends.find({managerIds: currentUserId}).count();
// return true if user has backends
return backendsCount > 0;
- },
- apiDoc_notEmpty : function() {
While this works, it can be slightly more semantic. I.e. it can be more
descriptive:"If api documentation editor is configured"
apiDocumentationEditorIsEnabled: function () {}
And then in the template:
{{# if apiDocumentationEditorIsEnabled }}
...
{{/ if }}—
Reply to this email directly or view it on GitHub
https://github.com/apinf/api-umbrella-dashboard/pull/794/files#r50813653
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, and the ApiDoc.host setting happens to enable the documentation editor, hence the verbosity.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In effect, the not_empty
part, while accurate, does not describe the purpose of the check. Simply renaming the function can make the purpose more clear.
After a bit of thought, I have a suggestion to make our settings check more 'high-level' semantic and accurate to the underlying JavaScript.
This is a pattern we can later repeat with other settings, such as integrations with Github, etc.. |
This would also need a hook which would turn enabled on and off depending on the presence of |
@sebbel, good point. Lets leave the hook for later, if necessary, and simply document the |
Having Problems to grab the value of apiDocumentationEditor.enabled |
I have changed it according to your suggestions @brylie, but I am not really pleased with the outcome.
|
The save step is a good check to make sure the settings are correct before writing them to the collection. |
The Here is a custom validation function you can add to the "apiDocumentationEditor": {
type: Object,
optional: true
},
"apiDocumentationEditor.enabled": {
type: Boolean,
optional: true
}
"apiDocumentationEditor.host": {
type: String,
regEx: SimpleSchema.RegEx.Url,
optional: true, // Optional must be true for custom validation
custom: function () { // Custom validator logic
// get the value of apiDocumentationEditor.enabled field
let enabledFieldValue = this.field("apiDocumentationEditor.enabled").value;
// if enabled is true, host field is required
if (enabledFieldValue === true) {
return "required"; // host field is required
}
}
} |
apiDocumentationEditorIsEnabled : function() { | ||
// Saving the fields apiDocumentationEditor.enabled into the variable | ||
// settings. | ||
var settings = Settings.findOne({},{"apiDocumentationEditor.enabled": 1, _id:0}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where is the subscription that provides data for this query?
We may need a new publication that returns only a single field from the Settings document, just as you are doing here. E.g.
Meteor.publish("singleSetting", function (setting) {
// Set up a query settings object containing fields and a result limit
let querySettings = {"fields": {}, "limit": 1};
// Specify the setting field we want to retrieve (passed in as argument)
querySettings.fields[setting] = 1;
// Return a cursor containing only the requested setting from the Settings document
let cursor = Settings.find({}, querySettings);
return cursor;
});
Then, in your Template.created callback:
// Subscribe to the API Documentation Editor setting (including sub-fields)
instance.subscribe("singleSetting", "apiDocumentationEditor");
…user the possibility to check the box and not enter a host.
Thanks for your feedback @brylie, Really like the generic publish method! |
label: "Host", | ||
optional: true, // Optional must be true for custom validation | ||
custom: function () { // Custom validator logic | ||
// get the value of apiDocumentationEditor.enabled field |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Check indentation here. Nested blocks should be one level (two spaces) indented.
This PR is nearly ready. There is just a minor issue with indentation (two spaces per indent level). Please be consistent with whitespace. |
Hope my edits helped maintain a clean whitespace. |
Looks great! Thanks Sebastian :-) |
Adding apiDocumentationEditor to collection and settings page.
No description provided.