Index: app/models/models.js |
=== modified file 'app/models/models.js' |
--- app/models/models.js 2013-04-12 16:04:02 +0000 |
+++ app/models/models.js 2013-04-17 13:28:40 +0000 |
@@ -91,7 +91,26 @@ |
}); |
models.Environment = Environment; |
- var Service = Y.Base.create('service', Y.Model, [], {}, { |
+ var ALIVE = 'alive'; |
+ |
+ var Service = Y.Base.create('service', Y.Model, [], { |
+ |
+ /** |
+ Return true if this service life is "alive", false otherwise. |
+ |
+ A model instance is alive if its life cycle (i.e. the "life" attribute) |
+ is set to "alive". Other possible values, as they arrive from the |
+ juju-core delta stream, are "dying" and "dead", in which cases the |
+ service is not considered alive. |
+ |
+ @method isAlive |
+ @return {Boolean} Whether this service is alive. |
+ */ |
+ isAlive: function() { |
+ return this.get('life') === ALIVE; |
+ } |
+ |
+ }, { |
ATTRS: { |
displayName: { |
/** |
@@ -115,6 +134,9 @@ |
pending: { |
value: false |
}, |
+ life: { |
+ value: ALIVE |
+ }, |
unit_count: {}, |
aggregated_status: {} |
} |
@@ -124,6 +146,18 @@ |
var ServiceList = Y.Base.create('serviceList', Y.ModelList, [], { |
model: Service, |
+ /** |
+ Return a list of alive model instances. |
+ |
+ @method alive |
+ @return {Y.ModelList} The model instances having life === 'alive'. |
+ */ |
+ alive: function() { |
+ return this.filter({asList: true}, function(model) { |
+ return model.isAlive(); |
+ }); |
+ }, |
+ |
process_delta: function(action, data) { |
_process_delta(this, action, data, {exposed: false}); |
} |