web/res/js/tracemanager.js
changeset 583 f655dafb741e
parent 581 7607516bd9f1
child 623 5b7d7ab6baff
equal deleted inserted replaced
582:79b222c29887 583:f655dafb741e
    41                      // prefixing it with c
    41                      // prefixing it with c
    42                      var data = 'c' + JSON.stringify(temp.map(function (o) { return o.toCompactJSON(); }));
    42                      var data = 'c' + JSON.stringify(temp.map(function (o) { return o.toCompactJSON(); }));
    43                      // Swap " (very frequent, which will be
    43                      // Swap " (very frequent, which will be
    44                      // serialized into %22) and ; (rather rare), this
    44                      // serialized into %22) and ; (rather rare), this
    45                      // saves some bytes
    45                      // saves some bytes
    46                      data = data.replace(/[;"]/g, function(s){ return s == ';' ? '"' : ';'; }).replace(/#/g, '%23');
    46                      data = data.replace(/[;"#]/g, function(s){ return s == ';' ? '"' : ( s == '"' ? ';' : '%23'); });
    47                      // FIXME: check data length (< 2K is safe)
    47                      // FIXME: check data length (< 2K is safe)
    48                      var request=$('<img />').error( function() { this.failureCount += 1; })
    48                      var request=$('<img />').error( function() { this.failureCount += 1; })
    49                          .load( function() { this.failureCount = 0; })
    49                          .load( function() { this.failureCount = 0; })
    50                          .attr('src', this.url + 'trace/?data=' + data);
    50                          .attr('src', this.url + 'trace/?data=' + data);
    51                  }
    51                  }
   345          },
   345          },
   346 
   346 
   347          list_attribute_types: function() {
   347          list_attribute_types: function() {
   348              var result = [];
   348              var result = [];
   349              for (var prop in this.attributes) {
   349              for (var prop in this.attributes) {
   350                  if (this.hasOwnProperty(prop))
   350                  if (this.attributes.hasOwnProperty(prop))
   351                      result.push(prop);
   351                      result.push(prop);
   352              }
   352              }
   353              /* FIXME: we return URIs here instead of AttributeType elements */
   353              /* FIXME: we return URIs here instead of AttributeType elements */
   354              return result;
   354              return result;
   355          },
   355          },
   418                  "begin": this.begin,
   418                  "begin": this.begin,
   419                  "end": this.end,
   419                  "end": this.end,
   420                  "subject": this.subject
   420                  "subject": this.subject
   421              };
   421              };
   422              for (var prop in this.attributes) {
   422              for (var prop in this.attributes) {
   423                  if (this.hasOwnProperty(prop))
   423                  if (this.attributes.hasOwnProperty(prop))
   424                      r[prop] = this.attributes[prop];
   424                      r[prop] = this.attributes[prop];
   425              }
   425              }
   426              return r;
   426              return r;
   427          },
   427          },
   428 
   428 
   430           * Return a compact JSON representation of the obsel.
   430           * Return a compact JSON representation of the obsel.
   431           * Use predefined + custom shorthands for types/properties
   431           * Use predefined + custom shorthands for types/properties
   432           */
   432           */
   433          toCompactJSON: function() {
   433          toCompactJSON: function() {
   434              var r = {
   434              var r = {
   435                  "@i": this.id,
       
   436                  "@t": (this.trace.shorthands.hasOwnProperty(this.type) ? this.trace.shorthands[this.type] : this.type),
   435                  "@t": (this.trace.shorthands.hasOwnProperty(this.type) ? this.trace.shorthands[this.type] : this.type),
   437                  "@b": this.begin,
   436                  "@b": this.begin,
   438                  "@s": this.subject
   437                  "@s": this.subject
   439              };
   438              };
   440              // Store duration (to save some bytes) and only if it is non-null
   439              // Store duration (to save some bytes) and only if it is non-null
   441              if (this.begin !== this.end)
   440              if (this.begin !== this.end)
   442                  r["@d"] = this.end - this.begin;
   441                  r["@d"] = this.end - this.begin;
   443 
   442 
       
   443              // Store id only if != ""
       
   444              if (this.id !== "")
       
   445                  r["@i"] = this.id;
       
   446 
   444              for (var prop in this.attributes) {
   447              for (var prop in this.attributes) {
   445                  if (this.hasOwnProperty(prop))
   448                  if (this.attributes.hasOwnProperty(prop))
   446                  {
   449                  {
   447                      var v = this.attributes[prop];
   450                      var v = this.attributes[prop];
   448                      r[prop] = this.trace.shorthands.hasOwnProperty(v) ? this.trace.shorthands[v] : v;
   451                      r[prop] = this.trace.shorthands.hasOwnProperty(v) ? this.trace.shorthands[v] : v;
   449                  }
   452                  }
   450              }
   453              }