Merge pull request #4320 from MaximilianKrambach/mediafileFilter
full text search for media file, some permission checks
This commit is contained in:
commit
89a1b722e0
@ -1,5 +1,5 @@
|
||||
<os-head-bar
|
||||
[mainButton]="true"
|
||||
[mainButton]="canEdit"
|
||||
[editMode]="editFile"
|
||||
[multiSelectMode]="isMultiSelect"
|
||||
(mainEvent)="onMainEvent()"
|
||||
@ -35,7 +35,7 @@
|
||||
</div>
|
||||
|
||||
<!-- Menu -->
|
||||
<div class="menu-slot">
|
||||
<div class="menu-slot" *ngIf="canEdit">
|
||||
<button type="button" mat-icon-button [matMenuTriggerFor]="mediafilesMenu">
|
||||
<mat-icon>more_vert</mat-icon>
|
||||
</button>
|
||||
@ -170,7 +170,7 @@
|
||||
<span translate>Deselect all</span>
|
||||
</button>
|
||||
<mat-divider></mat-divider>
|
||||
<button mat-menu-item *osPerms="'mediafiles.can_manage'" (click)="deleteSelected()">
|
||||
<button mat-menu-item *ngIf="canEdit" (click)="deleteSelected()">
|
||||
<mat-icon>delete</mat-icon>
|
||||
<span translate>Delete</span>
|
||||
</button>
|
||||
|
@ -15,6 +15,7 @@ import { Mediafile } from 'app/shared/models/mediafiles/mediafile';
|
||||
import { MediafileFilterListService } from '../../services/mediafile-filter.service';
|
||||
import { MediafilesSortListService } from '../../services/mediafiles-sort-list.service';
|
||||
import { ViewportService } from 'app/core/ui-services/viewport.service';
|
||||
import { OperatorService } from 'app/core/core-services/operator.service';
|
||||
|
||||
/**
|
||||
* Lists all the uploaded files.
|
||||
@ -55,6 +56,13 @@ export class MediafileListComponent extends ListViewBaseComponent<ViewMediafile>
|
||||
*/
|
||||
public fileToEdit: ViewMediafile;
|
||||
|
||||
/**
|
||||
* @returns true if the user can manage media files
|
||||
*/
|
||||
public get canEdit(): boolean {
|
||||
return this.operator.hasPerms('mediafiles.can_manage');
|
||||
}
|
||||
|
||||
/**
|
||||
* The form to edit Files
|
||||
*/
|
||||
@ -73,6 +81,9 @@ export class MediafileListComponent extends ListViewBaseComponent<ViewMediafile>
|
||||
* @param mediaManage service to manage media files (setting images as logos)
|
||||
* @param promptService prevent deletion by accident
|
||||
* @param vp viewport Service to check screen size
|
||||
* @param fitlerService MediaFileFilterService for advanced filtering
|
||||
* @param sortService MediaFileSortService sort for advanced sorting
|
||||
* @param operator permission check
|
||||
*/
|
||||
public constructor(
|
||||
titleService: Title,
|
||||
@ -85,7 +96,8 @@ export class MediafileListComponent extends ListViewBaseComponent<ViewMediafile>
|
||||
private promptService: PromptService,
|
||||
public vp: ViewportService,
|
||||
public filterService: MediafileFilterListService,
|
||||
public sortService: MediafilesSortListService
|
||||
public sortService: MediafilesSortListService,
|
||||
private operator: OperatorService
|
||||
) {
|
||||
super(titleService, translate, matSnackBar);
|
||||
|
||||
@ -123,6 +135,7 @@ export class MediafileListComponent extends ListViewBaseComponent<ViewMediafile>
|
||||
this.mediaManage.getFontActions().subscribe(action => {
|
||||
this.fontActions = action;
|
||||
});
|
||||
this.setFulltextFilter();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -291,4 +304,18 @@ export class MediafileListComponent extends ListViewBaseComponent<ViewMediafile>
|
||||
this.editFile = false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Overwrites the dataSource's string filter with a case-insensitive search
|
||||
* in the file name property
|
||||
*/
|
||||
private setFulltextFilter(): void {
|
||||
this.dataSource.filterPredicate = (data, filter) => {
|
||||
if (!data || !data.title) {
|
||||
return false;
|
||||
}
|
||||
filter = filter ? filter.toLowerCase() : '';
|
||||
return data.title.toLowerCase().indexOf(filter) >= 0;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ import { Mediafile } from 'app/shared/models/mediafiles/mediafile';
|
||||
import { ViewMediafile } from '../models/view-mediafile';
|
||||
import { StorageService } from 'app/core/core-services/storage.service';
|
||||
import { MediafileRepositoryService } from 'app/core/repositories/mediafiles/mediafile-repository.service';
|
||||
import { OperatorService } from 'app/core/core-services/operator.service';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
@ -12,16 +13,10 @@ import { MediafileRepositoryService } from 'app/core/repositories/mediafiles/med
|
||||
export class MediafileFilterListService extends BaseFilterListService<Mediafile, ViewMediafile> {
|
||||
protected name = 'Mediafile';
|
||||
|
||||
public filterOptions: OsFilter[] = [
|
||||
{
|
||||
property: 'is_hidden',
|
||||
label: 'Hidden',
|
||||
options: [
|
||||
{ condition: true, label: 'is hidden' },
|
||||
{ condition: false, label: 'is not hidden', isActive: true }
|
||||
]
|
||||
},
|
||||
{
|
||||
/**
|
||||
* A filter checking if a file is a pdf or not
|
||||
*/
|
||||
public pdfOption: OsFilter = {
|
||||
property: 'type',
|
||||
label: 'Is PDF',
|
||||
options: [
|
||||
@ -34,11 +29,28 @@ export class MediafileFilterListService extends BaseFilterListService<Mediafile,
|
||||
label: 'Is no PDF file'
|
||||
}
|
||||
]
|
||||
}
|
||||
];
|
||||
};
|
||||
|
||||
public constructor(store: StorageService, repo: MediafileRepositoryService) {
|
||||
/**
|
||||
* A filter checking if a file is hidden. Only included if the operator has permission to see hidden files
|
||||
*/
|
||||
public hiddenOptions: OsFilter = {
|
||||
property: 'is_hidden',
|
||||
label: 'Hidden',
|
||||
options: [{ condition: true, label: 'is hidden' }, { condition: false, label: 'is not hidden', isActive: true }]
|
||||
};
|
||||
|
||||
/**
|
||||
* Constructor. Sets the filter options according to permissions
|
||||
* @param store
|
||||
* @param repo
|
||||
* @param operator
|
||||
*/
|
||||
public constructor(store: StorageService, repo: MediafileRepositoryService, operator: OperatorService) {
|
||||
super(store, repo);
|
||||
this.updateFilterDefinitions(this.filterOptions);
|
||||
const filterOptions = operator.hasPerms('mediafiles.can_see_hidden')
|
||||
? [this.hiddenOptions, this.pdfOption]
|
||||
: [this.pdfOption];
|
||||
this.updateFilterDefinitions(filterOptions);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user