This repository has been archived by the owner on Nov 22, 2022. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
360 additions
and
43 deletions.
There are no files selected for viewing
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
<template> | ||
<wrap | ||
v-bind="$props" | ||
v-on="$listeners" | ||
> | ||
<div | ||
v-if="processing" | ||
class="d-flex align-items-center justify-content-center h-100" | ||
> | ||
<b-spinner /> | ||
</div> | ||
|
||
<display-element | ||
v-else-if="displayElement" | ||
:display-element="displayElement" | ||
:labels="{ | ||
previous: $t('recordList.pagination.prev'), | ||
next: $t('recordList.pagination.next'), | ||
}" | ||
@update="getDataframes" | ||
/> | ||
</wrap> | ||
</template> | ||
<script> | ||
import base from '../base' | ||
import { system, reporter, NoID } from '@cortezaproject/corteza-js' | ||
import DisplayElement from './DisplayElements' | ||
export default { | ||
name: 'ReportBase', | ||
components: { | ||
DisplayElement, | ||
}, | ||
extends: base, | ||
data () { | ||
return { | ||
processing: false, | ||
report: undefined, | ||
displayElement: undefined, | ||
} | ||
}, | ||
watch: { | ||
options: { | ||
deep: true, | ||
immediate: true, | ||
handler ({ reportID = NoID }) { | ||
if (reportID !== NoID) { | ||
this.fetchReport(reportID) | ||
} | ||
}, | ||
}, | ||
}, | ||
methods: { | ||
fetchReport (reportID) { | ||
this.processing = true | ||
this.$SystemAPI.reportRead({ reportID }) | ||
.then(report => { | ||
this.report = new system.Report(report) | ||
this.getDataframes() | ||
}).catch(this.toastErrorHandler(this.$t('notification:report.fetchFailed'))) | ||
.finally(() => { | ||
this.processing = false | ||
}) | ||
}, | ||
getDataframes (definition = {}) { | ||
const { elementID } = this.options | ||
this.displayElement = undefined | ||
if (elementID) { | ||
const block = this.report.blocks.find(({ elements }) => { | ||
return elements.some(e => e.elementID === elementID) | ||
}) | ||
let element = (block.elements || []).find(e => e.elementID === elementID) | ||
if (element && element.kind !== 'Text') { | ||
element = reporter.DisplayElementMaker(element) | ||
const scenarioDefinition = this.getScenarioDefinition(element) | ||
Object.entries(definition).forEach(([key, value]) => { | ||
definition[key] = { ...value, ...scenarioDefinition[key] } | ||
}) | ||
const { dataframes: frames = [] } = element.reportDefinitions({ ...definition, ...scenarioDefinition }) | ||
if (frames.length) { | ||
this.$SystemAPI.reportRun({ frames, reportID: this.options.reportID }) | ||
.then(({ frames: dataframes = [] }) => { | ||
this.displayElement = { | ||
...element, | ||
dataframes, | ||
} | ||
}).catch((e) => { | ||
this.toastErrorHandler(this.$t('notification:report.run-failed'))(e) | ||
}) | ||
} | ||
} else { | ||
this.displayElement = element | ||
} | ||
} | ||
}, | ||
getScenarioDefinition (element) { | ||
const scenarioDefinition = {} | ||
const { scenarioID } = this.options | ||
const scenario = this.report.scenarios.find(({ label }) => scenarioID === label) | ||
// Generate filter for each load datasource | ||
if (scenario && scenario.filters) { | ||
element.options.datasources.forEach(({ name }) => { | ||
scenarioDefinition[name] = { | ||
ref: name, | ||
filter: scenario.filters[name] || {}, | ||
} | ||
}) | ||
} | ||
return scenarioDefinition | ||
}, | ||
}, | ||
} | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
<template> | ||
<b-tab :title="$t('report.label')"> | ||
<b-row> | ||
<b-col> | ||
<b-form-group | ||
:label="$t('report.label')" | ||
> | ||
<b-form-select | ||
v-model="options.reportID" | ||
:options="reportOptions" | ||
text-field="handle" | ||
value-field="reportID" | ||
/> | ||
</b-form-group> | ||
</b-col> | ||
<b-col | ||
v-if="selectedReport && scenarioOptions.length > 1" | ||
> | ||
<b-form-group | ||
:label="$t('report.scenario.label')" | ||
> | ||
<b-form-select | ||
v-model="options.scenarioID" | ||
:options="scenarioOptions" | ||
text-field="label" | ||
value-field="scenarioID" | ||
/> | ||
</b-form-group> | ||
</b-col> | ||
</b-row> | ||
|
||
<b-form-group | ||
v-if="selectedReport" | ||
:label="$t('report.element.label')" | ||
:description="$t('report.element.description')" | ||
> | ||
<b-form-select | ||
v-model="options.elementID" | ||
:options="elementOptions" | ||
text-field="name" | ||
value-field="elementID" | ||
/> | ||
</b-form-group> | ||
</b-tab> | ||
</template> | ||
<script> | ||
import base from '../base' | ||
import { NoID } from '@cortezaproject/corteza-js' | ||
export default { | ||
i18nOptions: { | ||
namespaces: 'block', | ||
}, | ||
extends: base, | ||
data () { | ||
return { | ||
reports: [], | ||
} | ||
}, | ||
computed: { | ||
reportOptions () { | ||
return [ | ||
{ reportID: NoID, handle: this.$t('general:label.none') }, | ||
...this.reports, | ||
] | ||
}, | ||
selectedReport () { | ||
const { reportID = NoID } = this.options | ||
if (reportID !== NoID) { | ||
return this.reports.find(r => r.reportID === reportID) | ||
} | ||
return undefined | ||
}, | ||
scenarioOptions () { | ||
const { scenarios = [] } = this.selectedReport || {} | ||
return [ | ||
{ scenarioID: NoID, label: this.$t('general:label.none') }, | ||
...scenarios, | ||
] | ||
}, | ||
elementOptions () { | ||
const elements = [{ elementID: NoID, name: this.$t('general:label.none') }] | ||
if (this.selectedReport) { | ||
this.selectedReport.blocks.forEach(b => { | ||
elements.push({ | ||
label: b.title || b.key, | ||
options: b.elements.map(({ elementID, name, kind }) => ({ elementID, name: name || kind })), | ||
}) | ||
}) | ||
} | ||
return elements | ||
}, | ||
}, | ||
watch: { | ||
'options.blockID' () { | ||
this.options.elementID = NoID | ||
}, | ||
}, | ||
created () { | ||
this.fetchReports() | ||
}, | ||
methods: { | ||
fetchReports () { | ||
this.$SystemAPI.reportList() | ||
.then(({ set = [] }) => { | ||
this.reports = set | ||
}) | ||
.catch(this.toastErrorHandler(this.$t('notification:report.listFetchFailed'))) | ||
}, | ||
}, | ||
} | ||
</script> |
Oops, something went wrong.