<commit_before>package com.anchortab.snippet

import net.liftweb._
  import sitemap._
  import http._
    import js.JsCmds._
    import SHtml._
  import common._
  import util._
    import Helpers._
  import mongodb.BsonDSL._

import com.anchortab.model.{User, Tab, Plan}

import org.bson.types.ObjectId

case class TabEmbedCodeReceived(embedCode: String) extends SimpleAnchorTabEvent("tab-embed-code-received")
case class NewTabCreated(embedCode: String) extends SimpleAnchorTabEvent("new-tab-created")

object TabList {
  val menu = Menu.i("My Tabs") / "manager" / "tabs"
}
class TabList {
  def render = {
    val tabs = {
      for {
        session <- userSession.is
        userId = session.userId
      } yield {
        Tab.findAll("userId" -> userId, "name" -> 1)
      }
    } openOr {
      Nil
    }

    ".empty-list" #> (tabs.isEmpty ? PassThru | ClearNodes) andThen
    ".tab" #> (tabs.isEmpty ? ClearNodes | PassThru) andThen
    ".tab" #> tabs.map { tab =>
      ".tab [data-tab-id]" #> tab._id.toString &
      ".tab-name *" #> tab.name &
      ".subscription-count *" #> tab.stats.submissions &
      ".get-code [onclick]" #> ajaxInvoke(() => {
        TabEmbedCodeReceived(tab.embedCode) 
      }) &
      ".view-errors [onclick]" #> ajaxInvoke(() => {
        RedirectTo(TabErrorsList.menu.toLoc.calcHref(tab))
      }) &
      ".edit-tab [onclick]" #> ajaxInvoke(() => {
        RedirectTo(TabForm.tabEditMenu.toLoc.calcHref(tab))
      }) &
      ".delete-tab [onclick]" #> ajaxInvoke(() => {
        Tab.delete("_id" -> tab._id)

        Notices.notice("Tab deleted.")
        Reload
      })
    }
  }

  def newTabButton = {
    {
      for {
        session <- userSession.is
        user <- User.find(session.userId)
        userTabCount = Tab.count("userId" -> user._id)
      } yield {
        if (user.plan.quotas.get(Plan.Quotas.NumberOfTabs).map(_ > userTabCount) getOrElse true) {
          "button [onclick]" #> onEvent(_ => RedirectTo("/manager/tabs/new"))
        } else {
          "button [class+]" #> "disabled" &
          "button [title]" #> "You've reached the maximum number of tabs allowed for your plan. Please upgrade to add more." &
          "button [rel]" #> "tipsy"
        }
      }
    } openOr {
      ClearNodes
    }
  }

  def noTabViewsHelp = {
    {
      for {
        session <- userSession.is
        numTabs = Tab.count("userId" -> session.userId)
        numEmptyTabs = Tab.count(
          ("userId" -> session.userId) ~
          ("stats.views" -> 0)
        ) if numEmptyTabs == numTabs && numTabs > 0
      } yield {
        PassThru
      }
    } openOr {
      ClearNodes
    }
  }
}
<commit_msg>Hide the view errors button when there are no errors.<commit_after>package com.anchortab.snippet

import net.liftweb._
  import sitemap._
  import http._
    import js.JsCmds._
    import SHtml._
  import common._
  import util._
    import Helpers._
  import mongodb.BsonDSL._

import com.anchortab.model.{User, Tab, Plan}

import org.bson.types.ObjectId

case class TabEmbedCodeReceived(embedCode: String) extends SimpleAnchorTabEvent("tab-embed-code-received")
case class NewTabCreated(embedCode: String) extends SimpleAnchorTabEvent("new-tab-created")

object TabList {
  val menu = Menu.i("My Tabs") / "manager" / "tabs"
}
class TabList {
  def render = {
    val tabs = {
      for {
        session <- userSession.is
        userId = session.userId
      } yield {
        Tab.findAll("userId" -> userId, "name" -> 1)
      }
    } openOr {
      Nil
    }

    ".empty-list" #> (tabs.isEmpty ? PassThru | ClearNodes) andThen
    ".tab" #> (tabs.isEmpty ? ClearNodes | PassThru) andThen
    ".tab" #> tabs.map { tab =>
      ".tab [data-tab-id]" #> tab._id.toString &
      ".tab-name *" #> tab.name &
      ".subscription-count *" #> tab.stats.submissions &
      ".get-code [onclick]" #> ajaxInvoke(() => {
        TabEmbedCodeReceived(tab.embedCode) 
      }) &
      ".view-errors [onclick]" #> ajaxInvoke(() => {
        RedirectTo(TabErrorsList.menu.toLoc.calcHref(tab))
      }) &
      ".edit-tab [onclick]" #> ajaxInvoke(() => {
        RedirectTo(TabForm.tabEditMenu.toLoc.calcHref(tab))
      }) &
      ".delete-tab [onclick]" #> ajaxInvoke(() => {
        Tab.delete("_id" -> tab._id)

        Notices.notice("Tab deleted.")
        Reload
      }) andThen
      ".view-errors" #> (tab.errors.nonEmpty ? PassThru | ClearNodes)
    }
  }

  def newTabButton = {
    {
      for {
        session <- userSession.is
        user <- User.find(session.userId)
        userTabCount = Tab.count("userId" -> user._id)
      } yield {
        if (user.plan.quotas.get(Plan.Quotas.NumberOfTabs).map(_ > userTabCount) getOrElse true) {
          "button [onclick]" #> onEvent(_ => RedirectTo("/manager/tabs/new"))
        } else {
          "button [class+]" #> "disabled" &
          "button [title]" #> "You've reached the maximum number of tabs allowed for your plan. Please upgrade to add more." &
          "button [rel]" #> "tipsy"
        }
      }
    } openOr {
      ClearNodes
    }
  }

  def noTabViewsHelp = {
    {
      for {
        session <- userSession.is
        numTabs = Tab.count("userId" -> session.userId)
        numEmptyTabs = Tab.count(
          ("userId" -> session.userId) ~
          ("stats.views" -> 0)
        ) if numEmptyTabs == numTabs && numTabs > 0
      } yield {
        PassThru
      }
    } openOr {
      ClearNodes
    }
  }
}

{'fraction_non_alphanumeric': 0.14587155963302753, 'fraction_numerical': 0.0011009174311926607, 'mean_word_length': 2.182136602451839, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 62, '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': '1882718', 'n_tokens_mistral': 1844, 'n_tokens_neox': 1789, 'n_words': 362}