]> git.datanom.net - omvzfs.git/blob - gui/js/omv/module/admin/storage/zfs/Overview.js
0bad63995853a5ddcb0ed1090d861163a5a3abc0
[omvzfs.git] / gui / js / omv / module / admin / storage / zfs / Overview.js
1 // require("js/omv/tree/Panel.js")
2 // require("js/omv/module/admin/storage/zfs/TreePanel.js")
3 // require("js/omv/workspace/window/Grid.js")
4 // require("js/omv/form/field/CheckboxGrid.js")
5
6 Ext.define("OMV.module.admin.storage.zfs.ShowDetails", {
7 extend: "OMV.workspace.window.Form",
8 requires: [
9 "OMV.data.Store",
10 "OMV.data.Model",
11 "OMV.data.proxy.Rpc",
12 ],
13
14 rpcService: "ZFS",
15 title: _("Object details"),
16 autoLoadData: true,
17 hideResetButton: true,
18 hideCancelButton: true,
19 width: 550,
20 height: 350,
21 layout: 'fit',
22 okButtonText: _("Ok"),
23
24 getFormItems: function() {
25 var me = this;
26
27 return [{
28 xtype: "textareafield",
29 name: "details",
30 grow: true,
31 anchor: '100%',
32 readOnly: true
33 }];
34
35 }
36 });
37
38 Ext.define("OMV.module.admin.storage.zfs.AddPool", {
39 extend: "OMV.workspace.window.Form",
40 requires: [
41 "OMV.data.Store",
42 "OMV.data.Model",
43 "OMV.data.proxy.Rpc",
44 "OMV.form.field.CheckboxGrid"
45 ],
46
47 rpcService: "ZFS",
48 rpcSetMethod: "addPool",
49 title: _("Create ZFS pool"),
50 autoLoadData: false,
51 hideResetButton: true,
52 width: 550,
53 height: 350,
54
55 getFormItems: function() {
56 var me = this;
57 return [{
58 xtype: "textfield",
59 name: "name",
60 fieldLabel: _("Name")
61 },{
62 xtype: "combo",
63 name: "pooltype",
64 fieldLabel: _("Pool type"),
65 queryMode: "local",
66 store: Ext.create("Ext.data.ArrayStore", {
67 fields: [ "value", "text" ],
68 data: [
69 [ "basic", _("Basic") ],
70 [ "mirror", _("Mirror") ],
71 [ "raidz1", _("RAID-Z1") ],
72 [ "raidz2", _("RAID-Z2") ],
73 [ "raidz3", _("RAID-Z3") ]
74 ]
75 }),
76 displayField: "text",
77 valueField: "value",
78 allowBlank: false,
79 editable: false,
80 triggerAction: "all",
81 value: "raidz1",
82 listeners: {
83 scope: me,
84 change: function(combo, value) {
85 var devicesField = this.findField("devices");
86 switch(value) {
87 case "basic":
88 devicesField.minSelections = 1;
89 break;
90 case "mirror":
91 devicesField.minSelections = 2;
92 break;
93 case "raidz1":
94 devicesField.minSelections = 3;
95 break;
96 case "raidz2":
97 devicesField.minSelections = 4;
98 case "raidz3":
99 devicesField.minSelections = 5;
100 break;
101 default:
102 devicesField.minSelections = 2;
103 break;
104 }
105 devicesField.validate();
106 }
107 }
108 },{
109 xtype: "checkboxgridfield",
110 name: "devices",
111 fieldLabel: _("Devices"),
112 valueField: "devicefile",
113 minSelections: 3, // Min. number of devices for RAIDZ-1
114 useStringValue: true,
115 height: 130,
116 store: Ext.create("OMV.data.Store", {
117 autoLoad: true,
118 model: OMV.data.Model.createImplicit({
119 idProperty: "devicefile",
120 fields: [
121 { name: "devicefile", type: "string" },
122 { name: "size", type: "string" },
123 { name: "vendor", type: "string" },
124 { name: "serialnumber", type: "string" }
125 ]
126 }),
127 proxy: {
128 type: "rpc",
129 appendSortParams: false,
130 rpcData: {
131 service: "RaidMgmt",
132 method: "getCandidates"
133 }
134 },
135 sorters: [{
136 direction: "ASC",
137 property: "devicefile"
138 }]
139 }),
140 gridConfig: {
141 stateful: true,
142 stateId: "1866b5d0-327e-11e4-8c21-0800200c9a66",
143 columns: [{
144 text: _("Device"),
145 sortable: true,
146 dataIndex: "devicefile",
147 stateId: "devicefile",
148 flex: 1
149 },{
150 xtype: "binaryunitcolumn",
151 text: _("Capacity"),
152 sortable: true,
153 dataIndex: "size",
154 stateId: "size",
155 width: 50,
156 flex: 1
157 },{
158 text: _("Vendor"),
159 sortable: true,
160 dataIndex: "vendor",
161 stateId: "vendor",
162 flex: 1
163 },{
164 text: _("Serial Number"),
165 sortable: true,
166 dataIndex: "serialnumber",
167 stateId: "serialnumber",
168 flex: 1
169 }]
170 }
171 },{
172 xtype: "textfield",
173 name: "mountpoint",
174 fieldLabel: _("Mountpoint"),
175 plugins: [{
176 ptype: "fieldinfo",
177 text: _("Optional mountpoint for the pool. Default is to use pool name.")
178 }]
179 },{
180 xtype: "checkbox",
181 name: "force",
182 fieldLabel: _("Force creation"),
183 checked: false,
184 plugins: [{
185 ptype: "fieldinfo",
186 text: _("Forces the creation of the pool even if errors are reported. Use with extreme caution!")
187 }]
188 }];
189 },
190
191 doSubmit: function() {
192 var me = this;
193 OMV.MessageBox.show({
194 title: _("Confirmation"),
195 msg: _("Do you really want to create the ZFS pool?"),
196 buttons: Ext.Msg.YESNO,
197 fn: function(answer) {
198 if(answer === "no")
199 return;
200 me.superclass.doSubmit.call(me);
201 },
202 scope: me,
203 icon: Ext.Msg.QUESTION
204 });
205 }
206 });
207
208 Ext.define("OMV.module.admin.storage.zfs.AddObject", {
209 extend: "OMV.workspace.window.Form",
210 uses: [
211 "OMV.data.Store",
212 "OMV.data.Model",
213 "OMV.data.proxy.Rpc",
214 "OMV.data.reader.RpcArray"
215 ],
216
217 rpcService: "ZFS",
218 rpcSetMethod: "addObject",
219 width: 420,
220
221 getFormItems: function() {
222 var me = this;
223 return [{
224 xtype: "combo",
225 name: "type",
226 fieldLabel: _("Object Type"),
227 queryMode: "local",
228 store: [
229 [ "filesystem", "Filesystem" ],
230 [ "snapshot", "Snapshot" ],
231 [ "volume", "Volume" ]
232 ],
233 allowBlank: true,
234 editable: false,
235 triggerAction: "all",
236 value: "filesystem",
237 listeners: {
238 scope: me,
239 change: function(combo, value) {
240 var sizeField = this.findField("size");
241 switch(value) {
242 case "volume":
243 sizeField.show();
244 sizeField.allowBlank = false;
245 break;
246 default:
247 sizeField.hide();
248 sizeField.allowBlank = true;
249 break;
250 }
251 sizeField.validate();
252 }
253 }
254 },{
255 xtype: "textfield",
256 name: "path",
257 fieldLabel: _("Prefix"),
258 allowBlank: false,
259 readOnly: true
260 },{
261 xtype: "textfield",
262 name: "name",
263 fieldLabel: _("Name"),
264 allowBlank: false,
265 plugins: [{
266 ptype: "fieldinfo",
267 text: _("Name of the new object. Prefix will prepend the name. Please omit leading /")
268 }]
269 },{
270 xtype: "textfield",
271 name: "size",
272 hidden: true,
273 fieldLabel: _("Size"),
274 allowBlank: true,
275 plugins: [{
276 ptype: "fieldinfo",
277 text: _("Size of the volume e.g. 5mb,100gb,1tb etc")
278 }]
279 }];
280 }
281 });
282
283 Ext.define("OMV.module.admin.storage.zfs.ExpandPool", {
284 extend: "OMV.workspace.window.Form",
285 uses: [
286 "OMV.data.Store",
287 "OMV.data.Model",
288 "OMV.data.proxy.Rpc",
289 "OMV.data.reader.RpcArray"
290 ],
291
292 rpcService: "ZFS",
293 rpcSetMethod: "expandPool",
294 width: 550,
295 height: 350,
296 autoLoadData: true,
297
298 getFormItems: function() {
299 var me = this;
300 return [{
301 xtype: "textfield",
302 name: "name",
303 fieldLabel: _("Name"),
304 allowBlank: false,
305 readOnly: true,
306 value: me.name
307 },{
308 xtype: "textfield",
309 name: "pool_type",
310 fieldLabel: _("Pool type"),
311 allowBlank: false,
312 readOnly: true,
313 value: me.pool_type
314 },{
315 xtype: "checkboxgridfield",
316 name: "devices",
317 fieldLabel: _("Devices"),
318 valueField: "devicefile",
319 listeners: {
320 scope: me,
321 change: function(e, eOpts) {
322 var deviceField = this.findField("devices");
323 if (me.pool_type == "Basic") {
324 deviceField.minSelections = 1;
325 } else {
326 deviceField.minSelections = me.nr_disks;
327 deviceField.maxSelections = me.nr_disks;
328 }
329 }
330 },
331 useStringValue: true,
332 height: 130,
333 store: Ext.create("OMV.data.Store", {
334 autoLoad: true,
335 model: OMV.data.Model.createImplicit({
336 idProperty: "devicefile",
337 fields: [
338 { name: "devicefile", type: "string" },
339 { name: "size", type: "string" },
340 { name: "vendor", type: "string" },
341 { name: "serialnumber", type: "string" }
342 ]
343 }),
344 proxy: {
345 type: "rpc",
346 appendSortParams: false,
347 rpcData: {
348 service: "RaidMgmt",
349 method: "getCandidates"
350 }
351 },
352 sorters: [{
353 direction: "ASC",
354 property: "devicefile"
355 }]
356 }),
357 gridConfig: {
358 stateful: true,
359 stateId: "04942d40-4ee3-11e4-916c-0800200c9a66",
360 columns: [{
361 text: _("Device"),
362 sortable: true,
363 dataIndex: "devicefile",
364 stateId: "devicefile",
365 flex: 1
366 },{
367 xtype: "binaryunitcolumn",
368 text: _("Capacity"),
369 sortable: true,
370 dataIndex: "size",
371 stateId: "size",
372 width: 50,
373 flex: 1
374 },{
375 text: _("Vendor"),
376 sortable: true,
377 dataIndex: "vendor",
378 stateId: "vendor",
379 flex: 1
380 },{
381 text: _("Serial Number"),
382 sortable: true,
383 dataIndex: "serialnumber",
384 stateId: "serialnumber",
385 flex: 1
386 }]
387 }
388 }];
389 }
390 });
391
392
393 Ext.define("OMV.module.admin.storage.zfs.EditProperties", {
394 extend: "OMV.workspace.window.Grid",
395 requires: [
396 "OMV.data.Store",
397 "OMV.data.Model",
398 "OMV.data.proxy.Rpc"
399 ],
400
401 rpcService: "ZFS",
402 rpcSetMethod: "setProperties",
403
404 title: _("Edit properties"),
405 width: 500,
406 height: 305,
407
408 getGridConfig: function() {
409 var me = this;
410
411 var rowEditing = Ext.create('Ext.grid.plugin.RowEditing', {
412 clicksToEdit: 1,
413 pluginId: 'rowEditing',
414 listeners: {
415 validateedit: function(editor, e, eOpts) {
416 e.record.set("modified", "true");
417 },
418 beforeedit: function(editor, e, eOpts) {
419 if (e.record.get("newproperty") === "false") {
420 e.grid.getPlugin('rowEditing').editor.form.findField("value").enable();
421 e.grid.getPlugin('rowEditing').editor.form.findField("property").disable();
422 } else {
423 e.grid.getPlugin('rowEditing').editor.form.findField("value").enable();
424 e.grid.getPlugin('rowEditing').editor.form.findField("property").enable();
425 }
426 }
427
428 }
429 });
430
431 var store = Ext.create("OMV.data.Store", {
432 autoLoad: true,
433 model: OMV.data.Model.createImplicit({
434 fields: [
435 { name: "property", type: "string" },
436 { name: "value", type: "string" },
437 { name: "source", type: "string" },
438 { name: "modified", type: "string" },
439 { name: "newproperty", type: "string", defaultValue: "false" }
440 ]
441 }),
442 proxy: {
443 type: "rpc",
444 rpcData: {
445 service: "ZFS",
446 method: "getProperties",
447 params: {
448 name: me.name,
449 type: me.type
450 }
451 }
452 }
453 });
454
455 return {
456 border: false,
457 stateful: true,
458 stateId: "8c3dc800-bdbb-11e3-b1b6-0800200c9a66",
459 selType: 'rowmodel',
460 plugins: [rowEditing],
461 store: store,
462 tbar: [{
463 text: "Add property",
464 icon: "images/add.png",
465 iconCls: Ext.baseCSSPrefix + "btn-icon-16x16",
466 handler: function(view) {
467 Ext.define('Property', {
468 extend: 'Ext.data.Model',
469 fields: [
470 "property",
471 "value",
472 "source",
473 "modified",
474 "newproperty"
475 ]
476 });
477 var newProperty = Ext.create("Property", {
478 property: "",
479 value: "",
480 source: "local",
481 modified: "true",
482 newproperty: "true"
483 });
484 rowEditing.cancelEdit();
485 store.insert(0, newProperty);
486 rowEditing.startEdit();
487 }
488 }],
489 columns: [{
490 text: _("Property"),
491 sortable: true,
492 dataIndex: "property",
493 stateId: "property",
494 editor: {
495 xtype: "textfield",
496 allowBlank: false,
497 }
498 },{
499 text: _("Value"),
500 sortable: true,
501 dataIndex: "value",
502 stateId: "value",
503 flex: 1,
504 readOnly: true,
505 editor: {
506 xtype: "textfield",
507 allowBlank: false,
508 }
509 },{
510 text: _("Source"),
511 sortable: true,
512 dataIndex: "source",
513 stateId: "source",
514 },{
515 xtype: 'actioncolumn',
516 header: 'Inherit',
517 icon: "images/checkmark.png",
518 tooltip: "Inherit",
519 handler: function(view, rowIndex, colIndex, item, e, record, row) {
520 OMV.RpcObserver.request({
521 msg : _("Updating property..."),
522 rpcData : {
523 service: "ZFS",
524 method: "inherit",
525 params: {
526 name: me.name,
527 type: me.type,
528 property: record.get("property")
529 }
530 },
531 finish : function() {
532 view.getStore().reload();
533 }
534 });
535 },
536 isDisabled: function(view, rowIdx, colIdx, item, record) {
537 var src = record.get("source");
538 if(src === "local") {
539 return false;
540 } else {
541 return true;
542 }
543 }
544 },{
545 text: _("New"),
546 dataIndex: "newproperty",
547 stateId: "newproperty",
548 sortable: false,
549 hidden: true
550 },{
551 text: _("Modified"),
552 sortable: false,
553 dataIndex: "modified",
554 stateId: "modified",
555 hidden: true
556 }],
557 };
558 },
559
560 getRpcSetParams: function() {
561 var me = this;
562 var properties = [];
563 var values = me.getValues();
564 Ext.Array.each(values, function(value) {
565 if(value.modified === "false")
566 return;
567 properties.push({
568 "property": value.property,
569 "value": value.value,
570 });
571 });
572 return {
573 name: me.name,
574 type: me.type,
575 properties: properties
576 };
577 }
578
579 });
580
581
582 Ext.define("OMV.module.admin.storage.zfs.CreateShare", {
583 extend: "OMV.workspace.window.Form",
584 uses: [
585 "OMV.data.Store",
586 "OMV.data.Model",
587 "OMV.data.proxy.Rpc",
588 "OMV.data.reader.RpcArray"
589 ],
590
591 rpcService: "ZFS",
592 rpcSetMethod: "createShare",
593 width: 500,
594
595 getFormItems: function() {
596 var me = this;
597 return [{
598 xtype: "textfield",
599 name: "sharename",
600 fieldLabel: _("Name"),
601 allowBlank: false,
602 },{
603 xtype: "textfield",
604 name: "mountpoint",
605 fieldLabel: _("Path"),
606 allowBlank: true,
607 readOnly: false
608 },{
609 xtype: "combo",
610 name: "mode",
611 fieldLabel: _("Permissions"),
612 queryMode: "local",
613 store: Ext.create("Ext.data.ArrayStore", {
614 fields: [ "value", "text" ],
615 data: [
616 [ "700", _("Administrator: read/write, Users: no access, Others: no access") ],
617 [ "750", _("Administrator: read/write, Users: read-only, Others: no access") ],
618 [ "770", _("Administrator: read/write, Users: read/write, Others: no access") ],
619 [ "755", _("Administrator: read/write, Users: read-only, Others: read-only") ],
620 [ "775", _("Administrator: read/write, Users: read/write, Others: read-only") ],
621 [ "777", _("Everyone: read/write") ]
622 ]
623 }),
624 displayField: "text",
625 valueField: "value",
626 allowBlank: false,
627 editable: false,
628 showItemTooltip: true,
629 triggerAction: "all",
630 value: "775",
631 plugins: [{
632 ptype: "fieldinfo",
633 text: _("The file mode of the shared folder path.")
634 }]
635 },{
636 xtype: "textarea",
637 name: "comment",
638 fieldLabel: _("Comment"),
639 allowBlank: true
640 },{
641 xtype: "textarea",
642 name: "name",
643 hidden: true
644 },{
645 xtype: "textarea",
646 name: "type",
647 hidden: true
648 }];
649 }
650 });
651
652
653
654 Ext.define("OMV.module.admin.storage.zfs.Overview", {
655 extend: "OMV.module.admin.storage.zfs.TreePanel",
656
657 rpcService: "ZFS",
658 rpcGetMethod: "getObjectTree",
659 requires: [
660 "OMV.data.Store",
661 "OMV.data.Model",
662 "OMV.data.proxy.Rpc"
663 ],
664
665 rootVisible: false,
666 stateful: true,
667 stateId: "cec54550-bc2a-11e3-a5e2-0800200c9a66",
668
669 columns: [{
670 text: _("Name"),
671 xtype: 'treecolumn',
672 dataIndex: 'name',
673 sortable: true,
674 flex: 2,
675 stateId: 'name'
676 },{
677 text: _("Type"),
678 dataIndex: 'type',
679 sortable: true,
680 flex: 1,
681 stateId: 'type',
682 renderer: function(value, p, r){
683 if (r.data['type'] == "Pool") {
684 return r.data['type'] + ' (' + r.data['pool_type'] + ')';
685 } else {
686 return r.data['type'];
687 }
688 }
689 },{
690 text: _("Size"),
691 dataIndex: 'size',
692 sortable: true,
693 flex: 1,
694 stateId: 'size'
695 },{
696 text: _("Used"),
697 dataIndex: 'used',
698 sortable: true,
699 flex: 1,
700 stateId: 'used'
701 },{
702 text: _("Available"),
703 dataIndex: 'available',
704 sortable: true,
705 flex: 1,
706 stateId: 'available'
707 },{
708 text: _("Mountpoint"),
709 dataIndex: 'mountpoint',
710 sortable: true,
711 flex: 1,
712 stateId: 'mountpoint'
713 },{
714 text: _("Share"),
715 xtype: 'actioncolumn',
716 tooltip: 'Create shared folder',
717 align: 'center',
718 icon: 'images/checkmark.png',
719 handler: function(view, rowIndex, colIndex, item, e, record, row) {
720 var me = this;
721 Ext.create("OMV.module.admin.storage.zfs.CreateShare", {
722 title: _("Create shared folder"),
723 rpcGetMethod: "getSharedParams",
724 rpcGetParams: {
725 name: record.get('path'),
726 type: record.get('type')
727 }
728 }).show();
729 },
730 isDisabled: function(view, rowIdx, colIdx, item, record) {
731 var src = record.get("type");
732 if((src === "Filesystem") && (record.get("shared") === "false")) {
733 return false;
734 } else {
735 return true;
736 }
737 }
738 },{
739 text: _("Details"),
740 xtype: 'actioncolumn',
741 tooltip: 'Details',
742 align: 'center',
743 icon: 'images/search.png',
744 handler: function(view, rowIndex, colIndex, item, e, record, row) {
745 var me = this;
746 Ext.create("OMV.module.admin.storage.zfs.ShowDetails", {
747 title: _("Object details"),
748 rpcGetMethod: "getObjectDetails",
749 rpcGetParams: {
750 name: record.get('path'),
751 type: record.get('type')
752 }
753 }).show();
754 }
755 },{
756 text: _("Shared"),
757 dataIndex: 'shared',
758 sortable: false,
759 stateId: 'shared',
760 hidden: true
761 }],
762
763 initComponent: function() {
764 var me = this;
765 this.width = 600;
766 Ext.apply(me, {
767 store: Ext.create("Ext.data.TreeStore", {
768 autoLoad: true,
769 model: OMV.data.Model.createImplicit({
770 fields: [
771 { name: "name", type: "string" },
772 { name: "type", type: "string" },
773 { name: "size", type: "string" },
774 { name: "used", type: "string" },
775 { name: "available", type: "string" },
776 { name: "mountpoint", type: "string" },
777 { name: "id", type: "string" },
778 { name: "path", type: "string" },
779 { name: "origin", type: "string", defaultValue: "none" },
780 { name: "shared", type: "string", defaultValue: "false" },
781 { name: "pool_type", type: "string"},
782 { name: "nr_disks", type: "string"}
783 ]
784 }),
785 proxy: {
786 type: "rpc",
787 rpcData: {
788 service: "ZFS",
789 method: "getObjectTree",
790 }
791 },
792 folderSort: true
793 })
794 });
795 me.callParent(arguments);
796 },
797
798 onAddButton: function() {
799 var me = this;
800 Ext.create("OMV.module.admin.storage.zfs.AddPool", {
801 listeners: {
802 scope: me,
803 submit: function() {
804 this.doReload();
805 }
806 }
807 }).show();
808 },
809
810 onAddObjButton: function() {
811 var me = this;
812 var sm = me.getSelectionModel();
813 var records = sm.getSelection();
814 var record = records[0];
815 Ext.create("OMV.module.admin.storage.zfs.AddObject", {
816 title: _("Add Object"),
817 rpcGetMethod: "passParam",
818 rpcGetParams: {
819 key: "path",
820 value: record.get('path')
821 },
822 listeners: {
823 scope: me,
824 submit: function() {
825 this.doReload();
826 }
827 }
828 }).show();
829 },
830
831 onEditButton: function() {
832 var me = this;
833 var sm = me.getSelectionModel();
834 var records = sm.getSelection();
835 var record = records[0];
836 Ext.create("OMV.module.admin.storage.zfs.EditProperties", {
837 name: record.get("path"),
838 type: record.get("type")
839 }).show();
840 },
841
842 onExpandPoolButton: function() {
843 var me = this;
844 var sm = me.getSelectionModel();
845 var records = sm.getSelection();
846 var record = records[0];
847 Ext.create("OMV.module.admin.storage.zfs.ExpandPool", {
848 title: _("Expand Pool"),
849 name: record.get("path"),
850 type: record.get("type"),
851 pool_type: record.get("pool_type"),
852 nr_disks: record.get("nr_disks"),
853 listeners: {
854 scope: me,
855 submit: function() {
856 this.doReload();
857 }
858 }
859 }).show();
860 },
861
862 doDeletion: function(record) {
863 var me = this;
864 OMV.Rpc.request({
865 scope: me,
866 callback: me.onDeletion,
867 rpcData: {
868 service: "ZFS",
869 method: "deleteObject",
870 params: {
871 name: record.get('path'),
872 type: record.get('type')
873 }
874 }
875 });
876 }
877
878 });
879
880 OMV.WorkspaceManager.registerPanel({
881 id: "overview",
882 path: "/storage/zfs",
883 text: _("Overview"),
884 position: 10,
885 className: "OMV.module.admin.storage.zfs.Overview"
886 });
887
888
889
This page took 0.155085 seconds and 4 git commands to generate.