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

Commit ec55770

Browse files
committed
ENH: refs #0377. Display human readable quotas on the upload views
1 parent 67e5aed commit ec55770

File tree

9 files changed

+132
-70
lines changed

9 files changed

+132
-70
lines changed

core/controllers/UploadController.php

Lines changed: 41 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,47 @@ public function simpleuploadAction()
101101
$this->view->extraHtml = Zend_Registry::get('notifier')->callback('CALLBACK_CORE_GET_SIMPLEUPLOAD_EXTRA_HTML', array('folder' => $parent));
102102
}//end simple upload
103103

104-
/** upload new revision */
104+
/** Render the large file upload view */
105+
public function javauploadAction()
106+
{
107+
if(!$this->logged)
108+
{
109+
throw new Zend_Exception('You have to be logged in to do that');
110+
}
111+
$this->requireAjaxRequest();
112+
$this->_helper->layout->disableLayout();
113+
$this->view->protocol = 'http';
114+
$this->view->host = empty($_SERVER['HTTP_X_FORWARDED_HOST']) ? $_SERVER['HTTP_HOST'] : $_SERVER['HTTP_X_FORWARDED_HOST'];
115+
$this->view->selectedLicense = Zend_Registry::get('configGlobal')->defaultlicense;
116+
$this->view->defaultUploadLocation = $this->userSession->Dao->getPrivatefolderId();
117+
$this->view->defaultUploadLocationText = $this->t('My Private Folder');
118+
119+
$parent = $this->_getParam('parent');
120+
$license = $this->_getParam('license');
121+
if(!empty($parent) && !empty($license))
122+
{
123+
$this->disableView();
124+
$this->userSession->JavaUpload->parent = $parent;
125+
$this->userSession->JavaUpload->license = $license;
126+
}
127+
if(isset($parent))
128+
{
129+
$folder = $this->Folder->load($parent);
130+
if($this->logged && $folder != false)
131+
{
132+
$this->view->defaultUploadLocation = $folder->getKey();
133+
$this->view->defaultUploadLocationText = $folder->getName();
134+
}
135+
}
136+
else
137+
{
138+
$folder = $this->Folder->load($this->userSession->Dao->getPrivatefolderId());
139+
}
140+
$this->view->extraHtml = Zend_Registry::get('notifier')->callback('CALLBACK_CORE_GET_JAVAUPLOAD_EXTRA_HTML',
141+
array('folder' => $folder));
142+
}//end java upload
143+
144+
/** upload new revision */
105145
public function revisionAction()
106146
{
107147
if(!$this->logged)
@@ -156,30 +196,6 @@ public function savelinkAction()
156196
}
157197
}//end simple upload
158198

159-
/** java upload*/
160-
public function javauploadAction()
161-
{
162-
if(!$this->logged)
163-
{
164-
throw new Zend_Exception('You have to be logged in to do that');
165-
}
166-
$this->requireAjaxRequest();
167-
$this->_helper->layout->disableLayout();
168-
$this->view->protocol = 'http';
169-
$this->view->host = empty($_SERVER['HTTP_X_FORWARDED_HOST']) ? $_SERVER['HTTP_HOST'] : $_SERVER['HTTP_X_FORWARDED_HOST'];
170-
$this->view->selectedLicense = Zend_Registry::get('configGlobal')->defaultlicense;
171-
172-
$parent = $this->_getParam('parent');
173-
$license = $this->_getParam('license');
174-
if(!empty($parent) && !empty($license))
175-
{
176-
$this->disableView();
177-
$this->userSession->JavaUpload->parent = $parent;
178-
$this->userSession->JavaUpload->license = $license;
179-
}
180-
}//end java upload
181-
182-
183199
/**
184200
* Used to see how much of a file made it to the server during an interrupted upload attempt
185201
* @param uploadUniqueIdentifier The upload token to check

core/public/js/upload/upload.javaupload.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,5 @@ function folderSelectionCallback()
2424
{
2525
sendParentToJavaSession();
2626
}
27+
28+
midas.doCallback('CALLBACK_CORE_JAVAUPLOAD_LOADED');

core/public/js/upload/upload.simpleupload.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,3 +189,4 @@
189189
loadDialog("select","/browse/selectfolder/?policy=write");
190190
showDialog('Browse');
191191
});
192+
midas.doCallback('CALLBACK_CORE_SIMPLEUPLOAD_LOADED');

core/translation/fr-main.csv

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ Step 1: Select files to upload;Etape 1: Sélectionner les fichiers à ajouter
227227
Browse or drop files;Parcourir ou déposer des fichiers
228228
Step 2: Where do you want to upload your files;Etape 2: Où voulez vous ajouter ces fichiers
229229
Step 1: Where do you want to upload your files;Etape 1: Où voulez vous ajouter ces fichiers
230-
Curent selected location:;Destination sélèctionnée
230+
Current selected location:;Destination sélèctionnée
231231
Step 3: Select a license;Etape 3 : Sélectionner une lisence
232232
Step 2: Select a license;Etape 2 : Sélectionner une lisence
233233
Step 4: Start the upload;Etape 4 : Lancer l'upload

core/views/upload/javaupload.phtml

Lines changed: 40 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,43 @@
11
<?php
2-
echo '<script type="text/javascript" src="' . $this->coreWebroot . '/public/js/upload/upload.javaupload.js"></script>';
2+
echo '<script type="text/javascript" src="' . $this->coreWebroot . '/public/js/upload/upload.javaupload.js"></script>';
33
?>
44
<b><?php echo $this->t('Step 1: Where do you want to upload your files')?>?</b>
5-
<div>
6-
<br/>
7-
<b><?php echo $this->t('Curent selected location:')?></b>
8-
<span class="destinationUpload"><?php echo $this->defaultUploadLocationText?></span>
9-
<input type="hidden" name="parent" class="destinationId" value="<?php echo $this->defaultUploadLocation?>"/>
10-
<br/>
11-
<input style="margin-left:0px;" class="browseMIDASLink globalButton" type="button" value="Change location" />
12-
<br/>
13-
<br/>
14-
</div>
15-
<b><?php echo $this->t('Step 2: Select a license')?></b>
16-
<div>
17-
<?php
18-
echo $this->element('license')?>
19-
</div>
20-
<br/>
21-
<b><?php echo $this->t('Step 3: Select files to upload')?></b>
22-
<br/>
23-
<applet name="MidasUploader" code="com.kitware.utils.Main"
24-
archive="<?php echo $this->coreWebroot?>/public/java/uploader/dist/MidasUploader.jar?rev=3&<?php echo time()?>"
25-
width="305" height="200" mayscript="">
26-
<param name = "type" value = "application/x-java-applet;version=1.5" />
27-
<param name = "background" value = "ffffff" />
28-
<param name = "loglevel" value = "WARNING" />
29-
<param name = "sessionId" value = "<?php echo session_id();?>"/>
30-
<param name = "baseURL" value="<?php echo $this->protocol."://".$this->host . $this->webroot ?>/upload/"/>
31-
<param name = "getUploadFileOffsetBaseURL" value="gethttpuploadoffset/"/>
32-
<param name = "onSuccessfulUploadRedirectEnable" value="true"/>
33-
<param name = "onSuccessRedirectURL" value="review"/>
34-
<param name = "uploadUniqueIdentifierURL" value="gethttpuploaduniqueidentifier/"/>
35-
<param name = "uploadFileBaseURL" value="processjavaupload/?sid="/>
36-
</applet>
37-
5+
<div>
6+
<br/>
7+
<b><?php echo $this->t('Current selected location:')?></b>
8+
<span class="destinationUpload"><?php echo $this->defaultUploadLocationText?></span>
9+
<br/><br/>
10+
<div class="belowDestinationUpload" style="display: none;"></div>
11+
<input type="hidden" name="parent" class="destinationId" value="<?php echo $this->defaultUploadLocation?>"/>
12+
<br/>
13+
<input style="margin-left:0px;" class="browseMIDASLink globalButton" type="button" value="Change location" />
14+
<br/><br/>
15+
</div>
16+
<b><?php echo $this->t('Step 2: Select a license')?></b>
17+
<div>
18+
<?php
19+
echo $this->element('license')?>
20+
</div>
21+
<br/>
22+
<b><?php echo $this->t('Step 3: Select files to upload')?></b>
23+
<br/>
24+
<applet name="MidasUploader" code="com.kitware.utils.Main"
25+
archive="<?php echo $this->coreWebroot?>/public/java/uploader/dist/MidasUploader.jar?rev=3&<?php echo time()?>"
26+
width="305" height="200" mayscript="">
27+
<param name = "type" value = "application/x-java-applet;version=1.5" />
28+
<param name = "background" value = "ffffff" />
29+
<param name = "loglevel" value = "WARNING" />
30+
<param name = "sessionId" value = "<?php echo session_id();?>"/>
31+
<param name = "baseURL" value="<?php echo $this->protocol."://".$this->host . $this->webroot ?>/upload/"/>
32+
<param name = "getUploadFileOffsetBaseURL" value="gethttpuploadoffset/"/>
33+
<param name = "onSuccessfulUploadRedirectEnable" value="true"/>
34+
<param name = "onSuccessRedirectURL" value="review"/>
35+
<param name = "uploadUniqueIdentifierURL" value="gethttpuploaduniqueidentifier/"/>
36+
<param name = "uploadFileBaseURL" value="processjavaupload/?sid="/>
37+
</applet>
38+
<?php
39+
foreach($this->extraHtml as $module => $extra)
40+
{
41+
echo $extra."\n";
42+
}
43+
?>

core/views/upload/simpleupload.phtml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,13 @@ PURPOSE. See the above copyright notices for more information.
7171
<b><?php echo $this->t('Step 2: Where do you want to upload your files')?>?</b>
7272
<div>
7373
<br/>
74-
<b><?php echo $this->t('Curent selected location:')?></b>
74+
<b><?php echo $this->t('Current selected location:')?></b>
7575
<span id="destinationUpload"><?php echo $this->defaultUploadLocationText?></span>
7676
<input type="hidden" name="destinationId" id="destinationId" value="<?php echo $this->defaultUploadLocation?>"/>
77+
<br/><br/>
78+
<div class="belowDestinationUpload" style="display: none;"></div>
7779
<br/>
78-
<input style="margin-left:0px;" class="browseMIDASLink globalButton" type="button" value="Change location" />
80+
<input style="margin-left:0px;" class="browseMIDASLink globalButton" type="button" value="Change location" />
7981
<br/>
8082
<br/>
8183
</div>

modules/sizequota/Notification.php

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ public function init()
3232
$this->addCallBack('CALLBACK_CORE_GET_COMMUNITY_MANAGE_TABS', 'getCommunityTab');
3333
$this->addCallBack('CALLBACK_CORE_GET_USER_TABS', 'getUserTab');
3434
$this->addCallBack('CALLBACK_CORE_GET_FOOTER_LAYOUT', 'getScript');
35-
$this->addCallBack('CALLBACK_CORE_GET_SIMPLEUPLOAD_EXTRA_HTML', 'getSimpleuploadExtraHtml');
35+
$this->addCallBack('CALLBACK_CORE_GET_SIMPLEUPLOAD_EXTRA_HTML', 'getExtraHtml');
36+
$this->addCallBack('CALLBACK_CORE_GET_JAVAUPLOAD_EXTRA_HTML', 'getExtraHtml');
3637
$this->addCallBack('CALLBACK_CORE_VALIDATE_UPLOAD', 'validateUpload');
3738

3839
$this->enableWebAPI($this->moduleName);
@@ -72,7 +73,7 @@ public function getScript()
7273
}
7374

7475
/** Add free space information to the dom on the simple upload page */
75-
public function getSimpleuploadExtraHtml($args)
76+
public function getExtraHtml($args)
7677
{
7778
$modelLoader = new MIDAS_ModelLoader();
7879
$folderModel = $modelLoader->loadModel('Folder');
@@ -83,16 +84,20 @@ public function getSimpleuploadExtraHtml($args)
8384
$quota = $folderQuotaModel->getFolderQuota($rootFolder);
8485
if($quota == '')
8586
{
86-
return '<div id="sizequotaFreeSpace" style="display:none;"></div>';
87+
return '<div id="sizequotaFreeSpace" style="display:none;"></div>'.
88+
'<div id="sizequotaHFreeSpace" style="display:none;">'.$this->t('Unlimited').'</div>';
8789
}
8890
else
8991
{
90-
$freeSpace = number_format($quota - $folderModel->getSize($rootFolder), 0, '.', '');
91-
return '<div id="sizequotaFreeSpace" style="display:none;">'.$freeSpace.'</div>';
92+
$used = $folderModel->getSize($rootFolder);
93+
$freeSpace = number_format($quota - $used, 0, '.', '');
94+
$hFreeSpace = UtilityComponent::formatSize($quota - $used);
95+
return '<div id="sizequotaFreeSpace" style="display:none;">'.$freeSpace.'</div>'.
96+
'<div id="sizequotaHFreeSpace" style="display:none;">'.$hFreeSpace.'</div>';
9297
}
9398
}
9499

95-
/**
100+
/**
96101
* Return whether or not the upload is allowed. If uploading the file
97102
* will cause the size to surpass the quota, it will be rejected.
98103
* @param size Size of the uploaded file

modules/sizequota/controllers/ConfigController.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,12 +185,17 @@ public function getfreespaceAction()
185185
if($quota == '')
186186
{
187187
$freeSpace = '';
188+
$hFreeSpace = $this->t('Unlimited');
188189
}
189190
else
190191
{
191-
$freeSpace = number_format($quota - $this->Folder->getSize($rootFolder), 0, '.', '');
192+
$used = $this->Folder->getSize($rootFolder);
193+
$freeSpace = number_format($quota - $used, 0, '.', '');
194+
$hFreeSpace = UtilityComponent::formatSize($quota - $used);
192195
}
193-
echo JsonComponent::encode(array('status' => true, 'freeSpace' => $freeSpace));
196+
echo JsonComponent::encode(array('status' => true,
197+
'freeSpace' => $freeSpace,
198+
'hFreeSpace' => $hFreeSpace));
194199
}
195200

196201
/** Test whether the provided quota values are legal */

modules/sizequota/public/js/common/common.notify.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,16 @@ midas.sizequota.resetTotal = function()
3636
midas.sizequota.totalSize = 0;
3737
}
3838

