<commit_before>/*global document, top, $, location, confirm, alert */
import Nanoajax from 'nanoajax'
import qs from 'qs'
import {Promise} from 'bluebird'
import extend from 'extend'
import on from 'on'

export default class TaskRepublish {
  constructor() {
    this._ajax = Nanoajax.ajax

    // this.remove = on(this)

    // event handlers
    this._handleBtnGeneratePostsClick = this._btnGeneratePostsClick.bind(this)
    this._btnGeneratePosts = document.querySelector('[data-generate-posts]')

    this.rebind()
  }

  rebind() {
    if(typeof this._btnGeneratePosts !== 'undefined' && this._btnGeneratePosts !== null) {
      this._btnGeneratePosts.removeEventListener('click', this._handleBtnGeneratePostsClick)
      this._btnGeneratePosts.addEventListener('click', this._handleBtnGeneratePostsClick)
    }

    if (!!window.EventSource) {
      var source = new EventSource('/abe/generate/post');
      source.addEventListener('message', (e, data) => {
        var json = JSON.parse(e.data)
        if (json.percent != null && json.time != null) {
          this._btnGeneratePosts.classList.add('disabled')
          this._btnGeneratePosts.querySelector('[data-not-clicked]').className = 'hidden'
          this._btnGeneratePosts.querySelector('[data-clicked]').className = ''
          this._btnGeneratePosts.querySelector('[data-clicked]').innerHTML = `publish site... ${json.percent}% (${json.time})`
        }else if (json.msg != "") {
          this._btnGeneratePosts.classList.remove('disabled')
          this._btnGeneratePosts.querySelector('[data-not-clicked]').className = ''
          this._btnGeneratePosts.querySelector('[data-clicked]').className = 'hidden'
        }
      }, false);

      source.addEventListener('open', (e) => {
        // Connection was opened.
      }, false);

      source.addEventListener('error', (e) => {
        if (e.readyState == EventSource.CLOSED) {
          // Connection was closed.
        }
      }, false);

    } else {
      // Result to xhr polling :(
    }
  }<commit_msg>fix: bug if button republish not present for user role<commit_after>/*global document, top, $, location, confirm, alert */
import Nanoajax from 'nanoajax'
import qs from 'qs'
import {Promise} from 'bluebird'
import extend from 'extend'
import on from 'on'

export default class TaskRepublish {
  constructor() {
    this._ajax = Nanoajax.ajax

    // this.remove = on(this)

    // event handlers
    this._handleBtnGeneratePostsClick = this._btnGeneratePostsClick.bind(this)
    this._btnGeneratePosts = document.querySelector('[data-generate-posts]')

    this.rebind()
  }

  rebind() {
    if(typeof this._btnGeneratePosts !== 'undefined' && this._btnGeneratePosts !== null) {
      this._btnGeneratePosts.removeEventListener('click', this._handleBtnGeneratePostsClick)
      this._btnGeneratePosts.addEventListener('click', this._handleBtnGeneratePostsClick)

      // don't watch if btn source not present
      if (!!window.EventSource) {
        var source = new EventSource('/abe/generate/post');
        source.addEventListener('message', (e, data) => {
          var json = JSON.parse(e.data)
          if (json.percent != null && json.time != null) {
            this._btnGeneratePosts.classList.add('disabled')
            this._btnGeneratePosts.querySelector('[data-not-clicked]').className = 'hidden'
            this._btnGeneratePosts.querySelector('[data-clicked]').className = ''
            this._btnGeneratePosts.querySelector('[data-clicked]').innerHTML = `publish site... ${json.percent}% (${json.time})`
          }else if (json.msg != "") {
            this._btnGeneratePosts.classList.remove('disabled')
            this._btnGeneratePosts.querySelector('[data-not-clicked]').className = ''
            this._btnGeneratePosts.querySelector('[data-clicked]').className = 'hidden'
          }
        }, false);

        source.addEventListener('open', (e) => {
          // Connection was opened.
        }, false);

        source.addEventListener('error', (e) => {
          if (e.readyState == EventSource.CLOSED) {
            // Connection was closed.
          }
        }, false);

      } else {
        // Result to xhr polling :(
      }
    }
  }
{'fraction_non_alphanumeric': 0.14170616113744075, 'fraction_numerical': 0.0, 'mean_word_length': 2.9375, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3136811', 'n_tokens_mistral': 1205, 'n_tokens_neox': 1160, 'n_words': 228}