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 1 commit
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
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" />
NikIvv marked this conversation as resolved.
Show resolved Hide resolved

<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
NikIvv marked this conversation as resolved.
Show resolved Hide resolved

watch(isAllChecked, (value) => {
admNodes.value.forEach((admNode) => {
if (admNode && admNode.active !== value) {
store.dispatch('nodes/toggle', {...admNode, active: value})
}
})
})
NikIvv marked this conversation as resolved.
Show resolved Hide resolved

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 }) {
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
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