Пример #1
0
function mapKeyValuesDeep (cb, obj, key) {
  if (_.isArray(obj)) {
    return _.mapValues((val, key) => mapKeyValuesDeep(cb, val, key), obj)
  } else if (_.isObject(obj)) {
    return _.pickBy((val, key) => mapKeyValuesDeep(cb, val, key), obj)
  } else {
    return cb(obj, key)
  }
}
Пример #2
0
        const columns = this.props.columns.map((columnName, index) => {
            const rowValue = getValueAfterValueTypeGuess(this.props.dataSource, columnName);
            let displayValue;

            // Render objects by name or otherwise by their toString method.
            // ReactElements are also objects but we want to render them out normally, so they are excluded.
            if (isObject(rowValue) && !isValidElement(rowValue)) {
                displayValue = rowValue.displayName || rowValue.name || rowValue.toString();
            } else {
                displayValue = rowValue;
            }

            // TODO: PublicAccess Hack - need to make it so that value transformers can be registered
            if (columnName === 'publicAccess') {
                const dataSource = this.props.dataSource;

                if (dataSource[columnName]) {
                    if (dataSource[columnName] === 'rw------') {
                        displayValue = this.getTranslation('public_can_edit');
                    }

                    if (dataSource[columnName] === 'r-------') {
                        displayValue = this.getTranslation('public_can_view');
                    }

                    if (dataSource[columnName] === '--------') {
                        displayValue = this.getTranslation('public_none');
                    }
                }
            }

            const textWrapStyle = {
                width: '100%',
                textOverflow: 'ellipsis',
                overflow: 'hidden',
                whiteSpace: 'nowrap',
                position: 'absolute',
                wordBreak: 'break-all',
                wordWrap: 'break-word',
                top: 0,
                bottom: 0,
                lineHeight: '50px',
                paddingRight: '1rem',
            };

            return (
                <div
                    key={index}
                    className={'data-table__rows__row__column'}
                    onContextMenu={this.handleContextClick}
                    onClick={this.handleClick}
                >
                    {isString(displayValue) ? <span title={displayValue} style={textWrapStyle} >{displayValue}</span> : displayValue}
                </div>
            );
        });
Пример #3
0
 const getOptions = function(name, options) {
     return fp.defaults({
         dirname: mycro._appPath + '/' + name,
         filter:  /(.+)\.js$/,
         excludeDirs:  /^\.(git|svn)$/,
         keepDirectoryPath: true,
         flattenDirectories: true,
         optional: true
     }, fp.isObject(options) ? options : {});
 };
Пример #4
0
function deepClone(obj) {
  if (!existy(obj) || !isObject(obj)) {
    return obj
  }

  const temp = new obj.constructor()

  each(obj, (value, key) => {
    if (obj.hasOwnProperty(key)) {
      temp[key] = deepClone(obj[key])
    }
  })

  return temp
}
Пример #5
0
module.exports = function containers(done) {
    const mycro = this;

    // ensure appPath present
    const appPath = mycro._appPath;
    if (!fp.isString(appPath)) {
        return process.nextTick(function() {
            const err = new Error('Mycro is missing required "_appPath" variable');
            done(err);
        });
    }

    // determine appropriate hook configuration
    const defaultConfig = require('./defaults');
    const userConfig = fp.get('config.containers', mycro);
    const config = fp.isObject(userConfig) ? userConfig : defaultConfig;

    const getOptions = function(name, options) {
        return fp.defaults({
            dirname: mycro._appPath + '/' + name,
            filter:  /(.+)\.js$/,
            excludeDirs:  /^\.(git|svn)$/,
            keepDirectoryPath: true,
            flattenDirectories: true,
            optional: true
        }, fp.isObject(options) ? options : {});
    };

    // loop keys in configuration and load containers
    Object.keys(config).forEach(function(name) {
        const options = getOptions(name, config[name]);
        const container = fp.mapValues(function(mod) {
            if (fp.isFunction(mod)) {
                return mod(mycro);
            }
            return mod;
        }, include(options));
        if (Object.keys(container).length > 0) {
            mycro[name] = fp.merge(mycro[name], container);
        }
    }, {});

    process.nextTick(done);
};
Пример #6
0
 return function(done) {
     const findConnection = createFindConnection(mycro);
     const models = fp.isObject(mycro.models) ? mycro.models : {};
     const keys = Object.keys(models);
     if (keys.length === 0) {
         return process.nextTick(done);
     }
     async.each(keys, function(key, next) {
         const connection = findConnection(key);
         if (!connection) {
             mycro.log('info', `[mycro-adapters] Unable to locate connection for model: ${key}`);
             return async.setImmediate(next.bind(null, new Error(`Unable to locate connection for model: ${key}`)));
         }
         const registerModel = connection.adapter.registerModel;
         registerModel(connection.connection, models[key], function(err, model) {
             if (err) {
                 mycro.log('error', `[mycro-adapters] Error registering model: ${key}`);
                 return next(err);
             }
             mycro.models[key] = model;
             next();
         });
     }, done);
 };
Пример #7
0
const aMap = obj => isObject(obj)
Пример #8
0
const removeEmptyObjects = omitBy(o => isObject(o) && isEmpty(o));