-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex4.html
158 lines (149 loc) · 6.25 KB
/
index4.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
<html>
<head>
<style>
/* .container {
display: grid;
gap: 20px;
} */
.row {
display: grid;
gap: 10px;
}
.cell {
grid-row: 1;
/* border: 1px solid yellow; */
text-align: center;
padding-top: 5px;
padding-bottom: 5px;
margin-top: 5px;
margin-bottom: 5px;
}
</style>
<script async defer src="https://apis.google.com/js/api.js" onload="this.onload=function(){};handleClientLoad()"
onreadystatechange="if (this.readyState === 'complete') this.onload()">
</script>
<script>
function start() {
// Initializes the client with the API key and the Translate API.
gapi.client.init({
'apiKey': 'AIzaSyBRW6aMCSm4aoo636LnVIExSMYWuow7IV4',
'discoveryDocs': ['https://sheets.googleapis.com/$discovery/rest?version=v4'],
}).then(function (response) {
// console.log(response);
});
};
// Loads the JavaScript client library and invokes `start` afterwards.
function handleClientLoad() {
gapi.load('client', start);
// execute();
}
function execute() {
return gapi.client.sheets.spreadsheets.get({
"spreadsheetId": "1xou6_yJOAtKxzcugUWuE1JpzIhPqI0WMJN05M-U1sJc",
"includeGridData": true
}).then(function (response) {
// Handle the results here (response.result has the parsed body).
console.log("Response", response.result);
buildHtml(response.result);
},
function (err) { console.error("Execute error", err); });
}
var htmlAccumulator = '';
function buildHtml(data) {
let maxRows = 0;
// find the max rows lenght
for (const rowData in data.sheets[0].data[0].rowData) {
length = data.sheets[0].data[0].rowData[rowData].values.length;
// console.dir(data.sheets[0].data[0].rowData[rowData]);
if (length > maxRows) {
maxRows = length;
}
}
htmlAccumulator += "<div class='container'>";
for (const rowData in data.sheets[0].data[0].rowData) {
// merge same items and increase row width
let newCell = [];
let possition = 0;
let rows = 1;
for (const cell in data.sheets[0].data[0].rowData[rowData].values) {
if (typeof newCell[possition - rows] === 'undefined' || newCell[possition - rows].formattedValue != data.sheets[0].data[0].rowData[rowData].values[cell].formattedValue) {
newCell[possition] = {};
// remove empty value and apply colors
if (typeof data.sheets[0].data[0].rowData[rowData].values[cell].formattedValue === 'undefined') {
newCell[possition].formattedValue = '';
newCell[possition].bColor = '';
} else {
newCell[possition].formattedValue = data.sheets[0].data[0].rowData[rowData].values[cell].formattedValue;
if(typeof data.sheets[0].data[0].rowData[rowData].values[cell].userEnteredFormat !== 'undefined' &&
typeof data.sheets[0].data[0].rowData[rowData].values[cell].userEnteredFormat.backgroundColor !== 'undefined'
) {
let red = data.sheets[0].data[0].rowData[rowData].values[cell].userEnteredFormat.backgroundColor.red * 255;
let green = data.sheets[0].data[0].rowData[rowData].values[cell].userEnteredFormat.backgroundColor.green * 255;
let blue = data.sheets[0].data[0].rowData[rowData].values[cell].userEnteredFormat.backgroundColor.blue * 255;
newCell[possition].bColor = `;background-color: rgb(${red}, ${green}, ${blue});`;
} else {
newCell[possition].bColor = ';background-color: rgba(80, 80, 80, 0.1);';
}
}
newCell[possition].rowSpawn = 1;
++possition;
rows = 1;
} else {
newCell[possition - rows].rowSpawn = rows + 1;
++rows;
++possition;
}
}
// lines
htmlAccumulator += `<div class='row' style='grid-template-columns: repeat(${maxRows}, 1fr);'>`;
let gridColumnCounter = 1;
for (const cell in newCell) {
if (newCell[cell].rowSpawn > 1) {
let columnEnd = gridColumnCounter + newCell[cell].rowSpawn;
htmlAccumulator += `<div class='cell' style='grid-column: ${gridColumnCounter}/${columnEnd}${newCell[cell].bColor}'>`;
gridColumnCounter = gridColumnCounter + newCell[cell].rowSpawn;
} else {
htmlAccumulator += `<div class='cell' style='grid-column: ${gridColumnCounter}${newCell[cell].bColor}'>`;
++gridColumnCounter;
}
htmlAccumulator += newCell[cell].formattedValue;
htmlAccumulator += "</div>";
}
htmlAccumulator += "</div>";
// lines
// htmlAccumulator += "<div class='row'>";
// for (const cell in data.sheets[0].data[0].rowData[rowData].values) {
// htmlAccumulator += "<div class='cell'>";
// htmlAccumulator += data.sheets[0].data[0].rowData[rowData].values[cell].formattedValue;
// htmlAccumulator += "</div>";
// // console.log(htmlAccumulator);
// // console.log(data.sheets[0].data[0].rowData[rowData].values[cell].formattedValue);
// }
// htmlAccumulator += "</div>";
}
htmlAccumulator += "</div>";
document.getElementById('results').innerHTML = htmlAccumulator;
// console.log(htmlAccumulator);
}
</script>
</head>
<body>
<div id="results">
<!-- <div class="row">
<div class="cell"></div>
<div class="cell">2-Aug-2021</div>
<div class="cell">9-Aug-2021</div>
<div class="cell">16-Aug-2021</div>
<div class="cell">23-Aug-2021</div>
</div>
<div class="row">
<div class="cell">Person1</div>
<div class="cell">Project Name one</div>
<div class="cell">Project Name one</div>
<div class="cell">Project name two</div>
<div class="cell">Project name two</div>
</div> -->
</div>
<button onclick="execute()">execute</button>
</body>
</html>