From c04b9e534096a50342f707ec1858e07743ba9be1 Mon Sep 17 00:00:00 2001 From: Anthony Lapenna Date: Thu, 13 Jul 2017 13:50:42 +0200 Subject: [PATCH] feat(volumes): new truncate method for volume paths (#1028) --- app/components/volumes/volumes.html | 2 +- app/filters/filters.js | 17 +++++++++++++++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/app/components/volumes/volumes.html b/app/components/volumes/volumes.html index d0eb0f744..d467c2c9b 100644 --- a/app/components/volumes/volumes.html +++ b/app/components/volumes/volumes.html @@ -85,7 +85,7 @@ {{ volume.Id|truncate:25 }} {{ volume.Driver }} - {{ volume.Mountpoint | truncate:52 }} + {{ volume.Mountpoint | truncatelr }} diff --git a/app/filters/filters.js b/app/filters/filters.js index b1201dcf7..b5573bcd5 100644 --- a/app/filters/filters.js +++ b/app/filters/filters.js @@ -12,12 +12,25 @@ angular.module('portainer.filters', []) if (text.length <= length || text.length - end.length <= length) { return text; - } - else { + } else { return String(text).substring(0, length - end.length) + end; } }; }) +.filter('truncatelr', function () { + 'use strict'; + return function (text, max, left, right) { + max = isNaN(max) ? 50 : max; + left = isNaN(left) ? 25 : left; + right = isNaN(right) ? 25 : right; + + if (text.length <= max) { + return text; + } else { + return text.substring(0, left) + '[...]' + text.substring(text.length - right, text.length); + } + }; +}) .filter('taskstatusbadge', function () { 'use strict'; return function (text) {