<commit_before>var css = require('dom-css')
var inherits = require('inherits')
var _ = require('lodash')
var EventEmitter = require('events').EventEmitter
var reader = require('../lib/reader.js')
var DownloadPaperBtn = require('./downloadpaperbtn.js')

inherits(PaperBox, EventEmitter)

function PaperBox (paper, opts) {
  if (!(this instanceof PaperBox)) return new PaperBox(paper, opts)
  var self = this
  self.paper = paper
  self.opts = opts

  var downloadPaper = DownloadPaperBtn(paper, opts)

  var box = document.createElement('div')
  box.className = 'paper paper-box clickable'
  var title = box.appendChild(document.createElement('div'))
  var author = box.appendChild(document.createElement('div'))
  var year = box.appendChild(document.createElement('div'))
  var overlay = box.appendChild(document.createElement('div'))
  var lens = overlay.appendChild(document.createElement('img'))
  var downloadBtn = overlay.appendChild(downloadPaper.element)
  var bar = box.appendChild(document.createElement('div'))
  lens.src = './images/lens.png'

  self.pmcid = self.paper.getId('pmcid')

  title.innerHTML = self.paper.title
  author.innerHTML = self.paper.etalia()
  year.innerHTML = self.paper.year

  var lensReader = null

  var base = {
    position: 'absolute',
    fontFamily: 'Aleo-Regular',
    textAlign: 'left',
    color: 'rgb(178,180,184)'
  }

  css(box, {
    position: 'relative',
    background: 'rgb(43,43,51)',
    display: 'inline-block',
    marginRight: '20px',
    marginBottom: '20px',
    cursor: 'pointer'
  })

  css(bar, {
    position: 'absolute',
    bottom: 0,
    left: 0,
    zIndex: 999,
    width: '0%',
    height: 7,
    display: 'block',
    backgroundColor: 'rgb(202, 172, 77)'
  })

  css(overlay, {
    position: 'absolute',
    left: 0,
    top: 0,
    width: '100%',
    height: '100%',
    display: 'none',
    background: 'rgba(255, 255, 255, 0.4)',
    alignItems: 'center',
    justifyContent: 'center'
  })

  var hasFulltextDownloaded = paper.assetPathByFilename('fulltext.xml')
  css(lens, {
    width: '20%',
    display: hasFulltextDownloaded ? 'block' : 'none'
  })

  css(downloadBtn, {
    width: '20%'
  })

  self.layout = function () {

    var width = '160'

    css(box, {
      width: width + 'px',
      height: width * 1.31,
      padding: width * 0.09
    })

    css(title, _.extend(_.clone(base), {
      fontSize: '14px',
      left: '10px',
      right: '10px',
      top: '10px',
      bottom: '40px',
      overflowY: 'scroll',
      overflowX: 'hidden'
    }))

    css(author, _.extend(_.clone(base), {
      fontSize: '10px',
      left: '10px',
      right: '40px',
      bottom: '10px'
    }))

    css(year, _.extend(_.clone(base), {
      position: 'absolute',
      fontSize: '14px',
      left: '120px',
      right: '10px',
      bottom: '10px'
    }))

  }

  self.updateBar = function (done, total) {
    css(bar, { width: `${Math.min((done / total) * 100, 100)}%`})
  }

  self.downloadFailed = function (err) {
    css(bar, {
      width: '100%',
      backgroundColor: 'rgb(202,77,107)'
    })
  }

  self.downloaded = function () {
    css(lens, {
      display: 'block'
    })
  }

  self.layout()
  //
  // self.updateBar(0, 9999)
  // self.loadFile()

  box.onclick  = function () {
    self.emit('click')
  }

  box.addEventListener("mouseenter", function(event) {
    if (self.paper && contentServer.port) css(overlay, { display: 'flex' })
  })

  box.addEventListener("mouseleave", function(event) {
    css(overlay, { display: 'none' })
  })

  lens.onclick = function () {
    self.emit('lens-click')
    lensReader = reader(self.paper, self.opts)
    lensReader.show()
    // TODO: destroy on close<commit_msg>Hide download button when fulltext is downloaded<commit_after>var css = require('dom-css')
var inherits = require('inherits')
var _ = require('lodash')
var EventEmitter = require('events').EventEmitter
var reader = require('../lib/reader.js')
var DownloadPaperBtn = require('./downloadpaperbtn.js')

inherits(PaperBox, EventEmitter)

function PaperBox (paper, opts) {
  if (!(this instanceof PaperBox)) return new PaperBox(paper, opts)
  var self = this
  self.paper = paper
  self.opts = opts

  var downloadPaper = DownloadPaperBtn(paper, opts)

  var box = document.createElement('div')
  box.className = 'paper paper-box clickable'
  var title = box.appendChild(document.createElement('div'))
  var author = box.appendChild(document.createElement('div'))
  var year = box.appendChild(document.createElement('div'))
  var overlay = box.appendChild(document.createElement('div'))
  var lens = overlay.appendChild(document.createElement('img'))
  var downloadBtn = overlay.appendChild(downloadPaper.element)
  var bar = box.appendChild(document.createElement('div'))
  lens.src = './images/lens.png'

  self.pmcid = self.paper.getId('pmcid')

  title.innerHTML = self.paper.title
  author.innerHTML = self.paper.etalia()
  year.innerHTML = self.paper.year

  var lensReader = null

  var base = {
    position: 'absolute',
    fontFamily: 'Aleo-Regular',
    textAlign: 'left',
    color: 'rgb(178,180,184)'
  }

  css(box, {
    position: 'relative',
    background: 'rgb(43,43,51)',
    display: 'inline-block',
    marginRight: '20px',
    marginBottom: '20px',
    cursor: 'pointer'
  })

  css(bar, {
    position: 'absolute',
    bottom: 0,
    left: 0,
    zIndex: 999,
    width: '0%',
    height: 7,
    display: 'block',
    backgroundColor: 'rgb(202, 172, 77)'
  })

  css(overlay, {
    position: 'absolute',
    left: 0,
    top: 0,
    width: '100%',
    height: '100%',
    display: 'none',
    background: 'rgba(255, 255, 255, 0.4)',
    alignItems: 'center',
    justifyContent: 'center'
  })

  var hasFulltextDownloaded = paper.assetPathByFilename('fulltext.xml')
  css(lens, {
    width: '20%',
    display: hasFulltextDownloaded ? 'block' : 'none'
  })

  css(downloadBtn, {
    width: '20%',
    display: hasFulltextDownloaded ? 'none' : 'block'
  })

  self.layout = function () {

    var width = '160'

    css(box, {
      width: width + 'px',
      height: width * 1.31,
      padding: width * 0.09
    })

    css(title, _.extend(_.clone(base), {
      fontSize: '14px',
      left: '10px',
      right: '10px',
      top: '10px',
      bottom: '40px',
      overflowY: 'scroll',
      overflowX: 'hidden'
    }))

    css(author, _.extend(_.clone(base), {
      fontSize: '10px',
      left: '10px',
      right: '40px',
      bottom: '10px'
    }))

    css(year, _.extend(_.clone(base), {
      position: 'absolute',
      fontSize: '14px',
      left: '120px',
      right: '10px',
      bottom: '10px'
    }))

  }

  self.updateBar = function (done, total) {
    css(bar, { width: `${Math.min((done / total) * 100, 100)}%`})
  }

  self.downloadFailed = function (err) {
    css(bar, {
      width: '100%',
      backgroundColor: 'rgb(202,77,107)'
    })
  }

  self.downloaded = function () {
    css(lens, {
      display: 'block'
    })

    css(downloadBtn, {
      display: 'none'
    })
  }

  self.layout()
  //
  // self.updateBar(0, 9999)
  // self.loadFile()

  box.onclick  = function () {
    self.emit('click')
  }

  box.addEventListener("mouseenter", function(event) {
    if (self.paper && contentServer.port) css(overlay, { display: 'flex' })
  })

  box.addEventListener("mouseleave", function(event) {
    css(overlay, { display: 'none' })
  })

  lens.onclick = function () {
    self.emit('lens-click')
    lensReader = reader(self.paper, self.opts)
    lensReader.show()
    // TODO: destroy on close
{'fraction_non_alphanumeric': 0.16404702152952053, 'fraction_numerical': 0.030379078061022323, 'mean_word_length': 3.0340969632392114, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 26, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6313109', 'n_tokens_mistral': 2743, 'n_tokens_neox': 2514, 'n_words': 546}