Example #1
0
 handleGroupSearch = (group_id: string) => {
   const {t} = this.props
   if (!group_id) {
     this.resetSearch()
     return
   }
   const _this = this
   debug.log(`searching for group: ${group_id}`)
   request.get(`${urlUtil.getBaseUrl()}/api/layers/group/${group_id}`)
     .type('json').accept('json')
     .end((err, res) => {
       checkClientError(res, err, (err) => {
         if (err) {
           MessageActions.showMessage({title: 'Error', message: err})
         } else {
           if (res.body.layers && res.body.layers.length > 0) {
             _this.setState({searchActive: true, searchResults: res.body.layers, selectedGroupId: group_id})
             NotificationActions.showNotification({message: res.body.layers.length + ' ' + t('Results'), position: 'topright'})
           } else {
           // show error message
             NotificationActions.showNotification({message: t('No Results Found'), dismissAfter: 5000, position: 'topright'})
           }
         }
       },
       (cb) => {
         cb()
       }
       )
     })
 }
Example #2
0
 handleSearch = (input: string) => {
   const {t} = this
   const _this = this
   debug.log('searching for: ' + input)
   request.get(urlUtil.getBaseUrl() + '/api/groups/search?q=' + input)
     .type('json').accept('json')
     .end((err, res) => {
       checkClientError(res, err, (err) => {
         if (err) {
           MessageActions.showMessage({title: t('Error'), message: err})
         } else {
           if (res.body.groups && res.body.groups.length > 0) {
             _this.setState({searchActive: true, searchResults: res.body.groups})
             NotificationActions.showNotification({message: res.body.groups.length + ' ' + t('Results'), position: 'bottomleft'})
           } else {
           // show error message
             NotificationActions.showNotification({message: t('No Results Found'), dismissAfter: 5000, position: 'bottomleft'})
           }
         }
       },
       (cb) => {
         cb()
       }
       )
     })
 }
Example #3
0
  render () {
    const {group, size, fontSize, chipWidth} = this.props
    const baseUrl = urlUtil.getBaseUrl()
    const sizeStr = size + 'px'
    const fontSizeStr = fontSize + 'px'
    const imgWidth = size.toString() + 'px'
    const chipWidthStr = chipWidth.toString() + 'px'
    const className = classNames(['chip', 'truncate', this.props.className])

    return (
      <div className={className}
        style={{height: sizeStr,
          width: chipWidthStr,
          minWidth: '75px',
          marginBottom: '2px',
          border: '0.25pt solid #E4E4E4',
          lineHeight: sizeStr,
          fontSize: fontSizeStr}}>
        <a target='_blank' className='no-padding' rel='noopener noreferrer' href={`${baseUrl}/group/${group}`} style={{height: 'initial'}}>
          <div className='valign-wrapper'
            style={{
              height: sizeStr,
              width: imgWidth,
              backgroundColor: 'white',
              marginRight: '0px',
              marginLeft: '-12px',
              float: 'left'
            }}>
            <img ref='groupimg' className='valign' src={`/img/resize/40?url=/group/${group}/thumbnail`}
              style={{
                height: sizeStr,
                width: 'auto',
                marginRight: 0,
                marginLeft: 0,
                borderRadius: 0
              }}
              alt={'Group Photo'} />
          </div>

        </a>
        <Tooltip
          title={group}
          position='top'
          inertia
          followCursor
        >
          <a target='_blank' rel='noopener noreferrer' className='omh-accent-text no-padding'
            style={{height: sizeStr, width: 'auto', display: 'inherit', lineHeight: sizeStr, fontSize: fontSizeStr}}
            href={`${baseUrl}/group/${group}`}>{group}</a>
        </Tooltip>
      </div>
    )
  }
