mirror of
https://we.phorge.it/source/phorge.git
synced 2025-01-17 18:21:11 +01:00
Rough cut of Herald home controller.
This commit is contained in:
parent
084c79d85a
commit
75fcf56b67
8 changed files with 284 additions and 0 deletions
44
resources/sql/patches/010.herald.sql
Normal file
44
resources/sql/patches/010.herald.sql
Normal file
|
@ -0,0 +1,44 @@
|
|||
CREATE DATABASE phabricator_herald;
|
||||
|
||||
CREATE TABLE phabricator_herald.herald_action (
|
||||
id int unsigned not null auto_increment primary key,
|
||||
ruleID int unsigned not null,
|
||||
action varchar(255) not null,
|
||||
target text not null
|
||||
);
|
||||
|
||||
CREATE TABLE phabricator_herald.herald_rule (
|
||||
id int unsigned not null auto_increment primary key,
|
||||
name varchar(255) not null,
|
||||
authorPHID varchar(64) binary not null,
|
||||
contentType varchar(255) not null,
|
||||
mustMatchAll bool not null,
|
||||
configVersion int unsigned not null default '1',
|
||||
dateCreated int unsigned not null,
|
||||
dateModified int unsigned not null,
|
||||
unique key (authorPHID, name)
|
||||
);
|
||||
|
||||
CREATE TABLE phabricator_herald.herald_condition (
|
||||
id int unsigned not null auto_increment primary key,
|
||||
ruleID int unsigned not null,
|
||||
fieldName varchar(255) not null,
|
||||
fieldCondition varchar(255) not null,
|
||||
value text not null
|
||||
);
|
||||
|
||||
CREATE TABLE phabricator_herald.herald_transcript (
|
||||
id int unsigned not null auto_increment primary key,
|
||||
phid varchar(64) binary not null,
|
||||
time int unsigned not null,
|
||||
host varchar(255) not null,
|
||||
psth varchar(255) not null,
|
||||
duration float not null,
|
||||
objectPHID varchar(64) binary not null,
|
||||
dryRun bool not null,
|
||||
objectTranscript longblob not null,
|
||||
ruleTranscripts longblob not null,
|
||||
conditionTranscripts longblob not null,
|
||||
applyTranscripts longblob not null,
|
||||
unique key (phid)
|
||||
);
|
|
@ -185,10 +185,12 @@ phutil_register_library_map(array(
|
|||
'HeraldConditionConfig' => 'applications/herald/config/condition',
|
||||
'HeraldConditionTranscript' => 'applications/herald/storage/transcript/condition',
|
||||
'HeraldContentTypeConfig' => 'applications/herald/config/contenttype',
|
||||
'HeraldController' => 'applications/herald/controller/base',
|
||||
'HeraldDAO' => 'applications/herald/storage/base',
|
||||
'HeraldEffect' => 'applications/herald/engine/effect',
|
||||
'HeraldEngine' => 'applications/herald/engine/engine',
|
||||
'HeraldFieldConfig' => 'applications/herald/config/field',
|
||||
'HeraldHomeController' => 'applications/herald/controller/home',
|
||||
'HeraldInvalidConditionException' => 'applications/herald/engine/engine/exception',
|
||||
'HeraldInvalidFieldException' => 'applications/herald/engine/engine/exception',
|
||||
'HeraldObjectTranscript' => 'applications/herald/storage/transcript/object',
|
||||
|
@ -528,7 +530,9 @@ phutil_register_library_map(array(
|
|||
'HeraldAction' => 'HeraldDAO',
|
||||
'HeraldApplyTranscript' => 'HeraldDAO',
|
||||
'HeraldCondition' => 'HeraldDAO',
|
||||
'HeraldController' => 'PhabricatorController',
|
||||
'HeraldDAO' => 'PhabricatorLiskDAO',
|
||||
'HeraldHomeController' => 'HeraldController',
|
||||
'HeraldRule' => 'HeraldDAO',
|
||||
'HeraldTranscript' => 'HeraldDAO',
|
||||
'ManiphestController' => 'PhabricatorController',
|
||||
|
|
|
@ -217,6 +217,11 @@ class AphrontDefaultApplicationConfiguration
|
|||
'$' => 'PhabricatorDaemonConsoleController',
|
||||
),
|
||||
|
||||
'/herald/' => array(
|
||||
'$' => 'HeraldHomeController',
|
||||
'view/(?P<view>[^/]+)/$' => 'HeraldHomeController',
|
||||
),
|
||||
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -27,8 +27,10 @@ class HeraldContentTypeConfig {
|
|||
static $map = array(
|
||||
self::CONTENT_TYPE_DIFFERENTIAL => 'Differential Revisions',
|
||||
self::CONTENT_TYPE_COMMIT => 'Commits',
|
||||
/* TODO: Deal with this
|
||||
self::CONTENT_TYPE_MERGE => 'Merge Requests',
|
||||
self::CONTENT_TYPE_OWNERS => 'Owners Changes',
|
||||
*/
|
||||
);
|
||||
return $map;
|
||||
}
|
||||
|
|
34
src/applications/herald/controller/base/HeraldController.php
Normal file
34
src/applications/herald/controller/base/HeraldController.php
Normal file
|
@ -0,0 +1,34 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* Copyright 2011 Facebook, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
abstract class HeraldController extends PhabricatorController {
|
||||
|
||||
public function buildStandardPageResponse($view, array $data) {
|
||||
$page = $this->buildStandardPageView();
|
||||
|
||||
$page->setApplicationName('Herald');
|
||||
$page->setBaseURI('/herald/');
|
||||
$page->setTitle(idx($data, 'title'));
|
||||
$page->setGlyph("\xE2\x98\xBF");
|
||||
$page->appendChild($view);
|
||||
|
||||
$response = new AphrontWebpageResponse();
|
||||
return $response->setContent($page->render());
|
||||
|
||||
}
|
||||
}
|
15
src/applications/herald/controller/base/__init__.php
Normal file
15
src/applications/herald/controller/base/__init__.php
Normal file
|
@ -0,0 +1,15 @@
|
|||
<?php
|
||||
/**
|
||||
* This file is automatically generated. Lint this module to rebuild it.
|
||||
* @generated
|
||||
*/
|
||||
|
||||
|
||||
|
||||
phutil_require_module('phabricator', 'aphront/response/webpage');
|
||||
phutil_require_module('phabricator', 'applications/base/controller/base');
|
||||
|
||||
phutil_require_module('phutil', 'utils');
|
||||
|
||||
|
||||
phutil_require_source('HeraldController.php');
|
161
src/applications/herald/controller/home/HeraldHomeController.php
Normal file
161
src/applications/herald/controller/home/HeraldHomeController.php
Normal file
|
@ -0,0 +1,161 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* Copyright 2011 Facebook, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
class HeraldHomeController extends HeraldController {
|
||||
|
||||
private $view;
|
||||
|
||||
public function willProcessRequest(array $data) {
|
||||
$this->view = idx($data, 'view');
|
||||
}
|
||||
|
||||
public function processRequest() {
|
||||
|
||||
$request = $this->getRequest();
|
||||
$user = $request->getUser();
|
||||
|
||||
$map = HeraldContentTypeConfig::getContentTypeMap();
|
||||
if (empty($map[$this->view])) {
|
||||
reset($map);
|
||||
$this->view = key($map);
|
||||
}
|
||||
|
||||
$rules = id(new HeraldRule())->loadAllWhere(
|
||||
'contentType = %s AND authorPHID = %s',
|
||||
$this->view,
|
||||
$user->getPHID());
|
||||
|
||||
$handles = array();
|
||||
$need_phids = mpull($rules, 'getAuthorPHID');
|
||||
|
||||
/*
|
||||
$data = new ToolsHandleData($need_fbids, $handles);
|
||||
$data->needNames();
|
||||
$data->needAlternateNames();
|
||||
prep($data);
|
||||
*/
|
||||
$type = 'differential';
|
||||
|
||||
$rows = array();
|
||||
foreach ($rules as $rule) {
|
||||
|
||||
$owner = 'owner';
|
||||
/* <a href={$handles[$rule->getOwnerID()]->getURI()}>
|
||||
{$handles[$rule->getOwnerID()]->getName()}
|
||||
</a>;
|
||||
*/
|
||||
$name = 'name';
|
||||
/* <a href={"/herald/rule/".$rule->getID()."/"}>
|
||||
{$rule->getName()}
|
||||
</a>;
|
||||
*/
|
||||
$delete = 'delete';
|
||||
|
||||
/* <a href={"/herald/delete/".$rule->getID()."/"} workflow={true}>
|
||||
Delete
|
||||
</a>;
|
||||
*/
|
||||
$rows[] = array(
|
||||
$map[$rule->getContentType()],
|
||||
$owner->toString(),
|
||||
$name->toString(),
|
||||
$delete->toString(),
|
||||
);
|
||||
}
|
||||
|
||||
$table = new AphrontTableView($rows);
|
||||
$table->setNoDataString(
|
||||
"No matching subscription rules for ".
|
||||
phutil_escape_html($map[$this->view]).".");
|
||||
|
||||
$table->setHeaders(
|
||||
array(
|
||||
'Type',
|
||||
'Owner',
|
||||
'Rule Name',
|
||||
'Delete',
|
||||
));
|
||||
$table->setColumnClasses(
|
||||
array(
|
||||
'',
|
||||
'',
|
||||
'wide wrap',
|
||||
'action'
|
||||
));
|
||||
|
||||
$items = array();
|
||||
foreach ($map as $key => $value) {
|
||||
$uri = '/herald/view/'.$key.'/';
|
||||
$items[] = 'item';
|
||||
/* <tools:nav-item href={$uri} selected={$key == $this->view}>
|
||||
{$value}
|
||||
</tools:nav-item>;
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
// require_static('herald-css');
|
||||
|
||||
// If you're viewing as an admin, this string renders in the table header.
|
||||
// $map['admin'] = 'Omniscience';
|
||||
|
||||
$sidenav = new AphrontSideNavView();
|
||||
foreach ($map as $key => $value) {
|
||||
$sidenav->addNavItem(
|
||||
phutil_render_tag(
|
||||
'a',
|
||||
array(
|
||||
'href' => '/herald/view/'.$key.'/',
|
||||
'class' => ($key == $this->view)
|
||||
? 'aphront-side-nav-selected'
|
||||
: null,
|
||||
),
|
||||
phutil_escape_html($value)));
|
||||
}
|
||||
|
||||
|
||||
$content = array();
|
||||
$content[] = 'oh hi';
|
||||
|
||||
return $this->buildStandardPageResponse(
|
||||
$sidenav,
|
||||
array(
|
||||
'title' => 'Herald',
|
||||
));
|
||||
|
||||
/*
|
||||
<herald:standard-page title="Herald"
|
||||
selectednav={:herald:standard-page::NAV_RULES}>
|
||||
<div style="padding: 1em;">
|
||||
<tools:side-nav items={$items}>
|
||||
<div class="tools-table">
|
||||
<a href={"/herald/rule/?type=".$this->view}
|
||||
class="button green"
|
||||
style="float: right;">Create New Rule</a>
|
||||
<h1>Herald Subscription Rules
|
||||
for {txt2html($map[$this->view])}</h1>
|
||||
{HTML($table->render())}
|
||||
</div>
|
||||
</tools:side-nav>
|
||||
</div>
|
||||
</herald:standard-page>;
|
||||
*/
|
||||
|
||||
}
|
||||
|
||||
}
|
19
src/applications/herald/controller/home/__init__.php
Normal file
19
src/applications/herald/controller/home/__init__.php
Normal file
|
@ -0,0 +1,19 @@
|
|||
<?php
|
||||
/**
|
||||
* This file is automatically generated. Lint this module to rebuild it.
|
||||
* @generated
|
||||
*/
|
||||
|
||||
|
||||
|
||||
phutil_require_module('phabricator', 'applications/herald/config/contenttype');
|
||||
phutil_require_module('phabricator', 'applications/herald/controller/base');
|
||||
phutil_require_module('phabricator', 'applications/herald/storage/rule');
|
||||
phutil_require_module('phabricator', 'view/control/table');
|
||||
phutil_require_module('phabricator', 'view/layout/sidenav');
|
||||
|
||||
phutil_require_module('phutil', 'markup');
|
||||
phutil_require_module('phutil', 'utils');
|
||||
|
||||
|
||||
phutil_require_source('HeraldHomeController.php');
|
Loading…
Reference in a new issue