Skip to content

Commit

Permalink
refactor(typescript): drop prefix from interface
Browse files Browse the repository at this point in the history
This is keeping with best practice.

Also works well when using the new typescript `Partial` which create type
aliases which are not interfaces
  • Loading branch information
ccrowhurstram committed Dec 21, 2016
1 parent 6e810ba commit 2e5bf71
Show file tree
Hide file tree
Showing 39 changed files with 394 additions and 394 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { IComponentOptions } from 'angular';
import { IColumnDef } from 'ng-table';
import { ColumnDef } from 'ng-table';

export class ColumnPickerComponent implements IComponentOptions {
templateUrl = './column-picker.html';
Expand All @@ -9,5 +9,5 @@ export class ColumnPickerComponent implements IComponentOptions {
}
}
class ColumnPickerController {
columns: IColumnDef[];
columns: ColumnDef[];
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { IComponentOptions, IComponentController } from 'angular';
import { IColumnDef, NgTableParams } from 'ng-table';
import { ColumnDef, NgTableParams } from 'ng-table';
import { Person } from '../shared';

export class DeclarativeTableComponent implements IComponentOptions {
Expand All @@ -10,7 +10,7 @@ export class DeclarativeTableComponent implements IComponentOptions {
};
}
class DeclarativeTableController implements IComponentController {
exportedColumns: IColumnDef[];
exportedColumns: ColumnDef[];
data: Person[];
tableParams = new NgTableParams<Person>({});
$onInit(){
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { IComponentOptions, IComponentController } from 'angular';
import { IDynamicTableColDef, NgTableParams } from 'ng-table';
import { DynamicTableColDef, NgTableParams } from 'ng-table';
import { Person } from '../shared';

interface IExtendedDynamicTableColDef extends IDynamicTableColDef {
interface ExtendedDynamicTableColDef extends DynamicTableColDef {
field: string;
}

Expand All @@ -14,7 +14,7 @@ export class DynamicTableComponent implements IComponentOptions {
};
}
class DynamicTableController implements IComponentController {
columns: IExtendedDynamicTableColDef[] = [
columns: ExtendedDynamicTableColDef[] = [
{ field: 'name', title: 'Name', show: true, filter: { name: 'text' }, sortable: 'name' },
{ field: 'age', title: 'Age', show: true, filter: { age: 'number' }, sortable: 'age' },
{ field: 'money', title: 'Money', show: true, filter: { money: 'number' }, sortable: 'money' }
Expand Down
16 changes: 8 additions & 8 deletions src/browser/ngTable.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
import { IAugmentedJQuery, IDirective, IQService, IParseService, IPromise, IScope } from 'angular';
import * as ng1 from 'angular';
import {
IColumnDef, ColumnFieldContext, IColumnField, IFilterTemplateDefMap, SelectData, ITableInputAttributes
ColumnDef, ColumnFieldContext, ColumnField, FilterTemplateDefMap, SelectData, TableInputAttributes
} from './public-interfaces';
import { NgTableController } from './ngTableController';

interface IScopeExtensions {
$columns: IColumnDef[]
interface ScopeExtensions {
$columns: ColumnDef[]
}

ngTable.$inject = ['$q', '$parse'];
Expand Down Expand Up @@ -45,7 +45,7 @@ export function ngTable($q: IQService, $parse: IParseService) : IDirective {
scope: true,
controller: 'ngTableController',
compile: function(element: IAugmentedJQuery) {
let columns: IColumnDef[] = [],
let columns: ColumnDef[] = [],
i = 0,
dataRow: JQuery,
groupRow: JQuery
Expand Down Expand Up @@ -79,7 +79,7 @@ export function ngTable($q: IQService, $parse: IParseService) : IDirective {
}
};

const parsedAttribute = function<T>(attr: string): IColumnField<T> {
const parsedAttribute = function<T>(attr: string): ColumnField<T> {
const expr = getAttrValue(attr);
if (!expr){
return undefined;
Expand All @@ -102,7 +102,7 @@ export function ngTable($q: IQService, $parse: IParseService) : IDirective {
localValue = value;
}
};
return getter as IColumnField<T>;
return getter as ColumnField<T>;
};
const titleExpr = getAttrValue('title-alt') || getAttrValue('title');
if (titleExpr){
Expand All @@ -117,7 +117,7 @@ export function ngTable($q: IQService, $parse: IParseService) : IDirective {
headerTitle: parsedAttribute<string>('header-title'),
sortable: parsedAttribute<string | boolean>('sortable'),
'class': parsedAttribute<string>('header-class'),
filter: parsedAttribute<IFilterTemplateDefMap>('filter'),
filter: parsedAttribute<FilterTemplateDefMap>('filter'),
groupable: parsedAttribute<string | boolean>('groupable'),
headerTemplateURL: parsedAttribute<string | boolean>('header'),
filterData: parsedAttribute<IPromise<SelectData> | SelectData>('filter-data'),
Expand All @@ -132,7 +132,7 @@ export function ngTable($q: IQService, $parse: IParseService) : IDirective {
setAttrValue('ng-if', '$columns[' + (columns.length - 1) + '].show(this)');
}
});
return function(scope: IScope & IScopeExtensions, element: IAugmentedJQuery, attrs: ITableInputAttributes, controller: NgTableController<any, IColumnDef>) {
return function(scope: IScope & ScopeExtensions, element: IAugmentedJQuery, attrs: TableInputAttributes, controller: NgTableController<any, ColumnDef>) {
scope.$columns = columns = controller.buildColumns(columns);

controller.setupBindingsToInternalScope(attrs.ngTable);
Expand Down
8 changes: 4 additions & 4 deletions src/browser/ngTableColumn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import { IScope } from 'angular';
import * as ng1 from 'angular';
import { IColumnDef, IDynamicTableColDef } from './public-interfaces';
import { ColumnDef, DynamicTableColDef } from './public-interfaces';

/**
* @private
Expand All @@ -21,7 +21,7 @@ function isScopeLike(object: any) {
* @private
* Service to construct a $column definition used by {@link ngTable ngTable} directive
*/
export class NgTableColumn<TCol extends IColumnDef | IDynamicTableColDef> {
export class NgTableColumn<TCol extends ColumnDef | DynamicTableColDef> {
static $inject: string[] = [];

/**
Expand All @@ -32,7 +32,7 @@ export class NgTableColumn<TCol extends IColumnDef | IDynamicTableColDef> {
* @param columns a reference to the $columns array to make available on the context supplied to the
* $column getter methods
*/
buildColumn(column: TCol, defaultScope: IScope, columns: IColumnDef[]): IColumnDef {
buildColumn(column: TCol, defaultScope: IScope, columns: ColumnDef[]): ColumnDef {
// note: we're not modifying the original column object. This helps to avoid unintended side affects
const extendedCol = Object.create(column);
const defaults = this.createDefaults();
Expand Down Expand Up @@ -90,7 +90,7 @@ export class NgTableColumn<TCol extends IColumnDef | IDynamicTableColDef> {
extendedCol[prop] = getterSetter;
}
}
return extendedCol as IColumnDef;
return extendedCol as ColumnDef;
}

private createDefaults() {
Expand Down
10 changes: 5 additions & 5 deletions src/browser/ngTableColumnsBinding.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
*/

import { IAugmentedJQuery, IAttributes, IDirective, IParseService } from 'angular';
import { ITableScope } from './ngTableController';
import { IColumnDef } from './public-interfaces';
import { TableScope } from './ngTableController';
import { ColumnDef } from './public-interfaces';

/**
* @private
*/
interface IInputAttributes extends IAttributes {
interface InputAttributes extends IAttributes {
ngTableColumnsBinding: string;
}

Expand All @@ -39,10 +39,10 @@ export function ngTableColumnsBinding<T>($parse: IParseService) : IDirective {
};
return directive;

function linkFn($scope: ITableScope<T>, $element: IAugmentedJQuery, $attrs: IInputAttributes){
function linkFn($scope: TableScope<T>, $element: IAugmentedJQuery, $attrs: InputAttributes){
const setter = $parse($attrs.ngTableColumnsBinding).assign;
if (setter){
$scope.$watch<IColumnDef[]>('$columns', newColumns => {
$scope.$watch<ColumnDef[]>('$columns', newColumns => {
const shallowClone = (newColumns || []).slice(0);
setter($scope, shallowClone);
});
Expand Down
24 changes: 12 additions & 12 deletions src/browser/ngTableController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@ import {
} from 'angular';
import * as ng1 from 'angular';
import {
DataResult, DataResults, IDataRowGroup, GroupedDataResults, NgTableParams, NgTableEventsChannel,
IPageButton
DataResult, DataResults, DataRowGroup, GroupedDataResults, NgTableParams, NgTableEventsChannel,
PageButton
} from '../core';
import { IColumnDef, IDynamicTableColDef, SelectData, ITableInputAttributes } from './public-interfaces';
import { ColumnDef, DynamicTableColDef, SelectData, TableInputAttributes } from './public-interfaces';
import { NgTableColumn } from './ngTableColumn';

/**
* @private
*/
export interface ITableScope<T> extends IScope {
$columns: IColumnDef[];
export interface TableScope<T> extends IScope {
$columns: ColumnDef[];
$loading: boolean;
$filterRow: {
disabled: boolean;
Expand All @@ -33,7 +33,7 @@ export interface ITableScope<T> extends IScope {
show: boolean;
};
show_filter: boolean;
pages: IPageButton[];
pages: PageButton[];
templates: {
header: string;
pagination: string;
Expand All @@ -44,7 +44,7 @@ export interface ITableScope<T> extends IScope {
/**
* The controller for the {@link ngTable ngTable} and {@link ngTableDynamic ngTableDynamic} directives
*/
export class NgTableController<TParams, TCol extends IColumnDef | IDynamicTableColDef> {
export class NgTableController<TParams, TCol extends ColumnDef | DynamicTableColDef> {
static $inject = [
'$scope', '$timeout', '$parse', '$compile', '$attrs', '$element', '$document', 'ngTableColumn', 'ngTableEventsChannel'
];
Expand All @@ -57,11 +57,11 @@ export class NgTableController<TParams, TCol extends IColumnDef | IDynamicTableC
});
}
constructor(
private $scope: ITableScope<TParams>,
private $scope: TableScope<TParams>,
$timeout: ITimeoutService,
private $parse: IParseService,
private $compile: ICompileService,
private $attrs: IAttributes & ITableInputAttributes,
private $attrs: IAttributes & TableInputAttributes,
private $element: IAugmentedJQuery,
private $document: IDocumentService,
private ngTableColumn: NgTableColumn<TCol>,
Expand Down Expand Up @@ -156,7 +156,7 @@ export class NgTableController<TParams, TCol extends IColumnDef | IDynamicTableC
}
}

loadFilterData($columns: IColumnDef[]) {
loadFilterData($columns: ColumnDef[]) {
ng1.forEach($columns, ($column) => {
const result = $column.filterData(this.$scope);
if (!result) {
Expand Down Expand Up @@ -186,9 +186,9 @@ export class NgTableController<TParams, TCol extends IColumnDef | IDynamicTableC
}
}

buildColumns(columns: TCol[]): IColumnDef[] {
buildColumns(columns: TCol[]): ColumnDef[] {
// todo: use strictNullChecks and remove guard clause
const result: IColumnDef[] = [];
const result: ColumnDef[] = [];
(columns || []).forEach(col => {
result.push(this.ngTableColumn.buildColumn(col, this.$scope, result));
});
Expand Down
10 changes: 5 additions & 5 deletions src/browser/ngTableDynamic.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@

import { IAugmentedJQuery, IDirective, IScope } from 'angular';
import * as ng1 from 'angular';
import { IColumnDef, IDynamicTableColDef, ITableInputAttributes } from './public-interfaces';
import { ColumnDef, DynamicTableColDef, TableInputAttributes } from './public-interfaces';
import { NgTableController } from './ngTableController';

interface IScopeExtensions {
$columns: IColumnDef[]
interface ScopeExtensions {
$columns: ColumnDef[]
}

ngTableDynamic.$inject = [];
Expand Down Expand Up @@ -68,13 +68,13 @@ export function ngTableDynamic () : IDirective{
el.attr('ng-if', '$columns[$index].show(this)');
}
});
return function (scope: IScope & IScopeExtensions, element: IAugmentedJQuery, attrs: ITableInputAttributes, controller: NgTableController<any, IDynamicTableColDef>) {
return function (scope: IScope & ScopeExtensions, element: IAugmentedJQuery, attrs: TableInputAttributes, controller: NgTableController<any, DynamicTableColDef>) {
const expr = controller.parseNgTableDynamicExpr(attrs.ngTableDynamic);

controller.setupBindingsToInternalScope(expr.tableParams);
controller.compileDirectiveTemplates();

scope.$watchCollection<IDynamicTableColDef[]>(expr.columns, (newCols/*, oldCols*/) => {
scope.$watchCollection<DynamicTableColDef[]>(expr.columns, (newCols/*, oldCols*/) => {
scope.$columns = controller.buildColumns(newCols);
controller.loadFilterData(scope.$columns);
});
Expand Down
14 changes: 7 additions & 7 deletions src/browser/ngTableFilterConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@

import * as ng1 from 'angular';
import { IServiceProvider, auto } from 'angular';
import { IFilterConfigValues, IFilterTemplateDef } from './public-interfaces';
import { FilterConfigValues, FilterTemplateDef } from './public-interfaces';

/**
* The angular provider used to configure the behaviour of the `NgTableFilterConfig` service.
*/
export class NgTableFilterConfigProvider implements IServiceProvider {
static $inject = ['$injector'];
$get: () => NgTableFilterConfig;
private config: IFilterConfigValues;
private defaultConfig: IFilterConfigValues = {
private config: FilterConfigValues;
private defaultConfig: FilterConfigValues = {
defaultBaseUrl: 'ng-table/filters/',
defaultExt: '.html',
aliasUrls: {}
Expand All @@ -40,7 +40,7 @@ export class NgTableFilterConfigProvider implements IServiceProvider {
/**
* Set the config values used by `NgTableFilterConfig` service
*/
setConfig(customConfig: IFilterConfigValues) {
setConfig(customConfig: FilterConfigValues) {
const mergeConfig = ng1.extend({}, this.config, customConfig);
mergeConfig.aliasUrls = ng1.extend({}, this.config.aliasUrls, customConfig.aliasUrls);
this.config = mergeConfig;
Expand All @@ -57,7 +57,7 @@ export class NgTableFilterConfig {
/**
* Readonly copy of the final values used to configure the service.
*/
public readonly config: IFilterConfigValues
public readonly config: FilterConfigValues
) { }

/**
Expand All @@ -69,9 +69,9 @@ export class NgTableFilterConfig {

/**
* Return the url of the html filter template for the supplied definition and key.
* For more information see the documentation for {@link IFilterTemplateMap}
* For more information see the documentation for {@link FilterTemplateMap}
*/
getTemplateUrl(filterDef: string | IFilterTemplateDef, filterKey?: string) {
getTemplateUrl(filterDef: string | FilterTemplateDef, filterKey?: string) {
let filterName: string;
if (typeof filterDef !== 'string') {
filterName = filterDef.id;
Expand Down
12 changes: 6 additions & 6 deletions src/browser/ngTableFilterRowController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
*/

import { IScope } from 'angular';
import { IFilterTemplateDef, IFilterTemplateDefMap } from './public-interfaces';
import { FilterTemplateDef, FilterTemplateDefMap } from './public-interfaces';
import { NgTableFilterConfig } from './ngTableFilterConfig';

/**
* @private
*/
export interface IScopeExtensions {
getFilterPlaceholderValue(filterDef: string | IFilterTemplateDef, filterKey?: string): string;
export interface ScopeExtensions {
getFilterPlaceholderValue(filterDef: string | FilterTemplateDef, filterKey?: string): string;
}

/**
Expand All @@ -23,7 +23,7 @@ export interface IScopeExtensions {
export class NgTableFilterRowController {
static $inject = ['$scope', 'ngTableFilterConfig'];
config: NgTableFilterConfig;
constructor($scope: IScope & IScopeExtensions, ngTableFilterConfig: NgTableFilterConfig) {
constructor($scope: IScope & ScopeExtensions, ngTableFilterConfig: NgTableFilterConfig) {
this.config = ngTableFilterConfig;

// todo: stop doing this. Why?
Expand All @@ -33,7 +33,7 @@ export class NgTableFilterRowController {
$scope.getFilterPlaceholderValue = this.getFilterPlaceholderValue.bind(this);
}

getFilterCellCss(filter: IFilterTemplateDefMap, layout: string) {
getFilterCellCss(filter: FilterTemplateDefMap, layout: string) {
if (layout !== 'horizontal') {
return 's12';
}
Expand All @@ -43,7 +43,7 @@ export class NgTableFilterRowController {
return 's' + width;
}

getFilterPlaceholderValue(filterDef: string | IFilterTemplateDef, filterKey?: string) {
getFilterPlaceholderValue(filterDef: string | FilterTemplateDef, filterKey?: string) {
if (typeof filterDef === 'string') {
return '';
} else {
Expand Down
Loading

0 comments on commit 2e5bf71

Please sign in to comment.