Skip to content

[ZEPPELIN-697] Replace dynamic form with angular object from registry if exists#745

Closed
doanduyhai wants to merge 1 commit intoapache:masterfrom
doanduyhai:ZEPPELIN-697
Closed

[ZEPPELIN-697] Replace dynamic form with angular object from registry if exists#745
doanduyhai wants to merge 1 commit intoapache:masterfrom
doanduyhai:ZEPPELIN-697

Conversation

@doanduyhai
Copy link
Copy Markdown
Contributor

What is this PR for?

Replace dynamic form with angular object from registry if exists

I updated the Paragraph.jobRun() method to look for existing variable from the Angular Object Registry first before displaying the dynamic form.

We look for Angular object having same name:

  • first at paragraph scope (note id + paragraph id)
  • then at note scope (note id only)

I did not look at global scope because @Leemoonsoo was mentioning somewhere that we may likely remove the global scope some day

This is a sub-task of epic ZEPPELIN-635

What type of PR is it?

[Improvement]

Todos

  • - Code Review
  • - Simple Test

Is there a relevant Jira issue?

ZEPPELIN-697

How should this be tested?

  • git fetch origin pull/745/head:AngularObjectReplaceDynamicFormVar
  • git checkout AngularObjectReplaceDynamicFormVar
  • mvn clean package -DskipTests
  • bin/zeppelin-daemon.sh restart
  • Create a new note
  • In the first paragraph, put the following code
%angular

<form class="form-inline">
  <div class="form-group">
    <label for="superheroId">Super Hero: </label>
    <input type="text" class="form-control" id="superheroId" placeholder="Superhero name ..." ng-model="superhero"></input>
  </div>
  <button type="submit" class="btn btn-primary" ng-click="z.angularBind('superhero', superhero, 'PUT_HERE_PARAGRAPH_ID'); z.runParagraph('PUT_HERE_PARAGRAPH_ID')"> Bind</button>
    <button type="submit" class="btn btn-primary" ng-click="z.angularUnbind('superhero','PUT_HERE_PARAGRAPH_ID'); z.runParagraph('PUT_HERE_PARAGRAPH_ID')"> Unbind</button>
</form>
</form>
  • Create a second paragraph with the following code:
%md

### The superhero is : **${superhero}**
  • In the first paragraph, replace the text PUT_HERE_PARAGRAPH_ID by the paragraph id of the second paragraph
  • Execute first the second paragraph to see that the dynamic form system is working as usual
  • Now put Batman in the input text of the first paragraph and click alternatively on Bind to see that dynamic form in the second paragraph is removed
  • Click on Unbind to see that the dynamic form system is back

Screenshots (if appropriate)

replacedynamicform

Questions:

  • Does the licenses files need update? --> No
  • Is there breaking changes for older versions? --> Yes
  • Does this needs documentation? --> Yes

@doanduyhai
Copy link
Copy Markdown
Contributor Author

ping @Leemoonsoo for code review

@doanduyhai
Copy link
Copy Markdown
Contributor Author

ping @Leemoonsoo

@Leemoonsoo
Copy link
Copy Markdown
Member

The implementation itself looks good to me.

While this PR links 'dynamic form' and 'angular display system', I'd like to discuss little bit about the direction.

Zeppelin has 'dynamic form' and 'angular display system' for frontend - backend interaction.
And 'resource pool' for interpreter-interpreter interaction. I can summarize characteristics of these three, like

Dynamic Form Angular Display System ResourcePool
Propagate value to the font-end yes yes no
Persisted in note.json yes yes no
Trigger actions on change yes yes no
Store arbitrary java object no yes yes
Note / Paragraph scope no yes yes
Access value between interpreters no no yes

'Dynamic Form' and 'Angular Display System' are both does frontend-backend interaction.
'Angular Display System' and 'Resource pool' are both object store.

While they're sharing similar characteristics, do you see any possibilities of consolidate these 3 into 1?
If it is, how this PR can be aligned?

@doanduyhai
Copy link
Copy Markdown
Contributor Author

Hello @Leemoonsoo

Thank for raising question about the 3 types of variables.

My though is that Angular Variables should be merged/replaced by ResourcePool. Indeed the Angular Object scope is not very intuitive. It is first scoped by interpreter group then by note/paragraph.

Removing Angular Object to use Resource Pool is a good idea but there is still one pending issue: angular value watcher. As you know people can assign a watcher function in the back-end on Angular value. If we want to replace Angular objects by Resource Pool, we need to provide similar feature, unless you think we can completely drop this watcher feature ...

