Skip to content

Commit e86de0c

Browse files
class search feature
1 parent 1e3afe9 commit e86de0c

File tree

7 files changed

+72
-6
lines changed

7 files changed

+72
-6
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ An UML Class explorer for InterSystems Caché.
1111

1212
## Screenshots
1313

14-
![Demo](https://cloud.githubusercontent.com/assets/4989256/7799624/f0255216-0310-11e5-8783-06300fc6d957.png)
14+
![Demo](https://cloud.githubusercontent.com/assets/4989256/7898598/7d367720-070d-11e5-9177-dded6abf93e1.png)
1515

1616
## Installation
1717

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "CacheUMLExplorer",
3-
"version": "0.11.1",
3+
"version": "0.12.0",
44
"description": "An UML Class explorer for InterSystems Caché",
55
"directories": {
66
"test": "test"

web/css/interface.css

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ html, body {
1515
.ui-sideBlock {
1616
position: relative;
1717
float: left;
18-
width: 250px;
18+
width: 200px;
1919
height: 100%;
2020
}
2121

2222
.ui-mainBlock {
2323
position: relative;
24-
margin-left: 250px;
24+
margin-left: 200px;
2525
height: 100%;
2626
}
2727

web/css/treeView.css

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,26 @@
55
height: 100%;
66
border-right: 1px solid lightgray;
77
overflow: auto;
8+
box-sizing: border-box;
9+
padding-top: 24px;
10+
}
11+
12+
.ui-sideSearchBlock {
13+
position: absolute;
14+
top: 0;
15+
left: 0;
16+
width: 100%;
17+
z-index: 1;
18+
}
19+
20+
.ui-sideSearchBlock > input {
21+
display: block;
22+
box-sizing: border-box;
23+
border: 1px solid gray;
24+
border-radius: 5px;
25+
width: 196px;
26+
margin: 1px 1px 1px 2px;
27+
height: 22px;
828
}
929

1030
.tv-package-name.minimized + .tv-package-content {

web/index.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@
2828
<body onload="cue = new CacheUMLExplorer(document.getElementById('treeView'), document.getElementById('svgContainer'))">
2929
<div class="ui-body" id="ui-body">
3030
<div class="ui-sideBlock">
31+
<div class="ui-sideSearchBlock">
32+
<input type="search" id="classTreeSearch" placeholder="Search..."/>
33+
</div>
3134
<div id="treeView">
3235

3336
</div>

web/js/CacheUMLExplorer.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ var CacheUMLExplorer = function (treeViewContainer, classViewContainer) {
2828
svgContainer: id("svgContainer"),
2929
methodDescription: id("methodDescription"),
3030
methodViewBounds: id("methodViewBounds"),
31-
namespaces: id("namespaces")
31+
namespaces: id("namespaces"),
32+
classTreeSearch: id("classTreeSearch")
3233
};
3334

3435
this.UI = new UI(this);

web/js/ClassTree.js

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,28 @@
66
*/
77
var ClassTree = function (parent, treeViewContainer) {
88

9+
var self = this;
10+
911
this.cacheUMLExplorer = parent;
1012
this.container = treeViewContainer;
1113
this.loader = null;
1214
this.SELECTED_NAME = null;
1315
this.SELECTED_TYPE = null; // "class" || "package"
1416
this.SELECTED_ELEMENT = null;
17+
this.treeObject = null;
18+
19+
this.cacheUMLExplorer.elements.classTreeSearch.addEventListener("input", function (e) {
20+
self.searchChanged.call(self, (e.target || e.srcElement).value);
21+
});
1522

1623
};
1724

1825
ClassTree.prototype.showLoader = function () {
1926

2027
if (this.loader) return;
2128

29+
this.cacheUMLExplorer.elements.classTreeSearch.value = "";
30+
this.treeObject = null;
2231
this.loader = document.createElement("div");
2332
this.loader.className = "spinner";
2433
this.container.appendChild(this.loader);
@@ -28,6 +37,8 @@ ClassTree.prototype.showLoader = function () {
2837
ClassTree.prototype.removeLoader = function () {
2938

3039
if (!this.loader) return;
40+
41+
this.cacheUMLExplorer.elements.classTreeSearch.value = "";
3142
this.loader.parentNode.removeChild(this.loader);
3243
this.loader = null;
3344

@@ -61,7 +72,36 @@ ClassTree.prototype.packageSelected = function (element, packageName) {
6172

6273
};
6374

64-
ClassTree.prototype.updateTree = function (treeObject) {
75+
ClassTree.prototype.searchChanged = function (query) {
76+
77+
var o = this.treeObject;
78+
79+
if (!o) return;
80+
query = query.toLowerCase();
81+
82+
var searchClone = function (o, copyFlag) {
83+
var i, matches = 0, lm, t, clone = {}, cpf;
84+
for (i in o) {
85+
lm = 0; cpf = false;
86+
if (i.toLowerCase().indexOf(query) !== -1) { lm += 1; matches++; cpf = true; }
87+
if (typeof o[i] === "object") {
88+
lm += (t = searchClone(o[i], cpf)).matches;
89+
matches += t.matches;
90+
} else t = { obj: o[i] };
91+
if (copyFlag || lm !== 0) clone[i] = t.obj;
92+
}
93+
return { matches: matches, obj: clone };
94+
};
95+
96+
this.updateTree(searchClone(o).obj || {}, true);
97+
98+
};
99+
100+
/**
101+
* @param treeObject
102+
* @param {boolean} [doNotChangeRoot] - Determines to restrict assign of this.treeObject.
103+
*/
104+
ClassTree.prototype.updateTree = function (treeObject, doNotChangeRoot) {
65105

66106
var self = this,
67107
div = function () { return document.createElement("div");},
@@ -159,4 +199,6 @@ ClassTree.prototype.updateTree = function (treeObject) {
159199

160200
build(this.container, treeObject, [], 0);
161201

202+
if (!doNotChangeRoot) this.treeObject = treeObject;
203+
162204
};

0 commit comments

Comments
 (0)