Skip to content

Commit

Permalink
Remove all content/essence related code
Browse files Browse the repository at this point in the history
This is a HUGE commit, but it is atomic and this is good.
  • Loading branch information
tvdeyen committed Jan 21, 2023
1 parent 6ffa05d commit c7dd085
Show file tree
Hide file tree
Showing 253 changed files with 1,008 additions and 8,002 deletions.
2 changes: 1 addition & 1 deletion app/assets/javascripts/alchemy/alchemy.dirty.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ $.extend Alchemy,
setElementClean: (element) ->
$element = $(element)
$element.removeClass('dirty')
$element.find('> .element-content .dirty').removeClass('dirty')
$element.find('> .element-body .dirty').removeClass('dirty')
window.onbeforeunload = undefined

isPageDirty: ->
Expand Down
50 changes: 18 additions & 32 deletions app/assets/javascripts/alchemy/alchemy.element_editors.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Alchemy.ElementEditors =
init: ->
@element_area = $("#element_area")
@bindEvents()
@expandContentGroups()
@expandIngredientGroups()
return

# Binds click events on several DOM elements from element editors
Expand All @@ -29,27 +29,25 @@ Alchemy.ElementEditors =
@onDoubleClickElement(e)
@element_area.on "click", "[data-element-toggle]", (e) =>
@onClickToggle(e)
@element_area.on "click", '[data-create-missing-content]', (e) =>
@onClickMissingContent(e)
# Binds the custom FocusElementEditor event
@element_area.on "FocusElementEditor.Alchemy", '.element-editor', (e) =>
@onFocusElement(e)
# Binds the custom SaveElement event
@element_area.on "SaveElement.Alchemy", '.element-editor', (e, data) =>
@onSaveElement(e, data)
@element_area.on "click", '[data-toggle-content-group]', (e) =>
@onToggleContentGroup(e)
@element_area.on "click", '[data-toggle-ingredient-group]', (e) =>
@onToggleIngredientGroup(e)
# Listen to postMessage messages from the preview frame
window.addEventListener 'message', (e) =>
@onMessage(e.data)
true
return

# Expands content groups that are stored in sessionStorage as expanded
expandContentGroups: ->
if $expanded_content_groups = sessionStorage.getItem('Alchemy.expanded_content_groups')
for header_id in JSON.parse($expanded_content_groups) then do (header_id) =>
$('#' + header_id).closest('.content-group').addClass('expanded');
# Expands ingredient groups that are stored in sessionStorage as expanded
expandIngredientGroups: ->
if $expanded_ingredient_groups = sessionStorage.getItem('Alchemy.expanded_ingredient_groups')
for header_id in JSON.parse($expanded_ingredient_groups) then do (header_id) =>
$('#' + header_id).closest('.ingredient-group').addClass('expanded');

# Selects and scrolls to element with given id in the preview window.
#
Expand Down Expand Up @@ -179,21 +177,21 @@ Alchemy.ElementEditors =
Alchemy.Buttons.enable($element)
true

# Toggle visibility of the content fields in the group
onToggleContentGroup: (event) ->
$group_div = $(event.currentTarget).closest('.content-group');
# Toggle visibility of the ingredient fields in the group
onToggleIngredientGroup: (event) ->
$group_div = $(event.currentTarget).closest('.ingredient-group');
$group_div.toggleClass('expanded');

$expanded_content_groups = JSON.parse(sessionStorage.getItem('Alchemy.expanded_content_groups') || '[]');
# Add or remove depending on whether this content group is expanded
$expanded_ingredient_groups = JSON.parse(sessionStorage.getItem('Alchemy.expanded_ingredient_groups') || '[]');
# Add or remove depending on whether this ingredient group is expanded
if $group_div.hasClass('expanded')
if $expanded_content_groups.indexOf(event.currentTarget.id) == -1
$expanded_content_groups.push(event.currentTarget.id);
if $expanded_ingredient_groups.indexOf(event.currentTarget.id) == -1
$expanded_ingredient_groups.push(event.currentTarget.id);
else
$expanded_content_groups = $expanded_content_groups.filter (value) ->
$expanded_ingredient_groups = $expanded_ingredient_groups.filter (value) ->
value != event.currentTarget.id

sessionStorage.setItem('Alchemy.expanded_content_groups', JSON.stringify($expanded_content_groups))
sessionStorage.setItem('Alchemy.expanded_ingredient_groups', JSON.stringify($expanded_ingredient_groups))
false

# Event handlers
Expand Down Expand Up @@ -248,22 +246,10 @@ Alchemy.ElementEditors =
e.stopPropagation()
false

# Handles the missing content button click events.
#
# Ensures that the links query string is converted into post body and send
# the request via a real ajax post to server, to allow long query strings.
#
onClickMissingContent: (e) ->
link = e.target
url = link.pathname
querystring = link.search.replace(/\?/, '')
$.post(url, querystring)
false

# private

_shouldUpdateTitle: (element, event) ->
editors = element.find('> .element-content .element-content-editors, > .element-content .element-ingredient-editors').children()
editors = element.find('> .element-body .element-ingredient-editors').children()
if @_hasParents(element)
editors.length != 0
else if @_isParent(element) && @_isFirstChild $(event.target)
Expand Down
28 changes: 8 additions & 20 deletions app/assets/stylesheets/alchemy/elements.scss
Original file line number Diff line number Diff line change
Expand Up @@ -275,11 +275,10 @@
}
}

