#51 Make non-active branches greyish and fix the calls for url_for()
Merged 8 years ago by pingou. Opened 8 years ago by pingou.

file modified
+7 -7
@@ -13,23 +13,23 @@ 

      <span>{{ split_message[0] }}</span>

      <div class="pull-xs-right btn-group">

        <a class="btn btn-secondary btn-sm" href="{{ url_for(

-         'view_raw_file',

+         'ui_ns.view_raw_file',

          repo=repo.name,

          username=username,

          namespace=repo.namespace,

          identifier=commitid) }}" title="View as raw">raw</a>

        <a class="btn btn-secondary btn-sm" href="{{ url_for(

-         'view_commit_patch',

+         'ui_ns.view_commit_patch',

          repo=repo.name,

          username=username,

          namespace=repo.namespace,

          commitid=commitid) }}">patch</a>

        <a class="btn btn-secondary btn-sm" href="{{ url_for(

-         'view_tree', username=username, namespace=repo.namespace,

+         'ui_ns.view_tree', username=username, namespace=repo.namespace,

          repo=repo.name, identifier=commitid) }}">tree</a>

        {% if (commit.parents|length) == 1 %}

        <a class="btn btn-secondary btn-sm" title={{commit.parents[0].oid.hex}} href="{{ url_for(

-         'view_commit',

+         'ui_ns.view_commit',

          repo=repo.name,

          username=username,

          namespace=repo.namespace,
@@ -43,7 +43,7 @@ 

          <div class="dropdown-menu dropdown-menu-right" aria-labelledby="parentsDrop">

            {% for parent in commit.parents %}

              <a class="dropdown-item" href="{{ url_for(

-                 'view_commit',

+                 'ui_ns.view_commit',

                  repo=repo.name,

                  username=username,

                  namespace=repo.namespace,
@@ -165,14 +165,14 @@ 

    <div class="card-header">

      {% if patch|hasattr('new_file_path') %}

        <a href="{{ url_for(

-           'view_file', username=username, namespace=repo.namespace,

+           'ui_ns.view_file', username=username, namespace=repo.namespace,

            repo=repo.name, identifier=commitid,

            filename=patch.new_file_path) }}" title="View file as of {{ commitid|short }}">

          {{  patch.new_file_path|unicode }}

        </a>

      {% elif patch|hasattr('delta') %}

        <a href="{{ url_for(

-           'view_file', username=username, namespace=repo.namespace,

+           'ui_ns.view_file', username=username, namespace=repo.namespace,

            repo=repo.name, identifier=commitid,

            filename=patch.delta.new_file.path) }}" title="View file as of {{ commitid|short }}">

          {{  patch.delta.new_file.path|unicode }}

file modified
+5 -5
@@ -52,7 +52,7 @@ 

            <div class="dropdown-menu dropdown-menu-right">

              {% for branch in g.branches %}

                  <a class="dropdown-item" href="{{ url_for(

-                     'view_commits',

+                     'ui_ns.view_commits',

                      repo=repo.name,

                      username=username,

                      namespace=repo.namespace,
@@ -89,7 +89,7 @@ 

          (repo.is_fork or repo.settings.get('pull_requests', True)) %}

            <div id="request_pull" class="pull-xs-right">

              <a class="btn btn-primary btn-sm"

-               href="{{ url_for('new_request_pull',

+               href="{{ url_for('ui_ns.new_request_pull',

                      repo=repo.name,

                      username=username,

                      namespace=repo.namespace,
@@ -101,7 +101,7 @@ 

  

        <div id="diff_commits" class="list-group m-t-1" style="display:none;">

          {% for diff_commit_full in diff_commits_full %}

-            <a href="{{ url_for('view_commit',

+            <a href="{{ url_for('ui_ns.view_commit',

                      repo=repo.name,

                      username=username,

                      namespace=repo.namespace,
@@ -143,7 +143,7 @@ 

                </div>

              {% endif %}

              <h5>

-               <a href="{{ url_for('view_commit',

+               <a href="{{ url_for('ui_ns.view_commit',

                      repo=repo.name,

                      username=username,

                      namespace=repo.namespace,
@@ -159,7 +159,7 @@ 

                </a>

              </h5>

                {{ commit.author|author2user_commits(

-                 link=url_for('view_commits',

+                 link=url_for('ui_ns.view_commits',

                      repo=repo.name,

                      branchname=branchname,

                      username=username,

file modified
+10 -9
@@ -27,7 +27,8 @@ 

              {% if config.get('ENABLE_NEW_PROJECTS', True) and

                    config.get('ENABLE_UI_NEW_PROJECTS', True) and repos %}

              <span class="pull-xs-right">

-               <a class="btn btn-secondary btn-sm" href="{{ url_for('new_project') }}">

+               <a class="btn btn-secondary btn-sm" href="{{

+                     url_for('ui_ns.new_project') }}">

                  <span class="oi" data-glyph="plus" data-toggle="tooltip"

                      title="Create New Project" aria-hidden="true">

                  </span>
@@ -40,7 +41,7 @@ 

              {% for repo in repos %}

                <div class="list-group-item">

                  {% set url = url_for(

-                     'view_repo',

+                     'ui_ns.view_repo',

                      repo=repo.name,

                      username=repo.user.username if repo.is_fork else None,

                      namespace=repo.namespace) %}
@@ -61,7 +62,7 @@ 

              <div class="text-xs-center m-t-1">

                {% if config.get('ENABLE_NEW_PROJECTS', True) and

                    config.get('ENABLE_UI_NEW_PROJECTS', True) %}

-               <a class="btn btn-success" href="{{ url_for('new_project') }}">

+               <a class="btn btn-success" href="{{ url_for('ui_ns.new_project') }}">

                  <span class="oi" data-glyph="plus" data-toggle="tooltip"

                      title="Create New Project" aria-hidden="true">

                  </span> Create a Project
@@ -81,7 +82,7 @@ 

              {% for fork in forks %}

                <div class="list-group-item">

                  {% set url = url_for(

-                     'view_repo',

+                     'ui_ns.view_repo',

                      repo=fork.name,

                      username=fork.user.username if fork.is_fork else None,

                      namespace=fork.namespace) %}
@@ -93,7 +94,7 @@ 

                    <div class="pull-xs-right">

                    <span class="text-muted">forked from</span>

                    <a href="{{ url_for(

-                     'view_repo', repo=fork.parent.name,

+                     'ui_ns.view_repo', repo=fork.parent.name,

                      namespace=fork.parent.namespace) }}">

                      {{ fork.parent.namespace + '/' if fork.parent.namespace

                      }}{{fork.parent.name}}
@@ -117,7 +118,7 @@ 

                  My Groups <span class="label label-default">{{ user.groups | length }}</span>

                  <span class="pull-xs-right">

                    {% if config.get('ENABLE_GROUP_MNGT') %}

-                     <a class="btn btn-secondary btn-sm" href="{{ url_for('add_group') }}">

+                     <a class="btn btn-secondary btn-sm" href="{{ url_for('ui_ns.add_group') }}">

                        <span class="oi" data-glyph="plus" data-toggle="tooltip"

                          title="Create New Group" aria-hidden="true">

                        </span>
@@ -128,7 +129,7 @@ 

              {% for group in user.groups %}

                <div class="list-group">

                  <a class="list-group-item" href="{{ url_for(

-                     'view_group', group=group)}}">

+                     'ui_ns.view_group', group=group)}}">

                    <div class=""><strong><span class="oi" data-glyph="people">

                      </span> &nbsp;{{ group }}</strong>

                    </div>
@@ -148,7 +149,7 @@ 

                <div class="list-group">

                  {% if repo.is_fork %}

                    <a class="list-group-item" href="{{ url_for(

-                     'view_repo',

+                     'ui_ns.view_repo',

                      repo=repo.name,

                      username=repo.user.username,

                      namespace=repo.namespace) }}">
@@ -163,7 +164,7 @@ 

                    </a>

                  {% else %}

                    <a class="list-group-item" href="{{ url_for(

-                     'view_repo', repo=repo.name, namespace=repo.namespace) }}">

+                     'ui_ns.view_repo', repo=repo.name, namespace=repo.namespace) }}">

                      <div class="">

                        <strong>

                          <span class="oi" data-glyph="document"></span>

file modified
+54 -15
@@ -35,6 +35,13 @@ 

      white-space: -o-pre-wrap;    /* Opera 7 */

      word-wrap: break-word;       /* Internet Explorer 5.5+ */

    }

+ 

+   .disabled_branch a {

+     color: #818a91;

+   }

+   .disabled_branch .new_pr_btn {

+     display: none;

+   }

    </style>

  

  {% endblock %}
@@ -144,7 +151,7 @@ 

              <h5><strong>Contributors</strong></h5>

              <div class="m-b-2">

                <div>

-                 <a href="{{ url_for('view_user', username=repo.user.user)}}">

