Github user benkeen commented on a diff in the pull request:

    https://github.com/apache/couchdb-fauxton/pull/669#discussion_r72912803
  
    --- Diff: app/addons/replication/components.react.jsx ---
    @@ -0,0 +1,527 @@
    +// Licensed under the Apache License, Version 2.0 (the "License"); you may 
not
    +// use this file except in compliance with the License. You may obtain a 
copy of
    +// the License at
    +//
    +//   http://www.apache.org/licenses/LICENSE-2.0
    +//
    +// Unless required by applicable law or agreed to in writing, software
    +// distributed under the License is distributed on an "AS IS" BASIS, 
WITHOUT
    +// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
    +// License for the specific language governing permissions and limitations 
under
    +// the License.
    +import app from '../../app';
    +import FauxtonAPI from '../../core/api';
    +import React from 'react';
    +import Stores from './stores';
    +import Actions from './actions';
    +import Constants from './constants';
    +import Components from '../components/react-components.react';
    +import base64 from 'base-64';
    +import AuthActions from '../auth/actions';
    +import AuthComponents from '../auth/components.react';
    +
    +const store = Stores.replicationStore;
    +const LoadLines = Components.LoadLines;
    +const TypeaheadField = Components.TypeaheadField;
    +const StyledSelect = Components.StyledSelect;
    +const ConfirmButton = Components.ConfirmButton;
    +const PasswordModal = AuthComponents.PasswordModal;
    +
    +
    +class ReplicationController extends React.Component {
    +  constructor (props) {
    +    super(props);
    +    this.state = this.getStoreState();
    +    this.submit = this.submit.bind(this);
    +    this.clear = this.clear.bind(this);
    +    this.showPasswordModal = this.showPasswordModal.bind(this);
    +  }
    +
    +  getStoreState () {
    +    return {
    +      loading: store.isLoading(),
    +      databases: store.getDatabases(),
    +      authenticated: store.isAuthenticated(),
    +      password: store.getPassword(),
    +
    +      // source fields
    +      replicationSource: store.getReplicationSource(),
    +      sourceDatabase: store.getSourceDatabase(),
    +      localSourceDatabaseKnown: store.isLocalSourceDatabaseKnown(),
    +      remoteSource: store.getRemoteSource(),
    +
    +      // target fields
    +      replicationTarget: store.getReplicationTarget(),
    +      targetDatabase: store.getTargetDatabase(),
    +      localTargetDatabaseKnown: store.isLocalTargetDatabaseKnown(),
    +      remoteTarget: store.getRemoteTarget(),
    +
    +      // other
    +      passwordModalVisible: store.isPasswordModalVisible(),
    +      replicationType: store.getReplicationType(),
    +      replicationDocName: store.getReplicationDocName()
    +    };
    +  }
    +
    +  componentDidMount () {
    +    store.on('change', this.onChange, this);
    +  }
    +
    +  componentWillUnmount () {
    +    store.off('change', this.onChange);
    +  }
    +
    +  onChange () {
    +    this.setState(this.getStoreState());
    +  }
    +
    +  // the four local replication targets all show slightly different fields
    +  getReplicationTargetRow () {
    +    const { replicationTarget, remoteTarget, databases, targetDatabase } = 
this.state;
    +    if (!replicationTarget) {
    +      return null;
    +    }
    +    return (
    +      <ReplicationTargetRow
    +        remoteTarget={remoteTarget}
    +        replicationTarget={replicationTarget}
    +        databases={databases}
    +        targetDatabase={targetDatabase}/>
    +    );
    +  }
    +
    +  clear (e) {
    +    e.preventDefault();
    +    Actions.clearReplicationForm();
    +  }
    +
    +  showPasswordModal () {
    +    const { replicationSource, replicationTarget } = this.state;
    +
    +    var hasLocalSourceOrTarget = (replicationSource === 
Constants.REPLICATION_SOURCE.LOCAL ||
    +      replicationTarget === 
Constants.REPLICATION_TARGET.EXISTING_LOCAL_DATABASE ||
    +      replicationTarget === 
Constants.REPLICATION_TARGET.NEW_LOCAL_DATABASE);
    +
    +    // if the user is authenticated, or if NEITHER the source nor target 
are local, just submit. The password
    +    // modal isn't necessary
    +    if (!hasLocalSourceOrTarget || this.state.authenticated) {
    +      this.submit();
    +      return;
    +    }
    +    AuthActions.showPasswordModal();
    +  }
    +
    +  getUsername () {
    +    return app.session.get('userCtx').name;
    +  }
    +
    +  getAuthHeaders () {
    +    const username = this.getUsername();
    +    return {
    +      'Authorization': 'Basic ' + base64.encode(username + ':' + 
this.state.password)
    +    };
    +  }
    +
    +  submit () {
    --- End diff --
    
    Done.


---
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 [email protected] or file a JIRA ticket
with INFRA.
---

Reply via email to