|
| 1 | +// Licensed to the Apache Software Foundation (ASF) under one |
| 2 | +// or more contributor license agreements. See the NOTICE file |
| 3 | +// distributed with this work for additional information |
| 4 | +// regarding copyright ownership. The ASF licenses this file |
| 5 | +// to you under the Apache License, Version 2.0 (the |
| 6 | +// "License"); you may not use this file except in compliance |
| 7 | +// with the License. You may obtain a copy of the License at |
| 8 | +// |
| 9 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +// |
| 11 | +// Unless required by applicable law or agreed to in writing, |
| 12 | +// software distributed under the License is distributed on an |
| 13 | +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 14 | +// KIND, either express or implied. See the License for the |
| 15 | +// specific language governing permissions and limitations |
| 16 | +// under the License. |
| 17 | + |
| 18 | +function download_query() { |
| 19 | + let tableThs = Array.from($('table th')).map(v=>{return v.textContent}) |
| 20 | + let tableTds = Array.from($('table td')).map(v=>{return v.textContent}) |
| 21 | + let combine = tableThs.concat(tableTds) |
| 22 | + let csv = '' |
| 23 | + let colWidth = 9 |
| 24 | + let column = [] |
| 25 | + combine.map((v,i)=>{ |
| 26 | + column.push(v.trim()) |
| 27 | + if((i+1)%colWidth === 0){ |
| 28 | + csv += column.join(",")+'\n' |
| 29 | + column = [] |
| 30 | + } |
| 31 | + }) |
| 32 | + let uri = 'data:text/csv;charset=utf-8,\ufeff' + encodeURIComponent(csv); |
| 33 | + let link = document.createElement("a"); |
| 34 | + let date = new Date().toISOString().replace(/\D/g, '').slice(0, -3) |
| 35 | + link.href = uri; |
| 36 | + link.download = "query_" + date + ".csv"; |
| 37 | + document.body.appendChild(link); |
| 38 | + link.click(); |
| 39 | + document.body.removeChild(link); |
| 40 | +} |
0 commit comments