+                 <a href="{{ url_for('ui_ns.view_user', username=repo.user.user)}}">

                    {{ repo.user.default_email | avatar(20) | safe }}

                    {{ repo.user.fullname }} ({{ repo.user.user }})

                  </a>
@@ -153,7 +160,7 @@ 

                {% for access in repo.contributors %}

                  {% for user in repo.contributors[access] %}

                    <div>

-                     <a href="{{ url_for('view_user', username=user.user)}}">

+                     <a href="{{ url_for('ui_ns.view_user', username=user.user)}}">

                        {{ user.default_email | avatar(20) | safe }}

                        {{ user.fullname }} ({{ user.user }})

                      </a>
@@ -164,7 +171,7 @@ 

                {% for access in repo.contributor_groups %}

                  {% for group in repo.contributor_groups[access] %}

                    <div>

-                     <a href="{{ url_for('view_group', group=group.group_name)}}">

+                     <a href="{{ url_for('ui_ns.view_group', group=group.group_name)}}">

                        @{{ group.group_name }}

                      </a>

                      - {{ access }}
@@ -184,7 +191,7 @@ 

                    {% else  %}

                    <span class="oi text-muted" data-glyph="random"

                      title="Default branch"></span>

-                   <a href="{{ url_for('view_repo_branch',

+                   <a href="{{ url_for('ui_ns.view_repo_branch',

                      repo=repo.name,

                      username=username,

                      namespace=repo.namespace,
@@ -206,7 +213,7 @@ 

                  <div class="branch_name col-md-8">

                    <span class="oi text-muted" data-glyph="random"></span>

                    {% if branchname != branch %}

-                   <a class="" href="{{ url_for('view_repo_branch',

+                   <a class="" href="{{ url_for('ui_ns.view_repo_branch',

                      repo=repo.name,

                      username=username,

                      namespace=repo.namespace,
@@ -221,7 +228,7 @@ 

                  <div class="branch_del col-md-4">

                    {% if g.repo_committer and branch != head and config.get('ALLOW_DELETE_BRANCH', True) %}

                    <form id="delete_branch_form-{{ branch | replace('/', '__') }}" action="{{

-                     url_for('.delete_branch',

+                     url_for('ui_ns.delete_branch',

                              repo=repo.name,

                              username=username,

                              namespace=repo.namespace,
@@ -329,7 +336,7 @@ 

                <div class="list-group list-group-flush">

                  {% for commit in last_commits %}

                    <a href="{{

-                       url_for('view_commit',

+                       url_for('ui_ns.view_commit',

                        repo=repo.name,

                        username=username,

                        namespace=repo.namespace,
@@ -381,6 +388,35 @@ 

    });

  });

  

+ function disable_branches(){

+   function get_branches(_url){

+     $.ajax({

+       url: _url,

+       type: 'GET',

+       dataType: 'json',

+       success: function(res) {

+         for (branch in res.results){

+           branch = res.results[branch];

+           var _it = $('#branch-' + branch.name);

+           _it.addClass('disabled_branch');

+         }

+         if (res.next){

+           get_branches(res.next);

+         }

+       }

+     })

+   }

+   var _ns = '{{ repo.namespace }}';

+   if (_ns == 'rpms') {

+     _ns = 'rpm';

+   } else if (_ns == 'modules') {

+     _ns = 'modules';

+   }

+   var _url = 'https://pdc.fedoraproject.org/rest_api/v1/component-branches/'

+         + '?active=false&type=' + _ns + '&global_component={{ repo.name }}';

+   get_branches(_url);

+ }

+ 

  $(function() {

    $( "#more_gits" ).click(function() {

        if ($( "#more_gits" ).html() == 'more') {
@@ -390,7 +426,7 @@ 

        }

    });

  

-   {% if authenticated and g.repo_committer %}

+   {% if g.authenticated and g.repo_committer %}

    $.ajax({

      url: '{{ url_for("internal_ns.get_pull_request_ready_branch") }}' ,

      type: 'POST',
@@ -405,7 +441,7 @@ 

        if (res.code == 'OK'){

          for (branch in res.message.new_branch){

            var url = "{{ url_for(

-             'new_request_pull',

+             'ui_ns.new_request_pull',

              repo=repo.name,

              username=repo.user.user if repo.is_fork else None,

              namespace=repo.namespace,
@@ -424,16 +460,16 @@ 

            /*$($('.bodycontent').find('.row').children()[0]).before(html);*/

            {% if repo.is_fork %}

            html2 = ' \

-                 <a class="small label label-sm label-primary" data-toggle="tooltip" \

-                 href="' + url + branch + '"\

+                 <a class="small label label-sm label-primary new_pr_btn" data-toggle="tooltip" \

+                  href="' + url + branch + '"\

                   title="' + branch +' contains '

                   + res.message.new_branch[branch].length+' \

                   commit not in the upstream project. Click to create new PR now.'+'"> New PR</a> \

                  </div>';

            {% else %}

            html2 = ' \

-                 <a class="small label label-sm label-primary" data-toggle="tooltip" \

-                 href="' + url + branch + '"\

+                 <a class="small label label-sm label-primary new_pr_btn" data-toggle="tooltip" \

+                  href="' + url + branch + '"\

                   title="' + branch +' contains '

                   + res.message.new_branch[branch].length+' \

                   commit not in the main branch. Click to create new PR now.'+'"> New PR</a> \
@@ -445,7 +481,7 @@ 

          }

          for (branch in res.message.branch_w_pr){

            var url = "{{ url_for(

-               'request_pull',

+               'ui_ns.request_pull',

                repo=repo.name,

                username=None,

                namespace=repo.namespace,
@@ -454,7 +490,7 @@ 

            var html = ' \

                <a class="small label label-sm label-success" data-toggle="tooltip" \

                href="' + url + '"\

-                title="' + branch +' is already in an opened pull-request">'

+               title="' + branch +' is already in an opened pull-request">'

                 + 'PR#' + res.message.branch_w_pr[branch] + ' </a> \

                </div>';

            $('#branch-' + branch.replace('.', '\\.').replace('/', '__')
@@ -465,6 +501,9 @@ 

      }

    });

    {% endif %}

+ 

+   disable_branches();

+ 

  });

  </script>

  {% endblock %}

file modified
+1 -1
@@ -45,7 +45,7 @@ 

              {% for group in user.groups %}

                <div class="list-group">

                  <a class="list-group-item" href="{{ url_for(

-                     'view_group', group=group)}}">

+                     'ui_ns.view_group', group=group)}}">

                    <div class=""><strong><span class="oi" data-glyph="people">

                      </span> &nbsp;{{ group }}</strong>

                    </div>

no initial comment

You also need to filter by dist-git namespace here. The type query parameter can be used for this.

It's more traditional to define functions like:
function disabled_branches() {

Is there a particular reason you are doing it this way?

It'd be clearer if the function name was disable_branches as the current name insinuates that it'd return the disabled branches.

Rename to disable_branches and will adjust function declaration

2 new commits added

  • Make the branch name grey and remove the new PR button for disabled branches
  • Add namespace to the url_for() calls
8 years ago

2 new commits added

  • Make the branch name grey and remove the new PR button for disabled branches
  • Add namespace to the url_for() calls
8 years ago

The modules namespace is also singular in PDC. The type field is a direct mapping to the values in this API:
https://pdc.fedoraproject.org/rest_api/v1/release-component-types/

Should this be in an else block? If I'm a committer on the repo, it seems that disable_branches gets run as part of the AJAX request to get_pull_request_ready_branch, and then it would get run again here too.

2 new commits added

  • Make the branch name grey and remove the new PR button for disabled branches
  • Add namespace to the url_for() calls
8 years ago

Should this be in an else block? If I'm a committer on the repo, it seems that disable_branches gets run as part of the AJAX request to get_pull_request_ready_branch, and then it would get run again here too.

It is run twice indeed. The first time it makes the branch show up grey the second time after the new PR button are added to remove them.

We could run them only the second time, but since it's likely faster get the info from PDC than to get the list of branches, it makes the branches appear grey sooner.

It is run twice indeed. The first time it makes the branch show up grey the second time after the new PR button are added to remove them.
We could run them only the second time, but since it's likely faster get the info from PDC than to get the list of branches, it makes the branches appear grey sooner.

Could the disable_branches function add a class (e.g. disabled_branch) to the div that contains the branch link and the new PR button? Then that class' CSS would set the PR button div to display: None. Then you could also move the color change of the disabled branch link to this CSS class as well.

That would allow you to run the query just once and it'd make the JS cleaner in my opinion.

2 new commits added

  • Make the branch name grey and remove the new PR button for disabled branches
  • Add namespace to the url_for() calls
8 years ago

Adjusted, it makes the 'bin' icon to delete the branch grey as well but I don't think it's an issue

Pull-Request has been merged by pingou

8 years ago