Skip to content

Commit 021e5ab

Browse files
author
epriestley
committedMay 23, 2022
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
1 parent 5033ef6 commit 021e5ab

File tree

4 files changed

+156
-0
lines changed

4 files changed

+156
-0
lines changed
 

‎src/__phutil_library_map__.php

+4
Original file line numberDiff line numberDiff line change
@@ -3508,6 +3508,7 @@
35083508
'PhabricatorFileTransformController' => 'applications/files/controller/PhabricatorFileTransformController.php',
35093509
'PhabricatorFileTransformListController' => 'applications/files/controller/PhabricatorFileTransformListController.php',
35103510
'PhabricatorFileTransformTestCase' => 'applications/files/transform/__tests__/PhabricatorFileTransformTestCase.php',
3511+
'PhabricatorFileUICurtainListController' => 'applications/files/controller/PhabricatorFileUICurtainListController.php',
35113512
'PhabricatorFileUploadController' => 'applications/files/controller/PhabricatorFileUploadController.php',
35123513
'PhabricatorFileUploadDialogController' => 'applications/files/controller/PhabricatorFileUploadDialogController.php',
35133514
'PhabricatorFileUploadException' => 'applications/files/exception/PhabricatorFileUploadException.php',
@@ -3521,6 +3522,7 @@
35213522
'PhabricatorFilesComposeAvatarBuiltinFile' => 'applications/files/builtin/PhabricatorFilesComposeAvatarBuiltinFile.php',
35223523
'PhabricatorFilesComposeIconBuiltinFile' => 'applications/files/builtin/PhabricatorFilesComposeIconBuiltinFile.php',
35233524
'PhabricatorFilesConfigOptions' => 'applications/files/config/PhabricatorFilesConfigOptions.php',
3525+
'PhabricatorFilesCurtainExtension' => 'applications/files/engineextension/PhabricatorFilesCurtainExtension.php',
35243526
'PhabricatorFilesManagementCatWorkflow' => 'applications/files/management/PhabricatorFilesManagementCatWorkflow.php',
35253527
'PhabricatorFilesManagementCompactWorkflow' => 'applications/files/management/PhabricatorFilesManagementCompactWorkflow.php',
35263528
'PhabricatorFilesManagementCycleWorkflow' => 'applications/files/management/PhabricatorFilesManagementCycleWorkflow.php',
@@ -9970,6 +9972,7 @@
99709972
'PhabricatorFileTransformController' => 'PhabricatorFileController',
99719973
'PhabricatorFileTransformListController' => 'PhabricatorFileController',
99729974
'PhabricatorFileTransformTestCase' => 'PhabricatorTestCase',
9975+
'PhabricatorFileUICurtainListController' => 'PhabricatorFileController',
99739976
'PhabricatorFileUploadController' => 'PhabricatorFileController',
99749977
'PhabricatorFileUploadDialogController' => 'PhabricatorFileController',
99759978
'PhabricatorFileUploadException' => 'Exception',
@@ -9983,6 +9986,7 @@
99839986
'PhabricatorFilesComposeAvatarBuiltinFile' => 'PhabricatorFilesBuiltinFile',
99849987
'PhabricatorFilesComposeIconBuiltinFile' => 'PhabricatorFilesBuiltinFile',
99859988
'PhabricatorFilesConfigOptions' => 'PhabricatorApplicationConfigOptions',
9989+
'PhabricatorFilesCurtainExtension' => 'PHUICurtainExtension',
99869990
'PhabricatorFilesManagementCatWorkflow' => 'PhabricatorFilesManagementWorkflow',
99879991
'PhabricatorFilesManagementCompactWorkflow' => 'PhabricatorFilesManagementWorkflow',
99889992
'PhabricatorFilesManagementCycleWorkflow' => 'PhabricatorFilesManagementWorkflow',

‎src/applications/files/application/PhabricatorFilesApplication.php

