Skip to content
This repository has been archived by the owner on Oct 26, 2019. It is now read-only.

Commit

Permalink
Merge pull request #183 from jameslmartin/no-layout
Browse files Browse the repository at this point in the history
[Issue 145] Fix notebook dashboards with no layout in metadata
  • Loading branch information
dalogsdon committed Apr 14, 2016
2 parents a120187 + f97fa6f commit 070ba8f
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 15 deletions.
8 changes: 8 additions & 0 deletions less/dashboard.less
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,21 @@ body {
img {
max-width: 100%;
height: auto;
margin-left: auto;
margin-right: auto;
}

.widget-subarea:empty {
display: none;
}
}

&.no-layout {
.dashboard-cell{
position: relative;
}
}

@media (max-width: @dashboard-width-small) {
.dashboard-cell {
position: relative;
Expand Down
8 changes: 8 additions & 0 deletions routes/renderers.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,21 @@ function _renderDashboard(req, res, next, opts) {
.then(function success(notebook) {
debug('Success loading nb');

// Check if some cell in the notebook has the dashboard metadata
var hasDashboardLayout = notebook.cells.some(function(currentCell){
return ( currentCell.hasOwnProperty('metadata') &&
currentCell.metadata.hasOwnProperty('urth') &&
currentCell.metadata.urth.hasOwnProperty('dashboard') );
});

res.status(200);
res.render('dashboard', {
title: title,
notebook: notebook,
username: req.session.username,
hideChrome: hideChrome,
supportsDeclWidgets: stats.supportsDeclWidgets,
hasDashboardLayout: hasDashboardLayout,
// need to set document.baseURI with trailing slash (i.e. "/dashboards/nb/") so
// that relative paths load correctly
baseURI: urljoin(req.originalUrl, '/')
Expand Down
42 changes: 27 additions & 15 deletions views/dashboard.handlebars
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,33 @@
</noscript>

<div id="outer-dashboard">
<div id="dashboard-container" class="invisible center-container">
{{#each notebook.cells}}
{{#if metadata.urth.dashboard.layout}}
{{#with metadata.urth.dashboard.layout}}
<div class="cell dashboard-cell {{mapCellType ../cell_type}}"
data-cell-index={{@index}}
data-x={{col}}
data-y={{row}}
data-width={{width}}
data-height={{height}}>{{{markdownContent ../cell_type ../source}}}</div>
{{/with}}
{{else}}
<div class="cell dashboard-cell hidden {{mapCellType cell_type}}" data-cell-index={{@index}}></div>
{{/if}}
{{/each}}
{{! Might need to refactor this line to better handle author mode?}}
<div id="dashboard-container" class="{{#if hasDashboardLayout}} invisible center-container{{else}}no-layout{{/if}}">
{{#if hasDashboardLayout}}
{{#each notebook.cells}}
{{#if metadata.urth.dashboard.layout}}
{{#with metadata.urth.dashboard.layout}}
<div class="cell dashboard-cell {{mapCellType ../cell_type}}"
data-cell-index={{@index}}
data-x={{col}}
data-y={{row}}
data-width={{width}}
data-height={{height}}>{{{markdownContent ../cell_type ../source}}}</div>
{{/with}}
{{! If some cell in the notebook has dashboard metadata, but another cell is missing it, then simply hide the cell }}
{{else}}
<div class="cell dashboard-cell hidden {{mapCellType cell_type}}" data-cell-index={{@index}}></div>
{{/if}}
{{/each}}
{{! Notebook has no dashboard metadata, render as normal notebook }}
{{else}}

{{#each notebook.cells}}
<div class="cell dashboard-cell {{mapCellType cell_type}}"
data-cell-index={{@index}}>
</div>
{{/each}}
{{/if}}
</div>

<div class="busy-indicator progress">
Expand Down

0 comments on commit 070ba8f

Please sign in to comment.