Skip to content
Snippets Groups Projects
Commit 93c4415b authored by Jaden Diefenbaugh's avatar Jaden Diefenbaugh
Browse files

finish adding groups to report API, now saving/loading appropriately

parent b187fb6b
No related branches found
No related tags found
1 merge request!223Reports overhaul
...@@ -24,8 +24,6 @@ angular.module('reportApp').controller('GroupsController', ['$scope', 'ReportSer ...@@ -24,8 +24,6 @@ angular.module('reportApp').controller('GroupsController', ['$scope', 'ReportSer
let vm = this; let vm = this;
// testing stuffs // testing stuffs
ReportService.createGroup('great');
ReportService.addExperimentToGroup('exp1', 'great');
vm.test = 'test'; vm.test = 'test';
vm.report = $scope.report; vm.report = $scope.report;
......
...@@ -98,6 +98,9 @@ angular.module('reportApp').controller('reportController',['$scope', 'reportFact ...@@ -98,6 +98,9 @@ angular.module('reportApp').controller('reportController',['$scope', 'reportFact
if($scope.report.content.alias_experiments != undefined){ if($scope.report.content.alias_experiments != undefined){
mutateSave($scope.report_experiments_alias, $scope.report.content.alias_experiments); mutateSave($scope.report_experiments_alias, $scope.report.content.alias_experiments);
} }
// save groups data to the model
ReportService.loadGroups($scope.report.content.groups);
} }
function getReportData(user, report_id){ function getReportData(user, report_id){
......
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
*/ */
//Directive for opening smart_selector list on "Add a report item" button click that displays options //Directive for opening smart_selector list on "Add a report item" button click that displays options
angular.module('reportApp').directive("savereportitems", function($compile){ angular.module('reportApp').directive("savereportitems", ['$compile', 'ReportService', function($compile, ReportService){
return function(scope, element, attrs){ return function(scope, element, attrs){
//add new report item //add new report item
element.bind("click", function(){ element.bind("click", function(){
...@@ -57,6 +57,10 @@ angular.module('reportApp').directive("savereportitems", function($compile){ ...@@ -57,6 +57,10 @@ angular.module('reportApp').directive("savereportitems", function($compile){
savecontent["sorted_tables_keys_reverse"] = scope.sorted_experiments_keys_reverse; savecontent["sorted_tables_keys_reverse"] = scope.sorted_experiments_keys_reverse;
savecontent["sorted_tables_sortkey"] = scope.sorted_experiments_keys_tables_sortkey; savecontent["sorted_tables_sortkey"] = scope.sorted_experiments_keys_tables_sortkey;
} }
// save group data
savecontent['groups'] = ReportService.serializeGroups();
//call set report content from factory //call set report content from factory
let mydict = {}; let mydict = {};
mydict["experiments"] = scope.report.experiments; mydict["experiments"] = scope.report.experiments;
...@@ -84,6 +88,6 @@ angular.module('reportApp').directive("savereportitems", function($compile){ ...@@ -84,6 +88,6 @@ angular.module('reportApp').directive("savereportitems", function($compile){
} }
}; };
}); }]);
...@@ -69,6 +69,17 @@ angular.module('reportApp').factory('ReportService', ['$http', function($http){ ...@@ -69,6 +69,17 @@ angular.module('reportApp').factory('ReportService', ['$http', function($http){
// gets groups // gets groups
reportServiceInstance.groups = groupData; reportServiceInstance.groups = groupData;
// serializes groups as an object with form:
// {
// <group name 1>: <array of exp names for group 1>,
// ...
// }
reportServiceInstance.serializeGroups = () => {
return groupData
.map(g => { return { [g.name]: g.experiments }; })
.reduce((o, g) => Object.assign(o, g), {});
};
// create a new group for the report // create a new group for the report
// returns false if it already exists // returns false if it already exists
// returns true if it adds a new group // returns true if it adds a new group
...@@ -93,9 +104,20 @@ angular.module('reportApp').factory('ReportService', ['$http', function($http){ ...@@ -93,9 +104,20 @@ angular.module('reportApp').factory('ReportService', ['$http', function($http){
} }
}; };
// fetch group info from the api // load group info from the serialized format:
reportServiceInstance.fetchGroups = (reportName) => { // {
console.warn(`not implemented: reportServiceInstance.fetchGroups(${JSON.stringify(reportName)})`); // <group name 1>: <array of exp names for group 1>,
// ...
// }
reportServiceInstance.loadGroups = (data) => {
// wipe data and load groups
groupData.splice(0, groupData.length);
Object.entries(data)
.forEach(([groupName, expNames]) => {
let g = new Group(groupName);
expNames.forEach(n => g.addExperiment(n));
groupData.push(g);
});
}; };
// save group info via sending to server // save group info via sending to server
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment