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

add hackish active group for choosing new report item group

parent 93c4415b
No related branches found
No related tags found
1 merge request!223Reports overhaul
...@@ -42,5 +42,17 @@ angular.module('reportApp').controller('GroupsController', ['$scope', 'ReportSer ...@@ -42,5 +42,17 @@ angular.module('reportApp').controller('GroupsController', ['$scope', 'ReportSer
// report's experiments // report's experiments
vm.experiments = $scope.report_experiments; vm.experiments = $scope.report_experiments;
// 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'];
return a;
};
// set active group
vm.setActiveGroup = (groupName) => {
ReportService.activeGroup = groupName;
};
console.log(vm); console.log(vm);
}]); }]);
...@@ -37,12 +37,18 @@ angular.module('reportApp').factory('ReportService', ['$http', function($http){ ...@@ -37,12 +37,18 @@ angular.module('reportApp').factory('ReportService', ['$http', function($http){
class Group { class Group {
constructor (name) { constructor (name) {
this._name = name; this._name = name;
this.experimentNames = new Set(); this._experimentNames = new Set();
this._reportItemIds = new Set();
} }
// get the experiment names in this group // get the experiment names in this group
get experiments () { get experiments () {
return Array.from(this.experimentNames); return Array.from(this._experimentNames);
}
// get the ids of report items that use this group
get reportItemIds () {
return Array.from(this._reportItemIds);
} }
// get the group name // get the group name
...@@ -50,24 +56,31 @@ angular.module('reportApp').factory('ReportService', ['$http', function($http){ ...@@ -50,24 +56,31 @@ angular.module('reportApp').factory('ReportService', ['$http', function($http){
return this._name; return this._name;
} }
// check if an exp is in this group
hasExperiment (expName) {
return this.experimentNames.has(expName);
}
// add an exp to this group // add an exp to this group
addExperiment (expName) { addExperiment (expName) {
return this.experimentNames.add(expName); return this._experimentNames.add(expName);
} }
// rm an exp from this group // rm an exp from this group
removeExperiment (expName) { removeExperiment (expName) {
return this.experimentNames.delete(expName); return this._experimentNames.delete(expName);
}
// add an exp to this group
addReportItem (id) {
return this._reportItemIds.add(id);
}
// rm an exp from this group
removeReportItem (id) {
return this._reportItemIds.delete(id);
} }
}; };
// gets groups // gets groups
reportServiceInstance.groups = groupData; reportServiceInstance.groups = groupData;
// TODO: move this hacky state to the addReportItem miniwindows
reportServiceInstance.activeGroup = '';
// serializes groups as an object with form: // serializes groups as an object with form:
// { // {
...@@ -82,7 +95,7 @@ angular.module('reportApp').factory('ReportService', ['$http', function($http){ ...@@ -82,7 +95,7 @@ angular.module('reportApp').factory('ReportService', ['$http', function($http){
// 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 the newly added group if successful
reportServiceInstance.createGroup = (name) => { reportServiceInstance.createGroup = (name) => {
if(typeof name !== 'string'){ if(typeof name !== 'string'){
throw new Error(`new group name is not a string: ${JSON.stringify(name)}`); throw new Error(`new group name is not a string: ${JSON.stringify(name)}`);
...@@ -92,8 +105,12 @@ angular.module('reportApp').factory('ReportService', ['$http', function($http){ ...@@ -92,8 +105,12 @@ angular.module('reportApp').factory('ReportService', ['$http', function($http){
return false; return false;
} }
groupData.push(new Group(name)); let g = new Group(name);
return true;
groupData.push(g);
// change active group to newest group by default
reportServiceInstance.activeGroup = g.name;
return g;
}; };
// delete a group // delete a group
...@@ -114,7 +131,7 @@ angular.module('reportApp').factory('ReportService', ['$http', function($http){ ...@@ -114,7 +131,7 @@ angular.module('reportApp').factory('ReportService', ['$http', function($http){
groupData.splice(0, groupData.length); groupData.splice(0, groupData.length);
Object.entries(data) Object.entries(data)
.forEach(([groupName, expNames]) => { .forEach(([groupName, expNames]) => {
let g = new Group(groupName); let g = reportServiceInstance.createGroup(groupName);
expNames.forEach(n => g.addExperiment(n)); expNames.forEach(n => g.addExperiment(n));
groupData.push(g); groupData.push(g);
}); });
...@@ -149,7 +166,12 @@ angular.module('reportApp').factory('ReportService', ['$http', function($http){ ...@@ -149,7 +166,12 @@ angular.module('reportApp').factory('ReportService', ['$http', function($http){
// gets groups for an experiment // gets groups for an experiment
reportServiceInstance.getExperimentGroups = (expName) => { reportServiceInstance.getExperimentGroups = (expName) => {
return groupData.filter(g => g.hasExperiment(expName)).map(g => g.name); return groupData.filter(g => g.experiments.includes(expName)).map(g => g.name);
};
// gets group for a report item's id
reportServiceInstance.getReportItemGroup = (id) => {
return groupData.find(g => g.reportItemIds.includes(id));
}; };
// helper to assert that a group exists // helper to assert that a group exists
......
...@@ -75,11 +75,16 @@ ...@@ -75,11 +75,16 @@
</div> </div>
</div> </div>
</div> </div>
<div ng-repeat='group in groups.groups' class='panel panel-default'> <div ng-repeat='group in groups.groups track by $index' ng-class='groups.classArr(group.name)'>
<div class='panel-heading'> <div class='panel-heading'>
<h4 class='panel-title'>{$ group.name $}</h4> <h4 class='panel-title'>{$ group.name $}</h4>
</div> </div>
<div class='panel-body'> <div class='panel-body'>
<button
class='btn btn-success'
ng-click='groups.setActiveGroup(group.name)'>
Set as Active Group
</button>
<button <button
class='btn btn-danger' class='btn btn-danger'
ng-click='groups.deleteGroup(group.name)'> ng-click='groups.deleteGroup(group.name)'>
......
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