Skip to content

Commit 9001b34

Browse files
committed
Add functionality to create and use global block
1 parent 1204d95 commit 9001b34

10 files changed

Lines changed: 285 additions & 46 deletions

File tree

client/web/compose/src/components/Admin/Page/Builder/Selector.vue

Lines changed: 74 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,30 +33,74 @@
3333
</b-col>
3434

3535
<hr
36-
v-if="existingBlocks.length"
36+
v-if="existingLayoutBlocks.length || selectableNamespaceGlobalBlocks"
3737
class="w-100"
3838
>
3939

4040
<b-col
41-
v-if="existingBlocks.length"
41+
v-if="selectableNamespaceGlobalBlocks.length"
4242
cols="12"
4343
>
4444
<b-input-group class="d-flex w-100">
4545
<c-input-select
46-
v-model="selectedExistingBlock"
46+
v-model="selectedGlobalBlock"
47+
:get-option-label="getBlockLabel"
48+
:get-option-key="getOptionKey"
49+
:options="selectableNamespaceGlobalBlocks"
50+
:reduce="b => b.blockID"
51+
placeholder="Select global block from other pages"
52+
/>
53+
54+
<b-input-group-append>
55+
<b-button
56+
v-b-tooltip.noninteractive.hover="{ title: $t('selector.tooltip.clone.noRef'), container: '#body' }"
57+
variant="extra-light"
58+
:disabled="!selectedGlobalBlock"
59+
class="d-flex align-items-center"
60+
@click="$emit('select', fetchBlockData(selectedGlobalBlock).clone())"
61+
>
62+
<font-awesome-icon
63+
:icon="['far', 'clone']"
64+
/>
65+
</b-button>
66+
67+
<b-button
68+
v-b-tooltip.noninteractive.hover="{ title: $t('selector.tooltip.clone.ref'), container: '#body' }"
69+
variant="extra-light"
70+
:disabled="!selectedGlobalBlock"
71+
class="d-flex align-items-center"
72+
@click="$emit('select', fetchBlockData(selectedGlobalBlock))"
73+
>
74+
<font-awesome-icon
75+
:icon="['far', 'copy']"
76+
/>
77+
</b-button>
78+
</b-input-group-append>
79+
</b-input-group>
80+
</b-col>
81+
82+
<b-col
83+
v-if="existingLayoutBlocks.length"
84+
cols="12"
85+
class="mt-3"
86+
>
87+
<b-input-group class="d-flex w-100">
88+
<c-input-select
89+
v-model="selectedLayoutExistingBlock"
4790
:get-option-label="getBlockLabel"
4891
:get-option-key="b => b.blockID"
49-
:options="existingBlocks"
92+
:options="existingLayoutBlocks"
93+
:reduce="b => b.blockID"
5094
:placeholder="$t('selector.selectableBlocks.placeholder')"
5195
/>
5296

5397
<b-input-group-append>
5498
<b-button
5599
v-b-tooltip.noninteractive.hover="{ title: $t('selector.tooltip.clone.noRef'), container: '#body' }"
56100
variant="extra-light"
57-
:disabled="!selectedExistingBlock"
101+
:disabled="!selectedLayoutExistingBlock"
58102
class="d-flex align-items-center"
59-
@click="$emit('select', selectedExistingBlock.clone())"
103+
@click="$emit('select', fetchBlockData(selectedLayoutExistingBlock).clone())"
60104
>
61105
<font-awesome-icon
62106
:icon="['far', 'clone']"
@@ -66,9 +110,9 @@
66110
<b-button
67111
v-b-tooltip.noninteractive.hover="{ title: $t('selector.tooltip.clone.ref'), container: '#body' }"
68112
variant="extra-light"
69-
:disabled="!selectedExistingBlock"
113+
:disabled="!selectedLayoutExistingBlock"
70114
class="d-flex align-items-center"
71-
@click="$emit('select', selectedExistingBlock)"
115+
@click="$emit('select', fetchBlockData(selectedLayoutExistingBlock))"
72116
>
73117
<font-awesome-icon
74118
:icon="['far', 'copy']"
@@ -101,7 +145,12 @@ export default {
101145
default: () => [],
102146
},
103147
104-
existingBlocks: {
148+
existingLayoutBlocks: {
149+
type: Array,
150+
default: () => [],
151+
},
152+
153+
selectableNamespaceGlobalBlocks: {
105154
type: Array,
106155
default: () => [],
107156
},
@@ -111,7 +160,8 @@ export default {
111160
return {
112161
current: undefined,
113162
114-
selectedExistingBlock: undefined,
163+
selectedLayoutExistingBlock: undefined,
164+
selectedGlobalBlock: undefined,
115165
116166
types: [
117167
{
@@ -225,9 +275,22 @@ export default {
225275
226276
setDefaultValues () {
227277
this.current = undefined
228-
this.selectedExistingBlock = undefined
278+
this.selectedLayoutExistingBlock = undefined
279+
this.selectedGlobalBlock = undefined
229280
this.types = []
230281
},
282+
283+
getOptionKey ({ blockID }) {
284+
return blockID
285+
},
286+
287+
fetchBlockData (blockID) {
288+
if (blockID.includes('-')) {
289+
return this.selectableNamespaceGlobalBlocks.find((b) => b.blockID === blockID)
290+
}
291+
292+
return this.existingLayoutBlocks.find((b) => b.blockID === blockID)
293+
},
231294
},
232295
}
233296
</script>

client/web/compose/src/components/PageBlocks/Configurator.vue

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,16 @@
128128
>
129129
{{ $t('general.hidden.label') }}
130130
</b-form-checkbox>
131+
<b-form-checkbox
132+
v-if="block.kind !== 'Tabs'"
133+
v-model="block.meta.namespaceID"
134+
:value="namespace.namespaceID"
135+
:disabled="alreadyGlobalBlock"
136+
switch
137+
class="mb-2"
138+
>
139+
{{ $t('general.globalBlock.label') }}
140+
</b-form-checkbox>
131141
</b-col>
132142

133143
<b-col
@@ -221,6 +231,17 @@ export default {
221231
type: compose.Page,
222232
required: true,
223233
},
234+
235+
namespace: {
236+
type: compose.Namespace,
237+
required: true,
238+
},
239+
},
240+
241+
data () {
242+
return {
243+
alreadyGlobalBlock: false,
244+
}
224245
},
225246
226247
computed: {
@@ -254,6 +275,17 @@ export default {
254275
},
255276
},
256277
278+
watch: {
279+
block: {
280+
immediate: true,
281+
handler (block) {
282+
if (block.meta.namespaceID && !this.alreadyGlobalBlock) {
283+
this.alreadyGlobalBlock = !!block.meta.namespaceID
284+
}
285+
},
286+
},
287+
},
288+
257289
methods: {
258290
updateRefresh (e) {
259291
// If value is less than 5 but greater than 0 make it 5. Otherwise value stays the same.
@@ -266,4 +298,4 @@ export default {
266298
.mh-tab {
267299
max-height: calc(100vh - 16rem);
268300
}
269-
</style>
301+
</style>import { watch } from 'fs'

client/web/compose/src/views/Admin/Modules/List.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
"<template>
1+
<template>
22
<b-container
33
fluid="xl"
44
class="d-flex flex-column py-3"

0 commit comments

Comments
 (0)