var Unibase; (function (Unibase) { let Platform; (function (Platform) { let Analytics; (function (Analytics) { let Components; (function (Components) { class ReportPermissions extends Platform.Core.BaseComponent { constructor() { super(); this._ReportPermission_ViewRoles = []; this._ReportPermission_ChangeRoles = []; this.Reportspermission_ReportRoles = []; this.reportManager = Analytics.Managers.ReportManager.Instance(); } cssFiles() { return []; } jsFiles() { var jsFiles = []; return jsFiles; } html(id, containerid) { let html = ""; html += `
Report Permissions
Everyone can view this report?
`; return html; } load(reportid, containerid, callback) { var instance = this; var _fileCacheHelper = this.fileCacheHelper; $("#div_reportpermissions").height($(window).outerHeight() - 115); _fileCacheHelper.loadJsFile('/platform/analytics/managers/reportmanager.js', function () { Unibase.Platform.Analytics.Components.ReportPermissions.Instance().Reportspermission_reportid = reportid; instance.Reportspermission_ReportRoles = []; instance.reportManager.getReportRoles(reportid).then(function (response) { if (response.result != null) { var selectedRoles = response.result; for (var i = 0; i < selectedRoles.length; i++) { instance.Reportspermission_ReportRoles.push({ ReportRoleId: selectedRoles[i].ReportRoleId, RoleId: selectedRoles[i].RoleId, ViewReport: selectedRoles[i].ViewReport, ChangeReport: selectedRoles[i].ChangeReport }); } instance.getRoleList(reportid, selectedRoles); } else { MessageHelper.Instance().showError(response.message, "Bizgaze_ValidationSummary"); } }); }); $("#btn_Close").click(function () { $('#' + containerid).modal('hide'); $('#' + containerid).remove(); }); } getRoleList(reportid, widgetroles) { var instance = this; Unibase.Platform.Permissions.Managers.PermissionManager.Instance().getRoles("").then(function (response) { var widgetpermissions_AllRoles = response.result; instance.loadAssignedRoles(reportid, widgetroles, widgetpermissions_AllRoles); }); } loadAssignedRoles(reportid, widgetroles, widgetpermissions_AllRoles) { var instance = this; var ExcludeViewRoles = []; var _Permissions_ViewRoles = []; for (var i = 0; i < widgetpermissions_AllRoles.length; i++) { var data = widgetpermissions_AllRoles[i]; var assignedRoles = widgetroles; for (var j = 0; j < assignedRoles.length; j++) { var assignedRole = assignedRoles[j]; if (assignedRole.RoleId == data.RoleId) { if (assignedRole.ViewReport == true) { _Permissions_ViewRoles.push({ id: data.RoleId, text: data.RoleName }); } else if (assignedRole.ExcludeViewReport == true) { ExcludeViewRoles.push({ id: data.RoleId, text: data.RoleName }); } } } } instance.loadReportDetails(reportid, _Permissions_ViewRoles, ExcludeViewRoles); } loadReportDetails(ReportId, _Permissions_ViewRoles, ExcludeViewRoles) { var instance = this; instance.reportManager.getReportById(ReportId).then(function (response) { var data = response.result; if (data.ViewAll == true) { $("#chkIsViewable").prop('checked', true); instance.loadViewRoles(ReportId, response.result.ChangeAll, _Permissions_ViewRoles, ExcludeViewRoles); $('#divViewRoles').hide(); } else { $("#chkIsViewable").prop('checked', false); instance.loadViewRoles(ReportId, response.result.ChangeAll, _Permissions_ViewRoles, ExcludeViewRoles); $('#divViewRoles').show(); } }); } loadViewRoles(reportid, IsMandatory, _Permissions_ViewRoles, ExcludeViewRoles) { var Ids = []; for (var i = 0; i < _Permissions_ViewRoles.length; i++) { Ids.push(_Permissions_ViewRoles[i].id); } let ExludedIds = []; for (var i = 0; i < ExcludeViewRoles.length; i++) { ExludedIds.push(ExcludeViewRoles[i].id); } 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: _Permissions_ViewRoles, 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; }, }); $("#" + ViewRoleElementId).val(Ids).trigger('change'); $('#txtIncludeViewRoles').on('select2:select', function (e) { let result = e.params.data; if (Number(result.id) != 0) { var roleId = result.id; ReportPermissions.Instance().addViewRole(reportid, roleId, true, false); Ids.push(roleId); $(ExludedIds).each(function (i, value) { if (value == roleId) { var index = ExludedIds.indexOf(value); if (index > -1) { ExludedIds.splice(index, 1); } ExludedIds.splice(value, 1); jQuery("#txtExcludeViewRoles").val(ExludedIds).trigger('change'); return false; } }); } }); $('#txtIncludeViewRoles').on('select2:unselect', function (e) { let result = e.params.data; if (Number(result.id) != 0) { var roleId = result.id; ReportPermissions.Instance().removeViewRole(reportid, roleId, true, false); } }); $("#" + ExcludeRoleElementId).select2({ multiple: true, allowClear: false, data: ExcludeViewRoles, 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(ExludedIds).trigger('change'); $('.select2-search__field').css("width", "100%"); $('#txtExcludeViewRoles').on('select2:select', function (e) { let result = e.params.data; if (Number(result.id) != 0) { var roleId = result.id; ReportPermissions.Instance().addViewRole(reportid, roleId, false, true); ExludedIds.push(roleId); $(Ids).each(function (i, value) { if (value == roleId) { var index = Ids.indexOf(value); if (index > -1) { Ids.splice(index, 1); } jQuery("#txtIncludeViewRoles").val(Ids).trigger('change'); return false; } }); } }); $('#txtExcludeViewRoles').on('select2:unselect', function (e) { let result = e.params.data; if (Number(result.id) != 0) { var roleId = result.id; ReportPermissions.Instance().removeViewRole(reportid, roleId, false, true); } }); } addViewRole(reportId, roleId, IsView, IsExclude) { var instance = this; var _fileCacheHelper = this.fileCacheHelper; let reqObj = new Unibase.Platform.Analytics.Requests.ReportRole(); reqObj.ReportId = reportId; reqObj.RoleId = Number(roleId); reqObj.ViewReport = IsView; reqObj.ExcludeViewReport = IsExclude; instance.reportManager.addReportRole(reqObj).then(function (response) { MessageHelper.Instance().showSuccess(response.message, 'Bizgaze_ValidationSummary'); }); } removeViewRole(ReportId, roleId, IsView, IsExclude) { var instance = this; let reqObj = new Unibase.Platform.Analytics.Requests.ReportRole(); reqObj.ReportId = ReportId; reqObj.RoleId = Number(roleId); reqObj.ViewReport = IsView; reqObj.ExcludeViewReport = IsExclude; instance.reportManager.removeReportRole(reqObj).then(function (response) { MessageHelper.Instance().showSuccess(response.message, 'Bizgaze_ValidationSummary'); }); } setViewable() { var instance = this; var viewable = $("#chkIsViewable").prop('checked'); if (viewable) $('#divViewRoles').hide(); else $('#divViewRoles').show(); instance.reportManager.setViewable(instance.Reportspermission_reportid, viewable).then(function (response) { MessageHelper.Instance().showSuccess(response.message, 'Bizgaze_ValidationSummary'); }); } static Instance() { if (this.rp_instance === undefined) { this.rp_instance = new ReportPermissions(); } return this.rp_instance; } } Components.ReportPermissions = ReportPermissions; })(Components = Analytics.Components || (Analytics.Components = {})); })(Analytics = Platform.Analytics || (Platform.Analytics = {})); })(Platform = Unibase.Platform || (Unibase.Platform = {})); })(Unibase || (Unibase = {}));