Explorar o código

[indexer] Change defaults of 'add field' screen

Also disallow deselection of unique key field.
Abraham Elmahrek %!s(int64=11) %!d(string=hai) anos
pai
achega
64ac825

+ 6 - 1
desktop/libs/indexer/src/indexer/templates/collections.mako

@@ -278,7 +278,12 @@ ${ commonheader(_('Collection Manager'), "indexer", user, "29px") | n,unicode }
         <td><p class="text-center"><input data-bind="checked: required" type="checkbox"></p></td>
         <td><p class="text-center"><input data-bind="checked: indexed" type="checkbox"></p></td>
         <td><p class="text-center"><input data-bind="checked: stored" type="checkbox"></p></td>
-        <td><p class="text-center"><input data-bind="checked: uniqueKeyField" name="unique-key" type="checkbox" /></p></td>
+        <td>
+          <p class="text-center">
+            <input data-bind="checked: uniqueKeyField, visible: !uniqueKeyField()" name="unique-key" type="checkbox" />
+            <span class="fa" data-bind="css: {'fa-check': uniqueKeyField}">
+          </p>
+        </td>
         <td>
           <a data-bind="click: remove, visible: editable" href="javascript:void(0)" class="btn btn-danger"><i class="fa fa-minus"></i>&nbsp;${_("Remove")}</a>
         </td>

+ 6 - 12
desktop/libs/indexer/static/js/collections.js

@@ -226,19 +226,13 @@ var CreateCollectionViewModel = function() {
 
           // Find unique key default field
           var message = null;
-          var first = null;
-          ko.utils.arrayForEach(self.collection.fields(), function(field) {
-            if (!first) {
-              first = field;
-            }
-            if (field.name() == 'message') {
-              message = field;
-            }
+          var uniqueKeyFields = ko.utils.arrayFilter(self.collection.fields(), function(field) {
+            return field.indexed();
           });
-          if (message) {
-            self.collection.uniqueKeyField(message.name());
-          } else if (first) {
-            self.collection.uniqueKeyField(first.name());
+          if (uniqueKeyFields.length > 0) {
+            self.collection.uniqueKeyField(uniqueKeyFields[0].name());
+          } else if (self.collection.fields().length > 0) {
+            self.collection.uniqueKeyField(self.collection.fields().name());
           }
         } else {
           $(document).trigger("error", data.message);

+ 3 - 1
desktop/libs/indexer/static/js/lib.js

@@ -49,7 +49,9 @@ var Collection = function(name) {
 var Field = function(collection, name, type, required, indexed, stored) {
   var self = this;
 
-  indexed = (indexed == undefined) ? true : !!indexed;
+  if (indexed == undefined) {
+    indexed = type.indexOf('text_') == -1;
+  }
   required = (required == undefined) ? true : !!required;
 
   self.name = ko.observable(name).extend({'errors': null});