-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add setMessage method to table store * Create table action component * add selection to row component * refactor table component * add executeAction method in table store * increase version * closeModal using force close * add confirm and cancel emitter to modal * Update row.component.vue * refactor table action * refactor table * Update modal.component.vue * add actionMsg to template props * Update table.component.vue * fetch items after row delete * Update table.component.vue * set message only if defined * update modalMessage on props change * fix method name * clear selection on search when keepSelectionAcrossPage is false
- Loading branch information
Showing
9 changed files
with
268 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,44 @@ | ||
<template> | ||
<slot :row="row" v-bind="$attrs">row</slot> | ||
</template> | ||
|
||
<script> | ||
import {computed, inject, toRefs} from "vue"; | ||
import {useTableStoreFactory} from "./table.store"; | ||
export default { | ||
name: 'fohn-table-row', | ||
props: { | ||
// storeId: String, | ||
hasSelection: { | ||
type: Boolean, | ||
default: false, | ||
}, | ||
row: Object, | ||
}, | ||
emits: {}, | ||
setup: function (props, { attrs, slots, emit }) { | ||
const { row } = props; | ||
const method = {}; | ||
const { hasSelection: isActionable } = props; | ||
const { row } = toRefs(props); | ||
const tableStore = useTableStoreFactory(inject('tableStoreId'))(); | ||
method.getRowClass = (idx) => ({ | ||
'bg-gray-200': idx % 2, | ||
}); | ||
const isEvenRow = (idx) => (idx % 2) === 0; | ||
const isSelected = computed(() => tableStore.isRowSelected(row.value.id)); | ||
return { row }; | ||
const toggleRow = (id) => { | ||
tableStore.toggleRow(id); | ||
} | ||
return { row, isEvenRow, isActionable, isSelected, toggleRow }; | ||
}, | ||
}; | ||
</script> | ||
|
||
<template> | ||
<slot | ||
:row="row" | ||
:isEvenRow="isEvenRow" | ||
:isActionable="isActionable" | ||
:isSelected="isSelected" | ||
:toggleRow="toggleRow" | ||
v-bind="$attrs">row</slot> | ||
</template> | ||
|
||
<style scoped> | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<script> | ||
import {useTableStoreFactory} from "./table.store"; | ||
import {computed, inject, toRefs} from "vue"; | ||
import {toReactive} from "@vueuse/core"; | ||
export default { | ||
name: 'fohn-table-action', | ||
props: { | ||
actionUrl: String, | ||
tableRowsSelected: Number, | ||
isTableFetching: Boolean, | ||
placeHolder: { | ||
type: String, | ||
default: '{#}', | ||
}, | ||
messages: { | ||
type: Object, | ||
default: () => ({none: '', single: '', multiple: ''}) | ||
} | ||
}, | ||
setup(props, { attrs, slots, emit }) { | ||
const {actionUrl, placeHolder} = props; | ||
const {isTableFetching, tableRowsSelected } = toRefs(props); | ||
const {messages} = toReactive(props); | ||
const tableStore = useTableStoreFactory(inject('tableStoreId'))(); | ||
const isEnable = computed(() => tableRowsSelected.value > 0); | ||
const actionMsg = computed(() => { | ||
if (tableRowsSelected.value === 0) { | ||
return messages.none || ''; | ||
} | ||
if (tableRowsSelected.value === 1 && messages.single) { | ||
return messages.single.replace(placeHolder, tableRowsSelected.value); | ||
} | ||
if (tableRowsSelected.value > 1 && messages.multiple) { | ||
return messages.multiple.replace(placeHolder, tableRowsSelected.value); | ||
} | ||
return ''; | ||
}); | ||
const execute = (event) => { | ||
if (!isTableFetching.value) { | ||
tableStore.executeAction(actionUrl, event?.currentTarget); | ||
} | ||
} | ||
return {execute, isEnable, isTableFetching, tableRowsSelected, actionMsg} | ||
} | ||
} | ||
</script> | ||
<template> | ||
<slot | ||
:isTableFetching="isTableFetching" | ||
:tableRowsSelected="tableRowsSelected" | ||
:execute="execute" | ||
:isEnable="isEnable" | ||
:actionMsg="actionMsg" | ||
v-bind="$attrs">table action</slot> | ||
</template> |
Oops, something went wrong.