Merge remote-tracking branch 'powerbi/master'

This commit is contained in:
Ali Hamud 2018-04-26 07:27:53 -07:00
Родитель 727a638bb1 82f4e97019
Коммит a8001c15cb
2 изменённых файлов: 85 добавлений и 9 удалений

Просмотреть файл

@ -1272,7 +1272,7 @@ function _Page_HasLayout() {
// Get a reference to the embedded report.
report = powerbi.get(embedContainer);
// Retrieve the page collection and check if the first page has a MobilePortrait layout.
report.getPages().then(function (pages) {
pages[0].hasLayout(models.LayoutType.MobilePortrait).then(function(hasLayout) {
@ -1575,7 +1575,7 @@ function _Bookmarks_Capture() {
// Get a reference to the embedded report.
report = powerbi.get(embedContainer);
// Capture the current bookmark and prints the bookmark's
// Capture the current bookmark and prints the bookmark's
// state string to Log window.
report.bookmarksManager.capture()
.then(function (capturedBookmark) {
@ -1800,8 +1800,8 @@ function _Visual_ExportData_Summarized() {
// Exports visual data
visual.exportData(models.ExportDataType.Summarized)
.then(function (data) {
Log.log(data);
.then(function (result) {
Log.logCsv(result.data);
})
.catch(function (errors) {
Log.log(errors);
@ -1845,8 +1845,8 @@ function _Visual_ExportData_Underlying() {
// Exports visual data
visual.exportData(models.ExportDataType.Underlying)
.then(function (data) {
Log.log(data);
.then(function (result) {
Log.logCsv(result.data);
})
.catch(function (errors) {
Log.log(errors);

Просмотреть файл

@ -2,13 +2,16 @@ function InitLogger(divId) {
var Logger = {};
Logger.log = function name(event) {
// Normal character takes ~1.5 width more than a space ' '.
Logger.spaceWidthCorrection = 1.3;
Logger.log = function (event) {
this.logText("Json Object\n" + JSON.stringify(event, null, " "));
};
Logger.logText = function name(text) {
Logger.logText = function (text) {
let textbox = document.getElementById(divId);
if (!textbox.value)
{
textbox.value = "";
@ -19,5 +22,78 @@ function InitLogger(divId) {
textbox.scrollTop = textbox.scrollHeight;
};
Logger.logCsv = function (text) {
let textbox = document.getElementById(divId);
if (!textbox.value)
{
textbox.value = "";
}
let maxLength = 0;
let lines = text.split("\r\n");
let valuesPerLine = [];
let log = "> CSV result in table view: \n\n";
if (!lines || lines.length === 0) {
log += "No data";
}
else {
// Calcualte values per line, and calculate max length for pretty print.
for (let i = 0; i < lines.length; ++i) {
valuesPerLine[i] = lines[i].split(",");
valuesPerLine[i].forEach(function (val) {
if (val.length > maxLength) {
maxLength = val.length;
}
});
}
// Add 2 spaces before and after.
maxLength += 4;
// Print title line
var title = this.getLineText(valuesPerLine[0], maxLength);
log += title + "\n";
log += this.repeatChar("-", title.length) + "\n";
// Print all lines
for (let i = 1; i < lines.length; ++i) {
log += this.getLineText(valuesPerLine[i], maxLength) + "\n"
}
}
textbox.value += log;
textbox.scrollTop = textbox.scrollHeight;
};
Logger.getLineText = function (values, spacesPerWord) {
var text = "";
_this = this;
values.forEach(function (val) {
text += _this.getCenteredText(val, spacesPerWord);
});
return text;
};
Logger.getCenteredText = function (value, spaces) {
var text = "";
let spacesBefore = (spaces - value.length) / 2;
let spacesAfter = spaces - value.length - spacesBefore;
text += this.repeatChar(" ", spacesBefore * this.spaceWidthCorrection);
text += value;
text += this.repeatChar(" ", spacesAfter * this.spaceWidthCorrection);
return text;
};
Logger.repeatChar = function (char, times) {
let text = "";
for (let i = 0; i < times; ++i) {
text += char;
}
return text;
};
return Logger;
}