Example #4
0
const getLayerLink = (feature, layer) => {
  const host = feature.properties.maphubs_host
  let baseUrl
  if (host && host !== 'dev.docker' && host !== window.location.hostname) {
    baseUrl = 'https://' + host
  } else {
    baseUrl = urlUtil.getBaseUrl()
  }

  const local_layer_id: string = layer.layer_id.toString() || '0'

  let layerLink
  if (host === window.location.hostname || host === 'dev.docker') {
    layerLink = `${baseUrl}/lyr/${local_layer_id}`
  } else {
    layerLink = `https://${host}/lyr/${local_layer_id}`
  }
  return layerLink
}
Example #5
0
  app.get('/group/:id', csrfProtection, async (req, res, next) => {
    try {
      const group_id = req.params.id

      let user_id = -1
      if (req.isAuthenticated && req.isAuthenticated() && req.session.user) {
        user_id = req.session.user.maphubsUser.id
      }
      const canEdit = await Group.allowedToModify(group_id, user_id)
      const group = await Group.getGroupByID(group_id)
      const maps = await Map.getGroupMaps(group_id, canEdit)
      const layers = await Layer.getGroupLayers(group_id, canEdit)
      const hubs = await Hub.getGroupHubs(group_id, canEdit)
      const members = await Group.getGroupMembers(group_id)

      if (!group) {
        return res.redirect('/notfound?path=' + req.path)
      }

      const image = urlUtil.getBaseUrl() + `/group/${group_id}/image`
      const name = Locales.getLocaleStringObject(req.locale, group.name)
      const description = Locales.getLocaleStringObject(req.locale, group.description)
      return app.next.render(req, res, '/groupinfo', await pageOptions(req, {
        title: name + ' - ' + MAPHUBS_CONFIG.productName,
        description,
        props: {
          group, maps, layers, hubs, members, canEdit
        },
        twitterCard: {
          card: 'summary',
          title: name,
          description,
          image,
          imageType: 'image/png',
          imageWidth: 600,
          imageHeight: 600
        }
      }))
    } catch (err) { nextError(next)(err) }
  })
Example #6
0
  render () {
    let linkUrl = ''
    let author = ''
    let userImage = ''
    const guessedTz = moment.tz.guess()
    const updatedTime = moment.tz(this.props.map.updated_at, guessedTz).format()

    userImage = (
      <Gravatar size={36} emailHash={this.props.map.emailhash} />

    )

    const baseUrl = urlUtil.getBaseUrl()
    linkUrl = baseUrl + '/user/' + this.props.map.username
    author = (
      <div style={{height: '40px', marginBottom: '10px'}}>
        <div className='valign-wrapper' style={{width: '36px', float: 'left'}}>
          <a className='valign' style={{marginTop: '4px'}} href={linkUrl + '/maps'}>{userImage}</a>
        </div>
        <div style={{marginLeft: '46px'}}>
          <p style={{fontSize: '14px', margin: 0, lineHeight: '1.4rem'}} className='truncate'><a className='valign' style={{marginTop: 0, marginBottom: 0, marginLeft: '5px', fontSize: '14px', lineHeight: '1.4rem'}} href={linkUrl + '/maps'}>{this.props.map.username}</a></p>
          <p style={{fontSize: '14px', margin: 0, lineHeight: '1.4rem'}}>
            <IntlProvider locale={this.state.locale}>
              <FormattedRelative value={updatedTime} />
            </IntlProvider>
          </p>
        </div>
      </div>
    )

    return (
      <div>
        {author}
      </div>
    )
  }
Example #7
0
      .then(async (story) => {
        if (!story) {
          return res.redirect('/notfound?path=' + req.path)
        }

        if (!req.session.storyviews) {
          req.session.storyviews = {}
        }
        if (!req.session.storyviews[story_id]) {
          req.session.storyviews[story_id] = 1
          Stats.addStoryView(story_id, user_id).catch(nextError(next))
        } else {
          const views = req.session.storyviews[story_id]

          req.session.storyviews[story_id] = views + 1
        }

        req.session.views = (req.session.views || 0) + 1

        if (user_id === -1) { // don't check permissions if user is not logged in
          let imageUrl = ''
          if (story.firstimage) {
            imageUrl = urlUtil.getBaseUrl() + story.firstimage
          }
          let description = story.title
          if (story.firstline) {
            description = story.firstline
          }
          if (!story.published) {
            // guest users never see draft stories
            return res.status(401).send('Unauthorized')
          } else {
            return app.next.render(req, res, '/userstory', await pageOptions(req, {
              title: story.title,
              description,
              props: {
                story, username, canEdit: false
              },
              talkComments: true,
              twitterCard: {
                title: story.title,
                description,
                image: imageUrl,
                imageType: 'image/jpeg'
              }
            }))
          }
        } else {
          return Story.allowedToModify(story_id, user_id)
            .then(async (canEdit) => {
              let imageUrl = ''
              if (story.firstimage) {
                imageUrl = story.firstimage
              }
              let description = story.title
              if (story.firstline) {
                description = story.firstline
              }

              if (!story.published && !canEdit) {
                return res.status(401).send('Unauthorized')
              } else {
                return app.next.render(req, res, '/userstory', await pageOptions(req, {
                  title: story.title,
                  description,
                  props: {
                    story, username, canEdit
                  },
                  talkComments: true,
                  twitterCard: {
                    title: story.title,
                    description,
                    image: imageUrl,
                    imageType: 'image/jpeg'
                  }
                }))
              }
            })
        }
      }).catch(nextError(next))
