activeadmin_ancestry_view 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ed828e32cb98a33fc8d20672a7404bc60ce20c0e
|
4
|
+
data.tar.gz: a21e3e1b3b978f29c7cd58041c674fbf3965c4a5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a40ef5ac7146d3dd67519c1ac1863b6ee981bb711499a72ff4b288d21f67e433b0ab5df388eb44db3c2db7fad2b19a9ce2df2ac18f238b170c4aa818a91c8a3e
|
7
|
+
data.tar.gz: 4d67bcf33aca393596735c56c941b11da54615b2f2cbc2a6cdf7f6907e23d5d3809a063227ad45347251b9e41448aa21453420e92d65377830b8a2b8b3bf00c4
|
@@ -0,0 +1,239 @@
|
|
1
|
+
$(document).ready(function() {
|
2
|
+
var CSSRule, branchProp, clearAllColors, distance, findPanelHeader, getElements, pseudoElement, similarItems;
|
3
|
+
CSSRule = {
|
4
|
+
get: function(ruleName, deleteFlag) {
|
5
|
+
var cssRule, i, ii, styleSheet;
|
6
|
+
ruleName = ruleName.toLowerCase();
|
7
|
+
if (document.styleSheets) {
|
8
|
+
i = 0;
|
9
|
+
while (i < document.styleSheets.length) {
|
10
|
+
styleSheet = document.styleSheets[i];
|
11
|
+
ii = 0;
|
12
|
+
cssRule = false;
|
13
|
+
while (true) {
|
14
|
+
if (styleSheet.cssRules) {
|
15
|
+
cssRule = styleSheet.cssRules[ii];
|
16
|
+
} else {
|
17
|
+
cssRule = styleSheet.rules[ii];
|
18
|
+
}
|
19
|
+
if (cssRule) {
|
20
|
+
if (cssRule.selectorText.toLowerCase() === ruleName) {
|
21
|
+
if (deleteFlag === 'delete') {
|
22
|
+
if (styleSheet.cssRules) {
|
23
|
+
styleSheet.deleteRule(ii);
|
24
|
+
} else {
|
25
|
+
styleSheet.removeRule(ii);
|
26
|
+
}
|
27
|
+
return true;
|
28
|
+
} else {
|
29
|
+
return cssRule;
|
30
|
+
}
|
31
|
+
}
|
32
|
+
}
|
33
|
+
ii++;
|
34
|
+
if (!cssRule) {
|
35
|
+
break;
|
36
|
+
}
|
37
|
+
}
|
38
|
+
i++;
|
39
|
+
}
|
40
|
+
}
|
41
|
+
return false;
|
42
|
+
},
|
43
|
+
add: function(ruleName, properies) {
|
44
|
+
if (document.styleSheets) {
|
45
|
+
if (!this.get(ruleName)) {
|
46
|
+
if (document.styleSheets[0].addRule) {
|
47
|
+
return document.styleSheets[0].addRule(ruleName, properies, 0);
|
48
|
+
} else {
|
49
|
+
return document.styleSheets[0].insertRule(ruleName + (" { " + properies + " }"), 0);
|
50
|
+
}
|
51
|
+
}
|
52
|
+
}
|
53
|
+
}
|
54
|
+
};
|
55
|
+
distance = {
|
56
|
+
middleHeight: function(node) {
|
57
|
+
return Math.abs($(node).height() / 2);
|
58
|
+
},
|
59
|
+
betweenTop: function(sourceNode, targetNode) {
|
60
|
+
return Math.abs($(sourceNode).offset().top - $(targetNode).offset().top);
|
61
|
+
},
|
62
|
+
verticalBranch: function(node, lastChild) {
|
63
|
+
return this.betweenTop(node, lastChild) + this.middleHeight(lastChild);
|
64
|
+
}
|
65
|
+
};
|
66
|
+
branchProp = {
|
67
|
+
baseMargin: 2,
|
68
|
+
base: "transition: 150ms ease; " + "content: ''; " + "position: absolute; " + "border: 0.1em solid gray; ",
|
69
|
+
vertical: function(height) {
|
70
|
+
return ("margin-left: " + this.baseMargin + "em; ") + ("height: " + height + "px; ") + "z-index: -1; " + this.base;
|
71
|
+
},
|
72
|
+
horizontal: function(marginTop, marginLeft) {
|
73
|
+
return ("margin-top: -" + marginTop + "px; ") + ("margin-left: -" + (marginLeft - this.baseMargin) + "em; ") + ("width: " + (marginLeft - this.baseMargin) + "em; ") + "z-index: -2; " + this.base;
|
74
|
+
}
|
75
|
+
};
|
76
|
+
pseudoElement = {
|
77
|
+
addHorizontal: function(node) {
|
78
|
+
var height, id, marginLeft;
|
79
|
+
id = $(node).attr('id');
|
80
|
+
height = distance.middleHeight(node);
|
81
|
+
marginLeft = $(node).attr('data-shift-multiplicator');
|
82
|
+
return CSSRule.add("[id='" + id + "']::after", branchProp.horizontal(height, marginLeft));
|
83
|
+
},
|
84
|
+
addVertical: function(node, purposeNode) {
|
85
|
+
var dist, id;
|
86
|
+
dist = distance.verticalBranch(node, purposeNode);
|
87
|
+
id = $(node).attr('id');
|
88
|
+
return CSSRule.add("[id='" + id + "']::before", branchProp.vertical(dist));
|
89
|
+
},
|
90
|
+
updHorizontal: function(node) {
|
91
|
+
var id, line, newHeight;
|
92
|
+
if ($(node).hasClass('panel-root')) {
|
93
|
+
return false;
|
94
|
+
} else {
|
95
|
+
id = $(node).attr('id');
|
96
|
+
newHeight = -Math.abs(distance.middleHeight(node));
|
97
|
+
line = CSSRule.get('[id="' + id + '"]::after');
|
98
|
+
return line.style.marginTop = newHeight.toString().concat('px');
|
99
|
+
}
|
100
|
+
},
|
101
|
+
updVertical: function(node) {
|
102
|
+
var lastChild, line, newDistance, nodeId;
|
103
|
+
nodeId = $(node).attr('id');
|
104
|
+
lastChild = $(node).parent().find(".panel-container[data-last-child=" + nodeId + "]");
|
105
|
+
if ($(lastChild).length) {
|
106
|
+
newDistance = distance.verticalBranch(node, lastChild);
|
107
|
+
line = CSSRule.get('[id="' + nodeId + '"]::before');
|
108
|
+
return line.style.height = newDistance.toString().concat('px');
|
109
|
+
}
|
110
|
+
},
|
111
|
+
updEachVertical: function(node) {
|
112
|
+
var actualCollection, actualIds, allParents, nodeClasses, parentIds, that;
|
113
|
+
nodeClasses = $(node).attr('class').split(' ');
|
114
|
+
allParents = $(node).prevAll('.panel-parent');
|
115
|
+
parentIds = $.map(allParents, function(el) {
|
116
|
+
return $(el).attr('id');
|
117
|
+
});
|
118
|
+
actualIds = similarItems(nodeClasses, parentIds);
|
119
|
+
actualIds.push($(node).attr('id'));
|
120
|
+
actualCollection = getElements(actualIds);
|
121
|
+
that = this;
|
122
|
+
return $.each(actualCollection, function(i, element) {
|
123
|
+
return that.updVertical(element);
|
124
|
+
});
|
125
|
+
}
|
126
|
+
};
|
127
|
+
findPanelHeader = function(object) {
|
128
|
+
return object.find('.panel').find('.panel-header');
|
129
|
+
};
|
130
|
+
clearAllColors = function() {
|
131
|
+
$('.panel-header').css('background-color', '');
|
132
|
+
return $('.panel-header').each(function() {
|
133
|
+
if ($(this).hasClass('selectable')) {
|
134
|
+
return $(this).removeClass('selectable');
|
135
|
+
}
|
136
|
+
});
|
137
|
+
};
|
138
|
+
similarItems = function(arr1, arr2) {
|
139
|
+
var item, _i, _len, _results;
|
140
|
+
_results = [];
|
141
|
+
for (_i = 0, _len = arr2.length; _i < _len; _i++) {
|
142
|
+
item = arr2[_i];
|
143
|
+
if (__indexOf.call(arr1, item) >= 0) {
|
144
|
+
_results.push(item);
|
145
|
+
}
|
146
|
+
}
|
147
|
+
return _results;
|
148
|
+
};
|
149
|
+
getElements = function(arrayOfIds) {
|
150
|
+
return $.map(arrayOfIds, function(id) {
|
151
|
+
return $("#" + id).get();
|
152
|
+
});
|
153
|
+
};
|
154
|
+
$('.panel-parent').each(function() {
|
155
|
+
var id, parentColor;
|
156
|
+
id = $(this).attr('id');
|
157
|
+
parentColor = findPanelHeader($(this)).css('background-color');
|
158
|
+
return $('.panel-childless').each(function() {
|
159
|
+
if ($(this).hasClass(id)) {
|
160
|
+
return findPanelHeader($(this)).css('background-color', parentColor);
|
161
|
+
}
|
162
|
+
});
|
163
|
+
});
|
164
|
+
$('.show-content').click(function() {
|
165
|
+
var content, node, nodeId, oldNodeHeight, verticalLine;
|
166
|
+
node = $(this).parents('.panel-container');
|
167
|
+
nodeId = $(node).attr('id');
|
168
|
+
content = $(this).parent().next('.panel_contents');
|
169
|
+
oldNodeHeight = $(node).height();
|
170
|
+
verticalLine = CSSRule.get('[id="' + $(node).attr('id') + '"]::before');
|
171
|
+
if (content.is(':hidden')) {
|
172
|
+
content.show(0, function() {
|
173
|
+
return pseudoElement.updHorizontal(node);
|
174
|
+
});
|
175
|
+
} else {
|
176
|
+
content.hide(0, function() {
|
177
|
+
return pseudoElement.updHorizontal(node);
|
178
|
+
});
|
179
|
+
}
|
180
|
+
return pseudoElement.updEachVertical(node);
|
181
|
+
});
|
182
|
+
$('.show-childrens').click(function() {
|
183
|
+
var lastChild, lastChildId, nodeContent, nodeId;
|
184
|
+
nodeId = $(this).parents('.panel-container').attr('id');
|
185
|
+
nodeContent = $(this).parent().next('.panel_contents');
|
186
|
+
lastChild = $(".panel-container[data-last-child=" + nodeId + "]");
|
187
|
+
lastChildId = $(lastChild).attr('id');
|
188
|
+
if (nodeContent.is(':hidden')) {
|
189
|
+
nodeContent.show();
|
190
|
+
} else {
|
191
|
+
nodeContent.hide();
|
192
|
+
}
|
193
|
+
$('.panel').each(function() {
|
194
|
+
var content, subLastChildId, subNode;
|
195
|
+
subNode = $(this).parent('.panel-container');
|
196
|
+
if (subNode.hasClass(nodeId)) {
|
197
|
+
content = $(this).find('.panel_contents');
|
198
|
+
if (nodeContent.is(':visible')) {
|
199
|
+
content.show(0, function() {
|
200
|
+
return pseudoElement.updHorizontal(subNode);
|
201
|
+
});
|
202
|
+
} else {
|
203
|
+
content.hide(0, function() {
|
204
|
+
return pseudoElement.updHorizontal(subNode);
|
205
|
+
});
|
206
|
+
}
|
207
|
+
subLastChildId = $(subNode).attr('data-last-child');
|
208
|
+
if (subLastChildId != null) {
|
209
|
+
return pseudoElement.updVertical($("#" + subLastChildId));
|
210
|
+
}
|
211
|
+
}
|
212
|
+
});
|
213
|
+
return pseudoElement.updEachVertical(lastChild);
|
214
|
+
});
|
215
|
+
$('.panel-header').on('click', function() {
|
216
|
+
var parentId;
|
217
|
+
clearAllColors();
|
218
|
+
$(this).addClass('selectable');
|
219
|
+
parentId = $(this).parents('.panel-container').attr('id');
|
220
|
+
return $('.panel-header').each(function() {
|
221
|
+
if (($(this)).parents('.panel-container').hasClass(parentId)) {
|
222
|
+
return $(this).addClass('selectable');
|
223
|
+
}
|
224
|
+
});
|
225
|
+
});
|
226
|
+
$('.panel-parent').each(function() {
|
227
|
+
var lastChild, nodeId;
|
228
|
+
nodeId = $(this).attr('id');
|
229
|
+
lastChild = $(this).parent().find(".panel-container[data-last-child=" + nodeId + "]");
|
230
|
+
if ($(lastChild).length) {
|
231
|
+
return pseudoElement.addVertical(this, lastChild);
|
232
|
+
}
|
233
|
+
});
|
234
|
+
return $('.panel-container').each(function() {
|
235
|
+
if (!$(this).hasClass('panel-root')) {
|
236
|
+
return pseudoElement.addHorizontal(this);
|
237
|
+
}
|
238
|
+
});
|
239
|
+
});
|
@@ -4,10 +4,15 @@ module ActiveadminAncestryView
|
|
4
4
|
def add_javascripts
|
5
5
|
target_file_path = 'app/assets/javascripts/active_admin'
|
6
6
|
ref = "#= require active_admin/base\n"
|
7
|
+
vanilla_ref = "//= require active_admin/base\n"
|
7
8
|
begin
|
8
9
|
inject_into_file("#{target_file_path}.coffee", js_to_add, after: ref)
|
9
|
-
rescue
|
10
|
-
|
10
|
+
rescue
|
11
|
+
begin
|
12
|
+
inject_into_file("#{target_file_path}.js.coffee", js_to_add, after: ref)
|
13
|
+
rescue
|
14
|
+
inject_into_file("#{target_file_path}.js", vanilla_js_to_add, after: vanilla_ref)
|
15
|
+
end
|
11
16
|
end
|
12
17
|
end
|
13
18
|
|
@@ -39,6 +44,10 @@ module ActiveadminAncestryView
|
|
39
44
|
"#= require activeadmin_ancestry_view/base\n"
|
40
45
|
end
|
41
46
|
|
47
|
+
def vanilla_js_to_add
|
48
|
+
"//= require activeadmin_ancestry_view/vanilla-base\n"
|
49
|
+
end
|
50
|
+
|
42
51
|
def css_to_add
|
43
52
|
"@import \"activeadmin_ancestry_view/base\";\n"
|
44
53
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activeadmin_ancestry_view
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dimkarodinz
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-12-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -73,7 +73,7 @@ dependencies:
|
|
73
73
|
- - ">="
|
74
74
|
- !ruby/object:Gem::Version
|
75
75
|
version: '0'
|
76
|
-
type: :
|
76
|
+
type: :runtime
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
@@ -103,6 +103,7 @@ extra_rdoc_files: []
|
|
103
103
|
files:
|
104
104
|
- MIT-LICENSE
|
105
105
|
- app/assets/javascripts/activeadmin_ancestry_view/base.coffee
|
106
|
+
- app/assets/javascripts/activeadmin_ancestry_view/vanilla-base.js
|
106
107
|
- app/assets/stylesheets/activeadmin_ancestry_view/base.scss
|
107
108
|
- app/helpers/active_admin/activeadmin_ancestry_view/nodes_helper.rb
|
108
109
|
- app/models/concerns/activeadmin_ancestry_view/model_methods.rb
|
@@ -145,7 +146,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
145
146
|
version: '0'
|
146
147
|
requirements: []
|
147
148
|
rubyforge_project:
|
148
|
-
rubygems_version: 2.6.
|
149
|
+
rubygems_version: 2.6.14
|
149
150
|
signing_key:
|
150
151
|
specification_version: 4
|
151
152
|
summary: Ancestry tree view in ActiveAdmin resource
|