Differential D19617 Diff 46896 src/applications/phriction/controller/PhrictionDocumentController.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/phriction/controller/PhrictionDocumentController.php
| Show First 20 Lines • Show All 195 Lines • ▼ Show 20 Lines | if (!$document) { | ||||
| $move_notice->appendChild( | $move_notice->appendChild( | ||||
| pht('This document was moved from elsewhere.')); | pht('This document was moved from elsewhere.')); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| $children = $this->renderDocumentChildren($slug); | $children = $this->renderDocumentChildren($slug); | ||||
| $actions = $this->buildActionView($viewer, $document); | $curtain = null; | ||||
| if ($document->getID()) { | |||||
| $curtain = $this->buildCurtain($document); | |||||
| } | |||||
| $crumbs = $this->buildApplicationCrumbs(); | $crumbs = $this->buildApplicationCrumbs(); | ||||
| $crumbs->setBorder(true); | $crumbs->setBorder(true); | ||||
| $crumb_views = $this->renderBreadcrumbs($slug); | $crumb_views = $this->renderBreadcrumbs($slug); | ||||
| foreach ($crumb_views as $view) { | foreach ($crumb_views as $view) { | ||||
| $crumbs->addCrumb($view); | $crumbs->addCrumb($view); | ||||
| } | } | ||||
| $header = id(new PHUIHeaderView()) | $header = id(new PHUIHeaderView()) | ||||
| ->setUser($viewer) | ->setUser($viewer) | ||||
| ->setPolicyObject($document) | ->setPolicyObject($document) | ||||
| ->setHeader($page_title) | ->setHeader($page_title); | ||||
| ->setActionList($actions); | |||||
| if ($content) { | if ($content) { | ||||
| $header->setEpoch($content->getDateCreated()); | $header->setEpoch($content->getDateCreated()); | ||||
| } | } | ||||
| $prop_list = null; | $prop_list = null; | ||||
| if ($properties) { | if ($properties) { | ||||
| $prop_list = new PHUIPropertyGroupView(); | $prop_list = new PHUIPropertyGroupView(); | ||||
| $prop_list->addPropertyList($properties); | $prop_list->addPropertyList($properties); | ||||
| } | } | ||||
| $prop_list = phutil_tag_div('phui-document-view-pro-box', $prop_list); | $prop_list = phutil_tag_div('phui-document-view-pro-box', $prop_list); | ||||
| $page_content = id(new PHUIDocumentView()) | $page_content = id(new PHUIDocumentView()) | ||||
| ->setHeader($header) | ->setHeader($header) | ||||
| ->setToc($toc) | ->setToc($toc) | ||||
| ->appendChild( | ->appendChild( | ||||
| array( | array( | ||||
| $version_note, | $version_note, | ||||
| $move_notice, | $move_notice, | ||||
| $core_content, | $core_content, | ||||
| )); | )); | ||||
| if ($curtain) { | |||||
| $page_content->setCurtain($curtain); | |||||
| } | |||||
| return $this->newPage() | return $this->newPage() | ||||
| ->setTitle($page_title) | ->setTitle($page_title) | ||||
| ->setCrumbs($crumbs) | ->setCrumbs($crumbs) | ||||
| ->setPageObjectPHIDs(array($document->getPHID())) | ->setPageObjectPHIDs(array($document->getPHID())) | ||||
| ->appendChild( | ->appendChild( | ||||
| array( | array( | ||||
| $page_content, | $page_content, | ||||
| $prop_list, | $prop_list, | ||||
| $children, | $children, | ||||
| )); | )); | ||||
| } | } | ||||
| private function buildPropertyListView( | private function buildPropertyListView( | ||||
| PhrictionDocument $document, | PhrictionDocument $document, | ||||
| PhrictionContent $content, | PhrictionContent $content, | ||||
| $slug) { | $slug) { | ||||
| $viewer = $this->getViewer(); | $viewer = $this->getViewer(); | ||||
| $view = id(new PHUIPropertyListView()) | $view = id(new PHUIPropertyListView()) | ||||
| ->setUser($viewer) | ->setUser($viewer); | ||||
| ->setObject($document); | |||||
| $view->addProperty( | $view->addProperty( | ||||
| pht('Last Author'), | pht('Last Author'), | ||||
| $viewer->renderHandle($content->getAuthorPHID())); | $viewer->renderHandle($content->getAuthorPHID())); | ||||
| $view->addProperty( | $view->addProperty( | ||||
| pht('Last Edited'), | pht('Last Edited'), | ||||
| phabricator_datetime($content->getDateCreated(), $viewer)); | phabricator_datetime($content->getDateCreated(), $viewer)); | ||||
| return $view; | return $view; | ||||
| } | } | ||||
| private function buildActionView( | private function buildCurtain(PhrictionDocument $document) { | ||||
| PhabricatorUser $viewer, | $viewer = $this->getViewer(); | ||||
| PhrictionDocument $document) { | |||||
| $can_edit = PhabricatorPolicyFilter::hasCapability( | $can_edit = PhabricatorPolicyFilter::hasCapability( | ||||
| $viewer, | $viewer, | ||||
| $document, | $document, | ||||
| PhabricatorPolicyCapability::CAN_EDIT); | PhabricatorPolicyCapability::CAN_EDIT); | ||||
| $slug = PhabricatorSlug::normalize($this->slug); | $slug = PhabricatorSlug::normalize($this->slug); | ||||
| $action_view = id(new PhabricatorActionListView()) | $curtain = $this->newCurtainView($document); | ||||
| ->setUser($viewer) | |||||
| ->setObject($document); | |||||
| if (!$document->getID()) { | $curtain->addAction( | ||||
| return $action_view->addAction( | |||||
| id(new PhabricatorActionView()) | |||||
| ->setName(pht('Create This Document')) | |||||
| ->setIcon('fa-plus-square') | |||||
| ->setHref('/phriction/edit/?slug='.$slug)); | |||||
| } | |||||
| $action_view->addAction( | |||||
| id(new PhabricatorActionView()) | id(new PhabricatorActionView()) | ||||
| ->setName(pht('Edit Document')) | ->setName(pht('Edit Document')) | ||||
| ->setDisabled(!$can_edit) | ->setDisabled(!$can_edit) | ||||
| ->setIcon('fa-pencil') | ->setIcon('fa-pencil') | ||||
| ->setHref('/phriction/edit/'.$document->getID().'/')); | ->setHref('/phriction/edit/'.$document->getID().'/')); | ||||
| if ($document->getStatus() == PhrictionDocumentStatus::STATUS_EXISTS) { | if ($document->getStatus() == PhrictionDocumentStatus::STATUS_EXISTS) { | ||||
| $action_view->addAction( | $curtain->addAction( | ||||
| id(new PhabricatorActionView()) | id(new PhabricatorActionView()) | ||||
| ->setName(pht('Move Document')) | ->setName(pht('Move Document')) | ||||
| ->setDisabled(!$can_edit) | ->setDisabled(!$can_edit) | ||||
| ->setIcon('fa-arrows') | ->setIcon('fa-arrows') | ||||
| ->setHref('/phriction/move/'.$document->getID().'/') | ->setHref('/phriction/move/'.$document->getID().'/') | ||||
| ->setWorkflow(true)); | ->setWorkflow(true)); | ||||
| $action_view->addAction( | $curtain->addAction( | ||||
| id(new PhabricatorActionView()) | id(new PhabricatorActionView()) | ||||
| ->setName(pht('Delete Document')) | ->setName(pht('Delete Document')) | ||||
| ->setDisabled(!$can_edit) | ->setDisabled(!$can_edit) | ||||
| ->setIcon('fa-times') | ->setIcon('fa-times') | ||||
| ->setHref('/phriction/delete/'.$document->getID().'/') | ->setHref('/phriction/delete/'.$document->getID().'/') | ||||
| ->setWorkflow(true)); | ->setWorkflow(true)); | ||||
| } | } | ||||
| $action_view->addAction( | $curtain->addAction( | ||||
| id(new PhabricatorActionView()) | id(new PhabricatorActionView()) | ||||
| ->setName(pht('View History')) | ->setName(pht('View History')) | ||||
| ->setIcon('fa-list') | ->setIcon('fa-list') | ||||
| ->setHref(PhrictionDocument::getSlugURI($slug, 'history'))); | ->setHref(PhrictionDocument::getSlugURI($slug, 'history'))); | ||||
| $print_uri = PhrictionDocument::getSlugURI($slug).'?__print__=1'; | $print_uri = PhrictionDocument::getSlugURI($slug).'?__print__=1'; | ||||
| $action_view->addAction( | $curtain->addAction( | ||||
| id(new PhabricatorActionView()) | id(new PhabricatorActionView()) | ||||
| ->setName(pht('Printable Page')) | ->setName(pht('Printable Page')) | ||||
| ->setIcon('fa-print') | ->setIcon('fa-print') | ||||
| ->setOpenInNewWindow(true) | ->setOpenInNewWindow(true) | ||||
| ->setHref($print_uri)); | ->setHref($print_uri)); | ||||
| return $action_view; | return $curtain; | ||||
| } | } | ||||
| private function renderDocumentChildren($slug) { | private function renderDocumentChildren($slug) { | ||||
| $d_child = PhabricatorSlug::getDepth($slug) + 1; | $d_child = PhabricatorSlug::getDepth($slug) + 1; | ||||
| $d_grandchild = PhabricatorSlug::getDepth($slug) + 2; | $d_grandchild = PhabricatorSlug::getDepth($slug) + 2; | ||||
| $limit = 250; | $limit = 250; | ||||
| ▲ Show 20 Lines • Show All 158 Lines • Show Last 20 Lines | |||||