<commit_before>var React = require('react');

module.exports = React.createClass({
  displayName: 'ProgressLabel',

  propTypes: {
    size: React.PropTypes.number,
    startDegree: React.PropTypes.number,
    endDegree: React.PropTypes.number,
    progressWidth: React.PropTypes.number,
    trackWidth: React.PropTypes.number,
    cornersWidth: React.PropTypes.number,
    progress: React.PropTypes.number,
    fillColor: React.PropTypes.string,
    trackColor: React.PropTypes.string,
    progressColor: React.PropTypes.string
  },

  getDefaultProps() {
    return {
      startDegree: 0,
      progress: 0,
      progressWidth: 5,
      trackWidth: 5,
      cornersWidth: 10,
      size: 200
    };
  },

  getPoint(r, degree) {
    var d = degree/180 * Math.PI;

    return {
      x: r * Math.sin(d) + 50,
      y: this.props.trackWidth/2 + r * (1 - Math.cos(d))
    };
  },

  render() {
    var size = this.props.size;
    var progress = this.props.progress;
    var r = 50 - this.props.trackWidth/2;
    var startDegree = this.props.startDegree;
    var endDegree = startDegree + progress * 360 / 100;
    var s = this.getPoint(r, this.props.startDegree);
    var e = this.getPoint(r, endDegree);

    var progressPath = null;
    if(progress < 50) {
      progressPath = `M ${s.x} ${s.y} A ${r} ${r}, 0, 0, 1, ${e.x},${e.y}`;
    } else {
      var m = this.getPoint(r, startDegree + 180);
      progressPath =
        `M ${s.x} ${s.y} A ${r} ${r}, 0, 0, 1, ${m.x},${m.y}
        M ${m.x} ${m.y} A ${r} ${r}, 0, 0, 1, ${e.x},${e.y}`;
    }

    var progressStyle = {
      strokeWidth: this.props.progressWidth,
      stroke: this.props.progressColor,
      fill: 'none'
    };

    var trackStyle = {
      fill: this.props.fillColor,
      stroke: this.props.trackColor,
      strokeWidth: this.props.trackWidth
    };

    return (
      <svg width={size} height={size} viewBox='0 0 100 100'>
        <circle
          cx="50"
          cy="50"
          r={r}
          style={trackStyle}
        />

        {progress > 0 ?
        <path
          d={progressPath}
          style={progressStyle}
        /> : null}

        {progress > 0 ?
        <circle
          cx={s.x}
          cy={s.y}
          r={this.props.cornersWidth}
          fill={this.props.progressColor}
        /> : null}

        {progress > 0 ?
        <circle
          cx={e.x}
          cy={e.y}
          r={this.props.cornersWidth}
          fill={this.props.progressColor}
        /> : null}

        {this.props.children}
      </svg>
    );
  }
});
<commit_msg>transfer props<commit_after>var React = require('react');

module.exports = React.createClass({
  displayName: 'ProgressLabel',

  propTypes: {
    size: React.PropTypes.number,
    startDegree: React.PropTypes.number,
    endDegree: React.PropTypes.number,
    progressWidth: React.PropTypes.number,
    trackWidth: React.PropTypes.number,
    cornersWidth: React.PropTypes.number,
    progress: React.PropTypes.number,
    fillColor: React.PropTypes.string,
    trackColor: React.PropTypes.string,
    progressColor: React.PropTypes.string
  },

  getDefaultProps() {
    return {
      startDegree: 0,
      progress: 0,
      progressWidth: 5,
      trackWidth: 5,
      cornersWidth: 10,
      size: 200
    };
  },

  getPoint(r, degree) {
    var d = degree/180 * Math.PI;

    return {
      x: r * Math.sin(d) + 50,
      y: this.props.trackWidth/2 + r * (1 - Math.cos(d))
    };
  },

  render() {
    var size = this.props.size;
    var progress = this.props.progress;
    var r = 50 - this.props.trackWidth/2;
    var startDegree = this.props.startDegree;
    var endDegree = startDegree + progress * 360 / 100;
    var s = this.getPoint(r, this.props.startDegree);
    var e = this.getPoint(r, endDegree);

    var progressPath = null;
    if(progress < 50) {
      progressPath = `M ${s.x} ${s.y} A ${r} ${r}, 0, 0, 1, ${e.x},${e.y}`;
    } else {
      var m = this.getPoint(r, startDegree + 180);
      progressPath =
        `M ${s.x} ${s.y} A ${r} ${r}, 0, 0, 1, ${m.x},${m.y}
        M ${m.x} ${m.y} A ${r} ${r}, 0, 0, 1, ${e.x},${e.y}`;
    }

    var progressStyle = {
      strokeWidth: this.props.progressWidth,
      stroke: this.props.progressColor,
      fill: 'none'
    };

    var trackStyle = {
      fill: this.props.fillColor,
      stroke: this.props.trackColor,
      strokeWidth: this.props.trackWidth
    };

    return (
      <svg {...this.props} width={size} height={size} viewBox="0 0 100 100">
        <circle
          cx="50"
          cy="50"
          r={r}
          style={trackStyle}
        />

        {progress > 0 ?
        <path
          d={progressPath}
          style={progressStyle}
        /> : null}

        {progress > 0 ?
        <circle
          cx={s.x}
          cy={s.y}
          r={this.props.cornersWidth}
          fill={this.props.progressColor}
        /> : null}

        {progress > 0 ?
        <circle
          cx={e.x}
          cy={e.y}
          r={this.props.cornersWidth}
          fill={this.props.progressColor}
        /> : null}

        {this.props.children}
      </svg>
    );
  }
});
<|endoftext|>


<commit_before>var utils = require('../../lib/utils');
var VError = require('verror');

// if they agree to the ULA, notify hubspot, create a trial and send verification link

module.exports = function trialSignup(request, reply) {
  var postToHubspot = request.server.methods.npme.sendData,
    getCustomer = request.server.methods.npme.getCustomer;

  var opts = {};

  var data = {
    hs_context: {
      pageName: "enterprise-trial-signup",
      ipAddress: utils.getUserIP(request)
    },
    // we can trust the email is fine because we've verified it in the show-ula handler
    email: request.payload.customer_email,
  };

  postToHubspot(process.env.HUBSPOT_FORM_NPME_AGREED_ULA, data, function(err) {

    if (err) {
      return reply(new VError(err, "Could not hit ULA notification form on Hubspot"));;
    }

    getCustomer(data.email, function(err, customer) {

      if (err) {
        return reply(new VError(err, "Unknown problem with customer record"));
      } else if (!customer) {
        return reply(new VError("Unable to locate customer '%s'", data.email));
      } else if (customer && String(customer.id) == String(request.payload.customer_id)) {
        return createTrialAccount(request, reply, customer);
      } else {
        return reply(new VError("Unable to verify customer record '%s'", data.email));
      }
    });
  });
};

function createTrialAccount(request, reply, customer) {

  var createTrial = request.server.methods.npme.createTrial;

  var opts = {};
  createTrial(customer, function(err, trial) {
    if (err) {
      return reply(new VError(err, "There was an error with creating a trial for %j", customer.id));
    }

    return sendVerificationEmail(request, reply, customer, trial);
  });
}

function sendVerificationEmail(request, reply, customer, trial) {

  var opts = {};

  var sendEmail = request.server.methods.email.send;

  var user = {
    name: customer.name,
    email: customer.email,
    verification_key: trial.verification_key
  };

  sendEmail('npme-trial-verification', user, request.redis)
    .then(function() {
      return reply.view('enterprise/thanks', opts);
    })
    .catch(function(er) {
      return reply(new VError(err, "unable to send verification email to %j", customer));
    });
}
<commit_msg>Doh, err not er<commit_after>var utils = require('../../lib/utils');
var VError = require('verror');

// if they agree to the ULA, notify hubspot, create a trial and send verification link

module.exports = function trialSignup(request, reply) {
  var postToHubspot = request.server.methods.npme.sendData,
    getCustomer = request.server.methods.npme.getCustomer;

  var opts = {};

  var data = {
    hs_context: {
      pageName: "enterprise-trial-signup",
      ipAddress: utils.getUserIP(request)
    },
    // we can trust the email is fine because we've verified it in the show-ula handler
    email: request.payload.customer_email,
  };

  postToHubspot(process.env.HUBSPOT_FORM_NPME_AGREED_ULA, data, function(err) {

    if (err) {
      return reply(new VError(err, "Could not hit ULA notification form on Hubspot"));;
    }

    getCustomer(data.email, function(err, customer) {

      if (err) {
        return reply(new VError(err, "Unknown problem with customer record"));
      } else if (!customer) {
        return reply(new VError("Unable to locate customer '%s'", data.email));
      } else if (customer && String(customer.id) == String(request.payload.customer_id)) {
        return createTrialAccount(request, reply, customer);
      } else {
        return reply(new VError("Unable to verify customer record '%s'", data.email));
      }
    });
  });
};

function createTrialAccount(request, reply, customer) {

  var createTrial = request.server.methods.npme.createTrial;

  var opts = {};
  createTrial(customer, function(err, trial) {
    if (err) {
      return reply(new VError(err, "There was an error with creating a trial for %j", customer.id));
    }

    return sendVerificationEmail(request, reply, customer, trial);
  });
}

function sendVerificationEmail(request, reply, customer, trial) {

  var opts = {};

  var sendEmail = request.server.methods.email.send;

  var user = {
    name: customer.name,
    email: customer.email,
    verification_key: trial.verification_key
  };

  sendEmail('npme-trial-verification', user, request.redis)
    .then(function() {
      return reply.view('enterprise/thanks', opts);
    })
    .catch(function(err) {
      return reply(new VError(err, "unable to send verification email to %j", customer));
    });
}
<|endoftext|>


<commit_before>/**
 * @fileOverview Render a group of scatters
 */
import React, { Component, PropTypes } from 'react';
import Animate from 'react-smooth';
import classNames from 'classnames';
import _ from 'lodash';
import pureRender from '../util/PureRender';
import Layer from '../container/Layer';
import { PRESENTATION_ATTRIBUTES, EVENT_ATTRIBUTES, getPresentationAttributes,
  filterEventsOfChild, isSsr, findAllByType } from '../util/ReactUtils';
import Curve from '../shape/Curve';
import Symbols from '../shape/Symbols';
import ErrorBar from './ErrorBar';
import AnimationDecorator from '../util/AnimationDecorator';

@AnimationDecorator
@pureRender
class Scatter extends Component {

  static displayName = 'Scatter';

  static propTypes = {
    ...PRESENTATION_ATTRIBUTES,
    ...PRESENTATION_ATTRIBUTES,

    xAxisId: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
    yAxisId: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
    zAxisId: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
    line: PropTypes.oneOfType([
      PropTypes.bool, PropTypes.object, PropTypes.func, PropTypes.element,
    ]),
    lineType: PropTypes.oneOf(['fitting', 'joint']),
    lineJointType: PropTypes.oneOfType([PropTypes.oneOf([
      'basis', 'basisClosed', 'basisOpen', 'linear', 'linearClosed', 'natural',
      'monotoneX', 'monotoneY', 'monotone', 'step', 'stepBefore', 'stepAfter',
    ]), PropTypes.func]),
    legendType: PropTypes.oneOf([
      'line', 'square', 'rect', 'circle', 'cross', 'diamond', 'star',
      'triangle', 'wye',
    ]),
    className: PropTypes.string,

    activeIndex: PropTypes.number,
    activeShape: PropTypes.oneOfType([
      PropTypes.object, PropTypes.func, PropTypes.element,
    ]),
    shape: PropTypes.oneOfType([
      PropTypes.oneOf(['circle', 'cross', 'diamond', 'square', 'star', 'triangle', 'wye']),
      PropTypes.element,
      PropTypes.func,
    ]),
    points: PropTypes.arrayOf(PropTypes.shape({
      cx: PropTypes.number,
      cy: PropTypes.number,
      size: PropTypes.number,
      node: PropTypes.shape({
        x: PropTypes.number,
        y: PropTypes.number,
        z: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
      }),
      payload: PropTypes.any,
    })),

    isAnimationActive: PropTypes.bool,
    animationId: PropTypes.number,
    animationBegin: PropTypes.number,
    animationDuration: PropTypes.number,
    animationEasing: PropTypes.oneOf(['ease', 'ease-in', 'ease-out', 'ease-in-out', 'linear']),
  };

