Browse Source

fix(table): remove html for htmlencoding option

bergquist 10 years ago
parent
commit
7d89cf228c

+ 0 - 6
public/app/plugins/panel/table/editor.html

@@ -103,11 +103,6 @@
 						<metric-segment-model property="style.dateFormat" options="editor.dateFormats" on-change="editor.render()" custom="true"></metric-segment-model>
 						<metric-segment-model property="style.dateFormat" options="editor.dateFormats" on-change="editor.render()" custom="true"></metric-segment-model>
 					</li>
 					</li>
 				</ul>
 				</ul>
-				<ul class="tight-form-list" ng-if="style.type === 'string'">
-					<li class="tight-form-item">
-						<editor-checkbox text="escape html" model="style.escapeHtml" change="editor.render()"></editor-checkbox>
-					</li>
-				</ul>
 				<div class="clearfix"></div>
 				<div class="clearfix"></div>
 			</div>
 			</div>
 			<div class="tight-form" ng-if="style.type === 'number'">
 			<div class="tight-form" ng-if="style.type === 'number'">
@@ -163,7 +158,6 @@
 				<div class="clearfix"></div>
 				<div class="clearfix"></div>
 			</div>
 			</div>
 
 
-
 		</div>
 		</div>
 	</div>
 	</div>
 
 

+ 0 - 1
public/app/plugins/panel/table/editor.ts

@@ -112,7 +112,6 @@ export class TablePanelEditorCtrl {
       pattern: '/.*/',
       pattern: '/.*/',
       dateFormat: 'YYYY-MM-DD HH:mm:ss',
       dateFormat: 'YYYY-MM-DD HH:mm:ss',
       thresholds: [],
       thresholds: [],
-      escapeHtml: true
     };
     };
 
 
     this.panel.styles.push(angular.copy(columnStyleDefaults));
     this.panel.styles.push(angular.copy(columnStyleDefaults));

+ 17 - 17
public/app/plugins/panel/table/renderer.ts

@@ -24,16 +24,16 @@ export class TableRenderer {
     return _.first(style.colors);
     return _.first(style.colors);
   }
   }
 
 
-  defaultCellFormater(value) {
-    if (value === null || value === void 0 || value === undefined) {
+  defaultCellFormater(v) {
+    if (v === null || v === void 0 || v === undefined) {
       return '';
       return '';
     }
     }
 
 
-    if (_.isArray(value)) {
-        value = value.join(',&nbsp;');
+    if (_.isArray(v)) {
+      v = v.join(',&nbsp;');
     }
     }
 
 
-    return value;
+    return v;
   }
   }
 
 
   createColumnFormater(style) {
   createColumnFormater(style) {
@@ -96,7 +96,7 @@ export class TableRenderer {
 
 
   renderCell(columnIndex, value, addWidthHack = false) {
   renderCell(columnIndex, value, addWidthHack = false) {
     value = this.formatColumnValue(columnIndex, value);
     value = this.formatColumnValue(columnIndex, value);
-    value = encodeHtml(value);
+    value = this.encodeHtml(value);
     var style = '';
     var style = '';
     if (this.colorState.cell) {
     if (this.colorState.cell) {
       style = ' style="background-color:' + this.colorState.cell + ';color: white"';
       style = ' style="background-color:' + this.colorState.cell + ';color: white"';
@@ -141,16 +141,16 @@ export class TableRenderer {
 
 
     return html;
     return html;
   }
   }
-}
 
 
-function encodeHtml(unsafe) {
-  return unsafe.replace(/[&<>"']/g, function(m) {
-    return ({
-      '&': '&amp;',
-      '<': '&lt;',
-      '>': '&gt;',
-      '"': '&quot;',
-      '\'': '&#039;'
-    })[m];
-  });
+  encodeHtml(unsafe) {
+    return unsafe.replace(/[&<>"']/g, function(m) {
+      return ({
+        '&': '&amp;',
+        '<': '&lt;',
+        '>': '&gt;',
+        '"': '&quot;',
+        '\'': '&#039;'
+      })[m];
+    });
+  }
 }
 }

+ 2 - 7
public/app/plugins/panel/table/specs/renderer_specs.ts

@@ -11,8 +11,7 @@ describe('when rendering table', () => {
       {text: 'Value'},
       {text: 'Value'},
       {text: 'Colored'},
       {text: 'Colored'},
       {text: 'Undefined'},
       {text: 'Undefined'},
-      {text: 'String'},
-      {text: 'UnescapedString' }
+      {text: 'String'}
     ];
     ];
 
 
     var panel = {
     var panel = {
@@ -41,10 +40,6 @@ describe('when rendering table', () => {
         {
         {
           pattern: 'String',
           pattern: 'String',
           type: 'string',
           type: 'string',
-        },
-        {
-          pattern: 'UnescapedString',
-          type: 'string'
         }
         }
       ]
       ]
     };
     };
@@ -92,7 +87,7 @@ describe('when rendering table', () => {
     });
     });
 
 
     it('undefined formater should return escaped html', () => {
     it('undefined formater should return escaped html', () => {
-      var html = renderer.renderCell(4, "&breaking <br /> the <br /> row");
+      var html = renderer.renderCell(3, "&breaking <br /> the <br /> row");
       expect(html).to.be('<td>&amp;breaking &lt;br /&gt; the &lt;br /&gt; row</td>');
       expect(html).to.be('<td>&amp;breaking &lt;br /&gt; the &lt;br /&gt; row</td>');
     });
     });