From fa7e4cf9642abb23db89e2f38882afdd54061ae6 Mon Sep 17 00:00:00 2001
From: “AnjaliPardeshi” <“anjalipardeshi92@gmail.com”>
Date: Oct 07 2016 21:01:48 +0000
Subject: [PATCH 1/5] Searches given word in title of issues.


Changes according to pep8
Docstring added for search pattern and pep8 changes
search bar and button added to input-group

---

diff --git a/pagure/lib/__init__.py b/pagure/lib/__init__.py
index c5d0b70..0540e8b 100644
--- a/pagure/lib/__init__.py
+++ b/pagure/lib/__init__.py
@@ -1679,12 +1679,11 @@ def get_project(session, name, user=None, namespace=None):
 
     return query.first()
 
-
 def search_issues(
         session, repo, issueid=None, issueuid=None, status=None,
         closed=False, tags=None, assignee=None, author=None, private=None,
-        priority=None, milestones=None,
-        count=False, offset=None, limit=None):
+        priority=None, milestones=None, count=False, offset=None,
+        limit=None, search_pattern=None):
     ''' Retrieve one or more issues associated to a project with the given
     criterias.
 
@@ -1731,6 +1730,8 @@ def search_issues(
     :kwarg count: a boolean to specify if the method should return the list
         of Issues or just do a COUNT query.
     :type count: boolean
+    :kwarg search_pattern: a string to search in issues title
+    :type search_pattern: str or None
 
     :return: A single Issue object if issueid is specified, a list of Project
         objects otherwise.
@@ -1875,6 +1876,15 @@ def search_issues(
         model.Issue.project_id == repo.id
     )
 
+    if search_pattern is not None:
+        query = session.query(
+            model.Issue
+        ).filter(
+            model.Issue.title.like('%' + str(search_pattern) + '%')
+        ).filter(
+            model.Issue.project_id == repo.id
+        )
+
     query = query.order_by(
         model.Issue.date_created.desc()
     )
diff --git a/pagure/templates/issues.html b/pagure/templates/issues.html
index ec07685..7efe051 100644
--- a/pagure/templates/issues.html
+++ b/pagure/templates/issues.html
@@ -121,6 +121,17 @@
         {{ tag.tag }}</a>
     {% endfor %}
 </span>
+<span class="col-lg-3 pull-xs-right" >
+   <form action="{{ url_for('view_issues', username=username,
+                  repo=repo.name ) }}">
+      <div class="input-group">
+         <input type="text" class="form-control" placeholder="Search">
+         <span class="input-group-btn">
+            <button class="btn btn-secondary" type="button">Go!</button>
+         </span>
+      </div>
+   </form>
+</span>
 </section>
 <div class="card m-t-1">
 <table id="pagure-issues-list" class="table table-hover table-striped m-b-0">
diff --git a/pagure/ui/issues.py b/pagure/ui/issues.py
index 85fb951..1ab47b6 100644
--- a/pagure/ui/issues.py
+++ b/pagure/ui/issues.py
@@ -435,6 +435,7 @@ def view_issues(repo, username=None, namespace=None):
     tags = [tag.strip() for tag in tags if tag.strip()]
     assignee = flask.request.args.get('assignee', None)
     author = flask.request.args.get('author', None)
+    search_pattern = flask.request.args.get('search_pattern', None)
 
     repo = flask.g.repo
 
@@ -472,6 +473,7 @@ def view_issues(repo, username=None, namespace=None):
             priority=priority,
             offset=flask.g.offset,
             limit=flask.g.limit,
+            search_pattern=search_pattern,
         )
         issues_cnt = pagure.lib.search_issues(
             SESSION,
@@ -495,12 +497,14 @@ def view_issues(repo, username=None, namespace=None):
             private=private,
             priority=priority,
             count=True,
+            search_pattern=search_pattern,
         )
     else:
         issues = pagure.lib.search_issues(
             SESSION, repo, tags=tags, assignee=assignee,
             author=author, private=private, priority=priority,
             offset=flask.g.offset, limit=flask.g.limit,
+            search_pattern=search_pattern,
         )
         issues_cnt = pagure.lib.search_issues(
             SESSION, repo, tags=tags, assignee=assignee,

From 83a327cbaba416021d442b24b2663269460aea18 Mon Sep 17 00:00:00 2001
From: Pierre-Yves Chibon <pingou@pingoured.fr>
Date: Oct 07 2016 21:01:48 +0000
Subject: [PATCH 2/5] Provide the searched pattern to the issues template


---

diff --git a/pagure/ui/issues.py b/pagure/ui/issues.py
index 1ab47b6..3f9acb8 100644
--- a/pagure/ui/issues.py
+++ b/pagure/ui/issues.py
@@ -533,6 +533,7 @@ def view_issues(repo, username=None, namespace=None):
         priority=priority,
         total_page=total_page,
         add_report_form=pagure.forms.AddReportForm(),
+        search_pattern=search_pattern,
     )
 
 

From b0dd02f656c8ffa6f0c43748f7a74e3eb6c2f1e3 Mon Sep 17 00:00:00 2001
From: Pierre-Yves Chibon <pingou@pingoured.fr>
Date: Oct 07 2016 21:01:48 +0000
Subject: [PATCH 3/5] Make the search box working and pretty on the issues page


---

diff --git a/pagure/static/pagure.css b/pagure/static/pagure.css
index 78c6665..b81dffc 100644
--- a/pagure/static/pagure.css
+++ b/pagure/static/pagure.css
@@ -544,7 +544,7 @@ th[data-sort] {
 }
 
 .readme dd{
-	margin-left:2em;
+    margin-left:2em;
 }
 
 /*Our specific responsive overrides*/
@@ -567,11 +567,19 @@ th[data-sort] {
 }
 
 .btn-align {
-    padding: 6px 0;
-    line-height: 1.42857143;
-    vertical-align: middle;
+  padding: 6px 0;
+  line-height: 1.42857143;
+  vertical-align: middle;
 }
 
 a.nav-link.btn{
   color:white!important;
 }
+
+.input-sm {
+ height: 28px;
+/*
+ font-size: 10px;
+*/
+ line-height: 14px;
+}
diff --git a/pagure/templates/issues.html b/pagure/templates/issues.html
index 7efe051..d332cd9 100644
--- a/pagure/templates/issues.html
+++ b/pagure/templates/issues.html
@@ -120,18 +120,20 @@
 
         {{ tag.tag }}</a>
     {% endfor %}
-</span>
-<span class="col-lg-3 pull-xs-right" >
-   <form action="{{ url_for('view_issues', username=username,
-                  repo=repo.name ) }}">
-      <div class="input-group">
-         <input type="text" class="form-control" placeholder="Search">
-         <span class="input-group-btn">
-            <button class="btn btn-secondary" type="button">Go!</button>
-         </span>
-      </div>
-   </form>
-</span>
+  </span>
+  <span class="col-lg-3 pull-xs-right tiny" >
+     <form action="{{ url_for('view_issues', username=username,
+                    repo=repo.name ) }}" method="GET">
+        <div class="input-group">
+           <input type="text" class="form-control input-sm"
+                  name="search_pattern" placeholder="Search"
+                  value="{{ search_pattern or '' }}" />
+           <span class="input-group-btn">
+              <input type="submit" class="btn btn-secondary btn-sm" value="Go!" />
+           </span>
+        </div>
+     </form>
+  </span>
 </section>
 <div class="card m-t-1">
 <table id="pagure-issues-list" class="table table-hover table-striped m-b-0">

From 6d8205ed3acf7e0f1056162b383b829bba7b228a Mon Sep 17 00:00:00 2001
From: Pierre-Yves Chibon <pingou@pingoured.fr>
Date: Oct 07 2016 21:01:48 +0000
Subject: [PATCH 4/5] Small indentation fix in the issues template


---

diff --git a/pagure/templates/issues.html b/pagure/templates/issues.html
index d332cd9..f97fdbd 100644
--- a/pagure/templates/issues.html
+++ b/pagure/templates/issues.html
@@ -28,24 +28,24 @@
         <button class="btn btn-secondary btn-sm">Roadmap</button>
       </a>
     {% endif %}
-    {% if g.repo.reports %}
-    <div class="dropdown" id="PR-dropdown">
-      <button class="btn btn-primary btn-sm dropdown-toggle"
-        type="button" id="dropdownMenu1" data-toggle="dropdown"
-        aria-haspopup="true" aria-expanded="false">
-        Report
-      </button>
-      <div class="dropdown-menu dropdown-menu-right" aria-labelledby="dropdownMenu1">
-        {% for report in repo.reports %}
-        <a class="dropdown-item" href="{{ url_for(
-            'view_report', namespace=repo.namespace,
-            username=username, repo=repo.name, report=report) }}">
-          <small>Report: {{ report }}</small>
-        </a>
-        {% endfor %}
+      {% if g.repo.reports %}
+      <div class="dropdown" id="PR-dropdown">
+        <button class="btn btn-primary btn-sm dropdown-toggle"
+          type="button" id="dropdownMenu1" data-toggle="dropdown"
+          aria-haspopup="true" aria-expanded="false">
+          Report
+        </button>
+        <div class="dropdown-menu dropdown-menu-right" aria-labelledby="dropdownMenu1">
+          {% for report in repo.reports %}
+          <a class="dropdown-item" href="{{ url_for(
+              'view_report', namespace=repo.namespace,
+              username=username, repo=repo.name, report=report) }}">
+            <small>Report: {{ report }}</small>
+          </a>
+          {% endfor %}
+        </div>
       </div>
-    </div>
-    {% endif %}
+      {% endif %}
     </span>
   </h2>
     {% if oth_issues %}

From 130ecb363701b8bfadfb91194f04628f8f243e53 Mon Sep 17 00:00:00 2001
From: Pierre-Yves Chibon <pingou@pingoured.fr>
Date: Oct 07 2016 21:14:34 +0000
Subject: [PATCH 5/5] No need to rebuild the search query when searching issues


Instead of building a new query, re-use the existing one and adjust it
for the new search criteria.

---

diff --git a/pagure/lib/__init__.py b/pagure/lib/__init__.py
index 0540e8b..a4e4bbc 100644
--- a/pagure/lib/__init__.py
+++ b/pagure/lib/__init__.py
@@ -1877,12 +1877,8 @@ def search_issues(
     )
 
     if search_pattern is not None:
-        query = session.query(
-            model.Issue
-        ).filter(
+        query = query.filter(
             model.Issue.title.like('%' + str(search_pattern) + '%')
-        ).filter(
-            model.Issue.project_id == repo.id
         )
 
     query = query.order_by(