  static defaultProps = {
    xAxisId: 0,
    yAxisId: 0,
    zAxisId: 0,
    legendType: 'circle',
    lineType: 'joint',
    lineJointType: 'linear',
    data: [],
    shape: 'circle',

    isAnimationActive: !isSsr(),
    animationBegin: 0,
    animationDuration: 400,
    animationEasing: 'linear',
  };

  state = { activeIndex: -1, isAnimationFinished: false };

  componentDidMount() {
    const { animationDuration } = this.props;
    window.setTimeout(() => this.setState({ isAnimationFinished: true }), animationDuration);
  }

  renderSymbolItem(option, props) {
    let symbol;

    if (React.isValidElement(option)) {
      symbol = React.cloneElement(option, props);
    } else if (_.isFunction(option)) {
      symbol = option(props);
    } else {
      symbol = <Symbols {...props} type={option} />;
    }

    return symbol;
  }

  renderSymbols() {
    const { points, shape, activeShape, activeIndex, animationBegin,
      animationDuration, isAnimationActive, animationEasing, animationId } = this.props;
    const baseProps = getPresentationAttributes(this.props);

    return points.map((entry, i) => {
      const props = {
        key: `symbol-${i}`,
        ...baseProps,
        ...entry,
      };
      return (
        <Layer
          className="recharts-scatter-symbol"
          {...filterEventsOfChild(this.props, entry, i)}
          key={`symbol-${i}`}
        >
          <Animate
            from={{ size: 0 }}
            to={{ size: props.size }}
            duration={animationDuration}
            begin={animationBegin}
            isActive={isAnimationActive}
            key={animationId}
            easing={animationEasing}
          >
            {
              ({ size }) => {
                const finalProps = { ...props, size };

                return this.renderSymbolItem(activeIndex === i ? activeShape : shape, finalProps);
              }
            }
          </Animate>
        </Layer>
      );
    });
  }

  renderErrorBar() {
    if (!this.state.isAnimationFinished) { return null; }

    const { points, xAxis, yAxis, layout, children } = this.props;
    const errorBarItems = findAllByType(children, ErrorBar);

    if (!errorBarItems) { return null; }

    function dataPointFormatterY(dataPoint, dataKey) {
      return {
        x: dataPoint.cx,
        y: dataPoint.cy,
        value: dataPoint.y,
        errorVal: dataPoint[dataKey],
      };
    }

    function dataPointFormatterX(dataPoint, dataKey) {
      return {
        x: dataPoint.cx,
        y: dataPoint.cy,
        value: dataPoint.x,
        errorVal: dataPoint[dataKey],
      };
    }

    return errorBarItems.map((item, i) => {
      if (item.props.direction === 'x') {
        return React.cloneElement(item, {
          key: i,
          data: points,
          xAxis,
          yAxis,
          layout: 'vertical',
          dataPointFormatter: dataPointFormatterX,
        });
      }

      return React.cloneElement(item, {
        key: i,
        data: points,
        xAxis,
        yAxis,
        layout,
        dataPointFormatter: dataPointFormatterY,
      });
    });
  }

  renderLine() {
    const { points, line, lineType, lineJointType } = this.props;
    const scatterProps = getPresentationAttributes(this.props);
    const customLineProps = getPresentationAttributes(line);
    let linePoints, lineItem;

    if (lineType === 'joint') {
      linePoints = points.map(entry => ({ x: entry.cx, y: entry.cy }));
    }
    const lineProps = {
      ...scatterProps,
      fill: 'none',
      stroke: scatterProps && scatterProps.fill,
      ...customLineProps,
      points: linePoints,
    };

    if (React.isValidElement(line)) {
      lineItem = React.cloneElement(line, lineProps);
    } else if (_.isFunction(line)) {
      lineItem = line(lineProps);
    } else {
      lineItem = <Curve {...lineProps} type={lineJointType} />;
    }

    return (
      <Layer className="recharts-scatter-line" key="recharts-scatter-line">
        {lineItem}
      </Layer>
    );
  }

  render() {
    const { points, line, className } = this.props;

    if (!points || !points.length) { return null; }

    const layerClass = classNames('recharts-scatter', className);

    return (
      <Layer className={layerClass}>
        {line && this.renderLine()}
        {this.renderErrorBar()}
        <Layer key="recharts-scatter-symbols">
          {this.renderSymbols()}
        </Layer>
      </Layer>
    );
  }
}

export default Scatter;
<commit_msg>tighten code up in renderErrorBar of scatter<commit_after>/**
 * @fileOverview Render a group of scatters
 */
import React, { Component, PropTypes } from 'react';
import Animate from 'react-smooth';
import classNames from 'classnames';
import _ from 'lodash';
import pureRender from '../util/PureRender';
import Layer from '../container/Layer';
import { PRESENTATION_ATTRIBUTES, EVENT_ATTRIBUTES, getPresentationAttributes,
  filterEventsOfChild, isSsr, findAllByType } from '../util/ReactUtils';
import Curve from '../shape/Curve';
import Symbols from '../shape/Symbols';
import ErrorBar from './ErrorBar';
import AnimationDecorator from '../util/AnimationDecorator';

@AnimationDecorator
@pureRender
class Scatter extends Component {

  static displayName = 'Scatter';

  static propTypes = {
    ...PRESENTATION_ATTRIBUTES,
    ...PRESENTATION_ATTRIBUTES,

    xAxisId: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
    yAxisId: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
    zAxisId: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
    line: PropTypes.oneOfType([
      PropTypes.bool, PropTypes.object, PropTypes.func, PropTypes.element,
    ]),
    lineType: PropTypes.oneOf(['fitting', 'joint']),
    lineJointType: PropTypes.oneOfType([PropTypes.oneOf([
      'basis', 'basisClosed', 'basisOpen', 'linear', 'linearClosed', 'natural',
      'monotoneX', 'monotoneY', 'monotone', 'step', 'stepBefore', 'stepAfter',
    ]), PropTypes.func]),
    legendType: PropTypes.oneOf([
      'line', 'square', 'rect', 'circle', 'cross', 'diamond', 'star',
      'triangle', 'wye',
    ]),
    className: PropTypes.string,

    activeIndex: PropTypes.number,
    activeShape: PropTypes.oneOfType([
      PropTypes.object, PropTypes.func, PropTypes.element,
    ]),
    shape: PropTypes.oneOfType([
      PropTypes.oneOf(['circle', 'cross', 'diamond', 'square', 'star', 'triangle', 'wye']),
      PropTypes.element,
      PropTypes.func,
    ]),
    points: PropTypes.arrayOf(PropTypes.shape({
      cx: PropTypes.number,
      cy: PropTypes.number,
      size: PropTypes.number,
      node: PropTypes.shape({
        x: PropTypes.number,
        y: PropTypes.number,
        z: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
      }),
      payload: PropTypes.any,
    })),

    isAnimationActive: PropTypes.bool,
    animationId: PropTypes.number,
    animationBegin: PropTypes.number,
    animationDuration: PropTypes.number,
    animationEasing: PropTypes.oneOf(['ease', 'ease-in', 'ease-out', 'ease-in-out', 'linear']),
  };

  static defaultProps = {
    xAxisId: 0,
    yAxisId: 0,
    zAxisId: 0,
    legendType: 'circle',
    lineType: 'joint',
    lineJointType: 'linear',
    data: [],
    shape: 'circle',

    isAnimationActive: !isSsr(),
    animationBegin: 0,
    animationDuration: 400,
    animationEasing: 'linear',
  };

  state = { activeIndex: -1, isAnimationFinished: false };

  componentDidMount() {
    const { animationDuration } = this.props;
    window.setTimeout(() => this.setState({ isAnimationFinished: true }), animationDuration);
  }

  renderSymbolItem(option, props) {
    let symbol;

    if (React.isValidElement(option)) {
      symbol = React.cloneElement(option, props);
    } else if (_.isFunction(option)) {
      symbol = option(props);
    } else {
      symbol = <Symbols {...props} type={option} />;
    }

    return symbol;
  }

  renderSymbols() {
    const { points, shape, activeShape, activeIndex, animationBegin,
      animationDuration, isAnimationActive, animationEasing, animationId } = this.props;
    const baseProps = getPresentationAttributes(this.props);

    return points.map((entry, i) => {
      const props = {
        key: `symbol-${i}`,
        ...baseProps,
        ...entry,
      };
      return (
        <Layer
          className="recharts-scatter-symbol"
          {...filterEventsOfChild(this.props, entry, i)}
          key={`symbol-${i}`}
        >
          <Animate
            from={{ size: 0 }}
            to={{ size: props.size }}
            duration={animationDuration}
            begin={animationBegin}
            isActive={isAnimationActive}
            key={animationId}
            easing={animationEasing}
          >
            {
              ({ size }) => {
                const finalProps = { ...props, size };

                return this.renderSymbolItem(activeIndex === i ? activeShape : shape, finalProps);
              }
            }
          </Animate>
        </Layer>
      );
    });
  }

  renderErrorBar() {
    if (!this.state.isAnimationFinished) { return null; }

    const { points, xAxis, yAxis, children } = this.props;
    const errorBarItems = findAllByType(children, ErrorBar);

    if (!errorBarItems) { return null; }

    function dataPointFormatterY(dataPoint, dataKey) {
      return {
        x: dataPoint.cx,
        y: dataPoint.cy,
        value: dataPoint.y,
        errorVal: dataPoint[dataKey],
      };
    }

    function dataPointFormatterX(dataPoint, dataKey) {
      return {
        x: dataPoint.cx,
        y: dataPoint.cy,
        value: dataPoint.x,
        errorVal: dataPoint[dataKey],
      };
    }

    return errorBarItems.map((item, i) => {
      const { direction } = item.props;

      return React.cloneElement(item, {
        key: i,
        data: points,
        xAxis,
        yAxis,
        layout: direction === 'x' ? 'vertical' : 'horizontal',
        dataPointFormatter: direction === 'x' ? dataPointFormatterX : dataPointFormatterY,
      });
    });
  }

  renderLine() {
    const { points, line, lineType, lineJointType } = this.props;
    const scatterProps = getPresentationAttributes(this.props);
    const customLineProps = getPresentationAttributes(line);
    let linePoints, lineItem;

    if (lineType === 'joint') {
      linePoints = points.map(entry => ({ x: entry.cx, y: entry.cy }));
    }
    const lineProps = {
      ...scatterProps,
      fill: 'none',
      stroke: scatterProps && scatterProps.fill,
      ...customLineProps,
      points: linePoints,
    };

    if (React.isValidElement(line)) {
      lineItem = React.cloneElement(line, lineProps);
    } else if (_.isFunction(line)) {
      lineItem = line(lineProps);
    } else {
      lineItem = <Curve {...lineProps} type={lineJointType} />;
    }

    return (
      <Layer className="recharts-scatter-line" key="recharts-scatter-line">
        {lineItem}
      </Layer>
    );
  }

  render() {
    const { points, line, className } = this.props;

    if (!points || !points.length) { return null; }

    const layerClass = classNames('recharts-scatter', className);

    return (
      <Layer className={layerClass}>
        {line && this.renderLine()}
        {this.renderErrorBar()}
        <Layer key="recharts-scatter-symbols">
          {this.renderSymbols()}
        </Layer>
      </Layer>
    );
  }
}

export default Scatter;
<|endoftext|>


<commit_before>import {uniq, isEmpty} from 'lodash';
import sortFolderContentFields from './sortFolderContentFields';
import DICTIONARY_LANGS from './../constants/dictionaryLangs';
import trimFractionLeadingZeros from './../helpers/trimFractionLeadingZeros';

export const FIELD_PAGE_NUM = 'page-num';
export const FIELD_CATEGORY = 'category';
export const FIELD_SECT = 'sect';
export const FIELD_EXPLANATION_NOTE = 'explanation-note';
export const FIELD_EXPLANATION_SOURCE = 'explanation-source';
export const FIELD_EXPLANATION_CATEGORY = 'explanation-category';

export const RE_SOURCE_ENTRY = /^source-entry-(.+)$/;
export const RE_EXPLANATION = /^explanation-(.+)$/;
export const RE_EXPLANATION_NOTE = /^explanation-note$/;
export const RE_EXPLANATION_CATEGORY = /^explanation-category$/;

const getSourceLang = (key) => {
  const [, lang] = key.match(RE_SOURCE_ENTRY) || [];
  return validLangs.includes(lang) ? lang : null;
};

const getExplanationLang = (key) => {
  const [, lang] = key.match(RE_EXPLANATION) || [];
  return validLangs.includes(lang) ? lang : null;
};

const isArrayField = (key) => {
  return [RE_EXPLANATION, RE_EXPLANATION_NOTE, RE_EXPLANATION_CATEGORY].some((re) => re.exec(key));
};

const validLangs = DICTIONARY_LANGS.map((row) => row.value);

export default class CsvProcessor {

  static isColumnRow(data) {
    return data.some((key) => {
      const sourceLanguage = getSourceLang(key);
      return !! sourceLanguage;
    });
  }

  static getColumnData(data) {

    const result = data.reduce((columnData, key, index) => {

      const sourceLanguage = getSourceLang(key);

      if (sourceLanguage) {
        columnData.sourceLanguage = sourceLanguage;
      }

      const explanationLanguage = getExplanationLang(key);

      if (explanationLanguage) {
        columnData.targetLanguages.push(explanationLanguage);
        columnData.contentFields.push(`explanation-lang-${explanationLanguage}`);
      }

      if (FIELD_PAGE_NUM === key) {
        columnData.contentFields.push(FIELD_PAGE_NUM);
      }

      return columnData;

    }, {sourceLanguage: '', targetLanguages: [], contentFields: []});

    result.targetLanguages = uniq(result.targetLanguages);
    result.contentFields = sortFolderContentFields(result.contentFields);

    return result;
  }

  static getFields(data) {

    return data.reduce((fields, key, index) => {

      const sourceLanguage = getSourceLang(key);
      const explanationLanguage = getExplanationLang(key);

      if (sourceLanguage) {
        fields[index] = 'sourceEntry';
      }
      else if (explanationLanguage) {
        fields[index] = `explanation-${explanationLanguage}`;
      }
      else if (FIELD_EXPLANATION_NOTE === key) {
        fields[index] = FIELD_EXPLANATION_NOTE;
      }
      else if (FIELD_EXPLANATION_SOURCE === key) {
        fields[index] = FIELD_EXPLANATION_SOURCE;
      }
      else if (FIELD_EXPLANATION_CATEGORY === key) {
        fields[index] = FIELD_EXPLANATION_CATEGORY;
      }
      else if (FIELD_PAGE_NUM === key) {
        fields[index] = FIELD_PAGE_NUM;
      }
      else {
        // unknown columns
        fields[index] = undefined;
      }
      return fields;
    }, []);
  }

  static getRowDataByFields(data, fields) {
    return fields.reduce((rowData, field, index) => {
      if (field) {

        if (FIELD_EXPLANATION_CATEGORY === field) {
          const value = data[index];
          rowData[field] = value ? [value.split(',').map(Number)] : [[]];
        }
        else if (isArrayField(field)) {
          rowData[field] = [data[index]]
        }
        else {
          rowData[field] = data[index];
        }
      }
      return rowData;
    }, {});
  }

  static appendData(newData, oldData, fields) {

    return fields.reduce((oldData, field, index) => {

      if (isArrayField(field)) {
        const arr = oldData[field];
        const value = newData[index];

        if (value && (FIELD_EXPLANATION_CATEGORY === field)) {
          arr.push(value.split(',').map(Number));
        }
        else if (value) {
          arr.push(value);
        }
      }
      return oldData;
    }, oldData);
  }

  // for csv export
  static getCsvRowsByEntry({folder, entry}) {

    const {sourceLanguage, contentFields} = folder.data;
    const defaultData = {
      [`source-entry-${sourceLanguage}`]: entry.sourceEntry
    };

    let hasHandledExplanationNote = false;
    let hasHandledExplanationSource = false;
    let hasHandledExplanationCategory = false;

    return contentFields.reduce((rows, field) => {

      if (FIELD_PAGE_NUM === field) {
        rows[0][FIELD_PAGE_NUM] = trimFractionLeadingZeros(entry.pageNum);
      }

      if (FIELD_CATEGORY === field) {
        rows[0][FIELD_CATEGORY] = entry.data.category;
      }

      if (FIELD_SECT === field) {
        rows[0][FIELD_SECT] = entry.data.sect;
      }

      const [, targetEntryLang] = field.match(/^target-entry-lang-(.+)$/) || [];

      if (targetEntryLang) {
        rows[0][`target-entry-${targetEntryLang}`] = entry.data[`target-entry-${targetEntryLang}`];
      }

      const [, originalLang] = field.match(/^original-lang-(.+)$/) || [];

      if (originalLang) {
        rows[0][`original-${originalLang}`] = entry.data[`original-${originalLang}`];
      }

      const [, explanationLang] = field.match(/^explanation-lang-(.+)$/) || [];

      if (explanationLang) {
        (entry.data[`explanation-${explanationLang}`] || []).forEach((explanation, index) => {
          if (isEmpty(rows[index])) {
            rows[index] = {};
          }
          rows[index][`explanation-${explanationLang}`] = explanation;
        });

        if (! hasHandledExplanationNote) {
          const notes = entry.data[FIELD_EXPLANATION_NOTE] || [];
          notes.forEach((note, index) => {
            if (isEmpty(rows[index])) {
              rows[index] = {};
            }
            rows[index][FIELD_EXPLANATION_NOTE] = note;
          });
          hasHandledExplanationNote = true;
        }

        if (! hasHandledExplanationSource) {
          const sources = entry.data[FIELD_EXPLANATION_SOURCE] || [];
          sources.forEach((source, index) => {
            if (isEmpty(rows[index])) {
              rows[index] = {};
            }
            rows[index][FIELD_EXPLANATION_SOURCE] = source;
          });
          hasHandledExplanationSource = true;
        }

        if (! hasHandledExplanationCategory) {
          const categories = entry.data[FIELD_EXPLANATION_CATEGORY] || [];
          categories.forEach((category, index) => {
            if (isEmpty(rows[index])) {
              rows[index] = {};
            }
            rows[index][FIELD_EXPLANATION_CATEGORY] = category;
          });
          hasHandledExplanationCategory = true;
        }
      }

      return rows;
    }, [defaultData])
  }
}
<commit_msg>add const RE_TARGET_ENTRY<commit_after>import {uniq, isEmpty} from 'lodash';
import sortFolderContentFields from './sortFolderContentFields';
import DICTIONARY_LANGS from './../constants/dictionaryLangs';
import trimFractionLeadingZeros from './../helpers/trimFractionLeadingZeros';

export const FIELD_PAGE_NUM = 'page-num';
export const FIELD_CATEGORY = 'category';
export const FIELD_SECT = 'sect';
export const FIELD_EXPLANATION_NOTE = 'explanation-note';
export const FIELD_EXPLANATION_SOURCE = 'explanation-source';
export const FIELD_EXPLANATION_CATEGORY = 'explanation-category';

export const RE_SOURCE_ENTRY = /^source-entry-(.+)$/;
export const RE_TARGET_ENTRY = /^target-entry-(.+)$/;
export const RE_EXPLANATION = /^explanation-(.+)$/;
export const RE_EXPLANATION_NOTE = /^explanation-note$/;
export const RE_EXPLANATION_CATEGORY = /^explanation-category$/;

const getSourceLang = (key) => {
  const [, lang] = key.match(RE_SOURCE_ENTRY) || [];
  return validLangs.includes(lang) ? lang : null;
};

const getExplanationLang = (key) => {
  const [, lang] = key.match(RE_EXPLANATION) || [];
  return validLangs.includes(lang) ? lang : null;
};

const isArrayField = (key) => {
  return [RE_EXPLANATION, RE_EXPLANATION_NOTE, RE_EXPLANATION_CATEGORY].some((re) => re.exec(key));
};

const validLangs = DICTIONARY_LANGS.map((row) => row.value);

export default class CsvProcessor {

  static isColumnRow(data) {
    return data.some((key) => {
      const sourceLanguage = getSourceLang(key);
      return !! sourceLanguage;
    });
  }

  static getColumnData(data) {

    const result = data.reduce((columnData, key, index) => {

      const sourceLanguage = getSourceLang(key);

      if (sourceLanguage) {
        columnData.sourceLanguage = sourceLanguage;
      }

      const explanationLanguage = getExplanationLang(key);

      if (explanationLanguage) {
        columnData.targetLanguages.push(explanationLanguage);
        columnData.contentFields.push(`explanation-lang-${explanationLanguage}`);
      }

      if (FIELD_PAGE_NUM === key) {
        columnData.contentFields.push(FIELD_PAGE_NUM);
      }

      return columnData;

    }, {sourceLanguage: '', targetLanguages: [], contentFields: []});

    result.targetLanguages = uniq(result.targetLanguages);
    result.contentFields = sortFolderContentFields(result.contentFields);

    return result;
  }

  static getFields(data) {

    return data.reduce((fields, key, index) => {

      const sourceLanguage = getSourceLang(key);
      const explanationLanguage = getExplanationLang(key);

      if (sourceLanguage) {
        fields[index] = 'sourceEntry';
      }
      else if (explanationLanguage) {
        fields[index] = `explanation-${explanationLanguage}`;
      }
      else if (FIELD_EXPLANATION_NOTE === key) {
        fields[index] = FIELD_EXPLANATION_NOTE;
      }
      else if (FIELD_EXPLANATION_SOURCE === key) {
        fields[index] = FIELD_EXPLANATION_SOURCE;
      }
      else if (FIELD_EXPLANATION_CATEGORY === key) {
        fields[index] = FIELD_EXPLANATION_CATEGORY;
      }
      else if (FIELD_PAGE_NUM === key) {
        fields[index] = FIELD_PAGE_NUM;
      }
      else {
        // unknown columns
        fields[index] = undefined;
      }
      return fields;
    }, []);
  }

  static getRowDataByFields(data, fields) {
    return fields.reduce((rowData, field, index) => {
      if (field) {

        if (FIELD_EXPLANATION_CATEGORY === field) {
          const value = data[index];
          rowData[field] = value ? [value.split(',').map(Number)] : [[]];
        }
        else if (isArrayField(field)) {
          rowData[field] = [data[index]]
        }
        else {
          rowData[field] = data[index];
        }
      }
      return rowData;
    }, {});
  }

  static appendData(newData, oldData, fields) {

    return fields.reduce((oldData, field, index) => {

      if (isArrayField(field)) {
        const arr = oldData[field];
        const value = newData[index];

        if (value && (FIELD_EXPLANATION_CATEGORY === field)) {
          arr.push(value.split(',').map(Number));
        }
        else if (value) {
          arr.push(value);
        }
      }
      return oldData;
    }, oldData);
  }

  // for csv export
  static getCsvRowsByEntry({folder, entry}) {

    const {sourceLanguage, contentFields} = folder.data;
    const defaultData = {
      [`source-entry-${sourceLanguage}`]: entry.sourceEntry
    };

    let hasHandledExplanationNote = false;
    let hasHandledExplanationSource = false;
    let hasHandledExplanationCategory = false;

    return contentFields.reduce((rows, field) => {

      if (FIELD_PAGE_NUM === field) {
        rows[0][FIELD_PAGE_NUM] = trimFractionLeadingZeros(entry.pageNum);
      }

      if (FIELD_CATEGORY === field) {
        rows[0][FIELD_CATEGORY] = entry.data.category;
      }

      if (FIELD_SECT === field) {
        rows[0][FIELD_SECT] = entry.data.sect;
      }

      const [, targetEntryLang] = field.match(/^target-entry-lang-(.+)$/) || [];

      if (targetEntryLang) {
        rows[0][`target-entry-${targetEntryLang}`] = entry.data[`target-entry-${targetEntryLang}`];
      }

      const [, originalLang] = field.match(/^original-lang-(.+)$/) || [];

      if (originalLang) {
        rows[0][`original-${originalLang}`] = entry.data[`original-${originalLang}`];
      }

      const [, explanationLang] = field.match(/^explanation-lang-(.+)$/) || [];

      if (explanationLang) {
        (entry.data[`explanation-${explanationLang}`] || []).forEach((explanation, index) => {
          if (isEmpty(rows[index])) {
            rows[index] = {};
          }
          rows[index][`explanation-${explanationLang}`] = explanation;
        });

        if (! hasHandledExplanationNote) {
          const notes = entry.data[FIELD_EXPLANATION_NOTE] || [];
          notes.forEach((note, index) => {
            if (isEmpty(rows[index])) {
              rows[index] = {};
            }
            rows[index][FIELD_EXPLANATION_NOTE] = note;
          });
          hasHandledExplanationNote = true;
        }

        if (! hasHandledExplanationSource) {
          const sources = entry.data[FIELD_EXPLANATION_SOURCE] || [];
          sources.forEach((source, index) => {
            if (isEmpty(rows[index])) {
              rows[index] = {};
            }
            rows[index][FIELD_EXPLANATION_SOURCE] = source;
          });
          hasHandledExplanationSource = true;
        }

        if (! hasHandledExplanationCategory) {
          const categories = entry.data[FIELD_EXPLANATION_CATEGORY] || [];
          categories.forEach((category, index) => {
            if (isEmpty(rows[index])) {
              rows[index] = {};
            }
            rows[index][FIELD_EXPLANATION_CATEGORY] = category;
          });
          hasHandledExplanationCategory = true;
        }
      }

      return rows;
    }, [defaultData])
  }
}
<|endoftext|>


<commit_before>'use babel';

import fs from 'fs-plus';
import FileUtils from './file/file-utils';
import path from 'path';

export default class ProjectConfig {

    static masterAppUpdated() {
        var updated = atom.config.get('ysp.masterAppUpdated');
        if (updated == 1) {
            return true;
        } else {
            return false;
        }
    }

    static setMasterAppUpdated(updated) {
        var value;
        if (updated == true) {
            value = 1;
        } else {
            value = 0;
        }
        atom.config.set('ysp.masterAppUpdated', value);
    }

    static quickDebug() {
        var b = atom.config.get('ysp.quickDebug');
        if (b == 1) {
            return true;
        } else {
            return false;
        }
    }

    static setQuickDebug(b) {
        var value;
        if (b == true) {
            value = 1;
        } else {
            value = 0;
        }
        atom.config.set('ysp.quickDebug', value);
    }

    static getProjectConfigJson() {
        var projectConfigPath = path.join(FileUtils.rootPath(), 'project.json')
        var configContent = fs.readFileSync(projectConfigPath);
        var json = JSON.parse(configContent);
        return json;
    }

    static saveProjectConfigJson(json) {
        var projectConfigPath = path.join(FileUtils.rootPath(), 'project.json')
        fs.writeFileSync(projectConfigPath, JSON.stringify(json));
    }

    static androidBuildToolsURL() {
        try {
            var json = ProjectConfig.getProjectConfigJson();
            return json.androidBuildToolsURL;

        } catch (e) {
            console.log('androidBuildToolsURL err:' + e);
            return "";
        }
    }
    static setAndroidBuildToolsURL(val) {
        try {
            var json = ProjectConfig.getProjectConfigJson();
            json.androidBuildToolsURL = val;
            ProjectConfig.saveProjectConfigJson(json);

        } catch (e) {
            console.log('setAndroidBuildToolsURL err:' + e);
        }
    }
    static masterAndroidAppUpdateURL() {
        try {
            var json = ProjectConfig.getProjectConfigJson();
            return json.androidAppUrl;

        } catch (e) {
            console.log('masterAppUpdateURL err:' + e);
            return "";
        }
    }
    static setMasterAndroidAppUpdateURL(val) {
        try {
            var json = ProjectConfig.getProjectConfigJson();
            json.androidAppUrl = val;
            ProjectConfig.saveProjectConfigJson(json);

        } catch (e) {
            console.log('setMasterAppUpdateURL err:' + e);
        }
    }
    static masteriOSAppUpdateURL() {
        try {
            var json = ProjectConfig.getProjectConfigJson();
            return json.iosAppUrl;

        } catch (e) {
            console.log('masterAppUpdateURL err:' + e);
            return "";
        }
    }
    static setMasteriOSAppUpdateURL(val) {
        try {
            var json = ProjectConfig.getProjectConfigJson();
            json.iosAppUrl = val;
            ProjectConfig.saveProjectConfigJson(json);

        } catch (e) {
            console.log('setMasterAppUpdateURL err:' + e);
        }
    }

    static iosBundleId() {
        try {
            var json = ProjectConfig.getProjectConfigJson();

            return json.iosBundleId;

        } catch (e) {
            console.log('iosBundleId err:' + e);
            return "";
        }
    }
    static setIosBundleId(val) {
        try {
            var json = ProjectConfig.getProjectConfigJson();
            json.iosBundleId = val;
            ProjectConfig.saveProjectConfigJson(json);

        } catch (e) {
            console.log('setIosBundleId err:' + e);
        }
    }

    static androidPackage() {
        try {
            var json = ProjectConfig.getProjectConfigJson();

            return json.androidPackageName;

        } catch (e) {
            console.log('androidPackage err:' + e);
            return "";
        }
    }
    static setAndroidPackage(val) {
        try {
            var json = ProjectConfig.getProjectConfigJson();
            json.androidPackageName = val;
            ProjectConfig.saveProjectConfigJson(json);

        } catch (e) {
            console.log('setAndroidPackage err:' + e);
        }
    }

    static androidScheme() {
        try {
            var json = ProjectConfig.getProjectConfigJson();

            return json.androidScheme;

        } catch (e) {
            console.log('androidScheme err:' + e);
            return "";
        }
    }
    static setAndroidScheme(val) {
        try {
            var json = ProjectConfig.getProjectConfigJson();
            json.androidScheme = val;
            ProjectConfig.saveProjectConfigJson(json);

        } catch (e) {
            console.log('setAndroidScheme err:' + e);
        }
    }

    static iosScheme() {
        try {
            var json = ProjectConfig.getProjectConfigJson();

            return json.iosScheme;

        } catch (e) {
            console.log('iosScheme err:' + e);
            return "";
        }
    }
    static setIosScheme(val) {
        try {
            var json = ProjectConfig.getProjectConfigJson();
            json.iosScheme = val;
            ProjectConfig.saveProjectConfigJson(json);

        } catch (e) {
            console.log('setIosScheme err:' + e);
        }
    }

    static androidAppFileName() {
        try {
            var json = ProjectConfig.getProjectConfigJson();

            return json.androidAppFileName;

        } catch (e) {
            console.log('androidAppFileName err:' + e);
            return "";
        }
    }
    static setAndroidAppFileName(val) {
        try {
            var json = ProjectConfig.getProjectConfigJson();
            json.androidAppFileName = val;
            ProjectConfig.saveProjectConfigJson(json);

        } catch (e) {
            console.log('setAndroidAppFileName err:' + e);
        }
    }

    static iosAppFileName() {
        try {
            var json = ProjectConfig.getProjectConfigJson();

            return json.iosAppFileName;

        } catch (e) {
            console.log('iosAppFileName err:' + e);
            return "";
        }
    }
    static setIosAppFileName(val) {
        try {
            var json = ProjectConfig.getProjectConfigJson();
            json.iosAppFileName = val;
            ProjectConfig.saveProjectConfigJson(json);

        } catch (e) {
            console.log('setIosAppFileName err:' + e);
        }
    }
    static isRuniOS() {
      try {
          var json = ProjectConfig.getProjectConfigJson();

          return json.isRuniOS;

      } catch (e) {
          console.log('isRuniOS err:' + e);
      }
    }
    static setIsRuniOS(val) {
      try {
          var json = ProjectConfig.getProjectConfigJson();
          json.isRuniOS = val;
          ProjectConfig.saveProjectConfigJson(json);

      } catch (e) {
          console.log('setIsRuniOS err:' + e);
      }
    }
    static isRunAndroid() {
      try {
          var json = ProjectConfig.getProjectConfigJson();

          return json.isRunAndroid;

      } catch (e) {
          console.log('isRunAndroid err:' + e);
      }
    }
    static setIsRunAndroid(val) {
      try {
          var json = ProjectConfig.getProjectConfigJson();
          json.isRunAndroid = val;
          ProjectConfig.saveProjectConfigJson(json);

      } catch (e) {
          console.log('setIsRunAndroid err:' + e);
      }
    }
}
<commit_msg>增加默认设置，默认iOS和Android都编译<commit_after>'use babel';

import fs from 'fs-plus';
import FileUtils from './file/file-utils';
import path from 'path';

export default class ProjectConfig {

    static masterAppUpdated() {
        var updated = atom.config.get('ysp.masterAppUpdated');
        if (updated == 1) {
            return true;
        } else {
            return false;
        }
    }

    static setMasterAppUpdated(updated) {
        var value;
        if (updated == true) {
            value = 1;
        } else {
            value = 0;
        }
        atom.config.set('ysp.masterAppUpdated', value);
    }

    static quickDebug() {
        var b = atom.config.get('ysp.quickDebug');
        if (b == 1) {
            return true;
        } else {
            return false;
        }
    }

    static setQuickDebug(b) {
        var value;
        if (b == true) {
            value = 1;
        } else {
            value = 0;
        }
        atom.config.set('ysp.quickDebug', value);
    }

    static getProjectConfigJson() {
        var projectConfigPath = path.join(FileUtils.rootPath(), 'project.json')
        var configContent = fs.readFileSync(projectConfigPath);
        var json = JSON.parse(configContent);
        return json;
    }

    static saveProjectConfigJson(json) {
        var projectConfigPath = path.join(FileUtils.rootPath(), 'project.json')
        fs.writeFileSync(projectConfigPath, JSON.stringify(json));
    }

    static androidBuildToolsURL() {
        try {
            var json = ProjectConfig.getProjectConfigJson();
            return json.androidBuildToolsURL;

        } catch (e) {
            console.log('androidBuildToolsURL err:' + e);
            return "";
        }
    }
    static setAndroidBuildToolsURL(val) {
        try {
            var json = ProjectConfig.getProjectConfigJson();
            json.androidBuildToolsURL = val;
            ProjectConfig.saveProjectConfigJson(json);

        } catch (e) {
            console.log('setAndroidBuildToolsURL err:' + e);
        }
    }
    static masterAndroidAppUpdateURL() {
        try {
            var json = ProjectConfig.getProjectConfigJson();
            return json.androidAppUrl;

        } catch (e) {
            console.log('masterAppUpdateURL err:' + e);
            return "";
        }
    }
    static setMasterAndroidAppUpdateURL(val) {
        try {
            var json = ProjectConfig.getProjectConfigJson();
            json.androidAppUrl = val;
            ProjectConfig.saveProjectConfigJson(json);

        } catch (e) {
            console.log('setMasterAppUpdateURL err:' + e);
        }
    }
    static masteriOSAppUpdateURL() {
        try {
            var json = ProjectConfig.getProjectConfigJson();
            return json.iosAppUrl;

        } catch (e) {
            console.log('masterAppUpdateURL err:' + e);
            return "";
        }
    }
    static setMasteriOSAppUpdateURL(val) {
        try {
            var json = ProjectConfig.getProjectConfigJson();
            json.iosAppUrl = val;
            ProjectConfig.saveProjectConfigJson(json);

        } catch (e) {
            console.log('setMasterAppUpdateURL err:' + e);
        }
    }

    static iosBundleId() {
        try {
            var json = ProjectConfig.getProjectConfigJson();

            return json.iosBundleId;

        } catch (e) {
            console.log('iosBundleId err:' + e);
            return "";
        }
    }
    static setIosBundleId(val) {
        try {
            var json = ProjectConfig.getProjectConfigJson();
            json.iosBundleId = val;
            ProjectConfig.saveProjectConfigJson(json);

        } catch (e) {
            console.log('setIosBundleId err:' + e);
        }
    }

    static androidPackage() {
        try {
            var json = ProjectConfig.getProjectConfigJson();

            return json.androidPackageName;

        } catch (e) {
            console.log('androidPackage err:' + e);
            return "";
        }
    }
    static setAndroidPackage(val) {
        try {
            var json = ProjectConfig.getProjectConfigJson();
            json.androidPackageName = val;
            ProjectConfig.saveProjectConfigJson(json);

        } catch (e) {
            console.log('setAndroidPackage err:' + e);
        }
    }

    static androidScheme() {
        try {
            var json = ProjectConfig.getProjectConfigJson();

            return json.androidScheme;

        } catch (e) {
            console.log('androidScheme err:' + e);
            return "";
        }
    }
    static setAndroidScheme(val) {
        try {
            var json = ProjectConfig.getProjectConfigJson();
            json.androidScheme = val;
            ProjectConfig.saveProjectConfigJson(json);

        } catch (e) {
            console.log('setAndroidScheme err:' + e);
        }
    }

    static iosScheme() {
        try {
            var json = ProjectConfig.getProjectConfigJson();

            return json.iosScheme;

        } catch (e) {
            console.log('iosScheme err:' + e);
            return "";
        }
    }
    static setIosScheme(val) {
        try {
            var json = ProjectConfig.getProjectConfigJson();
            json.iosScheme = val;
            ProjectConfig.saveProjectConfigJson(json);

        } catch (e) {
            console.log('setIosScheme err:' + e);
        }
    }

    static androidAppFileName() {
        try {
            var json = ProjectConfig.getProjectConfigJson();

            return json.androidAppFileName;

        } catch (e) {
            console.log('androidAppFileName err:' + e);
            return "";
        }
    }
    static setAndroidAppFileName(val) {
        try {
            var json = ProjectConfig.getProjectConfigJson();
            json.androidAppFileName = val;
            ProjectConfig.saveProjectConfigJson(json);

        } catch (e) {
            console.log('setAndroidAppFileName err:' + e);
        }
    }

    static iosAppFileName() {
        try {
            var json = ProjectConfig.getProjectConfigJson();

            return json.iosAppFileName;

        } catch (e) {
            console.log('iosAppFileName err:' + e);
            return "";
        }
    }
    static setIosAppFileName(val) {
        try {
            var json = ProjectConfig.getProjectConfigJson();
            json.iosAppFileName = val;
            ProjectConfig.saveProjectConfigJson(json);

        } catch (e) {
            console.log('setIosAppFileName err:' + e);
        }
    }
    static isRuniOS() {
      try {
          var json = ProjectConfig.getProjectConfigJson();
          if (json.isRuniOS == undefined) {
              return true;
          } else {
              return json.isRuniOS;
          }

      } catch (e) {
          console.log('isRuniOS err:' + e);
      }
    }
    static setIsRuniOS(val) {
      try {
          var json = ProjectConfig.getProjectConfigJson();
          json.isRuniOS = val;
          ProjectConfig.saveProjectConfigJson(json);

      } catch (e) {
          console.log('setIsRuniOS err:' + e);
      }
    }
    static isRunAndroid() {
      try {
          var json = ProjectConfig.getProjectConfigJson();
          if (json.isRunAndroid == undefined) {
              return true;
          } else {
              return json.isRunAndroid;
          }

      } catch (e) {
          console.log('isRunAndroid err:' + e);
      }
    }
    static setIsRunAndroid(val) {
      try {
          var json = ProjectConfig.getProjectConfigJson();
          json.isRunAndroid = val;
          ProjectConfig.saveProjectConfigJson(json);

      } catch (e) {
          console.log('setIsRunAndroid err:' + e);
      }
    }
}
<|endoftext|>


<commit_before>var ImagesUpload = {

	dropzone: null,
	activeWatch: null,

	init: function(){
		this.initDropzone();
	},

	initDropzone: function() {
		console.log("Dropzone: init");
		var that = this;
		var dropzoneOptions = {
			previewTemplate: '

',
			thumbnailWidth: 180,
			thumbnailHeight: 180,
			maxFilesize: 1,
			parallelUploads: 1,
			clickable: '.trigger',
			dictDefaultMessage: "Drop ici mec",
			url: "server/images/",
			resize: function(file) {
				var resizeInfo = {
					srcX: 0,
					srcY: 0,
					trgX: 0,
					trgY: 0,
					srcWidth: file.width,
					srcHeight: file.height,
					trgWidth: this.options.thumbnailWidth,
					trgHeight: parseInt(this.options.thumbnailWidth * file.height / file.width)
				};

				var imageRatio = file.width / file.height;
				var targetRadio = this.options.thumbnailWidth / this.options.thumbnailHeight;
				if(imageRatio !== targetRadio) {
					console.log("Dropzone: Remove file (image ratio is " + imageRatio +" instead of "+ targetRadio + ")");
					TipManager.createTip({type:"error",icon:"×",text:"The image must be "+this.options.thumbnailWidth+"×"+this.options.thumbnailHeight+" or an equivalent ratio"});
					this.removeFile(file);
				} else {
					that.imageProcess(file);
				}
				return resizeInfo;
			}
		};

		this.dropzone = new Dropzone(".dropzone", dropzoneOptions);
		this.dropzone.previewsContainer = this.activeWatch.find(".preview-zone")[0];
		this.bindDropZoneEvents();
	},

	bindDropZoneEvents: function() {
		var that = this;
		this.dropzone.on("drop", function(file) {
			console.log("Dropzone: drop");
			$('.dropzone').css({"z-index": "3" });
			that.activeWatch.find('.preview-zone').removeClass('active');
		});
		this.dropzone.on("dragenter", function() {
			console.log("Dropzone: dragenter");
			$('.dropzone').css({"z-index": "10" });
			that.activeWatch.find('.preview-zone').addClass('active');
		});
		this.dropzone.on("dragleave", function() {
			console.log("Dropzone: dragleave");
			$('.dropzone').css({"z-index": "3" });
			that.activeWatch.find('.preview-zone').removeClass('active');
		});
		this.dropzone.on("canceled", function() {
			console.log("Dropzone: canceled");
		});
		this.dropzone.on("error", function() {
			console.log("Dropzone: Error when adding file");
		});
		this.dropzone.on("complete", function(file) { //addedfile or //complete
			console.log("Dropzone: File added with the status", file.status);
		});
	},

	imageProcess: function(file) {
		var that = this;
		var returnedElem = $(file.previewElement);
		 if($(that.dropzone.previewsContainer).children().length > 1)
			$(that.dropzone.previewsContainer).children().first().remove()

		var ditherOptions = {
			"step": 1,
			"algorithm": Pixebble.options.ditherAlgorithmSelect.val(),
			"className": "dithered",
			"palette": pebbleColors()
		};
		if(that.activeWatch.data('title') == "pog") ditherOptions.palette = [[0,0,0],[255,255,255]];
		that.ditherImage(returnedElem.find('img'), ditherOptions);
		TipManager.createTip({type:"success",icon:"✔",text:"Image uploaded", delay: 1500});
	},

	clickWatch: function(event, element) {
		if(this.activeWatch.get(0) === $(element).get(0)) $('.trigger').click();
		this.activeWatch.removeClass("active");
		$(element).addClass('active');
		this.activeWatch = $(element);

		if(this.dropzone !== null) {
			this.dropzone.previewsContainer = this.activeWatch.find(".preview-zone")[0];
			this.dropzone.options.thumbnailWidth = parseInt(this.activeWatch.data("thumbnail-width"));
			this.dropzone.options.thumbnailHeight = parseInt(this.activeWatch.data("thumbnail-height"));
		}
	},

	ditherImage: function(element, ditherOptions) {
		var that = this;
		new DitherJS(element.get(0), ditherOptions, function(dataUrl){
			that.postImage(dataUrl, that);
		});
	},

	postImage: function(dataUrl, that) {
		$.ajax({
			  type: "POST",
			  url: "server/images/",
			  data: {
				 imgBase64: dataUrl,
				 userId: UsersManager.getLocalUserId(),
				 width: that.dropzone.options.thumbnailWidth,
				 height: that.dropzone.options.thumbnailHeight,
			  },
			  success : function(response) {
			  	Gallery.addImage(response.data);
			  }
			});
	}
};<commit_msg>feat(Upload): Display a popup when the file is not an image<commit_after>var ImagesUpload = {

	dropzone: null,
	activeWatch: null,

	init: function(){
		this.initDropzone();
	},

	initDropzone: function() {
		console.log("Dropzone: init");
		var that = this;
		var dropzoneOptions = {
			previewTemplate: '

',
			thumbnailWidth: 180,
			thumbnailHeight: 180,
			maxFilesize: 1,
			parallelUploads: 1,
			clickable: '.trigger',
			dictDefaultMessage: "Drop ici mec",
			url: "server/images/",
			resize: function(file) {
				var resizeInfo = {
					srcX: 0,
					srcY: 0,
					trgX: 0,
					trgY: 0,
					srcWidth: file.width,
					srcHeight: file.height,
					trgWidth: this.options.thumbnailWidth,
					trgHeight: parseInt(this.options.thumbnailWidth * file.height / file.width)
				};

				var imageRatio = file.width / file.height;
				var targetRadio = this.options.thumbnailWidth / this.options.thumbnailHeight;
				if(imageRatio !== targetRadio) {
					console.log("Dropzone: Remove file (image ratio is " + imageRatio +" instead of "+ targetRadio + ")");
					TipManager.createTip({type:"error",icon:"×",text:"The image must be "+this.options.thumbnailWidth+"×"+this.options.thumbnailHeight+" or an equivalent ratio"});
					this.removeFile(file);
				} else {
					that.imageProcess(file);
				}
				return resizeInfo;
			}
		};

		this.dropzone = new Dropzone(".dropzone", dropzoneOptions);
		this.dropzone.previewsContainer = this.activeWatch.find(".preview-zone")[0];
		this.bindDropZoneEvents();
	},

	bindDropZoneEvents: function() {
		var that = this;
		this.dropzone.on("drop", function(file) {
			console.log("Dropzone: drop");
			$('.dropzone').css({"z-index": "3" });
			that.activeWatch.find('.preview-zone').removeClass('active');
		});
		this.dropzone.on("dragenter", function() {
			console.log("Dropzone: dragenter");
			$('.dropzone').css({"z-index": "10" });
			that.activeWatch.find('.preview-zone').addClass('active');
		});
		this.dropzone.on("dragleave", function() {
			console.log("Dropzone: dragleave");
			$('.dropzone').css({"z-index": "3" });
			that.activeWatch.find('.preview-zone').removeClass('active');
		});
		this.dropzone.on("canceled", function() {
			console.log("Dropzone: canceled");
		});
		this.dropzone.on("error", function() {
			console.log("Dropzone: Error when adding file");
			TipManager.createTip({type:"error",icon:"×",text:"Error when adding file.
Are you sure the file is an image ?", delay: 4500});
		});
		this.dropzone.on("complete", function(file) { //addedfile or //complete
			console.log("Dropzone: File added with the status", file.status);
		});
	},

	imageProcess: function(file) {
		var that = this;
		var returnedElem = $(file.previewElement);
		 if($(that.dropzone.previewsContainer).children().length > 1)
			$(that.dropzone.previewsContainer).children().first().remove()

		var ditherOptions = {
			"step": 1,
			"algorithm": Pixebble.options.ditherAlgorithmSelect.val(),
			"className": "dithered",
			"palette": pebbleColors()
		};
		if(that.activeWatch.data('title') == "pog") ditherOptions.palette = [[0,0,0],[255,255,255]];
		that.ditherImage(returnedElem.find('img'), ditherOptions);
		TipManager.createTip({type:"success",icon:"✔",text:"Image uploaded", delay: 1500});
	},

	clickWatch: function(event, element) {
		if(this.activeWatch.get(0) === $(element).get(0)) $('.trigger').click();
		this.activeWatch.removeClass("active");
		$(element).addClass('active');
		this.activeWatch = $(element);

		if(this.dropzone !== null) {
			this.dropzone.previewsContainer = this.activeWatch.find(".preview-zone")[0];
			this.dropzone.options.thumbnailWidth = parseInt(this.activeWatch.data("thumbnail-width"));
			this.dropzone.options.thumbnailHeight = parseInt(this.activeWatch.data("thumbnail-height"));
		}
	},

	ditherImage: function(element, ditherOptions) {
		var that = this;
		new DitherJS(element.get(0), ditherOptions, function(dataUrl){
			that.postImage(dataUrl, that);
		});
	},

	postImage: function(dataUrl, that) {
		$.ajax({
			  type: "POST",
			  url: "server/images/",
			  data: {
				 imgBase64: dataUrl,
				 userId: UsersManager.getLocalUserId(),
				 width: that.dropzone.options.thumbnailWidth,
				 height: that.dropzone.options.thumbnailHeight,
			  },
			  success : function(response) {
			  	Gallery.addImage(response.data);
			  }
			});
	}
};<|endoftext|>


<commit_before>define(function(require, exports, module) {
  "use strict";

  var cc = require("../cc");

  var isDemandInput = function(unit, index) {
    var fromUnit = unit.fromUnits[index];
    return fromUnit && fromUnit.calcRate === C.DEMAND;
  };

  var demand_input_a = function(unit, index, offset) {
    var fromUnit = unit.fromUnits[index];
    if (fromUnit) {
      switch (fromUnit.calcRate) {
      case C.AUDIO:
        return unit.inputs[index][offset-1];
      case C.DEMAND:
        fromUnit.process(offset);
        /* fall through */
      default:
        return unit.inputs[index][0];
      }
    } else {
      return unit.inputs[index][0];
    }
  };

  var resetDemandInput = function(unit, index) {
    var fromUnit = unit.fromUnits[index];
    if (fromUnit && fromUnit.calcRate === C.DEMAND) {
      fromUnit.process(0);
    }
  };

  cc.ugen.specs.Demand = {
    Klass: cc.MultiOutUGen,
    $ar: {
      defaults: "trig=0,reset=0,demandUGens=[]",
      ctor: function(trig, reset, demandUGens) {
        return this.multiNewList([C.AUDIO, trig, reset].concat(demandUGens));
      }
    },
    $kr: {
      defaults: "trig=0,reset=0,demandUGens=[]",
      ctor: function(trig, reset, demandUGens) {
        return this.multiNewList([C.CONTROL, trig, reset].concat(demandUGens));
      }
    },
    init: function() {
      return this.initOutputs(this.inputs.length - 2, this.rate);
    },
    checkInputs: cc.ugen.checkSameRateAsFirstInput
  };

  cc.unit.specs.Demand = (function() {
    var ctor = function() {
      this.process = next;
      this._prevtrig  = 0;
      this._prevreset = 0;
      this._prevout   = new Float32Array(this.numOfOutputs);
    };
    var next = function(inNumSamples) {
      var outputs = this.outputs;
      var inputs  = this.inputs;
      var trigIn  = inputs[0];
      var resetIn = inputs[1];
      var prevout = this._prevout;
      var prevtrig  = this._prevtrig;
      var prevreset = this._prevreset;
      var ztrig, zreset, x;
      var numOfInputs = this.numOfInputs;
      var j, k;

      for (var i = 0; i < inNumSamples; ++i) {
        ztrig  = trigIn[i];
        zreset = resetIn[i];
        if (zreset > 0 && prevreset <= 0) {
          for (j = 2; j < numOfInputs; ++j) {
            resetDemandInput(this, j);
          }
        }
        if (ztrig > 0 && prevtrig <= 0) {
          for (j = 2, k = 0; j < numOfInputs; ++j) {
            x = demand_input_a(this, j, i + 1);
            if (isNaN(x)) {
              x = prevout[k];
              this.done = true;
            } else {
              prevout[k] = x;
            }
            outputs[k][i] = x;
          }
        } else {
          for (j = 2, k = 0; j < numOfInputs; ++j) {
            outputs[k][i] = prevout[k];
          }
        }
        prevtrig  = ztrig;
        prevreset = zreset;
      }
      this._prevtrig  = prevtrig;
      this._prevreset = prevreset;
    };
    return ctor;
  })();

  cc.ugen.specs.Dseq = {
    $new: {
      defaults: "list=[],repeats=1",
      ctor: function(list, repeats) {
        return this.multiNewList([C.DEMAND, repeats].concat(list));
      }
    }
  };

  cc.unit.specs.Dseq = (function() {
    var ctor = function() {
      this.process = next;
      next.call(this, 0);
    };
    var next = function(inNumSamples) {
      var out = this.outputs[0];
      var x, attempts;
      if (inNumSamples) {
        if (this._repeats < 0) {
          x = demand_input_a(this, 0, inNumSamples);
          this._repeats = isNaN(x) ? 0 : Math.floor(x + 0.5);
        }
        attempts = 0;
        while (true) {
          if (this._index >= this.numOfInputs) {
            this._index = 1;
            this._repeatCount++;
          }
          if (this._repeatCount >= this._repeats) {
            out[0] = NaN;
            this._index = 1;
            return;
          }
          if (isDemandInput(this, this._index)) {
            if (this._needToResetChild) {
              this._needToResetChild = false;
              resetDemandInput(this, this._index);
            }
            x = demand_input_a(this, this._index, inNumSamples);
            if (isNaN(x)) {
              this._index++;
              this._needToResetChild = true;
            } else {
              out[0] = x;
              return;
            }
          } else {
            out[0] = demand_input_a(this, this._index, inNumSamples);
            this._index++;
            this._needToResetChild = true;
            return;
          }
          if (attempts++ > this.numOfInputs) {
            return;
          }
        }
      } else {
        this._repeats = -1;
        this._repeatCount = 0;
        this._needToResetChild = true;
        this._index = 1;
      }
    };
    return ctor;
  })();

  module.exports = {};

});
<commit_msg>Added Demand UGens<commit_after>define(function(require, exports, module) {
  "use strict";

  var cc = require("../cc");

  var isDemandInput = function(unit, index) {
    var fromUnit = unit.fromUnits[index];
    return fromUnit && fromUnit.calcRate === C.DEMAND;
  };

  var demand_input_a = function(unit, index, offset) {
    var fromUnit = unit.fromUnits[index];
    if (fromUnit) {
      switch (fromUnit.calcRate) {
      case C.AUDIO:
        return unit.inputs[index][offset-1];
      case C.DEMAND:
        fromUnit.process(offset);
        /* fall through */
      default:
        return unit.inputs[index][0];
      }
    } else {
      return unit.inputs[index][0];
    }
  };

  var resetDemandInput = function(unit, index) {
    var fromUnit = unit.fromUnits[index];
    if (fromUnit && fromUnit.calcRate === C.DEMAND) {
      fromUnit.process(0);
    }
  };

  cc.ugen.specs.Demand = {
    Klass: cc.MultiOutUGen,
    $ar: {
      defaults: "trig=0,reset=0,demandUGens=[]",
      ctor: function(trig, reset, demandUGens) {
        return this.multiNewList([C.AUDIO, trig, reset].concat(demandUGens));
      }
    },
    $kr: {
      defaults: "trig=0,reset=0,demandUGens=[]",
      ctor: function(trig, reset, demandUGens) {
        return this.multiNewList([C.CONTROL, trig, reset].concat(demandUGens));
      }
    },
    init: function() {
      return this.initOutputs(this.inputs.length - 2, this.rate);
    },
    checkInputs: cc.ugen.checkSameRateAsFirstInput
  };

  cc.unit.specs.Demand = (function() {
    var ctor = function() {
      this.process = next;
      this._prevtrig  = 0;
      this._prevreset = 0;
      this._prevout   = new Float32Array(this.numOfOutputs);
    };
    var next = function(inNumSamples) {
      var outputs = this.outputs;
      var inputs  = this.inputs;
      var trigIn  = inputs[0];
      var resetIn = inputs[1];
      var prevout = this._prevout;
      var prevtrig  = this._prevtrig;
      var prevreset = this._prevreset;
      var ztrig, zreset, x;
      var numOfInputs = this.numOfInputs;
      var j, k;

      for (var i = 0; i < inNumSamples; ++i) {
        ztrig  = trigIn[i];
        zreset = resetIn[i];
        if (zreset > 0 && prevreset <= 0) {
          for (j = 2; j < numOfInputs; ++j) {
            resetDemandInput(this, j);
          }
        }
        if (ztrig > 0 && prevtrig <= 0) {
          for (j = 2, k = 0; j < numOfInputs; ++j) {
            x = demand_input_a(this, j, i + 1);
            if (isNaN(x)) {
              x = prevout[k];
              this.done = true;
            } else {
              prevout[k] = x;
            }
            outputs[k][i] = x;
          }
        } else {
          for (j = 2, k = 0; j < numOfInputs; ++j) {
            outputs[k][i] = prevout[k];
          }
        }
        prevtrig  = ztrig;
        prevreset = zreset;
      }
      this._prevtrig  = prevtrig;
      this._prevreset = prevreset;
    };
    return ctor;
  })();

  cc.ugen.specs.Dgeom = {
    $new: {
      defaults: "start=1,grow=2,length=Infinity",
      ctor: function(start, grow, length) {
        return this.multiNew(C.DEMAND, length, start, grow);
      }
    }
  };

  cc.unit.specs.Dgeom = (function() {
    var ctor = function() {
      this.process = next;
      this._grow  = 0;
      this._value = 0;
      next.call(this, 0);
    };

    var next = function(inNumSamples) {
      var grow, x;
      if (inNumSamples) {
        grow = demand_input_a(this, 2, inNumSamples);
        if (!isNaN(grow)) {
          this._grow = grow;
        }
        if (this._repeats < 0) {
          x = demand_input_a(this, 0, inNumSamples);
          this._repeats = x|0;
          this._value   = demand_input_a(this, 1, inNumSamples);
        }
        if (this._repeatCount >= this._repeats) {
          this.outputs[0][0] = NaN;
          return;
        }
        this.outputs[0][0] = this._value;
        this._value *= this._grow;
        this._repeatCount++;
      } else {
        this._repeats = -1;
        this._repeatCount = 0;
      }
    };

    return ctor;
  })();

  cc.ugen.specs.Dseries = {
    $new: {
      defaults: "start=1,step=1,length=Infinity",
      ctor: function(start, step, length) {
        return this.multiNew(C.DEMAND, length, start, step);
      }
    }
  };

  cc.unit.specs.Dseries = (function() {
    var ctor = function() {
      this.process = next;
      this._step  = 0;
      this._value = 0;
      next.call(this, 0);
    };

    var next = function(inNumSamples) {
      var step, x;
      if (inNumSamples) {
        step = demand_input_a(this, 2, inNumSamples);
        if (!isNaN(step)) {
          this._step = step;
        }
        if (this._repeats < 0) {
          x = demand_input_a(this, 0, inNumSamples);
          this._repeats = x|0;
          this._value   = demand_input_a(this, 1, inNumSamples);
        }
        if (this._repeatCount >= this._repeats) {
          this.outputs[0][0] = NaN;
          return;
        }
        this.outputs[0][0] = this._value;
        this._value += this._step;
        this._repeatCount++;
      } else {
        this._repeats = -1;
        this._repeatCount = 0;
      }
    };

    return ctor;
  })();

  cc.ugen.specs.Dwhite = {
    $new: {
      defaults: "lo=1,hi=1,length=Infinity",
      ctor: function(lo, hi, length) {
        return this.multiNew(C.DEMAND, length, lo, hi);
      }
    }
  };

  cc.unit.specs.Dwhite = (function() {
    var ctor = function() {
      this.process = next;
      this._lo = 0;
      this._hi = 0;
      next.call(this, 0);
    };

    var next = function(inNumSamples) {
      var lo, hi, x;
      if (inNumSamples) {
        if (this._repeats < 0) {
          x = demand_input_a(this, 0, inNumSamples);
          this._repeats = x|0;
        }
        if (this._repeatCount >= this._repeats) {
          this.outputs[0][0] = NaN;
          return;
        }
        this._repeatCount++;
        lo = demand_input_a(this, 1, inNumSamples);
        hi = demand_input_a(this, 2, inNumSamples);

        if (!isNaN(lo)) { this._lo = lo; }
        if (!isNaN(hi)) { this._hi = hi; }
        this.outputs[0][0] = Math.random() * (this._hi - this._lo) + this._lo;
      } else {
        this._repeats = -1;
        this._repeatCount = 0;
      }
    };

    return ctor;
  })();

  cc.ugen.specs.Diwhite = {
    $new: {
      defaults: "lo=1,hi=1,length=Infinity",
      ctor: function(lo, hi, length) {
        return this.multiNew(C.DEMAND, length, lo, hi);
      }
    }
  };

  cc.unit.specs.Diwhite = (function() {
    var ctor = function() {
      this.process = next;
      this._lo = 0;
      this._hi = 0;
      next.call(this, 0);
    };

    var next = function(inNumSamples) {
      var lo, hi, x;
      if (inNumSamples) {
        if (this._repeats < 0) {
          x = demand_input_a(this, 0, inNumSamples);
          this._repeats = x|0;
        }
        if (this._repeatCount >= this._repeats) {
          this.outputs[0][0] = NaN;
          return;
        }
        this._repeatCount++;
        lo = demand_input_a(this, 1, inNumSamples);
        hi = demand_input_a(this, 2, inNumSamples);

        if (!isNaN(lo)) { this._lo = lo|0; }
        if (!isNaN(hi)) { this._hi = hi|0; }
        this.outputs[0][0] = (Math.random() * (this._hi - this._lo) + this._lo)|0;
      } else {
        this._repeats = -1;
        this._repeatCount = 0;
      }
    };

    return ctor;
  })();

  var ListDUGen = {
    $new: {
      defaults: "list=[],repeats=1",
      ctor: function(list, repeats) {
        return this.multiNewList([C.DEMAND, repeats].concat(list));
      }
    }
  };

  cc.ugen.specs.Dser = ListDUGen;

  cc.unit.specs.Dser = (function() {
    var ctor = function() {
      this.process = next;
      next.call(this, 0);
    };

    var next = function(inNumSamples) {
      var out = this.outputs[0];
      var x;
      if (inNumSamples) {
        if (this._repeats < 0) {
          x = demand_input_a(this, 0, inNumSamples);
          this._repeats = isNaN(x) ? 0 : Math.floor(x + 0.5);
        }
        while (true) {
          if (this._index >= this.numOfInputs) {
            this._index = 1;
          }
          if (this._repeatCount >= this._repeats) {
            out[0] = NaN;
            return;
          }
          if (isDemandInput(this, this._index)) {
            if (this._needToResetChild) {
              this._needToResetChild = false;
              resetDemandInput(this, this._index);
            }
            x = demand_input_a(this, this._index, inNumSamples);
            if (isNaN(x)) {
              this._index++;
              this._repeatCount++;
              this._needToResetChild = true;
            } else {
              out[0] = x;
              return;
            }
          } else {
            out[0] = this.inputs[this._index][0];
            this._index++;
            this._repeatCount++;
            this._needToResetChild = true;
            return;
          }
        }
      } else {
        this._repeats = -1;
        this._repeatCount = 0;
        this._needToResetChild = true;
        this._index = 1;
      }
    };

    return ctor;
  })();

  cc.ugen.specs.Dseq = ListDUGen;

  cc.unit.specs.Dseq = (function() {
    var ctor = function() {
      this.process = next;
      next.call(this, 0);
    };
    var next = function(inNumSamples) {
      var out = this.outputs[0];
      var x, attempts;
      if (inNumSamples) {
        if (this._repeats < 0) {
          x = demand_input_a(this, 0, inNumSamples);
          this._repeats = isNaN(x) ? 0 : Math.floor(x + 0.5);
        }
        attempts = 0;
        while (true) {
          if (this._index >= this.numOfInputs) {
            this._index = 1;
            this._repeatCount++;
          }
          if (this._repeatCount >= this._repeats) {
            out[0] = NaN;
            this._index = 1;
            return;
          }
          if (isDemandInput(this, this._index)) {
            if (this._needToResetChild) {
              this._needToResetChild = false;
              resetDemandInput(this, this._index);
            }
            x = demand_input_a(this, this._index, inNumSamples);
            if (isNaN(x)) {
              this._index++;
              this._needToResetChild = true;
            } else {
              out[0] = x;
              return;
            }
          } else {
            out[0] = demand_input_a(this, this._index, inNumSamples);
            this._index++;
            this._needToResetChild = true;
            return;
          }
          if (attempts++ > this.numOfInputs) {
            return;
          }
        }
      } else {
        this._repeats = -1;
        this._repeatCount = 0;
        this._needToResetChild = true;
        this._index = 1;
      }
    };
    return ctor;
  })();

  cc.ugen.specs.Dshuf = ListDUGen;

  cc.unit.specs.Dshuf = (function() {
    var ctor = function() {
      this.process = next;
      var indices = new Array(this.numOfInputs - 1);
      for (var i = 0, imax = indices.length; i < imax; ++i) {
        indices[i] = i + 1;
      }
      this._indices = indices.sort(scramble);
      next.call(this, 0);
    };
    var scramble = function() {
      return Math.random() - 0.5;
    };
    var next = function(inNumSamples) {
      var out = this.outputs[0];
      var x, attempts;
      if (inNumSamples) {
        if (this._repeats < 0) {
          x = demand_input_a(this, 0, inNumSamples);
          this._repeats = isNaN(x) ? 0 : Math.floor(x + 0.5);
        }
        attempts = 0;
        while (true) {
          if (this._index >= this.numOfInputs - 1) {
            this._index = 0;
            this._repeatCount++;
          }
          if (this._repeatCount >= this._repeats) {
            out[0] = NaN;
            this._index = 0;
            return;
          }
          var index = this._indices[this._index];
          if (isDemandInput(this, index)) {
            if (this._needToResetChild) {
              this._needToResetChild = false;
              resetDemandInput(this, index);
            }
            x = demand_input_a(this, index, inNumSamples);
            if (isNaN(x)) {
              this._index++;
              this._needToResetChild = true;
            } else {
              out[0] = x;
              return;
            }
          } else {
            out[0] = demand_input_a(this, index, inNumSamples);
            this._index++;
            this._needToResetChild = true;
            return;
          }
          if (attempts++ > this.numOfInputs) {
            return;
          }
        }
      } else {
        this._repeats = -1;
        this._repeatCount = 0;
        this._needToResetChild = true;
        this._index = 1;
      }
    };
    return ctor;
  })();

  cc.ugen.specs.Drand = ListDUGen;

  cc.unit.specs.Drand = (function() {
    var ctor = function() {
      this.process = next;
      next.call(this, 0);
    };

    var next = function(inNumSamples) {
      var out = this.outputs[0];
      var x;
      if (inNumSamples) {
        if (this._repeats < 0) {
          x = demand_input_a(this, 0, inNumSamples);
          this._repeats = isNaN(x) ? 0 : Math.floor(x + 0.5);
        }
        while (true) {
          if (this._repeatCount >= this._repeats) {
            out[0] = NaN;
            return;
          }
          if (isDemandInput(this, this._index)) {
            if (this._needToResetChild) {
              this._needToResetChild = false;
              resetDemandInput(this, this._index);
            }
            x = demand_input_a(this, this._index, inNumSamples);
            if (isNaN(x)) {
              this._index = ((Math.random() * (this.numOfInputs-1))|0)+1;
              this._repeatCount++;
              this._needToResetChild = true;
            } else {
              out[0] = x;
              return;
            }
          } else {
            out[0] = this.inputs[this._index][0];
            this._index = ((Math.random() * (this.numOfInputs-1))|0)+1;
            this._repeatCount++;
            this._needToResetChild = true;
            return;
          }
        }
      } else {
        this._repeats = -1;
        this._repeatCount = 0;
        this._needToResetChild = true;
        this._index = 1;
      }
    };

    return ctor;
  })();

  module.exports = {};

});
<|endoftext|>


<commit_before>
/*!
 * Ext JS SS Library 0.0.1
 * Copyright(c) 2006-2010 Ext JS, Inc.
 * licensing@extjs.com
 * http://www.extjs.com/license
 */

/**
 * Module dependencies.
 */

var extname = require('path').extname

/**
 * Mime type lookup table.
 */

exports.types = {
  '323'     : 'text/h323',
  '3gp'     : 'video/3gpp',
  'a'       : 'application/octet-stream',
  'acx'     : 'application/internet-property-stream',
  'ai'      : 'application/postscript',
  'aif'     : 'audio/x-aiff',
  'aifc'    : 'audio/x-aiff',
  'aiff'    : 'audio/x-aiff',
  'asc'     : 'application/pgp-signature',
  'asf'     : 'video/x-ms-asf',
  'asr'     : 'video/x-ms-asf',
  'asm'     : 'text/x-asm',
  'asx'     : 'video/x-ms-asf',
  'atom'    : 'application/atom+xml',
  'au'      : 'audio/basic',
  'avi'     : 'video/x-msvideo',
  'axs'     : 'application/olescript',
  'bas'     : 'text/plain',
  'bat'     : 'application/x-msdownload',
  'bcpio'   : 'application/x-bcpio',
  'bin'     : 'application/octet-stream',
  'bmp'     : 'image/bmp',
  'bz2'     : 'application/x-bzip2',
  'c'       : 'text/x-c',
  'cab'     : 'application/vnd.ms-cab-compressed',
  'cat'     : 'application/vnd.ms-pkiseccat',
  'cc'      : 'text/x-c',
  'cdf'     : 'application/x-netcdf',
  'cer'     : 'application/x-x509-ca-cert',
  'cgm'     : 'image/cgm',
  'chm'     : 'application/vnd.ms-htmlhelp',
  'class'   : 'application/octet-stream',
  'clp'     : 'application/x-msclip',
  'cmx'     : 'image/x-cmx',
  'cod'     : 'image/cis-cod',
  'com'     : 'application/x-msdownload',
  'conf'    : 'text/plain',
  'cpio'    : 'application/x-cpio',
  'cpp'     : 'text/x-c',
  'cpt'     : 'application/mac-compactpro',
  'crd'     : 'application/x-mscardfile',
  'crl'     : 'application/pkix-crl',
  'crt'     : 'application/x-x509-ca-cert',
  'csh'     : 'application/x-csh',
  'css'     : 'text/css',
  'csv'     : 'text/csv',
  'cxx'     : 'text/x-c',
  'dcr'     : 'application/x-director',
  'deb'     : 'application/x-debian-package',
  'der'     : 'application/x-x509-ca-cert',
  'diff'    : 'text/x-diff',
  'dir'     : 'application/x-director',
  'djv'     : 'image/vnd.djvu',
  'djvu'    : 'image/vnd.djvu',
  'dll'     : 'application/x-msdownload',
  'dmg'     : 'application/octet-stream',
  'dms'     : 'application/octet-stream',
  'doc'     : 'application/msword',
  'dot'     : 'application/msword',
  'dtd'     : 'application/xml-dtd',
  'dv'      : 'video/x-dv',
  'dvi'     : 'application/x-dvi',
  'dxr'     : 'application/x-director',
  'ear'     : 'application/java-archive',
  'eml'     : 'message/rfc822',
  'eps'     : 'application/postscript',
  'etx'     : 'text/x-setext',
  'evy'     : 'application/envoy',
  'exe'     : 'application/x-msdownload',
  'ez'      : 'application/andrew-inset',
  'f'       : 'text/x-fortran',
  'f77'     : 'text/x-fortran',
  'f90'     : 'text/x-fortran',
  'fif'     : 'application/fractals',
  'flr'     : 'x-world/x-vrml',
  'flv'     : 'video/x-flv',
  'for'     : 'text/x-fortran',
  'gem'     : 'application/octet-stream',
  'gemspec' : 'text/x-script.ruby',
  'gif'     : 'image/gif',
  'gram'    : 'application/srgs',
  'grxml'   : 'application/srgs+xml',
  'gtar'    : 'application/x-gtar',
  'gz'      : 'application/x-gzip',
  'h'       : 'text/x-c',
  'hdf'     : 'application/x-hdf',
  'hh'      : 'text/x-c',
  'hlp'     : 'application/winhlp',
  'hqx'     : 'application/mac-binhex40',
  'hta'     : 'application/hta',
  'htc'     : 'text/x-component',
  'htm'     : 'text/html',
  'html'    : 'text/html',
  'htt'     : 'text/webviewhtml',
  'ice'     : 'x-conference/x-cooltalk',
  'ico'     : 'image/vnd.microsoft.icon',
  'ics'     : 'text/calendar',
  'ief'     : 'image/ief',
  'ifb'     : 'text/calendar',
  'iges'    : 'model/iges',
  'igs'     : 'model/iges',
  'iii'     : 'application/x-iphone',
  'ins'     : 'application/x-internet-signup',
  'isp'     : 'application/x-internet-signup',
  'iso'     : 'application/octet-stream',
  'jar'     : 'application/java-archive',
  'java'    : 'text/x-java-source',
  'jfif'    : 'image/pipeg',
  'jnlp'    : 'application/x-java-jnlp-file',
  'jp2'     : 'image/jp2',
  'jpe'     : 'image/jpeg',
  'jpeg'    : 'image/jpeg',
  'jpg'     : 'image/jpeg',
  'js'      : 'application/javascript',
  'json'    : 'application/json',
  'kar'     : 'audio/midi',
  'latex'   : 'application/x-latex',
  'lha'     : 'application/octet-stream',
  'lsf'     : 'video/x-la-asf',
  'lsx'     : 'video/x-la-asf',
  'lzh'     : 'application/octet-stream',
  'log'     : 'text/plain',
  'm13'     : 'application/x-msmediaview',
  'm14'     : 'application/x-msmediaview',
  'm3u'     : 'audio/x-mpegurl',
  'm4a'     : 'audio/mp4a-latm',
  'm4b'     : 'audio/mp4a-latm',
  'm4p'     : 'audio/mp4a-latm',
  'm4u'     : 'video/vnd.mpegurl',
  'm4v'     : 'video/mp4',
  'mac'     : 'image/x-macpaint',
  'man'     : 'text/troff',
  'mathml'  : 'application/mathml+xml',
  'mbox'    : 'application/mbox',
  'mdb'     : 'application/x-msaccess',
  'mdoc'    : 'text/troff',
  'me'      : 'text/troff',
  'mesh'    : 'model/mesh',
  'mht'     : 'message/rfc822',
  'mhtml'   : 'message/rfc822',
  'mid'     : 'audio/midi',
  'midi'    : 'audio/midi',
  'mif'     : 'application/vnd.mif',
  'mime'    : 'message/rfc822',
  'mml'     : 'application/mathml+xml',
  'mng'     : 'video/x-mng',
  'mny'     : 'application/x-msmoney',
  'mov'     : 'video/quicktime',
  'movie'   : 'video/x-sgi-movie',
  'mp2'     : 'video/mpeg',
  'mp3'     : 'audio/mpeg',
  'mp4'     : 'video/mp4',
  'mp4v'    : 'video/mp4',
  'mpa'     : 'video/mpeg',
  'mpe'     : 'video/mpeg',
  'mpeg'    : 'video/mpeg',
  'mpg'     : 'video/mpeg',
  'mpga'    : 'audio/mpeg',
  'mpp'     : 'application/vnd.ms-project',
  'mpv2'    : 'video/mpeg',
  'ms'      : 'text/troff',
  'msh'     : 'model/mesh',
  'msi'     : 'application/x-msdownload',
  'mvb'     : 'application/x-msmediaview',
  'mxu'     : 'video/vnd.mpegurl',
  'nc'      : 'application/x-netcdf',
  'nws'     : 'message/rfc822',
  'oda'     : 'application/oda',
  'odp'     : 'application/vnd.oasis.opendocument.presentation',
  'ods'     : 'application/vnd.oasis.opendocument.spreadsheet',
  'odt'     : 'application/vnd.oasis.opendocument.text',
  'ogg'     : 'application/ogg',
  'p'       : 'text/x-pascal',
  'p10'     : 'application/pkcs10',
  'p12'     : 'application/x-pkcs12',
  'p7b'     : 'application/x-pkcs7-certificates',
  'p7c'     : 'application/x-pkcs7-mime',
  'p7m'     : 'application/x-pkcs7-mime',
  'p7r'     : 'application/x-pkcs7-certreqresp',
  'p7s'     : 'application/x-pkcs7-signature',
  'pas'     : 'text/x-pascal',
  'pbm'     : 'image/x-portable-bitmap',
  'pct'     : 'image/pict',
  'pdb'     : 'chemical/x-pdb',
  'pdf'     : 'application/pdf',
  'pem'     : 'application/x-x509-ca-cert',
  'pfx'     : 'application/x-pkcs12',
  'pgm'     : 'image/x-portable-graymap',
  'pgn'     : 'application/x-chess-pgn',
  'pgp'     : 'application/pgp-encrypted',
  'pic'     : 'image/pict',
  'pict'    : 'image/pict',
  'pkg'     : 'application/octet-stream',
  'pko'     : 'application/ynd.ms-pkipko',
  'pl'      : 'text/x-script.perl',
  'pm'      : 'text/x-script.perl-module',
  'pma'     : 'application/x-perfmon',
  'pmc'     : 'application/x-perfmon',
  'pml'     : 'application/x-perfmon',
  'pmr'     : 'application/x-perfmon',
  'pmw'     : 'application/x-perfmon',
  'png'     : 'image/png',
  'pnm'     : 'image/x-portable-anymap',
  'pnt'     : 'image/x-macpaint',
  'pntg'    : 'image/x-macpaint',
  'pot'     : 'application/vnd.ms-powerpoint',
  'ppm'     : 'image/x-portable-pixmap',
  'pps'     : 'application/vnd.ms-powerpoint',
  'ppt'     : 'application/vnd.ms-powerpoint',
  'prf'     : 'application/pics-rules',
  'ps'      : 'application/postscript',
  'psd'     : 'image/vnd.adobe.photoshop',
  'pub'     : 'application/x-mspublisher',
  'py'      : 'text/x-script.python',
  'qt'      : 'video/quicktime',
  'qti'     : 'image/x-quicktime',
  'qtif'    : 'image/x-quicktime',
  'ra'      : 'audio/x-pn-realaudio',
  'rake'    : 'text/x-script.ruby',
  'ram'     : 'audio/x-pn-realaudio',
  'rar'     : 'application/x-rar-compressed',
  'ras'     : 'image/x-cmu-raster',
  'rb'      : 'text/x-script.ruby',
  'rdf'     : 'application/rdf+xml',
  'rgb'     : 'image/x-rgb',
  'rm'      : 'application/vnd.rn-realmedia',
  'rmi'     : 'audio/mid',
  'roff'    : 'text/troff',
  'rpm'     : 'application/x-redhat-package-manager',
  'rss'     : 'application/rss+xml',
  'rtf'     : 'application/rtf',
  'rtx'     : 'text/richtext',
  'ru'      : 'text/x-script.ruby',
  's'       : 'text/x-asm',
  'scd'     : 'application/x-msschedule',
  'sct'     : 'text/scriptlet',
  'setpay'  : 'application/set-payment-initiation',
  'setreg'  : 'application/set-registration-initiation',
  'sgm'     : 'text/sgml',
  'sgml'    : 'text/sgml',
  'sh'      : 'application/x-sh',
  'shar'    : 'application/x-shar',
  'sig'     : 'application/pgp-signature',
  'silo'    : 'model/mesh',
  'sit'     : 'application/x-stuffit',
  'skd'     : 'application/x-koan',
  'skm'     : 'application/x-koan',
  'skp'     : 'application/x-koan',
  'skt'     : 'application/x-koan',
  'smi'     : 'application/smil',
  'smil'    : 'application/smil',
  'snd'     : 'audio/basic',
  'so'      : 'application/octet-stream',
  'spc'     : 'application/x-pkcs7-certificates',
  'spl'     : 'application/x-futuresplash',
  'src'     : 'application/x-wais-source',
  'sst'     : 'application/vnd.ms-pkicertstore',
  'stl'     : 'application/vnd.ms-pkistl',
  'stm'     : 'text/html',
  'sv4cpio' : 'application/x-sv4cpio',
  'sv4crc'  : 'application/x-sv4crc',
  'svg'     : 'image/svg+xml',
  'svgz'    : 'image/svg+xml',
  'swf'     : 'application/x-shockwave-flash',
  't'       : 'text/troff',
  'tar'     : 'application/x-tar',
  'tbz'     : 'application/x-bzip-compressed-tar',
  'tcl'     : 'application/x-tcl',
  'tex'     : 'application/x-tex',
  'texi'    : 'application/x-texinfo',
  'texinfo' : 'application/x-texinfo',
  'text'    : 'text/plain',
  'tgz'     : 'application/x-compressed',
  'tif'     : 'image/tiff',
  'tiff'    : 'image/tiff',
  'torrent' : 'application/x-bittorrent',
  'tr'      : 'text/troff',
  'trm'     : 'application/x-msterminal',
  'tsv'     : 'text/tab-seperated-values',
  'txt'     : 'text/plain',
  'uls'     : 'text/iuls',
  'ustar'   : 'application/x-ustar',
  'vcd'     : 'application/x-cdlink',
  'vcf'     : 'text/x-vcard',
  'vcs'     : 'text/x-vcalendar',
  'vrml'    : 'model/vrml',
  'vxml'    : 'application/voicexml+xml',
  'war'     : 'application/java-archive',
  'wav'     : 'audio/x-wav',
  'wbmp'    : 'image/vnd.wap.wbmp',
  'wbxml'   : 'application/vnd.wap.wbxml',
  'wcm'     : 'application/vnd.ms-works',
  'wdb'     : 'application/vnd.ms-works',
  'wks'     : 'application/vnd.ms-works',
  'wma'     : 'audio/x-ms-wma',
  'wmf'     : 'application/x-msmetafile',
  'wml'     : 'text/vnd.wap.wml',
  'wmls'    : 'text/vnd.wap.wmlscript',
  'wmlsc'   : 'application/vnd.wap.wmlscriptc',
  'wmv'     : 'video/x-ms-wmv',
  'wmx'     : 'video/x-ms-wmx',
  'wps'     : 'application/vnd.ms-works',
  'wri'     : 'application/x-mswrite',
  'wrl'     : 'model/vrml',
  'wrz'     : 'x-world/x-vrml',
  'wsdl'    : 'application/wsdl+xml',
  'xaf'     : 'x-world/x-vrml',
  'xbm'     : 'image/x-xbitmap',
  'xht'     : 'application/xhtml+xml',
  'xhtml'   : 'application/xhtml+xml',
  'xla'     : 'application/vnd.ms-excel',
  'xlc'     : 'application/vnd.ms-excel',
  'xlm'     : 'application/vnd.ms-excel',
  'xls'     : 'application/vnd.ms-excel',
  'xlt'     : 'application/vnd.ms-excel',
  'xml'     : 'application/xml',
  'xof'     : 'x-world/x-vrml',
  'xpm'     : 'image/x-xpixmap',
  'xsl'     : 'application/xml',
  'xslt'    : 'application/xslt+xml',
  'xul'     : 'application/vnd.mozilla.xul+xml',
  'xwd'     : 'image/x-xwindowdump',
  'xyz'     : 'chemical/x-xyz',
  'yaml'    : 'text/yaml',
  'yml'     : 'text/yaml',
  'z'       : 'application/x-compress',
  'zip'     : 'application/zip'
}

/**
 * Return the mime type associated with the given path,
 * where path may be an extension, or filename.
 *
 * By default 'application/octet-stream' is returned.
 *
 *     var mime = require('ext/mime')
 *     mime.type('png')               // => 'image/png'
 *     mime.type('.png')              // => 'image/png'
 *     mime.type('image.png')         // => 'image/png'
 *     mime.type('path/to/image.png') // => 'image/png'
 *
 * @param  {String} path
 * @return {String}
 * @api public
 */

exports.type = function(path) {
    return exports.types[path]
           || exports.types[extname(path).substr(1)]
           || 'application/octet-stream'
}
<commit_msg>Remove a broken symlink.<commit_after><|endoftext|>


<commit_before>/**
 * Created by Kavi on 4/5/16.
 */
const querystring = require('querystring');

Template.viewClient.events(
  {
    'click .edit'(evt, tmpl) {
      const query = {};
      if (tmpl.data.isHMISClient) {
        query.query = 'isHMISClient=true';
      }
      Router.go('adminDashboardclientsEdit', { _id: tmpl.data._id }, query);
    },
    'click .back'() {
      Router.go('adminDashboardclientsView');
    },
    'click .add-to-hmis'(event, tmpl) {
      Meteor.call(
        'addClientToHMIS', tmpl.data._id, (error, result) => {
          if (error) {
            logger.log(error);
          } else {
            let query = 'addClientToHMISError=1';
            let clientId = tmpl.data._id;
            if (result) {
              const params = {
                addedToHMIS: 1,
                isHMISClient: true,
                link: result.link,
              };
              clientId = result._id;
              query = querystring.stringify(params);
            }

            Router.go('viewClient', { _id: clientId }, { query });
          }
        }
      );
    },
    'click .takeSurvey'(event, tmpl) {
      const query = {};

      if (Router.current().params && Router.current().params.query
        && Router.current().params.query.isHMISClient && Router.current().params.query.link) {
        const url = encodeURIComponent(Router.current().params.query.link);
        query.query = {
          isHMISClient: true,
          link: url,
        };
      }

      Router.go('selectSurvey', { _id: tmpl.data._id }, query);
    },
  }
);
<commit_msg>collapse siebar on viewClient page<commit_after>/**
 * Created by Kavi on 4/5/16.
 */
const querystring = require('querystring');

Template.viewClient.onRendered(() => {
  $('body').addClass('sidebar-collapse');
});

Template.viewClient.onDestroyed(() => {
  $('body').removeClass('sidebar-collapse');
});

Template.viewClient.events(
  {
    'click .edit'(evt, tmpl) {
      const query = {};
      if (tmpl.data.isHMISClient) {
        query.query = 'isHMISClient=true';
      }
      Router.go('adminDashboardclientsEdit', { _id: tmpl.data._id }, query);
    },
    'click .back'() {
      Router.go('adminDashboardclientsView');
    },
    'click .add-to-hmis'(event, tmpl) {
      Meteor.call(
        'addClientToHMIS', tmpl.data._id, (error, result) => {
          if (error) {
            logger.log(error);
          } else {
            let query = 'addClientToHMISError=1';
            let clientId = tmpl.data._id;
            if (result) {
              const params = {
                addedToHMIS: 1,
                isHMISClient: true,
                link: result.link,
              };
              clientId = result._id;
              query = querystring.stringify(params);
            }

            Router.go('viewClient', { _id: clientId }, { query });
          }
        }
      );
    },
    'click .takeSurvey'(event, tmpl) {
      const query = {};

      if (Router.current().params && Router.current().params.query
        && Router.current().params.query.isHMISClient && Router.current().params.query.link) {
        const url = encodeURIComponent(Router.current().params.query.link);
        query.query = {
          isHMISClient: true,
          link: url,
        };
      }

      Router.go('selectSurvey', { _id: tmpl.data._id }, query);
    },
  }
);
<|endoftext|>


<commit_before><commit_msg>Fix incorrect array index verification. Fix not returning on error, when show is not found.<commit_after><|endoftext|>