From 2027d1e7dc82e88822acde197e5cfce16b237648 Mon Sep 17 00:00:00 2001 From: Vincent Fiduccia Date: Thu, 10 Aug 2017 09:58:23 -0700 Subject: [PATCH] Missed a file.. --- app/mixins/endpoint-ports.js | 74 ++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 app/mixins/endpoint-ports.js diff --git a/app/mixins/endpoint-ports.js b/app/mixins/endpoint-ports.js new file mode 100644 index 000000000..d815eb249 --- /dev/null +++ b/app/mixins/endpoint-ports.js @@ -0,0 +1,74 @@ +import Ember from 'ember'; +import Util from 'ui/utils/util'; + +export default Ember.Mixin.create({ + intl: Ember.inject.service(), + + endpointsMap: function() { + var out = {}; + (this.get('publicEndpoints')||[]).forEach((endpoint) => { + if ( !endpoint.publicPort ) + { + // Skip nulls + return; + } + + let key = endpoint.get('portProto'); + let ary = out[key] + if ( !ary ) { + ary = []; + out[key] = ary; + } + + out[key].push(endpoint); + }); + + return out; + }.property('publicEndpoints.@each.{ipAddress,publicPort}'), + + endpointsByPort: function() { + var out = []; + var map = this.get('endpointsMap'); + Object.keys(map).forEach((key) => { + out.push({ + port: parseInt(key,10), + endpoints: map[key] + }); + }); + + return out; + }.property('endpointsMap'), + + endpointPorts: Ember.computed.mapBy('endpointsByPort','publicPort'), + + displayEndpoints: function() { + let parts = []; + + this.get('endpointsByPort').forEach((obj) => { + let endpoint = obj.endpoints.get('firstObject'); + if ( endpoint ) { + if ( endpoint.get('isMaybeHttp') ) { + parts.push('' + + '' + + Util.escapeHtml(endpoint.get('displayEndpoint')) + + '' + + ''); + } else { + parts.push('' + Util.escapeHtml(endpoint.get('displayEndpoint')) + ''); + } + } + }); + + let pub = parts.join(" / "); + + if ( pub ) + { + return pub.htmlSafe(); + } + else + { + return ''; + } + }.property('endpointsByPort.@each.{port,endpoints}', 'intl.locale'), + +});