From 29d66bfd978f8a46f7033b7d2c3c5a5f03a2b6ea Mon Sep 17 00:00:00 2001 From: Anthony Lapenna Date: Wed, 19 Jul 2017 16:34:11 +0200 Subject: [PATCH] fix(containers): add support for the 'dead' status (#1048) --- app/filters/filters.js | 39 ++++++++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 15 deletions(-) diff --git a/app/filters/filters.js b/app/filters/filters.js index b5573bcd5..b4cac3fe0 100644 --- a/app/filters/filters.js +++ b/app/filters/filters.js @@ -1,3 +1,9 @@ +function includeString(text, values) { + return values.some(function(val){ + return text.indexOf(val) !== -1; + }); +} + angular.module('portainer.filters', []) .filter('truncate', function () { 'use strict'; @@ -35,15 +41,13 @@ angular.module('portainer.filters', []) 'use strict'; return function (text) { var status = _.toLower(text); - if (status.indexOf('new') !== -1 || status.indexOf('allocated') !== -1 || - status.indexOf('assigned') !== -1 || status.indexOf('accepted') !== -1) { + if (includeString(status, ['new', 'allocated', 'assigned', 'accepted'])) { return 'info'; - } else if (status.indexOf('pending') !== -1) { + } else if (includeString(status, ['pending'])) { return 'warning'; - } else if (status.indexOf('shutdown') !== -1 || status.indexOf('failed') !== -1 || - status.indexOf('rejected') !== -1) { + } else if (includeString(status, ['shutdown', 'failed', 'rejected'])) { return 'danger'; - } else if (status.indexOf('complete') !== -1) { + } else if (includeString(status, ['complete'])) { return 'primary'; } return 'success'; @@ -53,11 +57,11 @@ angular.module('portainer.filters', []) 'use strict'; return function (text) { var status = _.toLower(text); - if (status.indexOf('paused') !== -1 || status.indexOf('starting') !== -1) { + if (includeString(status, ['paused', 'starting'])) { return 'warning'; - } else if (status.indexOf('created') !== -1) { + } else if (includeString(status, ['created'])) { return 'info'; - } else if (status.indexOf('stopped') !== -1 || status.indexOf('unhealthy') !== -1) { + } else if (includeString(status, ['stopped', 'unhealthy', 'dead'])) { return 'danger'; } return 'success'; @@ -67,17 +71,19 @@ angular.module('portainer.filters', []) 'use strict'; return function (text) { var status = _.toLower(text); - if (status.indexOf('paused') !== -1) { + if (includeString(status, ['paused'])) { return 'paused'; - } else if (status.indexOf('created') !== -1) { + } else if (includeString(status, ['dead'])) { + return 'dead'; + } else if (includeString(status, ['created'])) { return 'created'; - } else if (status.indexOf('exited') !== -1) { + } else if (includeString(status, ['exited'])) { return 'stopped'; - } else if (status.indexOf('(healthy)') !== -1) { + } else if (includeString(status, ['(healthy)'])) { return 'healthy'; - } else if (status.indexOf('(unhealthy)') !== -1) { + } else if (includeString(status, ['(unhealthy)'])) { return 'unhealthy'; - } else if (status.indexOf('(health: starting)') !== -1) { + } else if (includeString(status, ['(health: starting)'])) { return 'starting'; } return 'running'; @@ -113,6 +119,9 @@ angular.module('portainer.filters', []) if (state === undefined) { return ''; } + if (state.Dead) { + return 'Dead'; + } if (state.Ghost && state.Running) { return 'Ghost'; }