Moved posts export to analytics settings page (#16539)

refs https://github.com/TryGhost/Team/issues/2869
This commit is contained in:
Fabien 'egg' O'Carroll 2023-04-03 13:35:56 +07:00 committed by GitHub
parent 301a21106c
commit a978f9f6b9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 14 additions and 51 deletions

View File

@ -111,7 +111,9 @@
Download a single, glorious CSV file with all your post analytics
</p>
</div>
<button type="button" class="gh-btn"><span>Export</span></button>
<button type="button" class="gh-btn" {{on "click" this.exportData}}>
<span>Export</span>
</button>
</div>
</div>
</section>

View File

@ -1,10 +1,12 @@
import Component from '@glimmer/component';
import ghostPaths from 'ghost-admin/utils/ghost-paths';
import {action} from '@ember/object';
import {inject as service} from '@ember/service';
export default class Analytics extends Component {
@service settings;
@service feature;
@service utils;
@action
toggleEmailTrackOpens(event) {
@ -14,6 +16,15 @@ export default class Analytics extends Component {
this.settings.emailTrackOpens = !this.settings.emailTrackOpens;
}
@action
exportData() {
let exportUrl = ghostPaths().url.api('posts/export');
let downloadParams = new URLSearchParams();
downloadParams.set('limit', 'all');
this.utils.downloadFile(`${exportUrl}?${downloadParams.toString()}`);
}
@action
toggleEmailTrackClicks(event) {
if (event) {

View File

@ -1,5 +1,4 @@
import Controller from '@ember/controller';
import ghostPaths from 'ghost-admin/utils/ghost-paths';
import {DEFAULT_QUERY_PARAMS} from 'ghost-admin/helpers/reset-query-params';
import {action} from '@ember/object';
import {inject} from 'ghost-admin/decorators/inject';
@ -53,7 +52,6 @@ export default class PostsController extends Controller {
@service router;
@service session;
@service store;
@service utils;
@inject config;
@ -142,17 +140,6 @@ export default class PostsController extends Controller {
return authors.findBy('slug', author) || {slug: '!unknown'};
}
@action
exportData() {
let exportUrl = ghostPaths().url.api('posts/export');
// the filter and order params are set from the route to the controller via the infinity model
// we can retrieve these via the extraParams of the infinity model
let downloadParams = new URLSearchParams(this.model.extraParams);
downloadParams.set('limit', 'all');
this.utils.downloadFile(`${exportUrl}?${downloadParams.toString()}`);
}
@action
changeType(type) {
this.type = type.value;

View File

@ -23,43 +23,6 @@
/>
<div class="view-actions-top-row">
{{#if (feature 'makingItRain')}}
<span class="dropdown posts-actions-dropdown">
<GhDropdownButton
@dropdownName="posts-actions-menu"
@classNames="gh-btn gh-btn-icon icon-only gh-btn-action-icon"
@title="Posts Actions"
data-test-button="posts-actions"
>
<span>
{{svg-jar "settings"}}
<span class="hidden">Actions</span>
</span>
</GhDropdownButton>
<GhDropdown
@name="posts-actions-menu"
@tagName="ul"
@classNames="gh-post-actions-menu dropdown-menu dropdown-triangle-top-right"
>
<li class="{{if this.totalPosts "" "disabled"}}">
{{#if this.totalPosts}}
<button class="mr2" type="button" {{on "click" this.exportData}} data-test-button="export-posts">
{{#if this.showingAll}}
<span>Export post analytics</span>
{{else}}
<span>Export post analytics ({{this.totalPosts}})</span>
{{/if}}
</button>
{{else}}
<button class="mr2" disabled="true" type="button" data-test-button="export-posts">
<span>Export post analytics (0)</span>
</button>
{{/if}}
</li>
</GhDropdown>
</span>
{{/if}}
<LinkTo @route="editor.new" @model="post" class="gh-btn gh-btn-primary" data-test-new-post-button={{true}}><span>New post</span></LinkTo>
</div>
</section>