Display link column in part table

This commit is contained in:
Oliver Walters 2021-01-20 18:04:08 +11:00
parent 71522fa608
commit 69362ab960
2 changed files with 38 additions and 2 deletions

View File

@ -8,11 +8,33 @@ function deleteButton(url, text='Delete') {
}
function renderLink(text, url) {
if (text === '' || url === '') {
function renderLink(text, url, options={}) {
if (url == null || url === '') {
return text;
}
var max_length = options.max_length || -1;
var remove_http = options.remove_http || false;
if (remove_http) {
if (text.startsWith('http://')) {
text = text.slice(7);
} else if (text.startsWith('https://')) {
text = text.slice(8);
}
}
// Shorten the displayed length if required
if ((max_length > 0) && (text.length > max_length)) {
var slice_length = (max_length - 3) / 2;
var text_start = text.slice(0, slice_length);
var text_end = text.slice(-slice_length);
text = `${text_start}...${text_end}`;
}
return '<a href="' + url + '">' + text + '</a>';
}

View File

@ -446,6 +446,20 @@ function loadPartTable(table, url, options={}) {
}
});
columns.push({
field: 'link',
title: '{% trans "Link" %}',
formatter: function(value, row, index, field) {
return renderLink(
value, value,
{
max_length: 32,
remove_http: true,
}
);
}
});
$(table).inventreeTable({
url: url,
sortName: 'name',