2018-09-25 16:28:26 +00:00
|
|
|
import { capitalize } from '@ember/string';
|
|
|
|
import Component from '@ember/component';
|
|
|
|
import { computed } from '@ember/object';
|
2018-05-25 20:33:22 +00:00
|
|
|
import columnify from 'columnify';
|
|
|
|
|
|
|
|
export function stringifyObjectValues(data) {
|
2021-12-17 03:44:29 +00:00
|
|
|
Object.keys(data).forEach((item) => {
|
2018-05-25 20:33:22 +00:00
|
|
|
let val = data[item];
|
|
|
|
if (typeof val !== 'string') {
|
|
|
|
val = JSON.stringify(val);
|
|
|
|
}
|
|
|
|
data[item] = val;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-09-25 16:28:26 +00:00
|
|
|
export default Component.extend({
|
2018-05-25 20:33:22 +00:00
|
|
|
content: null,
|
2021-12-17 03:44:29 +00:00
|
|
|
columns: computed('content', function () {
|
2022-11-09 23:15:31 +00:00
|
|
|
const data = this.content;
|
2018-05-25 20:33:22 +00:00
|
|
|
stringifyObjectValues(data);
|
|
|
|
|
|
|
|
return columnify(data, {
|
|
|
|
preserveNewLines: true,
|
2021-12-17 03:44:29 +00:00
|
|
|
headingTransform: function (heading) {
|
2018-09-25 16:28:26 +00:00
|
|
|
return capitalize(heading);
|
2018-05-25 20:33:22 +00:00
|
|
|
},
|
|
|
|
});
|
|
|
|
}),
|
|
|
|
});
|