Skip to content
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

Merged
merged 14 commits into from
Jan 29, 2016

Conversation

sebbel
Copy link
Contributor

@sebbel sebbel commented Jan 25, 2016

No description provided.

Added apiDocumentationEditor.Host as a String to settings collection
@sebbel
Copy link
Contributor Author

sebbel commented Jan 25, 2016

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() {
Copy link
Contributor

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 }}

Copy link
Contributor Author

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
.

Copy link
Contributor

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.

Copy link
Contributor

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.

@brylie
Copy link
Contributor

brylie commented Jan 26, 2016

After a bit of thought, I have a suggestion to make our settings check more 'high-level' semantic and accurate to the underlying JavaScript.

  1. Add a sub-field to the apiDocumentationEditor field, called enabled with a type of Boolean.
  2. When the enabled field is true the host field is marked as required.
  3. Then, in the apiDocumentationEditorIsEnabled template helper, simply return the value of the enabled field.
  4. bonus points (optional) In the Settings autoform, use AutoForm {{ afFieldValueIs ... }} helper to selectively toggle the visibility of the host field, based on whether enabled is true

This is a pattern we can later repeat with other settings, such as integrations with Github, etc..

@sebbel
Copy link
Contributor Author

sebbel commented Jan 26, 2016

This would also need a hook which would turn enabled on and off depending on the presence of apiDocumentationEditor.host

@brylie
Copy link
Contributor

brylie commented Jan 26, 2016

@sebbel, good point. Lets leave the hook for later, if necessary, and simply document the enabled field. That way, the host can be passed in and stored, even if the feature is not enabled (e.g. if the editor service is temporarily offline, but the admin wants to keep the host setting preserved.)

@sebbel
Copy link
Contributor Author

sebbel commented Jan 26, 2016

Having Problems to grab the value of apiDocumentationEditor.enabled

@sebbel
Copy link
Contributor Author

sebbel commented Jan 26, 2016

I have changed it according to your suggestions @brylie, but I am not really pleased with the outcome.

  • The checkbox is not reactive, which means that the Documentation Editor Link only appears after the User has saved the settings.
  • The Link appears even when there is no host set, I don't know if thats desired.

@brylie
Copy link
Contributor

brylie commented Jan 27, 2016

The save step is a good check to make sure the settings are correct before writing them to the collection.

@brylie
Copy link
Contributor

brylie commented Jan 27, 2016

The host setting should be conditionally required. You can tell AutoForm that "when the enabled field is true, the host field is required."

Here is a custom validation function you can add to the apiDocumentationEditor field schema:

"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
    }
  }
}

@brylie brylie added the WIP label Jan 27, 2016
apiDocumentationEditorIsEnabled : function() {
// Saving the fields apiDocumentationEditor.enabled into the variable
// settings.
var settings = Settings.findOne({},{"apiDocumentationEditor.enabled": 1, _id:0})
Copy link
Contributor

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");

@sebbel
Copy link
Contributor Author

sebbel commented Jan 28, 2016

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
Copy link
Contributor

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.

@brylie
Copy link
Contributor

brylie commented Jan 29, 2016

This PR is nearly ready. There is just a minor issue with indentation (two spaces per indent level). Please be consistent with whitespace.

@sebbel
Copy link
Contributor Author

sebbel commented Jan 29, 2016

Hope my edits helped maintain a clean whitespace.

@brylie
Copy link
Contributor

brylie commented Jan 29, 2016

Looks great! Thanks Sebastian :-)

brylie added a commit that referenced this pull request Jan 29, 2016
Adding apiDocumentationEditor to collection and settings page.
@brylie brylie merged commit e2d5597 into develop Jan 29, 2016
@brylie brylie deleted the feature/792-add-apidocumentation branch January 29, 2016 09:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants