]>
Commit | Line | Data |
---|---|---|
5f93e010 DM |
1 | Ext.define('apt-pkglist', { |
2 | extend: 'Ext.data.Model', | |
01031528 TL |
3 | fields: ['Package', 'Title', 'Description', 'Section', 'Arch', |
4 | 'Priority', 'Version', 'OldVersion', 'ChangeLogUrl', 'Origin'], | |
5 | idProperty: 'Package', | |
5f93e010 DM |
6 | }); |
7 | ||
8 | Ext.define('Proxmox.node.APT', { | |
9 | extend: 'Ext.grid.GridPanel', | |
10 | ||
11 | xtype: 'proxmoxNodeAPT', | |
12 | ||
13 | upgradeBtn: undefined, | |
14 | ||
15 | columns: [ | |
16 | { | |
17 | header: gettext('Package'), | |
18 | width: 200, | |
19 | sortable: true, | |
01031528 | 20 | dataIndex: 'Package', |
5f93e010 DM |
21 | }, |
22 | { | |
23 | text: gettext('Version'), | |
24 | columns: [ | |
25 | { | |
26 | header: gettext('current'), | |
27 | width: 100, | |
28 | sortable: false, | |
01031528 | 29 | dataIndex: 'OldVersion', |
5f93e010 DM |
30 | }, |
31 | { | |
32 | header: gettext('new'), | |
33 | width: 100, | |
34 | sortable: false, | |
01031528 TL |
35 | dataIndex: 'Version', |
36 | }, | |
37 | ], | |
5f93e010 DM |
38 | }, |
39 | { | |
40 | header: gettext('Description'), | |
41 | sortable: false, | |
42 | dataIndex: 'Title', | |
01031528 TL |
43 | flex: 1, |
44 | }, | |
5f93e010 DM |
45 | ], |
46 | ||
01031528 | 47 | initComponent: function() { |
05a977a2 | 48 | let me = this; |
5f93e010 DM |
49 | |
50 | if (!me.nodename) { | |
51 | throw "no node name specified"; | |
52 | } | |
53 | ||
05a977a2 | 54 | let store = Ext.create('Ext.data.Store', { |
5f93e010 DM |
55 | model: 'apt-pkglist', |
56 | groupField: 'Origin', | |
57 | proxy: { | |
f12e1aba | 58 | type: 'proxmox', |
01031528 | 59 | url: "/api2/json/nodes/" + me.nodename + "/apt/update", |
5f93e010 DM |
60 | }, |
61 | sorters: [ | |
62 | { | |
01031528 TL |
63 | property: 'Package', |
64 | direction: 'ASC', | |
65 | }, | |
66 | ], | |
5f93e010 DM |
67 | }); |
68 | ||
05a977a2 | 69 | let groupingFeature = Ext.create('Ext.grid.feature.Grouping', { |
5f93e010 | 70 | groupHeaderTpl: '{[ "Origin: " + values.name ]} ({rows.length} Item{[values.rows.length > 1 ? "s" : ""]})', |
01031528 | 71 | enableGroupingMenu: false, |
5f93e010 DM |
72 | }); |
73 | ||
05a977a2 | 74 | let rowBodyFeature = Ext.create('Ext.grid.feature.RowBody', { |
01031528 | 75 | getAdditionalData: function(data, rowIndex, record, orig) { |
05a977a2 TL |
76 | let headerCt = this.view.headerCt; |
77 | let colspan = headerCt.getColumnCount(); | |
f12e1aba TL |
78 | return { |
79 | rowBody: '<div style="padding: 1em">' + | |
5f93e010 DM |
80 | Ext.String.htmlEncode(data.Description) + |
81 | '</div>', | |
6895e13f | 82 | rowBodyCls: me.full_description ? '' : Ext.baseCSSPrefix + 'grid-row-body-hidden', |
01031528 | 83 | rowBodyColspan: colspan, |
f12e1aba | 84 | }; |
01031528 | 85 | }, |
5f93e010 DM |
86 | }); |
87 | ||
05a977a2 | 88 | let reload = function() { |
5f93e010 DM |
89 | store.load(); |
90 | }; | |
91 | ||
92 | Proxmox.Utils.monStoreErrors(me, store, true); | |
93 | ||
05a977a2 | 94 | let apt_command = function(cmd) { |
5f93e010 DM |
95 | Proxmox.Utils.API2Request({ |
96 | url: "/nodes/" + me.nodename + "/apt/" + cmd, | |
97 | method: 'POST', | |
98 | failure: function(response, opts) { | |
99 | Ext.Msg.alert(gettext('Error'), response.htmlStatus); | |
100 | }, | |
101 | success: function(response, opts) { | |
05a977a2 | 102 | let upid = response.result.data; |
5f93e010 | 103 | |
05a977a2 | 104 | let win = Ext.create('Proxmox.window.TaskViewer', { |
01031528 | 105 | upid: upid, |
5f93e010 DM |
106 | }); |
107 | win.show(); | |
108 | me.mon(win, 'close', reload); | |
01031528 | 109 | }, |
5f93e010 DM |
110 | }); |
111 | }; | |
112 | ||
05a977a2 | 113 | let sm = Ext.create('Ext.selection.RowModel', {}); |
5f93e010 | 114 | |
05a977a2 | 115 | let update_btn = new Ext.Button({ |
5f93e010 | 116 | text: gettext('Refresh'), |
f12e1aba | 117 | handler: function() { |
5f93e010 | 118 | Proxmox.Utils.checked_command(function() { apt_command('update'); }); |
01031528 | 119 | }, |
5f93e010 DM |
120 | }); |
121 | ||
05a977a2 | 122 | let show_changelog = function(rec) { |
5f93e010 DM |
123 | if (!rec || !rec.data || !(rec.data.ChangeLogUrl && rec.data.Package)) { |
124 | return; | |
125 | } | |
126 | ||
05a977a2 | 127 | let view = Ext.createWidget('component', { |
5f93e010 DM |
128 | autoScroll: true, |
129 | style: { | |
130 | 'background-color': 'white', | |
131 | 'white-space': 'pre', | |
132 | 'font-family': 'monospace', | |
01031528 TL |
133 | padding: '5px', |
134 | }, | |
5f93e010 DM |
135 | }); |
136 | ||
05a977a2 | 137 | let win = Ext.create('Ext.window.Window', { |
5f93e010 DM |
138 | title: gettext('Changelog') + ": " + rec.data.Package, |
139 | width: 800, | |
140 | height: 400, | |
141 | layout: 'fit', | |
142 | modal: true, | |
01031528 | 143 | items: [view], |
5f93e010 DM |
144 | }); |
145 | ||
146 | Proxmox.Utils.API2Request({ | |
147 | waitMsgTarget: me, | |
148 | url: "/nodes/" + me.nodename + "/apt/changelog", | |
149 | params: { | |
150 | name: rec.data.Package, | |
01031528 | 151 | version: rec.data.Version, |
5f93e010 DM |
152 | }, |
153 | method: 'GET', | |
154 | failure: function(response, opts) { | |
155 | win.close(); | |
156 | Ext.Msg.alert(gettext('Error'), response.htmlStatus); | |
157 | }, | |
158 | success: function(response, opts) { | |
159 | win.show(); | |
160 | view.update(Ext.htmlEncode(response.result.data)); | |
01031528 | 161 | }, |
5f93e010 | 162 | }); |
5f93e010 DM |
163 | }; |
164 | ||
05a977a2 | 165 | let changelog_btn = new Proxmox.button.Button({ |
5f93e010 DM |
166 | text: gettext('Changelog'), |
167 | selModel: sm, | |
168 | disabled: true, | |
169 | enableFn: function(rec) { | |
170 | if (!rec || !rec.data || !(rec.data.ChangeLogUrl && rec.data.Package)) { | |
171 | return false; | |
172 | } | |
173 | return true; | |
174 | }, | |
175 | handler: function(b, e, rec) { | |
176 | show_changelog(rec); | |
01031528 | 177 | }, |
5f93e010 DM |
178 | }); |
179 | ||
05a977a2 | 180 | let verbose_desc_checkbox = new Ext.form.field.Checkbox({ |
6895e13f TL |
181 | boxLabel: gettext('Show details'), |
182 | value: false, | |
183 | listeners: { | |
184 | change: (f, val) => { | |
185 | me.full_description = val; | |
186 | me.getView().refresh(); | |
01031528 TL |
187 | }, |
188 | }, | |
6895e13f TL |
189 | }); |
190 | ||
5f93e010 | 191 | if (me.upgradeBtn) { |
01031528 | 192 | me.tbar = [update_btn, me.upgradeBtn, changelog_btn, '->', verbose_desc_checkbox]; |
5f93e010 | 193 | } else { |
01031528 | 194 | me.tbar = [update_btn, changelog_btn, '->', verbose_desc_checkbox]; |
5f93e010 DM |
195 | } |
196 | ||
197 | Ext.apply(me, { | |
198 | store: store, | |
199 | stateful: true, | |
200 | stateId: 'grid-update', | |
201 | selModel: sm, | |
202 | viewConfig: { | |
203 | stripeRows: false, | |
01031528 | 204 | 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>', |
5f93e010 | 205 | }, |
01031528 | 206 | features: [groupingFeature, rowBodyFeature], |
5f93e010 DM |
207 | listeners: { |
208 | activate: reload, | |
209 | itemdblclick: function(v, rec) { | |
210 | show_changelog(rec); | |
01031528 TL |
211 | }, |
212 | }, | |
5f93e010 DM |
213 | }); |
214 | ||
215 | me.callParent(); | |
01031528 | 216 | }, |
5f93e010 | 217 | }); |