couchdb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From michellephung <...@git.apache.org>
Subject [GitHub] couchdb-fauxton pull request: [WIP] Fix view bugs
Date Wed, 22 Apr 2015 15:14:33 GMT
Github user michellephung commented on a diff in the pull request:

    https://github.com/apache/couchdb-fauxton/pull/391#discussion_r28882270
  
    --- Diff: app/addons/components/react-components.react.jsx ---
    @@ -63,15 +64,123 @@ function (app, FauxtonAPI, React, Components, beautifyHelper) {
       });
     
       var CodeEditor = React.createClass({
    -    render: function () {
    -      var code = this.aceEditor ? this.aceEditor.getValue() : this.props.code;
    -      return (
    -        <div className="control-group">
    -          {this.getTitleFragment()}
    -          <div className="js-editor" id={this.props.id}>{this.props.code}</div>
    -          <Beautify code={code} beautifiedCode={this.setEditorValue} />
    -        </div>
    -      );
    +    getDefaultProps: function () {
    +      return {
    +        id: 'code-editor',
    +        mode: 'javascript',
    +        theme: 'idle_fingers',
    +        fontSize: 13,
    +        code: '',
    +        showGutter: true,
    +        highlightActiveLine: true,
    +        showPrintMargin: false,
    +        autoScrollEditorIntoView: true,
    +        setHeightWithJS: true,
    +        isFullPageEditor: false,
    +      };
    +    },
    +
    +    hasChanged: function () {
    +      return !_.isEqual(this.props.code, this.getValue());
    +    },
    +
    +    setupAce: function (props) {
    +      this.editor = ace.edit(this.getDOMNode(this.refs.ace));
    +      // Automatically scrolling cursor into view after selection
    +      // change this will be disabled in the next version
    +      // set editor.$blockScrolling = Infinity to disable this message
    +      this.editor.$blockScrolling = Infinity;
    +
    +      this.editor.setShowPrintMargin(props.showPrintMargin);
    +      this.editor.autoScrollEditorIntoView = props.autoScrollEditorIntoView;
    +      this.setEditorValue(props.code);
    +      this.setHeightToLineCount();
    +      this.removeIncorrectAnnotations();
    +      this.editor.getSession().setMode("ace/mode/" + props.mode);
    +      this.editor.setTheme("ace/theme/" + props.theme);
    +      this.editor.setFontSize(props.fontSize);
    +    },
    +
    +    setupEvents: function () {
    +      $(window).on('beforeunload.editor_' + this.props.id, _.bind(this.quitWarningMsg));
    +      FauxtonAPI.beforeUnload('editor_' + this.props.id, _.bind(this.quitWarningMsg,
this));
    +    },
    +
    +    quitWarningMsg: function () {
    +      if (this.hasChanged()) {
    +        return 'Your changes have not been saved. Click cancel to return to the document.';
    +      }
    +    },
    +
    +    removeEvents: function () {
    +      $(window).off('beforeunload.editor_' + this.props.id);
    +      FauxtonAPI.removeBeforeUnload('editor_' + this.props.id);
    +    },
    +
    +    setHeightToLineCount: function () {
    +      if (!this.props.setHeightWithJS) {
    +        return;
    +      }
    +
    +      var lines = this.editor.getSession().getDocument().getLength();
    +
    +      if (this.props.isFullPageEditor) {
    +        var maxLines = this.getMaxAvailableLinesOnPage();
    +        lines = lines < maxLines ? lines : maxLines;
    +      }
    +      this.editor.setOptions({
    +        maxLines: lines
    +      });
    +    },
    +
    +    // List of JSHINT errors to ignore
    +    // Gets around problem of anonymous functions not being a valid statement
    +    excludedViewErrors: [
    +      "Missing name in function declaration.",
    +      "['{a}'] is better written in dot notation."
    +    ],
    +
    +    isIgnorableError: function (msg) {
    +      return _.contains(this.excludedViewErrors, msg);
    +    },
    +
    +    removeIncorrectAnnotations: function () {
    +      var editor = this.editor,
    +          isIgnorableError = this.isIgnorableError;
    +
    +      this.editor.getSession().on("changeAnnotation", function () {
    +        var annotations = editor.getSession().getAnnotations();
    +
    +        var newAnnotations = _.reduce(annotations, function (annotations, error) {
    +          if (!isIgnorableError(error.raw)) {
    +            annotations.push(error);
    +          }
    +          return annotations;
    +        }, []);
    +
    +        if (annotations.length !== newAnnotations.length) {
    +          editor.getSession().setAnnotations(newAnnotations);
    +        }
    +      });
    +    },
    +
    +    componentDidMount: function () {
    +      this.setupAce(this.props);
    +      this.setupEvents();
    +    },
    +
    +    componentWillUnmount: function () {
    +      console.log('hello unmount', this.props.id);
    --- End diff --
    
    :koala: console.log


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message