Skip to content

Commit b060f0a

Browse files
author
epriestley
committed
Herald JS basics.
1 parent 9c5e7bb commit b060f0a

File tree

7 files changed

+598
-28
lines changed

7 files changed

+598
-28
lines changed

scripts/celerity_mapper.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@
101101
$provides = array_filter($provides);
102102
$requires = array_filter($requires);
103103

104+
var_dump($requires);
105+
104106
if (count($provides) !== 1) {
105107
throw new Exception(
106108
"File {$path} must @provide exactly one Celerity target.");

src/__celerity_resource_map__.php

Lines changed: 51 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@
8181
),
8282
'aphront-side-nav-view-css' =>
8383
array(
84-
'uri' => '/res/09b7eb85/rsrc/css/aphront/side-nav-view.css',
84+
'uri' => '/res/4f4c5ca8/rsrc/css/aphront/side-nav-view.css',
8585
'type' => 'css',
8686
'requires' =>
8787
array(
@@ -199,7 +199,7 @@
199199
),
200200
'diffusion-commit-view-css' =>
201201
array(
202-
'uri' => '/res/4593ecc8/rsrc/css/application/diffusion/commit-view.css',
202+
'uri' => '/res/8c139192/rsrc/css/application/diffusion/commit-view.css',
203203
'type' => 'css',
204204
'requires' =>
205205
array(
@@ -336,6 +336,16 @@
336336
),
337337
'disk' => '/rsrc/js/application/core/behavior-workflow.js',
338338
),
339+
'multirow-row-manager' =>
340+
array(
341+
'uri' => '/res/330d076b/rsrc/js/application/core/MultirowRowManager.js',
342+
'type' => 'js',
343+
'requires' =>
344+
array(
345+
0 => 'javelin-lib-dev',
346+
),
347+
'disk' => '/rsrc/js/application/core/MultirowRowManager.js',
348+
),
339349
'javelin-behavior-differential-add-reviewers' =>
340350
array(
341351
'uri' => '/res/330154e4/rsrc/js/application/differential/behavior-add-reviewers.js',
@@ -406,6 +416,26 @@
406416
),
407417
'disk' => '/rsrc/js/application/differential/behavior-show-more.js',
408418
),
419+
'javelin-behavior-herald-rule-editor' =>
420+
array(
421+
'uri' => '/res/f18bcd5e/rsrc/js/application/herald/herald-rule-editor.js',
422+
'type' => 'js',
423+
'requires' =>
424+
array(
425+
0 => 'herald-rule-editor',
426+
),
427+
'disk' => '/rsrc/js/application/herald/herald-rule-editor.js',
428+
),
429+
'herald-rule-editor' =>
430+
array(
431+
'uri' => '/res/e71d1d0e/rsrc/js/application/herald/HeraldRuleEditor.js',
432+
'type' => 'js',
433+
'requires' =>
434+
array(
435+
0 => 'multirow-row-manager',
436+
),
437+
'disk' => '/rsrc/js/application/herald/HeraldRuleEditor.js',
438+
),
409439
'javelin-behavior-maniphest-transaction-controls' =>
410440
array(
411441
'uri' => '/res/fc6a8722/rsrc/js/application/maniphest/behavior-transaction-controls.js',
@@ -491,7 +521,7 @@
491521
), array (
492522
'packages' =>
493523
array (
494-
73063447 =>
524+
'848f4c9f' =>
495525
array (
496526
'name' => 'core.pkg.css',
497527
'symbols' =>
@@ -511,7 +541,7 @@
511541
12 => 'phabricator-remarkup-css',
512542
13 => 'syntax-highlighting-css',
513543
),
514-
'uri' => '/res/pkg/73063447/core.pkg.css',
544+
'uri' => '/res/pkg/848f4c9f/core.pkg.css',
515545
'type' => 'css',
516546
),
517547
'76f3c1f8' =>
@@ -545,33 +575,33 @@
545575
'uri' => '/res/pkg/30d594cf/differential.pkg.js',
546576
'type' => 'js',
547577
),
548-
'2393c3a4' =>
578+
'eadf6ec3' =>
549579
array (
550580
'name' => 'diffusion.pkg.css',
551581
'symbols' =>
552582
array (
553583
0 => 'diffusion-commit-view-css',
554584
),
555-
'uri' => '/res/pkg/2393c3a4/diffusion.pkg.css',
585+
'uri' => '/res/pkg/eadf6ec3/diffusion.pkg.css',
556586
'type' => 'css',
557587
),
558588
),
559589
'reverse' =>
560590
array (
561-
'phabricator-core-css' => '73063447',
562-
'phabricator-core-buttons-css' => '73063447',
563-
'phabricator-standard-page-view' => '73063447',
564-
'aphront-dialog-view-css' => '73063447',
565-
'aphront-form-view-css' => '73063447',
566-
'aphront-panel-view-css' => '73063447',
567-
'aphront-side-nav-view-css' => '73063447',
568-
'aphront-table-view-css' => '73063447',
569-
'aphront-crumbs-view-css' => '73063447',
570-
'aphront-tokenizer-control-css' => '73063447',
571-
'aphront-typeahead-control-css' => '73063447',
572-
'phabricator-directory-css' => '73063447',
573-
'phabricator-remarkup-css' => '73063447',
574-
'syntax-highlighting-css' => '73063447',
591+
'phabricator-core-css' => '848f4c9f',
592+
'phabricator-core-buttons-css' => '848f4c9f',
593+
'phabricator-standard-page-view' => '848f4c9f',
594+
'aphront-dialog-view-css' => '848f4c9f',
595+
'aphront-form-view-css' => '848f4c9f',
596+
'aphront-panel-view-css' => '848f4c9f',
597+
'aphront-side-nav-view-css' => '848f4c9f',
598+
'aphront-table-view-css' => '848f4c9f',
599+
'aphront-crumbs-view-css' => '848f4c9f',
600+
'aphront-tokenizer-control-css' => '848f4c9f',
601+
'aphront-typeahead-control-css' => '848f4c9f',
602+
'phabricator-directory-css' => '848f4c9f',
603+
'phabricator-remarkup-css' => '848f4c9f',
604+
'syntax-highlighting-css' => '848f4c9f',
575605
'differential-core-view-css' => '76f3c1f8',
576606
'differential-changeset-view-css' => '76f3c1f8',
577607
'differential-revision-detail-css' => '76f3c1f8',
@@ -585,6 +615,6 @@
585615
'javelin-behavior-differential-populate' => '30d594cf',
586616
'javelin-behavior-differential-show-more' => '30d594cf',
587617
'javelin-behavior-differential-diff-radios' => '30d594cf',
588-
'diffusion-commit-view-css' => '2393c3a4',
618+
'diffusion-commit-view-css' => 'eadf6ec3',
589619
),
590620
));

