Skip to content

Commit baae52b

Browse files
committed
wip
1 parent f3d4d96 commit baae52b

8 files changed

Lines changed: 91 additions & 92 deletions

File tree

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

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

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

4040
<b-col
41-
v-if="selectableNamespaceGlobalBlocks.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="selectedGlobalBlock"
47+
v-model="selectedLayoutBlock"
4748
:get-option-label="getBlockLabel"
48-
:get-option-key="getOptionKey"
49-
:options="selectableNamespaceGlobalBlocks"
49+
:get-option-key="b => b.blockID"
50+
:options="existingLayoutBlocks"
5051
:reduce="b => b.blockID"
51-
placeholder="Select global block from other pages"
52+
:placeholder="$t('selector.selectableBlocks.placeholder')"
5253
/>
5354

5455
<b-input-group-append>
5556
<b-button
5657
v-b-tooltip.noninteractive.hover="{ title: $t('selector.tooltip.clone.noRef'), container: '#body' }"
5758
variant="extra-light"
58-
:disabled="!selectedGlobalBlock"
59+
:disabled="!selectedLayoutBlock"
5960
class="d-flex align-items-center"
60-
@click="$emit('select', fetchBlockData(selectedGlobalBlock).clone())"
61+
@click="selectBlock(selectedLayoutBlock, true)"
6162
>
6263
<font-awesome-icon
6364
:icon="['far', 'clone']"
@@ -67,9 +68,9 @@
6768
<b-button
6869
v-b-tooltip.noninteractive.hover="{ title: $t('selector.tooltip.clone.ref'), container: '#body' }"
6970
variant="extra-light"
70-
:disabled="!selectedGlobalBlock"
71+
:disabled="!selectedLayoutBlock"
7172
class="d-flex align-items-center"
72-
@click="$emit('select', fetchBlockData(selectedGlobalBlock))"
73+
@click="selectBlock(selectedLayoutBlock)"
7374
>
7475
<font-awesome-icon
7576
:icon="['far', 'copy']"
@@ -80,27 +81,26 @@
8081
</b-col>
8182

8283
<b-col
83-
v-if="existingLayoutBlocks.length"
84+
v-if="selectableGlobalBlocks.length"
8485
cols="12"
85-
class="mt-3"
8686
>
8787
<b-input-group class="d-flex w-100">
8888
<c-input-select
89-
v-model="selectedLayoutExistingBlock"
89+
v-model="selectedGlobalBlock"
9090
:get-option-label="getBlockLabel"
9191
:get-option-key="b => b.blockID"
92-
:options="existingLayoutBlocks"
92+
:options="selectableGlobalBlocks"
9393
:reduce="b => b.blockID"
94-
:placeholder="$t('selector.selectableBlocks.placeholder')"
94+
:placeholder="$t('selector.selectableGlobalBlocks.placeholder')"
9595
/>
9696

