Skip to content
This repository has been archived by the owner on Sep 10, 2021. It is now read-only.

Commit

Permalink
ENH: refs #0377. Display human readable quotas on the upload views
Browse files Browse the repository at this point in the history
  • Loading branch information
zachmullen committed Jan 11, 2012
1 parent 67e5aed commit ec55770
Show file tree
Hide file tree
Showing 9 changed files with 132 additions and 70 deletions.
66 changes: 41 additions & 25 deletions core/controllers/UploadController.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,47 @@ public function simpleuploadAction()
$this->view->extraHtml = Zend_Registry::get('notifier')->callback('CALLBACK_CORE_GET_SIMPLEUPLOAD_EXTRA_HTML', array('folder' => $parent));
}//end simple upload

/** upload new revision */
/** Render the large file upload view */
public function javauploadAction()
{
if(!$this->logged)
{
throw new Zend_Exception('You have to be logged in to do that');
}
$this->requireAjaxRequest();
$this->_helper->layout->disableLayout();
$this->view->protocol = 'http';
$this->view->host = empty($_SERVER['HTTP_X_FORWARDED_HOST']) ? $_SERVER['HTTP_HOST'] : $_SERVER['HTTP_X_FORWARDED_HOST'];
$this->view->selectedLicense = Zend_Registry::get('configGlobal')->defaultlicense;
$this->view->defaultUploadLocation = $this->userSession->Dao->getPrivatefolderId();
$this->view->defaultUploadLocationText = $this->t('My Private Folder');

$parent = $this->_getParam('parent');
$license = $this->_getParam('license');
if(!empty($parent) && !empty($license))
{
$this->disableView();
$this->userSession->JavaUpload->parent = $parent;
$this->userSession->JavaUpload->license = $license;
}
if(isset($parent))
{
$folder = $this->Folder->load($parent);
if($this->logged && $folder != false)
{
$this->view->defaultUploadLocation = $folder->getKey();
$this->view->defaultUploadLocationText = $folder->getName();
}
}
else
{
$folder = $this->Folder->load($this->userSession->Dao->getPrivatefolderId());
}
$this->view->extraHtml = Zend_Registry::get('notifier')->callback('CALLBACK_CORE_GET_JAVAUPLOAD_EXTRA_HTML',
array('folder' => $folder));
}//end java upload

/** upload new revision */
public function revisionAction()
{
if(!$this->logged)
Expand Down Expand Up @@ -156,30 +196,6 @@ public function savelinkAction()
}
}//end simple upload

/** java upload*/
public function javauploadAction()
{
if(!$this->logged)
{
throw new Zend_Exception('You have to be logged in to do that');
}
$this->requireAjaxRequest();
$this->_helper->layout->disableLayout();
$this->view->protocol = 'http';
$this->view->host = empty($_SERVER['HTTP_X_FORWARDED_HOST']) ? $_SERVER['HTTP_HOST'] : $_SERVER['HTTP_X_FORWARDED_HOST'];
$this->view->selectedLicense = Zend_Registry::get('configGlobal')->defaultlicense;

$parent = $this->_getParam('parent');
$license = $this->_getParam('license');
if(!empty($parent) && !empty($license))
{
$this->disableView();
$this->userSession->JavaUpload->parent = $parent;
$this->userSession->JavaUpload->license = $license;
}
}//end java upload


/**
* Used to see how much of a file made it to the server during an interrupted upload attempt
* @param uploadUniqueIdentifier The upload token to check
Expand Down
2 changes: 2 additions & 0 deletions core/public/js/upload/upload.javaupload.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,5 @@ function folderSelectionCallback()
{
sendParentToJavaSession();
}

midas.doCallback('CALLBACK_CORE_JAVAUPLOAD_LOADED');
1 change: 1 addition & 0 deletions core/public/js/upload/upload.simpleupload.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,3 +189,4 @@
loadDialog("select","/browse/selectfolder/?policy=write");
showDialog('Browse');
});
midas.doCallback('CALLBACK_CORE_SIMPLEUPLOAD_LOADED');
2 changes: 1 addition & 1 deletion core/translation/fr-main.csv
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ Step 1: Select files to upload;Etape 1: Sélectionner les fichiers à ajouter
Browse or drop files;Parcourir ou déposer des fichiers
Step 2: Where do you want to upload your files;Etape 2: Où voulez vous ajouter ces fichiers
Step 1: Where do you want to upload your files;Etape 1: Où voulez vous ajouter ces fichiers
Curent selected location:;Destination sélèctionnée
Current selected location:;Destination sélèctionnée
Step 3: Select a license;Etape 3 : Sélectionner une lisence
Step 2: Select a license;Etape 2 : Sélectionner une lisence
Step 4: Start the upload;Etape 4 : Lancer l'upload
Expand Down
74 changes: 40 additions & 34 deletions core/views/upload/javaupload.phtml
Original file line number Diff line number Diff line change
@@ -1,37 +1,43 @@
<?php
echo '<script type="text/javascript" src="' . $this->coreWebroot . '/public/js/upload/upload.javaupload.js"></script>';
echo '<script type="text/javascript" src="' . $this->coreWebroot . '/public/js/upload/upload.javaupload.js"></script>';
?>
<b><?php echo $this->t('Step 1: Where do you want to upload your files')?>?</b>
<div>
<br/>
<b><?php echo $this->t('Curent selected location:')?></b>
<span class="destinationUpload"><?php echo $this->defaultUploadLocationText?></span>
<input type="hidden" name="parent" class="destinationId" value="<?php echo $this->defaultUploadLocation?>"/>
<br/>
<input style="margin-left:0px;" class="browseMIDASLink globalButton" type="button" value="Change location" />
<br/>
<br/>
</div>
<b><?php echo $this->t('Step 2: Select a license')?></b>
<div>
<?php
echo $this->element('license')?>
</div>
<br/>
<b><?php echo $this->t('Step 3: Select files to upload')?></b>
<br/>
<applet name="MidasUploader" code="com.kitware.utils.Main"
archive="<?php echo $this->coreWebroot?>/public/java/uploader/dist/MidasUploader.jar?rev=3&<?php echo time()?>"
width="305" height="200" mayscript="">
<param name = "type" value = "application/x-java-applet;version=1.5" />
<param name = "background" value = "ffffff" />
<param name = "loglevel" value = "WARNING" />
<param name = "sessionId" value = "<?php echo session_id();?>"/>
<param name = "baseURL" value="<?php echo $this->protocol."://".$this->host . $this->webroot ?>/upload/"/>
<param name = "getUploadFileOffsetBaseURL" value="gethttpuploadoffset/"/>
<param name = "onSuccessfulUploadRedirectEnable" value="true"/>
<param name = "onSuccessRedirectURL" value="review"/>
<param name = "uploadUniqueIdentifierURL" value="gethttpuploaduniqueidentifier/"/>
<param name = "uploadFileBaseURL" value="processjavaupload/?sid="/>
</applet>

<div>
<br/>
<b><?php echo $this->t('Current selected location:')?></b>
<span class="destinationUpload"><?php echo $this->defaultUploadLocationText?></span>
<br/><br/>
<div class="belowDestinationUpload" style="display: none;"></div>
<input type="hidden" name="parent" class="destinationId" value="<?php echo $this->defaultUploadLocation?>"/>
<br/>
<input style="margin-left:0px;" class="browseMIDASLink globalButton" type="button" value="Change location" />
<br/><br/>
</div>
<b><?php echo $this->t('Step 2: Select a license')?></b>
<div>
<?php
echo $this->element('license')?>
</div>
<br/>
<b><?php echo $this->t('Step 3: Select files to upload')?></b>
<br/>
<applet name="MidasUploader" code="com.kitware.utils.Main"
archive="<?php echo $this->coreWebroot?>/public/java/uploader/dist/MidasUploader.jar?rev=3&<?php echo time()?>"
width="305" height="200" mayscript="">
<param name = "type" value = "application/x-java-applet;version=1.5" />
<param name = "background" value = "ffffff" />
<param name = "loglevel" value = "WARNING" />
<param name = "sessionId" value = "<?php echo session_id();?>"/>
<param name = "baseURL" value="<?php echo $this->protocol."://".$this->host . $this->webroot ?>/upload/"/>
<param name = "getUploadFileOffsetBaseURL" value="gethttpuploadoffset/"/>
<param name = "onSuccessfulUploadRedirectEnable" value="true"/>
<param name = "onSuccessRedirectURL" value="review"/>
<param name = "uploadUniqueIdentifierURL" value="gethttpuploaduniqueidentifier/"/>
<param name = "uploadFileBaseURL" value="processjavaupload/?sid="/>
</applet>
<?php
foreach($this->extraHtml as $module => $extra)
{
echo $extra."\n";
}
?>
6 changes: 4 additions & 2 deletions core/views/upload/simpleupload.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,13 @@ PURPOSE. See the above copyright notices for more information.
<b><?php echo $this->t('Step 2: Where do you want to upload your files')?>?</b>
<div>
<br/>
<b><?php echo $this->t('Curent selected location:')?></b>
<b><?php echo $this->t('Current selected location:')?></b>
<span id="destinationUpload"><?php echo $this->defaultUploadLocationText?></span>
<input type="hidden" name="destinationId" id="destinationId" value="<?php echo $this->defaultUploadLocation?>"/>
<br/><br/>
<div class="belowDestinationUpload" style="display: none;"></div>
<br/>
<input style="margin-left:0px;" class="browseMIDASLink globalButton" type="button" value="Change location" />
<input style="margin-left:0px;" class="browseMIDASLink globalButton" type="button" value="Change location" />
<br/>
<br/>
</div>
Expand Down
17 changes: 11 additions & 6 deletions modules/sizequota/Notification.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ public function init()
$this->addCallBack('CALLBACK_CORE_GET_COMMUNITY_MANAGE_TABS', 'getCommunityTab');
$this->addCallBack('CALLBACK_CORE_GET_USER_TABS', 'getUserTab');
$this->addCallBack('CALLBACK_CORE_GET_FOOTER_LAYOUT', 'getScript');
$this->addCallBack('CALLBACK_CORE_GET_SIMPLEUPLOAD_EXTRA_HTML', 'getSimpleuploadExtraHtml');
$this->addCallBack('CALLBACK_CORE_GET_SIMPLEUPLOAD_EXTRA_HTML', 'getExtraHtml');
$this->addCallBack('CALLBACK_CORE_GET_JAVAUPLOAD_EXTRA_HTML', 'getExtraHtml');
$this->addCallBack('CALLBACK_CORE_VALIDATE_UPLOAD', 'validateUpload');

$this->enableWebAPI($this->moduleName);
Expand Down Expand Up @@ -72,7 +73,7 @@ public function getScript()
}

/** Add free space information to the dom on the simple upload page */
public function getSimpleuploadExtraHtml($args)
public function getExtraHtml($args)
{
$modelLoader = new MIDAS_ModelLoader();
$folderModel = $modelLoader->loadModel('Folder');
Expand All @@ -83,16 +84,20 @@ public function getSimpleuploadExtraHtml($args)
$quota = $folderQuotaModel->getFolderQuota($rootFolder);
if($quota == '')
{
return '<div id="sizequotaFreeSpace" style="display:none;"></div>';
return '<div id="sizequotaFreeSpace" style="display:none;"></div>'.
'<div id="sizequotaHFreeSpace" style="display:none;">'.$this->t('Unlimited').'</div>';
}
else
{
$freeSpace = number_format($quota - $folderModel->getSize($rootFolder), 0, '.', '');
return '<div id="sizequotaFreeSpace" style="display:none;">'.$freeSpace.'</div>';
$used = $folderModel->getSize($rootFolder);
$freeSpace = number_format($quota - $used, 0, '.', '');
$hFreeSpace = UtilityComponent::formatSize($quota - $used);
return '<div id="sizequotaFreeSpace" style="display:none;">'.$freeSpace.'</div>'.
'<div id="sizequotaHFreeSpace" style="display:none;">'.$hFreeSpace.'</div>';
}
}

/**
/**
* Return whether or not the upload is allowed. If uploading the file
* will cause the size to surpass the quota, it will be rejected.
* @param size Size of the uploaded file
Expand Down
9 changes: 7 additions & 2 deletions modules/sizequota/controllers/ConfigController.php
Original file line number Diff line number Diff line change
Expand Up @@ -185,12 +185,17 @@ public function getfreespaceAction()
if($quota == '')
{
$freeSpace = '';
$hFreeSpace = $this->t('Unlimited');
}
else
{
$freeSpace = number_format($quota - $this->Folder->getSize($rootFolder), 0, '.', '');
$used = $this->Folder->getSize($rootFolder);
$freeSpace = number_format($quota - $used, 0, '.', '');
$hFreeSpace = UtilityComponent::formatSize($quota - $used);
}
echo JsonComponent::encode(array('status' => true, 'freeSpace' => $freeSpace));
echo JsonComponent::encode(array('status' => true,
'freeSpace' => $freeSpace,
'hFreeSpace' => $hFreeSpace));
}

/** Test whether the provided quota values are legal */
Expand Down
25 changes: 25 additions & 0 deletions modules/sizequota/public/js/common/common.notify.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,16 @@ midas.sizequota.resetTotal = function()
midas.sizequota.totalSize = 0;
}

/**
* Call this to update the message
*/
midas.sizequota.updateFreeSpaceMessage = function()
{
var hFreeSpace = $('#sizequotaHFreeSpace').html();
$('.belowDestinationUpload').html('<b>Free space:</b> ' + hFreeSpace);
$('.belowDestinationUpload').show();
}

/**
* Called when a different upload location is selected
*/
Expand All @@ -48,6 +58,9 @@ midas.sizequota.folderChanged = function(args)
success: function(jsonContent) {
var jsonResponse = jQuery.parseJSON(jsonContent);
$('#sizequotaFreeSpace').html(jsonResponse.freeSpace);
$('#sizequotaHFreeSpace').html(jsonResponse.hFreeSpace);

midas.sizequota.updateFreeSpaceMessage();

if(midas.sizequota.totalSize == 0)
{
Expand All @@ -71,6 +84,18 @@ midas.sizequota.folderChanged = function(args)
});
}

/**
* Correctly initializes the free space message
*/
midas.sizequota.onPageLoad = function()
{
var folderId = $('.destinationId').val();
midas.sizequota.folderChanged({folderId: folderId});
}

midas.registerCallback('CALLBACK_CORE_VALIDATE_UPLOAD', 'sizequota', midas.sizequota.validateUpload);
midas.registerCallback('CALLBACK_CORE_RESET_UPLOAD_TOTAL', 'sizequota', midas.sizequota.resetTotal);
midas.registerCallback('CALLBACK_CORE_UPLOAD_FOLDER_CHANGED', 'sizequota', midas.sizequota.folderChanged);
midas.registerCallback('CALLBACK_CORE_SIMPLEUPLOAD_LOADED', 'sizequota', midas.sizequota.onPageLoad);
midas.registerCallback('CALLBACK_CORE_JAVAUPLOAD_LOADED', 'sizequota', midas.sizequota.onPageLoad);

0 comments on commit ec55770

Please sign in to comment.