<commit_before><template>
  <pagination class="node-presentable-row"
              :config="tableConfig"
              :formatHandler="formatHandler"
              ref="listRef"
              :showFooter="showFooter"
              :pagination="paginationConfig">
    <template slot="list">
      <el-table-column
              label=""
              width="100">
        <template slot-scope="scope">
          <div>
            <a :href="`/resource/detail/${scope.row.resourceId}`" target="_blank">
              <img :src="scope.row.resourceInfo.postImgUrl | padImage"
                   :class="{'resource-default-preview':!scope.row.resourceInfo.postImgUrl}"
                   alt="">
            </a>
          </div>
        </template>
      </el-table-column>
      <el-table-column
              label="">
        <template slot-scope="scope">
          <p class="resource-name" :title="scope.row.presentableName">{{ scope.row.presentableName }} </p>
          <p class="resource-name" :title="scope.row.presentableId">{{ scope.row.presentableId }} </p>
        </template>
      </el-table-column>
      <el-table-column
              width="180"
              label="签约状态">
        <template slot-scope="scope">
          <div class="contract-state-info" :class="[
                      scope.row.hasContract?'active-status-2':'active-status-0',
                      {'is-presentable-online':scope.row.isOnlineChecked}
                    ]">
            <i class="dot"></i>
            <div class="scheme-state">
              <div>
                <template v-if="scope.row.hasContract">已签约</template>
                <template v-else>
                  未签约
                  <el-button type="text" @click="deletePresentableHandler(scope.row)"><i class="el-icon-delete"></i>
                  </el-button>
                </template>
              </div>
              <p class="scheme-info" v-if="scope.row.scheme && scope.row.scheme.selectedPolicy">
                {{scope.row.scheme.authSchemeName}}/{{scope.row.scheme.selectedPolicy.policyName}}</p>
            </div>
          </div>
        </template>
      </el-table-column>
      <el-table-column
              width="250"
              label="">
        <template slot-scope="{row}">
          <div class="presentable-nav-links active-status-0">
            <router-link :to="row.detailLink + '?tab=policy'">
              <el-button type="text" class="nav-link-btn">策略管理<i class="dot" v-if="(row.status&2) !== 2"></i>
              </el-button>
            </router-link>
            <span>|</span>
            <router-link :to="row.detailLink + '?tab=contract'">
              <el-button type="text" class="nav-link-btn" :disabled="!row.hasContract">合约管理<i class="dot"
                                                                                              v-if="row.hasContract && row.isContractActived === false"></i>
              </el-button>
            </router-link>
            <span>|</span>
            <router-link :to="row.detailLink + '?tab=scheme'">
              <el-button type="text" class="nav-link-btn">授权方案<i class="dot" v-if="(row.status&1) !== 1"></i>
              </el-button>
            </router-link>
          </div>
        </template>
      </el-table-column>
      <el-table-column
              width="150"
              label="资源类型">
        <template slot-scope="scope">
          <div>
            <span class="resource-type" :class="['is-'+scope.row.resourceInfo.resourceType]">{{scope.row.resourceInfo.resourceType}}</span>
          </div>
        </template>
      </el-table-column>
      <slot name="append"></slot>
    </template>
    <template slot="empty">
      <slot name="empty"></slot>
    </template>
  </pagination>
</template>

<script>
import {PRESENTABLE_STATUS_TIPS} from '@/config/presentable'
import {loadAuthSchemes} from '@/data/scheme/loader'
import Pagination from '@/components/Pagination/index.vue'

