<commit_before><template lang="jade">
div
  n3-alert(type="success", message="发送周报", placement="top", :show.sync="alert.sendSuccess", :duration="2000") 发送成功！
  n3-alert(type="danger", message="发送周报", placement="top", :show.sync="alert.sendFail", :duration="2000") 发送失败，请重试。
  n3-row
    n3-column(:col="12")
      div.report-header
        n3-datepicker.date(placeholder="日期", :value.sync="date", width="100px")
        n3-button.pull-right(type="primary", @click="getMailHTML") 发送周报&nbsp;
          n3-icon(type="envelope")
  n3-row
    n3-column(:col="12")
      div.mail(v-el:"mail")
        h2
          span(v-text="title")
          span(v-text="week")
        hr
        ul
          li(v-for="project of currentReport")
            h4(v-text="project.name || '未命名项目'")
            ul
              li(v-for="task of project.tasks")
                h5
                  span.state(v-text="status[task.progress[0].state].text", :style="{backgroundColor: status[task.progress[0].state].color}")
                  span.name(v-text="task.name || '未命名任务'")
                ul
                  li.point(v-for="point of task.progress")
                    span.state(v-text="`${status[point.state].text}`")
                    span.date(v-text="point.date")
                    p(v-text="point.detail")
            hr
</template>
<script>
import {n3Row, n3Column, n3Form, n3FormItem, n3Input, n3Button, n3Tabs, n3Tab, n3Datepicker, n3Icon, n3Alert} from 'N3-Components'
import status from '../../lib/task-status.js'
import week from '../../lib/week.js'

const mailer = global.require ? global.require('../src/service/mailer.js') : function (options, callback) {
  console.log(options.content)
  callback && callback(true, '')
}

const styleKeys = [
  'border',
  'margin',
  'padding',
  'background',
  'height',
  'lineHeight',
  'textIndent',
  'font',
  'borderRadius',
  'borderLeft',
  'listStyle',
  'color'
]

