Repository: incubator-atlas
Updated Branches:
  refs/heads/master 45d0930b2 -> c4fd42b86


ATLAS-1897 : UI - Render HTML element based on attribute data-type while 
assigning Tag to entity.


Project: http://git-wip-us.apache.org/repos/asf/incubator-atlas/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-atlas/commit/c4fd42b8
Tree: http://git-wip-us.apache.org/repos/asf/incubator-atlas/tree/c4fd42b8
Diff: http://git-wip-us.apache.org/repos/asf/incubator-atlas/diff/c4fd42b8

Branch: refs/heads/master
Commit: c4fd42b86bfe1f4654460ba621714bcea3336fbb
Parents: 45d0930
Author: Kalyani <[email protected]>
Authored: Wed Jun 28 17:10:12 2017 +0530
Committer: Kalyani <[email protected]>
Committed: Tue Jul 4 18:15:58 2017 +0530

----------------------------------------------------------------------
 .../public/js/views/tag/addTagModalView.js      | 42 ++++++++++++++++++--
 1 file changed, 38 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/c4fd42b8/dashboardv2/public/js/views/tag/addTagModalView.js
----------------------------------------------------------------------
diff --git a/dashboardv2/public/js/views/tag/addTagModalView.js 
b/dashboardv2/public/js/views/tag/addTagModalView.js
index 7eaf23c..97d80bd 100644
--- a/dashboardv2/public/js/views/tag/addTagModalView.js
+++ b/dashboardv2/public/js/views/tag/addTagModalView.js
@@ -26,6 +26,7 @@ define(['require',
     'utils/UrlLinks',
     'utils/Enums',
     'utils/Messages',
+    'daterangepicker'
 ], function(require, AddTagModalViewTmpl, VTagList, VCommonList, Modal, 
VEntity, Utils, UrlLinks, Enums, Messages) {
     'use strict';
 
@@ -82,7 +83,12 @@ define(['require',
                     };
                 tagAttributeNames.each(function(i, item) {
                     var selection = $(item).data("key");
-                    tagAttributes[selection] = $(item).val() || null;
+                    var datatypeSelection = $(item).data("type");
+                    if (datatypeSelection === "date") {
+                        tagAttributes[selection] = Date.parse($(item).val()) 
|| null;
+                    } else {
+                        tagAttributes[selection] = $(item).val() || null;
+                    }
                 });
 
                 if (that.multiple) {
@@ -271,16 +277,44 @@ define(['require',
                         _.each(enumValue, function(key, value) {
                             str += '<option ' + (that.tagModel && key.value 
=== that.tagModel.attributes[name] ? 'selected' : '') + '>' + key.value + 
'</option>';
                         })
-                        that.ui.tagAttribute.append('<div 
class="form-group"><label>' + name + '</label>' +
+                        that.ui.tagAttribute.append('<div 
class="form-group"><label>' + name + '</label>' + ' (' + typeName + ')' +
                             '<select class="form-control attributeInputVal 
attrName" data-key="' + name + '">' + str + '</select></div>');
                     } else {
-                        that.ui.tagAttribute.append('<div 
class="form-group"><label>' + name + '</label>' +
-                            '<input type="text" value="' + (that.tagModel ? 
(that.tagModel.attributes[name] == null ? '' : that.tagModel.attributes[name]) 
: '') + '" class="form-control attributeInputVal attrName" data-key="' + name + 
'" ></input></div>');
+                        var textElement = that.getElement(name, typeName);
+                        that.ui.tagAttribute.append('<div 
class="form-group"><label>' + name + '</label>' + ' (' + typeName + ')' + 
textElement);
+                    }
+                });
+                that.$('input[data-type="date"]').each(function() {
+                    if (!$(this).data('daterangepicker')) {
+                        var dateObj = { "singleDatePicker": true, 
"showDropdowns": true };
+                        if (that.tagModel) {
+                            var formatDate = Number(this.value);
+                            dateObj["startDate"] = new Date(formatDate);
+                        }
+                        $(this).daterangepicker(dateObj);
+                    }
+                });
+                that.$('select[data-type="boolean"]').each(function() {
+                    var labelName = $(this).data('key');
+                    if (that.tagModel) {
+                        this.value = that.tagModel.attributes[labelName];
                     }
                 });
                 this.showAttributeBox();
             }
         },
+        getElement: function(labelName, typeName) {
+            var value = this.tagModel && this.tagModel.attributes ? 
(this.tagModel.attributes[labelName] || "") : "",
+                type = (typeName === "int" || typeName === "long" || typeName 
=== "float" || typeName === "byte" || typeName === "double" || typeName === 
"short") ? "number" : "text";
+            if (typeName === "boolean") {
+                return '<select class="form-control attributeInputVal 
attrName" data-key="' + labelName + '" data-type="' + typeName + '"> ' +
+                    '<option value="">--Select true or false--</option>' +
+                    '<option value="true">true</option>' +
+                    '<option value="false">false</option></select>';
+            } else {
+                return '<input type="' + type + '" value="' + value + '" 
class="form-control attributeInputVal attrName" data-key="' + labelName + '"  
data-type="' + typeName + '"></input></div>';
+            }
+        },
         saveTagData: function(options) {
             var that = this;
             this.entityModel = new VEntity();

Reply via email to