Drag-drop file upload.
Summary: - have files be uploaded by drag+drop instead of browse. - Files are named by their uploaded filename, the user isn't given a chance to enter a file name. Is this bad? - Store author PHID now with files - Allow an ?author=<username> to limit the /files/ list by author. - If one file is uploaded, the user is taken to its info page. - If several are uploaded, they are taken to a list of their files. Test Plan: - Quickly tested everything and it still worked, I'd recommend some people try this out before it gets committed though. It's a rather huge revision. Reviewers: epriestley, Ttech CC: Differential Revision: 612
This commit is contained in:
@@ -20,6 +20,7 @@ class PhabricatorFileDropUploadController extends PhabricatorFileController {
|
||||
|
||||
public function processRequest() {
|
||||
$request = $this->getRequest();
|
||||
$user = $request->getUser();
|
||||
|
||||
$data = file_get_contents('php://input');
|
||||
$name = $request->getStr('name');
|
||||
@@ -28,6 +29,7 @@ class PhabricatorFileDropUploadController extends PhabricatorFileController {
|
||||
$data,
|
||||
array(
|
||||
'name' => $request->getStr('name'),
|
||||
'authorPHID' => $user->getPHID(),
|
||||
));
|
||||
|
||||
$view = new AphrontAttachedFileView();
|
||||
|
||||
@@ -22,13 +22,32 @@ class PhabricatorFileListController extends PhabricatorFileController {
|
||||
|
||||
$request = $this->getRequest();
|
||||
|
||||
$author_username = $request->getStr('author');
|
||||
if ($author_username) {
|
||||
$author = id(new PhabricatorUser())->loadOneWhere(
|
||||
'userName = %s',
|
||||
$author_username);
|
||||
|
||||
if (!$author) {
|
||||
return id(new Aphront404Response());
|
||||
}
|
||||
}
|
||||
|
||||
$pager = new AphrontPagerView();
|
||||
$pager->setOffset($request->getInt('page'));
|
||||
|
||||
$files = id(new PhabricatorFile())->loadAllWhere(
|
||||
'1 = 1 ORDER BY id DESC LIMIT %d, %d',
|
||||
$pager->getOffset(),
|
||||
$pager->getPageSize() + 1);
|
||||
if ($author) {
|
||||
$files = id(new PhabricatorFile())->loadAllWhere(
|
||||
'authorPHID = %s ORDER BY id DESC LIMIT %d, %d',
|
||||
$author->getPHID(),
|
||||
$pager->getOffset(),
|
||||
$pager->getPageSize() + 1);
|
||||
} else {
|
||||
$files = id(new PhabricatorFile())->loadAllWhere(
|
||||
'1 = 1 ORDER BY id DESC LIMIT %d, %d',
|
||||
$pager->getOffset(),
|
||||
$pager->getPageSize() + 1);
|
||||
}
|
||||
|
||||
$files = $pager->sliceResults($files);
|
||||
$pager->setURI($request->getRequestURI(), 'page');
|
||||
|
||||
@@ -6,8 +6,10 @@
|
||||
|
||||
|
||||
|
||||
phutil_require_module('phabricator', 'aphront/response/404');
|
||||
phutil_require_module('phabricator', 'applications/files/controller/base');
|
||||
phutil_require_module('phabricator', 'applications/files/storage/file');
|
||||
phutil_require_module('phabricator', 'applications/people/storage/user');
|
||||
phutil_require_module('phabricator', 'view/control/pager');
|
||||
phutil_require_module('phabricator', 'view/control/table');
|
||||
phutil_require_module('phabricator', 'view/layout/panel');
|
||||
|
||||
@@ -39,6 +39,7 @@ class PhabricatorFileMacroEditController extends PhabricatorFileController {
|
||||
$e_name = true;
|
||||
|
||||
$request = $this->getRequest();
|
||||
$user = $request->getUser();
|
||||
if ($request->isFormPost()) {
|
||||
|
||||
$macro->setName($request->getStr('name'));
|
||||
@@ -60,6 +61,7 @@ class PhabricatorFileMacroEditController extends PhabricatorFileController {
|
||||
idx($_FILES, 'file'),
|
||||
array(
|
||||
'name' => $request->getStr('name'),
|
||||
'authorPHID' => $user->getPHID(),
|
||||
));
|
||||
$macro->setFilePHID($file->getPHID());
|
||||
|
||||
|
||||
@@ -21,43 +21,47 @@ class PhabricatorFileUploadController extends PhabricatorFileController {
|
||||
public function processRequest() {
|
||||
|
||||
$request = $this->getRequest();
|
||||
if ($request->isFormPost()) {
|
||||
$file = PhabricatorFile::newFromPHPUpload(
|
||||
idx($_FILES, 'file'),
|
||||
array(
|
||||
'name' => $request->getStr('name'),
|
||||
));
|
||||
$user = $request->getUser();
|
||||
|
||||
return id(new AphrontRedirectResponse())
|
||||
->setURI('/file/info/'.phutil_escape_uri($file->getPHID()).'/');
|
||||
if ($request->isFormPost()) {
|
||||
$files = $request->getArr('file');
|
||||
|
||||
if (count($files) > 1) {
|
||||
return id(new AphrontRedirectResponse())
|
||||
->setURI('/file/?author='.phutil_escape_uri($user->getUserName()));
|
||||
} else {
|
||||
return id(new AphrontRedirectResponse())
|
||||
->setURI('/file/info/'.end($files).'/');
|
||||
}
|
||||
}
|
||||
|
||||
$panel_id = celerity_generate_unique_node_id();
|
||||
|
||||
$form = new AphrontFormView();
|
||||
$form->setAction('/file/upload/');
|
||||
$form->setUser($request->getUser());
|
||||
|
||||
$form
|
||||
->setEncType('multipart/form-data')
|
||||
|
||||
->appendChild(
|
||||
id(new AphrontFormFileControl())
|
||||
->setLabel('File')
|
||||
->setName('file')
|
||||
->setError(true))
|
||||
->appendChild(
|
||||
id(new AphrontFormTextControl())
|
||||
->setLabel('Name')
|
||||
->setName('name')
|
||||
->setCaption('Optional file display name.'))
|
||||
id(new AphrontFormDragAndDropUploadControl())
|
||||
->setLabel('Files')
|
||||
->setName('file')
|
||||
->setError(true)
|
||||
->setDragAndDropTarget($panel_id)
|
||||
->setActivatedClass('aphront-panel-view-drag-and-drop'))
|
||||
|
||||
->appendChild(
|
||||
id(new AphrontFormSubmitControl())
|
||||
->setValue('Upload')
|
||||
->addCancelButton('/file/'));
|
||||
->setValue('Done here!'));
|
||||
|
||||
$panel = new AphrontPanelView();
|
||||
$panel->setHeader('Upload File');
|
||||
|
||||
$panel->appendChild($form);
|
||||
$panel->setWidth(AphrontPanelView::WIDTH_FORM);
|
||||
$panel->setID($panel_id);
|
||||
|
||||
return $this->buildStandardPageResponse(
|
||||
array($panel),
|
||||
|
||||
@@ -8,11 +8,10 @@
|
||||
|
||||
phutil_require_module('phabricator', 'aphront/response/redirect');
|
||||
phutil_require_module('phabricator', 'applications/files/controller/base');
|
||||
phutil_require_module('phabricator', 'applications/files/storage/file');
|
||||
phutil_require_module('phabricator', 'infrastructure/celerity/api');
|
||||
phutil_require_module('phabricator', 'view/form/base');
|
||||
phutil_require_module('phabricator', 'view/form/control/file');
|
||||
phutil_require_module('phabricator', 'view/form/control/draganddropupload');
|
||||
phutil_require_module('phabricator', 'view/form/control/submit');
|
||||
phutil_require_module('phabricator', 'view/form/control/text');
|
||||
phutil_require_module('phabricator', 'view/layout/panel');
|
||||
|
||||
phutil_require_module('phutil', 'markup');
|
||||
|
||||
@@ -71,6 +71,20 @@ class PhabricatorFileViewController extends PhabricatorFileController {
|
||||
break;
|
||||
}
|
||||
|
||||
$author_child = null;
|
||||
if ($file->getAuthorPHID()) {
|
||||
$author = id(new PhabricatorUser())->loadOneWhere(
|
||||
'phid = %s',
|
||||
$file->getAuthorPHID());
|
||||
|
||||
if ($author) {
|
||||
$author_child = id(new AphrontFormStaticControl())
|
||||
->setLabel('Author')
|
||||
->setName('author')
|
||||
->setValue($author->getUserName());
|
||||
}
|
||||
}
|
||||
|
||||
$form = new AphrontFormView();
|
||||
|
||||
if ($file->isViewableInBrowser()) {
|
||||
@@ -80,7 +94,7 @@ class PhabricatorFileViewController extends PhabricatorFileController {
|
||||
$form->setAction('/file/download/'.$file->getPHID().'/');
|
||||
$button_name = 'Download File';
|
||||
}
|
||||
$form->setUser($this->getRequest()->getUser());
|
||||
$form->setUser($user);
|
||||
$form
|
||||
->appendChild(
|
||||
id(new AphrontFormStaticControl())
|
||||
@@ -92,6 +106,7 @@ class PhabricatorFileViewController extends PhabricatorFileController {
|
||||
->setLabel('PHID')
|
||||
->setName('phid')
|
||||
->setValue($file->getPHID()))
|
||||
->appendChild($author_child)
|
||||
->appendChild(
|
||||
id(new AphrontFormStaticControl())
|
||||
->setLabel('Created')
|
||||
|
||||
@@ -13,6 +13,7 @@ phutil_require_module('phabricator', 'applications/files/controller/base');
|
||||
phutil_require_module('phabricator', 'applications/files/storage/file');
|
||||
phutil_require_module('phabricator', 'applications/files/storage/transformed');
|
||||
phutil_require_module('phabricator', 'applications/files/uri');
|
||||
phutil_require_module('phabricator', 'applications/people/storage/user');
|
||||
phutil_require_module('phabricator', 'view/control/table');
|
||||
phutil_require_module('phabricator', 'view/form/base');
|
||||
phutil_require_module('phabricator', 'view/form/control/static');
|
||||
|
||||
@@ -29,6 +29,7 @@ class PhabricatorFile extends PhabricatorFileDAO {
|
||||
protected $name;
|
||||
protected $mimeType;
|
||||
protected $byteSize;
|
||||
protected $authorPHID;
|
||||
|
||||
protected $storageEngine;
|
||||
protected $storageFormat;
|
||||
@@ -88,9 +89,14 @@ class PhabricatorFile extends PhabricatorFileDAO {
|
||||
$file_name = idx($params, 'name');
|
||||
$file_name = self::normalizeFileName($file_name);
|
||||
|
||||
// If for whatever reason, authorPHID isn't passed as a param
|
||||
// (always the case with newFromFileDownload()), store a ''
|
||||
$authorPHID = idx($params, 'authorPHID');
|
||||
|
||||
$file = new PhabricatorFile();
|
||||
$file->setName($file_name);
|
||||
$file->setByteSize(strlen($data));
|
||||
$file->setAuthorPHID($authorPHID);
|
||||
|
||||
$blob = new PhabricatorFileStorageBlob();
|
||||
$blob->setData($data);
|
||||
|
||||
Reference in New Issue
Block a user