${columnindex}
${columnname}
`;
html += htmlli;
}
$("#" + containerid).find("#selectedColumns").html(html);
instance.sortSelectedColums(previewscontainerid, containerid);
$('#selectedColumns').find(".btn-flush-biz-theme").click(function () {
$(".list-group-item").removeClass("z-index-10");
$(this).parents(".list-group-item").addClass("z-index-10");
});
$('#selectedColumns').find(".column-visible-icon").click(function () {
const isVisible = $(this).find(".eye-icon").hasClass("la-eye");
if (isVisible) {
$(this).find(".eye-icon").removeClass("la-eye").addClass("la-eye-slash");
}
else {
$(this).find(".eye-icon").removeClass("la-eye-slash").addClass("la-eye");
}
});
});
}
updatestageindex() {
var instance = this;
$(".report_Columns_Duplicate_Fields #selectedColumns").find(".list-group-item").each(function (i, e) {
$(this).find(".ListColumnIndex").html(`${i}`);
$(this).find(".ListColumnIndexInput").val(`${i}`);
});
instance.updateIndexBasedOnSorting();
}
sortSelectedColums(previewscontainerid, containerid) {
var instance = this;
let list = $('#selectedColumns');
if (!list)
return;
list.sortable({
connectWith: "#selectedColumns",
cursor: 'move',
update: function (event, ui) {
instance.updatestageindex();
}
});
}
updateIndexBasedOnSorting() {
var instance = this;
let ui_updated_array = [];
$(".ui_list_sorting").each(function () {
var ColumnIndex = $(this).find(".ListColumnIndexInput").val();
var DisplayText = $(this).find(".columnname").text();
var ReportColumnId = $(this).attr("data-ReportColumnId");
ui_updated_array.push({ ReportColumnId, ColumnIndex, DisplayText });
});
ui_updated_array = ui_updated_array.reverse();
function mapOrder(array, order, key) {
array.sort(function (a, b) {
var A = a[key], B = b[key];
if (order.indexOf(A) > order.indexOf(B)) {
return 1;
}
else {
return -1;
}
});
return array;
}
;
let ordered_array = mapOrder(instance.reportColumns, ui_updated_array, 'ReportColumnId');
console.log(ordered_array.reverse());
}
bindSelect2() {
var ViewRoleElementId = "txtIncludeViewRoles";
var ExcludeRoleElementId = "txtExcludeViewRoles";
var userinfo = Unibase.Platform.Membership.Infos.Identity.getCurrentUser();
var url = _appsettings.server_url() + '/apis/v4/unibase/platform/roles/getroles';
url = url + "/term/";
url = url.replace('#', '');
$("#" + ViewRoleElementId).select2({
multiple: true,
allowClear: false,
data: [],
placeholder: 'Select Role',
ajax: {
url: (request) => {
var reqUrl = url;
var term = request.term;
if (term == undefined || term == "")
reqUrl = reqUrl + term + "/authtoken/" + userinfo.sessionId;
else
reqUrl = reqUrl + term + "/authtoken/" + userinfo.sessionId;
return reqUrl;
},
beforeSend: (xhr) => {
if (userinfo !== undefined && userinfo !== null) {
xhr.setRequestHeader("Authorization", "Basic " + userinfo.sessionId);
xhr.setRequestHeader('geoposition', userinfo.latd + ':' + userinfo.lgId);
}
},
delay: 250,
dataType: 'json',
processResults: function (data) {
var selectData = [];
var Data = JSON.parse(data.result);
for (var i = 0; i < Data.length; i++) {
selectData.push({
id: Data[i].Value,
text: Data[i].SelectText
});
}
;
return { results: selectData };
}
},
templateResult: function (item) { return item.text; },
templateSelection: function (item) { return item.text; },
});
$("#" + ViewRoleElementId).val("").trigger('change');
$('#txtIncludeViewRoles').on('select2:select', (e) => {
let result = e.params.data;
if (Number(result.id) != 0) {
var roleId = result.id;
this.addViewRole(this.reportId, roleId, true, false);
}
});
$('#txtIncludeViewRoles').on('select2:unselect', (e) => {
let result = e.params.data;
var roleId = Number(result.id);
if (roleId != 0) {
let idx = this.includeRoles.findIndex(x => x.RoleId == roleId);
if (idx != -1) {
this.includeRoles.splice(idx, 1);
let ids = this.excludeRoles.map(x => x.RoleId);
$("#txtExcludeViewRoles").val(ids).trigger('change');
}
}
});
$("#" + ExcludeRoleElementId).select2({
multiple: true,
allowClear: false,
data: [],
placeholder: 'Select Role',
ajax: {
url: function (request) {
var reqUrl = url;
var term = request.term;
if (term == undefined || term == "")
reqUrl = reqUrl + term + "/authtoken/" + userinfo.sessionId;
else
reqUrl = reqUrl + term + "/authtoken/" + userinfo.sessionId;
return reqUrl;
},
beforeSend: function (xhr) {
if (userinfo !== undefined && userinfo !== null) {
xhr.setRequestHeader("Authorization", "Basic " + userinfo.sessionId);
xhr.setRequestHeader('geoposition', userinfo.latd + ':' + userinfo.lgId);
}
},
delay: 250,
dataType: 'json',
processResults: function (data) {
var selectData = [];
var Data = JSON.parse(data.result);
for (var i = 0; i < Data.length; i++) {
selectData.push({
id: Data[i].Value,
text: Data[i].SelectText
});
}
;
return { results: selectData };
}
},
templateResult: function (item) { return item.text; },
templateSelection: function (item) { return item.text; },
});
jQuery("#" + ExcludeRoleElementId).val("").trigger('change');
$('.select2-search__field').css("width", "100%");
$('#txtExcludeViewRoles').on('select2:select', (e) => {
let result = e.params.data;
if (Number(result.id) != 0) {
var roleId = result.id;
this.addViewRole(this.reportId, roleId, false, true);
let includeRoleIdx = this.includeRoles.findIndex(x => x.RoleId == Number(roleId));
if (includeRoleIdx != -1) {
this.includeRoles.splice(includeRoleIdx, 1);
let ids = this.includeRoles.map(x => x.RoleId);
$("#txtIncludeViewRoles").val(ids).trigger('change');
}
}
});
$('#txtExcludeViewRoles').on('select2:unselect', (e) => {
let result = e.params.data;
var roleId = Number(result.id);
if (roleId != 0) {
let idx = this.excludeRoles.findIndex(x => x.RoleId == roleId);
if (idx != -1) {
this.excludeRoles.splice(idx, 1);
}
}
});
}
changeViewAllPermission() {
var viewable = $("#chkIsViewable").prop('checked');
this.viewAll = viewable;
if (viewable) {
$('#divViewRoles').hide();
}
else
$('#divViewRoles').show();
}
addViewRole(reportId, roleId, IsView, IsExclude) {
let listOfRoles;
if (IsView) {
listOfRoles = this.includeRoles;
}
else {
listOfRoles = this.excludeRoles;
}
let idx = listOfRoles.findIndex(x => x.RoleId == roleId);
if (idx == -1) {
let reqObj = new Unibase.Platform.Analytics.Requests.ReportRole();
reqObj.ReportId = reportId;
reqObj.RoleId = Number(roleId);
reqObj.ViewReport = IsView;
reqObj.ExcludeViewReport = IsExclude;
listOfRoles.push(reqObj);
}
}
removeReportRole(reportId, roleId, IsView, IsExclude) {
let listOfRoles;
if (IsView) {
listOfRoles = this.includeRoles;
}
else {
listOfRoles = this.excludeRoles;
}
let idx = listOfRoles.findIndex(x => x.RoleId == roleId);
if (idx != -1) {
listOfRoles.splice(idx, 1);
}
}
saveDuplicateReport() {
for (var i = 0; i < this.reportColumns.length; i++) {
this._reportBuilder.reportColumns_Array(this.reportColumns[i]);
}
let model = new Analytics.Requests.DuplicateReport();
model.ReportId = this.reportId;
model.ReportName = $("#txt_reportname").val();
model.ReportRoles = this.excludeRoles.concat(this.includeRoles);
model.ViewAll = this.viewAll;
model.ReportColumns = this.reportColumns;
model.SubReports = this.subReports;
Unibase.Platform.Analytics.Managers.ReportManager.Instance().duplicateReport(model).then((res) => {
if (res.status == Unibase.Data.Status.Success) {
MessageHelper.Instance().showSuccess("Report duplicate sucessfully created", "duplicate_errormsg");
return $("#btn_Close").click();
}
else {
return MessageHelper.Instance().showError(res.message, "duplicate_errormsg");
}
});
}
changeDisplayText(aliasName) {
let column = this.getReportColumn(aliasName);
if (column) {
column.DisplayText = $("#txtAliasName_" + aliasName).val();
}
}
showOrHideColumn(aliasName) {
let column = this.getReportColumn(aliasName);
if (column) {
column.Isvisible = !column.Isvisible;
}
}
removeColumn(aliasName) {
var sortColumns = JSON.parse(this.reportInfo.SortColumns);
var index = sortColumns.findIndex(x => x.Name == aliasName);
if (index > -1) {
return MessageHelper.Instance().showError("Current column is used as sort column in main report", "duplicate_errormsg");
}
let idx = this.getReportColumnIndex(aliasName);
if (idx > -1) {
this.reportColumns.splice(idx, 1);
$("#dsl_column_" + aliasName).remove();
this.updatestageindex();
}
}
getReportColumnIndex(aliasName) {
return this.reportColumns.findIndex(x => x.AliasName == aliasName);
}
getReportColumn(aliasName) {
return this.reportColumns.find(x => x.AliasName == aliasName);
}
linkreport(aliasname) {
this._reportBuilder.selectedColumns = this.reportInfo.ReportColumns;
this._reportBuilder.res = this.reportInfo;
let sr = Unibase.Platform.Analytics.Reports.SubReport.Instance();
sr.isReportDuplicate = true;
sr.linkreport(aliasname);
}
static Instance() {
if (this.instance === undefined) {
this.instance = new DuplicateReport();
}
return this.instance;
}
}
Components.DuplicateReport = DuplicateReport;
})(Components = Analytics.Components || (Analytics.Components = {}));
})(Analytics = Platform.Analytics || (Platform.Analytics = {}));
})(Platform = Unibase.Platform || (Unibase.Platform = {}));
})(Unibase || (Unibase = {}));