diff --git a/beat/web/reports/static/reports/app/controllers/groupsController.js b/beat/web/reports/static/reports/app/controllers/groupsController.js index c8fa6f3bc16da01d78902ad5e6c498a75bc54801..2a3a587809b8d3e535f9f6550a9ecbbbdc9a0b59 100644 --- a/beat/web/reports/static/reports/app/controllers/groupsController.js +++ b/beat/web/reports/static/reports/app/controllers/groupsController.js @@ -20,7 +20,7 @@ * with the BEAT platform. If not, see http://www.gnu.org/licenses/. */ // this controller handles the 'groups' partial, where groups of experiments are managed -angular.module('reportApp').controller('GroupsController', ['$scope', 'ReportService', function ($scope, ReportService){ +angular.module('reportApp').controller('GroupsController', ['$scope', 'GroupsService', function ($scope, GroupsService){ let vm = this; // testing stuffs @@ -34,20 +34,20 @@ angular.module('reportApp').controller('GroupsController', ['$scope', 'ReportSer return analyzer_block.algorithm; }; - // ReportService stuff to be used directly in ui - vm.groups = ReportService.groups; - vm.removeExperimentFromGroup = ReportService.removeExperimentFromGroup; + // GroupsService stuff to be used directly in ui + vm.groups = GroupsService.groups; + vm.removeExperimentFromGroup = GroupsService.removeExperimentFromGroup; vm.addExperimentToGroup = (expName, groupName) => { let analyzer = getAnalyzerFromExpName(expName); - ReportService.addExperimentToGroup(expName, groupName); - ReportService.groups.find(g => g.name === groupName).analyzer = analyzer; + GroupsService.addExperimentToGroup(expName, groupName); + GroupsService.groups.find(g => g.name === groupName).analyzer = analyzer; }; vm.createGroup = function(name) { - ReportService.createGroup(name); + GroupsService.createGroup(name); vm.newGroupName = ''; }; - vm.deleteGroup = ReportService.deleteGroup; + vm.deleteGroup = GroupsService.deleteGroup; // createGroup input val vm.newGroupName = ''; @@ -67,13 +67,13 @@ angular.module('reportApp').controller('GroupsController', ['$scope', 'ReportSer // a group panel's classes // one panel is the active group ('panel-success') vm.classArr = (groupName) => { - let a = ['panel', groupName === ReportService.activeGroup ? 'panel-success' : 'panel-default']; + let a = ['panel', groupName === GroupsService.activeGroup ? 'panel-success' : 'panel-default']; return a; }; // set active group vm.setActiveGroup = (groupName) => { - ReportService.activeGroup = groupName; + GroupsService.activeGroup = groupName; }; console.log(vm); diff --git a/beat/web/reports/static/reports/app/controllers/reportController.js b/beat/web/reports/static/reports/app/controllers/reportController.js index ec53e858913313499dff7400aec87df8f525081f..1187c3c6da6eb5a83b31f32bf672b1cf92ca5d0a 100644 --- a/beat/web/reports/static/reports/app/controllers/reportController.js +++ b/beat/web/reports/static/reports/app/controllers/reportController.js @@ -21,7 +21,7 @@ */ //This controller retrieves data from the reportFactory/experimentFactory through the REST API and associates it with the $scope //The $scope is ultimately bound to the report view -angular.module('reportApp').controller('reportController',['$scope', 'reportFactory', 'experimentFactory', 'plotterFactory', 'dataFactory', '$q', 'ReportService', function ($scope, reportFactory, experimentFactory, plotterFactory, dataFactory, $q, ReportService){ +angular.module('reportApp').controller('reportController',['$scope', 'reportFactory', 'experimentFactory', 'plotterFactory', 'dataFactory', '$q', 'GroupsService', function ($scope, reportFactory, experimentFactory, plotterFactory, dataFactory, $q, GroupsService){ $scope.q = $q; $scope.user; $scope.report_id; @@ -100,7 +100,7 @@ angular.module('reportApp').controller('reportController',['$scope', 'reportFact } // save groups data to the model - ReportService.loadGroups($scope.report.content.groups); + GroupsService.loadGroups($scope.report.content.groups); } function getReportData(user, report_id){ diff --git a/beat/web/reports/static/reports/app/directives/addReportItem.js b/beat/web/reports/static/reports/app/directives/addReportItem.js index e4f0aac57d7426d579d403dffdee0a5b8065efb6..b21c31b1f27638f76caf445d3e5292a947795e43 100644 --- a/beat/web/reports/static/reports/app/directives/addReportItem.js +++ b/beat/web/reports/static/reports/app/directives/addReportItem.js @@ -21,8 +21,9 @@ */ //Directive for opening smart_selector list on "Add a report item" button click that displays options -angular.module('reportApp').directive("addreportitem", ['$compile', 'ReportService', function($compile, ReportService){ +angular.module('reportApp').directive("addreportitem", ['$compile', 'GroupsService', function($compile, GroupsService){ return function(scope, element, attrs){ + console.log(scope); scope.$on("addSavedElement", function(event, id_content, type){ let num_tables_in_content = 0; let num_figures_in_content = 0; @@ -342,9 +343,9 @@ angular.module('reportApp').directive("addreportitem", ['$compile', 'ReportServi }); // get the possible plot data - let possiblePlots = ReportService + let possiblePlots = GroupsService // only look at plots from exps in active group - .getGroupExperiments(ReportService.activeGroup) + .getGroupExperiments(GroupsService.activeGroup) // get the obj with the exp's possible plots .map(expName => Object.entries(scope.report.all_experiments[expName].results.analysis) .filter(([res_name, obj]) => res_name !== 'out_data') @@ -363,7 +364,7 @@ angular.module('reportApp').directive("addreportitem", ['$compile', 'ReportServi console.log(v); let plotTypeCount = a.filter(o => o.description === v.description).length; // if every exp couldnt do this plot, dont keep it - if(plotTypeCount < ReportService.getGroupExperiments(ReportService.activeGroup).length){ + if(plotTypeCount < GroupsService.getGroupExperiments(GroupsService.activeGroup).length){ console.log(`break less than`); return aKeep; } @@ -581,12 +582,12 @@ angular.module('reportApp').directive("addreportitem", ['$compile', 'ReportServi let alias_experiments = []; let reportItemGroupExps; - let existGroup = ReportService.getReportItemGroup(container.id); + let existGroup = GroupsService.getReportItemGroup(container.id); if(existGroup){ reportItemGroupExps = existGroup.experiments; } else { - ReportService.addReportItemToGroup(container.id, ReportService.activeGroup); - reportItemGroupExps = ReportService.getReportItemGroup(container.id).experiments; + GroupsService.addReportItemToGroup(container.id, GroupsService.activeGroup); + reportItemGroupExps = GroupsService.getReportItemGroup(container.id).experiments; } for(let i = 0; i < scope.report.experiments.length; i++){ diff --git a/beat/web/reports/static/reports/app/directives/saveReportItems.js b/beat/web/reports/static/reports/app/directives/saveReportItems.js index 50b5ae9579bed212a05bdc1ba5234bb9ad85c970..cc7c4b1cd69ec6fde1dbf2b216ba875a936d40e3 100644 --- a/beat/web/reports/static/reports/app/directives/saveReportItems.js +++ b/beat/web/reports/static/reports/app/directives/saveReportItems.js @@ -21,7 +21,7 @@ */ //Directive for opening smart_selector list on "Add a report item" button click that displays options -angular.module('reportApp').directive("savereportitems", ['$compile', 'ReportService', function($compile, ReportService){ +angular.module('reportApp').directive("savereportitems", ['$compile', 'GroupsService', function($compile, GroupsService){ return function(scope, element, attrs){ //add new report item element.bind("click", function(){ @@ -59,7 +59,7 @@ angular.module('reportApp').directive("savereportitems", ['$compile', 'ReportSer } // save group data - savecontent['groups'] = ReportService.serializeGroups(); + savecontent['groups'] = GroupsService.serializeGroups(); //call set report content from factory let mydict = {}; diff --git a/beat/web/reports/static/reports/app/services/reportService.js b/beat/web/reports/static/reports/app/services/groupsService.js similarity index 83% rename from beat/web/reports/static/reports/app/services/reportService.js rename to beat/web/reports/static/reports/app/services/groupsService.js index 668c2a4d20bdce70868b80ba9bba111e318b77d4..c10caa27654b7dc4a630a97546a3b5644ed8dabc 100644 --- a/beat/web/reports/static/reports/app/services/reportService.js +++ b/beat/web/reports/static/reports/app/services/groupsService.js @@ -21,13 +21,13 @@ */ /* - * ReportService + * GroupsService * Desc: * The datastore for the reports app, including data fetched from the * server and cross-component app state */ -angular.module('reportApp').factory('ReportService', ['$http', function($http){ - let reportServiceInstance = {}; +angular.module('reportApp').factory('GroupsService', ['$http', function($http){ + let groupsServiceInstance = {}; // experiments of reports are in arbitrary groups, // in a many-to-many relationship let groupData = []; @@ -89,16 +89,16 @@ angular.module('reportApp').factory('ReportService', ['$http', function($http){ }; // gets groups - reportServiceInstance.groups = groupData; + groupsServiceInstance.groups = groupData; // TODO: move this hacky state to the addReportItem miniwindows - reportServiceInstance.activeGroup = ''; + groupsServiceInstance.activeGroup = ''; // serializes groups as an object with form: // { // <group name 1>: { experiments: [], reportItemIds: [], analyzer: '' }, // ... // } - reportServiceInstance.serializeGroups = () => { + groupsServiceInstance.serializeGroups = () => { return groupData .map(g => { return { [g.name]: { @@ -114,7 +114,7 @@ angular.module('reportApp').factory('ReportService', ['$http', function($http){ // create a new group for the report // returns false if it already exists // returns the newly added group if successful - reportServiceInstance.createGroup = (name) => { + groupsServiceInstance.createGroup = (name) => { if(typeof name !== 'string'){ throw new Error(`new group name is not a string: ${JSON.stringify(name)}`); } @@ -127,12 +127,12 @@ angular.module('reportApp').factory('ReportService', ['$http', function($http){ groupData.push(g); // change active group to newest group by default - reportServiceInstance.activeGroup = g.name; + groupsServiceInstance.activeGroup = g.name; return g; }; // delete a group - reportServiceInstance.deleteGroup = (name) => { + groupsServiceInstance.deleteGroup = (name) => { let idx = groupData.indexOf(groupData.find(g => g.name === name)); if (idx > -1) { groupData.splice(idx, 1); @@ -144,13 +144,13 @@ angular.module('reportApp').factory('ReportService', ['$http', function($http){ // <group name 1>: { experiments: [], reportItemIds: [], analyzer: '' }, // ... // } - reportServiceInstance.loadGroups = (data) => { + groupsServiceInstance.loadGroups = (data) => { // wipe data and load groups groupData.splice(0, groupData.length); // if there's no group data, create a default one if(!data || Object.keys(data).length === 0){ - reportServiceInstance.createGroup('default'); + groupsServiceInstance.createGroup('default'); return; } @@ -158,7 +158,7 @@ angular.module('reportApp').factory('ReportService', ['$http', function($http){ // sometimes we get an empty string for name for some reason .filter(([groupName, gData]) => groupName.length > 0) .forEach(([groupName, gData]) => { - let g = reportServiceInstance.createGroup(groupName); + let g = groupsServiceInstance.createGroup(groupName); g.analyzer = gData.analyzer; gData.experiments.forEach(n => g.addExperiment(n)); gData.reportItemIds.forEach(id => g.addReportItem(id)); @@ -166,12 +166,12 @@ angular.module('reportApp').factory('ReportService', ['$http', function($http){ }; // save group info via sending to server - reportServiceInstance.saveGroups = () => { - console.warn(`not implemented: reportServiceInstance.saveGroups`); + groupsServiceInstance.saveGroups = () => { + console.warn(`not implemented: groupsServiceInstance.saveGroups`); }; // add experiment to group - reportServiceInstance.addExperimentToGroup = (expName, groupName, analyzer) => { + groupsServiceInstance.addExperimentToGroup = (expName, groupName, analyzer) => { checkForGroup(groupName); let group = groupData.find(g => g.name === groupName); @@ -179,26 +179,26 @@ angular.module('reportApp').factory('ReportService', ['$http', function($http){ }; // rm experiment from group - reportServiceInstance.removeExperimentFromGroup = (expName, groupName) => { + groupsServiceInstance.removeExperimentFromGroup = (expName, groupName) => { checkForGroup(groupName); let group = groupData.find(g => g.name === groupName); return group.removeExperiment(expName); }; // gets experiments from a group - reportServiceInstance.getGroupExperiments = (groupName) => { + groupsServiceInstance.getGroupExperiments = (groupName) => { checkForGroup(groupName); let group = groupData.find(g => g.name === groupName); return group.experiments; }; // gets groups for an experiment - reportServiceInstance.getExperimentGroups = (expName) => { + groupsServiceInstance.getExperimentGroups = (expName) => { return groupData.filter(g => g.experiments.includes(expName)).map(g => g.name); }; // add report item to group - reportServiceInstance.addReportItemToGroup = (id, groupName) => { + groupsServiceInstance.addReportItemToGroup = (id, groupName) => { checkForGroup(groupName); let group = groupData.find(g => g.name === groupName); @@ -206,14 +206,14 @@ angular.module('reportApp').factory('ReportService', ['$http', function($http){ }; // rm report item id from group - reportServiceInstance.removeReportItemFromGroup = (id, groupName) => { + groupsServiceInstance.removeReportItemFromGroup = (id, groupName) => { checkForGroup(groupName); let group = groupData.find(g => g.name === groupName); return group.removeReportItem(id); }; // gets group for a report item's id - reportServiceInstance.getReportItemGroup = (id) => { + groupsServiceInstance.getReportItemGroup = (id) => { return groupData.find(g => g.reportItemIds.includes(id)); }; @@ -224,5 +224,5 @@ angular.module('reportApp').factory('ReportService', ['$http', function($http){ } } - return reportServiceInstance; + return groupsServiceInstance; }]); diff --git a/beat/web/reports/templates/reports/report.html b/beat/web/reports/templates/reports/report.html index 1fad65da6482b593117cf4271b15dbbb7ebf7a81..6a38aa008d47f0bfcb50cebf51479f27c0ebdda9 100644 --- a/beat/web/reports/templates/reports/report.html +++ b/beat/web/reports/templates/reports/report.html @@ -82,7 +82,7 @@ <script src="{% fingerprint "reports/app/factories/dataFactory.js" %}" type="text/javascript" charset="utf-8"></script> <!-- services --> - <script src="{% fingerprint "reports/app/services/reportService.js" %}" type="text/javascript" charset="utf-8"></script> + <script src="{% fingerprint "reports/app/services/groupsService.js" %}" type="text/javascript" charset="utf-8"></script> <!-- directives -->