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

feat/checkbox-check-uncheck-all-nodes #680

Merged
merged 6 commits into from
Dec 2, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
31 changes: 23 additions & 8 deletions src/components/nodes/adm/AdmNodesTable.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<template>
<NodesTableContainer>
<NodesTableHead />
<NodesTableHead v-model="isAllNodesChecked" :indeterminate="isPartiallyChecked" />

<tbody>
<AdmNodesTableItem v-for="node in admNodes" :key="node.url" blockchain="adm" :node="node" />
Expand Down Expand Up @@ -29,23 +29,38 @@ export default defineComponent({
},
setup() {
const store = useStore()

const admNodes = computed(() => {
const arr = store.getters['nodes/adm']

return [...arr].sort(sortNodesFn)
})

const isAllNodesChecked = computed({
get() {
return !admNodes.value.some(node => node.active === false)
},
set(value) {
admNodes.value.forEach((admNode) => {
if (admNode && admNode.active !== value) {
store.dispatch('nodes/toggle', {...admNode, active: value})
}
})
}
})

const isPartiallyChecked = computed(() => {
return admNodes.value.some(node => node.active) && admNodes.value.some(node => !node.active)
})

return {
admNodes,
classes
classes,
isAllNodesChecked,
isPartiallyChecked
}
}
})
</script>

<style lang="scss">
@import 'vuetify/settings';

.adm-nodes-table {
}
</style>
<style lang="scss"></style>
23 changes: 21 additions & 2 deletions src/components/nodes/coins/CoinNodesTable.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<template>
<NodesTableContainer>
<NodesTableHead hide-socket :label="t('nodes.coin')" />
<NodesTableHead v-model="isAllNodesChecked" :indeterminate="isPartiallyChecked" hide-socket :label="t('nodes.coin')" />

<tbody>
<CoinNodesTableItem v-for="node in nodes" :key="node.url" :label="node.label" :node="node" />
Expand Down Expand Up @@ -39,10 +39,29 @@ export default defineComponent({
return [...arr].sort(sortCoinNodesFn)
})

const isAllNodesChecked = computed({
get() {
return !nodes.value.some(node => node.active === false)
},
set(value) {
nodes.value.forEach((node) => {
if (node && node.active !== value) {
store.dispatch('nodes/toggle', {...node, active: value})
}
})
}
})

const isPartiallyChecked = computed(() => {
return nodes.value.some(node => node.active) && nodes.value.some(node => !node.active)
})

return {
t,
nodes,
classes
classes,
isAllNodesChecked,
isPartiallyChecked
}
}
})
Expand Down
49 changes: 36 additions & 13 deletions src/components/nodes/components/NodesTableHead.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
<template>
<thead :class="classes.root">
<tr>
<th :class="classes.checkbox" v-if="!hideCheckbox" />
<th :class="classes.checkbox" v-if="!hideCheckbox">
<NodeStatusCheckbox v-model="isAllEnabled" :indeterminate="indeterminate"/>
</th>
<th :class="classes.label" class="pl-0 pr-2" v-if="label">
{{ label }}
</th>
Expand All @@ -19,10 +21,26 @@
</template>

<script>
import { computed } from 'vue'
import NodeStatusCheckbox from './NodeStatusCheckbox.vue'
import { useI18n } from 'vue-i18n'

const className = 'nodes-table-head'
const classes = {
root: className,
th: `${className}__th`,
checkbox: `${className}__checkbox`,
label: `${className}__label`
}

export default {
components: {
NodeStatusCheckbox
},
props: {
modelValue: {
type: Boolean,
},
hideCheckbox: {
type: Boolean
},
Expand All @@ -37,22 +55,27 @@ export default {
},
label: {
type: String
}
},
indeterminate: {
type: Boolean
},
},
setup() {
setup(props, { emit }) {
NikIvv marked this conversation as resolved.
Show resolved Hide resolved
const { t } = useI18n()

const className = 'nodes-table-head'
const classes = {
root: className,
th: `${className}__th`,
checkbox: `${className}__checkbox`,
label: `${className}__label`
}


const isAllEnabled = computed({
get() {
return props.modelValue
},
set(value) {
emit('update:modelValue', value)
}
})

return {
classes,
t
t,
isAllEnabled
}
}
}
Expand Down
31 changes: 28 additions & 3 deletions src/components/nodes/services/ServiceNodesTable.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
<template>
<NodesTableContainer>
<NodesTableHead hide-socket :label="t('nodes.service')" />

<NodesTableHead
v-model="isAllNodesChecked"
:indeterminate="isPartiallyChecked"
hide-socket
:label="t('nodes.service')"
/>

<tbody>
<ServiceNodesTableItem
v-for="node in nodes"
Expand Down Expand Up @@ -44,10 +49,30 @@ export default defineComponent({
return [...arr].sort(sortCoinNodesFn)
})

const isAllNodesChecked = computed({
get() {
return !nodes.value.some(node => node.active === false)
NikIvv marked this conversation as resolved.
Show resolved Hide resolved
},
set(value) {
nodes.value.forEach((node) => {
if (node && node.active !== value) {
NikIvv marked this conversation as resolved.
Show resolved Hide resolved
const { label, url } = node
store.dispatch('services/toggle', {type: label, url, active: value})
NikIvv marked this conversation as resolved.
Show resolved Hide resolved
}
})
}
})

const isPartiallyChecked = computed(() => {
return nodes.value.some(node => node.active) && nodes.value.some(node => !node.active)
})

return {
t,
nodes,
classes
classes,
isAllNodesChecked,
isPartiallyChecked
}
}
})
Expand Down