All of lore.kernel.org
 help / color / mirror / Atom feed
* [layerindex-web][PATCH 1/3] editlayer: allow selecting web interface type
@ 2016-10-26  2:41 Paul Eggleton
  2016-10-26  2:41 ` [layerindex-web][PATCH 2/3] about: update contributors list Paul Eggleton
  2016-10-26  2:41 ` [layerindex-web][PATCH 3/3] recipedetail: don't show homepage as link if not URL Paul Eggleton
  0 siblings, 2 replies; 3+ messages in thread
From: Paul Eggleton @ 2016-10-26  2:41 UTC (permalink / raw)
  To: yocto

For some repo URLs we can automatically determine the values of all of
the other fields - e.g. for github or git.openembedded.org, and we've
been doing that for a while. However if someone submits a URL for some
other site we don't know what type of interface it uses, and usually
the submitter leaves the fields blank so it falls to the layer index
maintainer to set the values, and then you have to remember what the
correct URL format is which is awkward especially for gitweb.

In order to fix this, add a select field to the form which allows
specifying which type of interface is being used. At the moment only
cgit, gitweb, gitlab and "(custom)" (i.e. the current behaviour) are
supported. This is not a real field but activates javascript code
that sets the other fields and enables/disables the controls.

Signed-off-by: Paul Eggleton <paul.eggleton@linux.intel.com>
---
 layerindex/static/css/additional.css |   6 ++
 templates/layerindex/editlayer.html  | 117 +++++++++++++++++++++++++++++++----
 2 files changed, 112 insertions(+), 11 deletions(-)

diff --git a/layerindex/static/css/additional.css b/layerindex/static/css/additional.css
index e6cf526..2a27712 100644
--- a/layerindex/static/css/additional.css
+++ b/layerindex/static/css/additional.css
@@ -88,6 +88,12 @@ padding: 8px;
     width: 50%;
 }
 
+.formfield-div {
+    width: 50%;
+    display: inline-block;
+    margin-right: 13px;
+}
+
 .checkboxtd input {
     width: 25px;
 }
diff --git a/templates/layerindex/editlayer.html b/templates/layerindex/editlayer.html
index b7ff5dc..161dcda 100644
--- a/templates/layerindex/editlayer.html
+++ b/templates/layerindex/editlayer.html
@@ -89,6 +89,24 @@
                 </div>
             </div>
             {% endif %}
+            {% if field.name = 'vcs_web_url' %}
+                <div class="control-label">
+                    Web interface type
+                </div>
+                <div class="controls">
+                    <div class="formfield-div">
+                        <select id="idx_vcs_web_type">
+                        <option>(custom)</option>
+                        <option>cgit</option>
+                        <option>gitweb</option>
+                        <option>gitlab</option>
+                        </select>
+                    </div>
+                    <span class="help-inline custom-help">
+                        Type of web interface (helps to auto-determine other URL fields)
+                    </span>
+                </div>
+            {% endif %}
         {% endfor %}
     </div>
     <h3 id="maintainers">Maintainers</h3>
@@ -169,6 +187,7 @@
     }
 
     function AutoWebFields(repoval) {
+        // Auto-determine web interface URLs from repo URL
         if( repoval[repoval.length-1] == '/' )
             repoval = repoval.slice(0, repoval.length-1)
 
@@ -177,12 +196,14 @@
             this.vcs_web_url = 'http://cgit.openembedded.org/cgit.cgi/' + reponame
             this.vcs_web_tree_base_url = 'http://cgit.openembedded.org/cgit.cgi/' + reponame + '/tree/%path%?h=%branch%'
             this.vcs_web_file_base_url = 'http://cgit.openembedded.org/cgit.cgi/' + reponame + '/tree/%path%?h=%branch%'
+            this.vcs_web_type = 'cgit'
         }
         else if( repoval.indexOf('git.yoctoproject.org/') > -1 ) {
             reponame = repoval.replace(/^.*\//, '')
             this.vcs_web_url = 'http://git.yoctoproject.org/cgit/cgit.cgi/' + reponame
             this.vcs_web_tree_base_url = 'http://git.yoctoproject.org/cgit/cgit.cgi/' + reponame + '/tree/%path%?h=%branch%'
             this.vcs_web_file_base_url = 'http://git.yoctoproject.org/cgit/cgit.cgi/' + reponame + '/tree/%path%?h=%branch%'
+            this.vcs_web_type = 'cgit'
         }
         else if( repoval.indexOf('github.com/') > -1 ) {
             reponame = repoval.replace(/^.*github.com\//, '')
@@ -190,13 +211,7 @@
             this.vcs_web_url = 'http://github.com/' + reponame
             this.vcs_web_tree_base_url = 'http://github.com/' + reponame + '/tree/%branch%/'
             this.vcs_web_file_base_url = 'http://github.com/' + reponame + '/blob/%branch%/'
-        }
-        else if( repoval.indexOf('gitorious.org/') > -1 ) {
-            reponame = repoval.replace(/^.*gitorious.org\//, '')
-            reponame = reponame.replace(/.git$/, '')
-            this.vcs_web_url = 'http://gitorious.org/' + reponame
-            this.vcs_web_tree_base_url = 'http://gitorious.org/' + reponame + '/trees/%branch%/'
-            this.vcs_web_file_base_url = 'http://gitorious.org/' + reponame + '/blobs/%branch%/'
+            this.vcs_web_type = '(custom)'
         }
         else if( repoval.indexOf('bitbucket.org/') > -1 ) {
             reponame = repoval.replace(/^.*bitbucket.org\//, '')
@@ -204,14 +219,91 @@
             this.vcs_web_url = 'http://bitbucket.org/' + reponame
             this.vcs_web_tree_base_url = 'http://bitbucket.org/' + reponame + '/src/%branch%/%path%?at=%branch%'
             this.vcs_web_file_base_url = 'http://bitbucket.org/' + reponame + '/src/%branch%/%path%?at=%branch%'
+            this.vcs_web_type = '(custom)'
         }
         else {
             this.vcs_web_url = ''
             this.vcs_web_tree_base_url = ''
             this.vcs_web_file_base_url = ''
+            this.vcs_web_type = '(custom)'
+        }
+    };
+
+    auto_web_url_field = function (e) {
+        // Auto-determine web interface type from URL
+        vcs_web_url = $('#id_vcs_web_url').val()
+        if ( vcs_web_url.indexOf('/cgit.cgi/') > -1 || vcs_web_url.indexOf('/cgit/') > -1 ) {
+            $('#idx_vcs_web_type').val('cgit')
+            auto_web_type_field(e)
+        }
+        else if ( vcs_web_url.indexOf('a=summary') > -1 ) {
+            $('#idx_vcs_web_type').val('gitweb')
+            auto_web_type_field(e)
         }
     }
 
+    auto_web_type_field = function (e) {
+        // Auto-determine web interface tree/file URLs based on type
+        type = $('#idx_vcs_web_type').val()
+        if (type == '(custom)') {
+            readonly = $('#idx_vcs_web_type').prop('disabled')
+            $('#id_vcs_web_tree_base_url').prop('readonly', readonly)
+            $('#id_vcs_web_file_base_url').prop('readonly', readonly)
+        }
+        else {
+            $('#id_vcs_web_tree_base_url').prop('readonly', true)
+            $('#id_vcs_web_file_base_url').prop('readonly', true)
+            vcs_web_url = $('#id_vcs_web_url').val()
+            if (vcs_web_url) {
+                if (vcs_web_url.endsWith('/')) {
+                    vcs_web_url = vcs_web_url.slice(0, -1)
+                }
+                if (type == 'cgit') {
+                    $('#id_vcs_web_tree_base_url').val('readonly', true)
+                    $('#id_vcs_web_file_base_url').prop('readonly', true)
+                    if (e) {
+                        $('#id_vcs_web_tree_base_url').val(vcs_web_url + '/tree/%path%?h=%branch%')
+                        $('#id_vcs_web_file_base_url').val(vcs_web_url + '/tree/%path%?h=%branch%')
+                    }
+                }
+                else if (type == 'gitweb') {
+                    $('#id_vcs_web_tree_base_url').val('readonly', true)
+                    $('#id_vcs_web_file_base_url').prop('readonly', true)
+                    if (e) {
+                        spliturl = vcs_web_url.split('?')
+                        if (spliturl.length > 1) {
+                            params = spliturl[1].split(';')
+                            newparams = []
+                            for (i = 0; i < params.length; i++) {
+                                if (!params[i].startsWith('a=')) {
+                                    newparams.push(params[i])
+                                }
+                            }
+                            newparamsstr = newparams.join(';')
+                            if( newparamsstr ) {
+                                newparamsstr += ';'
+                            }
+                            vcs_web_url = spliturl[0] + '?' + newparamsstr
+                        }
+                        else {
+                            vcs_web_url = spliturl[0] + '?'
+                        }
+                        $('#id_vcs_web_tree_base_url').val(vcs_web_url + 'a=tree;f=%path%;hb=refs/heads/%branch%')
+                        $('#id_vcs_web_file_base_url').val(vcs_web_url + 'a=blob;f=%path%;hb=refs/heads/%branch%')
+                    }
+                }
+                else if (type == 'gitlab') {
+                    $('#id_vcs_web_tree_base_url').val('readonly', true)
+                    $('#id_vcs_web_file_base_url').prop('readonly', true)
+                    if (e) {
+                        $('#id_vcs_web_tree_base_url').val(vcs_web_url + '/tree/%branch%/%path%')
+                        $('#id_vcs_web_file_base_url').val(vcs_web_url + '/blob/%branch%/%path%')
+                    }
+                }
+            }
+        }
+    };
+
     auto_web_fields = function (e) {
         repoval = $('#id_vcs_url').val()
         awf = new AutoWebFields(repoval)
@@ -220,16 +312,17 @@
                 $('#id_vcs_web_url').val(awf.vcs_web_url)
                 $('#id_vcs_web_tree_base_url').val(awf.vcs_web_tree_base_url)
                 $('#id_vcs_web_file_base_url').val(awf.vcs_web_file_base_url)
+                $('#idx_vcs_web_type').val(awf.vcs_web_type)
             }
             $('#id_vcs_web_url').prop('readonly', true);
-            $('#id_vcs_web_tree_base_url').prop('readonly', true);
-            $('#id_vcs_web_file_base_url').prop('readonly', true);
+            $('#idx_vcs_web_type').prop('disabled', true);
         }
         else {
             $('#id_vcs_web_url').prop('readonly', false);
-            $('#id_vcs_web_tree_base_url').prop('readonly', false);
-            $('#id_vcs_web_file_base_url').prop('readonly', false);
+            $('#idx_vcs_web_type').prop('disabled', false);
         }
+
+        auto_web_type_field(e)
     };
 
     split_email = function() {
@@ -280,6 +373,8 @@
         $('#addanothermaintainer').click(expand_maintainer)
 
         $('#id_vcs_url').change(auto_web_fields)
+        $('#id_vcs_web_url').change(auto_web_url_field)
+        $('#idx_vcs_web_type').change(auto_web_type_field)
         auto_web_fields(null)
 
         firstfield = $("#edit_layer_form input:text, #edit_layer_form textarea").first();
-- 
2.5.5



^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [layerindex-web][PATCH 2/3] about: update contributors list
  2016-10-26  2:41 [layerindex-web][PATCH 1/3] editlayer: allow selecting web interface type Paul Eggleton
@ 2016-10-26  2:41 ` Paul Eggleton
  2016-10-26  2:41 ` [layerindex-web][PATCH 3/3] recipedetail: don't show homepage as link if not URL Paul Eggleton
  1 sibling, 0 replies; 3+ messages in thread
From: Paul Eggleton @ 2016-10-26  2:41 UTC (permalink / raw)
  To: yocto

Ensure recent contributions from Mark and Liam are reflected in the
authors list.

Signed-off-by: Paul Eggleton <paul.eggleton@linux.intel.com>
---
 templates/layerindex/about.html | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/templates/layerindex/about.html b/templates/layerindex/about.html
index 3e98825..a290344 100644
--- a/templates/layerindex/about.html
+++ b/templates/layerindex/about.html
@@ -43,6 +43,8 @@
 <li>Belen Barros Pena</li>
 <li>Alexandru Damian</li>
 <li>Michael Halstead</li>
+<li>Liam R. Howlett</li>
+<li>Mark Hatle</li>
 </ul>
 
 <p>The code is Open Source and can be found on <a href="http://git.yoctoproject.org/cgit/cgit.cgi/layerindex-web/">git.yoctoproject.org</a>. Patches welcome!</p>
-- 
2.5.5



^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [layerindex-web][PATCH 3/3] recipedetail: don't show homepage as link if not URL
  2016-10-26  2:41 [layerindex-web][PATCH 1/3] editlayer: allow selecting web interface type Paul Eggleton
  2016-10-26  2:41 ` [layerindex-web][PATCH 2/3] about: update contributors list Paul Eggleton
@ 2016-10-26  2:41 ` Paul Eggleton
  1 sibling, 0 replies; 3+ messages in thread
From: Paul Eggleton @ 2016-10-26  2:41 UTC (permalink / raw)
  To: yocto

Sometimes people put values that aren't URLs into the HOMEPAGE variable.
If that's the case, then we should not turn that value into a link which
will be invalid.

Signed-off-by: Paul Eggleton <paul.eggleton@linux.intel.com>
---
 layerindex/models.py                   | 6 ++++++
 templates/layerindex/recipedetail.html | 8 +++++++-
 2 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/layerindex/models.py b/layerindex/models.py
index 869d4a3..746fad4 100644
--- a/layerindex/models.py
+++ b/layerindex/models.py
@@ -292,6 +292,12 @@ class Recipe(models.Model):
         else:
             return self.filename.split('_')[0]
 
+    def homepage_url_only(self):
+        if '://' in self.homepage:
+            return self.homepage
+        else:
+            return None
+
     def __str__(self):
         return os.path.join(self.filepath, self.filename)
 
diff --git a/templates/layerindex/recipedetail.html b/templates/layerindex/recipedetail.html
index c0199a1..5b83886 100644
--- a/templates/layerindex/recipedetail.html
+++ b/templates/layerindex/recipedetail.html
@@ -72,7 +72,13 @@
                         </tr>
                         <tr>
                             <th>Homepage</th>
-                            <td>{% if recipe.homepage %}<a href="{{ recipe.homepage }}">{{ recipe.homepage }}</a>{% endif %}</td>
+                            <td>
+                                {% if recipe.homepage_url_only %}
+                                    <a href="{{ recipe.homepage }}">{{ recipe.homepage }}</a>
+                                {% elif recipe.homepage %}
+                                    {{ recipe.homepage }}
+                                {% endif %}
+                            </td>
                         </tr>
                         {% if recipe.bugtracker %}
                         <tr>
-- 
2.5.5



^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2016-10-26  2:42 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-10-26  2:41 [layerindex-web][PATCH 1/3] editlayer: allow selecting web interface type Paul Eggleton
2016-10-26  2:41 ` [layerindex-web][PATCH 2/3] about: update contributors list Paul Eggleton
2016-10-26  2:41 ` [layerindex-web][PATCH 3/3] recipedetail: don't show homepage as link if not URL Paul Eggleton

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.