[Kimchi-devel] [PATCH 5/7] Repository Management - Add Repository Support

Adam King rak at linux.vnet.ibm.com
Tue Mar 25 18:18:10 UTC 2014


From: Hongliang Wang <hlwang at linux.vnet.ibm.com>

Add repository.

Signed-off-by: Hongliang Wang <hlwang at linux.vnet.ibm.com>
Signed-off-by: Adam King <rak at linux.vnet.ibm.com>
---
 ui/css/theme-default/repository-add.css |  39 ++++++++++++
 ui/js/src/kimchi.repository_add_main.js |  91 +++++++++++++++++++++++++++
 ui/pages/repository-add.html.tmpl       | 108 ++++++++++++++++++++++++++++++++
 3 files changed, 238 insertions(+)
 create mode 100644 ui/css/theme-default/repository-add.css
 create mode 100644 ui/js/src/kimchi.repository_add_main.js
 create mode 100644 ui/pages/repository-add.html.tmpl

diff --git a/ui/css/theme-default/repository-add.css b/ui/css/theme-default/repository-add.css
new file mode 100644
index 0000000..fbe1c0c
--- /dev/null
+++ b/ui/css/theme-default/repository-add.css
@@ -0,0 +1,39 @@
+/*
+ * Project Kimchi
+ *
+ * Copyright IBM, Corp. 2013
+ *
+ * Authors:
+ *  Hongliang Wang <hlwang at linux.vnet.ibm.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#repository-add-window {
+    height: 500px;
+    width: 1000px;
+}
+
+#repository-add-window span.required {
+    color: red;
+    padding-left: 5px;
+    vertical-align: top;
+}
+
+#repository-add-window .textbox-wrapper input[type="text"] {
+    box-sizing: border-box;
+    width: 100%;
+}
+
+#repository-add-window .textbox-wrapper label {
+    vertical-align: middle;
+}
diff --git a/ui/js/src/kimchi.repository_add_main.js b/ui/js/src/kimchi.repository_add_main.js
new file mode 100644
index 0000000..6feab48
--- /dev/null
+++ b/ui/js/src/kimchi.repository_add_main.js
@@ -0,0 +1,91 @@
+/*
+ * Project Kimchi
+ *
+ * Copyright IBM, Corp. 2013
+ *
+ * Authors:
+ *  Hongliang Wang <hlwang at linux.vnet.ibm.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+kimchi.repository_add_main = function() {
+
+    var addForm = $('#form-repository-add');
+    var addButton = $('#button-repository-add');
+
+    var validateField = function(event) {
+        var valid=($(this).val()!=='');
+        $(addButton).prop('disabled', !valid);
+        return(valid);
+    };
+
+    var validateForm = function(event) {
+        var valid=false;
+        addForm.find('input.required').each( function() {
+            valid=($(this).val()!=='');
+            return(!valid);            
+        });
+        return(valid);
+    }
+
+    addForm.find('input.required').on('input propertychange', validateField);
+    
+    var weedObject = function(obj) {
+        for (var key in obj) {
+            if (obj.hasOwnProperty(key)) {
+                if((typeof(obj[key])==="object") && !Array.isArray(obj[key])) {
+                    weedObject(obj[key]);
+                }
+                else if(obj[key] == '') {
+                    delete obj[key];
+                }
+            }
+        }        
+    }
+
+    var addRepository = function(event) {
+        var valid = validateForm();
+        if(!valid) {
+            return false;
+        }
+
+        var formData = $(addForm).serializeObject();
+        
+        if (formData && formData.isMirror!=undefined) {
+            formData.isMirror=(String(formData.isMirror).toLowerCase() === 'true');
+        }
+        if(formData.isMirror) {
+            if(formData.config==undefined) {
+                formData.config=new Object();
+            }
+            formData.config.mirrorlist=formData.baseurl;
+            delete formData.baseurl;
+            delete formData.isMirror;
+        }
+        weedObject(formData);
+
+        kimchi.createRepository(formData, function() {
+            kimchi.topic('kimchi/repositoryAdded').publish();
+            kimchi.window.close();
+        }, function(jqXHR, textStatus, errorThrown) {
+            var reason = jqXHR &&
+                jqXHR['responseJSON'] &&
+                jqXHR['responseJSON']['reason'];
+            reason = reason ? ': ' + reason : '';
+            kimchi.message.error(i18n['KCHREPO6015M'] + reason);
+        });
+        return false;
+    };
+
+    $(addForm).on('submit', addRepository);
+};
diff --git a/ui/pages/repository-add.html.tmpl b/ui/pages/repository-add.html.tmpl
new file mode 100644
index 0000000..5502057
--- /dev/null
+++ b/ui/pages/repository-add.html.tmpl
@@ -0,0 +1,108 @@
+#*
+ * Project Kimchi
+ *
+ * Copyright IBM, Corp. 2013
+ *
+ * Authors:
+ *  Hongliang Wang <hlwang at linux.vnet.ibm.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *#
+#unicode UTF-8
+#import gettext
+#from kimchi.cachebust import href
+#silent t = gettext.translation($lang.domain, $lang.localedir, languages=$lang.lang)
+#silent _ = t.gettext
+#silent _t = t.gettext
+<div id="repository-add-window" class="window">
+    <form id="form-repository-add">
+        <header class="window-header">
+            <h1 class="title">$_("Add a Repository")</h1>
+            <div class="close">X</div>
+        </header>
+        <section>
+            <div class="content">
+                <div class="form-section yum">
+                    <h2>$_("Identifier")</h2>
+                    <div class="field">
+                        <p class="text-help">
+                            $_("Single word, unique identifier for the repository.")
+                        </p>
+                        <div class="textbox-wrapper">
+                            <input type="text" class="text" name="repo_id" />
+                        </div>
+                    </div>
+                </div>
+                <section class="form-section yum">
+                    <h2>$_("Name")</h2>
+                    <div class="field">
+                        <p class="text-help">
+                            $_("Textual name for the repository.")
+                        </p>
+                        <div class="textbox-wrapper">
+                            <input type="text" class="text" name="config[repo_name]" />
+                        </div>
+                    </div>
+                </section>
+                <section class="form-section">
+                    <h2>$_("URL")<span class="required" role="presentation" title='$_("Required Field")'>*</span></h2>
+                    <div class="field">
+                        <p class="text-help">
+                            $_("URL to the repository. Supported protocols are http, ftp, and file.")
+                        </p>
+                        <div class="textbox-wrapper">
+                            <input type="text" class="text required" name="baseurl" />
+                        </div>
+                    </div>
+                    <div class="field yum">
+                        <p class="yum">
+                            $_("Repository is a mirror.")
+                            <input type="checkbox" name="isMirror" value="true" />
+                        </p>
+                    </div>
+                </section>
+                <section class="form-section repository-dist deb">
+                    <h2>$_("Distribution")</h2>
+                    <div class="field">
+                        <p class="text-help">
+                            $_("Distribution of the DEB repository.")
+                        </p>
+                        <div class="textbox-wrapper">
+                            <input type="text" class="text" name="config[dist]" />
+                        </div>
+                    </div>
+                </section>
+                <section class="form-section repository-comps deb">
+                    <h2>$_("Components")</h2>
+                    <div class="field">
+                        <p class="text-help">
+                            $_("List of components in DEB repository.")
+                        </p>
+                        <div class="textbox-wrapper">
+                            <input type="text" class="text" name="config[comps]" />
+                        </div>
+                    </div>
+                </section>
+            </div>        </section>
+        <footer>
+            <div class="btn-group">
+                <button type="submit" id="button-repository-add" class="btn-normal" disabled="disabled">
+                    <span class="text">$_("Add")</span>
+                </button>
+            </div>
+        </footer>
+    </form>
+</div>
+<script>
+    kimchi.repository_add_main();
+</script>
-- 
1.8.1.4




More information about the Kimchi-devel mailing list