Skip to content

Commit 7bc30f3

Browse files
committed
Add functionality to create and use global block
1 parent 40316cd commit 7bc30f3

12 files changed

Lines changed: 365 additions & 47 deletions

File tree

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

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

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

4040
<b-col
41-
v-if="existingBlocks.length"
41+
v-if="existingLayoutBlocks.length"
4242
cols="12"
43+
class="mt-3"
4344
>
4445
<b-input-group class="d-flex w-100">
4546
<c-input-select
46-
v-model="selectedExistingBlock"
47+
v-model="selectedLayoutBlock"
4748
:get-option-label="getBlockLabel"
4849
:get-option-key="b => b.blockID"
49-
:options="existingBlocks"
50+
:options="existingLayoutBlocks"
51+
:reduce="b => b.blockID"
5052
:placeholder="$t('selector.selectableBlocks.placeholder')"
5153
/>
5254

5355
<b-input-group-append>
5456
<b-button
5557
v-b-tooltip.noninteractive.hover="{ title: $t('selector.tooltip.clone.noRef'), container: '#body' }"
5658
variant="extra-light"
57-
:disabled="!selectedExistingBlock"
59+
:disabled="!selectedLayoutBlock"
5860
class="d-flex align-items-center"
59-
@click="$emit('select', selectedExistingBlock.clone())"
61+
@click="selectBlock(selectedLayoutBlock, true)"
6062
>
6163
<font-awesome-icon
6264
:icon="['far', 'clone']"
@@ -66,9 +68,51 @@
6668
<b-button
6769
v-b-tooltip.noninteractive.hover="{ title: $t('selector.tooltip.clone.ref'), container: '#body' }"
6870
variant="extra-light"
69-
:disabled="!selectedExistingBlock"
71+
:disabled="!selectedLayoutBlock"
7072
class="d-flex align-items-center"
71-
@click="$emit('select', selectedExistingBlock)"
73+
@click="selectBlock(selectedLayoutBlock)"
74+
>
75+
<font-awesome-icon
76+
:icon="['far', 'copy']"
77+
/>
78+
</b-button>
79+
</b-input-group-append>
80+
</b-input-group>
81+
</b-col>
82+
83+
<b-col
84+
v-if="selectableGlobalBlocks.length"
85+
cols="12"
86+
>
87+
<b-input-group class="d-flex w-100">
88+
<c-input-select
89+
v-model="selectedGlobalBlock"
90+
:get-option-label="getBlockLabel"
91+
:get-option-key="b => b.blockID"
92+
:options="selectableGlobalBlocks"
93+
:reduce="b => b.blockID"
94+
:placeholder="$t('selector.selectableGlobalBlocks.placeholder')"
95+
/>
96+
97+
<b-input-group-append>
98+
<b-button
99+
v-b-tooltip.noninteractive.hover="{ title: $t('selector.tooltip.clone.noRef'), container: '#body' }"
100+
variant="extra-light"
101+
:disabled="!selectedGlobalBlock"
102+
class="d-flex align-items-center"
103+
@click="selectBlock(selectedGlobalBlock, true)"
104+
>
105+
<font-awesome-icon
106+
:icon="['far', 'clone']"
107+
/>
108+
</b-button>
109+
110+
<b-button
111+
v-b-tooltip.noninteractive.hover="{ title: $t('selector.tooltip.clone.ref'), container: '#body' }"
112+
variant="extra-light"
113+
:disabled="!selectedGlobalBlock"
114+
class="d-flex align-items-center"
115+
@click="selectBlock(selectedGlobalBlock)"
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+
selectableGlobalBlocks: {
105154
type: Array,
106155
default: () => [],
107156
},
@@ -111,7 +160,8 @@ export default {
111160
return {
112161
current: undefined,
113162
114-
selectedExistingBlock: undefined,
163+
selectedLayoutBlock: undefined,
164+
selectedGlobalBlock: undefined,
115165
116166
types: [
117167
{
@@ -220,9 +270,26 @@ export default {
220270
221271
setDefaultValues () {
222272
this.current = undefined
223-
this.selectedExistingBlock = undefined
273+
this.selectedLayoutBlock = undefined
274+
this.selectedGlobalBlock = undefined
224275
this.types = []
225276
},
277+
278+
fetchBlockData (blockID) {
279+
if (blockID.includes('-')) {
280+
return this.selectableGlobalBlocks.find((b) => b.blockID === blockID)
281+
}
282+
283+
return this.existingLayoutBlocks.find((b) => b.blockID === blockID)
284+
},
285+
286+
selectBlock (block, clone = false) {
287+
if (clone) {
288+
this.$emit('select', this.fetchBlockData(block).clone())
289+
} else {
290+
this.$emit('select', this.fetchBlockData(block))
291+
}
292+
},
226293
},
227294
}
228295
</script>

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

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,17 @@
116116
{{ $t('general.border.show') }}
117117
</b-form-checkbox>
118118
</b-form-group>
119+
120+
<b-form-checkbox
121+
v-if="block.kind !== 'Tabs'"
122+
:checked="block.meta.namespaceID"
123+
:value="namespace.namespaceID"
124+
switch
125+
class="mb-2"
126+
@change="updateGlobalState"
127+
>
128+
{{ $t('general.globalBlock.label') }}
129+
</b-form-checkbox>
119130
</b-col>
120131

121132
<b-col
@@ -303,6 +314,11 @@ export default {
303314
type: compose.Page,
304315
required: true,
305316
},
317+
318+
namespace: {
319+
type: compose.Namespace,
320+
required: true,
321+
},
306322
},
307323
308324
data () {
@@ -312,6 +328,8 @@ export default {
312328
options: [],
313329
},
314330
abortableRequests: [],
331+
initialBlockState: undefined,
332+
initialBlockID: undefined,
315333
}
316334
},
317335
@@ -371,6 +389,8 @@ export default {
371389
},
372390
373391
created () {
392+
this.initialBlockState = this.block.meta.namespaceID
393+
this.initialBlockID = this.block.blockID
374394
this.fetchRoles()
375395
},
376396
@@ -414,6 +434,16 @@ export default {
414434
}
415435
this.abortableRequests = []
416436
},
437+
438+
updateGlobalState (value) {
439+
this.block.blockID = this.initialBlockState === value ? this.initialBlockID : NoID
440+
441+
if (value) {
442+
this.block.meta.namespaceID = value
443+
} else {
444+
this.block.meta.namespaceID = undefined
445+
}
446+
},
417447
},
418448
}
419449
</script>

client/web/compose/src/store/namespace.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,16 @@ export default function (ComposeAPI) {
3737
set (state) {
3838
return state.set
3939
},
40+
41+
getNamespaceBlocksByID (state, { getByID }) {
42+
return (ID) => ((getByID(ID) || {}).blocks || []).map((b) => {
43+
const ns = getByID(ID)
44+
const block = compose.PageBlockMaker(b)
45+
block.blockID = `${ns.namespaceID}-${b.blockID}`
46+
47+
return block
48+
})
49+
},
4050
},
4151

4252
actions: {

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)