Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/webroot/rsrc/js/application/differential/behavior-populate.js
12242 views
1
/**
2
* @provides javelin-behavior-differential-populate
3
* @requires javelin-behavior
4
* javelin-dom
5
* javelin-stratcom
6
* phabricator-tooltip
7
* phabricator-diff-changeset-list
8
* phabricator-diff-changeset
9
* phuix-formation-view
10
* @javelin
11
*/
12
13
JX.behavior('differential-populate', function(config, statics) {
14
15
// When we perform a Quicksand navigation, deactivate the changeset lists on
16
// the current page and activate the changeset lists on the new page.
17
var onredraw = function(page_id) {
18
// If the current page is already active, we don't need to do anything.
19
if (statics.pageID === page_id) {
20
return;
21
}
22
23
var ii;
24
25
// Put the old lists to sleep.
26
var old_lists = get_lists(statics.pageID);
27
for (ii = 0; ii < old_lists.length; ii++) {
28
old_lists[ii].sleep();
29
}
30
statics.pageID = null;
31
32
// Awaken the new lists, if they exist.
33
if (statics.pages.hasOwnProperty(page_id)) {
34
var new_lists = get_lists(page_id);
35
for (ii = 0; ii < new_lists.length; ii++) {
36
new_lists[ii].wake();
37
}
38
39
statics.pageID = page_id;
40
}
41
};
42
43
// Get changeset lists on the current page.
44
var get_lists = function(page_id) {
45
if (page_id === null) {
46
return [];
47
}
48
49
return statics.pages[page_id] || [];
50
};
51
52
if (!statics.installed) {
53
statics.installed = true;
54
statics.pages = {};
55
statics.pageID = null;
56
57
JX.Stratcom.listen('quicksand-redraw', null, function(e) {
58
onredraw(e.getData().newResponseID);
59
});
60
}
61
62
var changeset_list = new JX.DiffChangesetList()
63
.setTranslations(JX.phtize(config.pht))
64
.setInlineURI(config.inlineURI)
65
.setInlineListURI(config.inlineListURI)
66
.setIsStandalone(config.isStandalone);
67
68
if (config.formationViewID) {
69
var formation_node = JX.$(config.formationViewID);
70
var formation_view = new JX.PHUIXFormationView(formation_node);
71
changeset_list.setFormationView(formation_view);
72
formation_view.start();
73
}
74
75
for (var ii = 0; ii < config.changesetViewIDs.length; ii++) {
76
var id = config.changesetViewIDs[ii];
77
var node = JX.$(id);
78
var changeset = changeset_list.newChangesetForNode(node);
79
if (changeset.shouldAutoload()) {
80
changeset.setStabilize(true).load();
81
}
82
}
83
84
// Install and activate the current page.
85
var page_id = JX.Quicksand.getCurrentPageID();
86
statics.pages[page_id] = [changeset_list];
87
onredraw(page_id);
88
89
var highlighted = null;
90
var highlight_class = null;
91
92
JX.Stratcom.listen(
93
['mouseover', 'mouseout'],
94
['differential-changeset', 'tag:td'],
95
function(e) {
96
var t = e.getTarget();
97
98
// NOTE: Using className is not best practice, but the diff UI is perf
99
// sensitive.
100
if (!t.className.match(/cov|copy/)) {
101
return;
102
}
103
104
if (e.getType() == 'mouseout') {
105
JX.Tooltip.hide();
106
if (highlighted) {
107
JX.DOM.alterClass(highlighted, highlight_class, false);
108
highlighted = null;
109
}
110
} else {
111
highlight_class = null;
112
var msg;
113
var align = 'W';
114
var sibling = 'previousSibling';
115
var width = 120;
116
if (t.className.match(/cov-C/)) {
117
msg = 'Covered';
118
highlight_class = 'source-cov-C';
119
} else if (t.className.match(/cov-U/)) {
120
msg = 'Not Covered';
121
highlight_class = 'source-cov-U';
122
} else if (t.className.match(/cov-N/)) {
123
msg = 'Not Executable';
124
highlight_class = 'source-cov-N';
125
} else {
126
var match = /new-copy|new-move/.exec(t.className);
127
if (match) {
128
sibling = 'nextSibling';
129
width = 500;
130
msg = JX.Stratcom.getData(t).msg;
131
highlight_class = match[0];
132
}
133
}
134
135
if (msg) {
136
JX.Tooltip.show(t, width, align, msg);
137
}
138
139
if (highlight_class) {
140
highlighted = t[sibling];
141
JX.DOM.alterClass(highlighted, highlight_class, true);
142
}
143
}
144
145
});
146
147
148
});
149
150