Get user quota information on main page | patching the code?

expert
modifications

#1

Hello,

I want to tweak , the front page by adding Quota information. I did my best to get the information from the hidden fields such as "usedSpacePercent" and "free_space" displayed on the main-page. For this , I learned a little from /apps/files/js/files.js with the relevant section looks like:-

if (response.data !== undefined && response.data.uploadMaxFilesize !== undefined) {
			$('#max_upload').val(response.data.uploadMaxFilesize);
			$('#free_space').val(response.data.freeSpace);
			$('#upload.button').attr('data-original-title', response.data.maxHumanFilesize);
			$('#usedSpacePercent').val(response.data.usedSpacePercent);
			$('#owner').val(response.data.owner);
			$('#ownerDisplayName').val(response.data.ownerDisplayName);
			Files.displayStorageWarnings();

The problem is that there is no 'quota' information present in the files.js, getJSON call to "getstoragestats.php" which lands to "/apps/files/lib/Helper.php" contains

public static function buildFileStorageStatistics($dir) {
	// information about storage capacities
	$storageInfo = \OC_Helper::getStorageInfo($dir);
	$l = new \OC_L10N('files');
	$maxUploadFileSize = \OCP\Util::maxUploadFilesize($dir, $storageInfo['free']);
	$maxHumanFileSize = \OCP\Util::humanFileSize($maxUploadFileSize);
	$maxHumanFileSize = $l->t('Upload (max. %s)', array($maxHumanFileSize));
	return [
		'uploadMaxFilesize' => $maxUploadFileSize,
		'maxHumanFilesize'  => $maxHumanFileSize,
		'freeSpace' => $storageInfo['free'],
		'usedSpacePercent'  => (int)$storageInfo['relative'],
		'owner' => $storageInfo['owner'],
		'ownerDisplayName' => $storageInfo['ownerDisplayName'],
	];

no return of 'Quota' value from "getStorageInfo()" defined here "lib/private/legacy/helper.php' as

$ownerId = $storage->getOwner($path);
$ownerDisplayName = '';
$owner = \OC::$server->getUserManager()->get($ownerId);
if($owner) {
$ownerDisplayName = $owner->getDisplayName();
}
return [
'free' => $free,
'used' => $used,
'quota' => $quota,
'total' => $total,
'relative' => $relative,
'owner' => $ownerId,
'ownerDisplayName' => $ownerDisplayName,
];
}

I'm thinking of thus patching the files.js as

$('#quota').val(response.data.quota);

and files/lib/Helper.php as

'quota' => $storageInfo['quota'],

After, that I can use JS, to call the id against whatever HTML element i.e span or div on the main-page. Please suggest?

UPDATE

using firebug in files.js

		state.call = $.getJSON(OC.filePath('files','ajax','getstoragestats.php') + '?dir=' + encodeURIComponent(currentDir),function(response) {

I get response as

{"data":{"uploadMaxFilesize":537919488,"maxHumanFilesize":"Upload (max. 513 MB)","freeSpace":1069113360
,"usedSpacePercent":0,"owner":"6A5DE276-3FEF-4B08-A8DB-79D8C9A8200E","ownerDisplayName":"XYZ"},"status"
:"success"}

No quota is returned?

regards
asad


#2

any assistance.....?


#3

To be honest - I don't really understand what you are trying to do :frowning:


#4

I'm trying to display quote information on the mainpage,by adding code to files.js and files/lib/Helper.php.


#5

What do you mean by mainpage? the login page?

Quota information is user specific - there is little to display without being logged in


#6

yes quote for specific user, the page I want it to be displayed is /index.php/apps/files/


#7

Hello assistance required?


#8

Generally speaking your approach looks valid.
If it doesn't work outyou need to dive into debugging the situation.

If you don't want to setup an ide and xdebug you can add logging statements to see whats going on in the server.