+2
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ public function getRoutes() {
9595
),
9696
'document/(?P<engineKey>[^/]+)/(?P<phid>[^/]+)/'
9797
=> 'PhabricatorFileDocumentController',
98+
'ui/curtainlist/(?P<phid>[^/]+)/'
99+
=> 'PhabricatorFileUICurtainListController',
98100
) + $this->getResourceSubroutes(),
99101
);
100102
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<?php
2+
3+
final class PhabricatorFileUICurtainListController
4+
extends PhabricatorFileController {
5+
6+
public function shouldAllowPublic() {
7+
return true;
8+
}
9+
10+
public function handleRequest(AphrontRequest $request) {
11+
$viewer = $request->getViewer();
12+
13+
$object_phid = $request->getURIData('phid');
14+
15+
$object = id(new PhabricatorObjectQuery())
16+
->setViewer($viewer)
17+
->withPHIDs(array($object_phid))
18+
->executeOne();
19+
if (!$object) {
20+
return new Aphront404Response();
21+
}
22+
23+
$attachments = id(new PhabricatorFileAttachmentQuery())
24+
->setViewer($viewer)
25+
->withObjectPHIDs(array($object->getPHID()))
26+
->needFiles(true)
27+
->execute();
28+
29+
$handles = $viewer->loadHandles(array($object_phid));
30+
$object_handle = $handles[$object_phid];
31+
32+
$file_phids = mpull($attachments, 'getFilePHID');
33+
$file_handles = $viewer->loadHandles($file_phids);
34+
35+
$list = id(new PHUIObjectItemListView())
36+
->setUser($viewer);
37+
foreach ($attachments as $attachment) {
38+
$file_phid = $attachment->getFilePHID();
39+
$handle = $file_handles[$file_phid];
40+
41+
$item = id(new PHUIObjectItemView())
42+
->setHeader($handle->getFullName())
43+
->setHref($handle->getURI())
44+
->setDisabled($handle->isDisabled());
45+
46+
if ($handle->getImageURI()) {
47+
$item->setImageURI($handle->getImageURI());
48+
}
49+
50+
$list->addItem($item);
51+
}
52+
53+
return $this->newDialog()
54+
->setViewer($viewer)
55+
->setWidth(AphrontDialogView::WIDTH_FORM)
56+
->setTitle(pht('Attached Files'))
57+
->setObjectList($list)
58+
->addCancelButton($object_handle->getURI(), pht('Close'));
59+
}
60+
61+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
<?php
2+
3+
final class PhabricatorFilesCurtainExtension
4+
extends PHUICurtainExtension {
5+
6+
const EXTENSIONKEY = 'files.files';
7+
8+
public function shouldEnableForObject($object) {
9+
return true;
10+
}
11+
12+
public function getExtensionApplication() {
13+
return new PhabricatorFilesApplication();
14+
}
15+
16+
public function buildCurtainPanel($object) {
17+
$viewer = $this->getViewer();
18+
19+
$attachment_table = new PhabricatorFileAttachment();
20+
$attachment_conn = $attachment_table->establishConnection('r');
21+
22+
$exact_limit = 100;
23+
$visible_limit = 8;
24+
25+
$attachments = id(new PhabricatorFileAttachmentQuery())
26+
->setViewer($viewer)
27+
->withObjectPHIDs(array($object->getPHID()))
28+
->setLimit($exact_limit + 1)
29+
->needFiles(true)
30+
->execute();
31+
32+
$visible_attachments = array_slice($attachments, 0, $visible_limit, true);
33+
$visible_phids = mpull($visible_attachments, 'getFilePHID');
34+
35+
$handles = $viewer->loadHandles($visible_phids);
36+
37+
PhabricatorPolicyFilterSet::loadHandleViewCapabilities(
38+
$viewer,
39+
$handles,
40+
array($object));
41+
42+
$ref_list = id(new PHUICurtainObjectRefListView())
43+
->setViewer($viewer)
44+
->setEmptyMessage(pht('None'));
45+
46+
foreach ($visible_attachments as $attachment) {
47+
$file_phid = $attachment->getFilePHID();
48+
$handle = $handles[$file_phid];
49+
50+
$ref = $ref_list->newObjectRefView()
51+
->setHandle($handle);
52+
53+
if ($handle->hasCapabilities()) {
54+
if (!$handle->hasViewCapability($object)) {
55+
$ref->setExiled(true);
56+
}
57+
}
58+
59+
$epoch = $attachment->getDateCreated();
60+
$ref->setEpoch($epoch);
61+
}
62+
63+
$show_all = (count($visible_attachments) < count($attachments));
64+
if ($show_all) {
65+
$view_all_uri = urisprintf(
66+
'/file/ui/curtainlist/%s/',
67+
$object->getPHID());
68+
69+
$loaded_count = count($attachments);
70+
if ($loaded_count > $exact_limit) {
71+
$link_text = pht('View All Files');
72+
} else {
73+
$link_text = pht('View All %d Files', new PhutilNumber($loaded_count));
74+
}
75+
76+
$ref_list->newTailLink()
77+
->setURI($view_all_uri)
78+
->setText($link_text)
79+
->setWorkflow(true);
80+
}
81+
82+
return $this->newPanel()
83+
->setHeaderText(pht('Attached Files'))
84+
->setOrder(15000)
85+
->appendChild($ref_list);
86+
}
87+
88+
89+
}

0 commit comments

Comments
 (0)
Failed to load comments.