Milimetric has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/75887


Change subject: added filtering for cohorts
......................................................................

added filtering for cohorts

Change-Id: I9e18f5da6c98f650562d224e4820bdeebdfddad9
---
M wikimetrics/static/js/cohortList.js
M wikimetrics/static/js/reportCreate.js
M wikimetrics/templates/cohorts.html
M wikimetrics/templates/request.html
4 files changed, 30 insertions(+), 4 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/analytics/wikimetrics 
refs/changes/87/75887/1

diff --git a/wikimetrics/static/js/cohortList.js 
b/wikimetrics/static/js/cohortList.js
index fe4bb0f..4679eeb 100644
--- a/wikimetrics/static/js/cohortList.js
+++ b/wikimetrics/static/js/cohortList.js
@@ -1,6 +1,7 @@
 $(document).ready(function(){
     
     var viewModel = {
+        filter: ko.observable(''),
         cohorts: ko.observableArray([]),
         
         view: function(cohort){
@@ -23,6 +24,18 @@
         },
     };
     
+    viewModel.filteredCohorts = ko.computed(function(){
+        if (this.cohorts().length && this.filter().length) {
+            filter = this.filter().toLowerCase();
+            return this.cohorts().filter(function(it){
+                var name = it.name.toLowerCase();
+                return name.indexOf(filter) >= 0;
+            });
+        } else {
+            return this.cohorts();
+        }
+    }, viewModel);
+    
     // fetch this user's cohorts
     $.get('/cohorts/list/')
         .done(site.handleWith(function(data){
diff --git a/wikimetrics/static/js/reportCreate.js 
b/wikimetrics/static/js/reportCreate.js
index 4988c6e..82d4b7c 100644
--- a/wikimetrics/static/js/reportCreate.js
+++ b/wikimetrics/static/js/reportCreate.js
@@ -1,6 +1,7 @@
 $(document).ready(function(){
     
     var viewModel = {
+        filter: ko.observable(''),
         cohorts: ko.observableArray([]),
         toggleCohort: function(cohort){
             // fetch wikiusers
@@ -132,6 +133,18 @@
         return ret;
     }, viewModel.request());
     
+    viewModel.filteredCohorts = ko.computed(function(){
+        if (this.cohorts().length && this.filter().length) {
+            filter = this.filter().toLowerCase();
+            return this.cohorts().filter(function(it){
+                var name = it.name.toLowerCase();
+                return name.indexOf(filter) >= 0;
+            });
+        } else {
+            return this.cohorts();
+        }
+    }, viewModel);
+    
     function setSelected(list){
         bareList = ko.utils.unwrapObservable(list);
         ko.utils.arrayForEach(bareList, function(item){
diff --git a/wikimetrics/templates/cohorts.html 
b/wikimetrics/templates/cohorts.html
index dedc0de..30eb35c 100644
--- a/wikimetrics/templates/cohorts.html
+++ b/wikimetrics/templates/cohorts.html
@@ -7,11 +7,11 @@
     <a class="btn btn-primary btn-large" 
href="{{url_for('cohort_upload')}}">Upload Cohort</a>
     &nbsp;
     &nbsp;
-    <input type="text" class="search-query" placeholder="find below"/>
+    <input type="text" class="search-query" placeholder="type and press enter 
to filter" data-bind="value: filter"/>
 </div>
 <hr/>
 <div class="tabbable tabs-left">
-    <ul class="nav nav-tabs" data-bind="foreach: cohorts">
+    <ul class="nav nav-tabs" data-bind="foreach: filteredCohorts">
         <li>
             <a data-bind="text: name, attr: {href: '#' + id}, click: 
$root.view" data-toggle="tab"></a>
         </li>
diff --git a/wikimetrics/templates/request.html 
b/wikimetrics/templates/request.html
index 1dab3a9..e444c4a 100644
--- a/wikimetrics/templates/request.html
+++ b/wikimetrics/templates/request.html
@@ -7,11 +7,11 @@
         <div class="navbar-search pull-right">
             <a href="{{url_for('cohort_upload')}}">upload a new cohort</a>
             &nbsp;&nbsp;
-            <input type="text" class="search-query" placeholder="find"/>
+            <input type="text" class="search-query" placeholder="type and 
press enter to filter" data-bind="value: filter"/>
         </div>
     </div>
     <div class="cohorts">
-        <ul class="unstyled" data-bind="foreach: cohorts">
+        <ul class="unstyled" data-bind="foreach: filteredCohorts">
             <li>
                 <label>
                     <input type="checkbox" data-bind="checked: selected, 
click: $root.toggleCohort"/>

-- 
To view, visit https://gerrit.wikimedia.org/r/75887
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I9e18f5da6c98f650562d224e4820bdeebdfddad9
Gerrit-PatchSet: 1
Gerrit-Project: analytics/wikimetrics
Gerrit-Branch: master
Gerrit-Owner: Milimetric <dandree...@wikimedia.org>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to