export default {
  name: 'node-presentable-list',

  data() {
    return {
      tableConfig: {
        rowClassName: 'resource-row',
        'cell-class-name': 'res-row-cell',
        'show-header': false
      },
      paginationConfig: {
        target: `/v1/presentables`,
        params: {
          nodeId: this.$route.params.nodeId
        }
      }
    }
  },

  props: {
    params: Object,
    showFooter: Boolean
  },

  components: {Pagination},

  watch: {
    params: {
      deep: true,
      handler() {
        this.reload()
      }
    },
    $route() {
      if (!this.$route.params.nodeId) return
      this.paginationConfig.params.nodeId = this.$route.params.nodeId
    }
  },

  mounted() {
    this.reload()
  },

  methods: {
    setParams() {
      var params = Object.assign({
        nodeId: this.$route.params.nodeId
      }, this.params || {})

      this.$set(this.paginationConfig, 'params', params)
    },
    refresh() {
      this.$refs.listRef.reload()
    },
    reload() {
      this.setParams()
      this.refresh()
    },
    formatHandler(list) {
      if (!list || !list.length) {
        return []
      }

      var authSchemeIds = []
      var maps = {}
      var schemeIdMaps = {}
      var presentablesIdMap = {}
      var promises = []
      var promise

      list.forEach((item, index) => {
        let contract = this.getPresentableContract(item)

        if (contract) {
          authSchemeIds.push(contract.authSchemeId)
          schemeIdMaps[contract.authSchemeId] = {
            index, contract
          }
        }

        maps[item.resourceId] = index
        presentablesIdMap[item.presentableId] = item
        item.resourceInfo.postImgUrl = this.resolvePostImgUrl(item.resourceInfo)
        this.resolvePresentable(item)
      })

      if (authSchemeIds.length) {
        promise = this.loadPresentablesSchemes(authSchemeIds)
          .then(schemes => {
            schemes.forEach(scheme => {
              let {index, contract} = schemeIdMaps[scheme.authSchemeId]
              scheme.selectedPolicy = this.getSelectedPolicy(scheme, contract)
              this.$set(list[index], 'scheme', scheme)
            })
            schemeIdMaps = null
          })
        promises.push(promise)
      }

      var presentableIds = Object.keys(presentablesIdMap)
      if (presentableIds.length) {
        promise = this.loadPresentablesAuth(presentableIds)
          .then((auths) => {
            auths.forEach(auth => {
              let presentable = presentablesIdMap[auth.presentableId]
              presentable.authResult = Number.isInteger(auth.authResult) ? auth.authResult : -1
            })
          })

        promises.push(promise)
        promise = this.loadPresentablesContractState(presentableIds)
          .then(states => {
            states.forEach(state => {
              let presentable = presentablesIdMap[state.presentableId]
              presentable.isContractActived = (state.status === 1)
            })
          })
        promises.push(promise)
      }

      if (promises.length) {
        Promise.all(promises).then(() => {
          this.fillWarningTips(list)
        })
      }

      return list
    },
    fillWarningTips(presentables) {
      //判断授权链上的策略包含presentable授权
      const tips = {
        'no': '未获得授权', //合同未到达presentable状态，无法让c端用户签约
        'yes': '已获得授权'
      }
      const contractTips = {
        'no': '已签约合同未全部激活',
        'yes': '全部激活'
      }
      const policyTips = {
        'no': '未有可用策略',<commit_msg>update text<commit_after><template>
  <pagination class="node-presentable-row"
              :config="tableConfig"
              :formatHandler="formatHandler"
              ref="listRef"
              :showFooter="showFooter"
              :pagination="paginationConfig">
    <template slot="list">
      <el-table-column
              label=""
              width="100">
        <template slot-scope="scope">
          <div>
            <a :href="`/resource/detail/${scope.row.resourceId}`" target="_blank">
              <img :src="scope.row.resourceInfo.postImgUrl | padImage"
                   :class="{'resource-default-preview':!scope.row.resourceInfo.postImgUrl}"
                   alt="">
            </a>
          </div>
        </template>
      </el-table-column>
      <el-table-column
              label="">
        <template slot-scope="scope">
          <p class="resource-name" :title="scope.row.presentableName">{{ scope.row.presentableName }} </p>
          <p class="resource-name" :title="scope.row.presentableId">{{ scope.row.presentableId }} </p>
        </template>
      </el-table-column>
      <el-table-column
              width="180"
              label="签约状态">
        <template slot-scope="scope">
          <div class="contract-state-info" :class="[
                      scope.row.hasContract?'active-status-2':'active-status-0',
                      {'is-presentable-online':scope.row.isOnlineChecked}
                    ]">
            <i class="dot"></i>
            <div class="scheme-state">
              <div>
                <template v-if="scope.row.hasContract">已签约</template>
                <template v-else>
                  未签约
                  <el-button type="text" @click="deletePresentableHandler(scope.row)"><i class="el-icon-delete"></i>
                  </el-button>
                </template>
              </div>
              <p class="scheme-info" v-if="scope.row.scheme && scope.row.scheme.selectedPolicy">
                {{scope.row.scheme.authSchemeName}}/{{scope.row.scheme.selectedPolicy.policyName}}</p>
            </div>
          </div>
        </template>
      </el-table-column>
      <el-table-column
              width="250"
              label="">
        <template slot-scope="{row}">
          <div class="presentable-nav-links active-status-0">
            <router-link :to="row.detailLink + '?tab=policy'">
              <el-button type="text" class="nav-link-btn">策略管理<i class="dot" v-if="(row.status&2) !== 2"></i>
              </el-button>
            </router-link>
            <span>|</span>
            <router-link :to="row.detailLink + '?tab=contract'">
              <el-button type="text" class="nav-link-btn" :disabled="!row.hasContract">合约管理<i class="dot"
                                                                                              v-if="row.hasContract && row.isContractActived === false"></i>
              </el-button>
            </router-link>
            <span>|</span>
            <router-link :to="row.detailLink + '?tab=scheme'">
              <el-button type="text" class="nav-link-btn">授权方案<i class="dot" v-if="(row.status&1) !== 1"></i>
              </el-button>
            </router-link>
          </div>
        </template>
      </el-table-column>
      <el-table-column
              width="150"
              label="资源类型">
        <template slot-scope="scope">
          <div>
            <span class="resource-type" :class="['is-'+scope.row.resourceInfo.resourceType]">{{scope.row.resourceInfo.resourceType}}</span>
          </div>
        </template>
      </el-table-column>
      <slot name="append"></slot>
    </template>
    <template slot="empty">
      <slot name="empty"></slot>
    </template>
  </pagination>
</template>

<script>
import {PRESENTABLE_STATUS_TIPS} from '@/config/presentable'
import {loadAuthSchemes} from '@/data/scheme/loader'
import Pagination from '@/components/Pagination/index.vue'

export default {
  name: 'node-presentable-list',

  data() {
    return {
      tableConfig: {
        rowClassName: 'resource-row',
        'cell-class-name': 'res-row-cell',
        'show-header': false
      },
      paginationConfig: {
        target: `/v1/presentables`,
        params: {
          nodeId: this.$route.params.nodeId
        }
      }
    }
  },

  props: {
    params: Object,
    showFooter: Boolean
  },

  components: {Pagination},

  watch: {
    params: {
      deep: true,
      handler() {
        this.reload()
      }
    },
    $route() {
      if (!this.$route.params.nodeId) return
      this.paginationConfig.params.nodeId = this.$route.params.nodeId
    }
  },

  mounted() {
    this.reload()
  },

  methods: {
    setParams() {
      var params = Object.assign({
        nodeId: this.$route.params.nodeId
      }, this.params || {})

      this.$set(this.paginationConfig, 'params', params)
    },
    refresh() {
      this.$refs.listRef.reload()
    },
    reload() {
      this.setParams()
      this.refresh()
    },
    formatHandler(list) {
      if (!list || !list.length) {
        return []
      }

      var authSchemeIds = []
      var maps = {}
      var schemeIdMaps = {}
      var presentablesIdMap = {}
      var promises = []
      var promise

      list.forEach((item, index) => {
        let contract = this.getPresentableContract(item)

        if (contract) {
          authSchemeIds.push(contract.authSchemeId)
          schemeIdMaps[contract.authSchemeId] = {
            index, contract
          }
        }

        maps[item.resourceId] = index
        presentablesIdMap[item.presentableId] = item
        item.resourceInfo.postImgUrl = this.resolvePostImgUrl(item.resourceInfo)
        this.resolvePresentable(item)
      })

      if (authSchemeIds.length) {
        promise = this.loadPresentablesSchemes(authSchemeIds)
          .then(schemes => {
            schemes.forEach(scheme => {
              let {index, contract} = schemeIdMaps[scheme.authSchemeId]
              scheme.selectedPolicy = this.getSelectedPolicy(scheme, contract)
              this.$set(list[index], 'scheme', scheme)
            })
            schemeIdMaps = null
          })
        promises.push(promise)
      }

      var presentableIds = Object.keys(presentablesIdMap)
      if (presentableIds.length) {
        promise = this.loadPresentablesAuth(presentableIds)
          .then((auths) => {
            auths.forEach(auth => {
              let presentable = presentablesIdMap[auth.presentableId]
              presentable.authResult = Number.isInteger(auth.authResult) ? auth.authResult : -1
            })
          })

        promises.push(promise)
        promise = this.loadPresentablesContractState(presentableIds)
          .then(states => {
            states.forEach(state => {
              let presentable = presentablesIdMap[state.presentableId]
              presentable.isContractActived = (state.status === 1)
            })
          })
        promises.push(promise)
      }

      if (promises.length) {
        Promise.all(promises).then(() => {
          this.fillWarningTips(list)
        })
      }

      return list
    },
    fillWarningTips(presentables) {
      //判断授权链上的策略包含presentable授权
      const tips = {
        'no': '未获得授权', //合同未到达presentable状态，无法让c端用户签约
        'yes': '已获得授权'
      }
      const contractTips = {
        'no': '已签约合同未全部激活',
        'yes': '全部激活'
      }
      const policyTips = {
        'no': '没有可用策略',
{'fraction_non_alphanumeric': 0.14740502942750133, 'fraction_numerical': 0.0029427501337613697, 'mean_word_length': 1.7814360119047619, 'pattern_counts': {'":': 0, '<': 179, '<?xml version=': 0, '>': 195, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '957944', 'n_tokens_mistral': 4496, 'n_tokens_neox': 4512, 'n_words': 652}