Move gr-list-view-mixin to typescript
Change-Id: Ib01a1f25b4b0025b1bc3201c0dad5ea8d78a53ad
This commit is contained in:
@@ -15,51 +15,64 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {encodeURL, getBaseUrl} from '../../utils/url-util.js';
|
import {encodeURL, getBaseUrl} from '../../utils/url-util';
|
||||||
import {dedupingMixin} from '@polymer/polymer/lib/utils/mixin.js';
|
import {dedupingMixin} from '@polymer/polymer/lib/utils/mixin';
|
||||||
|
import {PolymerElement} from '@polymer/polymer';
|
||||||
|
import {Constructor} from '../../utils/common-util';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @polymer
|
* @polymer
|
||||||
* @mixinFunction
|
* @mixinFunction
|
||||||
*/
|
*/
|
||||||
export const ListViewMixin = dedupingMixin(superClass => {
|
export const ListViewMixin = dedupingMixin(
|
||||||
/**
|
<T extends Constructor<PolymerElement>>(
|
||||||
* @polymer
|
superClass: T
|
||||||
* @mixinClass
|
): T & Constructor<ListViewMixinInterface> => {
|
||||||
*/
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {Object} params
|
* @polymer
|
||||||
* @return {string}
|
* @mixinClass
|
||||||
*/
|
*/
|
||||||
getFilterValue(params) {
|
class Mixin extends superClass {
|
||||||
if (!params) { return ''; }
|
computeLoadingClass(loading: boolean): string {
|
||||||
return params.filter || '';
|
return loading ? 'loading' : '';
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param {Object} params
|
|
||||||
* @return {number}
|
|
||||||
*/
|
|
||||||
getOffsetValue(params) {
|
|
||||||
if (params && params.offset) {
|
|
||||||
return params.offset;
|
|
||||||
}
|
}
|
||||||
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