<commit_before><style lang="scss">
@import 'variables';
.document-management {
  margin-bottom: 16px;
}

.document-management__caption {
  color: $grey-on-white;
}

.document-management__icon {
  font-size: 24px;
}

.document-management__column-row {
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  margin: 8px 0;
  i { padding: 4px; }
}

</style>

<script lang="coffee">
AbilityService = require 'shared/services/ability_service'
ModalService   = require 'shared/services/modal_service'
urlFor         = require 'vue/mixins/url_for'
truncate       = require 'vue/mixins/truncate'

module.exports =
  mixins: [urlFor, truncate]
  props:
    group: Object
    fragment: Object
    filter: Object
    header: Object
  methods:
    canAdministerGroup: ->
      AbilityService.canAdministerGroup(@group)

    edit: (doc) ->
      ModalService.open 'DocumentModal', doc: => doc

    remove: (doc) ->
      ModalService.open 'ConfirmModal', confirm: =>
        submit:      doc.destroy
        text:
          title:    'documents_page.confirm_remove_title'
          helptext: 'documents_page.confirm_remove_helptext'
          flash:    'documents_page.document_removed'
  computed:
    documents: ->
      _.filter @group.allDocuments(), (doc) =>
        return false  if @filter == 'group'   and doc.model() != @group
        return false  if @filter == 'content' and doc.model() == @group
        _.isEmpty(@fragment) or doc.title.match(///#{@fragment}///i)

    orderedDocuments: ->
      _.orderBy @documents, 'createdAt', 'desc'

    hasDocuments: ->
      _.some @documents
</script>

<template>
  <div v-if="hasDocuments" class="document-management">
    <h3 v-t="'document.management.' + filter + '_header'" v-if="filter" class="lmo-h3"></h3>
    <div v-for="document in orderedDocuments" :key="document.id" layout="row" class="document-management__document lmo-flex lmo-flex__space-between">
      <div class="document-management__column-row">
        <i :class="'mdi lmo-margin-right document-management__icon mdi-' + document.icon" :style="{color: document.color}"></i>
      </div>
      <div layout="column" class="document-management__column-row lmo-flex lmo-flex__grow">
        <strong class="lmo-truncate">
          <router-link :to="document.url" target="_blank">{{ truncate(document.title, 50) }}</router-link>
        </strong>
        <div class="document-management__caption md-caption">
          <router-link :to="urlFor(document.model())" class="lmo-truncate">{{ truncate(document.modelTitle(), 50) }}</router-link>
        </div>
        <div class="document-management__caption md-caption">
          <span>{{document.authorName()}}</span>
          <span>·</span>
          <time-ago :date="document.createdAt"></time-ago>
        </div>
      </div>
      <div v-if="canAdministerGroup()" class="document-management__column-row">
        <button @click="edit(document)" v-t="'common.action.edit'" class="md-accent"></button>
      </div>
      <div v-if="canAdministerGroup()" class="document-management__column-row">
        <button @click="remove(document)" v-t="'common.action.remove'" class="md-warn"></button>
      </div>
    </div>
  </div>
</template><commit_msg>add confirm modal to documents page<commit_after><style lang="scss">
@import 'variables';
.document-management {
  margin-bottom: 16px;
}

.document-management__caption {
  color: $grey-on-white;
}

.document-management__icon {
  font-size: 24px;
}

.document-management__column-row {
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  margin: 8px 0;
  i { padding: 4px; }
}

</style>

<script lang="coffee">
AbilityService = require 'shared/services/ability_service'
ModalService   = require 'shared/services/modal_service'
urlFor         = require 'vue/mixins/url_for'
truncate       = require 'vue/mixins/truncate'

module.exports =
  mixins: [urlFor, truncate]
  props:
    group: Object
    fragment: Object
    filter: Object
    header: Object
  data: ->
    isRemoveModalOpen: false
  methods:
    canAdministerGroup: ->
      AbilityService.canAdministerGroup(@group)

    edit: (doc) ->
      ModalService.open 'DocumentModal', doc: => doc

    closeRemoveModal: ->
      @isRemoveModalOpen = false
    openRemoveModal: ->
      @isRemoveModalOpen = true
    removeModalConfirmOpts: (doc) ->
      submit:      doc.destroy
      text:
        title:    'documents_page.confirm_remove_title'
        helptext: 'documents_page.confirm_remove_helptext'
        flash:    'documents_page.document_removed'
  computed:
    documents: ->
      _.filter @group.allDocuments(), (doc) =>
        return false  if @filter == 'group'   and doc.model() != @group
        return false  if @filter == 'content' and doc.model() == @group
        _.isEmpty(@fragment) or doc.title.match(///#{@fragment}///i)

    orderedDocuments: ->
      _.orderBy @documents, 'createdAt', 'desc'

    hasDocuments: ->
      _.some @documents
</script>

<template lang="pug">
.document-management(v-if='hasDocuments')
  h3.lmo-h3(v-t="'document.management.' + filter + '_header'", v-if='filter')
  .document-management__document.lmo-flex.lmo-flex__space-between(v-for='document in orderedDocuments', :key='document.id', layout='row')
    .document-management__column-row
      i(:class="'mdi lmo-margin-right document-management__icon mdi-' + document.icon", :style='{color: document.color}')
    .document-management__column-row.lmo-flex.lmo-flex__grow(layout='column')
      strong.lmo-truncate
        router-link(:to='document.url', target='_blank') {{ truncate(document.title, 50) }}
      .document-management__caption.md-caption
        router-link.lmo-truncate(:to='urlFor(document.model())') {{ truncate(document.modelTitle(), 50) }}
      .document-management__caption.md-caption
        span {{document.authorName()}}
        span ·
        time-ago(:date='document.createdAt')
    .document-management__column-row(v-if='canAdministerGroup()')
      button.md-accent(@click='edit(document)', v-t="'common.action.edit'")
    .document-management__column-row(v-if='canAdministerGroup()')
      button.md-warn(@click='openRemoveModal', v-t="'common.action.remove'")
      v-dialog(v-model="isRemoveModalOpen", lazy persistent)
        confirm-modal(:confirm="removeModalConfirmOpts(document)", :close="closeRemoveModal")
</template>
{'fraction_non_alphanumeric': 0.1554160125588697, 'fraction_numerical': 0.00423861852433281, 'mean_word_length': 3.470877192982456, 'pattern_counts': {'":': 0, '<': 51, '<?xml version=': 0, '>': 71, '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': '1075533', 'n_tokens_mistral': 2047, 'n_tokens_neox': 1985, 'n_words': 360}