src/applications/herald/controller/rule/HeraldRuleController.php

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,7 @@ public function processRequest() {
251251

252252
$form = id(new AphrontFormView())
253253
->setUser($user)
254+
->setID('herald-rule-edit-form')
254255
->addHiddenInput('type', $rule->getContentType())
255256
->addHiddenInput('save', true)
256257
->addHiddenInput('rule', '')
@@ -270,16 +271,33 @@ public function processRequest() {
270271
->appendChild(
271272
'<h1>Conditions</h1>'.
272273
'<div style="margin: .5em 0 1em; padding: .5em; background: #aaa;">'.
273-
'<a href="#" class="button green">Create New Condition</a>'.
274+
javelin_render_tag(
275+
'a',
276+
array(
277+
'href' => '#',
278+
'class' => 'button green',
279+
'sigil' => 'create-action',
280+
),
281+
'Create New Condition').
274282
'<p>When '.$must_match.' these conditions are met:</p>'.
275-
'<table></table>'.
283+
javelin_render_tag(
284+
'table',
285+
array(
286+
'sigil' => 'rule-conditions',
287+
),
288+
'').
276289
'</div>')
277290
->appendChild(
278291
'<h1>Action</h1>'.
279292
'<div style="margin: .5em 0 1em; padding: .5em; background: #aaa;">'.
280293
'<a href="#" class="button green">Create New Action</a>'.
281294
'<p>Take these actions:</p>'.
282-
'<table></table>'.
295+
javelin_render_tag(
296+
'table',
297+
array(
298+
'sigil' => 'rule-actions',
299+
),
300+
'').
283301
'</div>')
284302
->appendChild(
285303
id(new AphrontFormSubmitControl())
@@ -439,11 +457,10 @@ class="button green"
439457
HeraldValueTypeConfig::getValueTypeForAction($action);
440458
}
441459

442-
/*
443460
Javelin::initBehavior(
444461
'herald-rule-editor',
445462
array(
446-
'root' => 'qq',//$form->requireUniqueId(),
463+
'root' => 'herald-rule-edit-form',
447464
'conditions' => (object) $serial_conditions,
448465
'actions' => (object) $serial_actions,
449466
'template' => $this->buildTokenizerTemplates() + array(
@@ -452,8 +469,6 @@ class="button green"
452469
'info' => $config_info,
453470
));
454471

455-
*/
456-
457472
$panel = new AphrontPanelView();
458473
$panel->setHeader('Edit Herald Rule');
459474
$panel->setWidth(AphrontPanelView::WIDTH_WIDE);

src/view/form/base/AphrontFormView.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ final class AphrontFormView extends AphrontView {
2525
private $encType;
2626
private $user;
2727
private $workflow;
28+
private $id;
29+
30+
public function setID($id) {
31+
$this->id = $id;
32+
return $this;
33+
}
2834

2935
public function setUser(PhabricatorUser $user) {
3036
$this->user = $user;
@@ -66,6 +72,7 @@ public function render() {
6672
'class' => 'aphront-form-view',
6773
'enctype' => $this->encType,
6874
'sigil' => $this->workflow ? 'workflow' : null,
75+
'id' => $this->id,
6976
),
7077
$this->renderDataInputs().
7178
$this->renderChildren());
Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
/**
2+
* @requires javelin-lib-dev
3+
* @provides multirow-row-manager
4+
* @javelin
5+
*/
6+
7+
8+
/**
9+
* Give a MultirowRowManager a table DOM elem to manage.
10+
* You can add rows, and provide a given ID if you like.
11+
* You can update rows by ID.
12+
* Rows are automatically equipped with a removal button.
13+
* You can listen to the 'row-removed' event on the Manager to get
14+
* notifications of these row removals, with the DOM id of the removed
15+
* row as event data.
16+
*/
17+
JX.install('MultirowRowManager', {
18+
/**
19+
* @param DOM element <table> root Container for rows
20+
*/
21+
construct : function(root, minRows) {
22+
this._root = root;
23+
this._rows = [];
24+
25+
if (typeof minRows !== "undefined") {
26+
this._minRows = minRows;
27+
} else {
28+
this._minRows = 1;
29+
}
30+
31+
JX.DOM.listen(
32+
this._root,
33+
'click',
34+
JX.MultirowRowManager._removeSigil,
35+
JX.bind(this, this._onrowremoved));
36+
},
37+
38+
members : {
39+
_count : 0,
40+
_nextID : 0,
41+
_root : null,
42+
_rows : null,
43+
44+
_generateRowID : function() {
45+
return "" + this._nextID++;
46+
},
47+
48+
_wrapRowContents : function(row_id, row_contents) {
49+
var row = JX.$N('tr',
50+
{ sigil : JX.MultirowRowManager.getRowSigil(),
51+
meta : { multirow_row_manager_row_id : row_id }
52+
},
53+
row_contents);
54+
55+
var removeButton = JX.$N(
56+
'td',
57+
{},
58+
JX.$N(
59+
'a',
60+
{ className: "button",
61+
sigil: JX.MultirowRowManager._removeSigil
62+
},
63+
'-'));
64+
65+
JX.DOM.appendContent(row, removeButton);
66+
return row;
67+
},
68+
69+
getRowID : function(row) {
70+
return JX.Stratcom.getData(row).multirow_row_manager_row_id;
71+
},
72+
/**
73+
* @param row_contents [DOM elements] New contents of row
74+
* @param row_id row ID to update, will throw if this row has been removed
75+
*/
76+
updateRow : function(row_id, row_contents) {
77+
if (__DEV__) {
78+
if (typeof this._rows[row_id] === "undefined") {
79+
throw new Error("JX.MultirowRowManager.updateRow(row_id, " +
80+
"row_contents): provided row id does not exist." +
81+
" Use addRow to create a new row and make sure " +
82+
"not to update rows that have been deleted.");
83+
}
84+
}
85+
var old_row = this._rows[row_id];
86+
var new_row = this._wrapRowContents(row_id, row_contents);
87+
JX.copy(JX.Stratcom.getData(new_row), JX.Stratcom.getData(old_row));
88+
89+
JX.DOM.replace(old_row, new_row);
90+
this._rows[row_id] = new_row;
91+
92+
this._oncountchanged(); // Fix the new button.
93+
return new_row;
94+
},
95+
96+
addRow : function(row_contents) {
97+
var row_id = this._generateRowID();
98+
var row = this._wrapRowContents(row_id, row_contents);
99+
JX.DOM.appendContent(this._root, row);
100+
101+
this._count++;
102+
this._oncountchanged();
103+
104+
this._rows[row_id] = row;
105+
return row;
106+
},
107+
_onrowremoved : function(e) {
108+
if (!JX.Stratcom.getData(e.getTarget()).enabled) {
109+
return;
110+
}
111+
var row = e.getNode(JX.MultirowRowManager.getRowSigil());
112+
var row_id = this.getRowID(row);
113+
delete this._rows[row_id];
114+
JX.DOM.remove(row);
115+
116+
this._count--;
117+
this._oncountchanged();
118+
this.invoke('row-removed', row_id);
119+
},
120+
121+
_oncountchanged : function(e) {
122+
var buttons = JX.DOM.scry(
123+
this._root,
124+
'a',
125+
JX.MultirowRowManager._removeSigil);
126+
127+
var disable = (this._minRows >= 0 && this._count <= this._minRows);
128+
for (var i = 0; i < buttons.length; i++) {
129+
var button = buttons[i];
130+
JX.DOM.alterClass(button, 'disabled', disable);
131+
JX.Stratcom.getData(button).enabled = !disable;
132+
}
133+
}
134+
},
135+
events : ['row-removed'],
136+
statics : {
137+
getRowSigil : function() {
138+
return "tools-multirow-row-manager-row";
139+
},
140+
_removeSigil : "tools-multirow-row-manager-row-remove"
141+
}
142+
});
143+

0 commit comments

Comments
 (0)