@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
at recaptime-dev/main 172 lines 4.6 kB view raw
1<?php 2 3final class PhabricatorProjectBoardBackgroundController 4 extends PhabricatorProjectBoardController { 5 6 public function handleRequest(AphrontRequest $request) { 7 $viewer = $request->getUser(); 8 $board_id = $request->getURIData('projectID'); 9 10 $board = id(new PhabricatorProjectQuery()) 11 ->setViewer($viewer) 12 ->withIDs(array($board_id)) 13 ->needImages(true) 14 ->requireCapabilities( 15 array( 16 PhabricatorPolicyCapability::CAN_VIEW, 17 PhabricatorPolicyCapability::CAN_EDIT, 18 )) 19 ->executeOne(); 20 if (!$board) { 21 return new Aphront404Response(); 22 } 23 24 if (!$board->getHasWorkboard()) { 25 return new Aphront404Response(); 26 } 27 28 $this->setProject($board); 29 $id = $board->getID(); 30 31 $view_uri = $this->getApplicationURI("board/{$id}/"); 32 $manage_uri = $this->getApplicationURI("board/{$id}/manage/"); 33 34 if ($request->isFormPost()) { 35 $background_key = $request->getStr('backgroundKey'); 36 37 $xactions = array(); 38 39 $xactions[] = id(new PhabricatorProjectTransaction()) 40 ->setTransactionType( 41 PhabricatorProjectWorkboardBackgroundTransaction::TRANSACTIONTYPE) 42 ->setNewValue($background_key); 43 44 id(new PhabricatorProjectTransactionEditor()) 45 ->setActor($viewer) 46 ->setContentSourceFromRequest($request) 47 ->setContinueOnNoEffect(true) 48 ->setContinueOnMissingFields(true) 49 ->applyTransactions($board, $xactions); 50 51 return id(new AphrontRedirectResponse()) 52 ->setURI($view_uri); 53 } 54 55 $nav = $this->newNavigation( 56 $board, 57 PhabricatorProject::ITEM_WORKBOARD); 58 59 $crumbs = id($this->buildApplicationCrumbs()) 60 ->addTextCrumb(pht('Workboard'), $board->getWorkboardURI()) 61 ->addTextCrumb(pht('Manage'), $manage_uri) 62 ->addTextCrumb(pht('Background Color')); 63 64 $form = id(new AphrontFormView()) 65 ->setUser($viewer); 66 67 $group_info = array( 68 'basic' => array( 69 'label' => pht('Basics'), 70 ), 71 'solid' => array( 72 'label' => pht('Solid Colors'), 73 ), 74 'gradient' => array( 75 'label' => pht('Gradients'), 76 ), 77 ); 78 79 $groups = array(); 80 $options = PhabricatorProjectWorkboardBackgroundColor::getOptions(); 81 $option_groups = igroup($options, 'group'); 82 83 require_celerity_resource('people-profile-css'); 84 require_celerity_resource('phui-workboard-color-css'); 85 Javelin::initBehavior('phabricator-tooltips', array()); 86 87 foreach ($group_info as $group_key => $spec) { 88 $buttons = array(); 89 90 $available_options = idx($option_groups, $group_key, array()); 91 foreach ($available_options as $option) { 92 $buttons[] = $this->renderOptionButton($option); 93 } 94 95 $form->appendControl( 96 id(new AphrontFormMarkupControl()) 97 ->setLabel($spec['label']) 98 ->setValue($buttons)); 99 } 100 101 // NOTE: Each button is its own form, so we can't wrap them in a normal 102 // form. 103 $layout_view = $form->buildLayoutView(); 104 105 $form_box = id(new PHUIObjectBoxView()) 106 ->setHeaderText(pht('Edit Background Color')) 107 ->appendChild($layout_view); 108 109 return $this->newPage() 110 ->setTitle( 111 array( 112 pht('Edit Background Color'), 113 $board->getDisplayName(), 114 )) 115 ->setCrumbs($crumbs) 116 ->setNavigation($nav) 117 ->appendChild($form_box); 118 } 119 120 private function renderOptionButton(array $option) { 121 $viewer = $this->getViewer(); 122 123 $icon = idx($option, 'icon'); 124 if ($icon) { 125 $preview_class = null; 126 $preview_content = id(new PHUIIconView()) 127 ->setIcon($icon, 'lightbluetext'); 128 } else { 129 $preview_class = 'phui-workboard-'.$option['key']; 130 $preview_content = null; 131 } 132 133 $preview = phutil_tag( 134 'div', 135 array( 136 'class' => 'phui-workboard-color-preview '.$preview_class, 137 ), 138 $preview_content); 139 140 $button = javelin_tag( 141 'button', 142 array( 143 'class' => 'button-grey profile-image-button', 144 'sigil' => 'has-tooltip', 145 'meta' => array( 146 'tip' => $option['name'], 147 'size' => 300, 148 ), 149 ), 150 $preview); 151 152 $input = phutil_tag( 153 'input', 154 array( 155 'type' => 'hidden', 156 'name' => 'backgroundKey', 157 'value' => $option['key'], 158 )); 159 160 return phabricator_form( 161 $viewer, 162 array( 163 'class' => 'profile-image-form', 164 'method' => 'POST', 165 ), 166 array( 167 $button, 168 $input, 169 )); 170 } 171 172}