Skip to content

Commit 7afcf3e

Browse files
authored
[ZEPPELIN-2729] Paragraph numbering
### What is this PR for? Added a button on the top toolbar of the notebook to toggle paragraph numbering. It adds a "Paragraph N" on the top-right of each paragraph, mainly useful when collaborating and guiding others to the right place. ### What type of PR is it? Feature ### What is the Jira issue? [ZEPPELIN-2729](https://issues.apache.org/jira/browse/ZEPPELIN-2729) ### Screenshots [gfycat mp4 video](https://gfycat.com/LeafyAntiqueCrab) ### Questions: * Does the licenses files need update? no * Is there breaking changes for older versions? no * Does this needs documentation? no Closes #2782 from timovwb/paragraph-numbering. Signed-off-by: Jongyoul Lee <jongyoul@gmail.com>
1 parent e8422bc commit 7afcf3e

4 files changed

Lines changed: 57 additions & 0 deletions

File tree

zeppelin-web/src/app/notebook/notebook-actionBar.html

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,14 @@ <h3>
5151
ng-disabled="revisionView">
5252
<i ng-class="tableToggled ? 'fa icon-notebook' : 'fa icon-book-open'"></i>
5353
</button>
54+
<button type="button"
55+
class="btn btn-default btn-xs"
56+
ng-click="toggleAllNumbering()"
57+
ng-hide="viewOnly"
58+
tooltip-placement="bottom" uib-tooltip="Toggle paragraph numbering"
59+
ng-disabled="revisionView">
60+
<i class="fa fa-list-ol"></i>
61+
</button>
5462
<button type="button"
5563
class="btn btn-default btn-xs"
5664
ng-click="clearAllParagraphOutput(note.id)"

zeppelin-web/src/app/notebook/notebook.controller.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,22 @@ function NotebookCtrl($scope, $route, $routeParams, $location, $rootScope,
464464
$scope.$broadcast('closeTable');
465465
};
466466

467+
$scope.toggleAllNumbering = function () {
468+
if ($scope.note.config.numberingToggled) {
469+
$scope.$broadcast('setNumbering', false)
470+
} else {
471+
$scope.$broadcast('setNumbering', true)
472+
}
473+
$scope.note.config.numberingToggled = !$scope.note.config.numberingToggled
474+
$scope.setConfig()
475+
}
476+
477+
$scope.updateParagraphNumbering = function () {
478+
for (let i = 0; i < $scope.note.paragraphs.length; i++) {
479+
$scope.note.paragraphs[i].number = i + 1
480+
}
481+
}
482+
467483
/**
468484
* @returns {boolean} true if one more paragraphs are running. otherwise return false.
469485
*/
@@ -608,13 +624,15 @@ function NotebookCtrl($scope, $route, $routeParams, $location, $rootScope,
608624
return;
609625
}
610626
addPara(paragraph, index);
627+
$scope.updateParagraphNumbering();
611628
});
612629

613630
$scope.$on('removeParagraph', function(event, paragraphId) {
614631
if ($scope.paragraphUrl || $scope.revisionView === true) {
615632
return;
616633
}
617634
removePara(paragraphId);
635+
$scope.updateParagraphNumbering();
618636
});
619637

620638
$scope.$on('moveParagraph', function(event, paragraphId, newIdx) {
@@ -625,6 +643,7 @@ function NotebookCtrl($scope, $route, $routeParams, $location, $rootScope,
625643
if (removedPara && removedPara.length === 1) {
626644
addPara(removedPara[0], newIdx);
627645
}
646+
$scope.updateParagraphNumbering()
628647
});
629648

630649
$scope.$on('updateNote', function(event, name, config, info) {

zeppelin-web/src/app/notebook/paragraph/paragraph-control.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@
1313
-->
1414

1515
<div id="{{paragraph.id}}_control" class="control" ng-show="!asIframe">
16+
<span class="numbering"
17+
ng-if="paragraph.config.numbering">
18+
Paragraph<span ng-bind-html="paragraph.number"></span> |
19+
</span>
1620
<span>
1721
<span ng-show="paragraph.runtimeInfos.jobUrl.values.length == 1">
1822
<a href="{{paragraph.runtimeInfos.jobUrl.values[0].jobUrl}}" target="_blank" rel="noopener noreferrer" style="text-decoration: none;"

zeppelin-web/src/app/notebook/paragraph/paragraph.controller.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,8 @@ function ParagraphCtrl($scope, $rootScope, $route, $window, $routeParams, $locat
155155
noteVarShareService.put($scope.paragraph.id + '_paragraphScope', paragraphScope);
156156

157157
initializeDefault($scope.paragraph.config);
158+
159+
$scope.updateParagraphNumbering();
158160
};
159161

160162
$scope.$on('noteRunningStatus', function(event, status) {
@@ -177,6 +179,10 @@ function ParagraphCtrl($scope, $rootScope, $route, $window, $routeParams, $locat
177179
config.enabled = true;
178180
}
179181

182+
if (config.numbering === undefined) {
183+
config.numbering = $scope.note.config.numberingToggled
184+
}
185+
180186
for (let idx in forms) {
181187
if (forms[idx]) {
182188
if (forms[idx].options) {
@@ -643,6 +649,18 @@ function ParagraphCtrl($scope, $rootScope, $route, $window, $routeParams, $locat
643649
commitParagraph(paragraph);
644650
};
645651

652+
$scope.showNumbering = function(paragraph) {
653+
console.log('show numbering');
654+
paragraph.config.numbering = true;
655+
commitParagraph(paragraph);
656+
};
657+
658+
$scope.hideNumbering = function(paragraph) {
659+
console.log('hide numbering');
660+
paragraph.config.numbering = false;
661+
commitParagraph(paragraph);
662+
};
663+
646664
let openEditorAndCloseTable = function(paragraph) {
647665
manageEditorAndTableState(paragraph, false, true);
648666
};
@@ -1806,6 +1824,14 @@ function ParagraphCtrl($scope, $rootScope, $route, $window, $routeParams, $locat
18061824
$scope.closeTable($scope.paragraph);
18071825
});
18081826

1827+
$scope.$on('setNumbering', function(event, value) {
1828+
if (value) {
1829+
$scope.showNumbering($scope.paragraph)
1830+
} else {
1831+
$scope.hideNumbering($scope.paragraph)
1832+
}
1833+
});
1834+
18091835
$scope.$on('resultRendered', function(event, paragraphId) {
18101836
if ($scope.paragraph.id !== paragraphId) {
18111837
return;

0 commit comments

Comments
 (0)