1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-09-19 16:58:48 +02:00

Enable Phabricator admin to change the owner of a herald rule

Summary:
Added a typeahead in the edit herald rule page that allows an admin or
owner to change the current owner of a rule.  If the typeahead is emptied, the
current owner will remain owner.

Test Plan:
Created a test rule.  Changed the owner.  Deleted the owner in the
typahead. Verified expected behavior.

Reviewers: jungejason, epriestley

Reviewed By: epriestley

CC: aran, jungejason, epriestley, xela

Differential Revision: https://secure.phabricator.com/D1322
This commit is contained in:
awyler 2012-01-05 13:07:08 -08:00
parent 42ddad1bc8
commit 14d16eab17
5 changed files with 49 additions and 13 deletions

View file

@ -285,7 +285,7 @@ celerity_register_resource_map(array(
),
'herald-css' =>
array(
'uri' => '/res/5051f3ab/rsrc/css/application/herald/herald.css',
'uri' => '/res/ed5556e6/rsrc/css/application/herald/herald.css',
'type' => 'css',
'requires' =>
array(
@ -294,7 +294,7 @@ celerity_register_resource_map(array(
),
'herald-rule-editor' =>
array(
'uri' => '/res/4d6dff2b/rsrc/js/application/herald/HeraldRuleEditor.js',
'uri' => '/res/ec9eea63/rsrc/js/application/herald/HeraldRuleEditor.js',
'type' => 'js',
'requires' =>
array(
@ -332,14 +332,13 @@ celerity_register_resource_map(array(
),
0 =>
array(
'uri' => '/res/b6096fdd/rsrc/js/javelin/lib/__tests__/URI.js',
'uri' => '/res/14c48a9f/rsrc/js/javelin/lib/__tests__/behavior.js',
'type' => 'js',
'requires' =>
array(
0 => 'javelin-uri',
1 => 'javelin-php-serializer',
0 => 'javelin-behavior',
),
'disk' => '/rsrc/js/javelin/lib/__tests__/URI.js',
'disk' => '/rsrc/js/javelin/lib/__tests__/behavior.js',
),
'javelin-behavior-aphront-basic-tokenizer' =>
array(

View file

@ -1,7 +1,7 @@
<?php
/*
* Copyright 2011 Facebook, Inc.
* Copyright 2012 Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -127,9 +127,18 @@ class HeraldRuleController extends HeraldController {
->setError($e_name)
->setValue($rule->getName()))
->appendChild(
id(new AphrontFormStaticControl())
->setLabel('Author')
->setValue($handles[$rule->getAuthorPHID()]->getName()))
id(new AphrontFormMarkupControl())
->setLabel('Owner')
->setValue('<div id="author-input"/>'))
->appendChild(
// Build this explicitly so we can add a sigil to it.
javelin_render_tag(
'input',
array(
'type' => 'hidden',
'name' => 'author',
'sigil' => 'author',
)))
->appendChild(
id(new AphrontFormMarkupControl())
->setValue(
@ -317,6 +326,11 @@ class HeraldRuleController extends HeraldController {
$actions[] = $obj;
}
$author = $request->getStr('author');
if ($author) {
$rule->setAuthorPHID($author);
}
$rule->attachConditions($conditions);
$rule->attachActions($actions);
@ -427,6 +441,8 @@ class HeraldRuleController extends HeraldController {
'template' => $this->buildTokenizerTemplates() + array(
'rules' => $all_rules,
),
'author' => array($rule->getAuthorPHID() =>
$handles[$rule->getAuthorPHID()]->getName()),
'info' => $config_info,
));
}
@ -456,6 +472,7 @@ class HeraldRuleController extends HeraldController {
}
}
$phids += array($rule->getAuthorPHID());
$handles = id(new PhabricatorObjectHandleData($phids))
->loadHandles();
return $handles;

View file

@ -25,7 +25,6 @@ phutil_require_module('phabricator', 'infrastructure/javelin/markup');
phutil_require_module('phabricator', 'view/control/tokenizer');
phutil_require_module('phabricator', 'view/form/base');
phutil_require_module('phabricator', 'view/form/control/markup');
phutil_require_module('phabricator', 'view/form/control/static');
phutil_require_module('phabricator', 'view/form/control/submit');
phutil_require_module('phabricator', 'view/form/control/text');
phutil_require_module('phabricator', 'view/form/error');

View file

@ -29,3 +29,7 @@
.herald-action-table td.target {
width: 100%;
}
#herald-rule-edit-form #author-input {
width: 300px;
}

View file

@ -65,6 +65,7 @@ JX.install('HeraldRuleEditor', {
this._renderConditions(conditions);
this._renderActions(actions);
this._renderAuthorInput();
},
members : {
@ -115,11 +116,16 @@ JX.install('HeraldRuleEditor', {
for (k in this._config.actions) {
this._config.actions[k][1] = this._getActionTarget(k);
}
rule.value = JX.JSON.stringify({
conditions: this._config.conditions,
actions: this._config.actions
});
var authorInput = JX.DOM.find(this._root, 'input', 'author');
var authorID = JX.keys(this._config.authorGetter())[0];
if (authorID) {
authorInput.value = authorID;
}
},
_getConditionValue : function(id) {
@ -236,6 +242,16 @@ JX.install('HeraldRuleEditor', {
return [input, get_fn, set_fn];
},
_renderAuthorInput : function() {
var tokenizer = this._newTokenizer('email', 1);
input = tokenizer[0];
set_fn = tokenizer[2];
set_fn(this._config.author);
this._config.authorGetter = tokenizer[1];
var author_cell = JX.$('author-input');
JX.DOM.setContent(author_cell, input);
},
_renderValueInputForRow : function(row_id) {
var cond = this._config.conditions[row_id];
var type = this._config.info.values[cond[0]][cond[1]];
@ -260,7 +276,7 @@ JX.install('HeraldRuleEditor', {
return node;
},
_newTokenizer : function(type) {
_newTokenizer : function(type, limit) {
var template = JX.$N(
'div',
JX.$H(this._config.template.markup));
@ -274,6 +290,7 @@ JX.install('HeraldRuleEditor', {
typeahead.setDatasource(datasource);
var tokenizer = new JX.Tokenizer(template);
tokenizer.setLimit(limit);
tokenizer.setTypeahead(typeahead);
tokenizer.start();