F5 Test changes
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
#= require ace/ace
|
||||
#= require ace/theme-monokai
|
||||
#= require ace/mode-coffee
|
||||
#= require ace/mode-xml
|
||||
#= require_tree .
|
||||
#= require_self
|
||||
#$ ->
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
window.formatXml = (xml) ->
|
||||
formatted = ''
|
||||
reg = /(>)(<)(\/*)/g
|
||||
xml = xml.replace(reg, '$1\r\n$2$3')
|
||||
pad = 0
|
||||
jQuery.each xml.split('\r\n'), (index, node) ->
|
||||
indent = 0
|
||||
if node.match(/.+<\/\w[^>]*>$/)
|
||||
indent = 0
|
||||
else if node.match(/^<\/\w/)
|
||||
if pad != 0
|
||||
pad -= 1
|
||||
else if node.match(/^<\w[^>]*[^\/]>.*$/)
|
||||
indent = 1
|
||||
else
|
||||
indent = 0
|
||||
padding = ''
|
||||
i = 0
|
||||
while i < pad
|
||||
padding += ' '
|
||||
i++
|
||||
formatted += padding + node + '\r\n'
|
||||
pad += indent
|
||||
return
|
||||
formatted
|
||||
window.squashXml = (xml)->
|
||||
result = xml
|
||||
.trim()
|
||||
.replace(/^\s+/g, '')
|
||||
.replace(/\s+$/g, '')
|
||||
.replace(/>(?:\r\n|\r|\n)/g, '')
|
||||
.replace(/(?:\r\n|\r|\n)/g, ' ')
|
||||
result
|
||||
@@ -1,43 +1,76 @@
|
||||
class SvgElementClass
|
||||
setup: (container)->
|
||||
if container
|
||||
@text_field = container.find('.snap-code-editor')
|
||||
else
|
||||
@text_field = $('.snap-code-editor')
|
||||
@text_field.change => @compileSource()
|
||||
target = @text_field.data('target')
|
||||
@target = target
|
||||
setup: (context=$(document))->
|
||||
#@setupSnapCode(context)
|
||||
@svg_source = context.find('#svg_element_svg')
|
||||
@preview_target = context.find('#svg-preview').css('border', '1px solid black')
|
||||
@original_svg = @svg_source.val()
|
||||
container = @
|
||||
ace_div = $('<div></div>').attr('id', 'ace-div').html @text_field.val()
|
||||
@input_type_select = context.find('#svg_element_input_type').change ->
|
||||
switch $(@).val()
|
||||
when 'snap_code'
|
||||
container.setupSnapCode(context)
|
||||
else
|
||||
container.setupSvgEdit(context)
|
||||
.change()
|
||||
setupSvgEdit: (context)->
|
||||
@svg_source.val @original_svg #reset svg value
|
||||
$('#snap-code-ace-div').remove()
|
||||
container = @
|
||||
ace_div = $('<div></div>').attr('id', 'raw-svg-ace-div')
|
||||
ace_div.css
|
||||
width: '100%'
|
||||
height: '500px'
|
||||
@text_field.after(ace_div)
|
||||
@svg_source.after(ace_div)
|
||||
@editor = ace.edit('raw-svg-ace-div')
|
||||
@editor.setTheme 'ace/theme/monokai'
|
||||
@editor.getSession().setMode 'ace/mode/xml'
|
||||
@editor.setValue formatXml(@svg_source.val())
|
||||
@editor.getSession().on 'change', (e)=>
|
||||
result = @editor.getValue()
|
||||
@preview_target.html result
|
||||
@svg_source.val squashXml(result)
|
||||
# @svg_source.val(@editor.getValue()).change()
|
||||
#@svg_source.hide()
|
||||
window.editor = @editor
|
||||
|
||||
setupSnapCode: (context)->
|
||||
@snap_code_source = context.find('.snap-code-editor')
|
||||
@snap_code_source.change => @compileSource()
|
||||
#preview_target = @snap_code_source.data('previewTarget')
|
||||
#@preview_target = preview_target
|
||||
container = @
|
||||
ace_div = $('<div></div>').attr('id', 'snap-code-ace-div').html @snap_code_source.val()
|
||||
ace_div.css
|
||||
width: '100%'
|
||||
height: '500px'
|
||||
@snap_code_source.after(ace_div)
|
||||
|
||||
#ACE
|
||||
@editor = ace.edit('ace-div')
|
||||
@editor = ace.edit('snap-code-ace-div')
|
||||
@editor.setTheme 'ace/theme/monokai'
|
||||
@editor.getSession().setMode 'ace/mode/coffee'
|
||||
@editor.getSession().on 'change', (e)=>
|
||||
@text_field.val(@editor.getValue()).change()
|
||||
@text_field.hide()
|
||||
@snap_code_source.val(@editor.getValue()).change()
|
||||
@snap_code_source.hide()
|
||||
|
||||
@svg_code_field = $('#svg_element_svg')
|
||||
$(target).on "DOMSubtreeModified", =>
|
||||
@svg_code_field.val $(target).html()
|
||||
@preview_target.on "DOMSubtreeModified", => # In image editing in debug mode????
|
||||
@svg_code_field.val @preview_target.html()
|
||||
|
||||
@box_width = $('#svg_element_box_width')
|
||||
@box_height = $('#svg_element_box_height')
|
||||
@dpm = $('#svg_element_dpm')
|
||||
|
||||
@box_width.change(->
|
||||
$(target).attr 'width', $(@).val()
|
||||
@box_width.change ->
|
||||
container.preview_target.attr 'width', $(@).val()
|
||||
container.compileSource()
|
||||
).change()
|
||||
@box_height.change(->
|
||||
$(target).attr 'height', $(@).val()
|
||||
.change()
|
||||
|
||||
@box_height.change ->
|
||||
container.preview_target.attr 'height', $(@).val()
|
||||
container.compileSource()
|
||||
).change()
|
||||
.change()
|
||||
|
||||
@dpm.change(->
|
||||
return unless dpm = $(@).val()
|
||||
if pheight = container.box_height.val()
|
||||
@@ -49,11 +82,11 @@ class SvgElementClass
|
||||
$('.box_width .attribute-info').html "#{width} <i>m</i>"
|
||||
|
||||
).change()
|
||||
$(target).css('border', '1px solid black')
|
||||
@compileSource()
|
||||
compileSource: ->
|
||||
return unless source = @text_field.val()
|
||||
results = $(@text_field.data('preview'))
|
||||
return unless source = @snap_code_source.val()
|
||||
#results = $(@snap_code_source.data('preview'))
|
||||
results = @preview_target
|
||||
window.compiledJS = ''
|
||||
try
|
||||
window.compiledJS = CoffeeScript.compile source, bare: on
|
||||
@@ -63,11 +96,11 @@ class SvgElementClass
|
||||
else
|
||||
results.text(window.compiledJS)
|
||||
results.removeClass 'error'
|
||||
window.evaluator = new SnapDsl(window.compiledJS, target: @target, width: @box_width.val(), height: @box_height.val())
|
||||
window.evaluator = new SnapDsl(window.compiledJS, target: @preview_target, width: @box_width.val(), height: @box_height.val())
|
||||
evaluator.result()
|
||||
$('.minibutton.run').removeClass 'error'
|
||||
catch {location, message}
|
||||
if location?
|
||||
if location
|
||||
message = "Error on line #{location.first_line + 1}: #{message}"
|
||||
results.text(message).addClass 'error'
|
||||
$('.minibutton.run').addClass 'error'
|
||||
@@ -75,12 +108,12 @@ class SnapDsl
|
||||
constructor: (code, options = {})->
|
||||
@js_code = code
|
||||
@options = options
|
||||
@t = $(options.target)
|
||||
@t = options.target
|
||||
@width = options.width
|
||||
@height = options.height
|
||||
$(options.target).html('')
|
||||
result: ->
|
||||
@snap = Snap(@options.target)
|
||||
@snap = Snap(@t[0])
|
||||
s = @snap
|
||||
try
|
||||
eval @js_code
|
||||
|
||||
@@ -5,4 +5,7 @@ App.QrCodesLinkComponent = Ember.Component.extend
|
||||
attributeBindings: ['href', 'target']
|
||||
href: Ember.computed 'section.id', 'table.id', ->
|
||||
Routes.qr_codes_suppliers_tables_path(section_id: @get('section.id'), table_id: @get('table.id'))
|
||||
click: ->
|
||||
# Somehow this is needed for within the actions menu
|
||||
@$().click()
|
||||
|
||||
|
||||
@@ -3,12 +3,9 @@ App.SectionElementComponent = Ember.Component.extend DragNDrop.Draggable,
|
||||
classNames: ['section-element-container']
|
||||
attributeBindings: ['style']
|
||||
show_handles: false
|
||||
classNameBindings: [
|
||||
'uniqueClass'
|
||||
]
|
||||
uniqueClass: (->
|
||||
"section-element-#{@get('section_element.id')}"
|
||||
).property('section_element.id')
|
||||
spinning: false
|
||||
classNameBindings: ['uniqueClass', 'spinning:spin-rotate']
|
||||
uniqueClass: Ember.computed 'section_element.id', -> "section-element-#{@get('section_element.id')}"
|
||||
draggable: Ember.computed.alias 'section.editmode'
|
||||
offsetX: (->
|
||||
(@get('dpm') || 0) * (@get('section_element.position_x') || 0)
|
||||
@@ -30,7 +27,12 @@ App.SectionElementComponent = Ember.Component.extend DragNDrop.Draggable,
|
||||
@get('section_element').setProperties
|
||||
position_x: position.left / dpm
|
||||
position_y: position.top / dpm
|
||||
click: -> @toggleProperty('show_handles') if @get('section.editmode')
|
||||
click: ->
|
||||
if @get('section.editmode')
|
||||
@toggleProperty('show_handles')
|
||||
else
|
||||
@set 'spinning', true
|
||||
Ember.run.later (=> @set('spinning', false)), 2000
|
||||
showHandles: Ember.computed.and 'show_handles', 'section.editmode'
|
||||
actions:
|
||||
rotateLeft: ->
|
||||
|
||||
@@ -1257,4 +1257,3 @@ $button-edit-color: #ffa
|
||||
$button-destroy-color: #faa
|
||||
$button-submit-color: $primary-color
|
||||
$button-cancel-color: $secondary-color
|
||||
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
.spin-rotate
|
||||
+animation(spinRotate 2s)
|
||||
+keyframes(spinRotate)
|
||||
from
|
||||
transform: rotate(0deg)
|
||||
to
|
||||
transform: rotate(360deg)
|
||||
@@ -4,6 +4,7 @@ class SvgElement
|
||||
include SvgElementDefaults
|
||||
property :snap_code
|
||||
property :active, type: :boolean, default: true
|
||||
property :input_type # %w[raw snap_code]
|
||||
has_many :section_elements
|
||||
|
||||
def self.active
|
||||
|
||||
@@ -8,6 +8,9 @@
|
||||
= f.row :active
|
||||
.form-label= f.label :active
|
||||
.form-field= f.check_box :active
|
||||
= f.row :input_type
|
||||
.form-label= f.label :input_type
|
||||
.form-field= f.select :input_type, %w[raw snap_code]
|
||||
= f.row :dpm
|
||||
.small-3.columns= f.label :dpm
|
||||
.small-3.columns= f.number_field :dpm, step: :any
|
||||
@@ -25,7 +28,7 @@
|
||||
.form-field.full= f.text_area :svg
|
||||
= f.row :snap_code
|
||||
.form-label= f.label :snap_code
|
||||
.row: .small-12.columns= f.text_area :snap_code, rows: 20, class: ['snap-code-editor'], data: {target: '#svg-preview', preview: '#javascript-preview'}
|
||||
.row: .small-12.columns= f.text_area :snap_code, rows: 20, class: ['snap-code-editor'], data: {preview_target: '#svg-preview', preview: '#javascript-preview'}
|
||||
.row: .small-12.columns: pre#javascript-preview.hide
|
||||
.form-actions
|
||||
= f.submit nil, class: 'form-submit-button'
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
- model_class = SvgElement
|
||||
- title :edit, model_class
|
||||
= render 'form'
|
||||
- content_for :page_links do
|
||||
ul
|
||||
li= link_to link_to_destroy_content(@svg_element), [:admin, @svg_element], method: :delete, confirm: are_you_sure(@svg_element), class: 'record-destroy-button'
|
||||
|
||||
@@ -9,11 +9,8 @@
|
||||
tbody
|
||||
- @svg_elements.each do |svg_element|
|
||||
tr
|
||||
td= link_to svg_element.name, [:admin, svg_element]
|
||||
td
|
||||
= link_to t('helpers.links.edit'), [:edit, :admin, svg_element], class: 'table-edit-button'
|
||||
'
|
||||
= link_to t("helpers.links.destroy"), [:admin, svg_element], method: :delete, data: {confirm: are_you_sure? }, class: 'table-destroy-button'
|
||||
td= link_to svg_element.name, [:edit, :admin, svg_element]
|
||||
= edit_td [:admin, svg_element]
|
||||
- else
|
||||
= no_content_given model_class
|
||||
/= link_to t("helpers.links.new"), new_admin_svg_element_path, class: 'record-new-button'
|
||||
|
||||
Reference in New Issue
Block a user