~makyo/juju-gui/rel-prep

« back to all changes in this revision

Viewing changes to app/models/models.js

  • Committer: Benjamin Saller
  • Author(s): Benjamin Saller
  • Date: 2013-10-10 17:06:41 UTC
  • mfrom: (1108.2.4 restore-bundle-annotations)
  • Revision ID: bcsaller@gmail.com-20131010170641-igy2gv5i6qsinl4s
Fix annotations on go backend

Fix annotation roundtrips with go backend
      Splits how we prepare deltas for py/go juju fakebackends
      Change test expectations to merge updateAnnotation calls
  
  Fix import of constraints
  Fix export of undefined/default values
  
  Adjust simulator unit count rate of change.

R=benjamin.saller, gary.poster, jeff.pihach
CC=
https://codereview.appspot.com/14485046

Show diffs side-by-side

added added

removed removed

Lines of Context:
278
278
      charmChanged: {
279
279
        value: false
280
280
      },
281
 
      constraints: {},
 
281
      constraints: {
 
282
        'setter': function(value) {
 
283
          if (typeof value === 'string') {
 
284
            var output = {};
 
285
            value.split(',').map(function(pair) {
 
286
              var kv = pair.split('=');
 
287
              output[kv[0]] = kv[1];
 
288
            });
 
289
            value = output;
 
290
          }
 
291
          return value;
 
292
        }
 
293
      },
282
294
      constraintsStr: {
283
295
        'getter': function() {
284
296
          var result = [];
285
297
          Y.each(this.get('constraints'), function(v, k) {
286
 
            result.push(k + '=' + v);
 
298
            if (v !== undefined) {
 
299
              result.push(k + '=' + v);
 
300
            }
287
301
          });
288
302
          if (result.length) {
289
303
            return result.join(',');
967
981
   * @return {Object} Annotations.
968
982
   */
969
983
  models.getAnnotations = function(entity) {
 
984
    if (!entity) {
 
985
      return undefined;
 
986
    }
970
987
    if (_annotationProperty[entity.name]) {
971
988
      return entity.annotations;
972
989
    }
973
990
    return entity.get('annotations');
974
991
  };
975
992
 
976
 
  models.setAnnotations = function(entity, annotations) {
 
993
  models.setAnnotations = function(entity, annotations, merge) {
 
994
    if (!entity) {
 
995
      return;
 
996
    }
 
997
    if (merge) {
 
998
      var existing = models.getAnnotations(entity) || {};
 
999
      annotations = Y.mix(existing, annotations, true);
 
1000
    }
977
1001
    if (_annotationProperty[entity.name]) {
978
1002
      entity.annotations = annotations;
979
1003
    } else {
1147
1171
        var units = service.get('units');
1148
1172
        var charm = self.charms.getById(service.get('charm'));
1149
1173
        var serviceOptions = {};
1150
 
        var charmOptions = charm.get('config.options');
 
1174
        var charmOptions = charm.get('options');
1151
1175
 
1152
1176
        if (service.get('pending') === true) {
1153
1177
          return;
1157
1181
        // that are the default value for the charm.
1158
1182
        Y.each(service.get('config'), function(value, key) {
1159
1183
          var optionData = charmOptions && charmOptions[key];
1160
 
          if (!optionData || (optionData && optionData['default'] &&
 
1184
          if ((!optionData && value !== undefined) ||
 
1185
              (optionData && optionData['default'] &&
1161
1186
              (value !== optionData['default']))) {
1162
1187
            serviceOptions[key] = value;
1163
1188
          }
1174
1199
        // Add constraints
1175
1200
        var constraints = service.get('constraintsStr');
1176
1201
        if (constraints) {
 
1202
          // constraintStr will filter out empty values
1177
1203
          serviceData.constraints = constraints;
1178
1204
        }
1179
1205