mirror of
https://github.com/hcengineering/platform.git
synced 2024-12-23 03:22:19 +03:00
TSK-1064: fix export csv in hr (#3032)
Signed-off-by: Vyacheslav Tumanov <me@slavatumanov.me>
This commit is contained in:
parent
ab479a93a0
commit
6356899a2a
@ -93,7 +93,7 @@ export class TDepartment extends TSpace implements Department {
|
||||
export class TDepartmentMember extends TEmployeeAccount implements DepartmentMember {}
|
||||
|
||||
@Mixin(hr.mixin.Staff, contact.class.Employee)
|
||||
@UX(hr.string.Staff, hr.icon.HR)
|
||||
@UX(hr.string.Staff, hr.icon.HR, 'STFF', 'name')
|
||||
export class TStaff extends TEmployee implements Staff {
|
||||
@Prop(TypeRef(hr.class.Department), hr.string.Department)
|
||||
department!: Ref<Department>
|
||||
|
@ -47,6 +47,9 @@
|
||||
"Description": "Description",
|
||||
"MarkAsPublicHoliday": "Mark as public holiday",
|
||||
"EditPublicHoliday": "Edit public holiday",
|
||||
"Managers": "Managers"
|
||||
"Managers": "Managers",
|
||||
"Export": "Export",
|
||||
"Separator": "Separator",
|
||||
"ChooseSeparator": "Choose separator"
|
||||
}
|
||||
}
|
||||
|
@ -47,6 +47,9 @@
|
||||
"PublicHoliday": "Праздничный день",
|
||||
"MarkAsPublicHoliday": "Отметить как праздничный день",
|
||||
"EditPublicHoliday": "Редактировать праздничный день",
|
||||
"Managers": "Менеджера"
|
||||
"Managers": "Менеджера",
|
||||
"Export": "Экспортировать",
|
||||
"Separator": "Разделитель",
|
||||
"ChooseSeparator": "Выберите разделитель"
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,38 @@
|
||||
<!--
|
||||
// Copyright © 2023 Hardcore Engineering Inc.
|
||||
//
|
||||
// Licensed under the Eclipse Public License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License. You may
|
||||
// obtain a copy of the License at https://www.eclipse.org/legal/epl-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
//
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
-->
|
||||
<script lang="ts">
|
||||
import { Card } from '@hcengineering/presentation'
|
||||
import { createEventDispatcher } from 'svelte'
|
||||
import { DropdownLabelsIntl, Label } from '@hcengineering/ui'
|
||||
import hr from '../../plugin'
|
||||
|
||||
const dispatch = createEventDispatcher()
|
||||
export let items = []
|
||||
|
||||
let selectedSeparator = items[0].id
|
||||
</script>
|
||||
|
||||
<Card
|
||||
label={hr.string.Export}
|
||||
okLabel={hr.string.Export}
|
||||
okAction={() => dispatch('close', selectedSeparator)}
|
||||
canSave
|
||||
on:close
|
||||
>
|
||||
<div class="flex-row-center">
|
||||
<Label label={hr.string.ChooseSeparator} />
|
||||
<DropdownLabelsIntl {items} label={hr.string.Separator} bind:selected={selectedSeparator} />
|
||||
</div>
|
||||
</Card>
|
@ -18,7 +18,7 @@
|
||||
import type { Request, RequestType, Staff } from '@hcengineering/hr'
|
||||
import { getEmbeddedLabel } from '@hcengineering/platform'
|
||||
import { createQuery, getClient } from '@hcengineering/presentation'
|
||||
import { Button, Label, Loading, Scroller, tableSP, tableToCSV } from '@hcengineering/ui'
|
||||
import { Button, Label, Loading, Scroller, showPopup, tableSP, tableToCSV } from '@hcengineering/ui'
|
||||
import view, { BuildModelKey, Viewlet, ViewletPreference } from '@hcengineering/view'
|
||||
import {
|
||||
getViewOptions,
|
||||
@ -42,6 +42,7 @@
|
||||
import StatPresenter from './StatPresenter.svelte'
|
||||
import ReportPresenter from './ReportPresenter.svelte'
|
||||
import HolidayPresenter from './HolidayPresenter.svelte'
|
||||
import ExportPopup from './ExportPopup.svelte'
|
||||
import { Department } from '@hcengineering/hr'
|
||||
|
||||
export let currentDate: Date = new Date()
|
||||
@ -355,7 +356,44 @@
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
function exportTable (evt: Event) {
|
||||
const items = [
|
||||
{
|
||||
id: '0',
|
||||
label: getEmbeddedLabel(', (csv)'),
|
||||
separator: ','
|
||||
},
|
||||
{
|
||||
id: '1',
|
||||
label: getEmbeddedLabel('; (MS Excel)'),
|
||||
separator: ';'
|
||||
}
|
||||
]
|
||||
showPopup(
|
||||
ExportPopup,
|
||||
{
|
||||
items
|
||||
},
|
||||
evt.target as HTMLElement,
|
||||
(res) => {
|
||||
if (res !== undefined) {
|
||||
const filename = 'exportStaff' + new Date().toLocaleDateString() + '.csv'
|
||||
const link = document.createElement('a')
|
||||
link.style.display = 'none'
|
||||
link.setAttribute('target', '_blank')
|
||||
link.setAttribute(
|
||||
'href',
|
||||
'data:text/csv;charset=utf-8,%EF%BB%BF' +
|
||||
encodeURIComponent(tableToCSV('exportableData', items[res].separator))
|
||||
)
|
||||
link.setAttribute('download', filename)
|
||||
document.body.appendChild(link)
|
||||
link.click()
|
||||
document.body.removeChild(link)
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
$: viewOptions = getViewOptions(descr, $viewOptionStore)
|
||||
</script>
|
||||
|
||||
@ -370,25 +408,7 @@
|
||||
<div class="ml-1">
|
||||
<ViewletSettingButton bind:viewOptions viewlet={descr} />
|
||||
</div>
|
||||
<Button
|
||||
label={getEmbeddedLabel('Export')}
|
||||
size={'small'}
|
||||
on:click={() => {
|
||||
// Download it
|
||||
const filename = 'exportStaff' + new Date().toLocaleDateString() + '.csv'
|
||||
const link = document.createElement('a')
|
||||
link.style.display = 'none'
|
||||
link.setAttribute('target', '_blank')
|
||||
link.setAttribute(
|
||||
'href',
|
||||
'data:text/csv;charset=utf-8,%EF%BB%BF' + encodeURIComponent(tableToCSV('exportableData'))
|
||||
)
|
||||
link.setAttribute('download', filename)
|
||||
document.body.appendChild(link)
|
||||
link.click()
|
||||
document.body.removeChild(link)
|
||||
}}
|
||||
/>
|
||||
<Button label={getEmbeddedLabel('Export')} size={'small'} on:click={(evt) => exportTable(evt)} />
|
||||
</div>
|
||||
{#await createConfig(descr, preference, month) then config}
|
||||
<Table
|
||||
|
@ -51,6 +51,9 @@ export default mergeIds(hrId, hr, {
|
||||
Description: '' as IntlString,
|
||||
MarkAsPublicHoliday: '' as IntlString,
|
||||
EditPublicHoliday: '' as IntlString,
|
||||
Managers: '' as IntlString
|
||||
Managers: '' as IntlString,
|
||||
Export: '' as IntlString,
|
||||
Separator: '' as IntlString,
|
||||
ChooseSeparator: '' as IntlString
|
||||
}
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user