[Bps-public-commit] rt-extension-rightsdebugger branch, master, updated. 8e117ee921a6fbe6e062a7e9fa3441da7bf999ea

Shawn Moore shawn at bestpractical.com
Thu Feb 2 18:38:23 EST 2017


The branch, master has been updated
       via  8e117ee921a6fbe6e062a7e9fa3441da7bf999ea (commit)
       via  f874753010f13cf317e6b6da86e5045f1090588c (commit)
      from  026f8c5f3822f0839d4653059125b666c07e8543 (commit)

Summary of changes:
 html/Admin/RightsDebugger/index.html |  6 +++---
 html/Helpers/RightsDebugger/Search   |  2 +-
 static/css/rights-debugger.css       |  4 ++++
 static/js/rights-debugger.js         | 25 ++++++++++++++++++++++---
 4 files changed, 30 insertions(+), 7 deletions(-)

- Log -----------------------------------------------------------------
commit f874753010f13cf317e6b6da86e5045f1090588c
Author: Shawn M Moore <shawn at bestpractical.com>
Date:   Thu Feb 2 23:23:59 2017 +0000

    Avoid handlebars error on other pages

diff --git a/static/js/rights-debugger.js b/static/js/rights-debugger.js
index f4d1c45..a6da2af 100644
--- a/static/js/rights-debugger.js
+++ b/static/js/rights-debugger.js
@@ -1,5 +1,10 @@
 jQuery(function () {
-    var template = Handlebars.compile(jQuery('script#debugger-result').html());
+    var template = jQuery('script#debugger-result').html();
+    if (!template) {
+        return;
+    }
+
+    var renderItem = Handlebars.compile(template);
     var form = jQuery('form#rights-debugger');
     var display = form.find('.results');
 
@@ -14,7 +19,7 @@ jQuery(function () {
                 display.empty(); // just in case of race condition
                 var items = response.results;
                 jQuery.each(items, function (i, item) {
-                    display.append(template(item));
+                    display.append(renderItem(item));
                 });
             },
             error: function (xhr, reason) {

commit 8e117ee921a6fbe6e062a7e9fa3441da7bf999ea
Author: Shawn M Moore <shawn at bestpractical.com>
Date:   Thu Feb 2 23:38:07 2017 +0000

    Switch to RightName LIKE query, with result highlighting

diff --git a/html/Admin/RightsDebugger/index.html b/html/Admin/RightsDebugger/index.html
index 3c566e0..a5bd3a3 100644
--- a/html/Admin/RightsDebugger/index.html
+++ b/html/Admin/RightsDebugger/index.html
@@ -14,13 +14,13 @@
 <script type="text/x-template" id="debugger-result">
   <div class="result">
     <div class="principal cell">
-        {{principal.type}} {{principal.label}}
+        {{item.principal.type}} {{item.principal.label}}
     </div>
     <div class="object cell">
-        {{object.class}} #{{object.id}}
+        {{item.object.class}} #{{item.object.id}}
     </div>
     <div class="right cell">
-        {{right}}
+        {{search_highlight item.right search.right}}
     </div>
     <div class="revoke cell"><button>Revoke</button></div>
   </div>
diff --git a/html/Helpers/RightsDebugger/Search b/html/Helpers/RightsDebugger/Search
index cb8bb14..4374a2f 100644
--- a/html/Helpers/RightsDebugger/Search
+++ b/html/Helpers/RightsDebugger/Search
@@ -9,7 +9,7 @@ if ($ARGS{right}) {
     $has_search = 1;
     $ACL->Limit(
         FIELD         => 'RightName',
-        OPERATOR      => 'STARTSWITH',
+        OPERATOR      => 'LIKE',
         VALUE         => $ARGS{right},
         CASESENSITIVE => 0,
     );
diff --git a/static/css/rights-debugger.css b/static/css/rights-debugger.css
index 336f87f..0a2cc72 100644
--- a/static/css/rights-debugger.css
+++ b/static/css/rights-debugger.css
@@ -11,3 +11,7 @@
 #rights-debugger .results .result:nth-child(even) {
     background-color: #DBE5F0;
 }
+
+#rights-debugger .results .result .match {
+    font-weight: bold;
+}
diff --git a/static/js/rights-debugger.js b/static/js/rights-debugger.js
index a6da2af..205ce62 100644
--- a/static/js/rights-debugger.js
+++ b/static/js/rights-debugger.js
@@ -4,6 +4,14 @@ jQuery(function () {
         return;
     }
 
+    Handlebars.registerHelper('search_highlight', function (text, term) {
+        // this is simplistic; better would be to highlight on the
+        // unescaped text, and case insensitively
+        text = Handlebars.Utils.escapeExpression(text);
+        text = text.replace(term, '<span class="match">' + term + '</span>');
+        return new Handlebars.SafeString(text);
+    });
+
     var renderItem = Handlebars.compile(template);
     var form = jQuery('form#rights-debugger');
     var display = form.find('.results');
@@ -11,15 +19,21 @@ jQuery(function () {
     var refreshResults = function () {
         display.empty();
 
+        var serialized = form.serializeArray();
+        var search = {};
+        jQuery.each(serialized, function(i, field){
+            search[field.name] = field.value;
+        });
+
         jQuery.ajax({
             url: form.attr('action'),
-            data: form.serializeArray(),
+            data: search,
             timeout: 30000, /* 30 seconds */
             success: function (response) {
                 display.empty(); // just in case of race condition
                 var items = response.results;
                 jQuery.each(items, function (i, item) {
-                    display.append(renderItem(item));
+                    display.append(renderItem({ search: search, item: item }));
                 });
             },
             error: function (xhr, reason) {

-----------------------------------------------------------------------


More information about the Bps-public-commit mailing list