Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Load assets from remote storage #128

Closed
adrian1207 opened this issue Jun 27, 2017 · 8 comments
Closed

Load assets from remote storage #128

adrian1207 opened this issue Jun 27, 2017 · 8 comments

Comments

@adrian1207
Copy link

Hi, at first - thank you for this editor, its great and I will surely use it in many projects! :)

I have a problem with loading assets on init.

My storage configuration is:
storageManager: {
type: 'remote',
urlStore: '{!! url('admin/marketing/subscription/campaigns/store', [$model->id]) !!}',
urlLoad: '{!! url('admin/marketing/subscription/campaigns/load', [$model->id]) !!}',
contentTypeJson: true
}

My load function in PHP:

foreach((array)$entity->assets as $asset)
{
$assets[] = ['src' => File::find($asset)->getFullUrl(), 'type' => 'image'];
}
return response()->json(['gjs-html' => $entity->content, 'gjs-css' => $entity->styles, 'gjs-assets' => $assets]);

And Im returning this JSON from backend:

{"gjs-html":"SOME HTML", "gjs-css":"SOME CSS", "gjs-assets":[{"src":"http:\/\/edito.localhost\/storage\/image\/cms_subscription_campaigns\/2017\/6\/27\/4db7ee187e2798fe7828c88cc79e70af\/IMG_9489m.jpg","type":"image"}]}

In result, I have all HTML and CSS loaded in editor, but images (assets) component is still empty. How to return data from load function in backend to fill assets component with my files?

@artf
Copy link
Member

artf commented Jun 27, 2017

Hi @adrian1207 your JSON is correct, I think there is might be a bug with the Asset Manager loader. For a moment, as a workaround, I'd suggest loading assets via the main config:

...
assetManager: {
  assets: {!! $jsonAssets !!}
},

@artf artf added the bug label Jun 27, 2017
@artf artf closed this as completed in 56b4b2d Jun 30, 2017
@Chronis77
Copy link

Chronis77 commented Jul 5, 2017

Hi, I have got the latest version and I also seem to have nothing rendering.

The JSON that is being returned looks like this.

{"gjs-html":"<HTML>","gjs-assets":[{"src":"http:\/\/placehold.it\/350x250\/78c5d6\/fff\/image1.jpg","type":"image"},{"src":"http:\/\/placehold.it\/350x250\/78c5d6\/fff\/image2.jpg","type":"image"}]}

I have the latest version of Grapesjs: 0.9.4.

Maybe it is something with my configuration. When i try and load the images is asset manager it doesn't work either. The only way the asset manager works is if I change the storageManager type to 'local'.

My configuration looks like this:

var editor = grapesjs.init({
                    clearOnRender: true,
                   /* height: '100%',*/
                    storageManager: {
                      type: 'remote',
                      stepsBeforeSave: 5,
                      autoload: true,
                      autosave: true,
                      urlStore: '<?php echo Yii::app()->baseUrl . '/index.php/campaigns/'.$campaign->campaign_uid.'/push_campaign_template'; ?>',
                      urlLoad: '<?php echo Yii::app()->baseUrl . '/index.php/campaigns/'.$campaign->campaign_uid.'/pull_campaign_template'; ?>',
                      //control-dev.mailblaze.com/customer/index.php/campaigns/yy582mldbd38f/pull_campaign_template',
                      contentTypeJson: true,
                      params: {},   // For custom values on requests
                    },
                    assetManager: {
                      storageType      : '',
                      storeOnChange    : true,
                      storeAfterUpload  : true,        
                    },
                    container : '#gjs',
                    fromElement: true,

@artf
Copy link
Member

artf commented Jul 5, 2017

There is might be something wrong with the renderer, can you check if there are actually no assets

editor.AssetManager.getAll().length

Might help you setting some listener before rendering

var editor = grapesjs.init({
 autorender: 0,
 ...
});

editor.on('storage:load', function(obj) {
  console.log('Loaded ', obj);
})
editor.on('storage:store', function(obj) {
 console.log('Stored ', obj);
})

editor.AssetManager.getAll().on('reset change', function(asset){
  console.log('Assets changed', asset);
})

editor.render();

@artf artf reopened this Jul 5, 2017
@Chronis77
Copy link

See attached for the output.

capture

@artf
Copy link
Member

artf commented Jul 5, 2017

ah ok the loader, in asset manager, uses JSON.parse on any value 😁
will fix it for the next release

@Chronis77
Copy link

Thanks, any quick fix i can plug just for temporary testing purposes?

@artf
Copy link
Member

artf commented Jul 5, 2017

You should output your assets as an encoded JSON string

@artf artf closed this as completed in 5f5ba1a Jul 12, 2017
@lock
Copy link

lock bot commented Sep 18, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot added the outdated label Sep 18, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Sep 18, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants