1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-22 14:52:41 +01:00

Provide a rudimentary "Attached Files" curtain UI panel

Summary: Ref T13682. Provide a basic UI element for showing file attached to an object.

Test Plan: Viewed objects with attached files in the UI.

Maniphest Tasks: T13682

Differential Revision: https://secure.phabricator.com/D21836
This commit is contained in:
epriestley 2022-05-23 10:12:16 -07:00
parent 5033ef6f88
commit 021e5ab933
4 changed files with 156 additions and 0 deletions

View file

@ -3508,6 +3508,7 @@ phutil_register_library_map(array(
'PhabricatorFileTransformController' => 'applications/files/controller/PhabricatorFileTransformController.php',
'PhabricatorFileTransformListController' => 'applications/files/controller/PhabricatorFileTransformListController.php',
'PhabricatorFileTransformTestCase' => 'applications/files/transform/__tests__/PhabricatorFileTransformTestCase.php',
'PhabricatorFileUICurtainListController' => 'applications/files/controller/PhabricatorFileUICurtainListController.php',
'PhabricatorFileUploadController' => 'applications/files/controller/PhabricatorFileUploadController.php',
'PhabricatorFileUploadDialogController' => 'applications/files/controller/PhabricatorFileUploadDialogController.php',
'PhabricatorFileUploadException' => 'applications/files/exception/PhabricatorFileUploadException.php',
@ -3521,6 +3522,7 @@ phutil_register_library_map(array(
'PhabricatorFilesComposeAvatarBuiltinFile' => 'applications/files/builtin/PhabricatorFilesComposeAvatarBuiltinFile.php',
'PhabricatorFilesComposeIconBuiltinFile' => 'applications/files/builtin/PhabricatorFilesComposeIconBuiltinFile.php',
'PhabricatorFilesConfigOptions' => 'applications/files/config/PhabricatorFilesConfigOptions.php',
'PhabricatorFilesCurtainExtension' => 'applications/files/engineextension/PhabricatorFilesCurtainExtension.php',
'PhabricatorFilesManagementCatWorkflow' => 'applications/files/management/PhabricatorFilesManagementCatWorkflow.php',
'PhabricatorFilesManagementCompactWorkflow' => 'applications/files/management/PhabricatorFilesManagementCompactWorkflow.php',
'PhabricatorFilesManagementCycleWorkflow' => 'applications/files/management/PhabricatorFilesManagementCycleWorkflow.php',
@ -9970,6 +9972,7 @@ phutil_register_library_map(array(
'PhabricatorFileTransformController' => 'PhabricatorFileController',
'PhabricatorFileTransformListController' => 'PhabricatorFileController',
'PhabricatorFileTransformTestCase' => 'PhabricatorTestCase',
'PhabricatorFileUICurtainListController' => 'PhabricatorFileController',
'PhabricatorFileUploadController' => 'PhabricatorFileController',
'PhabricatorFileUploadDialogController' => 'PhabricatorFileController',
'PhabricatorFileUploadException' => 'Exception',
@ -9983,6 +9986,7 @@ phutil_register_library_map(array(
'PhabricatorFilesComposeAvatarBuiltinFile' => 'PhabricatorFilesBuiltinFile',
'PhabricatorFilesComposeIconBuiltinFile' => 'PhabricatorFilesBuiltinFile',
'PhabricatorFilesConfigOptions' => 'PhabricatorApplicationConfigOptions',
'PhabricatorFilesCurtainExtension' => 'PHUICurtainExtension',
'PhabricatorFilesManagementCatWorkflow' => 'PhabricatorFilesManagementWorkflow',
'PhabricatorFilesManagementCompactWorkflow' => 'PhabricatorFilesManagementWorkflow',
'PhabricatorFilesManagementCycleWorkflow' => 'PhabricatorFilesManagementWorkflow',

View file

@ -95,6 +95,8 @@ final class PhabricatorFilesApplication extends PhabricatorApplication {
),
'document/(?P<engineKey>[^/]+)/(?P<phid>[^/]+)/'
=> 'PhabricatorFileDocumentController',
'ui/curtainlist/(?P<phid>[^/]+)/'
=> 'PhabricatorFileUICurtainListController',
) + $this->getResourceSubroutes(),
);
}

View file

@ -0,0 +1,61 @@
<?php
final class PhabricatorFileUICurtainListController
extends PhabricatorFileController {
public function shouldAllowPublic() {
return true;
}
public function handleRequest(AphrontRequest $request) {
$viewer = $request->getViewer();
$object_phid = $request->getURIData('phid');
$object = id(new PhabricatorObjectQuery())
->setViewer($viewer)
->withPHIDs(array($object_phid))
->executeOne();
if (!$object) {
return new Aphront404Response();
}
$attachments = id(new PhabricatorFileAttachmentQuery())
->setViewer($viewer)
->withObjectPHIDs(array($object->getPHID()))
->needFiles(true)
->execute();
$handles = $viewer->loadHandles(array($object_phid));
$object_handle = $handles[$object_phid];
$file_phids = mpull($attachments, 'getFilePHID');
$file_handles = $viewer->loadHandles($file_phids);
$list = id(new PHUIObjectItemListView())
->setUser($viewer);
foreach ($attachments as $attachment) {
$file_phid = $attachment->getFilePHID();
$handle = $file_handles[$file_phid];
$item = id(new PHUIObjectItemView())
->setHeader($handle->getFullName())
->setHref($handle->getURI())
->setDisabled($handle->isDisabled());
if ($handle->getImageURI()) {
$item->setImageURI($handle->getImageURI());
}
$list->addItem($item);
}
return $this->newDialog()
->setViewer($viewer)
->setWidth(AphrontDialogView::WIDTH_FORM)
->setTitle(pht('Attached Files'))
->setObjectList($list)
->addCancelButton($object_handle->getURI(), pht('Close'));
}
}

View file

@ -0,0 +1,89 @@
<?php
final class PhabricatorFilesCurtainExtension
extends PHUICurtainExtension {
const EXTENSIONKEY = 'files.files';
public function shouldEnableForObject($object) {
return true;
}
public function getExtensionApplication() {
return new PhabricatorFilesApplication();
}
public function buildCurtainPanel($object) {
$viewer = $this->getViewer();
$attachment_table = new PhabricatorFileAttachment();
$attachment_conn = $attachment_table->establishConnection('r');
$exact_limit = 100;
$visible_limit = 8;
$attachments = id(new PhabricatorFileAttachmentQuery())
->setViewer($viewer)
->withObjectPHIDs(array($object->getPHID()))
->setLimit($exact_limit + 1)
->needFiles(true)
->execute();
$visible_attachments = array_slice($attachments, 0, $visible_limit, true);
$visible_phids = mpull($visible_attachments, 'getFilePHID');
$handles = $viewer->loadHandles($visible_phids);
PhabricatorPolicyFilterSet::loadHandleViewCapabilities(
$viewer,
$handles,
array($object));
$ref_list = id(new PHUICurtainObjectRefListView())
->setViewer($viewer)
->setEmptyMessage(pht('None'));
foreach ($visible_attachments as $attachment) {
$file_phid = $attachment->getFilePHID();
$handle = $handles[$file_phid];
$ref = $ref_list->newObjectRefView()
->setHandle($handle);
if ($handle->hasCapabilities()) {
if (!$handle->hasViewCapability($object)) {
$ref->setExiled(true);
}
}
$epoch = $attachment->getDateCreated();
$ref->setEpoch($epoch);
}
$show_all = (count($visible_attachments) < count($attachments));
if ($show_all) {
$view_all_uri = urisprintf(
'/file/ui/curtainlist/%s/',
$object->getPHID());
$loaded_count = count($attachments);
if ($loaded_count > $exact_limit) {
$link_text = pht('View All Files');
} else {
$link_text = pht('View All %d Files', new PhutilNumber($loaded_count));
}
$ref_list->newTailLink()
->setURI($view_all_uri)
->setText($link_text)
->setWorkflow(true);
}
return $this->newPanel()
->setHeaderText(pht('Attached Files'))
->setOrder(15000)
->appendChild($ref_list);
}
}