Skip to content

Commit

Permalink
special class for notification mail input
Browse files Browse the repository at this point in the history
  • Loading branch information
memurats committed Oct 10, 2023
1 parent 3264d6c commit 1f4de2c
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 19 deletions.
86 changes: 68 additions & 18 deletions lib/Settings/Personal/NmcPersonalInfoStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,42 +5,57 @@
use OC\Files\View;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\Files\FileInfo;
use OCP\IConfig;
use OCP\IDBConnection;
use OCP\IL10N;
use OCP\IUserManager;
use OCP\L10N\IFactory;
use OCP\Settings\ISettings;

class NmcPersonalInfoStorage implements ISettings {

/** @var IUserManager */
private $userManager;
/** @var IConfig */
private $config;

/** @var IDBConnection */
private $db;

/** @var IL10N */
private $l;

/** @var IDBConnection */
private $db;
/** @var IUserManager */
private $userManager;

/** @var IFactory */
private $l10nFactory;

private $uid;

public function __construct(
IUserManager $userManager,
IConfig $config,
IDBConnection $db,
IL10N $l,
IDBConnection $db
IUserManager $userManager,
IFactory $l10nFactory

) {
$this->userManager = $userManager;
$this->l = $l;
$this->config = $config;
$this->db = $db;
$this->l = $l;
$this->userManager = $userManager;
$this->l10nFactory = $l10nFactory;
$this->uid = \OC_User::getUser();
}

public function getForm(): TemplateResponse {

$uid = \OC_User::getUser();
$user = $this->userManager->get($uid);
$user = $this->userManager->get($this->uid);

$imageMimetypes = "'image','image/jpg','image/jpeg','image/gif','image/png','image/svg+xml','image/webp'";
$videoMimetypes = "'video','video/3gpp','video/mp4', 'video/mov', 'video/avi', 'video/flv'";

$imageStorageInBytes = $this->storageUtilization($uid, $imageMimetypes);
$videoStorageInBytes = $this->storageUtilization($uid, $videoMimetypes);
$imageStorageInBytes = $this->storageUtilization($this->uid, $imageMimetypes);
$videoStorageInBytes = $this->storageUtilization($this->uid, $videoMimetypes);
$photoVideoSizeInBytes = $imageStorageInBytes + $videoStorageInBytes;

// make sure FS is setup before querying storage related stuff...
Expand All @@ -50,10 +65,10 @@ public function getForm(): TemplateResponse {
if ($storageInfo['quota'] === FileInfo::SPACE_UNLIMITED) {
$totalSpace = $this->l->t('Unlimited');
} else {
$totalSpace = \OC_Helper::humanFileSize($storageInfo['total']);
$totalSpace = $this->humanFileSize($storageInfo['total']);
}

$trashSizeinBytes = self::getTrashbinSize($uid);
$trashSizeinBytes = self::getTrashbinSize($this->uid);
$filesSizeInBytes = $storageInfo['used'] - ($photoVideoSizeInBytes);

if($filesSizeInBytes < 0) {
Expand All @@ -64,11 +79,11 @@ public function getForm(): TemplateResponse {
'quota' => $storageInfo['quota'],
'totalSpace' => $totalSpace,
'tariff' => $this->getTariff($storageInfo['quota']),
'usage' => \OC_Helper::humanFileSize($storageInfo['used']),
'usage' => $this->humanFileSize($storageInfo['used']),
'usageRelative' => round($storageInfo['relative']),
'trashSize' => \OC_Helper::humanFileSize($trashSizeinBytes),
'photoVideoSize' => \OC_Helper::humanFileSize($photoVideoSizeInBytes),
'filesSize' => \OC_Helper::humanFileSize($filesSizeInBytes),
'trashSize' => $this->humanFileSize($trashSizeinBytes),
'photoVideoSize' => $this->humanFileSize($photoVideoSizeInBytes),
'filesSize' => $this->humanFileSize($filesSizeInBytes),
'trashSizeInPer' => round(($trashSizeinBytes / $storageInfo['quota']) * 100) ,
'photoVideoSizeInPer' => round(($photoVideoSizeInBytes / $storageInfo['quota']) * 100),
'filesSizeInPer' => round(($filesSizeInBytes / $storageInfo['quota']) * 100) ,
Expand Down Expand Up @@ -154,4 +169,39 @@ private function storageUtilization($user = null, $filterMimetypes = null) {
$result->closeCursor();
return $details;
}

private function humanFileSize($bytes, $binary = true) {
$humanList = ['B', 'KB', 'MB', 'GB', 'TB', 'PB'];
$kilo = 1000;

if($binary) {
$humanList = ['B', 'KB', 'MB', 'GB', 'TB', 'PB'];
$kilo = 1024;
}

if($bytes > 0) {
$order = floor(log($bytes) / log($kilo));
$order = min(sizeof($humanList) - 1, $order);
$readableFormat = $humanList[$order];

$relativeSize = round($bytes / pow($kilo, $order), 1);

if ($bytes < $kilo) {
return "$bytes B";
} else {
$decimalSeparator = ',';
$lang = $this->config->getUserValue($this->uid, 'core', 'lang', $this->l10nFactory->findLanguage());
$locale = explode('_', $lang);

if($locale[0] === 'en') {
$decimalSeparator = '.';
}

$relativeSize = number_format($relativeSize, 1, $decimalSeparator, '');
return $relativeSize . ' ' . $readableFormat;
}
} else {
return $bytes . ' ' . $humanList[0];
}
}
}
18 changes: 17 additions & 1 deletion src/components/EmailSection/Email.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
autocapitalize="none"
autocomplete="on"
autocorrect="off"
class="additional"
:class="setNotificationMailClass"
@input="onEmailChange">

<div class="email__actions-container">
Expand Down Expand Up @@ -155,6 +155,22 @@ export default {
return 'icon-auto-login'
},
setNotificationMailClass() {
if (this.isNotificationEmail) {
return 'additional notification'
}
return 'additional'
},
setNotificationMailLabel() {

Check failure on line 165 in src/components/EmailSection/Email.vue

View workflow job for this annotation

GitHub Actions / eslint

Duplicate key 'setNotificationMailLabel'

Check failure on line 165 in src/components/EmailSection/Email.vue

View workflow job for this annotation

GitHub Actions / eslint

Duplicate key 'setNotificationMailLabel'. May cause name collision in script or template tag
if (this.isNotificationEmail) {
return t('nmcsettings', 'Unset as primary email')
} else if (!this.primary && this.localVerificationState !== VERIFICATION_ENUM.VERIFIED) {
return t('nmcsettings', 'This address is not confirmed')
}
return t('nmcsettings', 'Set as primary email')
},
inputId() {
if (this.primary) {
return 'email'
Expand Down

0 comments on commit 1f4de2c

Please sign in to comment.