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
|
<os-head-bar
|
||||||
[mainButton]="true"
|
[mainButton]="canEdit"
|
||||||
[editMode]="editFile"
|
[editMode]="editFile"
|
||||||
[multiSelectMode]="isMultiSelect"
|
[multiSelectMode]="isMultiSelect"
|
||||||
(mainEvent)="onMainEvent()"
|
(mainEvent)="onMainEvent()"
|
||||||
@ -35,7 +35,7 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Menu -->
|
<!-- Menu -->
|
||||||
<div class="menu-slot">
|
<div class="menu-slot" *ngIf="canEdit">
|
||||||
<button type="button" mat-icon-button [matMenuTriggerFor]="mediafilesMenu">
|
<button type="button" mat-icon-button [matMenuTriggerFor]="mediafilesMenu">
|
||||||
<mat-icon>more_vert</mat-icon>
|
<mat-icon>more_vert</mat-icon>
|
||||||
</button>
|
</button>
|
||||||
@ -170,7 +170,7 @@
|
|||||||
<span translate>Deselect all</span>
|
<span translate>Deselect all</span>
|
||||||
</button>
|
</button>
|
||||||
<mat-divider></mat-divider>
|
<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>
|
<mat-icon>delete</mat-icon>
|
||||||
<span translate>Delete</span>
|
<span translate>Delete</span>
|
||||||
</button>
|
</button>
|
||||||
|
@ -15,6 +15,7 @@ import { Mediafile } from 'app/shared/models/mediafiles/mediafile';
|
|||||||
import { MediafileFilterListService } from '../../services/mediafile-filter.service';
|
import { MediafileFilterListService } from '../../services/mediafile-filter.service';
|
||||||
import { MediafilesSortListService } from '../../services/mediafiles-sort-list.service';
|
import { MediafilesSortListService } from '../../services/mediafiles-sort-list.service';
|
||||||
import { ViewportService } from 'app/core/ui-services/viewport.service';
|
import { ViewportService } from 'app/core/ui-services/viewport.service';
|
||||||
|
import { OperatorService } from 'app/core/core-services/operator.service';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Lists all the uploaded files.
|
* Lists all the uploaded files.
|
||||||
@ -55,6 +56,13 @@ export class MediafileListComponent extends ListViewBaseComponent<ViewMediafile>
|
|||||||
*/
|
*/
|
||||||
public fileToEdit: 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
|
* 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 mediaManage service to manage media files (setting images as logos)
|
||||||
* @param promptService prevent deletion by accident
|
* @param promptService prevent deletion by accident
|
||||||
* @param vp viewport Service to check screen size
|
* @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(
|
public constructor(
|
||||||
titleService: Title,
|
titleService: Title,
|
||||||
@ -85,7 +96,8 @@ export class MediafileListComponent extends ListViewBaseComponent<ViewMediafile>
|
|||||||
private promptService: PromptService,
|
private promptService: PromptService,
|
||||||
public vp: ViewportService,
|
public vp: ViewportService,
|
||||||
public filterService: MediafileFilterListService,
|
public filterService: MediafileFilterListService,
|
||||||
public sortService: MediafilesSortListService
|
public sortService: MediafilesSortListService,
|
||||||
|
private operator: OperatorService
|
||||||
) {
|
) {
|
||||||
super(titleService, translate, matSnackBar);
|
super(titleService, translate, matSnackBar);
|
||||||
|
|
||||||
@ -123,6 +135,7 @@ export class MediafileListComponent extends ListViewBaseComponent<ViewMediafile>
|
|||||||
this.mediaManage.getFontActions().subscribe(action => {
|
this.mediaManage.getFontActions().subscribe(action => {
|
||||||
this.fontActions = action;
|
this.fontActions = action;
|
||||||
});
|
});
|
||||||
|
this.setFulltextFilter();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -291,4 +304,18 @@ export class MediafileListComponent extends ListViewBaseComponent<ViewMediafile>
|
|||||||
this.editFile = false;
|
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 { ViewMediafile } from '../models/view-mediafile';
|
||||||
import { StorageService } from 'app/core/core-services/storage.service';
|
import { StorageService } from 'app/core/core-services/storage.service';
|
||||||
import { MediafileRepositoryService } from 'app/core/repositories/mediafiles/mediafile-repository.service';
|
import { MediafileRepositoryService } from 'app/core/repositories/mediafiles/mediafile-repository.service';
|
||||||
|
import { OperatorService } from 'app/core/core-services/operator.service';
|
||||||
|
|
||||||
@Injectable({
|
@Injectable({
|
||||||
providedIn: 'root'
|
providedIn: 'root'
|
||||||
@ -12,16 +13,10 @@ import { MediafileRepositoryService } from 'app/core/repositories/mediafiles/med
|
|||||||
export class MediafileFilterListService extends BaseFilterListService<Mediafile, ViewMediafile> {
|
export class MediafileFilterListService extends BaseFilterListService<Mediafile, ViewMediafile> {
|
||||||
protected name = 'Mediafile';
|
protected name = 'Mediafile';
|
||||||
|
|
||||||
public filterOptions: OsFilter[] = [
|
/**
|
||||||
{
|
* A filter checking if a file is a pdf or not
|
||||||
property: 'is_hidden',
|
*/
|
||||||
label: 'Hidden',
|
public pdfOption: OsFilter = {
|
||||||
options: [
|
|
||||||
{ condition: true, label: 'is hidden' },
|
|
||||||
{ condition: false, label: 'is not hidden', isActive: true }
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
property: 'type',
|
property: 'type',
|
||||||
label: 'Is PDF',
|
label: 'Is PDF',
|
||||||
options: [
|
options: [
|
||||||
@ -34,11 +29,28 @@ export class MediafileFilterListService extends BaseFilterListService<Mediafile,
|
|||||||
label: 'Is no PDF file'
|
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);
|
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