.element-content {
.element-body {
margin: 4px 8px;
}

.content_editor,
.ingredient-editor,
.picture_thumbnail {
width: 100%;
Expand All @@ -303,7 +302,7 @@
}
}

.element-content {
.element-body {
margin: 2 * $default-padding;
}

Expand Down Expand Up @@ -414,7 +413,7 @@
}
}

.content-group {
.ingredient-group {
width: 100%;
padding: $default-padding 0;
position: relative;
Expand All @@ -425,7 +424,7 @@
padding-bottom: 0;
}

.content-group-header {
.ingredient-group-header {
display: flex;
align-items: center;
justify-content: space-between;
Expand All @@ -434,22 +433,21 @@
padding: $default-padding 1px;
}

.content-group-contents {
.ingredient-group-ingredients {
display: none;
}

&.expanded {
.content-group-contents {
.ingredient-group-ingredients {
display: block;
}

.content-group-expand {
.ingredient-group-expand {
@extend .fa-angle-up;
}
}
}

.element-content-editors,
.element-ingredient-editors {
display: flex;
flex-wrap: wrap;
Expand Down Expand Up @@ -639,9 +637,6 @@
}
}

.content_editor.essence_audio,
.content_editor.essence_file,
.content_editor.essence_video,
.ingredient-editor.audio,
.ingredient-editor.file,
.ingredient-editor.video {
Expand Down Expand Up @@ -717,7 +712,6 @@ select.long {
padding: 0;
}

.content_editor,
.ingredient-editor {
width: 100%;
padding: $default-padding 0;
Expand Down Expand Up @@ -885,10 +879,6 @@ select.long {
}
}

.content_rtf_text_area {
display: none;
}

div.pictures_for_element {
overflow: auto;
margin-top: 4px;
Expand Down Expand Up @@ -928,8 +918,6 @@ textarea.has_tinymce {
}
}

.content_editor .hint-with-icon,
.content_editor .with-hint,
.ingredient-editor .hint-with-icon,
.ingredient-editor .with-hint,
.element-handle .hint-with-icon {
Expand All @@ -946,7 +934,7 @@ textarea.has_tinymce {
}

.is-fixed {
&.with-contents {
&.with-ingredients {
> .element-footer {
border-top: 0;
border-bottom: 1px solid $medium-gray;
Expand Down
21 changes: 0 additions & 21 deletions app/controllers/alchemy/admin/contents_controller.rb

This file was deleted.

39 changes: 8 additions & 31 deletions app/controllers/alchemy/admin/elements_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,16 @@ def create
def update
@page = @element.page

if element_params.key?(:ingredients_attributes)
update_element_with_ingredients
if @element.update(element_params)
@element_validated = true
else
update_element_with_contents
element_update_error
@error_messages = @element.ingredient_error_messages
end
end

def destroy
@richtext_ids = @element.richtext_contents_ids + @element.richtext_ingredients_ids
@richtext_ids = @element.richtext_ingredients_ids
@element.destroy
@notice = Alchemy.t("Successfully deleted element") % { element: @element.display_name }
end
Expand Down Expand Up @@ -103,14 +104,12 @@ def fold
def element_includes
[
{
contents: :essence,
ingredients: :related_object,
},
:tags,
{
all_nested_elements: [
{
contents: :essence,
ingredients: :related_object,
},
:tags,
Expand All @@ -130,9 +129,9 @@ def load_clipboard_items

def element_from_clipboard
@element_from_clipboard ||= begin
@clipboard = get_clipboard("elements")
@clipboard.detect { |item| item["id"].to_i == params[:paste_from_clipboard].to_i }
end
@clipboard = get_clipboard("elements")
@clipboard.detect { |item| item["id"].to_i == params[:paste_from_clipboard].to_i }
end
end

def paste_element_from_clipboard
Expand All @@ -152,10 +151,6 @@ def paste_element_from_clipboard
element
end

def contents_params
params.fetch(:contents, {}).permit!
end

def element_params
params.fetch(:element, {}).permit(:tag_list, ingredients_attributes: {})
end
Expand All @@ -164,24 +159,6 @@ def create_element_params
params.require(:element).permit(:name, :page_version_id, :parent_element_id)
end

def update_element_with_ingredients
if @element.update(element_params)
@element_validated = true
else
element_update_error
@error_messages = @element.ingredient_error_messages
end
end

def update_element_with_contents
if @element.update_contents(contents_params)
@element_validated = @element.update(element_params)
else
element_update_error
@error_messages = @element.essence_error_messages
end
end

def element_update_error
@element_validated = false
@notice = Alchemy.t("Validation failed")
Expand Down
30 changes: 0 additions & 30 deletions app/controllers/alchemy/admin/essence_audios_controller.rb

This file was deleted.

31 changes: 0 additions & 31 deletions app/controllers/alchemy/admin/essence_files_controller.rb

This file was deleted.

Loading

0 comments on commit c7dd085

Please sign in to comment.