Skip to content

Commit fdfdf8d

Browse files
committed
Allow admin to set DataBrowser default report
1 parent 4b2d7f9 commit fdfdf8d

File tree

4 files changed

+87
-13
lines changed

4 files changed

+87
-13
lines changed

laboratory/api-src/org/labkey/api/laboratory/TabbedReportItem.java

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ public class TabbedReportItem extends AbstractNavItem
4646
private final Map<String, FieldKey> _additionalKeys = new HashMap<>();
4747

4848
public static final String OVERRIDES_PROP_KEY = "laboratory.tabItemOverride";
49-
public static final String FILTER_PROP_KEY = "laboratory.tabItemFilterOverride";
5049

5150
protected static final Logger _log = LogManager.getLogger(TabbedReportItem.class);
5251

@@ -177,6 +176,23 @@ public static String getOverridesPropertyKey(NavItem item)
177176
return item.getDataProvider().getKey() + "||tabReport||" + item.getReportCategory() + "||" + item.getName() + "||" + item.getLabel();
178177
}
179178

179+
public boolean hasOverride(Container c, String propName)
180+
{
181+
Map<String, String> map = PropertyManager.getProperties(c, OVERRIDES_PROP_KEY);
182+
if (!map.containsKey(getPropertyManagerKey()))
183+
{
184+
return false;
185+
}
186+
187+
JSONObject props = new JSONObject(map.get(getPropertyManagerKey()));
188+
if (!props.has(propName))
189+
{
190+
return false;
191+
}
192+
193+
return true;
194+
}
195+
180196
public static void applyOverrides(NavItem item, Container c, JSONObject json)
181197
{
182198
Map<String, String> map = PropertyManager.getProperties(c, OVERRIDES_PROP_KEY);
@@ -188,9 +204,9 @@ public static void applyOverrides(NavItem item, Container c, JSONObject json)
188204

189205
if (props.has("reportCategory"))
190206
json.put("reportCategory", props.get("reportCategory"));
191-
// retained for settings saved prior to refactor
192-
else if (props.has("category"))
193-
json.put("reportCategory", props.get("category"));
207+
208+
if (props.has("isDefaultReport"))
209+
json.put("isDefaultReport", props.get("isDefaultReport"));
194210
}
195211
}
196212
}

laboratory/resources/web/laboratory/panel/CustomizeDataBrowserPanel.js

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@ Ext4.define('Laboratory.panel.CustomizeDataBrowserPanel', {
6969
},{
7070
html: '<b>Visible?</b>',
7171
style: 'padding-bottom: 5px;margin-left: 5px;'
72+
},{
73+
html: '<b>Default Report?</b>',
74+
style: 'padding-bottom: 5px;margin-left: 5px;'
7275
}];
7376

7477
items = LDK.Utils.sortByProperty(items, 'name', false);
@@ -90,17 +93,22 @@ Ext4.define('Laboratory.panel.CustomizeDataBrowserPanel', {
9093
width: 300,
9194
value: item.label
9295
},{
93-
xtype: 'displayfield',
94-
value: item.visible,
96+
xtype: 'checkbox',
97+
checked: item.visible,
9598
style: 'margin-left: 15px;'
99+
},{
100+
xtype: 'radio',
101+
name: 'isDefaultReport',
102+
inputValue: true,
103+
checked: item.isDefaultReport
96104
}]);
97105
}, this);
98106

99107
var cfg = {
100108
itemId: 'theTable',
101109
layout: {
102110
type: 'table',
103-
columns: 4
111+
columns: 5
104112
},
105113
border: false,
106114
defaults: {
@@ -117,15 +125,17 @@ Ext4.define('Laboratory.panel.CustomizeDataBrowserPanel', {
117125
doSave: function(btn){
118126
var toSave = {};
119127
var items = btn.up('form').down('#theTable').items;
120-
var cols = 4;
128+
var cols = 5;
121129
var rows = (items.getCount() / cols);
122130

123131
for (var i=1;i<rows;i++){
124132
var base = i * cols;
125133
var navItem = items.get(base).navItem;
126134
toSave[navItem.overridesKey] = {
135+
reportCategory: items.get(base + 1).getValue(),
127136
label: items.get(base + 2).getValue(),
128-
reportCategory: items.get(base + 1).getValue()
137+
isVisible: items.get(base + 3).getValue(),
138+
isDefaultReport: items.get(base + 4).getValue()
129139
}
130140
}
131141

laboratory/resources/web/laboratory/panel/DataBrowserPanel.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ Ext4.define('Laboratory.panel.DataBrowserPanel', {
55
Ext4.ns('Laboratory.tabbedReports');
66

77
Ext4.apply(this, {
8-
//defaultReport: 'abstract',
98
reportNamespace: Laboratory.tabbedReports
109
});
1110

@@ -23,6 +22,7 @@ Ext4.define('Laboratory.panel.DataBrowserPanel', {
2322
onDataLoad: function(results){
2423
Ext4.Msg.hide();
2524
this.reports = [];
25+
var foundDefault = false;
2626
Ext4.each(results.tabbedReports, function(report){
2727
LDK.Assert.assertNotEmpty('Tabbed Report is null', report);
2828
if (report && report.key){
@@ -33,6 +33,16 @@ Ext4.define('Laboratory.panel.DataBrowserPanel', {
3333
report.containerPath = report.targetContainer;
3434
}
3535
this.reports.push(report);
36+
37+
if (report.isDefaultReport) {
38+
this.defaultReport = report.id;
39+
if (foundDefault) {
40+
log.error('More than one TabbedReport marked as default!');
41+
}
42+
43+
foundDefault = true;
44+
console.log(this.defaultReport);
45+
}
3646
}
3747
}, this);
3848

laboratory/src/org/labkey/laboratory/LaboratoryController.java

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1658,6 +1658,8 @@ public ApiResponse execute(JsonDataForm form, BindException errors)
16581658
Map<String, Object> results = new HashMap<>();
16591659

16601660
WritablePropertyMap propMap = PropertyManager.getWritableProperties(getContainer(), TabbedReportItem.OVERRIDES_PROP_KEY, true);
1661+
WritablePropertyMap visibilityMap = PropertyManager.getWritableProperties(getContainer(), NavItem.PROPERTY_CATEGORY, true);
1662+
boolean shouldSaveVisibility = false;
16611663

16621664
List<TabbedReportItem> tabbedReports = LaboratoryService.get().getTabbedReportItems(getContainer(), getUser());
16631665
Map<String, TabbedReportItem> reportMap = new HashMap<String, TabbedReportItem>();
@@ -1669,7 +1671,7 @@ public ApiResponse execute(JsonDataForm form, BindException errors)
16691671
JSONObject json = new JSONObject(form.getJsonData());
16701672
for (String key : json.keySet())
16711673
{
1672-
JSONObject toSave= new JSONObject();
1674+
JSONObject toSave = new JSONObject();
16731675

16741676
TabbedReportItem ti = reportMap.get(key);
16751677
if (ti == null)
@@ -1685,13 +1687,49 @@ public ApiResponse execute(JsonDataForm form, BindException errors)
16851687
if (reportCategory != null && !ti.getReportCategory().equals(reportCategory))
16861688
toSave.put("reportCategory", reportCategory);
16871689

1688-
if (toSave.keySet().size() > 0)
1690+
String isDefaultReport = StringUtils.trimToNull(props.optString("isDefaultReport"));
1691+
if (isDefaultReport != null)
1692+
{
1693+
if (!ti.hasOverride(getContainer(), "isDefaultReport"))
1694+
{
1695+
if ("true".equals(isDefaultReport))
1696+
{
1697+
toSave.put("isDefaultReport", isDefaultReport);
1698+
}
1699+
}
1700+
else
1701+
{
1702+
toSave.put("isDefaultReport", isDefaultReport);
1703+
}
1704+
}
1705+
1706+
String isVisible = StringUtils.trimToNull(props.optString("isVisible"));
1707+
if (isVisible != null)
1708+
{
1709+
if (!isVisible.equals(visibilityMap.get(ti.getPropertyManagerKey())))
1710+
{
1711+
visibilityMap.put(ti.getPropertyManagerKey(), isVisible);
1712+
shouldSaveVisibility = true;
1713+
}
1714+
}
1715+
1716+
if (!toSave.isEmpty())
1717+
{
16891718
propMap.put(key, toSave.toString());
1690-
else propMap.remove(key);
1719+
}
1720+
else
1721+
{
1722+
propMap.remove(key);
1723+
}
16911724
}
16921725

16931726
propMap.save();
16941727

1728+
if (shouldSaveVisibility)
1729+
{
1730+
visibilityMap.save();
1731+
}
1732+
16951733
results.put("success", true);
16961734
return new ApiSimpleResponse(results);
16971735
}

0 commit comments

Comments
 (0)