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

Resolution configurable is now a Vue component #420

Merged
merged 33 commits into from
May 11, 2017

Conversation

martinRenou
Copy link
Member

No description provided.

@martinRenou martinRenou changed the title Resolution configurable is now a Vue component Resolution configurable is now a Vue component [WIP] May 4, 2017
@martinRenou martinRenou changed the title Resolution configurable is now a Vue component [WIP] Resolution configurable is now a Vue component May 4, 2017
@codecov-io
Copy link

codecov-io commented May 4, 2017

Codecov Report

Merging #420 into switch_to_vue will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@              Coverage Diff               @@
##           switch_to_vue     #420   +/-   ##
==============================================
  Coverage          95.33%   95.33%           
==============================================
  Files                 88       88           
  Lines               4077     4077           
  Branches             259      259           
==============================================
  Hits                3887     3887           
  Misses               138      138           
  Partials              52       52

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 109b522...daa9e2b. Read the comment docs.

"home/configurables"
], function (configurables) {
], function ($, configurables) {
Copy link
Contributor

Choose a reason for hiding this comment

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

if you can workaround jquery, try. otherwise keep it.

Copy link
Member Author

Choose a reason for hiding this comment

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

Here I use jQuery for the extend method which does a deep copy of the dictionary representing the model of the configurable. Underscore provides an extendmethod too but it doesn't do a deep copy of the dictionary.
Instead of returning a list of dictionaries representing the models of configurables in configurable.jsI could return a list of classes. So we get rid of this deep copy of dictionaries.

assert.equal(resolution.as_config_dict().resolution, "1024x768");
});

QUnit.test("view", function (assert) {
Copy link
Contributor

Choose a reason for hiding this comment

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

in principle you can still use the view on a configurable component.


data: function() {
return {
sel_value: this.value,
Copy link
Contributor

Choose a reason for hiding this comment

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

selected_value

template:
'<div class="form-group">' +
' <label>Resolution</label>' +
' <select class="form-control" v-model="sel_value">' +
Copy link
Contributor

Choose a reason for hiding this comment

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

call it selected_value

' <fieldset v-else :disabled="current_app.is_starting()">' +
' <component v-for="configurable in current_app.configurables"' +
' :is="configurable.tag"' +
' :value="configurable.value"' +
Copy link
Contributor

Choose a reason for hiding this comment

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

sync

Copy link
Member Author

Choose a reason for hiding this comment

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

The .syncdoesn't work like expected... The child selected_value is not correctly synchronized with the parent value.

'{{/each}}' +
'</div>'
);
var resolution_tag = 'resolution';
Copy link
Contributor

Choose a reason for hiding this comment

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

Vue recommends to use a hyphen.

Copy link
Contributor

Choose a reason for hiding this comment

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

maybe resolution-component?

Copy link
Contributor

Choose a reason for hiding this comment

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

make sure that you use reasonable differentiation between the configurable tag (e.g. "resolution") and the component tag (which is e.g. "resolution-component")


if (ConfigurableCls !== null) {
app.configurables.push(new ConfigurableCls());
if (configurable !== null) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it's undefined, not null, if you have an element that is not there.

@martinRenou martinRenou changed the title Resolution configurable is now a Vue component Resolution configurable is now a Vue component [WIP] May 5, 2017
@martinRenou martinRenou changed the title Resolution configurable is now a Vue component [WIP] Resolution configurable is now a Vue component May 8, 2017
});

// Your configurable class must implement tag and value attributes and as_config_dict method
var resolution_model = function() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Should be ResolutionModel (as a class)

Copy link
Contributor

Choose a reason for hiding this comment

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

which brings me to: do we really need it? I mean, technically, we could

  • have only the component.
  • have a component method as_config_dict that extracts the data from the component.
  • have the parent call this method when submit is called, aggregate all responses, and send them as part of the request

Copy link
Member Author

@martinRenou martinRenou May 8, 2017

Choose a reason for hiding this comment

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

I totally agree with this, that's what I wanted to do first. But I faced some problems with this implementation:

  • How to call the as_config_dict method from the parent ? The parent here is ApplicationView and we won't have access to the child component and this method in the Javascript code, as far as I understand.
  • Where to define the value of resolution of each application if not in a model object ?

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
Member Author

Choose a reason for hiding this comment

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

Ok, great thank you :) So with this I can define as_config_dict directly in the component.
We still have the issue of defining a value associated to each application, do you have any idea ?

' <fieldset v-else :disabled="current_app.is_starting()">' +
' <component v-for="configurable in current_app.configurables"' +
' :is="configurable.tag + \'-component\'"' +
' :value="configurable.value"' +
Copy link
Contributor

Choose a reason for hiding this comment

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

you can use .sync in this case. it should work, we are using vue 2.3

Copy link
Member Author

@martinRenou martinRenou May 8, 2017

Choose a reason for hiding this comment

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

As I said in the other comment, I tried to use .sync but it didn't work. selected_value wasn't correctly synchronized with the parent's value. I'm not sure what was going on.

var ResolutionModel = function() {
this.tag = resolution_conf_tag;
this.value = 'Window';
this.component = resolution_component;
Copy link
Member Author

Choose a reason for hiding this comment

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

This line is only for the tests. It's really weird to have the component constructor in the model. I should change this.

Copy link
Member Author

Choose a reason for hiding this comment

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

By the way, I couldn't find a proper way to set the value for each application without creating a model.

@martinRenou martinRenou changed the title Resolution configurable is now a Vue component Resolution configurable is now a Vue component [WIP] May 8, 2017
@martinRenou martinRenou changed the title Resolution configurable is now a Vue component [WIP] Resolution configurable is now a Vue component May 8, 2017
var resolution_conf_tag = 'resolution';
var resolution_component = Vue.component(resolution_conf_tag + '-component', {
// Your configurable must have a "value" property
props: ['value'],
Copy link
Contributor

Choose a reason for hiding this comment

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

data?

Copy link
Contributor

Choose a reason for hiding this comment

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

config_dict ?


data: function() {
return {
selected_value: this.value,
Copy link
Contributor

Choose a reason for hiding this comment

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

data that you accept is a bundle that contains specific information for the internals of the ui.
so in this case you have to extract data["resolution"] and put it here as the value for this specific widget of the UI.

// Your configurable class must implement tag and value attributes
var ResolutionModel = function() {
this.tag = resolution_conf_tag;
this.value = 'Window';
Copy link
Contributor

Choose a reason for hiding this comment

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

this.data = {"resolution": "Window"}

if (configurables[conf].prototype.tag === tag) {
return configurables[conf];

return { resolution: { resolution: resolution } };
Copy link
Contributor

Choose a reason for hiding this comment

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

just return for consistency with data that you put in.

},

methods: {
as_config_dict: function() {
Copy link
Contributor

Choose a reason for hiding this comment

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

this should be in the model. All your interaction should be with the model, and the component is just a view that is inserted in the right place.

@@ -121,15 +121,15 @@ define([
// to its client-side model.
app.configurables = [];

app.app_data.image.configurables.forEach(function(tag) {
app.app_data.image.configurables.forEach(function(conf_name) {
Copy link
Contributor

Choose a reason for hiding this comment

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

should be tag

@martinRenou martinRenou merged commit 6dcf0a0 into switch_to_vue May 11, 2017
@martinRenou martinRenou deleted the configurables_components branch May 11, 2017 11:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants