-
Notifications
You must be signed in to change notification settings - Fork 8
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
Conversation
Just define a description of each configurable for each application.
And fixed the issue of config_dict not correctly set by default
Codecov Report
@@ 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.
|
"home/configurables" | ||
], function (configurables) { | ||
], function ($, configurables) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 extend
method 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.js
I 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) { |
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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">' + |
There was a problem hiding this comment.
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"' + |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sync
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The .sync
doesn't work like expected... The child selected_value
is not correctly synchronized with the parent value.
'{{/each}}' + | ||
'</div>' | ||
); | ||
var resolution_tag = 'resolution'; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe resolution-component?
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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.
}); | ||
|
||
// Your configurable class must implement tag and value attributes and as_config_dict method | ||
var resolution_model = function() { |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 isApplicationView
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 ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- https://vuejs.org/v2/guide/components.html#Child-Component-Refs
- each component uses a different data object. the parent does not need to know anything about the types of the children. It just needs to know that, once done, it will go through the list and invoke
as_config_dict
There was a problem hiding this comment.
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"' + |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
var resolution_conf_tag = 'resolution'; | ||
var resolution_component = Vue.component(resolution_conf_tag + '-component', { | ||
// Your configurable must have a "value" property | ||
props: ['value'], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
data?
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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'; |
There was a problem hiding this comment.
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 } }; |
There was a problem hiding this comment.
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() { |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should be tag
No description provided.