From: Galen Charlton Date: Fri, 29 Jun 2018 18:45:27 +0000 (-0400) Subject: first pass at XUL report template cloning X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=refs%2Fheads%2Fuser%2Fgmcharlt%2Fxul-report-cloning;p=working%2FEvergreen.git first pass at XUL report template cloning Signed-off-by: Galen Charlton --- diff --git a/Open-ILS/web/js/ui/default/staff/reporter/template/app.js b/Open-ILS/web/js/ui/default/staff/reporter/template/app.js index b50dabc021..ecdc38a8ef 100644 --- a/Open-ILS/web/js/ui/default/staff/reporter/template/app.js +++ b/Open-ILS/web/js/ui/default/staff/reporter/template/app.js @@ -257,29 +257,128 @@ function($scope , $q , $routeParams , $location , $timeout , $window, egCore , } + function upgradeTemplate(template) { + template.name(template.name() + ' (converted from XUL)'); // FIXME I18N + template.data.version = 5; + + var order_by; + var rels = []; + for (var key in template.data.rel_cache) { + if (key == 'order_by') { + order_by = template.data.rel_cache[key]; + } else { + rels.push(template.data.rel_cache[key]); + } + } + + template.data['display_cols'] = []; + template.data['filter_cols'] = []; + + var dispcol_index = 0; + + function _convertPath(orig, rel) { + var newPath = []; + + var table_path = rel.path.split(/\./); + if (table_path.length > 1 || rel.path.indexOf('-') > -1) table_path.push( rel.idlclass ); + + var prev_type = ''; + var prev_link = ''; + table_path.forEach(function(link) { + var cls = link.split(/-/)[0]; + var fld = link.split(/-/)[1]; + var args = { + label : egCore.idl.classes[cls].label + } + if (prev_link != '') { + args['from'] = prev_link.split(/-/)[0]; + var prev_col = prev_link.split(/-/)[1].split(/>/)[0]; + egCore.idl.classes[prev_link.split(/-/)[0]].fields.forEach(function(f) { + if (prev_col == f.name) { + args['link'] = f; + } + }); + } + newPath.push(egCore.idl.classTree.buildNode(cls, args)); + prev_link = link; + }); + return newPath; + + } + + rels.map(function(rel) { + for (var col in rel.fields.dis_tab) { + var orig = rel.fields.dis_tab[col]; + var display_col = { + name : orig.colname, + path : _convertPath(orig, rel), + index : dispcol_index++, // FIXME + label : orig.alias, + datatype : orig.datatype, + doc_text : orig.field_doc, + transform : { + label : orig.transform_label, + transform : orig.transform, + aggregate : orig.aggregate + }, + path_label : rel.label + }; + template.data.display_cols.push(display_col); + } + }); + + rels.map(function(rel) { + for (var col in rel.fields.filter_tab) { + var orig = rel.fields.filter_tab[col]; + var filter_col = { + name : orig.colname, + path : _convertPath(orig, rel), + index : dispcol_index++, // FIXME + label : orig.alias, + datatype : orig.datatype, + doc_text : orig.field_doc, + operator : { + op : orig.op, + label : orig.op_label + }, + transform : { + label : orig.transform_label, + transform : orig.transform, + aggregate : orig.aggregate + }, + path_label : rel.label + }; + if ('value' in orig.op_value) { + filter_col['value'] = orig.op_value.value; + } + template.data.filter_cols.push(filter_col); + } + }); + + } + function loadTemplate () { if (!template_id) return; egCore.pcrud.retrieve( 'rt', template_id) .then( function(template) { template.data = angular.fromJson(template.data()); - if (template.data.version < 5) { // redirect to old editor... - $window.location.href = egCore.env.basePath + 'reporter/legacy/template/clone/'+folder_id + '/' + template_id; - // } else if (template.data.version < 5) { // redirect to old editor... - } else { - $scope.templateName = template.name() + ' (clone)'; - $scope.templateDescription = template.description(); - $scope.templateDocURL = template.data.doc_url; + if (template.data.version < 5) { + upgradeTemplate(template); + } - $scope.changeCoreSource( template.data.core_class ); + $scope.templateName = template.name() + ' (clone)'; + $scope.templateDescription = template.description(); + $scope.templateDocURL = template.data.doc_url; - egReportTemplateSvc.display_fields = template.data.display_cols; - egReportTemplateSvc.filter_fields = template.data.filter_cols; + $scope.changeCoreSource( template.data.core_class ); - $timeout(function(){ - dgrid.refresh(); - fgrid.refresh(); - }); - } + egReportTemplateSvc.display_fields = template.data.display_cols; + egReportTemplateSvc.filter_fields = template.data.filter_cols; + + $timeout(function(){ + dgrid.refresh(); + fgrid.refresh(); + }); }); } diff --git a/Open-ILS/web/reports/oils_rpt_folder_window.js b/Open-ILS/web/reports/oils_rpt_folder_window.js index d1ba641179..488cba6222 100644 --- a/Open-ILS/web/reports/oils_rpt_folder_window.js +++ b/Open-ILS/web/reports/oils_rpt_folder_window.js @@ -3,7 +3,6 @@ dojo.requireLocalization("openils.reports", "reports"); var rpt_strings = dojo.i18n.getLocalization("openils.reports", "reports"); var NG_NEW_TEMPLATE_INTERFACE = '/eg/staff/reporter/template/new'; var NG_CLONE_TEMPLATE_INTERFACE = '/eg/staff/reporter/template/clone'; -var NG_CLONE_LEGACY_TEMPLATE_INTERFACE = '/eg/staff/reporter/legacy/template/clone'; var OILS_TEMPLATE_INTERFACE = 'xul/template_builder.xul'; var OILS_LEGACY_TEMPLATE_INTERFACE = 'oils_rpt_builder.xhtml'; @@ -338,14 +337,14 @@ oilsRptFolderWindow.prototype.cloneTemplate = function(template) { window.top.location.href = NG_CLONE_TEMPLATE_INTERFACE+'/'+folderid+'/'+template.id(); } else if(version && version >= 2) { if (window.IAMBROWSER) { - window.top.location.href = NG_CLONE_LEGACY_TEMPLATE_INTERFACE+'/'+folderid+'/'+template.id(); + window.top.location.href = NG_CLONE_TEMPLATE_INTERFACE+'/'+folderid+'/'+template.id(); } else { _debug('entering new template building interface with template version ' + version); goTo(OILS_TEMPLATE_INTERFACE+s+'&folder='+folderid+'&ct='+template.id()); } } else { if (window.IAMBROWSER) { - window.top.location.href = NG_CLONE_LEGACY_TEMPLATE_INTERFACE+'/'+folderid+'/'+template.id(); + window.top.location.href = NG_CLONE_TEMPLATE_INTERFACE+'/'+folderid+'/'+template.id(); } else { goTo(OILS_LEGACY_TEMPLATE_INTERFACE+s+'&folder='+folderid+'&ct='+template.id()); }