Skip to content

Commit 9cf71e4

Browse files
authored
Merge pull request #9 from xgeek-net/dev
v1.2.0 release
2 parents fa43c78 + 6bf23f5 commit 9cf71e4

File tree

7 files changed

+236
-47
lines changed

7 files changed

+236
-47
lines changed

bower.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"vue": "^2.5.16",
1717
"font-awesome": "^5.0.13",
1818
"moment": "^2.22.2",
19-
"js-xlsx": "^0.14.0"
19+
"js-xlsx": "^0.14.0",
20+
"xlsx-populate": "^1.17.0"
2021
}
2122
}

builder.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
"!src/view/components/font-awesome/advanced-options/*",
2222
"!src/view/components/font-awesome/svg-with-js/*",
2323
"!src/view/components/font-awesome/use-on-desktop/*",
24+
"!src/view/components/xlsx-populate/examples/*",
2425
"!src/view/components/js-xlsx/demos/*",
2526
"!src/view/components/js-xlsx/docbits/*",
2627
"!src/view/components/js-xlsx/test_files/*",

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "pipeline",
33
"description": "Be less busy, less mistake in Salesforce metadata deploy",
4-
"version": "1.1.0",
4+
"version": "1.2.0",
55
"private": false,
66
"main": "src/main.js",
77
"dependencies": {

src/view/css/style.css

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,7 @@
349349
width: 1.8rem;
350350
height: 1.8rem;
351351
}
352+
352353
.slds-dropdown--actions a.slds-color-text-error,
353354
.slds-dropdown_actions a.slds-color-text-error,
354355
.slds-dropdown--actions a.slds-color-text-error:hover,
@@ -386,8 +387,25 @@
386387
.new-pipeline-detail-sfdc .slds-form_horizontal .slds-form-element>.slds-form-element__label.slds-text-align_left{
387388
text-align: left;
388389
}
389-
390-
390+
.new-pipeline-detail-sfdc .slds-th__action{
391+
height: auto;
392+
padding: 0;
393+
}
394+
.new-pipeline-detail-sfdc .slds-is-sortable__icon{
395+
opacity: 0;
396+
display: inline-block;
397+
}
398+
.new-pipeline-detail-sfdc .slds-is-sortable .slds-th__action:hover,
399+
.new-pipeline-detail-sfdc .slds-is-sortable .slds-th__action:focus {
400+
background-color: transparent;
401+
}
402+
.new-pipeline-detail-sfdc .slds-is-sortable .slds-th__action:hover .slds-icon,
403+
.new-pipeline-detail-sfdc .slds-is-sortable .slds-th__action:focus .slds-icon {
404+
opacity: 1.0;
405+
}
406+
.new-pipeline-detail-sfdc .sort-active .slds-th__action .slds-icon{
407+
opacity: 1.0;
408+
}
391409
/**
392410
* pipeline-detail
393411
*/

src/view/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ <h1 class="">{{ page.title }}</h1>
4444

4545
<script type="text/javascript" src="components/vue/dist/vue.min.js"></script>
4646
<script type="text/javascript" src="components/moment/min/moment-with-locales.min.js"></script>
47+
<script type="text/javascript" src="components/xlsx-populate/browser/xlsx-populate.min.js"></script>
4748
<script type="text/javascript" src="components/js-xlsx/dist/xlsx.full.min.js"></script>
4849
<script type="text/javascript" src="js/include/ExcelHandler.js"></script>
4950
<script type="text/javascript" src="js/include/master.js"></script>

src/view/js/include/ExcelHandler.js

Lines changed: 82 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -27,30 +27,75 @@ ExcelHandler.prototype.read = function(file, callback) {
2727

2828
// Export data to excel
2929
ExcelHandler.prototype.write = function(data, fileName) {
30-
fileName = fileName || 'Pipeline.xlsx';
31-
function s2ab(s) {
32-
var buf = new ArrayBuffer(s.length);
33-
var view = new Uint8Array(buf);
34-
for (var i=0; i!=s.length; ++i) view[i] = s.charCodeAt(i) & 0xFF;
35-
return buf;
36-
}
37-
const wb = XLSX.utils.book_new();
38-
for(let sheetName in data) {
39-
const ws = XLSX.utils.aoa_to_sheet(data[sheetName]);
40-
XLSX.utils.book_append_sheet(wb, ws, sheetName);
41-
}
42-
// const ws = XLSX.utils.aoa_to_sheet(data['Reference']);
43-
// XLSX.utils.book_append_sheet(wb, ws, 'Reference');
44-
45-
const fileContent = XLSX.write(wb, {bookType:'xlsx', bookSST:true, type: 'binary'});
46-
let link = document.createElement("A");
47-
const blob = new Blob([s2ab(fileContent)],{type:""})
48-
link.href = window.URL.createObjectURL(blob);
49-
link.download = fileName;
50-
link.target = '_blank';
51-
document.body.appendChild(link);
52-
link.click();
53-
document.body.removeChild(link);
30+
const self = this;
31+
fileName = fileName || 'Pipeline';
32+
XlsxPopulate
33+
.fromBlankAsync()
34+
.then(function(workbook) {
35+
// Create sheets
36+
workbook.sheet(0).name('Metadata');
37+
workbook.addSheet('Reference');
38+
for(let sheetName in data) {
39+
const sheet = workbook.sheet(sheetName);
40+
let columnCount = 0;
41+
let lineCount = 0;
42+
for(let l = 0; l < data[sheetName].length; l++) {
43+
let line = data[sheetName][l];
44+
let styles = {
45+
'border' : {
46+
top: { style: "thin" },
47+
left: { style: "thin" },
48+
bottom: { style: "thin" },
49+
right: { style: "thin" }
50+
},
51+
'wrapText' : true};
52+
if(l == 0) {
53+
lineCount = data[sheetName].length;
54+
columnCount = line.length;
55+
}
56+
for(let c = 0; c < line.length; c++) {
57+
// l0-c0 to A1, l0-c1 to B1
58+
let val = line[c];
59+
let cellNo = String.fromCharCode(65 + c) + (l + 1);
60+
sheet.cell(cellNo).value(val).style(styles);
61+
if(l == 0) {
62+
let fillStyle = (c < 3) ? {'fill' : '4285f4'} : {'fill' : 'a5a5a5'};
63+
sheet.cell(cellNo).style(fillStyle);
64+
} else {
65+
if(c == 4 && val.length > 0) {
66+
sheet.cell(cellNo).value(moment(val).format('YYYY/MM/DD HH:mm'))
67+
}
68+
}
69+
}
70+
}
71+
// Rejust cell width to fit data
72+
for(let c = 0; c < columnCount; c++) {
73+
let cellChar = String.fromCharCode(65 + c);
74+
// A1:A20
75+
const maxLength = sheet.range(cellChar + '1:' + cellChar + lineCount)
76+
.reduce(function(max, cell) {
77+
const value = cell.value();
78+
if (value === undefined) return max;
79+
// set length to 2x if has japanese string
80+
const vLen = self.getBytes(value.toString());
81+
return Math.max(max, vLen);
82+
}, 0);
83+
sheet.column(cellChar).width(maxLength + 5);
84+
}
85+
}
86+
return workbook.outputAsync();
87+
})
88+
.then(function(blob) {
89+
let link = document.createElement('A');
90+
//const blob = new Blob([s2ab(fileContent)],{type:""})
91+
link.href = window.URL.createObjectURL(blob);
92+
link.download = fileName + '.xlsx';;
93+
link.target = '_blank';
94+
document.body.appendChild(link);
95+
link.click();
96+
document.body.removeChild(link);
97+
});
98+
5499
}
55100

56101
// Read and convert xlsx to json
@@ -112,4 +157,17 @@ ExcelHandler.prototype.handleCodePoints = function(array) {
112157
index += CHUNK_SIZE;
113158
}
114159
return result;
160+
}
161+
// 'abcde' → 5, 'あいうえお' → 10
162+
ExcelHandler.prototype.getBytes = function(txt) {
163+
var length = 0;
164+
for (var i = 0; i < txt.length; i++) {
165+
var c = txt.charCodeAt(i);
166+
if ((c >= 0x0 && c < 0x81) || (c === 0xf8f0) || (c >= 0xff61 && c < 0xffa0) || (c >= 0xf8f1 && c < 0xf8f4)) {
167+
length += 1;
168+
} else {
169+
length += 2;
170+
}
171+
}
172+
return length;
115173
}

0 commit comments

Comments
 (0)