Commit 9abc89bf by pratik24mac Committed by nixonrodrigues

ATLAS-2272 : UI - Save the state of dragged columns using save search API.

parent 4516418b
......@@ -112,9 +112,18 @@ $color_celeste_approx: #1D1F2B;
}
}
}
.table-responsive{
position: relative;
}
.sindu_dragger {
@extend .gu-mirror;
&.sindu_column {
li {
float: none !important;
display: table-cell !important;
}
}
.gu-transit {
box-shadow: 0px 1px 15px inset;
}
......
......@@ -296,26 +296,34 @@ define(['require', 'utils/Utils', 'modules/Modal', 'utils/Messages', 'utils/Enum
CommonViewFunction.generateObjectForSaveSearchApi = function(options) {
var obj = {
name: options.name,
guid: options.guid,
searchParameters: {}
guid: options.guid
};
var value = options.value;
if (value) {
_.each(Enums.extractFromUrlForSearch, function(v, k) {
var val = value[k];
if (!_.isUndefinedNull(val)) {
if (k == "attributes") {
val = val.split(',');
} else if (_.contains(["tagFilters","entityFilters"],k)) {
val = CommonViewFunction.attributeFilter.generateAPIObj(val);
} else if (_.contains(["includeDE","excludeST","excludeSC"],k)) {
val = val ? false : true;
}
}
if (_.contains(["includeDE","excludeST","excludeSC"],k)) {
val = _.isUndefinedNull(val) ? true : val;
_.each(Enums.extractFromUrlForSearch, function(svalue, skey) {
if (_.isObject(svalue)) {
_.each(svalue, function(v, k) {
var val = value[k];
if (!_.isUndefinedNull(val)) {
if (k == "attributes") {
val = val.split(',');
} else if (_.contains(["tagFilters", "entityFilters"], k)) {
val = CommonViewFunction.attributeFilter.generateAPIObj(val);
} else if (_.contains(["includeDE", "excludeST", "excludeSC"], k)) {
val = val ? false : true;
}
}
if (_.contains(["includeDE", "excludeST", "excludeSC"], k)) {
val = _.isUndefinedNull(val) ? true : val;
}
if (!obj[skey]) {
obj[skey] = {};
}
obj[skey][v] = val;
});
} else {
obj[skey] = value[skey];
}
obj.searchParameters[v] = val;
});
return obj;
}
......@@ -326,50 +334,56 @@ define(['require', 'utils/Utils', 'modules/Modal', 'utils/Messages', 'utils/Enum
entityDefCollection = options.entityDefCollection,
obj = {};
if (value) {
_.each(Enums.extractFromUrlForSearch, function(v, k) {
var val = value[v];
if (!_.isUndefinedNull(val)) {
if (k == "attributes") {
val = val.join(',');
} else if (k == "tagFilters") {
if (classificationDefCollection) {
var classificationDef = classificationDefCollection.fullCollection.findWhere({ 'name': value.classification })
attributeDefs = Utils.getNestedSuperTypeObj({
collection: classificationDefCollection,
attrMerge: true,
data: classificationDef.toJSON()
});
_.each(val.criterion, function(obj) {
var attributeDef = _.findWhere(attributeDefs, { 'name': obj.attributeName });
if (attributeDef) {
obj.attributeValue = obj.attributeValue;
obj['attributeType'] = attributeDef.typeName;
_.each(Enums.extractFromUrlForSearch, function(svalue, skey) {
if(_.isObject(svalue)) {
_.each(svalue, function(v, k) {
var val = value[skey][v];
if (!_.isUndefinedNull(val)) {
if (k == "attributes") {
val = val.join(',');
} else if (k == "tagFilters") {
if (classificationDefCollection) {
var classificationDef = classificationDefCollection.fullCollection.findWhere({ 'name': value[skey].classification })
attributeDefs = Utils.getNestedSuperTypeObj({
collection: classificationDefCollection,
attrMerge: true,
data: classificationDef.toJSON()
});
_.each(val.criterion, function(obj) {
var attributeDef = _.findWhere(attributeDefs, { 'name': obj.attributeName });
if (attributeDef) {
obj.attributeValue = obj.attributeValue;
obj['attributeType'] = attributeDef.typeName;
}
});
}
});
}
val = CommonViewFunction.attributeFilter.generateUrl({ "value": val.criterion });
} else if (k == "entityFilters") {
if (entityDefCollection) {
var entityDef = entityDefCollection.fullCollection.findWhere({ 'name': value.typeName }),
attributeDefs = Utils.getNestedSuperTypeObj({
collection: entityDefCollection,
attrMerge: true,
data: entityDef.toJSON()
});
_.each(val.criterion, function(obj) {
var attributeDef = _.findWhere(attributeDefs, { 'name': obj.attributeName });
if (attributeDef) {
obj.attributeValue = obj.attributeValue;
obj['attributeType'] = attributeDef.typeName;
val = CommonViewFunction.attributeFilter.generateUrl({ "value": val.criterion });
} else if (k == "entityFilters") {
if (entityDefCollection) {
var entityDef = entityDefCollection.fullCollection.findWhere({ 'name': value[skey].typeName }),
attributeDefs = Utils.getNestedSuperTypeObj({
collection: entityDefCollection,
attrMerge: true,
data: entityDef.toJSON()
});
_.each(val.criterion, function(obj) {
var attributeDef = _.findWhere(attributeDefs, { 'name': obj.attributeName });
if (attributeDef) {
obj.attributeValue = obj.attributeValue;
obj['attributeType'] = attributeDef.typeName;
}
});
}
});
val = CommonViewFunction.attributeFilter.generateUrl({ "value": val.criterion });
} else if (_.contains(["includeDE", "excludeST", "excludeSC"], k)) {
val = val ? false : true;
}
}
val = CommonViewFunction.attributeFilter.generateUrl({ "value": val.criterion });
} else if (_.contains(["includeDE","excludeST","excludeSC"],k)) {
val = val ? false : true;
}
obj[k] = val;
});
}else{
obj[skey] = value[skey];
}
obj[k] = val;
});
return obj;
}
......
......@@ -57,17 +57,20 @@ define(['require'], function(require) {
'annual': "Annual Distribution"
}
Enums.extractFromUrlForSearch = {
"pageLimit": "limit",
"type": "typeName",
"tag": "classification",
"query": "query",
"pageOffset": "offset",
"includeDE": "excludeDeletedEntities",
"excludeST": "includeSubTypes",
"excludeSC": "includeSubClassifications",
"tagFilters": "tagFilters",
"entityFilters": "entityFilters",
"attributes": "attributes"
"searchParameters": {
"pageLimit": "limit",
"type": "typeName",
"tag": "classification",
"query": "query",
"pageOffset": "offset",
"includeDE": "excludeDeletedEntities",
"excludeST": "includeSubTypes",
"excludeSC": "includeSubClassifications",
"tagFilters": "tagFilters",
"entityFilters": "entityFilters",
"attributes": "attributes"
},
"uiParameters": "uiParameters"
}
return Enums;
......
......@@ -161,7 +161,7 @@ define(['require',
},
applyValue: function(model, searchType) {
that.manualRender(_.extend(searchType, CommonViewFunction.generateUrlFromSaveSearchObject({
value: model.get('searchParameters'),
value: { "searchParameters": model.get('searchParameters'), 'uiParameters': model.get('uiParameters') },
classificationDefCollection: that.classificationDefCollection,
entityDefCollection: that.entityDefCollection
})));
......
......@@ -211,6 +211,7 @@ define(['require',
this.ui.columnEmptyInfo.hide();
}
}
this.columnOrder = this.getColumnOrder(this.REntityTableLayoutView.$el.find('.colSort th.renderable'));
this.triggerUrl();
var attributes = this.searchCollection.filterObj.attributes;
if ((excludeDefaultColumn && attributes) && (excludeDefaultColumn.length > attributes.length || _.difference(excludeDefaultColumn, attributes).length)) {
......@@ -297,10 +298,16 @@ define(['require',
}
}
},
getColumnOrderWithPosition: function() {
var that = this;
return _.map(that.columnOrder, function(value, key) {
return key + "::" + value;
}).join(",");
},
triggerUrl: function(options) {
Utils.setUrl(_.extend({
url: Utils.getUrlState.getQueryUrl().queyParams[0],
urlParams: this.value,
urlParams: this.columnOrder ? _.extend(this.value, { 'uiParameters': this.getColumnOrderWithPosition() }) : this.value,
mergeBrowserUrl: false,
trigger: false,
updateTabState: true
......@@ -502,6 +509,11 @@ define(['require',
var that = this;
require(['utils/TableLayout'], function(TableLayout) {
// displayOrder added for column manager
if (that.value.uiParameters) {
var savedColumnOrder = _.object(that.value.uiParameters.split(',').map(function(a) {
return a.split('::');
})); // get Column position from string to object
}
var columnCollection = Backgrid.Columns.extend({
sortKey: "displayOrder",
comparator: function(item) {
......@@ -509,24 +521,28 @@ define(['require',
},
setPositions: function() {
_.each(this.models, function(model, index) {
model.set("displayOrder", (that.columnOrder == null ? index : that.columnOrder[model.get('label')]) + 1, { silent: true });
model.set("displayOrder", (savedColumnOrder == null ? index : parseInt(savedColumnOrder[model.get('label')])) + 1, { silent: true });
});
return this;
}
});
var columns = new columnCollection((that.searchCollection.dynamicTable ? that.getDaynamicColumns(that.searchCollection.toJSON()) : that.getFixedDslColumn()));
columns.setPositions().sort();
that.REntityTableLayoutView.show(new TableLayout(_.extend({}, that.commonTableOptions, {
var table = new TableLayout(_.extend({}, that.commonTableOptions, {
columns: columns
})));
}));
that.REntityTableLayoutView.show(table);
if (that.value.searchType !== "dsl") {
that.ui.containerCheckBox.show();
} else {
that.ui.containerCheckBox.hide();
}
that.$(".ellipsis .inputAssignTag").hide();
table.trigger("grid:refresh"); /*Event fire when table rendered*/
tableDragger(document.querySelector(".colSort")).on('drop', function(from, to, el) {
that.columnOrder = that.getColumnOrder(el.querySelectorAll('th'));
that.columnOrder = that.getColumnOrder(el.querySelectorAll('th.renderable'));
table.trigger("grid:refresh:update");
that.triggerUrl();
});
that.checkTableFetch();
});
......
......@@ -147,7 +147,7 @@ define(['require',
if (options && options.model) {
var searchParameters = options.model.toJSON().searchParameters,
params = CommonViewFunction.generateUrlFromSaveSearchObject({
value: searchParameters,
value: {"searchParameters" : searchParameters, "uiParameters": options.model.get('uiParameters')},
classificationDefCollection: this.classificationDefCollection,
entityDefCollection: this.entityDefCollection
});
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment