DiskDataTable.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. <?php
  2. /* * ********************************************************************
  3. * ProxmoxVPS Product developed. (26.03.19)
  4. * *
  5. *
  6. * CREATED BY MODULESGARDEN -> http://modulesgarden.com
  7. * CONTACT -> contact@modulesgarden.com
  8. *
  9. *
  10. * This software is furnished under a license and may be used and copied
  11. * only in accordance with the terms of such license and with the
  12. * inclusion of the above copyright notice. This software or any other
  13. * copies thereof may not be provided or otherwise made available to any
  14. * other person. No title to and ownership of the software is hereby
  15. * transferred.
  16. *
  17. *
  18. * ******************************************************************** */
  19. namespace ModulesGarden\Servers\ProxmoxCloudVps\App\UI\Disk\Pages;
  20. use ModulesGarden\ProxmoxAddon\App\Libs\Format;
  21. use ModulesGarden\ProxmoxAddon\App\Services\ApiService;
  22. use ModulesGarden\ProxmoxAddon\App\Services\Cloud\ProductService;
  23. use ModulesGarden\ProxmoxAddon\App\Services\Cloud\ResourceManager;
  24. use ModulesGarden\Servers\ProxmoxCloudVps\App\UI\Disk\Buttons\BackupSwitchButton;
  25. use ModulesGarden\Servers\ProxmoxCloudVps\App\UI\Disk\Buttons\CreateButton;
  26. use ModulesGarden\Servers\ProxmoxCloudVps\App\UI\Disk\Buttons\DeleteButton;
  27. use ModulesGarden\Servers\ProxmoxCloudVps\App\UI\Disk\Buttons\DeleteMassButton;
  28. use ModulesGarden\Servers\ProxmoxCloudVps\App\UI\Disk\Buttons\RestoreButton;
  29. use ModulesGarden\Servers\ProxmoxCloudVps\App\UI\Disk\Buttons\UpdateButton;
  30. use ModulesGarden\Servers\ProxmoxCloudVps\Core\UI\Interfaces\ClientArea;
  31. use ModulesGarden\Servers\ProxmoxCloudVps\Core\UI\Widget\DataTable\Column;
  32. use ModulesGarden\Servers\ProxmoxCloudVps\Core\UI\Widget\DataTable\DataProviders\Providers\ArrayDataProvider;
  33. use ModulesGarden\Servers\ProxmoxCloudVps\Core\UI\Widget\DataTable\DataTable;
  34. use function ModulesGarden\Servers\ProxmoxCloudVps\Core\Helper\sl;
  35. class DiskDataTable extends DataTable implements ClientArea
  36. {
  37. use ProductService;
  38. use ApiService;
  39. protected $id = 'diskDataTable';
  40. protected $name = 'diskDataTable';
  41. protected $title = 'diskDataTableTitle';
  42. public function initContent()
  43. {
  44. $vm = \ModulesGarden\ProxmoxAddon\Core\Helper\sl('Vm')->getVm();
  45. $resourceManager = new ResourceManager();
  46. if(!preg_match('/disk/', $vm->config()['hotplug'])){
  47. $this->setInternalAlertMessage("Adding, editing or removing disk will reboot the virtual machine.");
  48. }
  49. //Create
  50. $createButton = new CreateButton();
  51. $createButton->addClass("pmCreateDiskButton");
  52. if (!$resourceManager->disk()->hasFreeTotal())
  53. {
  54. $createButton->addClass("hidden");
  55. }
  56. $this->unsetShowTitle();
  57. $this->addButton($createButton);
  58. //Update
  59. $this->addActionButton(new UpdateButton());
  60. //Delete
  61. $this->addActionButton(new DeleteButton());
  62. logModuleCall(
  63. 'proxmoxCloud',
  64. __FUNCTION__,
  65. $this->getData() ,
  66. 'Debug',
  67. $this->getRawTitle()
  68. );
  69. }
  70. protected function loadHtml()
  71. {
  72. $this->addColumn((new Column('name'))->setSearchable(true, "string")->setOrderable('ASC'))
  73. ->addColumn((new Column('bus'))->setSearchable(true, "string")->setOrderable())
  74. ->addColumn((new Column('format'))->setSearchable(true)->setOrderable())
  75. ->addColumn((new Column('backup'))->setSearchable(true)->setOrderable())
  76. ->addColumn((new Column('bytes'))->setSearchable(true)->setOrderable());
  77. }
  78. public function replaceFieldName($key, $row)
  79. {
  80. $id = preg_replace('/[^0-9]/', '', $row[$key]);
  81. $id++;
  82. sl("lang")->addReplacementConstant("id",$id);
  83. return sl("lang")->abtr('Disk :id:');
  84. }
  85. public function replaceFieldBus($key, $row)
  86. {
  87. return sl("lang")->tr($row[$key]);
  88. }
  89. public function replaceFieldFormat($key, $row)
  90. {
  91. if ($row[$key])
  92. {
  93. return $row[$key];
  94. }
  95. return "raw";
  96. }
  97. public function replaceFieldBytes($key, $row)
  98. {
  99. return Format::convertBytes($row['bytes']);
  100. }
  101. public function replaceFieldCompress($key, $row)
  102. {
  103. return sl('lang')->tr($row['compress']);
  104. }
  105. public function customColumnHtmlBackup()
  106. {
  107. return (new BackupSwitchButton())->getHtml();
  108. }
  109. public function replaceFieldBackup($key, $row)
  110. {
  111. return $row['backup'] == "0" ? "off" : "on";
  112. }
  113. protected function loadData()
  114. {
  115. $data = [];
  116. $vm = \ModulesGarden\ProxmoxAddon\Core\Helper\sl('Vm')->getVm();
  117. foreach ( $vm->getHardDisks() as $entity)
  118. {
  119. $data[] = [
  120. "id" => $entity->getId(),
  121. "bus" => $entity->getId(),
  122. "name" => $entity->getName(),
  123. "format" => $entity->getFormat(),
  124. "backup" => $entity->getBackup(),
  125. "size" => $entity->getSize(),
  126. "bytes" => $entity->getBytes(),
  127. "master" => $entity->isMaster(),
  128. ];
  129. }
  130. $dataProv = new ArrayDataProvider();
  131. $dataProv->setDefaultSorting("name", 'ASC');
  132. $dataProv->setData($data);
  133. $this->setDataProvider($dataProv);
  134. }
  135. }