9797
<b-input-group-append>
9898
<b-button
9999
v-b-tooltip.noninteractive.hover="{ title: $t('selector.tooltip.clone.noRef'), container: '#body' }"
100100
variant="extra-light"
101-
:disabled="!selectedLayoutExistingBlock"
101+
:disabled="!selectedGlobalBlock"
102102
class="d-flex align-items-center"
103-
@click="$emit('select', fetchBlockData(selectedLayoutExistingBlock).clone())"
103+
@click="selectBlock(selectedGlobalBlock, true)"
104104
>
105105
<font-awesome-icon
106106
:icon="['far', 'clone']"
@@ -110,9 +110,9 @@
110110
<b-button
111111
v-b-tooltip.noninteractive.hover="{ title: $t('selector.tooltip.clone.ref'), container: '#body' }"
112112
variant="extra-light"
113-
:disabled="!selectedLayoutExistingBlock"
113+
:disabled="!selectedGlobalBlock"
114114
class="d-flex align-items-center"
115-
@click="$emit('select', fetchBlockData(selectedLayoutExistingBlock))"
115+
@click="selectBlock(selectedGlobalBlock)"
116116
>
117117
<font-awesome-icon
118118
:icon="['far', 'copy']"
@@ -150,7 +150,7 @@ export default {
150150
default: () => [],
151151
},
152152
153-
selectableNamespaceGlobalBlocks: {
153+
selectableGlobalBlocks: {
154154
type: Array,
155155
default: () => [],
156156
},
@@ -160,7 +160,7 @@ export default {
160160
return {
161161
current: undefined,
162162
163-
selectedLayoutExistingBlock: undefined,
163+
selectedLayoutBlock: undefined,
164164
selectedGlobalBlock: undefined,
165165
166166
types: [
@@ -275,22 +275,26 @@ export default {
275275
276276
setDefaultValues () {
277277
this.current = undefined
278-
this.selectedLayoutExistingBlock = undefined
278+
this.selectedLayoutBlock = undefined
279279
this.selectedGlobalBlock = undefined
280280
this.types = []
281281
},
282282
283-
getOptionKey ({ blockID }) {
284-
return blockID
285-
},
286-
287283
fetchBlockData (blockID) {
288284
if (blockID.includes('-')) {
289-
return this.selectableNamespaceGlobalBlocks.find((b) => b.blockID === blockID)
285+
return this.selectableGlobalBlocks.find((b) => b.blockID === blockID)
290286
}
291287
292288
return this.existingLayoutBlocks.find((b) => b.blockID === blockID)
293289
},
290+
291+
selectBlock (block, clone = false) {
292+
if (clone) {
293+
this.$emit('select', this.fetchBlockData(block).clone())
294+
} else {
295+
this.$emit('select', this.fetchBlockData(block))
296+
}
297+
},
294298
},
295299
}
296300
</script>

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

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -130,11 +130,11 @@
130130
</b-form-checkbox>
131131
<b-form-checkbox
132132
v-if="block.kind !== 'Tabs'"
133-
v-model="block.meta.namespaceID"
134133
:value="namespace.namespaceID"
135-
:disabled="alreadyGlobalBlock"
134+
:disabled="!!block.meta.namespaceID"
136135
switch
137136
class="mb-2"
137+
@change="updateGlobalState"
138138
>
139139
{{ $t('general.globalBlock.label') }}
140140
</b-form-checkbox>
@@ -238,12 +238,6 @@ export default {
238238
},
239239
},
240240
241-
data () {
242-
return {
243-
alreadyGlobalBlock: false,
244-
}
245-
},
246-
247241
computed: {
248242
textVariants () {
249243
return [
@@ -275,27 +269,21 @@ export default {
275269
},
276270
},
277271
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-
289272
methods: {
290273
updateRefresh (e) {
291274
// If value is less than 5 but greater than 0 make it 5. Otherwise value stays the same.
292275
this.block.options.refreshRate = e.target.value < 5 && e.target.value > 0 ? 5 : e.target.value
293276
},
277+
updateGlobalState (value) {
278+
if (value) {
279+
this.block.meta.namespaceID = value
280+
}
281+
},
294282
},
295283
}
296284
</script>
297285
<style scoped>
298286
.mh-tab {
299287
max-height: calc(100vh - 16rem);
300288
}
301-
</style>import { watch } from 'fs'
289+
</style>

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/Pages/Builder.vue

Lines changed: 19 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@
174174
<new-block-selector
175175
:record-page="!!module"
176176
:existing-layout-blocks="selectableExistingLayoutBlocks"
177-
:selectable-namespace-global-blocks="selectableNamespaceGlobalBlocks"
177+
:selectable-global-blocks="selectableNamespaceGlobalBlocks"
178178
style="max-height: 75vh;"
179179
@select="addBlock"
180180
/>
@@ -443,6 +443,7 @@ export default {
443443
getModuleByID: 'module/getByID',
444444
previousPage: 'ui/previousPage',
445445
namespaces: 'namespace/set',
446+
getNamespaceBlocks: 'namespace/getNamespaceBlocksByID',
446447
}),
447448
448449
trPage: {
@@ -508,19 +509,9 @@ export default {
508509
509510
selectableNamespaceGlobalBlocks () {
510511
const { namespaceID } = this.namespace
511-
const namespace = this.namespaces.find((n) => n.namespaceID === namespaceID)
512512
513-
if (!namespace) {
514-
return []
515-
}
516-
517-
return cloneDeep(namespace.blocks).map((b, i) => {
518-
const block = compose.PageBlockMaker(b)
519-
block.blockID = `${namespaceID}-${b.blockID}`
520-
521-
return block
522-
}).filter(b => {
523-
return !this.blocks.find(({ blockID }) => blockID === b.blockID)
513+
return this.getNamespaceBlocks(namespaceID).filter(({ blockID }) => {
514+
return !this.usedBlocks.some(b => b.blockID === blockID)
524515
})
525516
},
526517
@@ -906,7 +897,7 @@ export default {
906897
this.findPageByID({ ...this.page, force: true }),
907898
this.findLayoutByID({ ...this.layout }),
908899
]).then(async ([page, layout]) => {
909-
let blocks = [
900+
const blocks = [
910901
...page.blocks.filter(({ blockID }) => {
911902
// Check if block exists in any other layout, if not delete it permanently
912903
return !this.blocks.some(b => b.blockID === blockID) && this.layouts.some(({ pageLayoutID, blocks }) => pageLayoutID !== layout.pageLayoutID && blocks.some(b => b.blockID === blockID))
@@ -921,14 +912,16 @@ export default {
921912
b.meta.namespaceID ? namespaceBlocks.push(b) : pageBlocks.push(b)
922913
})
923914
915+
console.log('namespaceBlocks', namespaceBlocks)
916+
924917
const updatedGlobalBlocks = await this.processGlobalBlocks(namespaceBlocks)
925918
926919
return this.updatePage({ namespaceID, ...page, blocks: pageBlocks })
927920
.then(this.updateTabbedBlockIDs)
928921
.then(async page => {
929922
const blocks = this.blocks.map(({ blockID, meta, xywh }) => {
930923
// If the global blocks is a newly created global block
931-
if (meta.namespaceID && !blockID.includes('-')) {
924+
if (meta.namespaceID) {
932925
blockID = (updatedGlobalBlocks.find(block => block.meta.tempID === meta.tempID) || {}).blockID
933926
} else if (blockID === NoID) {
934927
blockID = (page.blocks.find(block => block.meta.tempID === meta.tempID) || {}).blockID
@@ -970,24 +963,21 @@ export default {
970963
971964
let { namespaceID, name, slug, enabled, meta } = this.namespace
972965
973-
// If new blocks are added to global blocks update the ID's
966+
// Block ID is already reset
974967
const newGlobalBlocks = globalBlocks
975-
// We can't detect new global block through NOID because there can be an existing local block that
976-
// was now made global previously and make a global block which means it does have the NoID added to it
977-
.filter(({ blockID }) => !blockID.includes('-'))
968+
.filter(({ blockID }) => !blockID.includes(namespaceID))
978969
.map((block) => {
979970
block.meta.namespaceID = namespaceID
980971
981972
return block
982973
})
983974
984-
// Update existing global blocks
985-
const existingGlobalBlocks = this.namespace.blocks
975+
const namespace = this.namespaces.find((n) => n.namespaceID === this.namespace.namespaceID)
976+
977+
const existingGlobalBlocks = namespace.blocks
986978
987-
// Update the state of the existing global blocks so the include the updated state changes
988979
globalBlocks.forEach((block) => {
989-
block.blockID = String(block.blockID).replace(`${namespaceID}-`, '')
990-
const matchingBlockIndex = existingGlobalBlocks.findIndex(({ blockID }) => blockID === block.blockID)
980+
const matchingBlockIndex = existingGlobalBlocks.findIndex(({ meta }) => meta.tempID === block.meta.tempID)
991981
992982
if (matchingBlockIndex > -1) {
993983
const normalBlockID = existingGlobalBlocks[matchingBlockIndex].blockID
@@ -1187,9 +1177,9 @@ export default {
11871177
meta,
11881178
}))
11891179
1190-
block.blockID = meta.namespaceID ? `${namespaceID}-${block.blockID}` : block.blockID
1191-
11921180
if (block) {
1181+
block.blockID = meta.namespaceID ? `${namespaceID}-${block.blockID}` : block.blockID
1182+
11931183
block.xywh = xywh
11941184
block.meta.hidden = !!meta.hidden
11951185
tempBlocks.push(block)
@@ -1255,11 +1245,9 @@ export default {
12551245
blockID = fetchID({ blockID, meta })
12561246
12571247
if (meta.namespaceID) {
1258-
const namespace = this.namespaces.find((n) => n.namespaceID === this.namespace.namespaceID)
1248+
const { blocks = [] } = this.namespaces.find((n) => n.namespaceID === this.namespace.namespaceID) || {}
12591249
1260-
if (namespace) {
1261-
return namespace.blocks.find((b) => fetchID(b) === blockID)
1262-
}
1250+
return blocks.find((b) => fetchID(b) === blockID)
12631251
}
12641252
12651253
return this.page.blocks.find((b) => fetchID(b) === blockID)
@@ -1293,4 +1281,4 @@ div.toolbox {
12931281
right: auto;
12941282
}
12951283
}
1296-
</style>
1284+
</style>, includes

client/web/compose/src/views/Public/Pages/View.vue

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ export default {
156156
...mapGetters({
157157
recordPaginationUsable: 'ui/recordPaginationUsable',
158158
getPageLayouts: 'pageLayout/getByPageID',
159+
namespaces: 'namespace/set',
159160
}),
160161
161162
isRecordPage () {
@@ -299,14 +300,17 @@ export default {
299300
document.title = [title, this.namespace.name, this.$t('general:label.app-name.public')].filter(v => v).join(' | ')
300301
301302
this.blocks = (this.layout || {}).blocks.map(({ blockID, meta, xywh }) => {
303+
console.log('{ blockID, meta, xywh }', { blockID, meta, xywh })
302304
const block = this.fetchBlockData({
303305
blockID,
304306
meta,
305307
})
306308
307-
block.xywh = xywh
308-
return block
309-
})
309+
if (block) {
310+
block.xywh = xywh
311+
return block
312+
}
313+
}).filter(b => b)
310314
},
311315
312316
refetchRecords () {
@@ -318,7 +322,11 @@ export default {
318322
blockID = fetchID({ blockID, meta })
319323
320324
if (meta.namespaceID) {
321-
return this.namespace.blocks.find((b) => fetchID(b) === blockID)
325+
const namespace = this.namespaces.find((n) => n.namespaceID === this.namespace.namespaceID)
326+
327+
if (namespace) {
328+
return namespace.blocks.find((b) => fetchID(b) === blockID)
329+
}
322330
}
323331
324332
return this.page.blocks.find((b) => fetchID(b) === blockID)

0 commit comments

Comments
 (0)