Skip to content

Commit

Permalink
Make posibile to expend view preset list on report page (via Widget#o…
Browse files Browse the repository at this point in the history
…ptions.viewPresets)
  • Loading branch information
lahmatiy committed Jan 16, 2019
1 parent 31307c8 commit 5b6541e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
2 changes: 1 addition & 1 deletion client/pages/report.css
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@
}
.page-report .data-query-result {
margin: 1em 0 1em -40px;
overflow: hidden;
}
.page-report .view-editor-form {
margin: 0 -40px 12px;
Expand Down Expand Up @@ -158,7 +159,6 @@
padding: 2px 12px;
background: #f4f4f4;
font-size: 12px;
text-transform: capitalize;
cursor: pointer;
}
.page-report .view-editor-form .tab:first-child {
Expand Down
17 changes: 10 additions & 7 deletions client/pages/report.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ const viewModeSource = {
default: () => '{\n view: \'struct\',\n expanded: 1\n}',
custom: results => viewModeSource.default(results)
};
const viewPresets = {
table: () => '"table"'
};
const defaultViewPresets = [
{ name: 'Table', content: '"table"' }
];

function valueDescriptor(value) {
if (Array.isArray(value)) {
Expand Down Expand Up @@ -118,6 +118,9 @@ export default function(discovery) {
let currentContext;
let lastQuery = {};
let lastView = {};
const viewPresets = Array.isArray(discovery.options.viewPresets)
? defaultViewPresets.concat(discovery.options.viewPresets)
: defaultViewPresets;

function renderQueryAutocompleteItem(el, self, { entry: { value, current, type }}) {
const startChar = current[0];
Expand Down Expand Up @@ -401,17 +404,17 @@ export default function(discovery) {
class: 'tab',
'data-mode': id,
onclick: () => setViewMode(id)
}, id)
}, id.replace(/^./, fc => fc.toUpperCase())) // captitalize
)),
createElement('div', 'tabs presets', Object.keys(viewPresets).map(id =>
createElement('div', 'tabs presets', viewPresets.map(({ name, content }) =>
createElement('div', {
class: 'tab',
onclick: () =>
discovery.setPageParams({
...discovery.pageParams,
view: viewPresets[id](lastView.data)
view: content
})
}, id)
}, name || 'Untitled preset')
)),
viewSetupEl = createElement('div', {
class: 'view-editor',
Expand Down

0 comments on commit 5b6541e

Please sign in to comment.