
From: Hongliang Wang <hlwang@linux.vnet.ibm.com> Integrate add/enable/disalbe/edit/remove a repository feature into host tab. Signed-off-by: Hongliang Wang <hlwang@linux.vnet.ibm.com> Signed-off-by: Adam King <rak@linux.vnet.ibm.com> --- po/POTFILES.in | 2 + ui/css/theme-default/host.css | 8 ++ ui/js/src/kimchi.host.js | 185 ++++++++++++++++++++++++++++++++++++++++++ ui/pages/tabs/host.html.tmpl | 13 +++ 4 files changed, 208 insertions(+) diff --git a/po/POTFILES.in b/po/POTFILES.in index 4ff7eaa..955a675 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -7,6 +7,8 @@ ui/pages/i18n.html.tmpl ui/pages/kimchi-ui.html.tmpl ui/pages/login-window.html.tmpl ui/pages/report-add.html.tmpl +ui/pages/repository-add.html.tmpl +ui/pages/repository-edit.html.tmpl ui/pages/storagepool-add.html.tmpl ui/pages/tabs/guests.html.tmpl ui/pages/tabs/host.html.tmpl diff --git a/ui/css/theme-default/host.css b/ui/css/theme-default/host.css index 0f8b941..0ca6684 100644 --- a/ui/css/theme-default/host.css +++ b/ui/css/theme-default/host.css @@ -253,3 +253,11 @@ width: 846px; } /* End of Software Updates */ + +/* Repository */ +.host-panel #repositories-grid { + border-color: #ddd; + height: 200px; + width: 850px; +} +/* End of Repository */ diff --git a/ui/js/src/kimchi.host.js b/ui/js/src/kimchi.host.js index 6300f37..bd07561 100644 --- a/ui/js/src/kimchi.host.js +++ b/ui/js/src/kimchi.host.js @@ -15,6 +15,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +kimchi.host={}; + kimchi.host_main = function() { var expand = function(header, toExpand) { var controlledNode = $(header).attr('aria-controls'); @@ -22,6 +24,169 @@ kimchi.host_main = function() { $(header).attr('aria-expanded', toExpand ? 'true' : 'false'); }; + var repositoriesGrid = null; + var initRepositoriesGrid = function(repo_type) { + var gridFields=[]; + if (repo_type == "yum") { + gridFields=[{ + name: 'repo_id', + label: i18n['KCHREPO6004M'], + 'class': 'repository-id' + }, { + name: 'config.repo_name', + label: i18n['KCHREPO6005M'], + 'class': 'repository-name' + }, { + name: 'enabled', + label: i18n['KCHREPO6009M'], + 'class': 'repository-enabled' + }]; + } + else if (repo_type == "deb") { + gridFields=[{ + name: 'baseurl', + label: i18n['KCHREPO6006M'], + makeTitle: true, + 'class': 'repository-baseurl' + }, { + name: 'enabled', + label: i18n['KCHREPO6009M'], + 'class': 'repository-enabled' + }, { + name: 'config.dist', + label: "dist", + 'class': 'repository-gpgcheck' + }, { + name: 'config.comps', + label: "comps", + 'class': 'repository-gpgcheck' + }]; + } + else { + gridFields=[{ + name: 'repo_id', + label: i18n['KCHREPO6004M'], + 'class': 'repository-id' + }, { + name: 'enabled', + label: i18n['KCHREPO6009M'], + 'class': 'repository-enabled' + }, { + name: 'baseurl', + label: i18n['KCHREPO6006M'], + makeTitle: true, + 'class': 'repository-baseurl' + }, { + name: 'gpgcheck', + label: i18n['KCHREPO6010M'], + 'class': 'repository-gpgcheck' + }]; + } + repositoriesGrid = new kimchi.widget.Grid({ + container: 'repositories-grid-container', + id: 'repositories-grid', + title: i18n['KCHREPO6003M'], + toolbarButtons: [{ + id: 'repositories-grid-add-button', + label: i18n['KCHREPO6012M'], + onClick: function(event) { + kimchi.window.open({url:'repository-add.html', class: repo_type}); + } + }, { + id: 'repositories-grid-enable-button', + label: i18n['KCHREPO6016M'], + disabled: true, + onClick: function(event) { + var repository = repositoriesGrid.getSelected(); + if(!repository) { + return; + } + var name = repository['repo_id']; + var enable = !repository['enabled']; + $(this).prop('disabled', true); + kimchi.enableRepository(name, enable, function() { + kimchi.topic('kimchi/repositoryUpdated').publish(); + }); + } + }, { + id: 'repositories-grid-edit-button', + label: i18n['KCHREPO6013M'], + disabled: true, + onClick: function(event) { + var repository = repositoriesGrid.getSelected(); + if(!repository) { + return; + } + kimchi.selectedRepository = repository['repo_id']; + kimchi.window.open({url:'repository-edit.html', class: repo_type}); + } + }, { + id: 'repositories-grid-remove-button', + label: i18n['KCHREPO6014M'], + disabled: true, + onClick: function(event) { + var repository = repositoriesGrid.getSelected(); + if(!repository) { + return; + } + + var settings = { + title : i18n['KCHREPO6001M'], + content : i18n['KCHREPO6002M'], + confirm : i18n['KCHAPI6004M'], + cancel : i18n['KCHAPI6003M'] + }; + + kimchi.confirm(settings, function() { + kimchi.deleteRepository( + repository['repo_id'], + function(result) { + kimchi.topic('kimchi/repositoryDeleted').publish(result); + }, function(error) { + } + ); + }); + } + }], + onRowSelected: function(row) { + var repository = repositoriesGrid.getSelected(); + if(!repository) { + return; + } + $('#repositories-grid-remove-button').prop('disabled', false); + $('#repositories-grid-edit-button').prop('disabled', false); + var enabled = repository['enabled']; + $('#repositories-grid-enable-button') + .text(i18n[enabled ? 'KCHREPO6017M' : 'KCHREPO6016M']) + .prop('disabled', false); + }, + frozenFields: [], + fields: gridFields, + data: listRepositories + }); + }; + + var listRepositories = function(gridCallback) { + kimchi.listRepositories(function(repositories) { + if($.isFunction(gridCallback)) { + gridCallback(repositories); + } + else { + if(repositoriesGrid) { + repositoriesGrid.setData(repositories); + } + else { + initRepositoriesGrid(); + repositoriesGrid.setData(repositories); + } + } + }); + + $('#repositories-grid-remove-button').prop('disabled', true); + $('#repositories-grid-edit-button').prop('disabled', true); + $('#repositories-grid-enable-button').prop('disabled', true); + }; + var softwareUpdatesGridID = 'software-updates-grid'; var softwareUpdatesGrid = null; var progressAreaID = 'software-updates-progress-textarea'; @@ -271,6 +436,18 @@ kimchi.host_main = function() { }); kimchi.getCapabilities(function(capabilities) { + kimchi.host.capabilities=capabilities; + if((capabilities['repo_mngt_tool']) && (capabilities['repo_mngt_tool']!="None")) { + initRepositoriesGrid(capabilities['repo_mngt_tool']); + $('#repositories-section').switchClass('hidden', capabilities['repo_mngt_tool']); + kimchi.topic('kimchi/repositoryAdded') + .subscribe(listRepositories); + kimchi.topic('kimchi/repositoryUpdated') + .subscribe(listRepositories); + kimchi.topic('kimchi/repositoryDeleted') + .subscribe(listRepositories); + } + if(capabilities['update_tool']) { $('#software-update-section').removeClass('hidden'); initSoftwareUpdatesGrid(); @@ -552,6 +729,14 @@ kimchi.host_main = function() { delete kimchi.hostTimer; } + repositoriesGrid && repositoriesGrid.destroy(); + kimchi.topic('kimchi/repositoryAdded') + .unsubscribe(listRepositories); + kimchi.topic('kimchi/repositoryUpdated') + .unsubscribe(listRepositories); + kimchi.topic('kimchi/repositoryDeleted') + .unsubscribe(listRepositories); + softwareUpdatesGrid && softwareUpdatesGrid.destroy(); kimchi.topic('kimchi/softwareUpdated').unsubscribe(listSoftwareUpdates); diff --git a/ui/pages/tabs/host.html.tmpl b/ui/pages/tabs/host.html.tmpl index 179deba..eaab451 100644 --- a/ui/pages/tabs/host.html.tmpl +++ b/ui/pages/tabs/host.html.tmpl @@ -120,6 +120,19 @@ </div> </div> </div> + <div id="repositories-section" class="host-section hidden"> + <h3 class="section-header" + aria-controls="content-repositories"> + $_("Repositories") + </h3> + <div id="content-repositories" class="section-content"> + <div class="section-row"> + <div class="section-value"> + <div id="repositories-grid-container"></div> + </div> + </div> + </div> + </div> <div id="software-update-section" class="host-section hidden"> <h3 class="section-header" aria-controls="content-software-update"> -- 1.8.1.4