MountPointDataTable.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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\ProxmoxVps\App\UI\MountPoint\Pages;
  20. use ModulesGarden\ProxmoxAddon\App\Libs\Format;
  21. use ModulesGarden\ProxmoxAddon\App\Services\ApiService;
  22. use ModulesGarden\ProxmoxAddon\App\Services\Vps\ProductService;
  23. use ModulesGarden\Servers\ProxmoxVps\App\UI\MountPoint\Buttons\BackupSwitchButton;
  24. use ModulesGarden\Servers\ProxmoxVps\App\UI\MountPoint\Buttons\CreateButton;
  25. use ModulesGarden\Servers\ProxmoxVps\App\UI\MountPoint\Buttons\DeleteButton;
  26. use ModulesGarden\Servers\ProxmoxVps\App\UI\MountPoint\Buttons\DeleteMassButton;
  27. use ModulesGarden\Servers\ProxmoxVps\App\UI\MountPoint\Buttons\RestoreButton;
  28. use ModulesGarden\Servers\ProxmoxVps\App\UI\MountPoint\Buttons\UpdateButton;
  29. use ModulesGarden\Servers\ProxmoxVps\Core\UI\Interfaces\ClientArea;
  30. use ModulesGarden\Servers\ProxmoxVps\Core\UI\Widget\DataTable\Column;
  31. use ModulesGarden\Servers\ProxmoxVps\Core\UI\Widget\DataTable\DataProviders\Providers\ArrayDataProvider;
  32. use ModulesGarden\Servers\ProxmoxVps\Core\UI\Widget\DataTable\DataTable;
  33. use function ModulesGarden\Servers\ProxmoxVps\Core\Helper\sl;
  34. class MountPointDataTable extends DataTable implements ClientArea
  35. {
  36. use ApiService;
  37. use ProductService;
  38. protected $id = 'mountPointDataTable';
  39. protected $title = 'mountPointDataTable';
  40. public function initContent()
  41. {
  42. $this->setInternalAlertMessage("Adding, editing or removing disk will reboot the virtual machine.");
  43. //Create
  44. $createButton = new CreateButton();
  45. $createButton->addClass("pmCreateButton");
  46. if (!$this->resourceGuard()->hasMountPointLimit())
  47. {
  48. $createButton->addClass("hidden");
  49. }
  50. $this->addButton($createButton);
  51. //Update
  52. $this->addActionButton(new UpdateButton());
  53. //Delete
  54. $this->addActionButton(new DeleteButton());
  55. }
  56. protected function loadHtml()
  57. {
  58. $this->addColumn((new Column('id'))->setSearchable(true, "string")->setOrderable('DESC'))
  59. ->addColumn((new Column('name'))->setSearchable(true, "string")->setOrderable())
  60. ->addColumn((new Column('mp'))->setSearchable(true)->setOrderable())
  61. ->addColumn((new Column('backup'))->setSearchable(true)->setOrderable())
  62. ->addColumn((new Column('bytes'))->setSearchable(true)->setOrderable());
  63. }
  64. public function replaceFieldName($key, $row)
  65. {
  66. return sl("lang")->tr($row[$key]);
  67. }
  68. public function replaceFieldPath($key, $row)
  69. {
  70. if ($row[$key])
  71. {
  72. return $row[$key];
  73. }
  74. return '-';
  75. }
  76. public function customColumnHtmlBackup()
  77. {
  78. return (new BackupSwitchButton())->getHtml();
  79. }
  80. public function replaceFieldBackup($key, $row)
  81. {
  82. if ($row['master'])
  83. {
  84. return "on";
  85. }
  86. return $row['backup'] == "1" ? "on" : "off";
  87. }
  88. public function replaceFieldBytes($key, $row)
  89. {
  90. return Format::convertBytes($row['bytes']);
  91. }
  92. protected function loadData()
  93. {
  94. $data = [];
  95. foreach ($this->vm()->getMounPoints()->fetch() as $entity)
  96. {
  97. $data[] = [
  98. "id" => $entity->getId(),
  99. "name" => $entity->getName(),
  100. "mp" => $entity->getMp(),
  101. "backup" => $entity->getBackup(),
  102. "size" => $entity->getSize(),
  103. "bytes" => $entity->getBytes(),
  104. "master" => $entity->getId() == "rootfs"
  105. ];
  106. }
  107. $dataProv = new ArrayDataProvider();
  108. $dataProv->setDefaultSorting("id", 'DESC');
  109. $dataProv->setData($data);
  110. $this->setDataProvider($dataProv);
  111. }
  112. }