export default {
  data () {
    const ls = global.localStorage
    return {
      alert: {
        sendSuccess: false,
        sendFail: false
      },
      title: ls.getItem('reportTitle') || '未命名周报',
      date: this.transDate(new Date()),
      output: '',
      projects: JSON.parse(ls.getItem('projects')) || [],
      status: status
    }
  },
  components: {
    n3Row: n3Row,
    n3Column: n3Column,
    n3Form: n3Form,
    n3FormItem: n3FormItem,
    n3Input: n3Input,
    n3Button: n3Button,
    n3Tabs: n3Tabs,
    n3Tab: n3Tab,
    n3Datepicker: n3Datepicker,
    n3Icon: n3Icon,
    n3Alert: n3Alert
  },
  methods: {
    walkMailNode (root) {
      const newRoot = document.createElement(root.tagName)
      const style = global.getComputedStyle(root)
      if (root.firstChild && root.firstChild.nodeName === '#text') {
        newRoot.textContent = root.firstChild.textContent
      }
      for (const key of styleKeys) {
        newRoot.style[key] = style[key]
      }
      for (const el of root.children) {
        const newEl = this.walkMailNode(el)
        newRoot.appendChild(newEl)
      }
      return newRoot
    },
    getMailHTML () {
      const ls = global.localStorage
      const el = this.$els.mail
      const mailStr = this.walkMailNode(el).innerHTML
      mailer({
        username: ls.getItem('username'),
        password: <PASSWORD>('password'),
        to: ls.getItem('sendTo'),
        cc: ls.getItem('cc'),
        title: `${this.title} ${this.week}`,
        content: mailStr
      }, (error, info) => {
        this.alert.sendSuccess = !error
        this.alert.sendFail = error
        if (error) {
          console.log(error)
        } else {
          console.log('Message sent: ' + info.response)
        }
      })
    },
    transDate (date) {
      const year = date.getFullYear()
      const month = (month => {
        let ret = (month + 1).toString()
        return ret.length === 1 ? '0' + ret : ret
      })(date.getMonth())
      const day = (date => {
        let ret = date.toString()
        return ret.length === 1 ? '0' + ret : ret
      })(date.getDate())
      return `${year}-${month}-${day}`
    }
  },
  computed: {
    hasReport () {
      return !!this.currentReport.length
    },
    currentReport () {
      const newProjects = []
      for (const project of this.projects) {
        const tasks = project.tasks
        const newTasks = []
        for (const task of tasks) {
          const progress = task.progress
          const newProgress = []
          const lastPoint = progress[0]
          if (lastPoint.state !== 'COMPLETED' && lastPoint.state !== 'DEPLOYED' && lastPoint.state !== 'ENDED' && new Date(lastPoint.date) < this.dateRange.start) {
            newProgress.push(lastPoint)
          }
          for (const point of progress) {
            const date = new Date(point.date)
            if (date >= this.dateRange.start && date < this.dateRange.end) {
              newProgress.push(point)
            }
          }
          if (newProgress.length) {
            task.progress = newProgress
            newTasks.push(task)
          }
        }
        if (newTasks.length) {
          project.tasks = tasks
          newProjects.push(project)<commit_msg>bug fixed<commit_after><template lang="jade">
div
  n3-alert(type="success", message="发送周报", placement="top", :show.sync="alert.sendSuccess", :duration="2000") 发送成功！
  n3-alert(type="danger", message="发送周报", placement="top", :show.sync="alert.sendFail", :duration="2000") 发送失败，请重试。
  n3-row
    n3-column(:col="12")
      div.report-header
        n3-datepicker.date(placeholder="日期", :value.sync="date", width="100px")
        n3-button.pull-right(type="primary", @click="getMailHTML") 发送周报&nbsp;
          n3-icon(type="envelope")
  n3-row
    n3-column(:col="12")
      div.mail(v-el:"mail")
        h2
          span(v-text="title")
          span(v-text="week")
        hr
        ul
          li(v-for="project of currentReport")
            h4(v-text="project.name || '未命名项目'")
            ul
              li(v-for="task of project.tasks")
                h5
                  span.state(v-text="status[task.progress[0].state].text", :style="{backgroundColor: status[task.progress[0].state].color}")
                  span.name(v-text="task.name || '未命名任务'")
                ul
                  li.point(v-for="point of task.progress")
                    span.state(v-text="`${status[point.state].text}`")
                    span.date(v-text="point.date")
                    p(v-text="point.detail")
            hr
</template>
<script>
import {n3Row, n3Column, n3Form, n3FormItem, n3Input, n3Button, n3Tabs, n3Tab, n3Datepicker, n3Icon, n3Alert} from 'N3-Components'
import status from '../../lib/task-status.js'
import week from '../../lib/week.js'

const mailer = global.require ? global.require('../service/mailer.js') : function (options, callback) {
  console.log(options.content)
  callback && callback(true, '')
}

const styleKeys = [
  'border',
  'margin',
  'padding',
  'background',
  'height',
  'lineHeight',
  'textIndent',
  'font',
  'borderRadius',
  'borderLeft',
  'listStyle',
  'color'
]

export default {
  data () {
    const ls = global.localStorage
    return {
      alert: {
        sendSuccess: false,
        sendFail: false
      },
      title: ls.getItem('reportTitle') || '未命名周报',
      date: this.transDate(new Date()),
      output: '',
      projects: JSON.parse(ls.getItem('projects')) || [],
      status: status
    }
  },
  components: {
    n3Row: n3Row,
    n3Column: n3Column,
    n3Form: n3Form,
    n3FormItem: n3FormItem,
    n3Input: n3Input,
    n3Button: n3Button,
    n3Tabs: n3Tabs,
    n3Tab: n3Tab,
    n3Datepicker: n3Datepicker,
    n3Icon: n3Icon,
    n3Alert: n3Alert
  },
  methods: {
    walkMailNode (root) {
      const newRoot = document.createElement(root.tagName)
      const style = global.getComputedStyle(root)
      if (root.firstChild && root.firstChild.nodeName === '#text') {
        newRoot.textContent = root.firstChild.textContent
      }
      for (const key of styleKeys) {
        newRoot.style[key] = style[key]
      }
      for (const el of root.children) {
        const newEl = this.walkMailNode(el)
        newRoot.appendChild(newEl)
      }
      return newRoot
    },
    getMailHTML () {
      const ls = global.localStorage
      const el = this.$els.mail
      const mailStr = this.walkMailNode(el).innerHTML
      mailer({
        username: ls.getItem('username'),
        password: <PASSWORD>'),
        to: ls.getItem('sendTo'),
        cc: ls.getItem('cc'),
        title: `${this.title} ${this.week}`,
        content: mailStr
      }, (error, info) => {
        this.alert.sendSuccess = !error
        this.alert.sendFail = error
        if (error) {
          console.log(error)
        } else {
          console.log('Message sent: ' + info.response)
        }
      })
    },
    transDate (date) {
      const year = date.getFullYear()
      const month = (month => {
        let ret = (month + 1).toString()
        return ret.length === 1 ? '0' + ret : ret
      })(date.getMonth())
      const day = (date => {
        let ret = date.toString()
        return ret.length === 1 ? '0' + ret : ret
      })(date.getDate())
      return `${year}-${month}-${day}`
    }
  },
  computed: {
    hasReport () {
      return !!this.currentReport.length
    },
    currentReport () {
      const newProjects = []
      for (const project of this.projects) {
        const tasks = project.tasks
        const newTasks = []
        for (const task of tasks) {
          const progress = task.progress
          const newProgress = []
          const lastPoint = progress[0]
          if (lastPoint.state !== 'COMPLETED' && lastPoint.state !== 'DEPLOYED' && lastPoint.state !== 'ENDED' && new Date(lastPoint.date) < this.dateRange.start) {
            newProgress.push(lastPoint)
          }
          for (const point of progress) {
            const date = new Date(point.date)
            if (date >= this.dateRange.start && date < this.dateRange.end) {
              newProgress.push(point)
            }
          }
          if (newProgress.length) {
            task.progress = newProgress
            newTasks.push(task)
          }
        }
        if (newTasks.length) {
          project.tasks = newTasks
          newProjects.push(project)
{'fraction_non_alphanumeric': 0.15008235636081774, 'fraction_numerical': 0.013370797403352388, 'mean_word_length': 2.1459920755867112, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 19, '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': '5809907', 'n_tokens_mistral': 3349, 'n_tokens_neox': 3357, 'n_words': 640}