full text search for media file, some permission checks

This commit is contained in:
Maximilian Krambach 2019-02-12 15:32:59 +01:00
parent f3452d8904
commit 9160346ccc
3 changed files with 69 additions and 30 deletions

View File

@ -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>

View File

@ -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;
};
}
}

View File

@ -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,33 +13,44 @@ 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 }
]
},
{
property: 'type',
label: 'Is PDF',
options: [
{
condition: 'application/pdf',
label: 'Is PDF file'
},
{
condition: null,
label: 'Is no PDF file'
}
]
}
];
/**
* A filter checking if a file is a pdf or not
*/
public pdfOption: OsFilter = {
property: 'type',
label: 'Is PDF',
options: [
{
condition: 'application/pdf',
label: 'Is PDF file'
},
{
condition: null,
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);
}
}