export function finalUrlsDomain (final_urls) {
  const finalUrl = head(final_urls)

  if (!isString(finalUrl)) return null

  const urlParts = finalUrl
    .replace(/.*?:\/\//g, '')
    .split('/')

  return head(urlParts)
}
示例#2
0
  it('concatenates topojson objects together, in order', () => {
    const expectedNumGeometries = reduce(geo.objects, (accum, object) => (
      accum + object.geometries.length
    ), 0);

    const concatenated = concatTopoJSON(geo.objects, ['country', 'states']);
    expect(concatenated).to.be.an('object')
      .with.property('geometries')
      .that.is.an('array')
      .of.length(expectedNumGeometries);

    expect(head(concatenated.geometries)).to.equal(head(geo.objects.country.geometries));
    expect(last(concatenated.geometries)).to.equal(last(geo.objects.states.geometries));
  });
示例#3
0
  render () {
    const {status, checked, feedItemId, sitelinkLine2, sitelinkLine3, sitelinkText, sitelinkFinalUrls: {urls}} = this.props
    const divProps = {
      className: 'mdl-list__item mdl-list__item--three-line',
      key: feedItemId
    }

    if (status !== 'ENABLED') {
      divProps.style = {opacity: 0.7}
      divProps.title = status
    }

    return (
      <div {...divProps}>
        <div className='mdl-list__item-primary-content'>
          <a href={head(urls)} target='_blank'>
            {sitelinkText}
          </a>
          <div className='mdl-list__item-text-body'>
            {sitelinkLine2}
            <br/>
            {sitelinkLine3}
          </div>
        </div>
        <div className='mdl-list__item-secondary-content'>
          <Checkbox
            checked={checked}
            onChange={this.onChange}
            name={`feed-item-${feedItemId}`}/>
        </div>
      </div>
    )
  }
示例#4
0
  /**
   * Shows the child options that pass the filter.
   * @param {Function} filter - Function that takes a child option and
   * returns whether to show the option or not.
   * @private
   */
  _showChildOptions(filter) {
    const currentSelectedOption = this.child.options[this.child.selectedIndex];

    // remove all options
    Array.from(this.child.children).forEach(child => {
      this.child.removeChild(child);
    });

    // Loop through all possible child options and check whether
    // to display them or not. We need to save whether the selection
    // of the select box needs to change. This happens if the selected
    // option won't get displayed in the new select box.
    let needToChangeSelection = true;
    this.childOptions.forEach(childOption => {
      if (filter(childOption)) {
        this.child.appendChild(childOption);
        childOption.selected = false;

        if (childOption === currentSelectedOption) {
          needToChangeSelection = false;
        }
      }
    });

    // select the first option in the select box if we need
    // to change the selection
    if (needToChangeSelection) {
      this._selectOption(head(this.child.options));
    } else {
      currentSelectedOption.selected = true;
    }
  }
示例#5
0
    /**
     * create 3d polygonal airspace
     *
     * @for AirportModel
     * @method buildAirportAirspace
     * @param airspace
     */
    buildAirportAirspace(airspace) {
        if (!airspace) {
            return;
        }

        // for each area
        this.airspace = _map(airspace, (airspaceSection) => {
            return new AirspaceModel(
                airspaceSection,
                this._positionModel,
                this._positionModel.magneticNorth
            );
        });

        // airspace perimeter (assumed to be first entry in data.airspace)
        this.perimeter = _head(this.airspace);
        this.ctr_radius = Math.max(
            ..._map(this.perimeter.poly, (vertexPosition) => vlen(
                vsub(
                    vertexPosition.relativePosition,
                    DynamicPositionModel.calculateRelativePosition(
                        this.rangeRings.center,
                        this._positionModel,
                        this.magneticNorth
                    )
                )
            ))
        );
    }
  render () {
    const {onChange, close, suggestedUrl} = this.props
    const biddable = this.props.criterion_use === 'BIDDABLE'
    const finalUrl = head(this.props.final_urls) || ''

    return (
      <div>
        <div className='mdl-grid'>
          <div className='mdl-cell mdl-cell--12-col'>
            <h5>{this.props.text}</h5>
            <br/>

            <Select name='status' label='keywordStatus' text='status' value={this.props.status} onChange={onChange}>
              {map(statuses[this.props.criterion_use], currentStatus =>
                <option key={currentStatus} value={currentStatus}>
                  {capitalize(currentStatus)}
                </option>)}
            </Select>
          </div>

          {biddable && (
            <div className='mdl-cell mdl-cell--12-col'>
              <Input
                type='number'
                format='currency'
                name='cpc_bid'
                label='cpcBid'
                value={pickBid(this.props.cpc_bid)}
                onChange={onChange}/>
            </div>)}

          {biddable && (
            <div className='mdl-cell mdl-cell--12-col'>
              <Input
                type='url'
                name='final_urls'
                label='finalUrl'
                value={finalUrl}
                onChange={onChange}/>

              {!finalUrl && suggestedUrl && (
                <p onClick={this.onClickSuggestion}>
                  <em>
                    <Message html url={suggestedUrl}>
                      suggestedUrl
                    </Message>
                  </em>
                </p>)}
            </div>)}

          <div className='mdl-cell mdl-cell--12-col' style={{textAlign: 'right'}}>
            <Button className='mdl-button' onClick={close}>
              <Message>close</Message>
            </Button>
          </div>
        </div>
      </div>
    )
  }
示例#7
0
function fileToConfig( pathParts, folderConfig = {} ) {
	const folder = head( pathParts );

	if ( folder === 'test' && pathParts.length === 2 ) {
		folderConfig[ folder ] = [ getFileName( pathParts ) ];
	} else {
		folderConfig[ folder ] = fileToConfig( tail( pathParts ) );
	}

	return folderConfig;
}
示例#8
0
文件: index.js 项目: noxee/wp-calypso
	promiseForFeedId = discover( feedUrl ).then( function( response ) {
		var feed;

		if ( ! isEmpty( response.feeds ) ) {
			feed = head( response.feeds );

			if ( ! isEmpty( feed.feed_ID ) ) {
				return feed.feed_ID;
			}
		}
	} );
 .then(list => {
   const sample = head(items)
   grouped[id] = {
     id,
     shared: get(sample, [level, 'shared']),
     name: get(sample, [level, 'name']),
     ids: flatten(map(list, ids)),
     openByDefault,
     list: list
   }
 })
示例#10
0
 parser.on('script', function(scriptElement, documentWrite, resume) {
   var attrs = parse5.treeAdapters.default.getAttrList(scriptElement);
   if (attrs.length) {
     var isGwjs = filter(attrs, {name: 'id'});
     if (isGwjs.length && first(isGwjs).value === 'gwjs') {
       // change the src attr
       utils.setAttribute(scriptElement, 'src', newSource);
     }
   }
   resume();
 });
示例#11
0
function mapStateToProps(state, props) {
  const { routeParams: { username, slug }} = props
  const authUser = state.authUserId ? state.entities.users[state.authUserId] : null
  
  const user = head(filter(
    state.entities.users,
    (u) => u.username === username
  ))

  const model = user ? head(filter(
    state.entities.models,
    (m) => m.userId === user.id && m.slug === slug
  )) : null

  const files = []
  if (model) {
    each(state.entities.files, (file) => {
      if (file.status === 'latest' &&
          file.modelId === model.id &&
          file.userId === user.id) {
        files.push(file)
      }
    })
  } 

  return {
    authTokenId: state.authTokenId,
    userFetching: state.userByUsername.fetching,
    userFetchError: state.userByUsername.fetchError,
    modelFetching: state.modelByUsernameAndSlug.fetching,
    modelFetchError: state.modelByUsernameAndSlug.fetchError,
    filesFetching: state.filesByUsernameAndSlug.fetching,
    filesFetchError: state.filesByUsernameAndSlug.fetchError,
    deleting: state.deleteModel.deleting,
    deleteError: state.deleteModel.deleteError,
    authUser,
    user,
    model,
    files
  }
}
示例#12
0
	it( 'should return an object with a new list of cards and deleting disabled when deleting completed', () => {
		Dispatcher.handleViewAction( {
			type: ActionTypes.STORED_CARDS_DELETE_COMPLETED,
			card: head( STORED_CARDS )
		} );

		expect( StoredCardsStore.get() ).to.be.eql( {
			isDeleting: false,
			isFetching: false,
			list: tail( STORED_CARDS )
		} );
	} );
示例#13
0
  render () {
    const {selected, openCreateModal} = this.state
    const {dispatch, params, cancel, extensions, folder} = this.props
    const apps = unionBy(
      unwrap(extensions),
      folder.apps,
      'feedItemId'
    )

    return (
      <Form onSubmit={this.save}>
        <div className='mdl-grid'>
          <div className='mdl-cell mdl-cell--12-col'>
            <div className={`mdl-list ${style.list}`}>{map(apps, ({feedItemId, appLinkText, appFinalUrls: {urls}}) =>
              <div key={feedItemId} className='mdl-list__item'>
                <a href={head(urls)} target='_blank' className='mdl-list__item-primary-content'>
                  {appLinkText}
                </a>
                <span className='mdl-list__item-secondary-action'>
                  <Checkbox
                    name={`app-${feedItemId}`}
                    value={feedItemId}
                    onChange={this.onCheck}
                    checked={includes(selected, feedItemId)}/>
                </span>
              </div>)}
            </div>
          </div>
        </div>
        <div className={style.actions}>
          <Button className='mdl-button mdl-button--raised' onClick={cancel}>
            <Message>cancel</Message>
          </Button>

          <Button className='mdl-button mdl-button--raised' onClick={this.toggleModal}>
            <Message>newApp</Message>
          </Button>
          <Submit className='mdl-button mdl-button--raised mdl-button--colored'>
            <Message>save</Message>
          </Submit>
        </div>

        {openCreateModal && (
          <Modal onEscPress={this.toggleModal}>
            <NewApp
              {...{folder, dispatch, params}}
              feedId={get(head(apps), 'feedId')}
              cancel={this.toggleModal}
              onSubmit={this.toggleModal}/>
          </Modal>)}
      </Form>
    )
  }
示例#14
0
	it( 'should return an object with the previous list of cards and deleting enabled when deleting is triggered', () => {
		Dispatcher.handleViewAction( {
			type: ActionTypes.STORED_CARDS_DELETE,
			card: head( STORED_CARDS )
		} );

		expect( StoredCardsStore.get() ).to.be.eql( {
			isDeleting: true,
			isFetching: false,
			list: STORED_CARDS
		} );
	} );
const buildTree = createTask(function builder (attributes, levels, mount = false) {
  function extend (attr) {
    attr = assign({}, attr)

    for (let i = levels.length - 1; i >= 0; i--) {
      const {id: level, mount} = levels[i]
      const levelInfo = mount(attr)

      if (levelInfo) {
        attr[level] = levelInfo
      } else {
        return null
      }
    }

    return attr
  }

  if (isEmpty(levels)) {
    return attributes
  }

  if (mount) {
    attributes = compact(map(attributes, extend))
  }

  const {id: level, openByDefault} = head(levels)
  const grouped = groupBy(attributes, `${level}.id`)
  const innerLevel = tail(levels)

  const format = (items, id) =>
    buildTree(items, innerLevel)
      .then(list => {
        const sample = head(items)
        grouped[id] = {
          id,
          shared: get(sample, [level, 'shared']),
          name: get(sample, [level, 'name']),
          ids: flatten(map(list, ids)),
          openByDefault,
          list: list
        }
      })

  return Promise.all(map(grouped, format))
    .then(() =>
      orderBy(
        grouped,
        ['shared', 'name'],
        ['desc', 'asc']
      ))
})
示例#16
0
 <div className={`mdl-list ${style.list}`}>{map(apps, ({feedItemId, appLinkText, appFinalUrls: {urls}}) =>
   <div key={feedItemId} className='mdl-list__item'>
     <a href={head(urls)} target='_blank' className='mdl-list__item-primary-content'>
       {appLinkText}
     </a>
     <span className='mdl-list__item-secondary-action'>
       <Checkbox
         name={`app-${feedItemId}`}
         value={feedItemId}
         onChange={this.onCheck}
         checked={includes(selected, feedItemId)}/>
     </span>
   </div>)}
示例#17
0
function isFileWhitelisted( config, pathParts ) {
	const folder = head( pathParts );

	if ( config[ folder ] ) {
		if ( folder === 'test' && Array.isArray( config[ folder ] ) ) {
			return ( config[ folder ].indexOf( getFileName( pathParts ) ) !== false );
		}

		return isFileWhitelisted( config[ folder ], tail( pathParts ) );
	}

	return false;
}
示例#18
0
  attributeLevels = () => {
    const {messages, report} = this.context

    return report.platform
      ? undefined
      : [{
        id: 'platform',
        openByDefault: true,
        mount ({id}) {
          const shared = !includes(id, ':')
          const platform = shared
            ? 'shared'
            : head(split(id, ':'))

          return {
            id: platform,
            shared,
            name: messages[platform + 'Level']
          }
        }
      }]
  }
示例#19
0
normalizePost.firstPassCanonicalImage = function firstPassCanonicalImage( post, callback ) {
	if ( post.featured_image ) {
		post.canonical_image = assign( {
			uri: post.featured_image,
			type: 'image'
		}, imageSizeFromAttachments( post.featured_image ) );
	} else {
		let candidate = head( filter( post.attachments, function( attachment ) {
			return startsWith( attachment.mime_type, 'image/' );
		} ) );

		if ( candidate ) {
			post.canonical_image = {
				uri: candidate.URL,
				width: candidate.width,
				height: candidate.height,
				type: 'image'
			};
		}
	}

	callback();
};
示例#20
0
 lines.map(line => first(words(line)));
示例#21
0
 resolve: (_, args) => head(populationData
    .filter(record => record.geo === args.geo && record.time === args.time))
 return map(groupBy(pullRequests, 'assignee.id'), (groupPullRequests) => ({
     ...head(groupPullRequests).assignee,
     pullRequests: groupPullRequests,
 }));
示例#23
0
 ({sitelinkText, sitelinkFinalUrls: {urls}}, index) =>
   <SubText key={index}>
     <a className='mdl-color-text--blue-grey-500' href={head(urls)} target='_blank'>
       {sitelinkText}
     </a>
   </SubText>))}