<commit_before>/**
 * Copyright (C) 2018-2022  The Software Heritage developers
 * See the AUTHORS file at the top-level directory of this distribution
 * License: GNU Affero General Public License version 3, or any later version
 * See top-level LICENSE file for more information
 */

import {getHumanReadableDate} from 'utils/functions';

function genSwhLink(data, type, linkText = '') {
  if (type === 'display' && data && data.startsWith('swh')) {
    const browseUrl = Urls.browse_swhid(data);
    const formattedSWHID = data.replace(/;/g, ';<br/>');
    if (!linkText) {
      linkText = formattedSWHID;
    }
    return `<a href="${browseUrl}">${linkText}</a>`;
  }
  return data;
}

function genLink(data, type, openInNewTab = false, linkText = '') {
  if (type === 'display' && data) {
    const sData = encodeURI(data);
    if (!linkText) {
      linkText = sData;
    }
    let attrs = '';
    if (openInNewTab) {
      attrs = 'target="_blank" rel="noopener noreferrer"';
    }
    return `<a href="${sData}" ${attrs}>${linkText}</a>`;
  }
  return data;
}

export function initDepositAdmin(username, isStaff) {
  let depositsTable;
  $(document).ready(() => {
    $.fn.dataTable.ext.errMode = 'none';
    depositsTable = $('#swh-admin-deposit-list')
      .on('error.dt', (e, settings, techNote, message) => {
        $('#swh-admin-deposit-list-error').text(message);
      })
      .DataTable({
        serverSide: true,
        processing: true,
        // let's define the order of table options display
        // f: (f)ilter
        // l: (l)ength changing
        // r: p(r)ocessing
        // t: (t)able
        // i: (i)nfo
        // p: (p)agination
        // see https://datatables.net/examples/basic_init/dom.html
        dom: '<<"d-flex justify-content-between align-items-center"f' +
             '<"#list-exclude">l>rt<"bottom"ip>>',
        // div#list-exclude is a custom filter added next to dataTable
        // initialization below through js dom manipulation, see
        // https://datatables.net/examples/advanced_init/dom_toolbar.html
        ajax: {
          url: Urls.admin_deposit_list(),
          data: d => {
            d.excludePattern = $('#swh-admin-deposit-list-exclude-filter').val();
            if (!isStaff) {
              d.username = username;
            }
          }<commit_msg>assets/admin/deposits: Remove deposits filtering by user for non staff<commit_after>/**
 * Copyright (C) 2018-2022  The Software Heritage developers
 * See the AUTHORS file at the top-level directory of this distribution
 * License: GNU Affero General Public License version 3, or any later version
 * See top-level LICENSE file for more information
 */

import {getHumanReadableDate} from 'utils/functions';

function genSwhLink(data, type, linkText = '') {
  if (type === 'display' && data && data.startsWith('swh')) {
    const browseUrl = Urls.browse_swhid(data);
    const formattedSWHID = data.replace(/;/g, ';<br/>');
    if (!linkText) {
      linkText = formattedSWHID;
    }
    return `<a href="${browseUrl}">${linkText}</a>`;
  }
  return data;
}

function genLink(data, type, openInNewTab = false, linkText = '') {
  if (type === 'display' && data) {
    const sData = encodeURI(data);
    if (!linkText) {
      linkText = sData;
    }
    let attrs = '';
    if (openInNewTab) {
      attrs = 'target="_blank" rel="noopener noreferrer"';
    }
    return `<a href="${sData}" ${attrs}>${linkText}</a>`;
  }
  return data;
}

export function initDepositAdmin(username, isStaff) {
  let depositsTable;
  $(document).ready(() => {
    $.fn.dataTable.ext.errMode = 'none';
    depositsTable = $('#swh-admin-deposit-list')
      .on('error.dt', (e, settings, techNote, message) => {
        $('#swh-admin-deposit-list-error').text(message);
      })
      .DataTable({
        serverSide: true,
        processing: true,
        // let's define the order of table options display
        // f: (f)ilter
        // l: (l)ength changing
        // r: p(r)ocessing
        // t: (t)able
        // i: (i)nfo
        // p: (p)agination
        // see https://datatables.net/examples/basic_init/dom.html
        dom: '<<"d-flex justify-content-between align-items-center"f' +
             '<"#list-exclude">l>rt<"bottom"ip>>',
        // div#list-exclude is a custom filter added next to dataTable
        // initialization below through js dom manipulation, see
        // https://datatables.net/examples/advanced_init/dom_toolbar.html
        ajax: {
          url: Urls.admin_deposit_list(),
          data: d => {
            d.excludePattern = $('#swh-admin-deposit-list-exclude-filter').val();
          }
{'fraction_non_alphanumeric': 0.1558469475494411, 'fraction_numerical': 0.003869303525365434, 'mean_word_length': 2.6153846153846154, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 27, 'https://': 4, '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': '1062304', 'n_tokens_mistral': 1534, 'n_tokens_neox': 1465, 'n_words': 356}