Skip to content

Commit

Permalink
Export faqs as json
Browse files Browse the repository at this point in the history
  • Loading branch information
rkuffer authored and vsct-jburet committed Oct 3, 2024
1 parent 9ef7b3b commit 9a1cc88
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@
<h1 class="flex-grow-1">FAQs stories</h1>

<section class="grid-actions">
<button
nbButton
ghost
shape="round"
nbTooltip="Export all faqs"
(click)="download()"
>
<nb-icon icon="download"></nb-icon>
</button>

<button
nbButton
ghost
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import { FaqDefinition, FaqFilter, FaqSearchQuery, PaginatedFaqResult } from '..
import { FaqManagementEditComponent } from './faq-management-edit/faq-management-edit.component';
import { FaqManagementSettingsComponent } from './faq-management-settings/faq-management-settings.component';
import { Pagination } from '../../shared/components';
import { getExportFileName } from '../../shared/utils';
import { saveAs } from 'file-saver-es';

export type FaqDefinitionExtended = FaqDefinition & { _initQuestion?: string };

Expand Down Expand Up @@ -315,6 +317,31 @@ export class FaqManagementComponent implements OnInit, OnDestroy {
}
}

download() {
let query: PaginatedQuery = this.stateService.createPaginatedQuery(0, 9999);
const request = this.toSearchQuery(query);

this.rest
.post('/faq/search', request)
.pipe(takeUntil(this.destroy))
.subscribe((faqsResult: PaginatedFaqResult) => {
const jsonBlob = new Blob([JSON.stringify(faqsResult.rows)], {
type: 'application/json'
});

const exportFileName = getExportFileName(
this.stateService.currentApplication.namespace,
this.stateService.currentApplication.name,
'Faqs',
'json'
);

saveAs(jsonBlob, exportFileName);

this.toastrService.show(`Faqs dump provided`, 'Faqs dump', { duration: 3000, status: 'success' });
});
}

ngOnDestroy() {
this.destroy.next(true);
this.destroy.complete();
Expand Down

0 comments on commit 9a1cc88

Please sign in to comment.