Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Content Activity and Subscriber Activity reports print functionality #963

Merged
merged 4 commits into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 22 additions & 14 deletions assets/company-reports/actions.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import {errorHandler, getItemFromArray, getDateInputDate, notify, gettext} from '../utils';
import server from '../server';
import {get, cloneDeep} from 'lodash';
import {cloneDeep} from 'lodash';
import {type ICompanyReportsData} from './types';
import {Store, Dispatch} from 'redux';

export const REPORTS_NAMES = {
'COMPANY_SAVED_SEARCHES': 'company-saved-searches',
Expand Down Expand Up @@ -32,11 +33,11 @@ export const REPORTS: any = {
[REPORTS_NAMES.COMPANY_AND_USER_SAVED_SEARCHES]: '/reports/company-and-user-saved-searches',
};

function getReportQueryString(currentState: any, next: any, exportReport: any, notify: any) {
function getReportQueryString(currentState: any, next: boolean, exportReport: boolean, notify: any) {
const params = cloneDeep(currentState.reportParams);
if (params) {
if (params.company) {
params.company = get(getItemFromArray(params.company, currentState.companies, 'name'), '_id');
params.company = getItemFromArray(params.company, currentState.companies, 'name')?._id;
}

if (params.date_from > params.date_to) {
Expand All @@ -52,22 +53,23 @@ function getReportQueryString(currentState: any, next: any, exportReport: any, n
}

if (params.section) {
params.section = get(getItemFromArray(params.section, currentState.sections, 'name'), '_id');
params.section = getItemFromArray(params.section, currentState.sections, 'name')?._id;
}

if (params.product) {
params.product = get(getItemFromArray(params.product, currentState.products, 'name'), '_id');
params.product = getItemFromArray(params.product, currentState.products, 'name')?._id;
}

if (exportReport) {
params.export = true;
}

params['from'] = next ? get(currentState, 'results.length') : 0;
params['from'] = next ? currentState?.results?.length : 0;
const queryString = Object.keys(params)
.filter((key: any) => params[key])
.map((key: any) => [key, params[key]].join('='))
.filter((key) => params[key])
.map((key) => [key, params[key]].join('='))
.join('&');

return queryString;
}
}
Expand Down Expand Up @@ -124,7 +126,7 @@ export function runReport() {

export function fetchAggregations(url: string) {
return function(dispatch: any, getState: any) {
const queryString = getReportQueryString(getState(), 0, false, notify);
const queryString = getReportQueryString(getState(), false, false, notify);

server.get(`${url}?${queryString}&aggregations=1`)
.then((data: any) => {
Expand Down Expand Up @@ -191,17 +193,23 @@ export function toggleFilterAndQuery(filter: any, value: any) {
}

export function printReport() {
return function (dispatch: any, getState: any) {
const queryStringRequiredReports = [
REPORTS_NAMES.SUBSCRIBER_ACTIVITY,
REPORTS_NAMES.CONTENT_ACTIVITY
];
const REPORTS_URL_BASE = '/reports/print/';

return async function (_: Dispatch, getState: Store['getState']) {
const state = getState();
const activeReport = state.activeReport;
let url = `${REPORTS_URL_BASE}${activeReport}`;

if (activeReport === REPORTS_NAMES.SUBSCRIBER_ACTIVITY) {
if (queryStringRequiredReports.includes(activeReport)) {
const queryString = getReportQueryString(state, false, false, notify);
window.open(`/reports/print/${activeReport}?${queryString}`, '_blank');
} else {
window.open(`/reports/print/${activeReport}`, '_blank');
url += `?${queryString}`;
}

window.open(url, '_blank');
return Promise.resolve();
};
}
Expand Down
2 changes: 1 addition & 1 deletion assets/render-utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {Provider} from 'react-redux';
import {render as _render} from 'react-dom';
import '@superdesk/common/dist/src/index.css';

export function render(store: any, App: any, element?: any, props?: any) {
export function render<T = any>(store: any, App: any, element?: any, props?: T) {
return _render(
<Provider store={store}>
<App {...props}/>
Expand Down
29 changes: 4 additions & 25 deletions newsroom/reports/content_activity.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,31 +253,10 @@ def export_csv(args, results):
aggs.get("total") or 0,
]

if "download" in actions:
row.append((aggs.get("actions") or {}).get("download") or 0)

if "copy" in actions:
row.append((aggs.get("actions") or {}).get("copy") or 0)

if "share" in actions:
row.append((aggs.get("actions") or {}).get("share") or 0)

if "print" in actions:
row.append((aggs.get("actions") or {}).get("print") or 0)

if "open" in actions:
row.append((aggs.get("actions") or {}).get("open") or 0)

if "preview" in actions:
row.append((aggs.get("actions") or {}).get("preview") or 0)

if "clipboard" in actions:
row.append((aggs.get("actions") or {}).get("clipboard") or 0)

if "api" in actions:
row.append((aggs.get("actions") or {}).get("api") or 0)

rows.append(row)
action_names = ["download", "copy", "share", "print", "open", "preview", "clipboard", "api"]
for action_name in action_names:
if action_name in actions:
row.append((aggs.get("actions") or {}).get(action_name, 0))

return rows

Expand Down
3 changes: 2 additions & 1 deletion newsroom/templates/reports_print.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ <h2 class="text-center">{{ data.get('name') }}</h2>

<script>
window.newsroom = {{ get_client_config() | tojson | safe }};
window.locale = '{{ get_locale() | tojson | safe }}';
reportData = {{ data | tojson | safe }};
report = "{{ report | tojson | safe }}";
</script>

{{ javascript_tag('%s_js' % setting_type) | safe }}

{% endblock %}
Loading