-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #373 from bozana/9666
pkp/pkp-lib#8248 COUNTER R5 TSV reports
- Loading branch information
Showing
6 changed files
with
254 additions
and
8 deletions.
There are no files selected for viewing
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
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,30 @@ | ||
<template> | ||
<h1 class="app__pageHeading"> | ||
{{ t('manager.statistics.counterR5Reports') }} | ||
</h1> | ||
<p v-html="t('manager.statistics.counterR5Reports.description')" /> | ||
<div class="mb-4"> | ||
<Notification v-if="usageNotPossible" type="warning"> | ||
{{ t('manager.statistics.counterR5Reports.usageNotPossible') }} | ||
</Notification> | ||
</div> | ||
<Panel> | ||
<PanelSection> | ||
<CounterReportsListPanel v-bind="counterReportsListPanel" @set="set" /> | ||
</PanelSection> | ||
</Panel> | ||
</template> | ||
|
||
<script setup> | ||
import Panel from '@/components/Panel/Panel.vue'; | ||
import PanelSection from '@/components/Panel/PanelSection.vue'; | ||
import CounterReportsListPanel from './components/CounterReportsListPanel.vue'; | ||
import {useLocalize} from '@/composables/useLocalize'; | ||
const {t} = useLocalize(); | ||
defineProps({ | ||
counterReportsListPanel: {type: Object, required: true}, | ||
usageNotPossible: {type: Boolean, required: true}, | ||
}); | ||
</script> |
112 changes: 112 additions & 0 deletions
112
src/pages/counter/components/CounterReportsEditModal.vue
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,112 @@ | ||
<template> | ||
<SideModalBody> | ||
<template #title> | ||
{{ title }} | ||
</template> | ||
<SideModalLayoutBasic> | ||
<PkpForm v-bind="form" @set="set" @success="closeModal" /> | ||
</SideModalLayoutBasic> | ||
</SideModalBody> | ||
</template> | ||
|
||
<script setup> | ||
import SideModalBody from '@/components/Modal/SideModalBody.vue'; | ||
import SideModalLayoutBasic from '@/components/Modal/SideModalLayoutBasic.vue'; | ||
import PkpForm from '@/components/Form/Form.vue'; | ||
import {useForm} from '@/composables/useForm'; | ||
import {useFetch} from '@/composables/useFetch'; | ||
import {inject} from 'vue'; | ||
const props = defineProps({ | ||
title: {type: String, required: true}, | ||
submitAction: {type: String, required: true}, | ||
activeForm: {type: Object, required: true}, | ||
}); | ||
const closeModal = inject('closeModal'); | ||
/** | ||
* Get the report parameters | ||
* | ||
* @param Object | ||
* @return Object | ||
*/ | ||
function getReportParams(formSubmitValues) { | ||
let params = {}; | ||
for (const [key, value] of Object.entries(formSubmitValues)) { | ||
switch (key) { | ||
case 'customer_id': | ||
if (parseInt(value, 10) >= 0) { | ||
params[key] = value; | ||
} | ||
break; | ||
case 'begin_date': | ||
case 'end_date': | ||
case 'yop': | ||
case 'item_id': | ||
if (value != null && value.length > 0) { | ||
params[key] = value; | ||
} | ||
break; | ||
case 'metric_type': | ||
case 'attributes_to_show': | ||
if (value != null && value.length > 0) { | ||
params[key] = value.join('|'); | ||
} | ||
break; | ||
case 'include_parent_details': | ||
if (value == true) { | ||
params.include_parent_details = 'True'; | ||
} | ||
break; | ||
case 'granularity': | ||
if (value == true) { | ||
params.granularity = 'Totals'; | ||
} | ||
break; | ||
} | ||
} | ||
return params; | ||
} | ||
const {form, set} = useForm(props.activeForm, { | ||
customSubmit: async (submittedValues) => { | ||
const {validationError, data, fetch} = useFetch(props.submitAction, { | ||
expectValidationError: true, | ||
headers: {Accept: 'text/tab-separated-values; charset=utf-8'}, | ||
query: getReportParams(submittedValues), | ||
}); | ||
await fetch(); | ||
if ( | ||
validationError.value && | ||
Object.prototype.hasOwnProperty.call(validationError.value, 'Code') | ||
) { | ||
// COUNTER speific errors should actually not occur | ||
// because of the form/user input validation | ||
// but consider them for any case as well. | ||
pkp.eventBus.$emit( | ||
'notify', | ||
validationError.value.Code + | ||
': ' + | ||
validationError.value.Message + | ||
' (' + | ||
validationError.value.Data + | ||
')', | ||
'warning', | ||
); | ||
validationError.value = null; | ||
data.value = null; | ||
} else if (data.value) { | ||
var blob = new Blob([data.value]); | ||
var link = document.createElement('a'); | ||
link.href = window.URL.createObjectURL(blob); | ||
link.download = 'counterReport.tsv'; | ||
link.click(); | ||
} | ||
return {data: data.value, validationError: validationError.value}; | ||
}, | ||
}); | ||
</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,84 @@ | ||
<template> | ||
<div class="counterReportsListPanel"> | ||
<slot> | ||
<ListPanel :items="items"> | ||
<template #header> | ||
<PkpHeader> | ||
<h2>{{ title }}</h2> | ||
<Spinner v-if="isLoadingItems" /> | ||
</PkpHeader> | ||
</template> | ||
<template #item-title="{item}"> | ||
<span :id="item.Report_ID" class="text-lg-normal"> | ||
{{ item.Report_Name }} ({{ item.Report_ID }}) | ||
</span> | ||
</template> | ||
<template #item-actions="{item}"> | ||
<PkpButton @click="openEditModal(item.Report_ID)"> | ||
{{ t('common.edit') }} | ||
</PkpButton> | ||
</template> | ||
</ListPanel> | ||
</slot> | ||
</div> | ||
</template> | ||
|
||
<script setup> | ||
import PkpButton from '@/components/Button/Button.vue'; | ||
import Spinner from '@/components/Spinner/Spinner.vue'; | ||
import ListPanel from '@/components/ListPanel/ListPanel.vue'; | ||
import PkpHeader from '@/components/Header/Header.vue'; | ||
import cloneDeep from 'clone-deep'; | ||
import CounterReportsEditModal from './CounterReportsEditModal.vue'; | ||
import {useModal} from '@/composables/useModal'; | ||
import {useFetch} from '@/composables/useFetch'; | ||
import {useApiUrl} from '@/composables/useApiUrl'; | ||
import {useLocalize} from '@/composables/useLocalize'; | ||
import {ref, computed} from 'vue'; | ||
const {t} = useLocalize(); | ||
const props = defineProps({ | ||
form: {type: Object, required: true}, | ||
id: {type: String, required: true}, | ||
title: {type: String, required: true}, | ||
}); | ||
const items = computed(() => data.value || []); | ||
const activeForm = ref(null); | ||
const activeFormTitle = ref(''); | ||
const {apiUrl} = useApiUrl(`stats/sushi/reports`); | ||
const { | ||
data, | ||
fetch, | ||
isLoading: isLoadingItems, | ||
} = useFetch(apiUrl, { | ||
method: 'GET', | ||
}); | ||
fetch(); | ||
/** | ||
* Open the modal to edit an item | ||
* | ||
* @param {String} id | ||
*/ | ||
function openEditModal(id) { | ||
const report = items.value.find((report) => report.Report_ID === id); | ||
activeForm.value = cloneDeep(props.form); | ||
activeForm.value.method = 'GET'; | ||
activeForm.value.fields = activeForm.value.reportFields[id]; | ||
activeFormTitle.value = t('manager.statistics.counterR5Report.settings'); | ||
const {openSideModal} = useModal(); | ||
const {apiUrl} = useApiUrl(`stats/sushi/${report.Path}`); | ||
openSideModal(CounterReportsEditModal, { | ||
title: t('manager.statistics.counterR5Report.settings'), | ||
submitAction: apiUrl, | ||
activeForm, | ||
}); | ||
} | ||
</script> |