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

Adds asset file upload #11450

Merged
merged 52 commits into from Feb 8, 2017
Merged

Adds asset file upload #11450

merged 52 commits into from Feb 8, 2017

Conversation

javierarce
Copy link
Contributor

@javierarce javierarce commented Feb 3, 2017

fixes #11020

This PR enables the upload of assets using direct file upload (of single or multiple files) and also revamps the asset modal window adding tabs.

In addition of those changes, whenever a user uploads a custom asset, the input field of the Fill components shows a generic icon to indicate an image is being used as a marker.

screen shot 2017-02-03 at 14 46 46
screen shot 2017-02-03 at 14 46 58
screen shot 2017-02-03 at 14 47 08
screen shot 2017-02-03 at 14 47 17

How to do acceptance

  1. Enable the icon-styling flag.
  2. Create a map with some points
  3. Style them however you want
  • Select an asset from the quick list in the Fill component
  • Select an asset from the modal window
  • Upload an asset
  • Delete/Select All/Deselect all custom assets from the modal window
  • Upload assets (with a URL or using the file browser)

@xavijam
Copy link
Contributor

xavijam commented Feb 6, 2017

Hey, has any designer reviewed this @javierarce?

@xavijam
Copy link
Contributor

xavijam commented Feb 6, 2017

I can't comment it in the code, but maki icons, simple icons and pin icons disclaimers are not translated, appear in plain english. Do we agree with that?

Copy link
Contributor

@xavijam xavijam left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Basically small details, I'd like to pass the acceptance as well. Things that worry me:

  • One error state that only displays a console, let's add the error view please.
  • CSS discussion about keep using the old styles or break with the past and look to the future (@piensaenpixel).

@@ -21,6 +21,7 @@ module.exports = CoreView.extend({
desc: _t('components.error.default-desc')
}
);
this._template = this.options && this.options.template || baseTemplate;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this.options is always available under a Backbone View, so we don't need the first check.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I got an undefined error on the specs when I removed that check, I'm not sure why is not defined in this case :|

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We reviewed this together and found that this.options is not defined.

initialize: function (opts) {
checkAndBuildOpts(opts, REQUIRED_OPTS, this);

this._assets = this.options.assets;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it a collection? If so, I'd call it _assetsCollection, in order to be more specific.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or if it is an array, _assetsArray.

},

_initBinds: function () {
this._assets.bind('add change remove', this.render, this);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's try to use listenTo if possible (http://stackoverflow.com/questions/16823746/backbone-js-listento-vs-on). If not remember we need to add our add_related_model thing.

editable: this._editable,
assetsCount: this._assets.length,
selectedCount: selectedCount,
allSelected: selectedCount === this._assets.length
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If assets is a collection, size method is available.


_onClick: function (e) {
this.killEvent(e);
this.trigger('selected', this.model);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couldn't we set an attribute called selected within the model? With that, we could check the collection changes instead of passing a custom event to the parent.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or better, I'm checking that we control that with the state attribute. Do we need this event then?

Copy link
Contributor Author

@javierarce javierarce Feb 7, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that it a regular case, it would make total sense to use the model state. The reason for my decision is that changing the state of an asset in this particular case doesn't only imply the asset itself, but the state of other assets (and this changes if the shift key is pressed). In this case it made more sense to centralice the selection in a common place instead of having it separated in two different locations (view of the item and parent view)

}
},

_isLoading: function () {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've seen several times this function, shouldn't we move it within the proper model? Like a helper one. Same for the below one.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Refactored the upload-tab view to use the upload method from the main modal (assets-view.js)

}, this);

