[Kimchi-devel] [PATCH v2 4/4] Integrate Repositories Management into Host Tab

Hongliang Wang hlwang at linux.vnet.ibm.com
Tue Mar 11 10:17:35 UTC 2014


Integrate repositories management into host tab.

Signed-off-by: Hongliang Wang <hlwang at linux.vnet.ibm.com>
---
 ui/css/theme-default/host.css |  40 ++++++++++++++
 ui/js/src/kimchi.host.js      | 123 ++++++++++++++++++++++++++++++++++++++++++
 ui/pages/tabs/host.html.tmpl  |  13 +++++
 3 files changed, 176 insertions(+)

diff --git a/ui/css/theme-default/host.css b/ui/css/theme-default/host.css
index 470ed1b..d304b13 100644
--- a/ui/css/theme-default/host.css
+++ b/ui/css/theme-default/host.css
@@ -224,3 +224,43 @@
     width: 300px;
 }
 /* End of Debug Report */
+
+/* Repository */
+.host-panel #repositories-grid {
+    border-color: #ddd;
+    height: 300px;
+    width: 850px;
+}
+
+.repository-id {
+    width: 70px;
+}
+
+.repository-name {
+    width: 180px;
+}
+
+.repository-baseurl {
+    width: 300px;
+}
+
+.repository-ismirror {
+    width: 60px;
+}
+
+.repository-urlargs {
+    width: 70px;
+}
+
+.repository-enabled {
+    width: 60px;
+}
+
+.repository-gpgcheck {
+    width: 60px;
+}
+
+.repository-gpgkey {
+    width: 300px;
+}
+/* End of Repository */
diff --git a/ui/js/src/kimchi.host.js b/ui/js/src/kimchi.host.js
index 7974054..34a6948 100644
--- a/ui/js/src/kimchi.host.js
+++ b/ui/js/src/kimchi.host.js
@@ -133,6 +133,126 @@ kimchi.host_main = function() {
         });
     };
 
+    var repositoriesGridID = 'repositories-grid';
+    var repositoriesGrid = null;
+    var initRepositoriesGrid = function(repositories) {
+        repositoriesGrid = new kimchi.widget.Grid({
+            container: 'repositories-grid-container',
+            id: repositoriesGridID,
+            title: i18n['KCHREPO6003M'],
+            toolbarButtons: [{
+                id: repositoriesGridID + '-add-button',
+                label: i18n['KCHREPO6012M'],
+                onClick: function(event) {
+                    kimchi.window.open('repository-add.html');
+                }
+            }, {
+                id: repositoriesGridID + '-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('repository-edit.html');
+                }
+            }, {
+                id: repositoriesGridID + '-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) {
+                $('#' + repositoriesGridID + '-remove-button')
+                    .prop('disabled', false);
+                $('#' + repositoriesGridID + '-edit-button')
+                    .prop('disabled', false);
+            },
+            frozenFields: [],
+            fields: [{
+                name: 'repo_id',
+                label: i18n['KCHREPO6004M'],
+                'class': 'repository-id'
+            }, {
+                name: 'repo_name',
+                label: i18n['KCHREPO6005M'],
+                'class': 'repository-name'
+            }, {
+                name: 'enabled',
+                label: i18n['KCHREPO6009M'],
+                'class': 'repository-enabled'
+            }, {
+                name: 'baseurl',
+                label: i18n['KCHREPO6006M'],
+                makeTitle: true,
+                'class': 'repository-baseurl'
+            }, {
+                name: 'url_args',
+                label: i18n['KCHREPO6008M'],
+                'class': 'repository-urlargs'
+            }, {
+                name: 'is_mirror',
+                label: i18n['KCHREPO6007M'],
+                'class': 'repository-ismirror'
+            }, {
+                name: 'gpgcheck',
+                label: i18n['KCHREPO6010M'],
+                'class': 'repository-gpgcheck'
+            }, {
+                name: 'gpgkey',
+                label: i18n['KCHREPO6011M'],
+                'class': 'repository-gpgkey'
+            }],
+            data: repositories
+        });
+        kimchi.topic('kimchi/repositoryAdded').subscribe(listRepositories);
+        kimchi.topic('kimchi/repositoryUpdated').subscribe(listRepositories);
+        kimchi.topic('kimchi/repositoryDeleted').subscribe(listRepositories);
+    };
+
+    var listRepositories = function() {
+        kimchi.listRepositories(function(repositories) {
+            $.each(repositories, function(i, item) {
+                repositories[i]['rowno'] = i + 1;
+            });
+            if(repositoriesGrid) {
+                repositoriesGrid.setData(repositories);
+            }
+            else {
+                initRepositoriesGrid(repositories);
+            }
+        });
+
+        $('#' + repositoriesGridID + '-remove-button')
+            .prop('disabled', true);
+        $('#' + repositoriesGridID + '-edit-button')
+            .prop('disabled', true);
+    };
+
     var shutdownButtonID = '#host-button-shutdown';
     var restartButtonID = '#host-button-restart';
     var shutdownHost = function(params) {
@@ -198,6 +318,8 @@ kimchi.host_main = function() {
             $('#debug-report-section').removeClass('hidden');
             listDebugReports();
         });
+
+        listRepositories();
     };
 
     kimchi.topic('kimchi/debugReportAdded').subscribe(function(params) {
@@ -469,5 +591,6 @@ kimchi.host_main = function() {
             delete kimchi.hostTimer;
         }
         reportGrid && reportGrid.destroy();
+        repositoriesGrid && repositoriesGrid.destroy();
     });
 };
diff --git a/ui/pages/tabs/host.html.tmpl b/ui/pages/tabs/host.html.tmpl
index 52f849b..9acb68a 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">
+                <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="debug-report-section" class="host-section hidden">
                 <h3 class="section-header"
                     aria-controls="content-sys-reports">
-- 
1.8.1.4




More information about the Kimchi-devel mailing list