Skip to content
This repository was archived by the owner on Feb 9, 2020. It is now read-only.

Commit 0ba5f25

Browse files
gary-bSomeKittens
authored andcommitted
fix(jsonTree) show icons
The arrows indicating expanded / collapsed status of objects and arrays in the jsonTree were missing. The expanded css class was added to a dom node that was immediately discarded while redrawing the jsonTree to display the child elements. Updated the code to reapply the css on each rebuild. Also corrected the relative path to the images.
1 parent 711d603 commit 0ba5f25

File tree

3 files changed

+58
-5
lines changed

3 files changed

+58
-5
lines changed

panel/components/json-tree/json-tree.css

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,16 +55,17 @@ bat-json-tree .properties-tree li.parent li {
5555

5656
bat-json-tree .properties-tree li.parent::before {
5757
-webkit-user-select: none;
58-
background-image: url(../../img/statusbarButtonGlyphs.png);
59-
background-size: 320px 120px;
58+
background-image: url(../../../img/statusbarButtonGlyphs.png);
59+
background-size: 320px 144px;
6060
opacity: 0.5;
6161
content: "a";
62-
width: 8px;
62+
width: 6px;
63+
height: 10px;
6364
float: left;
6465
margin-right: 2px;
6566
color: transparent;
6667
text-shadow: none;
67-
margin-top: -2px;
68+
margin-top: -3px;
6869
}
6970

7071
bat-json-tree .properties-tree li.parent::before {

panel/components/json-tree/json-tree.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,10 @@ function batJsonTreeDirective() {
4040
'': root
4141
};
4242

43+
var expandedPaths = {};
44+
4345
scope.$watch('batModel', function (val) {
46+
expandedPaths = {};
4447
if (!val) {
4548
root = angular.element(BAT_JSON_TREE_TEMPLATE);
4649
element.html('');
@@ -98,6 +101,10 @@ function batJsonTreeDirective() {
98101
'</li>'),
99102
childElt;
100103

104+
if (expandedPaths.hasOwnProperty(fullPath)) {
105+
parentElt.addClass('expanded');
106+
}
107+
101108
if (val === null) {
102109
childElt = angular.element('<span class="value console-formatted-null">null</span>');
103110
} else if (val['~object'] || val['~array-length'] !== undefined) {
@@ -106,8 +113,8 @@ function batJsonTreeDirective() {
106113
// you can't expand an empty array
107114
if (val['~array-length'] !== 0) {
108115
parentElt.on('click', function () {
116+
expandedPaths[fullPath] = true;
109117
scope.batInspect({ path: fullPath });
110-
parentElt.addClass('expanded');
111118
});
112119
}
113120

panel/components/json-tree/json-tree.spec.js

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,51 @@ describe('batJsonTree', function () {
141141
});
142142
});
143143

144+
describe('expanded css', function() {
145+
var modelWithObject = {
146+
'': {
147+
'$id': 1,
148+
objectA: { '~object': true }
149+
}
150+
};
151+
it("should not add expanded class to object that is not expanded", function () {
152+
$rootScope.data = modelWithObject;
153+
compileTree();
154+
expect(element[0].querySelectorAll('.expanded').length).toEqual(0);
155+
});
156+
157+
it("should add expanded class to object that is expanded", function () {
158+
setupTreeWithModelAndExpandIt();
159+
waitsFor(function() {
160+
return element[0].querySelector('.parent.expanded');
161+
}, 'Expected parent element to have the class .expanded');
162+
});
163+
164+
it("should clear the history of expanded elements when model changes", function () {
165+
setupTreeWithModelAndExpandIt();
166+
$rootScope.data = {
167+
'': {
168+
'$id': 1,
169+
objectA: { '~object': true }
170+
}
171+
};
172+
$rootScope.$apply();
173+
waitsFor(function() {
174+
return element[0].querySelector('.parent');
175+
}, 'Expected parent element to be present');
176+
runs(function() {
177+
expect(element[0].querySelector('.parent.expanded')).toBeNull();
178+
});
179+
});
180+
181+
function setupTreeWithModelAndExpandIt(){
182+
$rootScope.data = modelWithObject;
183+
compileTree();
184+
angular.element(element[0].querySelector('.parent')).triggerHandler('click');
185+
$rootScope.$broadcast('model:change', { id: 1 });
186+
}
187+
});
188+
144189
function compileAndExpectOutputToEqual(expected) {
145190
compileTree();
146191
expect(element.text()).toEqual(expected);

0 commit comments

Comments
 (0)