Move gr-list-view-mixin to typescript
Change-Id: Ib01a1f25b4b0025b1bc3201c0dad5ea8d78a53ad
This commit is contained in:
@@ -15,51 +15,64 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import {encodeURL, getBaseUrl} from '../../utils/url-util.js';
|
||||
import {dedupingMixin} from '@polymer/polymer/lib/utils/mixin.js';
|
||||
import {encodeURL, getBaseUrl} from '../../utils/url-util';
|
||||
import {dedupingMixin} from '@polymer/polymer/lib/utils/mixin';
|
||||
import {PolymerElement} from '@polymer/polymer';
|
||||
import {Constructor} from '../../utils/common-util';
|
||||
|
||||
/**
|
||||
* @polymer
|
||||
* @mixinFunction
|
||||
*/
|
||||
export const ListViewMixin = dedupingMixin(superClass => {
|
||||
/**
|
||||
* @polymer
|
||||
* @mixinClass
|
||||
*/
|
||||
class Mixin extends superClass {
|
||||
computeLoadingClass(loading) {
|
||||
return loading ? 'loading' : '';
|
||||
}
|
||||
|
||||
computeShownItems(items) {
|
||||
return items.slice(0, 25);
|
||||
}
|
||||
|
||||
getUrl(path, item) {
|
||||
return getBaseUrl() + path + encodeURL(item, true);
|
||||
}
|
||||
|
||||
export const ListViewMixin = dedupingMixin(
|
||||
<T extends Constructor<PolymerElement>>(
|
||||
superClass: T
|
||||
): T & Constructor<ListViewMixinInterface> => {
|
||||
/**
|
||||
* @param {Object} params
|
||||
* @return {string}
|
||||
* @polymer
|
||||
* @mixinClass
|
||||
*/
|
||||
getFilterValue(params) {
|
||||
if (!params) { return ''; }
|
||||
return params.filter || '';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Object} params
|
||||
* @return {number}
|
||||
*/
|
||||
getOffsetValue(params) {
|
||||
if (params && params.offset) {
|
||||
return params.offset;
|
||||
class Mixin extends superClass {
|
||||
computeLoadingClass(loading: boolean): string {
|
||||
return loading ? 'loading' : '';
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return Mixin;
|
||||
});
|
||||
computeShownItems<T>(items: T[]): T[] {
|
||||
return items.slice(0, 25);
|
||||
}
|
||||
|
||||
getUrl(path: string, item: string) {
|
||||
return getBaseUrl() + path + encodeURL(item, true);
|
||||
}
|
||||
|
||||
getFilterValue(params: ListViewParams): string {
|
||||
if (!params) {
|
||||
return '';
|
||||
}
|
||||
return params.filter || '';
|
||||
}
|
||||
|
||||
getOffsetValue(params: ListViewParams): number {
|
||||
if (params && params.offset) {
|
||||
return params.offset;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return Mixin;
|
||||
}
|
||||
);
|
||||
|
||||
export interface ListViewMixinInterface {
|
||||
computeLoadingClass(loading: boolean): string;
|
||||
computeShownItems<T>(items: T[]): T[];
|
||||
getUrl(path: string, item: string): string;
|
||||
getFilterValue(params: ListViewParams): string;
|
||||
getOffsetValue(params: ListViewParams): number;
|
||||
}
|
||||
|
||||
export interface ListViewParams {
|
||||
filter?: string;
|
||||
offset?: number;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user