Skip to content

Commit

Permalink
feat/checkbox-check-uncheck-all-nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
Ivanov N committed Nov 10, 2024
1 parent f986b0d commit a53f760
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 20 deletions.
28 changes: 19 additions & 9 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="isAllChecked" />

<tbody>
<AdmNodesTableItem v-for="node in admNodes" :key="node.url" blockchain="adm" :node="node" />
Expand All @@ -9,7 +9,7 @@
</template>

<script lang="ts">
import { computed, defineComponent } from 'vue'
import { ref, computed, watch, defineComponent } from 'vue'
import { useStore } from 'vuex'
import NodesTableContainer from '@/components/nodes/components/NodesTableContainer.vue'
import NodesTableHead from '@/components/nodes/components/NodesTableHead.vue'
Expand All @@ -29,23 +29,33 @@ export default defineComponent({
},
setup() {
const store = useStore()
const admNodes = computed(() => {
const arr = store.getters['nodes/adm']
return [...arr].sort(sortNodesFn)
})
const isAllChecked = ref(false)
const isAllNodesEnabled = !admNodes.value.some(node => node.active === false)
if (isAllNodesEnabled) isAllChecked.value = true
watch(isAllChecked, (value) => {
admNodes.value.forEach((admNode) => {
if (admNode && admNode.active !== value) {
store.dispatch('nodes/toggle', {...admNode, active: value})
}
})
})
return {
admNodes,
classes
classes,
isAllChecked
}
}
})
</script>

<style lang="scss">
@import 'vuetify/settings';
.adm-nodes-table {
}
</style>
<style lang="scss"></style>
20 changes: 17 additions & 3 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="isAllChecked" hide-socket :label="t('nodes.coin')" />

<tbody>
<CoinNodesTableItem v-for="node in nodes" :key="node.url" :label="node.label" :node="node" />
Expand All @@ -9,7 +9,7 @@
</template>

<script lang="ts">
import { computed, defineComponent } from 'vue'
import { ref, computed, watch, defineComponent } from 'vue'
import { useI18n } from 'vue-i18n'
import { useStore } from 'vuex'
import NodesTableContainer from '@/components/nodes/components/NodesTableContainer.vue'
Expand Down Expand Up @@ -39,10 +39,24 @@ export default defineComponent({
return [...arr].sort(sortCoinNodesFn)
})
const isAllChecked = ref(false)
const isAllNodesEnabled = !nodes.value.some(node => node.active === false)
if (isAllNodesEnabled) isAllChecked.value = true
watch(isAllChecked, (value) => {
nodes.value.forEach((node) => {
if (node && node.active !== value) {
store.dispatch('nodes/toggle', {...node, active: value})
}
})
})
return {
t,
nodes,
classes
classes,
isAllChecked
}
}
})
Expand Down
30 changes: 25 additions & 5 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" />
</th>
<th :class="classes.label" class="pl-0 pr-2" v-if="label">
{{ label }}
</th>
Expand All @@ -19,10 +21,18 @@
</template>

<script>
import { computed } from 'vue'
import NodeStatusCheckbox from './NodeStatusCheckbox.vue'
import { useI18n } from 'vue-i18n'
export default {
components: {
NodeStatusCheckbox
},
props: {
modelValue: {
type: Boolean,
},
hideCheckbox: {
type: Boolean
},
Expand All @@ -39,20 +49,30 @@ export default {
type: String
}
},
setup() {
setup(props, { emit }) {
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
21 changes: 18 additions & 3 deletions src/components/nodes/services/ServiceNodesTable.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<template>
<NodesTableContainer>
<NodesTableHead hide-socket :label="t('nodes.service')" />
<NodesTableHead v-model="isAllChecked" hide-socket :label="t('nodes.service')" />

<tbody>
<ServiceNodesTableItem
Expand All @@ -14,7 +14,7 @@
</template>

<script lang="ts">
import { computed, defineComponent } from 'vue'
import { ref, computed, watch, defineComponent } from 'vue'
import { useI18n } from 'vue-i18n'
import { useStore } from 'vuex'
import NodesTableContainer from '@/components/nodes/components/NodesTableContainer.vue'
Expand Down Expand Up @@ -44,10 +44,25 @@ export default defineComponent({
return [...arr].sort(sortCoinNodesFn)
})
const isAllChecked = ref(false)
const isAllNodesEnabled = !nodes.value.some(node => node.active === false)
if (isAllNodesEnabled) isAllChecked.value = true
watch(isAllChecked, (value) => {
nodes.value.forEach((node) => {
if (node && node.active !== value) {
const { label, url } = node
store.dispatch('services/toggle', {type: label, url, active: value})
}
})
})
return {
t,
nodes,
classes
classes,
isAllChecked
}
}
})
Expand Down

1 comment on commit a53f760

@NikIvv
Copy link
Collaborator

@NikIvv NikIvv commented on a53f760 Nov 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.