Skip to content

Commit 9e4052a

Browse files
committed
feat: first working version of the EditorUI using the layouts (WIP)
1 parent 7cca384 commit 9e4052a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+785
-235
lines changed

app/controllers/concerns/maglev/fetchers_concern.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@ def fetch_maglev_page
3535
)
3636
end
3737

38-
def fetch_maglev_page_sections(page_sections = nil)
38+
def fetch_maglev_page_sections(sections_content = nil)
3939
@fetch_maglev_page_sections ||= maglev_services.get_page_sections.call(
4040
page: fetch_maglev_page,
41-
page_sections: page_sections,
41+
sections_content: sections_content,
4242
locale: content_locale
4343
)
4444
end

app/controllers/maglev/api/pages_controller.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ def site_params
4949
end
5050

5151
def persist!(page)
52+
# TODO: don't use the PersistPage anymore, just use the AR methods
5253
services.persist_page.call(
5354
page: page,
5455
page_attributes: page_params,
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# frozen_string_literal: true
2+
3+
module Maglev
4+
module Api
5+
class SectionsContentController < ::Maglev::ApiController
6+
before_action :set_page
7+
8+
def show
9+
@sections_content = maglev_services.get_page_sections.call(
10+
page: @page,
11+
locale: content_locale
12+
)
13+
end
14+
15+
def update
16+
@stores = services.persist_sections_content.call(
17+
site: maglev_site,
18+
page: @page,
19+
sections_content: sections_content_params
20+
)
21+
end
22+
23+
private
24+
25+
def set_page
26+
@page = resources.find(params[:page_id])
27+
end
28+
29+
def sections_content_params
30+
params.to_unsafe_hash[:sections_content]
31+
end
32+
33+
def resources
34+
::Maglev::Page
35+
end
36+
end
37+
end
38+
end

app/controllers/maglev/editor_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class EditorController < ApplicationController
1313
before_action :set_content_locale, only: :show
1414

1515
helper_method :maglev_home_page_id
16-
16+
1717
def show
1818
fetch_maglev_page_content
1919
render layout: nil

app/controllers/maglev/page_preview_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def fetch_maglev_site
3232
def fetch_maglev_page_sections
3333
return super if action_name == 'index'
3434

35-
super(JSON.parse(params[:page_sections]))
35+
super(JSON.parse(params[:sections_content]))
3636
end
3737

3838
def maglev_rendering_mode

app/frontend/editor/components/header-nav/save-button.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export default {
2626
},
2727
methods: {
2828
async save() {
29-
await this.$store.dispatch('persistPage')
29+
await this.$store.dispatch('persistSectionsContent')
3030
},
3131
},
3232
}

app/frontend/editor/components/section-highlighter/bottom-actions.vue

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<router-link
77
:to="{
88
name: 'addSectionAfter',
9-
params: { sectionId: hoveredSection.sectionId },
9+
params: { layoutGroupId, sectionId }
1010
}"
1111
custom
1212
v-slot="{ navigate }"
@@ -35,6 +35,12 @@ export default {
3535
const { definition } = this.hoveredSection
3636
return definition.insertButton
3737
},
38+
sectionId() {
39+
return this.hoveredSection.sectionId
40+
},
41+
layoutGroupId() {
42+
return this.currentSectionLayoutGroupIdMap[this.sectionId]
43+
},
3844
},
3945
}
4046
</script>
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<template>
2+
<div class="divide-y">
3+
<section-list
4+
v-for="layoutGroup in sectionsContent"
5+
:key="['layout-group', layoutGroup.id].join('-')"
6+
:layout-group="layoutGroup"
7+
class="py-2"
8+
/>
9+
</div>
10+
</template>
11+
12+
<script>
13+
import SectionList from './list.vue'
14+
15+
export default {
16+
name: 'SectionsContent',
17+
components: { SectionList },
18+
computed: {
19+
sectionsContent() {
20+
return this.currentSectionsContent
21+
},
22+
}
23+
}
24+
</script>

app/frontend/editor/components/section-list/index.vue renamed to app/frontend/editor/components/sections-content/list.vue

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
<template>
2-
<div>
3-
<div v-if="isListEmpty" class="text-center mt-8">
2+
<div class="space-y-4">
3+
<h3 class="uppercase text-gray-800 antialiased text-xs font-semibold sticky top-0 bg-white pt-2">
4+
{{ layoutGroup.label }}
5+
</h3>
6+
<div v-if="isListEmpty" class="text-center">
47
<span class="text-gray-800">{{ $t('sections.listPane.empty') }}</span>
58
</div>
69
<draggable :list="list" @end="onSortEnd" v-bind="dragOptions" v-else>
@@ -15,11 +18,20 @@
1518
/>
1619
</transition-group>
1720
</draggable>
21+
22+
<p class="flex justify-center">
23+
<router-link
24+
:to="{ name: 'addSection', params: { layoutGroupId } }"
25+
class="flex items-center space-x-1 transition-colors duration-200 text-gray-500 hover:text-editor-primary">
26+
<uikit-icon name="add-box-line" size="1rem" />
27+
<span>Add section</span>
28+
</router-link>
29+
</p>
1830
</div>
1931
</template>
2032

2133
<script>
22-
import { mapActions } from 'vuex'
34+
import { mapActions, mapGetters } from 'vuex'
2335
import draggable from 'vuedraggable'
2436
import GroupedDropdownsMixin from '@/mixins/grouped-dropdowns'
2537
import ListItem from './list-item.vue'
@@ -28,12 +40,18 @@ export default {
2840
name: 'SectionList',
2941
mixins: [GroupedDropdownsMixin],
3042
components: { draggable, ListItem },
43+
props: {
44+
layoutGroup: { type: Object, required: true },
45+
},
3146
computed: {
3247
list() {
33-
return this.currentSectionList
48+
return this.layoutGroup.sections
3449
},
3550
isListEmpty() {
36-
return this.currentSectionList.length === 0
51+
return this.list.length === 0
52+
},
53+
layoutGroupId() {
54+
return this.layoutGroup.id
3755
},
3856
dragOptions() {
3957
return {
@@ -48,6 +66,7 @@ export default {
4866
...mapActions(['moveSection']),
4967
onSortEnd(event) {
5068
this.moveSection({
69+
layoutGroupId:this.layoutGroupId,
5170
from: event.oldIndex,
5271
to: event.newIndex,
5372
})

app/frontend/editor/components/sidebar-nav.vue

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,6 @@
77
<div class="w-6 bg-gray-200 rounded h-48 my-6"></div>
88
</div>
99
<ol class="divide-y divide-gray-300 px-4" v-else>
10-
<li>
11-
<router-link
12-
:to="{ name: 'addSection' }"
13-
class="flex justify-center py-5 -ml-4 -mr-4 hover:bg-editor-primary hover:bg-opacity-5 transition-colors duration-200"
14-
:class="{
15-
'bg-white': !isAddSectionPaneActive,
16-
'bg-editor-primary bg-opacity-5': isAddSectionPaneActive,
17-
}"
18-
v-tooltip.right="$t('sidebarNav.addNewSectionTooltip')"
19-
>
20-
<uikit-icon name="add-box-line" size="1.5rem" />
21-
</router-link>
22-
</li>
2310
<li>
2411
<router-link
2512
:to="{ name: 'listSections' }"

app/frontend/editor/components/theme-section-list/index.vue

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
v-for="section in category.children"
1717
:key="section.id"
1818
:section="section"
19-
:insertAfter="insertAfter"
19+
:layout-group-id="layoutGroupId"
20+
:insert-after="insertAfter"
2021
/>
2122

2223
<div
@@ -37,6 +38,7 @@ export default {
3738
name: 'ThemeSectionList',
3839
components: { ListItem },
3940
props: {
41+
layoutGroupId: { type: String, required: true },
4042
insertAfter: { type: String },
4143
},
4244
data() {

app/frontend/editor/components/theme-section-list/list-item.vue

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ export default {
4242
name: 'ThemeSectionListItem',
4343
props: {
4444
section: { type: Object, required: true, default: null },
45+
layoutGroupId: { type: String, required: true },
4546
insertAfter: { type: String },
4647
},
4748
data() {
@@ -63,6 +64,7 @@ export default {
6364
select() {
6465
if (!this.canBeAdded) return
6566
this.addSection({
67+
layoutGroupId: this.layoutGroupId,
6668
sectionDefinition: this.section,
6769
insertAt: this.insertAfter,
6870
}).then(() => {

app/frontend/editor/layouts/slide-pane.vue

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
</div>
3131

3232
<div class="ml-auto">
33-
<router-link :to="{ name: 'editPage' }">
33+
<router-link :to="closeRouteTo">
3434
<uikit-icon name="ri-close-circle-line" />
3535
</router-link>
3636
</div>
@@ -75,7 +75,8 @@ export default {
7575
overflowY: { type: Boolean, default: true },
7676
maxWidthPane: { type: Boolean, default: false },
7777
withPreTitle: { type: Boolean, default: false },
78-
},
78+
closeRouteTo: { type: Object, default: () => ({ name: 'editPage' }) }
79+
}
7980
}
8081
</script>
8182

app/frontend/editor/mixins/global.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,19 @@ Vue.mixin({
4343
currentSectionI18nScope() {
4444
return `${this.currentI18nScope}.sections.${this.currentSection.type}`
4545
},
46+
currentSectionsContent() {
47+
return this.$store.getters.sectionsContent
48+
},
4649
currentSectionList() {
47-
return this.$store.getters.sectionList
50+
console.log('🚨🚨🚨 currentSectionList is deprecated')
51+
return []; //this.$store.getters.sectionList
4852
},
4953
currentSectionContent() {
5054
return this.$store.getters.sectionContent
5155
},
56+
currentSectionLayoutGroupIdMap() {
57+
return this.$store.getters.sectionLayoutGroupIdMap
58+
},
5259
currentSectionDefinition() {
5360
return this.$store.state.sectionDefinition
5461
},
@@ -88,6 +95,9 @@ Vue.mixin({
8895
hasMultipleLocales() {
8996
return this.$store.state.site.locales.length > 1
9097
},
98+
hasSections() {
99+
return Object.keys(this.$store.state.sections).length > 0
100+
},
91101
currentContent() {
92102
return this.$store.getters.content
93103
},

app/frontend/editor/router/routes/section.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import SectionListPane from '@/views/sections/list-pane.vue'
55

66
export default [
77
{
8-
path: 'add-section',
8+
path: 'add-section/:layoutGroupId',
99
name: 'addSection',
1010
components: {
1111
default: PagePreview,
@@ -17,7 +17,7 @@ export default [
1717
},
1818
},
1919
{
20-
path: 'add-section/:sectionId',
20+
path: 'add-section/:layoutGroupId/:sectionId',
2121
name: 'addSectionAfter',
2222
components: {
2323
default: PagePreview,

app/frontend/editor/services/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import * as api from './api'
22
import buildSiteService from './site'
33
import * as theme from './theme'
44
import buildPageService from './page'
5+
import buildSectionsContentService from './sections-content'
56
import buildCollectionItemService from './collection-item'
67
import buildImageService from './image'
78
import * as section from './section'
@@ -13,6 +14,7 @@ export default {
1314
site: buildSiteService(api),
1415
theme,
1516
page: buildPageService(api),
17+
sectionsContent: buildSectionsContentService(api),
1618
section,
1719
block,
1820
image: buildImageService(api),

app/frontend/editor/services/live-preview.js

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@ import store from '@/store'
44
let iframe = null
55

66
// === Section related actions ===
7-
export const addSection = (content, section, insertAt) => {
8-
postMessage('section:add', { content, section, insertAt })
7+
export const addSection = (layoutGroupId, content, section, insertAt) => {
8+
postMessage('section:add', { layoutGroupId, content, section, insertAt })
99
}
1010

11-
export const moveSection = (content, sectionId, targetSectionId, direction) => {
11+
export const moveSection = (layoutGroupId, content, sectionId, targetSectionId, direction) => {
1212
postMessage('section:move', {
13+
layoutGroupId,
1314
content,
1415
sectionId,
1516
targetSectionId,
@@ -18,29 +19,29 @@ export const moveSection = (content, sectionId, targetSectionId, direction) => {
1819
}
1920

2021
// the editor modifies the content of a section setting
21-
export const updateSection = (content, section, change) => {
22-
postMessage('section:update', { content, section, change })
22+
export const updateSection = (layoutGroupId, content, section, change) => {
23+
postMessage('section:update', { layoutGroupId, content, section, change })
2324
}
2425

25-
export const removeSection = (sectionId) => {
26-
postMessage('section:remove', { sectionId })
26+
export const removeSection = (layoutGroupId, sectionId) => {
27+
postMessage('section:remove', { layoutGroupId, sectionId })
2728
}
2829

2930
// === Block related actions ===
30-
export const addBlock = (content, section, sectionBlock) => {
31-
postMessage('block:add', { content, section, sectionBlock })
31+
export const addBlock = (layoutGroupId, content, section, sectionBlock) => {
32+
postMessage('block:add', { layoutGroupId, content, section, sectionBlock })
3233
}
3334

34-
export const moveBlock = (content, section) => {
35-
postMessage('block:move', { content, section })
35+
export const moveBlock = (layoutGroupId, content, section) => {
36+
postMessage('block:move', { layoutGroupId, content, section })
3637
}
3738

38-
export const updateBlock = (content, section, sectionBlock, change) => {
39-
postMessage('block:update', { content, section, sectionBlock, change })
39+
export const updateBlock = (layoutGroupId, content, section, sectionBlock, change) => {
40+
postMessage('block:update', { layoutGroupId, content, section, sectionBlock, change })
4041
}
4142

42-
export const removeBlock = (content, section, sectionBlockId) => {
43-
postMessage('block:remove', { content, section, sectionBlockId })
43+
export const removeBlock = (layoutGroupId, content, section, sectionBlockId) => {
44+
postMessage('block:remove', { layoutGroupId, content, section, sectionBlockId })
4445
}
4546

4647
// === Other actions ===

0 commit comments

Comments
 (0)