var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; var Unibase; (function (Unibase) { let Platform; (function (Platform) { let Analytics; (function (Analytics) { let Components; (function (Components) { class DuplicateReport extends Platform.Core.BaseComponent { constructor() { super(...arguments); this.excludeRoles = []; this.includeRoles = []; this.viewAll = false; this.subReports = []; } ; cssFiles() { return []; } jsFiles() { return []; } html(id, containerid) { return `
Duplicate Report
Everyone can view this report?
Select Columns
`; } load(reportid, containerid, callback) { let instance = this; this.reportId = reportid; this.excludeRoles = []; this.includeRoles = []; this.viewAll = false; this._reportBuilder = Unibase.Platform.Analytics.Reports.ReportBuilder.Instance(); this._reportManager = Unibase.Platform.Analytics.Managers.ReportManager.Instance(); $("#chkIsViewable").prop('checked', false); $('#divViewRoles').show(); this.getAllRoles(); $("#" + containerid + " #btn_Close").click(function () { instance._reportBuilder.selectedColumns = []; $('#' + containerid).modal('hide'); $('#' + containerid).remove(); }); $("#btn_Save").click((e) => { this.saveDuplicateReport(); }); let previewscontainerid = Unibase.Platform.Helpers.NavigationHelper.ModalContainerIds[Unibase.Platform.Helpers.NavigationHelper.ModalContainerIds.length - 2]; instance.getReportColumns(previewscontainerid, containerid); } getAllRoles() { Unibase.Platform.Permissions.Managers.PermissionManager.Instance().getRoles("").then((response) => { var widgetpermissions_AllRoles = response.result; this.bindSelect2(); }); } getReportColumns(previewscontainerid, containerid) { return __awaiter(this, void 0, void 0, function* () { let instance = this; let response = Components.ReportViewer.Instance().getReportViewerInstance(previewscontainerid); instance.reportInfo = response && response.reportResponse && response.reportResponse.result && response.reportResponse.result.ReportInfo; if (!instance.reportInfo) { let reportid = Number(Unibase.Themes.Providers.Detail_Settings.Instance().InputParameters.find(x => x.Key.endsWith("_reportid")).Value); yield this._reportManager.getFullReportInfo(reportid).then(response => { if (response.status == Unibase.Data.Status.Success) { if (!response.result) return MessageHelper.Instance().showError("Report data does not exists", ""); instance.reportInfo = response.result; } else { return MessageHelper.Instance().showError(response.message, ""); } }); } instance._reportManager.getSubReports(instance.reportInfo.ReportId).then(function (response) { if (response.status == Unibase.Data.Status.Success && response.result && response.result.length) { response.result.map(x => { x.SubReportId = 0; x.ReportId = 0; }); instance.subReports = response.result; } }); instance.reportColumns = instance.reportInfo.ReportColumns; let html = ''; for (let i = 0; i <= instance.reportColumns.length - 1; i++) { let data = instance.reportColumns[i]; let columnname = data.DisplayText; let columnaliasname = data.AliasName; let reportcolumnid = data.ReportColumnId; let columnindex = data.ColumnIndex; let tablecolumname = data.ReportColumnName.replace(/\s/g, ''); const visibleIconHtml = ` `; tablecolumname = tablecolumname.replace(/\s/g, ''); let htmlli = `
  • ${columnindex}
    ${columnname}
    ${visibleIconHtml}
  • `; 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 = {}));