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

Feature/Ui view handle by Vue.js #678

Merged
merged 23 commits into from
Apr 4, 2019
Merged

Conversation

ibelar
Copy link
Contributor

@ibelar ibelar commented Mar 29, 2019

Implementation of Vue.js with Ui view.

  • Add vueService to atkjs-ui.js for handling creation of Vue component within atk4\ui;
  • Add two new view component:
    • InlineEdit for saving a simple field to db;
    • ItemSearch for searching into db and reloading a view.

Atkjs File name

  • Refactoring and standardizing atkjs-ui file name.

Demo in vue-composent.php

Screen Shot 2019-03-29 at 2 47 12 PM

@codecov
Copy link

codecov bot commented Mar 29, 2019

Codecov Report

Merging #678 into develop will increase coverage by 0.25%.
The diff coverage is 72.89%.

Impacted file tree graph

@@              Coverage Diff              @@
##             develop     #678      +/-   ##
=============================================
+ Coverage      72.69%   72.94%   +0.25%     
- Complexity      1870     1924      +54     
=============================================
  Files            102      105       +3     
  Lines           4421     4558     +137     
=============================================
+ Hits            3214     3325     +111     
- Misses          1207     1233      +26
Impacted Files Coverage Δ Complexity Δ
src/View.php 82.89% <100%> (+0.62%) 147 <5> (+5) ⬆️
src/jsVueService.php 100% <100%> (ø) 4 <4> (?)
src/Component/InlineEdit.php 52.54% <52.54%> (ø) 30 <30> (?)
src/Component/ItemSearch.php 96.42% <96.42%> (ø) 11 <11> (?)
src/FormField/Input.php 100% <0%> (ø) 33% <0%> (+2%) ⬆️
src/FormField/DropDown.php 91.17% <0%> (+0.26%) 31% <0%> (+1%) ⬆️
src/FormField/Upload.php 64.78% <0%> (+6.05%) 35% <0%> (+1%) ⬆️
... and 1 more

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 0b926ca...e24be24. Read the comment docs.

@codecov
Copy link

codecov bot commented Mar 29, 2019

Codecov Report

Merging #678 into develop will decrease coverage by 28.89%.
The diff coverage is 0%.

Impacted file tree graph

@@             Coverage Diff              @@
##             develop    #678      +/-   ##
============================================
- Coverage      72.69%   43.8%   -28.9%     
- Complexity      1870    1911      +41     
============================================
  Files            102     105       +3     
  Lines           4421    4639     +218     
============================================
- Hits            3214    2032    -1182     
- Misses          1207    2607    +1400
Impacted Files Coverage Δ Complexity Δ
src/jsVueService.php 0% <0%> (ø) 4 <4> (?)
src/Component/InlineEdit.php 0% <0%> (ø) 23 <23> (?)
src/Component/ItemSearch.php 0% <0%> (ø) 10 <10> (?)
src/AccordionSection.php 0% <0%> (-100%) 3% <0%> (ø)
src/HelloWorld.php 0% <0%> (-100%) 1% <0%> (ø)
src/Layout/Centered.php 0% <0%> (-100%) 1% <0%> (ø)
src/FormField/Radio.php 0% <0%> (-100%) 16% <0%> (ø)
src/FormField/Money.php 0% <0%> (-100%) 6% <0%> (ø)
src/Columns.php 0% <0%> (-100%) 10% <0%> (ø)
src/TableColumn/Password.php 0% <0%> (-100%) 1% <0%> (ø)
... and 77 more

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 0b926ca...4eceb65. Read the comment docs.

props: {
url: String,
initialValue: String,
id: Number,
Copy link
Member

Choose a reason for hiding this comment

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

i think ID should be a inside URL as a sticky get. The reasons are:

  • there may not be ID, we might want to edit something that has no ID, like "status" of a currently logged-in user.
  • ID is not something that component can change as it wishes.
  • If we introduce a special way to protect "get" arguments by signing them with limited-time token, this may not apply on "ID" and would require a separate protection.
  • similarly - form does not have "ID" as a separate get argument.

Copy link
Member

Choose a reason for hiding this comment

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

On other hand - perhaps we can pass OTHER arguments, for example if i have multiple inline fields on a page and i want them all to communicate with the same callback JS. Or ability to reference value of other field when submitting.

Perhaps the reason for ID field is so that we can use this component inside table, which would kinda justify the "ID" field. I'd prefer to have either "args" or nothing.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Id value was not mandatory and thought it could be good to have. I removed it.

@@ -1,4 +1,4 @@
import atkPlugin from 'plugins/atkPlugin';
import atkPlugin from './atk.plugin';
Copy link
Member

Choose a reason for hiding this comment

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

why atk is not is plugins ? I'm not saying to move it, just curious.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

not sure what you mean here. atk.plugin.js is the base class for all other plugins. ex: class ajaxec extends atkPlugin...

Copy link
Member

Choose a reason for hiding this comment

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

gotcha!


let atkComponents = {
'atk-inline-edit' : atkInlineEdit,
'atk-item-search' : itemSearch,
Copy link
Member

Choose a reason for hiding this comment

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

does this have to be populated for all new components? does not seem very universal.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Vue instance need to have it's component register when you created it. This is one way of doing it and it is ok for component that atk managed. For external component, there would be another way for registering them like the createVue method in Vue service.

Copy link
Member

Choose a reason for hiding this comment

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

ok

Copy link
Member

Choose a reason for hiding this comment

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

at some point if we have a vue create guide, should mention that then ;)

}

/**
* Created a Vue component and add it to the vues array.
Copy link
Member

Choose a reason for hiding this comment

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

description is unclear. Does that mean that other than those existing 2 components others would need to invoke this method to register themselves? is the name "createAtkVue" miss-leading? maybe not, just raising a question.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes. Component defined externally would have to use this method to create the Vue instance.

* @param event
* @param data
*/
emitEvent(event, data = {}) {
Copy link
Member

Choose a reason for hiding this comment

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

unclear what this does and how to use it. No doc or example.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This would allow for component define in seperate Vue instance to be able to talk to each other.
For example, I use this is saasty for updating the add-ons category when using the item-search component of the add-on market page. The button emit an event that tell the item-search component the category needed to include in it's query.
Been said, the mechanism is in place but I do not have proper use case yet to use it.

Copy link
Member

Choose a reason for hiding this comment

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

yes, but i mean - this need documentation.

*
* @return \atk4\ui\jsToast
*/
public function jsError($message)
Copy link
Member

Choose a reason for hiding this comment

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

is that consistent with $form->error() ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Update to use field validation in model.

*/
public function getQuery()
{
return $_GET['_q'] ? $_GET['_q'] : null;
Copy link
Member

Choose a reason for hiding this comment

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

what if multiple search fields present? can they be nested? wouldn't this conflict?

Copy link
Contributor Author

@ibelar ibelar Apr 2, 2019

Choose a reason for hiding this comment

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

Updated to accept multiple item search. Also doing via __atk_reload argument.

public function setModelCondition($m)
{
$q = $this->getQuery();
if ($q && ($_GET['__atk_reload'] ? $_GET['__atk_reload'] : null) === $this->reload->name) {
Copy link
Member

Choose a reason for hiding this comment

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

I think App should have a method for those magic get arguments. Like here: https://github.com/atk4/ui/blob/develop/src/App.php#L264

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is just to make sure we are setting up the model for the proper reload view.

$reloadId = $this->reload;
}

$this->js(true, (new jsVueService())->createAtkVue('#'.$this->name,
Copy link
Member

Choose a reason for hiding this comment

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

If VUE is built-in component of ATK, then this line should be simpler:

$this->vue('atk-item-search', ['reload'=>............... ]);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do you mean adding a vue method inside View class?

Copy link
Member

Choose a reason for hiding this comment

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

yes.

* Emit an event that other component can listen too.
* Allow Vue instances to talk to each other.
*
* This output js: atk.vueService.emitEvent("eventName", {});
Copy link
Member

Choose a reason for hiding this comment

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

no examples given.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No example to show yet. Will come later.

ibelar and others added 2 commits April 2, 2019 17:10
update to Romans comment.
fix minor issue.
@romaninsh
Copy link
Member

To be documented in #683

ibelar and others added 2 commits April 4, 2019 09:21
Updating initial prop variable name so it make more sense.
update method and comment accordingly
@ibelar
Copy link
Contributor Author

ibelar commented Apr 4, 2019

@romans - just push a quick update.
I changed the initial component variable name from "item" to "initData". Think this will reflect more the purpose of the variable. Prior name "item" was referring to the first item-search component we had in Saasty.

@romans
Copy link

romans commented Apr 4, 2019

Guys, stop mentioning me. Thanks! :)

@codecov
Copy link

codecov bot commented Apr 4, 2019

Codecov Report

Merging #678 into develop will increase coverage by 0.25%.
The diff coverage is 72.89%.

Impacted file tree graph

@@              Coverage Diff              @@
##             develop     #678      +/-   ##
=============================================
+ Coverage      72.69%   72.94%   +0.25%     
- Complexity      1870     1924      +54     
=============================================
  Files            102      105       +3     
  Lines           4421     4558     +137     
=============================================
+ Hits            3214     3325     +111     
- Misses          1207     1233      +26
Impacted Files Coverage Δ Complexity Δ
src/View.php 82.89% <100%> (+0.62%) 147 <5> (+5) ⬆️
src/jsVueService.php 100% <100%> (ø) 4 <4> (?)
src/Component/InlineEdit.php 52.54% <52.54%> (ø) 30 <30> (?)
src/Component/ItemSearch.php 96.42% <96.42%> (ø) 11 <11> (?)
src/FormField/Input.php 100% <0%> (ø) 33% <0%> (+2%) ⬆️
src/FormField/DropDown.php 91.17% <0%> (+0.26%) 31% <0%> (+1%) ⬆️
src/FormField/Upload.php 64.78% <0%> (+6.05%) 35% <0%> (+1%) ⬆️
... and 1 more

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 0b926ca...71b2827. Read the comment docs.

@romaninsh romaninsh merged commit 5848836 into develop Apr 4, 2019
@romaninsh romaninsh deleted the feature/vue-js-refactoring branch April 4, 2019 17:01
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.

3 participants