Skip to content

Commit 6d1d879

Browse files
committed
2 parents c7454b6 + 9fa7a93 commit 6d1d879

7 files changed

Lines changed: 94 additions & 7 deletions

File tree

src/i18n/en-US/messages.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -956,6 +956,7 @@
956956
"enableScreenshots": "Enable Screenshots",
957957
"exportPdf": "Export PDF",
958958
"showExcelExport": "Enable show excel export (when available)",
959+
"xlsxSheetName": "XLSX sheet name",
959960
"title": "Export"
960961
},
961962
"fontawesome": "Fontawesome",

src/i18n/it-IT/messages.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -764,6 +764,7 @@
764764
"enableScreenshots": "Enable Screenshots",
765765
"exportPdf": "Export PDF",
766766
"showExcelExport": "Enable show excel export (when available)",
767+
"xlsxSheetName": "Nome foglio XLSX",
767768
"title": "Export"
768769
},
769770
"fontawesome": "Fontawesome",

src/modules/documentExecution/dashboard/Dashboard.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ export interface IWidgetExports {
158158
}
159159
showExcelExport: boolean
160160
showScreenshot?: boolean
161+
xlsxSheetName?: string
161162
}
162163

163164
export interface ITableWidgetHeaders {

src/modules/documentExecution/dashboard/helpers/DashboardExportHelper.ts

Lines changed: 75 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ type IDashboardExportState = Pick<IDashboard, 'configuration'> & {
66
currentView?: unknown
77
selections?: ISelection[]
88
drivers?: IDashboardDriver[]
9+
locale?: string
910
}
1011

1112
type IWidgetExportBody = IWidget & {
@@ -20,6 +21,76 @@ type IWidgetExportBody = IWidget & {
2021
xlsxStyleEnabled?: boolean
2122
}
2223

24+
const defaultDashboardExportLocale = 'en-US'
25+
26+
const dashboardExportLocaleAliases: Record<string, string> = {
27+
ar: 'ar-EG',
28+
'ar-eg': 'ar-EG',
29+
ara: 'ar-EG',
30+
bg: 'bg-BG',
31+
'bg-bg': 'bg-BG',
32+
bul: 'bg-BG',
33+
da: 'da-DK',
34+
'da-dk': 'da-DK',
35+
dan: 'da-DK',
36+
de: 'de-DE',
37+
'de-de': 'de-DE',
38+
deu: 'de-DE',
39+
en: 'en-US',
40+
'en-gb': 'en-GB',
41+
'en-us': 'en-US',
42+
eng: 'en-US',
43+
es: 'es-ES',
44+
'es-es': 'es-ES',
45+
spa: 'es-ES',
46+
fr: 'fr-FR',
47+
'fr-fr': 'fr-FR',
48+
fra: 'fr-FR',
49+
he: 'he-IL',
50+
'he-il': 'he-IL',
51+
heb: 'he-IL',
52+
hu: 'hu-HU',
53+
'hu-hu': 'hu-HU',
54+
hun: 'hu-HU',
55+
it: 'it-IT',
56+
'it-it': 'it-IT',
57+
ita: 'it-IT',
58+
ja: 'ja-JP',
59+
'ja-jp': 'ja-JP',
60+
jpn: 'ja-JP',
61+
ko: 'ko-KR',
62+
'ko-kr': 'ko-KR',
63+
kor: 'ko-KR',
64+
pt: 'pt-BR',
65+
'pt-br': 'pt-BR',
66+
por: 'pt-BR',
67+
ru: 'ru-RU',
68+
'ru-ru': 'ru-RU',
69+
rus: 'ru-RU',
70+
sk: 'sk-SK',
71+
'sk-sk': 'sk-SK',
72+
slk: 'sk-SK',
73+
slo: 'sk-SK',
74+
tr: 'tr-TR',
75+
'tr-tr': 'tr-TR',
76+
tur: 'tr-TR',
77+
zh: 'zh-Hans-CN',
78+
'zh-cn': 'zh-Hans-CN',
79+
'zh-cn-#hans': 'zh-Hans-CN',
80+
'zh-hans-cn': 'zh-Hans-CN',
81+
zho: 'zh-Hans-CN'
82+
}
83+
84+
const normalizeDashboardExportLocale = (locale?: string) => {
85+
if (!locale) return defaultDashboardExportLocale
86+
87+
const normalizedLocale = locale.replaceAll('_', '-').trim().toLowerCase()
88+
if (dashboardExportLocaleAliases[normalizedLocale]) return dashboardExportLocaleAliases[normalizedLocale]
89+
90+
const languageCode = normalizedLocale.split('-')[0]
91+
return dashboardExportLocaleAliases[languageCode] ?? defaultDashboardExportLocale
92+
}
93+
2394
export const getDashboardXlsxStyleEnabled = (dashboard: Pick<IDashboard, 'configuration'> | null | undefined) => {
2495
return dashboard?.configuration?.menuWidgets?.xlsxStyleEnabled ?? false
2596
}
@@ -32,10 +103,11 @@ export const getDashboardExportVariables = (dashboard: Pick<IDashboard, 'configu
32103
return dashboard?.configuration?.variables ?? []
33104
}
34105

35-
export const createDashboardSpreadsheetExportBody = (dashboard: IDashboardExportState) => {
36-
const body = deepcopy(dashboard) as IDashboardExportState & { xlsxStyleEnabled?: boolean }
106+
export const createDashboardSpreadsheetExportBody = (dashboard: IDashboardExportState, locale?: string) => {
107+
const body = deepcopy(dashboard) as IDashboardExportState & { xlsxStyleEnabled?: boolean; locale?: string }
37108
delete body.currentView
38109
body.xlsxStyleEnabled = getDashboardXlsxStyleEnabled(dashboard)
110+
body.locale = normalizeDashboardExportLocale(locale ?? body.locale)
39111
return body
40112
}
41113

@@ -50,7 +122,7 @@ export const createWidgetExportBody = (type: string, widget: IWidget, dashboard:
50122
drivers: dashboard.drivers ?? [],
51123
variables: dashboard.configuration.variables ?? [],
52124
creationUser,
53-
locale
125+
locale: normalizeDashboardExportLocale(locale)
54126
} as IWidgetExportBody
55127

56128
if (dataset?.drivers) body.datasetDrivers = dataset.drivers

src/modules/documentExecution/dashboard/helpers/__tests__/DashboardExportHelper.spec.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,11 @@ describe('getDashboardExportVariables', () => {
6565
})
6666

6767
describe('createDashboardSpreadsheetExportBody', () => {
68-
it('removes currentView and adds the top-level xlsxStyleEnabled flag', () => {
69-
const body = createDashboardSpreadsheetExportBody(createDashboard())
68+
it('removes currentView, adds the top-level xlsxStyleEnabled flag and normalizes locale', () => {
69+
const body = createDashboardSpreadsheetExportBody(createDashboard(), 'eng')
7070

7171
expect(body.currentView).toBeUndefined()
72+
expect(body.locale).toBe('en-US')
7273
expect(body.xlsxStyleEnabled).toBe(true)
7374
expect(body.configuration.menuWidgets.exportFileName).toBe('dashboard $P{year} $V{region}')
7475
expect(body.configuration.menuWidgets.xlsxStyleEnabled).toBe(true)
@@ -77,7 +78,7 @@ describe('createDashboardSpreadsheetExportBody', () => {
7778

7879
describe('createWidgetExportBody', () => {
7980
it('adds xlsxStyleEnabled to spreadsheet exports', () => {
80-
const body = createWidgetExportBody('spreadsheet', createWidget(), createDashboard(), 'bi-user', 'en-US')
81+
const body = createWidgetExportBody('spreadsheet', createWidget(), createDashboard(), 'bi-user', 'eng')
8182

8283
expect(body.parameters).toEqual([{ name: 'country', value: 'IT' }])
8384
expect(body.datasetDrivers).toHaveLength(1)

src/modules/documentExecution/dashboard/widget/WidgetEditor/WidgetEditorSettingsTab/common/configuration/WidgetExport.vue

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@
2424
<div class="col-12">
2525
<q-toggle v-model="exportModel.showExcelExport" :label="$t('dashboard.widgetEditor.export.showExcelExport')" @update:model-value="onEnableExportChanged" dense />
2626
</div>
27+
<div v-if="exportModel.showExcelExport" class="col-12">
28+
<q-input v-model="exportModel.xlsxSheetName" :label="$t('dashboard.widgetEditor.export.xlsxSheetName')" :placeholder="getDefaultXlsxSheetName()" outlined dense @blur="onXlsxSheetNameChanged" />
29+
</div>
2730
</div>
2831
</div>
2932
</template>
@@ -61,6 +64,9 @@ export default defineComponent({
6164
this.setSelectedExport()
6265
}
6366
},
67+
getDefaultXlsxSheetName() {
68+
return this.widgetModel?.settings?.style?.title?.text || `${this.widgetType} ${this.widgetModel?.id ?? ''}`.trim()
69+
},
6470
setSelectedExport() {
6571
if (!this.exportModel || this.widgetType !== 'table' || !this.exportModel.pdf) return
6672
if (this.exportModel.pdf.a4landscape) this.selectedExport = 'a4landscape'
@@ -70,6 +76,11 @@ export default defineComponent({
7076
exportConfigurationChanged() {
7177
emitter.emit('exportModelChanged', this.exportModel)
7278
},
79+
onXlsxSheetNameChanged() {
80+
if (!this.exportModel) return
81+
this.exportModel.xlsxSheetName = this.exportModel.xlsxSheetName?.trim() ?? ''
82+
this.exportConfigurationChanged()
83+
},
7384
onEnableExportChanged() {
7485
this.exportConfigurationChanged()
7586
},

src/modules/documentExecution/main/DocumentExecution.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -729,7 +729,7 @@ export default defineComponent({
729729
if (format.includes('xls')) {
730730
format = 'spreadsheet'
731731
if (currentDashboard) {
732-
body = createDashboardSpreadsheetExportBody(currentDashboard)
732+
body = createDashboardSpreadsheetExportBody(currentDashboard, this.getCurrentLocale())
733733
enrichDashboardBodyWithPivotSortState(body)
734734
}
735735
}

0 commit comments

Comments
 (0)