Skip to content

[ZEPPELIN-695] Add AngularJS z.runParagraph()#742

Closed
doanduyhai wants to merge 1 commit into
apache:masterfrom
doanduyhai:ZEPPELIN-695
Closed

[ZEPPELIN-695] Add AngularJS z.runParagraph()#742
doanduyhai wants to merge 1 commit into
apache:masterfrom
doanduyhai:ZEPPELIN-695

Conversation

@doanduyhai
Copy link
Copy Markdown
Contributor

What is this PR for?

Add AngularJS z.runParagraph() method

@corneadoug
On the client-side, inside the scope of a paragraph, we cannot access to the list of all existing paragraphs for the current note. In my previous implementation, I was using the following trick:

var paragraphDiv = angular.element('#' + paragraphId +
                                '_paragraphColumn_main[ng-controller="ParagraphCtrl"]');

var paragraph = paragraphDiv.scope().paragraph;

This is dirty and can be broken if we change the CSS style tomorrow for paragraph.

For the current implementation, what I did is to inject a reference to the note object into the $scope of paragraph so that we can access the current list of paragraph programmatically:

        $scope.$broadcast('updateParagraph', {
          note: $scope.note, // pass the note object to paragraph scope
          paragraph: note.paragraphs[index]});
  <div id="{{currentParagraph.id}}_paragraphColumn_main"
       ng-repeat="currentParagraph in note.paragraphs"
       ng-controller="ParagraphCtrl"
       ng-Init="init(currentParagraph, note)"

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-695

How should this be tested?

  • git fetch origin pull/742/head:AngularJSRunParagraph
  • git checkout AngularJSRunParagraph
  • 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="paragraphId">Paragraph Id: </label>
    <input type="text" class="form-control" id="paragraphId" placeholder="Paragraph Id ..." ng-model="paragraph"></input>
  </div>
  <button type="submit" class="btn btn-primary" ng-click="z.runParagraph(paragraph)"> Run Paragraph</button>
</form>
  • Create a second paragraph with the following code:
println("Date "+new java.util.Date().toString)
  • Retrieve the paragraph id of the 2nd paragraph
  • In the first paragraph, put the paragraph id in the input text and click on the Run Paragraph button, it should trigger execution of the second paragraph

Screenshots (if appropriate)

angularrunparagraph

Questions:

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

@doanduyhai
Copy link
Copy Markdown
Contributor Author

@Leemoonsoo

Just rebased from master, can be merged quickly, only JS code change

@Leemoonsoo
Copy link
Copy Markdown
Member

Tested and working well.

Do you mind add a test?
Like existing test for angular display system https://github.com/apache/incubator-zeppelin/blob/master/zeppelin-server/src/test/java/org/apache/zeppelin/integration/ZeppelinIT.java#L71. to make sure future front-end change doesn't break this new API.

@doanduyhai
Copy link
Copy Markdown
Contributor Author

@Leemoonsoo Done, I have added ZeppelinIT.testAngularRunParagraph(). The PR can be merged if no more remark/question

@Leemoonsoo
Copy link
Copy Markdown
Member

@doanduyhai Great. LGTM and merge if there're no more discussions.

@deepakas
Copy link
Copy Markdown

Is this feature going to available in 0.6 snapshot soon. I am using the click button example from the doc and z.run("20160326-184416_217725826" ) in click function. But for some reason the click works only once.

https://zeppelin.incubator.apache.org/docs/0.6.0-incubating-SNAPSHOT/displaysystem/angular.html

My code is here. https://github.com/deepakas/zeppelin-gallery/tree/master/wikigraphvis/notebook

@doanduyhai
Copy link
Copy Markdown
Contributor Author

@deepakas as soon as this PR will be merged, you can start playing with it by building the master yourself

@asfgit asfgit closed this in 140adb8 Mar 26, 2016
onkarshedge pushed a commit to onkarshedge/incubator-zeppelin that referenced this pull request May 11, 2016
### What is this PR for?
Add AngularJS `z.runParagraph()` method

corneadoug
On the client-side, inside the scope of a paragraph, we cannot access to the list of all existing paragraphs for the current note. In my previous implementation, I was using the following trick:

```
var paragraphDiv = angular.element('#' + paragraphId +
                                '_paragraphColumn_main[ng-controller="ParagraphCtrl"]');

var paragraph = paragraphDiv.scope().paragraph;
```

This is **dirty** and can be broken if we change the CSS style tomorrow for paragraph.

For the current implementation, what I did is to **inject** a reference to the `note` object into the `$scope` of paragraph so that we can access the current list of paragraph **programmatically**:

```javascript
        $scope.$broadcast('updateParagraph', {
          note: $scope.note, // pass the note object to paragraph scope
          paragraph: note.paragraphs[index]});
```

```html
  <div id="{{currentParagraph.id}}_paragraphColumn_main"
       ng-repeat="currentParagraph in note.paragraphs"
       ng-controller="ParagraphCtrl"
       ng-Init="init(currentParagraph, note)"
```

_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-695]**

### How should this be tested?
* `git fetch origin pull/742/head:AngularJSRunParagraph`
* `git checkout AngularJSRunParagraph`
* `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="paragraphId">Paragraph Id: </label>
    <input type="text" class="form-control" id="paragraphId" placeholder="Paragraph Id ..." ng-model="paragraph"></input>
  </div>
  <button type="submit" class="btn btn-primary" ng-click="z.runParagraph(paragraph)"> Run Paragraph</button>
</form>
```
* Create a second paragraph with the following code:

```scala
println("Date "+new java.util.Date().toString)
```
* Retrieve the paragraph id of the 2nd paragraph
* In the first paragraph, put the paragraph id in the input text and click on the **Run Paragraph** button, it should trigger execution of the second paragraph

### Screenshots (if appropriate)
![angularrunparagraph](https://cloud.githubusercontent.com/assets/1532977/13898909/ee3767bc-ede0-11e5-9996-79aa3b5c465c.gif)

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

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

Author: DuyHai DOAN <doanduyhai@gmail.com>

Closes apache#742 from doanduyhai/ZEPPELIN-695 and squashes the following commits:

cf0e6e4 [DuyHai DOAN] [ZEPPELIN-695] Add AngularJS z.runParagraph()
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