mirror of https://github.com/nocodb/nocodb
Raju Udava
2 years ago
committed by
GitHub
11 changed files with 145 additions and 86 deletions
@ -0,0 +1,17 @@ |
|||||||
|
<template> |
||||||
|
<a-dropdown :trigger="['click']"> |
||||||
|
<a-button v-t="['c:actions']" class="nc-actions-menu-btn nc-toolbar-btn"> |
||||||
|
<div class="flex gap-2 items-center"> |
||||||
|
<MdiDownload class="group-hover:text-accent text-gray-500" /> |
||||||
|
<span class="text-capitalize !text-sm font-weight-normal">Download</span> |
||||||
|
<MdiMenuDown class="text-grey" /> |
||||||
|
</div> |
||||||
|
</a-button> |
||||||
|
|
||||||
|
<template #overlay> |
||||||
|
<a-menu class="ml-6 !text-sm !px-0 !py-2 !rounded"> |
||||||
|
<SmartsheetToolbarExportSubActions /> |
||||||
|
</a-menu> |
||||||
|
</template> |
||||||
|
</a-dropdown> |
||||||
|
</template> |
@ -0,0 +1,80 @@ |
|||||||
|
<script setup lang="ts"> |
||||||
|
import { ExportTypes } from 'nocodb-sdk' |
||||||
|
import FileSaver from 'file-saver' |
||||||
|
import * as XLSX from 'xlsx' |
||||||
|
import { message } from 'ant-design-vue' |
||||||
|
|
||||||
|
const isPublicView = inject(IsPublicInj, ref(false)) |
||||||
|
const fields = inject(FieldsInj, ref([])) |
||||||
|
|
||||||
|
const { project } = useProject() |
||||||
|
|
||||||
|
const { $api } = useNuxtApp() |
||||||
|
|
||||||
|
const meta = inject(MetaInj) |
||||||
|
|
||||||
|
const selectedView = inject(ActiveViewInj) |
||||||
|
|
||||||
|
const exportFile = async (exportType: ExportTypes) => { |
||||||
|
let offset = 0 |
||||||
|
let c = 1 |
||||||
|
const responseType = exportType === ExportTypes.EXCEL ? 'base64' : 'blob' |
||||||
|
|
||||||
|
try { |
||||||
|
while (!isNaN(offset) && offset > -1) { |
||||||
|
let res |
||||||
|
if (isPublicView.value) { |
||||||
|
const { exportFile: sharedViewExportFile } = useSharedView() |
||||||
|
res = await sharedViewExportFile(fields.value, offset, exportType, responseType) |
||||||
|
} else { |
||||||
|
res = await $api.dbViewRow.export( |
||||||
|
'noco', |
||||||
|
project?.value.title as string, |
||||||
|
meta?.value.title as string, |
||||||
|
selectedView?.value.title as string, |
||||||
|
exportType, |
||||||
|
{ |
||||||
|
responseType, |
||||||
|
query: { |
||||||
|
offset, |
||||||
|
}, |
||||||
|
} as any, |
||||||
|
) |
||||||
|
} |
||||||
|
const { data, headers } = res |
||||||
|
if (exportType === ExportTypes.EXCEL) { |
||||||
|
const workbook = XLSX.read(data, { type: 'base64' }) |
||||||
|
XLSX.writeFile(workbook, `${meta?.value.title}_exported_${c++}.xlsx`) |
||||||
|
} else if (exportType === ExportTypes.CSV) { |
||||||
|
const blob = new Blob([data], { type: 'text/plain;charset=utf-8' }) |
||||||
|
FileSaver.saveAs(blob, `${meta?.value.title}_exported_${c++}.csv`) |
||||||
|
} |
||||||
|
offset = +headers['nc-export-offset'] |
||||||
|
if (offset > -1) { |
||||||
|
message.info('Downloading more files') |
||||||
|
} else { |
||||||
|
message.success('Successfully exported all table data') |
||||||
|
} |
||||||
|
} |
||||||
|
} catch (e: any) { |
||||||
|
message.error(await extractSdkResponseErrorMsg(e)) |
||||||
|
} |
||||||
|
} |
||||||
|
</script> |
||||||
|
|
||||||
|
<template> |
||||||
|
<a-menu-item> |
||||||
|
<div v-t="['a:actions:download-csv']" class="nc-project-menu-item" @click="exportFile(ExportTypes.CSV)"> |
||||||
|
<MdiDownloadOutline class="text-gray-500" /> |
||||||
|
<!-- Download as CSV --> |
||||||
|
{{ $t('activity.downloadCSV') }} |
||||||
|
</div> |
||||||
|
</a-menu-item> |
||||||
|
<a-menu-item> |
||||||
|
<div v-t="['a:actions:download-excel']" class="nc-project-menu-item" @click="exportFile(ExportTypes.EXCEL)"> |
||||||
|
<MdiDownloadOutline class="text-gray-500" /> |
||||||
|
<!-- Download as XLSX --> |
||||||
|
{{ $t('activity.downloadExcel') }} |
||||||
|
</div> |
||||||
|
</a-menu-item> |
||||||
|
</template> |
@ -0,0 +1,19 @@ |
|||||||
|
<script setup lang="ts"> |
||||||
|
import { ActiveViewInj, viewIcons } from '#imports' |
||||||
|
|
||||||
|
const selectedView = inject(ActiveViewInj) |
||||||
|
</script> |
||||||
|
|
||||||
|
<template> |
||||||
|
<div class="flex gap-2 items-center ml-2 mr-2 pr-4 pb-1 py-0.5 border-r-1 border-gray-100"> |
||||||
|
<component |
||||||
|
:is="viewIcons[selectedView?.type].icon" |
||||||
|
v-if="selectedView?.type" |
||||||
|
class="nc-view-icon group-hover:hidden" |
||||||
|
:style="{ color: viewIcons[selectedView?.type].color }" |
||||||
|
/> |
||||||
|
<span class="!text-sm font-medium max-w-36 overflow-ellipsis overflow-hidden whitespace-nowrap">{{ |
||||||
|
selectedView?.title |
||||||
|
}}</span> |
||||||
|
</div> |
||||||
|
</template> |
Loading…
Reference in new issue