partkeepr

fork of partkeepr
git clone https://git.e1e0.net/partkeepr.git
Log | Files | Refs | Submodules | README | LICENSE

commit f7a2730645d3781dede804cd5e135e8935926fe6
parent 19f45a11852173a3c1d27d4e011844c7475458fb
Author: Felicitus <felicitus@felicitus.org>
Date:   Sat, 31 Oct 2015 20:00:44 +0100

Added disk usage to the file upload dialog

Diffstat:
Mapp/config/config.yml | 20++++++++++++--------
Msrc/PartKeepr/CoreBundle/Controller/DefaultController.php | 19++++++++++++++++++-
Msrc/PartKeepr/CoreBundle/Services/SystemService.php | 49+++++++++++++++++++++++++++++++++++++++++++++++++
Msrc/PartKeepr/FrontendBundle/Resources/public/js/Dialogs/FileUploadDialog.js | 47++++++++++++++++++++++++++++++++++++-----------
4 files changed, 115 insertions(+), 20 deletions(-)

diff --git a/app/config/config.yml b/app/config/config.yml @@ -117,35 +117,39 @@ services: - method: "setCircularReferenceLimit" arguments: [ [ 5 ] ] +parameters: + data_directory: %kernel.root_dir%/../data/ + quota: false + knp_gaufrette: adapters: iclogo: local: - directory: %kernel.root_dir%/../data/images/iclogo/ + directory: %data_directory%images/iclogo/ temp: local: - directory: %kernel.root_dir%/../data/temp/ + directory: %data_directory%temp/ tempfile: local: - directory: %kernel.root_dir%/../data/files/Temporary/ + directory: %data_directory%files/Temporary/ footprintattachment: local: - directory: %kernel.root_dir%/../data/files/FootprintAttachment/ + directory: %data_directory%files/FootprintAttachment/ footprint: local: - directory: %kernel.root_dir%/../data/images/footprint/ + directory: %data_directory%images/footprint/ partattachment: local: - directory: %kernel.root_dir%/../data/files/PartAttachment/ + directory: %data_directory%files/PartAttachment/ storagelocation: local: - directory: %kernel.root_dir%/../data/images/storagelocation/ + directory: %data_directory%images/storagelocation/ mimetype_icons: local: directory: %kernel.root_dir%/../src/PartKeepr/MimetypeIconsBundle/Resources/public/images/mimes/ projectattachment: local: - directory: %kernel.root_dir%/../data/files/ProjectAttachment/ + directory: %data_directory%files/ProjectAttachment/ filesystems: iclogo: adapter: iclogo diff --git a/src/PartKeepr/CoreBundle/Controller/DefaultController.php b/src/PartKeepr/CoreBundle/Controller/DefaultController.php @@ -28,7 +28,24 @@ class DefaultController extends FOSRestController * * @return array */ - public function getSystemInformationAction () { + public function getSystemInformationAction() + { return $this->get("partkeepr_systemservice")->getSystemInformation(); } + + /** + * Returns available disk space + * + * @Routing\Route("/api/disk_space", defaults={"method" = "get","_format" = "json"}) + * @View() + * + * @return array + */ + public function getDiskFreeSpaceAction() + { + return array( + "disk_total" => $this->get("partkeepr_systemservice")->getTotalDiskSpace(), + "disk_used" => $this->get("partkeepr_systemservice")->getUsedDiskSpace(), + ); + } } diff --git a/src/PartKeepr/CoreBundle/Services/SystemService.php b/src/PartKeepr/CoreBundle/Services/SystemService.php @@ -138,4 +138,53 @@ class SystemService extends ContainerAware return "complete"; } } + + /** + * Returns the available disk space for the configured data_dir. + * + * @return float + */ + public function getFreeDiskSpace () { + return disk_free_space($this->container->getParameter("data_dir")); + } + + public function getTotalDiskSpace () { + if ($this->container->getParameter("quota") === false) { + return disk_total_space($this->container->getParameter("data_dir")); + } else { + return $this->container->getParameter("quota"); + } + } + + /** + * Returns the used disk space occupied by attachments etc. + * + * Does not count temporary files. + * + * @return int + */ + public function getUsedDiskSpace () { + if ($this->container->getParameter("quota") === false) { + return $this->getTotalDiskSpace() - $this->getFreeDiskSpace(); + } + + $fileEntities = array( + 'PartKeepr\FootprintBundle\Entity\FootprintAttachment', + 'PartKeepr\FootprintBundle\Entity\FootprintImage', + 'PartKeepr\ManufacturerBundle\Entity\ManufacturerICLogo', + 'PartKeepr\PartBundle\Entity\PartAttachment', + 'PartKeepr\ProjectBundle\Entity\ProjectAttachment', + 'PartKeepr\StorageLocationBundle\Entity\StorageLocationImage' + ); + + $size = 0; + foreach ($fileEntities as $fileEntity) { + $qb = $this->container->get("doctrine.orm.default_entity_manager")->createQueryBuilder(); + $qb->select("SUM(a.size)")->from($fileEntity, "a"); + + $size += $qb->getQuery()->getSingleScalarResult(); + } + + return $size; + } } diff --git a/src/PartKeepr/FrontendBundle/Resources/public/js/Dialogs/FileUploadDialog.js b/src/PartKeepr/FrontendBundle/Resources/public/js/Dialogs/FileUploadDialog.js @@ -8,7 +8,9 @@ Ext.define('PartKeepr.FileUploadDialog', { layout: 'fit', resizable: false, modal: true, - iconCls: 'web-icon drive-upload', + defaults: { + labelWidth: 80 + }, initComponent: function () { @@ -19,8 +21,7 @@ Ext.define('PartKeepr.FileUploadDialog', { this.uploadButton = Ext.create("Ext.button.Button", { text: i18n('Upload'), - iconCls: 'web-icon drive-upload', - width: 120, + iconCls: 'fugue-icon drive-upload', handler: Ext.bind(function () { var form = this.form.getForm(); @@ -50,12 +51,17 @@ Ext.define('PartKeepr.FileUploadDialog', { this.urlField = Ext.create("Ext.form.field.Text", { fieldLabel: i18n("URL"), - labelWidth: 50, name: "url", anchor: '100%' }); - this.tbButtons = [this.uploadButton]; + this.diskUsage = Ext.create("Ext.ProgressBar", { + width: "200px" + }); + + this.diskUsage.updateProgress(0, i18n("Loading…")); + + this.tbButtons = [this.diskUsage, '->', this.uploadButton]; if (this.imageUpload) { @@ -65,8 +71,7 @@ Ext.define('PartKeepr.FileUploadDialog', { this.fileFormatButton = Ext.create("Ext.button.Button", { text: i18n("Available Formats"), - width: 120, - iconCls: 'web-icon infocard', + iconCls: 'fugue-icon infocard', handler: this.showAvailableFormats, scope: this }); @@ -78,7 +83,6 @@ Ext.define('PartKeepr.FileUploadDialog', { xtype: 'filefield', name: 'userfile', fieldLabel: this.fileFieldLabel, - labelWidth: 50, msgTarget: 'side', anchor: '100%', buttonText: this.uploadButtonText @@ -92,7 +96,7 @@ Ext.define('PartKeepr.FileUploadDialog', { }); this.form = Ext.create('Ext.form.Panel', { - width: 400, + width: 500, bodyPadding: 10, border: false, items: [ @@ -103,8 +107,10 @@ Ext.define('PartKeepr.FileUploadDialog', { }, this.fileField, { + xtype: 'fieldcontainer', + hideEmptyLabel: false, border: false, - style: 'margin-bottom: 20px;margin-left: 55px;', + style: 'margin-bottom: 20px;', layout: { type: 'hbox', pack: 'start', @@ -122,14 +128,33 @@ Ext.define('PartKeepr.FileUploadDialog', { }, this.urlField ], - buttons: this.tbButtons + dockedItems: [{ + xtype: 'toolbar', + dock: 'bottom', + ui: 'footer', + defaults: {minWidth: 120}, + items: this.tbButtons + }] }); this.on("beforedestroy", this.onBeforeDestroy, this); this.items = this.form; + + var call = new PartKeepr.ServiceCall("api", "disk_space"); + call.setHandler(Ext.bind(this.onDiskSpaceRetrieved, this)); + call.doCall(); + this.callParent(); }, + onDiskSpaceRetrieved: function (data) { + var usedString = PartKeepr.bytesToSize(data.disk_used), + totalString = PartKeepr.bytesToSize(data.disk_total); + + var text = usedString + " / " + totalString + " " + i18n("used"); + + this.diskUsage.updateProgress(data.disk_used / data.disk_total, text); + }, /** * Displays a little hint regarding the maximum upload size */