Another point to take into account is the migration path. For all people that have saved their notes as JSON with saved Angular objects, we need to handle the migration to Resource pool when the re-import those notes.

About the Dynamic Form system I don't think we should merge it with Angular Object/Resource Pool. Dynamic Form values are just an alias to automatically generate a form input. And the fact that its value change triggers the execution of the current paragraph can be implemented using z.runParagraph() Angular function that is now available.

All in all I think we should ultimately have enhanced Resource Pool and Dynamic Form only.

But those changes are very big and deserve another JIRA epic. For now, we can just implement this overriding system for this PR and then when we refactor the Angular JS to Resource Pool, we will merge the behavior together

WDYT ?

@Leemoonsoo
Copy link
Copy Markdown
Member

I agree, consolidate Angular Object / Resource Pool into Resource Pool really make sense. I think watcher also can be handled.
Also make sense Dynamic form doesn't really need to be consolidated.

I think the way how this links PR Resource Pool and Dynamic Form make sense and aligned with the future plan.

Thanks for the patch and sharing the idea. LGTM

@doanduyhai
Copy link
Copy Markdown
Contributor Author

@Leemoonsoo Merge if ok ? Next 2 PR will concentrate on keeping same paragraph Id when re-importing node from JSON and add comprehensive documentation for the new AngularJS z functions

@Leemoonsoo
Copy link
Copy Markdown
Member

Merge into master if there're no more discussions.

@asfgit asfgit closed this in 758abc6 Apr 12, 2016
onkarshedge pushed a commit to onkarshedge/incubator-zeppelin that referenced this pull request May 11, 2016
… if exists

### What is this PR for?
Replace dynamic form with angular object from registry if exists

I updated the `Paragraph.jobRun()` method to look for existing variable from the Angular Object Registry first before displaying the dynamic form.

We look for Angular object having same name:

* first at paragraph scope (note id + paragraph id)
* then at note scope (note id only)

I did not look at **global** scope because Leemoonsoo  was mentioning somewhere that we may likely remove the global scope some day

_This is a sub-task of epic **[ZEPPELIN-635]**_

### What type of PR is it?
[Improvement]

### Todos
* [ ] - Code Review
* [ ] - Simple Test

### Is there a relevant Jira issue?
**[ZEPPELIN-697]**

### How should this be tested?
* `git fetch origin pull/745/head:AngularObjectReplaceDynamicFormVar`
* `git checkout AngularObjectReplaceDynamicFormVar`
* `mvn clean package -DskipTests`
* `bin/zeppelin-daemon.sh restart`
* Create a new note
* In the first paragraph, put the following code

```html
%angular

<form class="form-inline">
  <div class="form-group">
    <label for="superheroId">Super Hero: </label>
    <input type="text" class="form-control" id="superheroId" placeholder="Superhero name ..." ng-model="superhero"></input>
  </div>
  <button type="submit" class="btn btn-primary" ng-click="z.angularBind('superhero', superhero, 'PUT_HERE_PARAGRAPH_ID'); z.runParagraph('PUT_HERE_PARAGRAPH_ID')"> Bind</button>
    <button type="submit" class="btn btn-primary" ng-click="z.angularUnbind('superhero','PUT_HERE_PARAGRAPH_ID'); z.runParagraph('PUT_HERE_PARAGRAPH_ID')"> Unbind</button>
</form>
</form>
```
* Create a second paragraph with the following code:
```scala
%md

### The superhero is : **${superhero}**
```
* In the first paragraph, replace the text PUT_HERE_PARAGRAPH_ID by the paragraph id of the second paragraph
* Execute first the second paragraph to see that the dynamic form system is working as usual
* Now put **Batman** in the input text of the first paragraph and click alternatively on **Bind** to see that dynamic form in the second paragraph is removed
* Click on **Unbind** to see that the dynamic form system is back

### Screenshots (if appropriate)
![replacedynamicform](https://cloud.githubusercontent.com/assets/1532977/14233999/34ea658a-f9d8-11e5-875d-da04dd5d0a9b.gif)

### Questions:
* Does the licenses files need update? --> **No**
* Is there breaking changes for older versions? --> **Yes**
* Does this needs documentation? --> **Yes**

[ZEPPELIN-635]: https://issues.apache.org/jira/browse/ZEPPELIN-635
[ZEPPELIN-697]: https://issues.apache.org/jira/browse/ZEPPELIN-697

Author: DuyHai DOAN <[email protected]>

Closes apache#745 from doanduyhai/ZEPPELIN-697 and squashes the following commits:

be4dbd1 [DuyHai DOAN] [ZEPPELIN-697] Replace dynamic form with angular object from registry if exists
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.

2 participants