Skip to content

Commit

Permalink
feat(content/entries): add export to CSV feature SUP-31109 (#1021)
Browse files Browse the repository at this point in the history
* export users and entries to CSV - initial commit

* additional fields for users and entries export

* updated fields

* updated export formatters
  • Loading branch information
amirch1 authored Jun 14, 2022
1 parent 9a25c68 commit 6628795
Show file tree
Hide file tree
Showing 15 changed files with 123 additions and 11 deletions.
Binary file not shown.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
"jquery": "~3.5.0",
"jsnlog": "~2.26.2",
"jsonschema": "~1.4.0",
"kaltura-ngx-client": "file:libs/kaltura-ngx-client-12.0.0-v20220508-090406.tgz",
"kaltura-ngx-client": "file:libs/kaltura-ngx-client-12.0.0-v20220614-103835.tgz",
"moment": "~2.22.2",
"ngx-page-scroll": "~5.0.1",
"ngx-webstorage": "~5.0.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
<span class="kSelectedUsersNum" *ngIf="_usersAmount">
{{_usersAmount}}
</span>
<button pButton class="kButtonDefault kExportBtn" (click)="_export()" type="text"
[label]="'applications.content.entryDetails.distribution.export' | translate"></button>
<button pButton class="kButtonDefault kRefreshBtn small" (click)="_reload()" type="text" icon="kIconrefresh"
[kTooltip]="'applications.administration.users.refresh' | translate"></button>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@
flex-direction: column;
}

.kExportBtn {
margin-left: auto;
margin-right: 8px;
::ng-deep .p-button-icon {
font-size: 24px;
}
}

.kRefreshBtn {
font-size: 24px;
border: none;
Expand All @@ -29,7 +37,6 @@
outline: 0;
color: $kGrayscale3;
right: 0;
margin-left: auto;
&:active {
box-shadow: none;
transform: rotate(45deg);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,4 +172,8 @@ export class UsersListComponent implements OnInit, OnDestroy {
public _reload(): void {
this._usersStore.reload(true);
}

public _export(): void {
this._usersStore.export();
}
}
36 changes: 35 additions & 1 deletion src/applications/administration-users-app/users/users.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { of } from 'rxjs';
import { AppLocalization } from '@kaltura-ng/mc-shared';
import { IsUserExistsStatuses } from './user-exists-statuses';
import { cancelOnDestroy, tag } from '@kaltura-ng/kaltura-common';
import { KalturaUser } from 'kaltura-ngx-client';
import {KalturaAPIException, KalturaKeyValueExtended, KalturaUser, UserExportToCsvAction} from 'kaltura-ngx-client';
import { KalturaUserRole } from 'kaltura-ngx-client';
import { KalturaClient, KalturaMultiRequest } from 'kaltura-ngx-client';
import { UserRoleListAction } from 'kaltura-ngx-client';
Expand Down Expand Up @@ -155,6 +155,40 @@ export class UsersStore implements OnDestroy {
);
}

public export(): void {
const request = new UserExportToCsvAction({
filter: new KalturaUserFilter({
isAdminEqual: KalturaNullableBoolean.trueValue,
loginEnabledEqual: KalturaNullableBoolean.trueValue,
statusIn: KalturaUserStatus.active + ',' + KalturaUserStatus.blocked,
orderBy: KalturaUserOrderBy.createdAtAsc.toString()
}),
mappedFields: [
new KalturaKeyValueExtended({key: 'Role', value: 'roleNames', predefinedFormat: KalturaNullableBoolean.falseValue}),
new KalturaKeyValueExtended({key: 'Status', value: 'status', predefinedFormat: KalturaNullableBoolean.trueValue}),
new KalturaKeyValueExtended({key: 'Registration Date', value: 'createdAt', predefinedFormat: KalturaNullableBoolean.trueValue}),
new KalturaKeyValueExtended({key: 'Last Login', value: 'lastLoginTime', predefinedFormat: KalturaNullableBoolean.trueValue})
]
});
this._kalturaServerClient.request(request)
.pipe(tag('block-shell'))
.pipe(cancelOnDestroy(this))
.subscribe(
response => {
this._browserService.alert({
header: this._appLocalization.get('applications.administration.users.export'),
message: this._appLocalization.get('app.common.export')
});
},
(e: KalturaAPIException) => {
this._browserService.alert({
header: this._appLocalization.get('app.common.error'),
message: e.message
});
}
);
}

public isCurrentUser(user: KalturaUser): boolean {
return this._appAuthentication.appUser.id === user.id;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<k-area-blocker [message]="_blockerMessage" [bodyScroll]="true">
<kEntriesList [columns]="_columns"
[showExport]="true"
[rowActions]="_rowActions"
(onActionsSelected)="_onActionSelected($event)">
<div class="bulk-actions">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Injectable, OnDestroy } from '@angular/core';
import { KalturaBaseEntry } from 'kaltura-ngx-client';
import { Observable } from 'rxjs';
import {Observable, of} from 'rxjs';
import { KalturaDetachedResponseProfile } from 'kaltura-ngx-client';
import { KalturaMetadataSearchItem } from 'kaltura-ngx-client';
import { KalturaNullableBoolean } from 'kaltura-ngx-client';
Expand Down Expand Up @@ -258,6 +258,9 @@ export class PlaylistEntriesDataProvider implements EntriesDataProvider, OnDestr
}
}

