Esempio n. 1
0
 public function render()
 {
     if ($this->flexible) {
         require_celerity_resource('phabricator-form-view-css');
     }
     require_celerity_resource('aphront-form-view-css');
     Javelin::initBehavior('aphront-form-disable-on-submit');
     $layout = new AphrontFormLayoutView();
     if (!$this->flexible) {
         $layout->setBackgroundShading(true)->setPadded(true);
     }
     $layout->appendChild($this->renderDataInputs())->appendChild($this->renderChildren());
     if (!$this->user) {
         throw new Exception('You must pass the user to AphrontFormView.');
     }
     return phabricator_render_form($this->user, array('class' => $this->flexible ? 'phabricator-form-view' : null, 'action' => $this->action, 'method' => $this->method, 'enctype' => $this->encType, 'sigil' => $this->workflow ? 'workflow' : null, 'id' => $this->id), $layout->render());
 }
 public function processRequest()
 {
     $request = $this->getRequest();
     $user = $request->getUser();
     $phid = $this->phid;
     $handle = PhabricatorObjectHandleData::loadOneHandle($phid);
     if (!$handle->isComplete()) {
         return new Aphront404Response();
     }
     $flag = PhabricatorFlagQuery::loadUserFlag($user, $phid);
     if (!$flag) {
         $flag = new PhabricatorFlag();
         $flag->setOwnerPHID($user->getPHID());
         $flag->setType($handle->getType());
         $flag->setObjectPHID($handle->getPHID());
         $flag->setReasonPHID($user->getPHID());
     }
     if ($request->isDialogFormPost()) {
         $flag->setColor($request->getInt('color'));
         $flag->setNote($request->getStr('note'));
         $flag->save();
         return id(new AphrontReloadResponse())->setURI('/flag/');
     }
     $type_name = $handle->getTypeName();
     $dialog = new AphrontDialogView();
     $dialog->setUser($user);
     $dialog->setTitle("Flag {$type_name}");
     require_celerity_resource('phabricator-flag-css');
     $form = new AphrontFormLayoutView();
     $is_new = !$flag->getID();
     if ($is_new) {
         $form->appendChild("<p>You can flag this {$type_name} if you want to remember to look " . "at it later.</p><br />");
     }
     $radio = new AphrontFormRadioButtonControl();
     foreach (PhabricatorFlagColor::getColorNameMap() as $color => $text) {
         $class = 'phabricator-flag-radio phabricator-flag-color-' . $color;
         $radio->addButton($color, $text, '', $class);
     }
     $form->appendChild($radio->setName('color')->setLabel('Flag Color')->setValue($flag->getColor()))->appendChild(id(new AphrontFormTextAreaControl())->setHeight(AphrontFormTextAreaControl::HEIGHT_VERY_SHORT)->setName('note')->setLabel('Note')->setValue($flag->getNote()));
     $dialog->appendChild($form);
     $dialog->addCancelButton($handle->getURI());
     $dialog->addSubmitButton($is_new ? "Flag {$type_name}" : 'Save');
     return id(new AphrontDialogResponse())->setDialog($dialog);
 }
 private function processGithubRequest()
 {
     $request = $this->getRequest();
     $repository = $this->repository;
     $repository_id = $repository->getID();
     $token = $repository->getDetail('github-token');
     $path = '/github-post-receive/' . $repository_id . '/' . $token . '/';
     $post_uri = PhabricatorEnv::getURI($path);
     $gitform = new AphrontFormLayoutView();
     $gitform->setBackgroundShading(true)->setPadded(true)->appendChild('<p class="aphront-form-instructions">You can configure GitHub to ' . 'notify Phabricator after changes are pushed. Log into GitHub, go ' . 'to "Admin" &rarr; "Service Hooks" &rarr; "Post-Receive URLs", and ' . 'add this URL to the list. Obviously, this will only work if your ' . 'Phabricator installation is accessible from the internet.</p>')->appendChild('<p class="aphront-form-instructions"> If things are working ' . 'properly, push notifications should appear below once you make some ' . 'commits.</p>')->appendChild(id(new AphrontFormTextControl())->setLabel('URL')->setCaption('Set this as a GitHub "Post-Receive URL".')->setValue($post_uri))->appendChild('<br /><br />')->appendChild('<h1>Recent Commit Notifications</h1>');
     $notifications = id(new PhabricatorRepositoryGitHubNotification())->loadAllWhere('repositoryPHID = %s ORDER BY id DESC limit 10', $repository->getPHID());
     $rows = array();
     foreach ($notifications as $notification) {
         $rows[] = array(phutil_escape_html($notification->getRemoteAddress()), phabricator_format_timestamp($notification->getDateCreated()), $notification->getPayload() ? phutil_escape_html(substr($notification->getPayload(), 0, 32) . '...') : 'Empty');
     }
     $notification_table = new AphrontTableView($rows);
     $notification_table->setHeaders(array('Remote Address', 'Received', 'Payload'));
     $notification_table->setColumnClasses(array(null, null, 'wide'));
     $notification_table->setNoDataString('Phabricator has not yet received any commit notifications for this ' . 'repository from GitHub.');
     $gitform->appendChild($notification_table);
     $github = new AphrontPanelView();
     $github->setHeader('GitHub Integration');
     $github->appendChild($gitform);
     $github->setWidth(AphrontPanelView::WIDTH_FORM);
     $nav = $this->sideNav;
     $nav->appendChild($github);
     return $this->buildStandardPageResponse($nav, array('title' => 'Repository Github Integration'));
 }