_.each(selectedAssets, function (asset) {
asset.destroy({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd not remove any asset until we have a response from the backend. Could we use here {wait: true} within the backbone destroy method.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I tried this at first, but I couldn't make it work using wait :/

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, talked with you and decided that the first approach was ok for this case (we wait until the deletion is complete and show the list again)

},

_onFetchAssetsError: function () {
console.log('Error');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should render an error message, not only a console.

@@ -62,6 +62,7 @@ module.exports = CoreView.extend({
name: 'file',
type: this.model.get('image') ? 'image' : 'text',
label: this.model.get('image') ? this.model.get('image') : _t('form-components.editors.fill.input-color.img'),
kind: this.model.get('kind') ? this.model.get('kind') : 'marker',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this.model.get('kind') || 'marker' ?

@@ -95,8 +96,16 @@ module.exports = CoreView.extend({
return false;
},

_activatedFlag: function () {
return this._userModel && this._userModel.featureEnabled('icon-styling');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel @matallo did something similar or I'm suffering a Dejavù??.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indeed! some lines below

it also checks wether _imageEnabled (this comes from editorAttrs at editor creation) as only points geometry have image enabled. I'm not sure if this applies here, too, but in any case the this._userModel && this._userModel.featureEnabled('icon-styling') part can be put in just one place

@javierarce
Copy link
Contributor Author

Hey, has any designer reviewed this @javierarce?

Not in staging, @xavijam. I'll deploy it somewhere so they can see it.

@@ -96,20 +96,16 @@ module.exports = CoreView.extend({
return false;
},

_activatedFlag: function () {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isn't it necessary anymore?

_onFetchAssetsError: function () {
console.log('Error');
_onFetchAssetsError: function (model, response) {
this.trigger('error', response);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤗

Copy link
Contributor

@xavijam xavijam left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's go to acceptance!

@javitonino
Copy link
Contributor

A couple of questions while I am still testing:

  • If I style using a custom uploaded icon, the fill component does not show the select icon in the layer view. Intended?
    screenshot_20170208_091544
  • Should this supports organization assets? They are not shown in the builder view now that it has tabs.

@xavijam
Copy link
Contributor

xavijam commented Feb 8, 2017

  1. Yes, intended, it is ok.
  2. Ticket is already created -> Enable the possibility to select an icon previously uploaded by the organization admin #11462.

@javitonino
Copy link
Contributor

javitonino commented Feb 8, 2017

I have tested:

  • Selecting icons from all pages in the icon modal
  • Uploading files from file and URL
  • Deleting files
  • Select and deselect all

Everything works awesome 👏

Only a couple design issues (designer hat on), at least on Firefox:

  1. Alignment changes by one pixel when the actions (select all, delete) in the upload tab are shown.
    screenshot_20170208_094448
    To reproduce, deselect all, stare at your screen, and select one icon in the "Your uploads" tab. You should see the icons move down a pixel.

  2. The actions are not consistent with other parts of the interface:

  • The Select/Deselect text is black (should be blue)
  • Both links are not underlined when hovered over
  • No "X items selected" (this probably doesn't make too much sense here)

For reference:
In org assets:
screenshot_20170208_095024
In builder modal:
screenshot_20170208_095049

They are minor, but I think they are legit.

@xavijam
Copy link
Contributor

xavijam commented Feb 8, 2017

Great, thanks for discovering that @javitonino. @urbanphes could you check those? Because you checked the feature in staging (in the name of the design team 💃).

@javierarce
Copy link
Contributor Author

javierarce commented Feb 8, 2017

Agree with the style of the link, sorry about that.

The number of selected items didn't appear in the design, so I'd handle that in a different ticket. And for the 1px issue, I'd open a new ticket.

To speed up the release of this feature, I'll take it and add the required class to fix the link style.

Thanks for the thorough review!

@javierarce
Copy link
Contributor Author

Styling classes added.

@javierarce
Copy link
Contributor Author

@javitonino did you tried enabling/disabling the feature flag?

@javitonino
Copy link
Contributor

Yep, there is only a small issue that if you activate it, apply a style with icons, deactivate the FF, the map keeps the icons but you cannot reset them from the style properties. But it is minor (you can reset using cartocss) and only when "downrgrading", so 👍

Everything is hidden when the FF is disabled, and everything works with it enabled ✨

@javierarce
Copy link
Contributor Author

Great, thanks! Promoting it to the next stage.

@javitonino javitonino merged commit d97accb into master Feb 8, 2017
@javitonino javitonino deleted the 11020-file-upload branch February 8, 2017 09:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add file upload support for the icon styling feature
4 participants