]> git.proxmox.com Git - pve-manager.git/blame - www/manager/node/APT.js
disable animation of charts on load
[pve-manager.git] / www / manager / node / APT.js
CommitLineData
719467c6
DM
1Ext.define('PVE.node.APT', {
2 extend: 'Ext.grid.GridPanel',
3
4 alias: ['widget.pveNodeAPT'],
5
6 initComponent : function() {
7 var me = this;
8
9 var nodename = me.pveSelNode.data.node;
10 if (!nodename) {
11 throw "no node name specified";
12 }
13
14 var store = Ext.create('Ext.data.Store', {
15 model: 'apt-pkglist',
a972b69d 16 groupField: 'Origin',
719467c6
DM
17 proxy: {
18 type: 'pve',
19 url: "/api2/json/nodes/" + nodename + "/apt/update"
20 },
21 sorters: [
22 {
23 property : 'Package',
24 direction: 'ASC'
25 }
26 ]
27 });
28
b9065f4d 29 var groupingFeature = Ext.create('Ext.grid.feature.Grouping', {
a972b69d
DM
30 groupHeaderTpl: '{[ "Origin: " + values.name ]} ({rows.length} Item{[values.rows.length > 1 ? "s" : ""]})',
31 enableGroupingMenu: false
719467c6
DM
32 });
33
b9065f4d
DM
34 var rowBodyFeature = Ext.create('Ext.grid.feature.RowBody', {
35 getAdditionalData: function (data, rowIndex, record, orig) {
36 var headerCt = this.view.headerCt;
37 var colspan = headerCt.getColumnCount();
38 // Usually you would style the my-body-class in CSS file
39 return {
40 rowBody: '<div style="padding: 1em">' + data.Description + '</div>',
41 rowBodyColspan: colspan
42 };
43 }
44 });
45
719467c6
DM
46 var reload = function() {
47 store.load();
48 };
49
b9065f4d 50 me.loadCount = 1; // avoid duplicate load mask
719467c6
DM
51 PVE.Utils.monStoreErrors(me, store);
52
b9065f4d
DM
53 var apt_command = function(cmd){
54 PVE.Utils.API2Request({
55 url: "/nodes/" + nodename + "/apt/" + cmd,
56 method: 'POST',
57 failure: function(response, opts) {
0070ee37 58 Ext.Msg.alert(gettext('Error'), response.htmlStatus);
b9065f4d
DM
59 },
60 success: function(response, opts) {
61 var upid = response.result.data;
62
7964ca34 63 var win = Ext.create('PVE.window.TaskViewer', {
b9065f4d
DM
64 upid: upid
65 });
66 win.show();
67 me.mon(win, 'close', reload);
68 }
69 });
70 };
71
37207a30
DM
72 var sm = Ext.create('Ext.selection.RowModel', {});
73
b9065f4d 74 var update_btn = new Ext.Button({
6f12dfc8 75 text: gettext('Refresh'),
b9065f4d 76 handler: function(){
9baa9680 77 PVE.Utils.checked_command(function() { apt_command('update'); });
b9065f4d
DM
78 }
79 });
80
ed51f6d6 81 var upgrade_btn = Ext.create('PVE.button.ConsoleButton', {
3a76893d 82 disabled: !(PVE.UserName && PVE.UserName === 'root@pam'),
ed51f6d6
DM
83 text: gettext('Upgrade'),
84 consoleType: 'upgrade',
85 nodename: nodename
86 });
b9065f4d 87
37207a30
DM
88 var show_changelog = function(rec) {
89 if (!rec || !rec.data || !(rec.data.ChangeLogUrl && rec.data.Package)) {
90 return;
91 }
92
396c9e4a
DM
93 var view = Ext.createWidget('component', {
94 autoScroll: true,
95 style: {
96 'background-color': 'white',
97 'white-space': 'pre',
98 'font-family': 'monospace',
99 padding: '5px'
100 }
101 });
102
37207a30
DM
103 var win = Ext.create('Ext.window.Window', {
104 title: gettext('Changelog') + ": " + rec.data.Package,
105 width: 800,
106 height: 400,
107 layout: 'fit',
108 modal: true,
396c9e4a
DM
109 items: [ view ]
110 });
111
112 PVE.Utils.API2Request({
113 waitMsgTarget: me,
114 url: "/nodes/" + nodename + "/apt/changelog",
115 params: {
116 name: rec.data.Package,
117 version: rec.data.Version
118 },
119 method: 'GET',
120 failure: function(response, opts) {
121 win.close();
0070ee37 122 Ext.Msg.alert(gettext('Error'), response.htmlStatus);
396c9e4a
DM
123 },
124 success: function(response, opts) {
125 win.show();
126 view.update(Ext.htmlEncode(response.result.data));
37207a30
DM
127 }
128 });
396c9e4a 129
37207a30
DM
130 };
131
132 var changelog_btn = new PVE.button.Button({
133 text: gettext('Changelog'),
134 selModel: sm,
135 disabled: true,
136 enableFn: function(rec) {
137 if (!rec || !rec.data || !(rec.data.ChangeLogUrl && rec.data.Package)) {
138 return false;
139 }
140 return true;
141 },
142 handler: function(b, e, rec) {
143 show_changelog(rec);
144 }
145 });
146
719467c6
DM
147 Ext.apply(me, {
148 store: store,
149 stateful: false,
37207a30 150 selModel: sm,
b9065f4d
DM
151 viewConfig: {
152 stripeRows: false,
6f12dfc8 153 emptyText: '<div style="display:table; width:100%; height:100%;"><div style="display:table-cell; vertical-align: middle; text-align:center;"><b>' + gettext('No updates available.') + '</div></div>'
b9065f4d 154 },
37207a30 155 tbar: [ update_btn, upgrade_btn, changelog_btn ],
b9065f4d 156 features: [ groupingFeature, rowBodyFeature ],
719467c6
DM
157 columns: [
158 {
159 header: gettext('Package'),
160 width: 200,
161 sortable: true,
162 dataIndex: 'Package'
163 },
164 {
b9065f4d
DM
165 text: gettext('Version'),
166 columns: [
167 {
168 header: gettext('current'),
169 width: 100,
170 sortable: false,
171 dataIndex: 'OldVersion'
172 },
173 {
174 header: gettext('new'),
175 width: 100,
176 sortable: false,
177 dataIndex: 'Version'
178 }
179 ]
719467c6
DM
180 },
181 {
182 header: gettext('Description'),
183 sortable: false,
184 dataIndex: 'Title',
185 flex: 1
186 }
187 ],
188 listeners: {
37207a30
DM
189 show: reload,
190 itemdblclick: function(v, rec) {
191 show_changelog(rec);
192 }
719467c6
DM
193 }
194 });
195
196 me.callParent();
197 }
198}, function() {
199
200 Ext.define('apt-pkglist', {
201 extend: 'Ext.data.Model',
202 fields: [ 'Package', 'Title', 'Description', 'Section', 'Arch',
a972b69d 203 'Priority', 'Version', 'OldVersion', 'ChangeLogUrl', 'Origin' ],
719467c6
DM
204 idProperty: 'Package'
205 });
206
207});