39+
/**
40+
* Call this to update the message
41+
*/
42+
midas.sizequota.updateFreeSpaceMessage = function()
43+
{
44+
var hFreeSpace = $('#sizequotaHFreeSpace').html();
45+
$('.belowDestinationUpload').html('<b>Free space:</b> ' + hFreeSpace);
46+
$('.belowDestinationUpload').show();
47+
}
48+
3949
/**
4050
* Called when a different upload location is selected
4151
*/
@@ -48,6 +58,9 @@ midas.sizequota.folderChanged = function(args)
4858
success: function(jsonContent) {
4959
var jsonResponse = jQuery.parseJSON(jsonContent);
5060
$('#sizequotaFreeSpace').html(jsonResponse.freeSpace);
61+
$('#sizequotaHFreeSpace').html(jsonResponse.hFreeSpace);
62+
63+
midas.sizequota.updateFreeSpaceMessage();
5164

5265
if(midas.sizequota.totalSize == 0)
5366
{
@@ -71,6 +84,18 @@ midas.sizequota.folderChanged = function(args)
7184
});
7285
}
7386

87+
/**
88+
* Correctly initializes the free space message
89+
*/
90+
midas.sizequota.onPageLoad = function()
91+
{
92+
var folderId = $('.destinationId').val();
93+
midas.sizequota.folderChanged({folderId: folderId});
94+
}
95+
7496
midas.registerCallback('CALLBACK_CORE_VALIDATE_UPLOAD', 'sizequota', midas.sizequota.validateUpload);
7597
midas.registerCallback('CALLBACK_CORE_RESET_UPLOAD_TOTAL', 'sizequota', midas.sizequota.resetTotal);
7698
midas.registerCallback('CALLBACK_CORE_UPLOAD_FOLDER_CHANGED', 'sizequota', midas.sizequota.folderChanged);
99+
midas.registerCallback('CALLBACK_CORE_SIMPLEUPLOAD_LOADED', 'sizequota', midas.sizequota.onPageLoad);
100+
midas.registerCallback('CALLBACK_CORE_JAVAUPLOAD_LOADED', 'sizequota', midas.sizequota.onPageLoad);
101+

0 commit comments

Comments
 (0)