Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TSK-1064: fix export csv in hr #3032

Merged
merged 2 commits into from
Apr 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion models/hr/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
5 changes: 4 additions & 1 deletion plugins/hr-assets/lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
5 changes: 4 additions & 1 deletion plugins/hr-assets/lang/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@
"PublicHoliday": "Праздничный день",
"MarkAsPublicHoliday": "Отметить как праздничный день",
"EditPublicHoliday": "Редактировать праздничный день",
"Managers": "Менеджера"
"Managers": "Менеджера",
"Export": "Экспортировать",
"Separator": "Разделитель",
"ChooseSeparator": "Выберите разделитель"
}
}
38 changes: 38 additions & 0 deletions plugins/hr-resources/src/components/schedule/ExportPopup.svelte
Original file line number Diff line number Diff line change
@@ -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>
62 changes: 41 additions & 21 deletions plugins/hr-resources/src/components/schedule/MonthTableView.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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()
Expand Down Expand Up @@ -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>

Expand All @@ -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
Expand Down
5 changes: 4 additions & 1 deletion plugins/hr-resources/src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
})