public exportToCsv(data: EntriesFilters): Observable<any> {
return of({});
}

public executeQuery(data: EntriesFilters): Observable<{ entries: KalturaBaseEntry[], totalCount?: number }> {
let pagination: KalturaFilterPager = null;
Expand Down
7 changes: 5 additions & 2 deletions src/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,8 @@
"save": "Save",
"error": "Error",
"connectionError": "Error connecting to server",
"invalidKs": "User session has expired. Please re-login."
"invalidKs": "User session has expired. Please re-login.",
"export": "We are preparing your report. We will send it to your email address shortly."
},
"redirect":{
"redirect1": "Redirecting to default view...",
Expand Down Expand Up @@ -323,7 +324,8 @@
"noMembers": "No Members",
"private": "Private"
}
}
},
"export": "Export Entries"
},
"upload": {
"fileStatus": {
Expand Down Expand Up @@ -2547,6 +2549,7 @@
"currentStatus": "Current status:",
"usersInfo": "{{0}} KMC {{1}} in use, {{2}} additional available.",
"failedLoading": "Failed to load users data",
"export": "Export Users",
"cantPerform": "You do not have access to perform this action",
"successSavingUser": "Changes will take effect immediately. \nPlease instruct the user to refresh their browser.",
"personalDetails": "Personal Details",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@
</div>
</div>
</div>
<button *ngIf="showExport" pButton class="kButtonDefault kExportBtn" (click)="_export()" type="text"
[label]="'applications.content.entryDetails.distribution.export' | translate"></button>
<button *ngIf="showReload"
pButton
class="kButtonDefault kRefreshBtn small"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@
left: 28px;
}
}

.kExportBtn {
margin-right: 8px;
::ng-deep .p-button-icon {
font-size: 24px;
}
}

.kRefreshBtn {
font-size: 24px;
border: none;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export interface CustomMenuItem extends MenuItem {
})
export class EntriesListComponent implements OnInit, OnDestroy, OnChanges {
@Input() showReload = true;
@Input() showExport = false;
@Input() selectedEntries: any[] = [];
@Input() columns: EntriesTableColumns | null;
@Input() rowActions: { label: string, commandName: string, styleClass: string }[];
Expand Down Expand Up @@ -418,6 +419,10 @@ export class EntriesListComponent implements OnInit, OnDestroy, OnChanges {
this._entriesStore.reload();
}

public _export(): void {
this._entriesStore.export();
}

clearSelection() {
this.selectedEntries = [];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ import {
KalturaExternalMediaSourceType,
KalturaExternalMediaEntryFilter,
KalturaEntryCaptionAdvancedFilter,
KalturaLiveChannel
KalturaLiveChannel,
BaseEntryExportToCsvAction,
KalturaKeyValueExtended
} from 'kaltura-ngx-client';
import { Observable } from 'rxjs';
import { cancelOnDestroy, KalturaUtils } from '@kaltura-ng/kaltura-common';
Expand Down Expand Up @@ -333,6 +335,26 @@ export class EntriesStoreDataProvider implements EntriesDataProvider, OnDestroy
}
}

public exportToCsv(data: EntriesFilters): Observable<any> {
return <any>
this.getServerFilter(data)
.pipe(switchMap(filter => this._kalturaServerClient.request(
new BaseEntryExportToCsvAction({
filter,
mappedFields: [
new KalturaKeyValueExtended({key: 'Media Type', value: 'mediaType', predefinedFormat: KalturaNullableBoolean.trueValue}),
new KalturaKeyValueExtended({key: 'Created On', value: 'createdAt', predefinedFormat: KalturaNullableBoolean.trueValue}),
new KalturaKeyValueExtended({key: 'Last Update Date', value: 'updatedAt', predefinedFormat: KalturaNullableBoolean.trueValue}),
new KalturaKeyValueExtended({key: 'Duration', value: 'duration', predefinedFormat: KalturaNullableBoolean.trueValue}),
new KalturaKeyValueExtended({key: 'Plays', value: 'plays', predefinedFormat: KalturaNullableBoolean.falseValue}),
new KalturaKeyValueExtended({key: 'Status', value: 'status', predefinedFormat: KalturaNullableBoolean.trueValue}),
new KalturaKeyValueExtended({key: 'Owner', value: 'userId', predefinedFormat: KalturaNullableBoolean.falseValue})
]
})
))
);
}

public executeQuery(data: EntriesFilters): Observable<{ entries: KalturaBaseEntry[], totalCount?: number }> {
const responseProfile: KalturaDetachedResponseProfile = new KalturaDetachedResponseProfile({
type: KalturaResponseProfileType.includeFields,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { BehaviorSubject } from 'rxjs';
import { Observable } from 'rxjs';
import { ISubscription } from 'rxjs/Subscription';
import { MetadataProfileStore } from 'app-shared/kmc-shared';
import { BaseEntryDeleteAction } from 'kaltura-ngx-client';
import {BaseEntryDeleteAction, KalturaAPIException} from 'kaltura-ngx-client';
import { KalturaMediaEntry } from 'kaltura-ngx-client';
import { KalturaClient } from 'kaltura-ngx-client';
import { BrowserService } from 'app-shared/kmc-shell/providers/browser.service';
Expand All @@ -27,7 +27,7 @@ import { Subject } from 'rxjs';
import { KalturaBaseEntry } from 'kaltura-ngx-client';
import { KalturaMediaEntryFilter } from 'kaltura-ngx-client';
import { globalConfig } from 'config/global';
import { cancelOnDestroy } from '@kaltura-ng/kaltura-common';
import {cancelOnDestroy, tag} from '@kaltura-ng/kaltura-common';
import { throwError } from 'rxjs';
import { map } from 'rxjs/operators';

Expand All @@ -39,6 +39,8 @@ export enum SortDirection {
export interface EntriesDataProvider {
executeQuery(filters: EntriesFilters): Observable<{ entries: KalturaBaseEntry[], totalCount?: number }>;

exportToCsv(filters: EntriesFilters): Observable<any>;

getDefaultFilterValues(savedAutoSelectChildren: CategoriesModes, pageSize: number): EntriesFilters;

getServerFilter(filters: EntriesFilters, forRequest?: boolean): Observable<KalturaMediaEntryFilter>;
Expand Down Expand Up @@ -186,6 +188,25 @@ export class EntriesStore extends FiltersStoreBase<EntriesFilters> implements On
}
}

public export(): void {
this._dataProvider.exportToCsv(this._getFiltersAsReadonly())
.pipe(tag('block-shell'))
.pipe(cancelOnDestroy(this))
.subscribe(
response => {
this._browserService.alert({
header: this._appLocalization.get('applications.entries.export'),
message: this._appLocalization.get('app.common.export')
});
},
(e: KalturaAPIException) => {
this._browserService.alert({
header: this._appLocalization.get('app.common.error'),
message: e.message
});
});
}

private _executeQuery(): void {
if (this._querySubscription) {
this._querySubscription.unsubscribe();
Expand Down

0 comments on commit 6628795

Please sign in to comment.