Example #8
0
      id: `layer-${layer_id.toString()}`,
      title: layer.name, // LocalizedString
      description: layer.description, // LocalizedString
      image_url,
      group: layer.owned_by_group_id,
      type: 'layer',
      link: '/lyr/' + layer_id,
      data: layer,
      private: layer.private,
      onClick
    }
  },

  getHubCard (hub: Object, id: number, arr: Array<Object>, onClick?: Function): CardConfig {
    const title = hub.name.replace('&nbsp;', '')
    const hubUrl = urlUtil.getBaseUrl() + '/hub/' + hub.hub_id
    return {
      id: `hub-${hub.hub_id}`,
      title,
      description: hub.description,
      group: hub.owned_by_group_id,
      image_url: `/img/resize/150?url=/hub/${hub.hub_id}/images/logo`,
      background_image_url: `/img/resize/400?url=/hub/${hub.hub_id}/images/banner/thumbnail`,
      link: hubUrl,
      type: 'hub',
      data: hub,
      private: hub.private,
      onClick
    }
  },
Example #9
0
          debug.log('found image in database for layer: ' + layer_id)
          return result[0].thumbnail
        } else {
          debug.log('no image in database for layer: ' + layer_id)
          return _this.updateLayerThumbnail(layer_id)
        }
      })
  },

  async updateLayerThumbnail (layer_id: number) {
    debug.log('updating image for layer: ' + layer_id)

    const width = 400
    const height = 300

    const maphubsUrl = urlUtil.getBaseUrl() + '/api/layer/' + layer_id + '/static/render/'
    const manetUrl = local.manetUrl

    const options = Object.assign(screenshotOptions, {
      url: maphubsUrl,
      width,
      height,
      type: 'jpeg',
      quality: 0.8
    })

    debug.log(JSON.stringify(options))

    const image = await this.base64Download(manetUrl, options)
    await knex('omh.layers').update({thumbnail: image}).where({layer_id})
    log.info('Updated Layer Thumbnail: ' + layer_id)
Example #10
0
  render () {
    const {t} = this
    const omhBaseUrl = urlUtil.getBaseUrl()

    const hubBaseUrl = omhBaseUrl + '/hub/' + this.state.hub.hub_id
    let bannerClass = 'hub-banner'
    if (this.props.subPage) {
      bannerClass = 'hub-banner-subpage'
    }
    let title = ''
    let tagline = ''
    let logoEditButton = ''
    let bannerEditButton = ''
    let imageCrop = ''

    let nameVal = null
    if (this.state.hub.name) nameVal = this.state.hub.name.replace('&nbsp;', '')
    let taglineVal = null
    if (this.state.hub.tagline) taglineVal = this.state.hub.tagline.replace('&nbsp;', '')

    if (this.props.editing) {
      title = (
        <div className='white-text text-shadow hub-title'>
          <Editor
            tag='h2'
            text={nameVal}
            onChange={this.handleTitleChange}
            options={{toolbar: false,
              placeholder: {text: t('Enter a Title for Your Hub')},
              disableReturn: true,
              buttons: []}}
          />
        </div>
      )
      tagline = (
        <div className='white-text text-shadow hub-tagline'>
          <Editor
            tag='p'
            text={taglineVal}
            onChange={this.handleTaglineChange}
            options={{toolbar: false,
              buttonLabels: false,
              placeholder: {text: t('Enter a Tagline or Subheading for Your Hub')},
              disableReturn: true,
              buttons: []}}
          />
        </div>
      )

      logoEditButton = (
        <a className='btn-floating omh-color white-text' onClick={this.showLogoEdit}
          style={{position: 'absolute', top: '-15px', left: '85px'}}>
          <i className='material-icons'>edit</i>
        </a>
      )

      bannerEditButton = (
        <a className='btn-floating omh-color white-text' onClick={this.showBannerEdit}
          style={{position: 'absolute', top: '205px', right: '10px'}}>
          <i className='material-icons'>edit</i>
        </a>
      )
      imageCrop = (
        <ImageCrop ref='imagecrop'
          aspectRatio={this.state.imageCropAspectRatio} lockAspect
          resize_max_width={this.state.imageCropResizeMaxWidth}
          resize_width={this.state.imageCropResizeWidth}
          resize_height={this.state.imageCropResizeHeight}
          onCrop={this.state.onCrop} />
      )
    } else {
      title = (
        <h2 className='white-text text-shadow no-margin'>{nameVal}</h2>
      )

      tagline = (
        <p className='white-text text-shadow no-margin'>{taglineVal}</p>
      )
    }
    let logoImage = ''
    let bannerImage = ''
    if (this.state.logoImage) { // use new image first
      logoImage = (
        <a href={hubBaseUrl}>
          <img alt={t('Hub Photo')} width='100' style={{borderRadius: '25px'}} src={this.state.logoImage} />
        </a>
      )
    } else if (this.state.hub.hasLogoImage) { // otherwise if there is an image from the server use that
      logoImage = (
        <a href={hubBaseUrl}>
          <img alt={t('Hub Photo')} width='100' style={{borderRadius: '25px'}} src={`/hub/${this.state.hub.hub_id}/images/logo`} />
        </a>
      )
    } else { // show placeholder
      logoImage = (
        <div className='center center-align valign-wrapper' style={{margin: 'auto', borderRadius: '25px', width: '100px', height: '100px', borderStyle: 'dashed', borderColor: '#bdbdbd', borderWidth: '3px'}}>
          <i className='material-icons grey-text valign'>add_a_photo</i>
          <p className='valign grey-text'>{t('Add a Logo')}</p>
        </div>
      )
    }
    if (this.state.bannerImage) {
      bannerImage = (<div className={bannerClass}
        style={{width: '100%', position: 'absolute', top: 0, backgroundImage: `url(${this.state.bannerImage.toString()})`, backgroundSize: 'cover', backgroundPosition: 'center'}} />)
    } else if (this.state.hub.hasBannerImage) {
      bannerImage = (<div className={bannerClass}
        style={{width: '100%', position: 'absolute', top: 0, backgroundImage: `url("/hub/${this.state.hub.hub_id}/images/banner")`, backgroundSize: 'cover', backgroundPosition: 'center'}} />)
    } else { // show placeholder
      bannerImage = (
        <div className='center center-align' style={{margin: 'auto', borderRadius: '25px', width: '100%', height: '100%', position: 'absolute', top: 0, borderColor: '#bdbdbd', borderStyle: 'dashed', borderWidth: '3px'}}>
          <div className='center center-align valign-wrapper' style={{margin: 'auto', height: '100%', width: '200px'}}>
            <i className='material-icons grey-text valign'>add_a_photo</i>
            <p className='valign grey-text'>{t('Add a Banner Image')}</p>
          </div>
        </div>
      )
    }

    return (
      <div>
        <div className={'row no-margin valign-wrapper ' + bannerClass} style={{position: 'relative'}}>
          {bannerImage}
          {bannerEditButton}
          <div className='row no-margin valign' style={{margin: 0, paddingLeft: '20px', width: '100%'}}>
            <div className='col s12 m1 l1 no-padding' style={{position: 'relative', minWidth: '110px'}}>
              {logoImage}
              {logoEditButton}
            </div>
            <div className='col s12 m9 l10 no-padding' style={{position: 'relative', marginTop: '20px'}}>
              {title}
              {tagline}
            </div>
          </div>
        </div>
        {imageCrop}
      </div>
    )
  }
Example #11
0
module.exports = async (req, options) => {
  let locale = 'en'
  if (req) {
    // var browserLocale = req.acceptsLanguages('en', 'fr', 'es', 'it');
    if (req.session && req.session.locale) {
      // the user has specified a language from the options on the website
      locale = req.session.locale
      req.setLocale(locale)
    } else {
      // use local from i18n parsing of http accept-language
      locale = req.locale
    }
    if (req.csrfToken) {
      options.props._csrf = req.csrfToken()
    }
  } else {
    console.error('req object not found when rendering view')
  }
  options.props.locale = locale

  // include version number in all pages for debugging
  options.props.version = version

  if (!options.props.error) { // don't hit the database on error and 404 pages
    try {
      const pageConfigs = await Page.getPageConfigs(['footer', 'header', 'map'])
      options.props.headerConfig = pageConfigs.header
      options.props.footerConfig = pageConfigs.footer
      options.props.mapConfig = pageConfigs.map
    } catch (err) {
      console.error(err)
    }
    try {
      if (req && req.session && req.session.user && req.session.user.maphubsUser) {
        const user_id = req.session.user.maphubsUser.id
        const user = await User.getUser(user_id)

        // add session content
        if (req.session.user && req.session.user._json) {
          user.username = req.session.user._json.username
          user.picture = req.session.user._json.picture
        }

        const groups = await Group.getGroupsForUser(user_id)
        user.groups = groups

        const admin = await Admin.checkAdmin(user_id)
        user.admin = admin
        options.props.user = user
      }
    } catch (err) {
      log.error(err)
      Raven.captureException(err)
    }
    options.baseUrl = urlUtil.getBaseUrl()
    if (req && req.url) {
      options.reqUrl = req.url
    }
  }
  return options
}
Example #12
0
 source.tiles = source.tiles.map((tile) => {
   tile = tile.replace('{MAPHUBS_DOMAIN}', urlUtil.getBaseUrl())
   tile = tile.replace('{DG_WMS_CONNECT_ID}', MAPHUBS_CONFIG.DG_WMS_CONNECT_ID)
   return tile
 })
Example #13
0
// @flow
import urlUtil from '@bit/kriscarle.maphubs-utils.maphubs-utils.url-util'
import type {GLLayer, GLSource} from '../../../types/mapbox-gl-style'

const RasterSource = {
  async load (key: string, source: GLSource, mapComponent: any) {
    if (source.url) {
      source.url = source.url.replace('{MAPHUBS_DOMAIN}', urlUtil.getBaseUrl())
    }

    if (source.tiles && source.tiles.length > 0) {
      source.tiles = source.tiles.map((tile) => {
        tile = tile.replace('{MAPHUBS_DOMAIN}', urlUtil.getBaseUrl())
        tile = tile.replace('{DG_WMS_CONNECT_ID}', MAPHUBS_CONFIG.DG_WMS_CONNECT_ID)
        return tile
      })
    }

    if (source.metadata && source.metadata.authUrl && source.metadata.authToken) {
      mapComponent.map.authUrlStartsWith = source.metadata.authUrl
      mapComponent.map.authToken = source.metadata.authToken
    }
    return mapComponent.addSource(key, source)
  },
  addLayer (layer: GLLayer, source: GLSource, position: number, mapComponent: any) {
    if (layer.metadata && layer.metadata['maphubs:showBehindBaseMapLabels']) {
      mapComponent.addLayerBefore(layer, 'water')
    } else {
      if (mapComponent.state.editing) {
        mapComponent.addLayerBefore(layer, mapComponent.getFirstDrawLayerID())
      } else {
Example #14
0
 copyInviteLink = (user: User) => {
   const baseUrl = urlUtil.getBaseUrl()
   const url = `${baseUrl}/signup/invite/${user.key}`
   this.clipboard.writeText(url)
   message.info(this.t('Copied'))
 }
Example #15
0
 req.session.destroy(() => {
   const baseUrl = urlUtil.getBaseUrl()
   res.redirect(`https://maphubs.auth0.com/v2/logout?returnTo=${urlencode(baseUrl)}&client_id=${local.AUTH0_CLIENT_ID}`)
 })