From cda9c115283be8e4e224f6036ba07e5eca243289 Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Wed, 31 Mar 2021 17:37:40 +0200 Subject: refactor tile forms into own files. add full-width marquee support --- frontend/app/views/tile/forms/index.js | 29 ++++ frontend/app/views/tile/forms/tile.constants.js | 92 ++++++++++++ frontend/app/views/tile/forms/tile.constructors.js | 113 ++++++++++++++ .../views/tile/forms/tile.form.element.gradient.js | 80 ++++++++++ .../views/tile/forms/tile.form.element.image.js | 46 ++++++ .../app/views/tile/forms/tile.form.element.link.js | 32 ++++ .../views/tile/forms/tile.form.element.script.js | 22 +++ .../app/views/tile/forms/tile.form.element.text.js | 166 +++++++++++++++++++++ .../views/tile/forms/tile.form.element.video.js | 101 +++++++++++++ .../app/views/tile/forms/tile.form.hyperlink.js | 64 ++++++++ frontend/app/views/tile/forms/tile.form.misc.js | 98 ++++++++++++ frontend/app/views/tile/forms/tile.form.sound.js | 53 +++++++ frontend/app/views/tile/forms/tile.form.type.js | 29 ++++ 13 files changed, 925 insertions(+) create mode 100644 frontend/app/views/tile/forms/index.js create mode 100644 frontend/app/views/tile/forms/tile.constants.js create mode 100644 frontend/app/views/tile/forms/tile.constructors.js create mode 100644 frontend/app/views/tile/forms/tile.form.element.gradient.js create mode 100644 frontend/app/views/tile/forms/tile.form.element.image.js create mode 100644 frontend/app/views/tile/forms/tile.form.element.link.js create mode 100644 frontend/app/views/tile/forms/tile.form.element.script.js create mode 100644 frontend/app/views/tile/forms/tile.form.element.text.js create mode 100644 frontend/app/views/tile/forms/tile.form.element.video.js create mode 100644 frontend/app/views/tile/forms/tile.form.hyperlink.js create mode 100644 frontend/app/views/tile/forms/tile.form.misc.js create mode 100644 frontend/app/views/tile/forms/tile.form.sound.js create mode 100644 frontend/app/views/tile/forms/tile.form.type.js (limited to 'frontend/app/views/tile/forms') diff --git a/frontend/app/views/tile/forms/index.js b/frontend/app/views/tile/forms/index.js new file mode 100644 index 0000000..8225365 --- /dev/null +++ b/frontend/app/views/tile/forms/index.js @@ -0,0 +1,29 @@ +import { TILE_CONSTRUCTORS } from './tile.constructors' + +import TileImageForm from './tile.form.element.image' +import TileLinkForm from './tile.form.element.link' +import TileTextForm from './tile.form.element.text' +import TileGradientForm from './tile.form.element.gradient' +import TileScriptForm from './tile.form.element.script' +import TileVideoForm from './tile.form.element.video' + +import TileHyperlinkForm from './tile.form.hyperlink' +import TileMiscForm from './tile.form.misc' +import TileSoundForm from './tile.form.sound' +import TileTypeForm from './tile.form.type' + +export { + TILE_CONSTRUCTORS, + + TileImageForm, + TileLinkForm, + TileTextForm, + TileGradientForm, + TileScriptForm, + TileVideoForm, + + TileHyperlinkForm, + TileMiscForm, + TileSoundForm, + TileTypeForm, +} diff --git a/frontend/app/views/tile/forms/tile.constants.js b/frontend/app/views/tile/forms/tile.constants.js new file mode 100644 index 0000000..f2dd0ad --- /dev/null +++ b/frontend/app/views/tile/forms/tile.constants.js @@ -0,0 +1,92 @@ +/* +import { + SELECT_TYPES, ALIGNMENTS, + REQUIRED_KEYS, + IMAGE_TILE_STYLES, VIDEO_STYLES, + TEXT_FONT_FAMILIES, TEXT_FONT_STYLES, + CURSORS, UNITS, + NO_LINK, EXTERNAL_LINK, OPEN_POPUP_LINK, CLOSE_POPUP_LINK, + PAGE_LIST_TOP_OPTIONS, + NO_POPUP, POPUP_LIST_TOP_OPTIONS, +} from 'app/constants' +*/ + +export const SELECT_TYPES = [ + "image", "text", "video", "link", "gradient", "script", +].map(s => ({ name: s, label: s })) + +export const ALIGNMENTS = [ + "top_left", "top_center", "top_right", + "center_left", "center_center", "center_right", + "bottom_left", "bottom_center", "bottom_right", +].map(align => ({ + name: align, + label: align === 'center_center' + ? 'center' + : align.replace('_', ' ') + })) + +export const REQUIRED_KEYS = { + image: ['url'], + video: ['url'], + text: ['content'], + link: [], + gradient: [], + script: [], +} + +export const IMAGE_TILE_STYLES = [ + 'tile', 'cover', 'contain', 'contain no-repeat' +].map(style => ({ name: style, label: style })) + +export const VIDEO_STYLES = [ + 'normal', 'cover', 'contain', +].map(style => ({ name: style, label: style })) + +export const TEXT_FONT_FAMILIES = [ + 'sans-serif', 'serif', 'fantasy', 'monospace', 'cursive', +].map(style => ({ name: style, label: style })) + +export const TEXT_FONT_STYLES = [ + 'normal', 'bold', 'italic', 'bold-italic', +].map(style => ({ name: style, label: style })) + +export const CURSORS = [ + { name: 'none', label: 'None', }, + { name: 'hand_up', label: 'Up', }, + { name: 'hand_down', label: 'Down', }, + { name: 'hand_left', label: 'Left', }, + { name: 'hand_right', label: 'Right', }, + { name: 'unclickable', label: 'Unclickable', }, +] + +export const MARQUEE_DIRECTIONS = [ + { name: 'left', label: 'Left', }, + { name: 'right', label: 'Right', }, +] + +export const UNITS = [ + { name: 'px', label: 'pixels' }, + { name: '%', label: 'percent' }, + { name: 'video', label: 'video' }, + { name: 'vmin', label: 'screen min' }, + { name: 'vmax', label: 'screen max' }, +] + +export const NO_LINK = 0 +export const EXTERNAL_LINK = -1 +export const OPEN_POPUP_LINK = -2 +export const CLOSE_POPUP_LINK = -3 +export const PAGE_LIST_TOP_OPTIONS = [ + { name: NO_LINK, label: 'No link' }, + { name: EXTERNAL_LINK, label: 'External link' }, + { name: OPEN_POPUP_LINK, label: 'Open popup' }, + { name: CLOSE_POPUP_LINK, label: 'Close popup' }, + { name: -99, label: '──────────', disabled: true }, +] + +export const NO_POPUP = 0 +export const POPUP_LIST_TOP_OPTIONS = [ + { name: NO_POPUP, label: 'Select a popup group' }, + { name: -99, label: '──────────', disabled: true }, +] diff --git a/frontend/app/views/tile/forms/tile.constructors.js b/frontend/app/views/tile/forms/tile.constructors.js new file mode 100644 index 0000000..2407274 --- /dev/null +++ b/frontend/app/views/tile/forms/tile.constructors.js @@ -0,0 +1,113 @@ +const newImage = (data) => ({ + settings: { + ...newPosition(), + is_tiled: false, + tile_style: 'tile', + url: "", + external_link_url: "", + cursor: 'hand_up', + }, + type: 'image', + target_page_id: 0, + ...data, +}) + +const newVideo = (data) => ({ + settings: { + ...newPosition(), + video_style: 'cover', + url: "", + external_link_url: "", + cursor: 'none', + muted: false, + loop_style: false, + autoadvance: false, + loop_section: false, + loop_start: 0, + loop_end: 0, + }, + type: 'video', + target_page_id: 0, + ...data, +}) + +const newText = (data) => ({ + settings: { + ...newPosition(), + content: "", + font_family: 'sans-serif', + font_size: 16, + font_style: 'normal', + font_color: '#dddddd', + background_color: 'transparent', + width: 0, + height: 0, + units: 'px', + external_link_url: "", + cursor: 'hand_up', + }, + type: 'text', + target_page_id: 0, + ...data, +}) + +const newGradient = (data) => ({ + settings: { + ...newPosition({ width: 100, height: 100 }), + from_color: '#ffffff', + from_opacity: 1.0, + to_color: '#000000', + to_opacity: 1.0, + angle: 0, + stop: 50, + units: '%', + external_link_url: "", + cursor: 'hand_up', + }, + type: 'gradient', + target_page_id: 0, + ...data, +}) + +const newLink = (data) => ({ + settings: { + ...newPosition({ width: 100, height: 100, }), + external_link_url: "", + cursor: 'hand_up', + units: 'px', + }, + type: 'link', + target_page_id: 0, + ...data, +}) + +const newScript = (data) => ({ + settings: { + ...newPosition({ width: 100, height: 100, }), + }, + type: 'script', + ...data, +}) + +const newPosition = (data) => ({ + x: 0, y: 0, + width: 0, height: 0, + rotation: 0, scale: 1, + opacity: 1, + units: false, + align: "center_center", + has_audio: false, + audio_on_click_id: 0, + audio_on_hover_id: 0, + navigate_when_audio_finishes: false, + ...data, +}) + +export const TILE_CONSTRUCTORS = { + image: newImage, + video: newVideo, + text: newText, + link: newLink, + gradient: newGradient, + script: newScript, +} diff --git a/frontend/app/views/tile/forms/tile.form.element.gradient.js b/frontend/app/views/tile/forms/tile.form.element.gradient.js new file mode 100644 index 0000000..3e35cc0 --- /dev/null +++ b/frontend/app/views/tile/forms/tile.form.element.gradient.js @@ -0,0 +1,80 @@ +import React from 'react' + +import { NumberInput, ColorInput, Slider } from 'app/common' + +export default function TileGradientForm({ tile, parent }) { + return ( +
+ + + + + + +
+ + +
+
+ ) +} diff --git a/frontend/app/views/tile/forms/tile.form.element.image.js b/frontend/app/views/tile/forms/tile.form.element.image.js new file mode 100644 index 0000000..68ef65a --- /dev/null +++ b/frontend/app/views/tile/forms/tile.form.element.image.js @@ -0,0 +1,46 @@ +import React from 'react' + +import { + TextInput, + Select, Checkbox, +} from 'app/common' + +import { IMAGE_TILE_STYLES } from './tile.constants' + +export default function TileImageForm({ tile, errorFields, parent }) { + return ( +
+
+ {tile.settings.url &&
} + +
+
+ + {tile.settings.is_tiled && +