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/common/form.component.js | 2 +- frontend/app/views/tile/components/tile.form.js | 795 +-------------------- 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 + frontend/app/views/tile/handles/tile.gradient.js | 18 +- frontend/app/views/tile/handles/tile.text.js | 23 +- frontend/app/views/tile/tile.utils.js | 28 +- package.json | 1 + yarn.lock | 5 + 20 files changed, 1021 insertions(+), 776 deletions(-) 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 diff --git a/frontend/app/common/form.component.js b/frontend/app/common/form.component.js index de1020a..ea4c5cb 100644 --- a/frontend/app/common/form.component.js +++ b/frontend/app/common/form.component.js @@ -68,7 +68,7 @@ export class NumberInput extends Component { onKeyDown={this.handleKeyDown} onChange={props.onChange} name={props.name} - value={props.data[props.name]} + value={props.name in props.data ? props.data[props.name] : (props.defaultValue || props.min)} min={props.min} max={props.max} step={props.step || 1} diff --git a/frontend/app/views/tile/components/tile.form.js b/frontend/app/views/tile/components/tile.form.js index 6a65194..372cd1d 100644 --- a/frontend/app/views/tile/components/tile.form.js +++ b/frontend/app/views/tile/components/tile.form.js @@ -16,198 +16,36 @@ import { preloadImage, preloadVideo } from 'app/utils' import * as pageActions from 'app/views/page/page.actions' import * as tileActions from 'app/views/tile/tile.actions' -const SELECT_TYPES = [ - "image", "text", "video", "link", "gradient", "script", -].map(s => ({ name: s, label: s })) - -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('_', ' ') - })) - -const REQUIRED_KEYS = { - image: ['url'], - video: ['url'], - text: ['content'], - link: [], - gradient: [], - script: [], -} - -const IMAGE_TILE_STYLES = [ - 'tile', 'cover', 'contain', 'contain no-repeat' -].map(style => ({ name: style, label: style })) - -const VIDEO_STYLES = [ - 'normal', 'cover', 'contain', -].map(style => ({ name: style, label: style })) - -const TEXT_FONT_FAMILIES = [ - 'sans-serif', 'serif', 'fantasy', 'monospace', 'cursive', -].map(style => ({ name: style, label: style })) - -const TEXT_FONT_STYLES = [ - 'normal', 'bold', 'italic', 'bold-italic', -].map(style => ({ name: style, label: style })) - -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', }, -] +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/views/tile/forms/tile.constants' -const UNITS = [ - { name: 'px', label: 'pixels' }, - { name: '%', label: 'percent' }, - { name: 'video', label: 'video' }, - { name: 'vmin', label: 'screen min' }, - { name: 'vmax', label: 'screen max' }, -] +import { + TILE_CONSTRUCTORS, -const NO_LINK = 0 -const EXTERNAL_LINK = -1 -const OPEN_POPUP_LINK = -2 -const CLOSE_POPUP_LINK = -3 -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 }, -] + TileImageForm, + TileLinkForm, + TileTextForm, + TileGradientForm, + TileScriptForm, + TileVideoForm, -const NO_POPUP = 0 -const POPUP_LIST_TOP_OPTIONS = [ - { name: NO_POPUP, label: 'Select a popup group' }, - { name: -99, label: '──────────', disabled: true }, -] + TileHyperlinkForm, + TileMiscForm, + TileSoundForm, + TileTypeForm, +} from 'app/views/tile/forms' // target_page_id = Column(Integer, ForeignKey('page.id'), nullable=True) // https://s3.amazonaws.com/i.asdf.us/im/1c/gradient_gold1-SpringGreen1_1321159749.jpg -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, -}) - -const TYPE_CONSTRUCTORS = { - image: newImage, - video: newVideo, - text: newText, - link: newLink, - gradient: newGradient, - script: newScript, -} - class TileForm extends Component { state = { title: "", @@ -252,7 +90,7 @@ class TileForm extends Component { ] this.setState({ pageList, popupList }) if (isNew) { - const newTile = newGradient({ + const newTile = TILE_CONSTRUCTORS.image({ id: "new", graph_id: graph.show.res.id, page_id: page.show.res.id, @@ -292,7 +130,7 @@ class TileForm extends Component { handleTypeChange(type) { const { graph, page, temporaryTile } = this.props - let newTile = TYPE_CONSTRUCTORS[type]({ + let newTile = TILE_CONSTRUCTORS[type]({ id: temporaryTile.id, graph_id: temporaryTile.graph_id, page_id: temporaryTile.page_id, @@ -455,42 +293,31 @@ class TileForm extends Component { {'◁'}
-
- -
+ + {this.renderPositionInfo()} {temporaryTile.type === 'image' - ? this.renderImageForm() + ? : temporaryTile.type === 'video' - ? this.renderVideoForm() + ? : temporaryTile.type === 'text' - ? this.renderTextForm() + ? : temporaryTile.type === 'link' - ? this.renderLinkForm() + ? : temporaryTile.type === 'gradient' - ? this.renderGradientForm() + ? : temporaryTile.type === 'script' - ? this.renderScriptForm() + ? : ""} - {this.renderHyperlinkForm()} - {this.renderMiscForm()} - {this.renderAudioForm()} + + +
) } - - renderImageForm() { - // const { isNew } = this.props - const { temporaryTile } = this.props - const { errorFields } = this.state - // console.log(temporaryTile.settings) - return ( -
-
- {temporaryTile.settings.url &&
} - -
-
- - {temporaryTile.settings.is_tiled && - - -
-
- - -
- {!temporaryTile.settings.muted && ( - - )} - {temporaryTile.settings.loop && ( -
- -
- )} - {temporaryTile.settings.loop && temporaryTile.settings.loop_section && ( -
- - -
- )} -
- ) - } - - renderTextForm() { - const { temporaryTile } = this.props - const { errorFields } = this.state - return ( -
-