Skip to content

Commit

Permalink
fix: filter assets by id paste
Browse files Browse the repository at this point in the history
  • Loading branch information
felixroos committed Sep 13, 2019
1 parent c86d1e9 commit fe14651
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 9 deletions.
Expand Up @@ -18,7 +18,12 @@
></ec-upload-select>
<div data-grid="small-gutter" *ngIf="active && sdk.apiResolved">
<div data-col="6@md">
<ec-searchbar #searchbar [listComponent]="resourceList" [list]="resourceList"></ec-searchbar>
<ec-searchbar
#searchbar
[listComponent]="resourceList"
[list]="resourceList"
(pasted)="pasted($event, resourceList)"
></ec-searchbar>
</div>
<div data-col="6@md" *ngIf="!isLegacy()">
<div data-grid="small-gutter">
Expand Down Expand Up @@ -54,6 +59,17 @@
[loader]="popLoader"
class="ec-asset-list"
>
<div data-ec-list-empty-filtered>
<p>
{{ 'list.filter.noResults' | symbol }}
<a (click)="resourceList?.list?.clearFilter()">{{ 'list.filter.reset' | symbol }}</a>
</p>
<a
*ngIf="!!listConfig.getFilteredID(resourceList?.list)"
(click)="selectID(listConfig.getFilteredID(resourceList?.list))"
>Select ID</a
>
</div>
</ec-resource-list>
<!-- (changed)="searchbar.updatedList($event)" -->
</div>
Expand Down
Expand Up @@ -10,7 +10,7 @@ import {
ViewChild,
} from '@angular/core';
import { Item, Selection } from '@ec.components/core';
import { PopComponent, PopService, SearchbarComponent, SymbolService } from '@ec.components/ui';
import { PopComponent, PopService, SearchbarComponent, SymbolService, ListConfigService } from '@ec.components/ui';
import PublicAssetResource from 'ec.sdk/lib/resources/publicAPI/PublicAssetResource';
import PublicTagResource from 'ec.sdk/lib/resources/publicAPI/PublicTagResource';
import { Subject } from 'rxjs';
Expand Down Expand Up @@ -76,6 +76,7 @@ export class AssetListPopComponent extends PopComponent implements OnInit {
/** Injects auth service and calls super constructor. */
constructor(
public popService: PopService,
public listConfig: ListConfigService,
public fileService: FileService,
public sdk: SdkService,
public elementRef: ElementRef,
Expand All @@ -85,6 +86,10 @@ export class AssetListPopComponent extends PopComponent implements OnInit {
super(popService, elementRef, cdr);
}


pasted(e, list) {
}

/** Changes the assetGroupID to the given value, emits groupChange */
setGroup(group) {
if (!group) {
Expand Down Expand Up @@ -140,6 +145,14 @@ export class AssetListPopComponent extends PopComponent implements OnInit {
);
}

selectID(id) {
if (this.getGroupRelation() === 'legacyAsset') {
console.warn('This is not supported by legacy assets');
return;
}
this.resourceList.list.load({ filter: { assetID: id } });
}

/** emits columnClicked event or toggles selection if no observers. */
select($event) {
if (this.columnClicked.observers.length) {
Expand Down
Expand Up @@ -476,9 +476,10 @@ export class ResourceConfig {
},
assetID: {
label: this.symbol.resolve('dmAsset.field.label.assetID'),
list: false,
filterOperator: 'exact',
hideInList: true,
form: false,
immutable: true,
immutable: true
},
title: {
label: this.symbol.resolve('field.label.title'),
Expand Down Expand Up @@ -660,7 +661,7 @@ export class ResourceConfig {
token: {},
};

constructor(private symbol: SymbolService, private typeConfig: TypeConfigService) {}
constructor(private symbol: SymbolService, private typeConfig: TypeConfigService) { }
/** Returns the CrudConfig for the given relation name. */
get(relationName: string): CrudConfig<Resource> {
const resolved = relationName.split('.').reduce((position: Object, key) => {
Expand Down
8 changes: 4 additions & 4 deletions packages/data/src/lib/resource-list/resource-list.ts
Expand Up @@ -32,7 +32,7 @@ export class ResourceList extends List<Resource> {
}

/** Returns true if the field of the given property has rawFilter set to true */
protected static isRawFilter(property: string, fields: Array<Field>): boolean {
public isRawFilter(property: string, fields: Array<Field> = this.fields): boolean {
if (!fields) {
return false;
}
Expand Down Expand Up @@ -119,11 +119,11 @@ export class ResourceList extends List<Resource> {
for (const property in filter) {
if (filter.hasOwnProperty(property)) {
Object.assign(options, {
[property]: ResourceList.isRawFilter(property, this.fields)
[property]: this.isRawFilter(property, this.fields)
? filter[property]
: {
[ResourceList.getFilterOperator(property, this.fields)]: filter[property],
},
[ResourceList.getFilterOperator(property, this.fields)]: filter[property],
},
});
}
}
Expand Down
14 changes: 14 additions & 0 deletions packages/ui/src/lib/list/list-config.service.ts
Expand Up @@ -58,4 +58,18 @@ export class ListConfigService {
});
}
}

getFilteredID(list) {
if (!list || !list.config || !list.config.filter) {
return;
}
return Object.keys(list.config.filter).reduce((id, property) => {
if (!id && list.config.identifierPattern && list.config.filter &&
typeof list.config.filter[property] === 'string' &&
list.config.filter[property].match(list.config.identifierPattern)) {
return list.config.filter[property];
}
return id;
}, null);
}
}

0 comments on commit fe14651

Please sign in to comment.