Fix markup

This commit is contained in:
Anton Ignatov 2019-04-28 19:11:41 +02:00
parent 2847ec7609
commit f80d881847
17 changed files with 240 additions and 1339 deletions

View file

@ -1,158 +1,163 @@
var MarvinJsEditor = (function() {
/* global MarvinJSUtil, I18n, FilePreviewModal, tinymce, TinyMCE */
/* eslint-disable no-param-reassign */
/* eslint-disable wrap-iife */
var MarvinJsEditor = (function() {
var marvinJsModal = $('#MarvinJsModal');
var marvinJsContainer = $('#marvinjs-editor');
var marvinJsObject = $('#marvinjs-sketch');
var emptySketch = "<cml><MDocument></MDocument></cml>"
var sketchName = marvinJsModal.find('.file-name input')
var emptySketch = '<cml><MDocument></MDocument></cml>';
var sketchName = marvinJsModal.find('.file-name input');
var loadEditor = () => {
return MarvinJSUtil.getEditor('#marvinjs-sketch')
}
return MarvinJSUtil.getEditor('#marvinjs-sketch');
};
var loadPackages = () => {
return MarvinJSUtil.getPackage('#marvinjs-sketch')
}
return MarvinJSUtil.getPackage('#marvinjs-sketch');
};
function preloadActions(config) {
if (config.mode === 'new' || config.mode === 'new-tinymce'){
if (config.mode === 'new' || config.mode === 'new-tinymce') {
loadEditor().then(function(sketcherInstance) {
sketcherInstance.importStructure("mrv",emptySketch)
sketchName.val(I18n.t('marvinjs.new_sketch'))
})
}else if (config.mode === 'edit'){
sketcherInstance.importStructure('mrv', emptySketch);
sketchName.val(I18n.t('marvinjs.new_sketch'));
});
} else if (config.mode === 'edit') {
loadEditor().then(function(sketcherInstance) {
sketcherInstance.importStructure("mrv",config.data)
sketchName.val(config.name)
})
}else if (config.mode === 'edit-tinymce'){
sketcherInstance.importStructure('mrv', config.data);
sketchName.val(config.name);
});
} else if (config.mode === 'edit-tinymce') {
loadEditor().then(function(sketcherInstance) {
$.get(config.marvinUrl,function(result){
sketcherInstance.importStructure("mrv",result.description)
sketchName.val(result.name)
})
})
$.get(config.marvinUrl, function(result) {
sketcherInstance.importStructure('mrv', result.description);
sketchName.val(result.name);
});
});
}
}
function createExporter(marvin,imageType) {
var inputFormat = "mrv";
function createExporter(marvin, imageType) {
var inputFormat = 'mrv';
var settings = {
'width' : 900,
'height' : 900
width: 900,
height: 900
};
var params = {
'imageType': imageType,
'settings': settings,
'inputFormat': inputFormat
}
imageType: imageType,
settings: settings,
inputFormat: inputFormat
};
return new marvin.ImageExporter(params);
}
function assignImage(target,data){
target.attr('src',data)
return data
function assignImage(target, data) {
target.attr('src', data);
return data;
}
function TinyMceBuildHTML(json) {
var imgstr = "<img src='" + json.image.url + "'";
imgstr += " data-mce-token='" + json.image.token + "'";
imgstr += " data-source-id='" + json.image.source_id + "'";
imgstr += " data-source-type='" + json.image.source_type + "'";
imgstr += " alt='description-" + json.image.token + "' />";
return imgstr;
}
return Object.freeze({
open: function(config) {
preloadActions(config)
preloadActions(config);
$(marvinJsModal).modal('show');
$(marvinJsObject)
.css('width', marvinJsContainer.width() + 'px')
.css('height', marvinJsContainer.height() + 'px')
.css('height', marvinJsContainer.height() + 'px');
marvinJsModal.find('.file-save-link').off('click').on('click', () => {
if (config.mode === 'new'){
MarvinJsEditor().save(config)
} else if (config.mode === 'edit'){
MarvinJsEditor().update(config)
} else if (config.mode === 'new-tinymce'){
config.objectType = 'TinyMceAsset'
MarvinJsEditor().save_with_image(config)
} else if (config.mode === 'edit-tinymce'){
MarvinJsEditor().update_tinymce(config)
if (config.mode === 'new') {
MarvinJsEditor().save(config);
} else if (config.mode === 'edit') {
MarvinJsEditor().update(config);
} else if (config.mode === 'new-tinymce') {
config.objectType = 'TinyMceAsset';
MarvinJsEditor().save_with_image(config);
} else if (config.mode === 'edit-tinymce') {
MarvinJsEditor().update_tinymce(config);
}
})
});
},
initNewButton: function(selector) {
$(selector).off('click').on('click', function(){
$(selector).off('click').on('click', function() {
var objectId = this.dataset.objectId;
var objectType = this.dataset.objectType;
var marvinUrl = this.dataset.marvinUrl;
var container = this.dataset.sketchContainer
var container = this.dataset.sketchContainer;
MarvinJsEditor().open({
mode: 'new',
objectId: objectId,
objectType: objectType,
marvinUrl: marvinUrl,
container: container
})
})
});
});
},
save: function(config){
save: function(config) {
loadEditor().then(function(sketcherInstance) {
sketcherInstance.exportStructure("mrv").then(function(source) {
$.post(config.marvinUrl,{
sketcherInstance.exportStructure('mrv').then(function(source) {
$.post(config.marvinUrl, {
description: source,
object_id: config.objectId,
object_type: config.objectType,
name: sketchName.val()
}, function(result){
if (config.objectType === 'Step'){
new_asset = $(result.html)
new_asset.find('.file-preview-link').css('top','-300px')
new_asset.addClass('new').prependTo($(config.container))
setTimeout(function(){
new_asset.find('.file-preview-link').css('top','0px')
},200)
FilePreviewModal.init()
}, function(result) {
var newAsset;
if (config.objectType === 'Step') {
newAsset = $(result.html);
newAsset.find('.file-preview-link').css('top', '-300px');
newAsset.addClass('new').prependTo($(config.container));
setTimeout(function() {
newAsset.find('.file-preview-link').css('top', '0px');
}, 200);
FilePreviewModal.init();
}
$(marvinJsModal).modal('hide');
})
});
});
})
});
},
save_with_image: function(config){
save_with_image: function(config) {
loadEditor().then(function(sketcherInstance) {
sketcherInstance.exportStructure("mrv").then(function(mrv_description) {
loadPackages().then(function (sketcherPackage) {
sketcherInstance.exportStructure('mrv').then(function(mrvDescription) {
loadPackages().then(function(sketcherPackage) {
sketcherPackage.onReady(function() {
exporter = createExporter(sketcherPackage,'image/jpeg')
exporter.render(mrv_description).then(function(image){
$.post(config.marvinUrl,{
description: mrv_description,
var exporter = createExporter(sketcherPackage, 'image/jpeg');
exporter.render(mrvDescription).then(function(image) {
$.post(config.marvinUrl, {
description: mrvDescription,
object_id: config.objectId,
object_type: config.objectType,
name: sketchName.val(),
image: image
}, function(result){
}, function(result) {
var json = tinymce.util.JSON.parse(result);
config.editor.execCommand('mceInsertContent', false, TinyMceBuildHTML(json));
TinyMCE.updateImages(config.editor)
TinyMCE.updateImages(config.editor);
$(marvinJsModal).modal('hide');
})
});
});
});
});
});
})
});
},
update: function(config){
update: function(config) {
loadEditor().then(function(sketcherInstance) {
sketcherInstance.exportStructure("mrv").then(function(source) {
sketcherInstance.exportStructure('mrv').then(function(source) {
$.ajax({
url: config.marvinUrl,
data: {
@ -163,29 +168,29 @@ var MarvinJsEditor = (function() {
type: 'PUT',
success: function(json) {
$(marvinJsModal).modal('hide');
config.reloadImage.src.val(json.description)
$(config.reloadImage.sketch).find('.attachment-label').text(json.name)
config.reloadImage.src.val(json.description);
$(config.reloadImage.sketch).find('.attachment-label').text(json.name);
MarvinJsEditor().create_preview(
config.reloadImage.src,
config.reloadImage.src,
$(config.reloadImage.sketch).find('img')
)
);
}
});
});
})
});
},
update_tinymce: function(config){
update_tinymce: function(config) {
loadEditor().then(function(sketcherInstance) {
sketcherInstance.exportStructure("mrv").then(function(mrv_description) {
loadPackages().then(function (sketcherPackage) {
sketcherInstance.exportStructure('mrv').then(function(mrvDescription) {
loadPackages().then(function(sketcherPackage) {
sketcherPackage.onReady(function() {
exporter = createExporter(sketcherPackage,'image/jpeg')
exporter.render(mrv_description).then(function(image){
var exporter = createExporter(sketcherPackage, 'image/jpeg');
exporter.render(mrvDescription).then(function(image) {
$.ajax({
url: config.marvinUrl,
data: {
description: mrv_description,
description: mrvDescription,
name: sketchName.val(),
object_type: 'TinyMceAsset',
image: image
@ -193,8 +198,8 @@ var MarvinJsEditor = (function() {
dataType: 'json',
type: 'PUT',
success: function(json) {
config.image[0].src = json.url
config.saveButton.removeClass('hidden')
config.image[0].src = json.url;
config.saveButton.removeClass('hidden');
$(marvinJsModal).modal('hide');
}
});
@ -202,27 +207,27 @@ var MarvinJsEditor = (function() {
});
});
});
})
});
},
create_preview: function(source,target){
loadPackages().then(function (sketcherInstance) {
create_preview: function(source, target) {
loadPackages().then(function(sketcherInstance) {
sketcherInstance.onReady(function() {
exporter = createExporter(sketcherInstance,'image/jpeg')
sketch_config = source.val();
exporter.render(sketch_config).then(function(result){
assignImage(target,result)
var exporter = createExporter(sketcherInstance, 'image/jpeg');
var sketchConfig = source.val();
exporter.render(sketchConfig).then(function(result) {
assignImage(target, result);
});
});
});
},
create_download_link: function(source,link,filename){
loadPackages().then(function (sketcherInstance) {
create_download_link: function(source, link, filename) {
loadPackages().then(function(sketcherInstance) {
sketcherInstance.onReady(function() {
exporter = createExporter(sketcherInstance,'image/jpeg')
sketch_config = source.val();
exporter.render(sketch_config).then(function(result){
var exporter = createExporter(sketcherInstance, 'image/jpeg');
var sketchConfig = source.val();
exporter.render(sketchConfig).then(function(result) {
link.attr('href', result);
link.attr('download', filename);
});
@ -230,13 +235,13 @@ var MarvinJsEditor = (function() {
});
},
delete_sketch: function(url,object){
delete_sketch: function(url, object) {
$.ajax({
url: url,
dataType: 'json',
type: 'DELETE',
success: function(json) {
$(object).remove()
success: function() {
$(object).remove();
}
});
}
@ -249,15 +254,15 @@ var MarvinJsEditor = (function() {
tinymce.PluginManager.requireLangPack('MarvinJsPlugin');
tinymce.create('tinymce.plugins.MarvinJsPlugin', {
MarvinJsPlugin: function(ed, url) {
MarvinJsPlugin: function(ed) {
var editor = ed;
function openMarvinJs(){
function openMarvinJs() {
MarvinJsEditor().open({
mode: 'new-tinymce',
marvinUrl: '/marvin_js_assets',
editor: editor
})
});
}
// Add a button that opens a window
editor.addButton('marvinjsplugin', {

View file

@ -1,7 +1,8 @@
/* eslint no-underscore-dangle: ["error", { "allowAfterThis": true }]*/
/* eslint no-use-before-define: ["error", { "functions": false }]*/
/* eslint-disable no-underscore-dangle */
/* global Uint8Array fabric tui animateSpinner setupAssetsLoading I18n PerfectScrollbar*/
/* global Uint8Array fabric tui animateSpinner
setupAssetsLoading I18n PerfectScrollbar MarvinJsEditor */
//= require assets
var FilePreviewModal = (function() {
@ -21,11 +22,12 @@ var FilePreviewModal = (function() {
name = $(this).find('.attachment-label').text();
url = $(this).data('preview-url');
downloadUrl = $(this).attr('href');
if ($(this).data('asset-type') === 'marvin-sketch'){
openMarvinPrevieModal(name,$(this).find('#description'),this)
return true
if ($(this).data('asset-type') === 'marvin-sketch') {
openMarvinPrevieModal(name, $(this).find('#description'), this);
return true;
}
openPreviewModal(name, url, downloadUrl);
return true;
});
}
@ -425,7 +427,7 @@ var FilePreviewModal = (function() {
dataType: 'json',
success: function(data) {
var link = modal.find('.file-download-link');
clearPrevieModal()
clearPrevieModal();
if (Object.prototype.hasOwnProperty.call(data, 'wopi-controls')) {
modal.find('.file-wopi-controls').html(data['wopi-controls']);
}
@ -523,24 +525,25 @@ var FilePreviewModal = (function() {
});
}
function clearPrevieModal(){
function clearPrevieModal() {
var modal = $('#filePreviewModal');
modal.find('.file-preview-container').empty();
modal.find('.file-wopi-controls').empty();
modal.find('.file-edit-link').css('display', 'none');
}
function openMarvinPrevieModal(name,src,sketch){
function openMarvinPrevieModal(name, src, sketch) {
var modal = $('#filePreviewModal');
var link = modal.find('.file-download-link');
clearPrevieModal()
var target;
clearPrevieModal();
modal.modal('show')
modal.modal('show');
modal.find('.file-preview-container')
.append($('<img>').attr('src', '').attr('alt', ''));
target=modal.find('.file-preview-container').find('img')
MarvinJsEditor().create_preview(src,target)
MarvinJsEditor().create_download_link(src,link,name)
.append($('<img>').attr('src', '').attr('alt', ''));
target = modal.find('.file-preview-container').find('img');
MarvinJsEditor().create_preview(src, target);
MarvinJsEditor().create_download_link(src, link, name);
modal.find('.file-name').text(name);
if (!readOnly) {
@ -558,7 +561,7 @@ var FilePreviewModal = (function() {
src: src,
sketch: sketch
}
})
});
});
} else {
modal.find('.file-edit-link').css('display', 'none');

View file

@ -1,4 +1,4 @@
/* global _ hljs tinyMCE SmartAnnotation */
/* global _ hljs tinyMCE SmartAnnotation MarvinJsEditor */
/* eslint-disable no-unused-vars */
var TinyMCE = (function() {
@ -50,8 +50,8 @@ var TinyMCE = (function() {
$(selector).closest('form').find('.form-group')
.before('<div class="tinymce-placeholder" style="height:' + tinyMceInitSize + 'px"></div>');
tinyMceContainer.addClass('hidden');
plugins = 'autosave autoresize customimageuploader link advlist codesample autolink lists charmap hr anchor searchreplace wordcount visualblocks visualchars insertdatetime nonbreaking save directionality paste textcolor colorpicker textpattern'
if (typeof(MarvinJsEditor) !== 'undefined') plugins += ' marvinjsplugin'
plugins = 'autosave autoresize customimageuploader link advlist codesample autolink lists charmap hr anchor searchreplace wordcount visualblocks visualchars insertdatetime nonbreaking save directionality paste textcolor colorpicker textpattern';
if (typeof (MarvinJsEditor) !== 'undefined') plugins += ' marvinjsplugin';
tinyMCE.init({
cache_suffix: '?v=4.9.3', // This suffix should be changed any time library is updated
selector: selector,
@ -130,11 +130,11 @@ var TinyMCE = (function() {
],
init_instance_callback: function(editor) {
var editorForm = $(editor.getContainer()).closest('form');
var editorContainer = $(editor.getContainer())
var editorContainer = $(editor.getContainer());
var menuBar = editorForm.find('.mce-menubar.mce-toolbar.mce-first .mce-flow-layout');
var editorToolbar = editorForm.find('.mce-top-part');
var editorToolbaroffset = mceConfig.toolbar_offset || 120;
var editorIframe = $('#' + editor.id).prev().find('.mce-edit-area iframe')
var editorIframe = $('#' + editor.id).prev().find('.mce-edit-area iframe');
$('.tinymce-placeholder').css('height', $(editor.editorContainer).height() + 'px');
setTimeout(() => {
@ -168,43 +168,44 @@ var TinyMCE = (function() {
// Init image helpers
$('<div class="tinymce-active-object-handler" style="display:none">'
+'<a class="file-download-link tool-button" href="#" data-turbolinks="false"><i class="mce-ico mce-i-donwload"></i></a>'
+'<span class="file-edit-link tool-button" href="#" data-turbolinks="false"><i class="mce-ico mce-i-pencil"></i></span>'
+'</div>').appendTo(editorToolbar.find('.mce-stack-layout'))
editorIframe.contents().click(function(){
+ '<a class="file-download-link tool-button" href="#" data-turbolinks="false"><i class="mce-ico mce-i-donwload"></i></a>'
+ '<span class="file-edit-link tool-button" href="#" data-turbolinks="false"><i class="mce-ico mce-i-pencil"></i></span>'
+ '</div>').appendTo(editorToolbar.find('.mce-stack-layout'));
editorIframe.contents().click(function() {
var marvinJsEdit;
setTimeout(() => {
var image = editorIframe.contents().find('img[data-mce-selected="1"]')
var image = editorIframe.contents().find('img[data-mce-selected="1"]');
var editLink;
if (image.length > 0){
editorContainer.find('.tinymce-active-object-handler').css('display', 'block')
if (image.length > 0) {
editorContainer.find('.tinymce-active-object-handler').css('display', 'block');
editorContainer.find('.tinymce-active-object-handler .file-download-link')
.attr('href', image[0].src)
.attr('download', 'tinymce-image');
editLink = editorContainer.find('.tinymce-active-object-handler .file-edit-link')
editLink = editorContainer.find('.tinymce-active-object-handler .file-edit-link');
if (image[0].dataset.sourceId) {
editLink.css('display','inline-block')
var marvinJsEdit = (image[0].dataset.sourceType === 'MarvinJsAsset' && typeof(MarvinJsEditor) !== 'undefined')
if (!marvinJsEdit) editLink.css('display','none')
editLink.on('click', function(){
if (marvinJsEdit){
editLink.css('display', 'inline-block');
marvinJsEdit = (image[0].dataset.sourceType === 'MarvinJsAsset' && typeof (MarvinJsEditor) !== 'undefined');
if (!marvinJsEdit) editLink.css('display', 'none');
editLink.on('click', function() {
if (marvinJsEdit) {
MarvinJsEditor().open({
mode: 'edit-tinymce',
marvinUrl: '/marvin_js_assets/'+image[0].dataset.sourceId,
marvinUrl: '/marvin_js_assets/' + image[0].dataset.sourceId,
image: image,
saveButton: editorContainer.find('.tinymce-save-button')
})
});
}
})
});
} else {
editLink.css('display','none')
editLink.off('click')
editLink.css('display', 'none');
editLink.off('click');
}
}else{
editorContainer.find('.tinymce-active-object-handler').css('display', 'none')
} else {
editorContainer.find('.tinymce-active-object-handler').css('display', 'none');
}
},100)
})
}, 100);
});
// After save action
editorForm

View file

@ -1,3 +1,9 @@
// scss-lint:disable SelectorDepth
// scss-lint:disable NestingDepth
// scss-lint:disable SelectorFormat
// scss-lint:disable ImportantRule
// scss-lint:disable IdSelector
@import "constants";
@import "mixins";
@ -25,7 +31,6 @@
.modal-content {
background: transparent;
border: 0;
-webkit-box-shadow: none;
box-shadow: none;
color: $color-white;
height: 100%;
@ -48,7 +53,7 @@
height: 40px;
outline: 0;
padding: 5px 10px;
position:relative;
position: relative;
top: -5px;
width: 350px;
}
@ -60,15 +65,15 @@
padding: 0;
#marvinjs-editor {
width: 100%;
height: 100%;
overflow: hidden;
position: relative;
width: 100%;
#marvinjs-sketch {
overflow: hidden;
min-width: 500px;
min-height: 450px;
min-width: 500px;
overflow: hidden;
}
}
}
@ -82,19 +87,20 @@
}
}
#new-step-sketch{
#new-step-sketch {
.sketch-container {
width: 100%;
float:left;
display: grid;
float: left;
grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
width: 100%;
}
}
i.mce-i-file-invoice:before {
content: "\F570";
font-family: "Font Awesome 5 Free";
font-weight: 900;
position: absolute;
line-height: 16px
}
.mce-i-file-invoice::before {
content: "\F570";
font-family: "Font Awesome 5 Free";
font-weight: 900;
line-height: 16px;
position: absolute;
}

View file

@ -17,7 +17,7 @@
li {
margin-bottom: 10px;
& > div > span.pull-left {
> div > span.pull-left {
margin-top: 10px;
}
}
@ -106,7 +106,7 @@
order: 0 !important;
.file-preview-link {
transition: 0.5s;
transition: .5s;
}
.attachment-placeholder {
@ -114,10 +114,10 @@
&::before {
background: $brand-primary;
border-radius: 0px 5px 0px 5px;
border-radius: 0 5px;
bottom: 16px;
color: $color-white;
content: 'NEW';
content: "NEW";
left: 8px;
line-height: 20px;
position: absolute;
@ -274,8 +274,8 @@
line-height: 16px;
overflow: hidden;
padding: 2px 5px;
width: 100%;
pointer-events: none;
width: 100%;
&:focus {
outline: 0;

View file

@ -70,8 +70,8 @@
border: 1px solid transparent;
cursor: pointer;
display: inline-block;
margin: 2px;
line-height: 27px;
margin: 2px;
text-align: center;
width: 30px;
@ -80,21 +80,21 @@
}
}
i.mce-i-donwload:before {
.mce-i-donwload::before {
content: "\F019";
font-family: "Font Awesome 5 Free";
font-weight: 900;
line-height: 16px;
position: absolute;
line-height: 16px
}
i.mce-i-pencil:before {
.mce-i-pencil::before {
content: "\F303";
font-family: "Font Awesome 5 Free";
font-weight: 900;
line-height: 16px;
position: absolute;
line-height: 16px
}
}
}
// scss-lint:enable ImportantRule
// scss-lint:enable ImportantRule

View file

@ -2,20 +2,22 @@
class MarvinJsAssetsController < ApplicationController
def create
new_asset = MarvinJsAsset.add_sketch(marvin_params,current_team)
new_asset = MarvinJsAsset.add_sketch(marvin_params, current_team)
if new_asset.object_type == 'Step'
render json: {
html: render_to_string(
partial: 'assets/marvinjs/marvin_sketch_card.html.erb',
locals: { sketch: new_asset, i:0, assets_count: 0, step: new_asset.object}
)
html: render_to_string(
partial: 'assets/marvinjs/marvin_sketch_card.html.erb',
locals: { sketch: new_asset, i: 0, assets_count: 0, step: new_asset.object }
)
}
elsif new_asset.object_type == 'TinyMceAsset'
tiny_img = TinyMceAsset.find(new_asset.object_id)
render json: {
image: {
url: view_context.image_url(tiny_img.url(:large)),
token: Base62.encode(tiny_img.id)
token: Base62.encode(tiny_img.id),
source_id: new_asset.id,
source_type: new_asset.class.name
}
}, content_type: 'text/html'
else
@ -28,7 +30,7 @@ class MarvinJsAssetsController < ApplicationController
end
def destroy
sketch=MarvinJsAsset.find(params[:id])
sketch = MarvinJsAsset.find(params[:id])
sketch.destroy
render json: sketch
end
@ -40,7 +42,6 @@ class MarvinJsAssetsController < ApplicationController
private
def marvin_params
params.permit(:id,:description, :object_id, :object_type, :name, :image)
params.permit(:id, :description, :object_id, :object_type, :name, :image)
end
end

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
module MyModulesHelper
def ordered_step_of(my_module)
my_module.protocol.steps.order(:position)
@ -8,21 +10,21 @@ module MyModulesHelper
end
def ordered_assets(step)
assets=[]
assets = []
assets += step.assets
assets += step.marvin_js_assets if MarvinJsAsset.enabled?
assets.sort! { |a, b|
a[asset_date_sort_field(a)] <=> b[asset_date_sort_field(b)]
}
assets.sort! do |a, b|
a[asset_date_sort_field(a)] <=> b[asset_date_sort_field(b)]
end
end
def az_ordered_assets_index(step, asset_id)
assets=[]
assets = []
assets += step.assets
assets += step.marvin_js_assets if MarvinJsAsset.enabled?
assets.sort! { |a, b|
assets.sort! do |a, b|
(a[asset_name_sort_field(a)] || '').downcase <=> (b[asset_name_sort_field(b)] || '').downcase
}.pluck(:id).index(asset_id)
end.pluck(:id).index(asset_id)
end
def number_of_samples(my_module)
@ -45,29 +47,28 @@ module MyModulesHelper
end
def is_steps_page?
action_name == "steps"
action_name == 'steps'
end
def is_results_page?
action_name == "results"
action_name == 'results'
end
private
def asset_date_sort_field(el)
def asset_date_sort_field(element)
result = {
'Asset' => :file_updated_at,
'MarvinJsAsset' => :updated_at
}
result[el.class.name]
result[element.class.name]
end
def asset_name_sort_field(el)
def asset_name_sort_field(element)
result = {
'Asset' => :file_file_name,
'MarvinJsAsset' => :name
}
result[el.class.name]
result[element.class.name]
end
end

View file

@ -1,5 +1,6 @@
class MarvinJsAsset < ApplicationRecord
# frozen_string_literal: true
class MarvinJsAsset < ApplicationRecord
belongs_to :object, polymorphic: true,
optional: true,
inverse_of: :marvin_js_assets
@ -14,7 +15,7 @@ class MarvinJsAsset < ApplicationRecord
ENV['MARVINJS_URL'] != nil
end
def self.add_sketch(values,team)
def self.add_sketch(values, team)
if values[:object_type] == 'TinyMceAsset'
tiny_mce_img = TinyMceAsset.new(
object: nil,
@ -27,18 +28,17 @@ class MarvinJsAsset < ApplicationRecord
values[:object_id] = tiny_mce_img.id
end
create(values.merge({team_id: team.id}).except(:image))
create(values.merge(team_id: team.id).except(:image))
end
def self.update_sketch(values)
sketch=MarvinJsAsset.find(values[:id])
sketch.update(values.except(:image,:object_type,:id))
sketch = MarvinJsAsset.find(values[:id])
sketch.update(values.except(:image, :object_type, :id))
if values[:object_type] == 'TinyMceAsset'
image = TinyMceAsset.find(sketch.object_id)
image.update(image: values[:image])
return {url: image.url(:large)}
return { url: image.url(:large) }
end
return sketch
sketch
end
end

View file

@ -34,9 +34,9 @@ class Step < ApplicationRecord
dependent: :destroy
has_many :marvin_js_assets,
as: :object,
class_name: :MarvinJsAsset,
dependent: :destroy
as: :object,
class_name: :MarvinJsAsset,
dependent: :destroy
accepts_nested_attributes_for :checklists,
reject_if: :all_blank,

View file

@ -15,9 +15,9 @@ class TinyMceAsset < ApplicationRecord
optional: true
has_one :marvin_js_asset,
as: :object,
class_name: :MarvinJsAsset,
dependent: :destroy
as: :object,
class_name: :MarvinJsAsset,
dependent: :destroy
belongs_to :object, polymorphic: true,
optional: true,
@ -63,15 +63,15 @@ class TinyMceAsset < ApplicationRecord
tm_assets.each do |tm_asset|
asset_id = tm_asset.attr('data-mce-token')
new_asset_url = find_by_id(Base62.decode(asset_id))
if new_asset_url
assets_source = new_asset_url.source
if assets_source
tm_asset.set_attribute('data-source-id', assets_source.id)
tm_asset.set_attribute('data-source-type', assets_source.class.name)
end
tm_asset.attributes['src'].value = new_asset_url.url
tm_asset['class'] = 'img-responsive'
next unless new_asset_url
assets_source = new_asset_url.source
if assets_source
tm_asset.set_attribute('data-source-id', assets_source.id)
tm_asset.set_attribute('data-source-type', assets_source.class.name)
end
tm_asset.attributes['src'].value = new_asset_url.url
tm_asset['class'] = 'img-responsive'
end
description.css('body').inner_html.to_s
end

View file

@ -676,7 +676,7 @@ Rails.application.routes.draw do
end
end
resources :marvin_js_assets, only: [:create, :update, :destroy, :show]
resources :marvin_js_assets, only: %i(create update destroy show)
post 'global_activities', to: 'global_activities#index'

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
class CreateMarvinJsAssets < ActiveRecord::Migration[5.1]
def change
create_table :marvin_js_assets do |t|

View file

@ -1,4 +1,5 @@
# frozen_string_literal: true
class AddNameToMarvinJsAssets < ActiveRecord::Migration[5.1]
def change
add_column :marvin_js_assets, :name, :string

File diff suppressed because it is too large Load diff

File diff suppressed because one or more lines are too long

View file

@ -1,5 +0,0 @@
require 'rails_helper'
RSpec.describe MarvinJsAsset, type: :model do
pending "add some examples to (or delete) #{__FILE__}"
end