Skip to content

Commit

Permalink
feat(settings/media-repurposing): add exclude categories, owner, tags…
Browse files Browse the repository at this point in the history
… to rule criteria KMCNG-2637 (#1068)

* feat(settings/media-repurposing): add exclude categories to rule criteria KMCNG-2637

* feat(settings/media-repurposing): add exclude owner to rule owner KMCNG-2637

* feat(settings/media-repurposing): add exclude tags to rule tags KMCNG-2637
  • Loading branch information
amirch1 authored May 22, 2024
1 parent 9423c79 commit 2e80dce
Show file tree
Hide file tree
Showing 6 changed files with 163 additions and 78 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import {Component, EventEmitter, Input, Output} from '@angular/core';
import {KalturaLogger, LogLevels} from '@kaltura-ng/kaltura-logger';
import {KalturaLogger} from '@kaltura-ng/kaltura-logger';
import {MenuItem} from 'primeng/api';
import {AppLocalization} from '@kaltura-ng/mc-shared';
import {KalturaMediaEntryCompareAttribute, KalturaMediaEntryMatchAttribute, KalturaSearchOperatorType} from 'kaltura-ngx-client';

@Component({
selector: 'kRuleCriteria',
Expand Down Expand Up @@ -35,15 +36,22 @@ export class CriteriaComponent {
this._criterias.push('played');
}
if (this._filter['advancedSearch']) {
this._criterias.push('plays');
if (this._filter['advancedSearch']['items'] && this._filter['advancedSearch']['items'].length) {
this._filter['advancedSearch']['items'].forEach(search => {
if (search['attribute'] === KalturaMediaEntryCompareAttribute.plays) {
this._criterias.push('plays');
}
if (search['attribute'] === KalturaMediaEntryMatchAttribute.tags) {
delete this._filter['tagsMultiLikeOr']; // remove old filter from old rules to prevent tags filter duplication
this._criterias.push('tags');
}
})
}
}
if (this._filter['categoriesIdsMatchOr']) {
if (this._filter['categoriesIdsMatchOr'] || this._filter['categoriesIdsNotContains']) {
this._criterias.push('categories');
}
if (this._filter['tagsMultiLikeOr']) {
this._criterias.push('tags');
}
if (this._filter['userIdIn']) {
if (this._filter['userIdIn'] || this._filter['userIdNotIn']) {
this._criterias.push('owner');
}
if (this._filter['durationLessThanOrEqual'] || this._filter['durationGreaterThan']) {
Expand Down Expand Up @@ -79,7 +87,7 @@ export class CriteriaComponent {
}
},
{
label: this._appLocalization.get('applications.settings.mr.criteria.published'),
label: this._appLocalization.get('applications.settings.mr.criteria.categories'),
disabled: this._criterias.indexOf('categories') > -1,
command: () => {
this.addFilter('categories');
Expand Down Expand Up @@ -119,16 +127,29 @@ export class CriteriaComponent {
delete this._filter['lastPlayedAtGreaterThanOrEqual'];
}
if (field === 'plays') {
delete this._filter['advancedSearch'];
if (this._filter['advancedSearch'] && this._filter['advancedSearch']['items'] && this._filter['advancedSearch']['items'].length) {
this._filter['advancedSearch']['items'] = this._filter['advancedSearch']['items'].filter(search => search['attribute'] !== KalturaMediaEntryCompareAttribute.plays);
}
if (this._filter['advancedSearch'] && this._filter['advancedSearch']['items'] && this._filter['advancedSearch']['items'].length === 0) {
delete this._filter['advancedSearch'];
}
}
if (field === 'categories') {
delete this._filter['categoriesIdsMatchOr'];
delete this._filter['categoriesIdsNotContains'];
}
if (field === 'tags') {
delete this._filter['tagsMultiLikeOr'];
delete this._filter['tagsMultiLikeOr']; // remove old filter from old rules to prevent tags filter duplication
if (this._filter['advancedSearch'] && this._filter['advancedSearch']['items'] && this._filter['advancedSearch']['items'].length) {
this._filter['advancedSearch']['items'] = this._filter['advancedSearch']['items'].filter(search => search['attribute'] !== KalturaMediaEntryMatchAttribute.tags);
}
if (this._filter['advancedSearch'] && this._filter['advancedSearch']['items'] && this._filter['advancedSearch']['items'].length === 0) {
delete this._filter['advancedSearch'];
}
}
if (field === 'owner') {
delete this._filter['userIdIn'];
delete this._filter['userIdNotIn'];
}
if (field === 'duration') {
delete this._filter['durationLessThanOrEqual'];
Expand All @@ -146,7 +167,25 @@ export class CriteriaComponent {

public onCriteriaChange(event: {field: string, value: any}): void {
this.clearFilterFields(event.field);
Object.assign(this._filter, event.value);
if (event.field === 'plays' || event.field === 'tags') {
if (this._filter['advancedSearch'] && this._filter['advancedSearch']['items'] && this._filter['advancedSearch']['items'].length) {
// remove old plays filter before adding the new one
if (event.field === 'plays') {
this._filter['advancedSearch']['items'] = this._filter['advancedSearch']['items'].filter((search: any) => search['attribute'] !== KalturaMediaEntryCompareAttribute.plays);
} else {
this._filter['advancedSearch']['items'] = this._filter['advancedSearch']['items'].filter((search: any) => search['attribute'] !== KalturaMediaEntryMatchAttribute.tags);
}
} else {
this._filter['advancedSearch'] = {
objectType: "KalturaSearchOperator",
type: KalturaSearchOperatorType.searchAnd,
items: []
};
}
this._filter['advancedSearch'].items.push(event.value);
} else {
Object.assign(this._filter, event.value);
}
this.removeEmptyFields();
this.onFilterChange.emit(this._filter);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,32 +14,34 @@ import {AppLocalization} from '@kaltura-ng/mc-shared';
<div class="criteria">
<div class="kRow">
<span class="kLabel">{{'applications.settings.mr.criteria.header' | translate}}</span>
<span class="kLabelWithHelpTip">{{'applications.settings.mr.criteria.published' | translate}}</span>
<span class="kLabelWithHelpTip">{{'applications.settings.mr.criteria.categories' | translate}}</span>
<kInputHelper>
<span>{{'applications.settings.mr.criteria.published_tt' | translate}}</span>
</kInputHelper>
</div>
<div class="kRow kCenter">
<span class="kLabel">{{'applications.settings.mr.criteria.categories' | translate}}</span>
<div class="kCol">
<kAutoComplete [(ngModel)]="categories"
(ngModelChange)="onCriteriaChange()"
field="name"
suggestionItemField="item"
suggestionLabelField="name"
suggestionSelectableField="isSelectable"
[allowMultiple]="true"
[tooltipResolver]="_categoriesTooltipResolver"
[minLength]="3"
[suggestionsProvider]="_categoriesProvider"
(completeMethod)="_searchCategories($event)">
</kAutoComplete>
<a (click)="categoriesPopup.open()" class="kLink">
{{'applications.content.entryDetails.metadata.browse' | translate}}
</a>
<div class="kRow">
<p-dropdown [options]="_publishOptions" [style]="{'width':'150px', 'margin-right': '16px'}" [(ngModel)]="_published" (ngModelChange)="onCriteriaChange()"></p-dropdown>
<div class="kCol">
<kAutoComplete [(ngModel)]="categories"
(ngModelChange)="onCriteriaChange()"
field="name"
suggestionItemField="item"
suggestionLabelField="name"
suggestionSelectableField="isSelectable"
[allowMultiple]="true"
[tooltipResolver]="_categoriesTooltipResolver"
[minLength]="3"
[suggestionsProvider]="_categoriesProvider"
(completeMethod)="_searchCategories($event)">
</kAutoComplete>
<a (click)="categoriesPopup.open()" class="kLink">
{{'applications.content.entryDetails.metadata.browse' | translate}}
</a>
</div>
</div>
</div>
<span class="kDelete" (click)="delete()">{{'applications.content.table.delete'| translate}}</span>
Expand All @@ -56,11 +58,17 @@ import {AppLocalization} from '@kaltura-ng/mc-shared';
export class CriteriaCategoriesComponent implements OnDestroy{

public categories: CategoryData[] = [];
public _publishOptions: { value: string, label: string }[] = [
{value: 'categoriesIdsMatchOr', label: this._appLocalization.get('applications.settings.mr.criteria.published')},
{value: 'categoriesIdsNotContains', label: this._appLocalization.get('applications.settings.mr.criteria.notPublished')}
];
public _published = 'categoriesIdsMatchOr';

@Input() set filter(value: any) {
if (value && value['categoriesIdsMatchOr']) {
if (value && (value['categoriesIdsMatchOr'] || value['categoriesIdsNotContains'])) {
this._published = value['categoriesIdsMatchOr'] ? 'categoriesIdsMatchOr' : 'categoriesIdsNotContains'; // set dropdown value
// load categories from their IDs
const categoriesFilter = value['categoriesIdsMatchOr'].split(',');
const categoriesFilter = value['categoriesIdsMatchOr'] ? value['categoriesIdsMatchOr'].split(',') : value['categoriesIdsNotContains'].split(',') ;
const categoryIDs: number[] = [];
categoriesFilter.forEach(id => categoryIDs.push(parseInt(id)));
this._categoriesSearchService.getCategories(categoryIDs).subscribe(response => {
Expand Down Expand Up @@ -98,7 +106,7 @@ export class CriteriaCategoriesComponent implements OnDestroy{
const cats = [];
const value = {};
this.categories.forEach(category => cats.push(category.id));
value['categoriesIdsMatchOr'] = cats.toString();
value[this._published] = cats.toString();
this.onFilterChange.emit({field: 'categories', value});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
KalturaFilterPager,
KalturaUser, KalturaUserFilter, UserListAction
} from 'kaltura-ngx-client';
import {AppLocalization} from '@kaltura-ng/mc-shared';

@Component({
selector: 'kCriteriaOwner',
Expand All @@ -30,22 +31,25 @@ import {
<div class="kRow kCenter">
<span class="kLabel">{{'applications.settings.mr.criteria.ownerLabel' | translate}}</span>
<div class="kCol">
<kAutoComplete
[(ngModel)]="owners"
(ngModelChange)="onCriteriaChange()"
suggestionItemField="item"
suggestionLabelField="name"
[tooltipResolver]="'__tooltip'"
[classField]="'__class'"
field="id"
[allowMultiple]="true"
[limitToSuggestions]="false"
[minLength]="3"
suggestionSelectableField="isSelectable"
[suggestionsProvider]="_usersProvider"
(completeMethod)="_searchUsers($event, 'editors')">
</kAutoComplete>
<div class="kRow">
<p-dropdown [options]="_ownerOptions" [style]="{'width':'150px', 'margin-right': '16px'}" [(ngModel)]="_owner" (ngModelChange)="onCriteriaChange()"></p-dropdown>
<div class="kCol">
<kAutoComplete
[(ngModel)]="owners"
(ngModelChange)="onCriteriaChange()"
suggestionItemField="item"
suggestionLabelField="name"
[tooltipResolver]="'__tooltip'"
[classField]="'__class'"
field="id"
[allowMultiple]="true"
[limitToSuggestions]="false"
[minLength]="3"
suggestionSelectableField="isSelectable"
[suggestionsProvider]="_usersProvider"
(completeMethod)="_searchUsers($event, 'editors')">
</kAutoComplete>
</div>
</div>
</div>
Expand All @@ -57,13 +61,19 @@ import {
export class CriteriaOwnerComponent implements OnDestroy{

public owners: KalturaUser[] = [];
public _ownerOptions: { value: string, label: string }[] = [
{value: 'userIdIn', label: this._appLocalization.get('applications.settings.mr.criteria.ownerIs')},
{value: 'userIdNotIn', label: this._appLocalization.get('applications.settings.mr.criteria.ownerIsNot')}
];
public _owner = 'userIdIn';

@Input() set filter(value: any) {
if (value && value['userIdIn']) {
if (value && (value['userIdIn'] || value['userIdNotIn'])) {
this._owner = value['userIdIn'] ? 'userIdIn' : 'userIdNotIn'; // set dropdown value
// load users from their IDs
this._kalturaServerClient.request(new UserListAction({
filter: new KalturaUserFilter({
idIn: value['userIdIn']
idIn: value['userIdIn'] ? value['userIdIn'] : value['userIdNotIn']
})
}))
.pipe(cancelOnDestroy(this))
Expand All @@ -81,15 +91,16 @@ export class CriteriaOwnerComponent implements OnDestroy{
private _searchUsersSubscription: ISubscription;
public _usersProvider = new Subject<SuggestionsProviderData>();

constructor(private _kalturaServerClient: KalturaClient) {
constructor(private _kalturaServerClient: KalturaClient,
private _appLocalization: AppLocalization) {
}


public onCriteriaChange(): void {
const value = {};
const userIds = [];
this.owners.forEach(user => userIds.push(user.id));
value['userIdIn'] = userIds.toString();
value[this._owner] = userIds.toString();
this.onFilterChange.emit({field: 'owner', value});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,14 @@ export class CriteriaPlaysComponent implements OnInit{
public playsInterval = KalturaSearchConditionComparison.lessThan;

@Input() set filter(value: any) {
if (value['advancedSearch'] && value['advancedSearch']['attribute'] && value['advancedSearch']['attribute'] === KalturaMediaEntryCompareAttribute.plays) {
this.playsInterval = value['advancedSearch']['comparison'];
this.numOfPlays = parseInt(value['advancedSearch']['value']);
};
if (value['advancedSearch'] && value['advancedSearch']['items'] && value['advancedSearch']['items'].length) {
value['advancedSearch']['items'].forEach((advancedSearch: any) => {
if (advancedSearch['attribute'] && advancedSearch['attribute'] === KalturaMediaEntryCompareAttribute.plays) {
this.playsInterval = advancedSearch['comparison'];
this.numOfPlays = parseInt(advancedSearch['value']);
}
});
}
}
@Output() onDelete = new EventEmitter<string>();
@Output() onFilterChange = new EventEmitter<{field: string, value: any}>();
Expand All @@ -51,8 +55,7 @@ export class CriteriaPlaysComponent implements OnInit{
}

public onCriteriaChange(): void {
const value = {};
value['advancedSearch'] = {
const value = {
objectType: "KalturaMediaEntryCompareAttributeCondition",
comparison: this.playsInterval,
attribute: KalturaMediaEntryCompareAttribute.plays,
Expand Down
Loading

0 comments on commit 2e80dce

Please sign in to comment.