Skip to content
This repository has been archived by the owner on Sep 7, 2020. It is now read-only.

Commit

Permalink
refactor(*): Add more tslint rules
Browse files Browse the repository at this point in the history
  • Loading branch information
Toilal committed Apr 27, 2017
1 parent 6535b72 commit f3cd7e7
Show file tree
Hide file tree
Showing 38 changed files with 387 additions and 324 deletions.
2 changes: 1 addition & 1 deletion build/webpack.dev.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ module.exports = merge(baseWebpackConfig, {
// devtool option doesn't output typescript sourcemaps to karma
new webpack.SourceMapDevToolPlugin({
filename: null, // if no value is provided the sourcemap is inlined
test: /\.(ts|js)($|\?)/i // process .js and .ts files only
test: /\.(ts|js|html)($|\?)/i // process .js and .ts files only
})
]
})
Expand Down
2 changes: 1 addition & 1 deletion build/webpack.test.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ var webpackConfig = merge(baseConfig, {
// devtool option doesn't output typescript sourcemaps to karma
new webpack.SourceMapDevToolPlugin({
filename: null, // if no value is provided the sourcemap is inlined
test: /\.(ts|js)($|\?)/i // process .js and .ts files only
test: /\.(ts|js|html)($|\?)/i // process .js and .ts files only
})
]
})
Expand Down
3 changes: 1 addition & 2 deletions src/core/logic/calendar/calendar.factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -417,8 +417,7 @@ export class GanttCalendar {
let minDate: moment.Moment;
let maxDate: moment.Moment;

for (let i = 0; i < timeFrames.length; i++) {
let timeFrame = timeFrames[i];
for (let timeFrame of timeFrames) {
if (minDate === undefined || minDate > timeFrame.start) {
minDate = timeFrame.start;
}
Expand Down
11 changes: 4 additions & 7 deletions src/core/logic/column/column.factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ export class GanttColumn {
visibleTimeFrames: TimeFrame[] = [];
daysTimeFrames: { [dateKey: string]: TimeFrame[] } = {};

currentDate: boolean = false;
cropped: boolean = false;
currentDate = false;
cropped = false;

constructor(date: moment.Moment,
endDate: moment.Moment,
Expand Down Expand Up @@ -141,8 +141,7 @@ export class GanttColumn {

if (this.timeFramesNonWorkingMode === 'cropped' || this.timeFramesWorkingMode === 'cropped') {
let timeFramesWidth = 0;
for (let j = 0; j < this.timeFrames.length; j++) {
let aTimeFrame = this.timeFrames[j];
for (let aTimeFrame of this.timeFrames) {
if (!aTimeFrame.working && this.timeFramesNonWorkingMode !== 'cropped' ||
aTimeFrame.working && this.timeFramesWorkingMode !== 'cropped') {
timeFramesWidth += aTimeFrame.width;
Expand All @@ -156,9 +155,7 @@ export class GanttColumn {

let allCropped = true;

for (let j = 0; j < this.timeFrames.length; j++) {
let bTimeFrame = this.timeFrames[j];

for (let bTimeFrame of this.timeFrames) {
if (!bTimeFrame.working && this.timeFramesNonWorkingMode !== 'cropped' ||
bTimeFrame.working && this.timeFramesWorkingMode !== 'cropped') {
bTimeFrame.left = (bTimeFrame.left - croppedWidth) * croppedRatio;
Expand Down
12 changes: 6 additions & 6 deletions src/core/logic/column/columnsManager.factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ export class GanttColumnsManager {
* @param extended
* @returns {any}
*/
getLastColumn(extended: boolean = false) {
getLastColumn(extended = false) {
let columns = this.columns;
if (extended) {
columns = this.nextColumns;
Expand All @@ -268,7 +268,7 @@ export class GanttColumnsManager {
* @param extended
* @returns {any}
*/
getFirstColumn(extended: boolean = false) {
getFirstColumn(extended = false) {
let columns = this.columns;
if (extended) {
columns = this.previousColumns;
Expand Down Expand Up @@ -336,8 +336,8 @@ export class GanttColumnsManager {
let widthFactor = newWidth / currentWidth;

GanttColumnsManager.ganttLayout.setColumnsWidthFactor(columns, widthFactor);
for (let i = 0; i < headers.length; i++) {
GanttColumnsManager.ganttLayout.setColumnsWidthFactor(headers[i], widthFactor);
for (let header of headers) {
GanttColumnsManager.ganttLayout.setColumnsWidthFactor(header, widthFactor);
}
// previous and next columns will be generated again on need.
previousColumns.splice(0, this.previousColumns.length);
Expand Down Expand Up @@ -452,8 +452,8 @@ export class GanttColumnsManager {
}
for (i = 0; i < this.visibleHeaders.length; i++) {
let headerRow = this.visibleHeaders[i];
for (let j = 0; j < headerRow.length; j++) {
headerRow[j].updateView();
for (let headerRowItem of headerRow) {
headerRowItem.updateView();
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/core/logic/column/headersGenerator.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ export default class GanttHeadersGenerator {
}

let headers = [];
for (let i = 0; i < headerNames.length; i++) {
headers.push(this.generateHeaders(columnsManager, headerNames[i]));
for (let headerName of headerNames) {
headers.push(this.generateHeaders(columnsManager, headerName));
}

return headers;
Expand Down
4 changes: 2 additions & 2 deletions src/core/logic/gantt.factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ export class Gantt {

originalWidth: number;
width: number;
rendered: boolean = false;
isRefreshingColumns: boolean = false;
rendered = false;
isRefreshingColumns = false;

constructor($scope: IScope, $element: IAugmentedJQuery) {
this.$scope = $scope;
Expand Down
6 changes: 3 additions & 3 deletions src/core/logic/row/row.factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export class GanttRow {
this.visibleTasks = [];
};

addTaskImpl(task: GanttTask, viewOnly: boolean = false) {
addTaskImpl(task: GanttTask, viewOnly = false) {
this.tasksMap[task.model.id] = task;
this.tasks.push(task);

Expand All @@ -59,7 +59,7 @@ export class GanttRow {
};

// Adds a task to a specific row. Merges the task if there is already one with the same id
addTask(taskModel: GanttTaskModel, viewOnly: boolean = false) {
addTask(taskModel: GanttTaskModel, viewOnly = false) {
// Copy to new task (add) or merge with existing (update)
let task;
let isUpdate = false;
Expand Down Expand Up @@ -92,7 +92,7 @@ export class GanttRow {
};

// Removes the task from the existing row and adds it to he current one
moveTaskToRow(task: GanttTask, viewOnly: boolean = false) {
moveTaskToRow(task: GanttTask, viewOnly = false) {
(this.rowsManager.gantt.api as any).tasks.raise.beforeViewRowChange(task, this);
if (!viewOnly) {
(this.rowsManager.gantt.api as any).tasks.raise.beforeRowChange(task, this);
Expand Down
15 changes: 7 additions & 8 deletions src/core/logic/row/rowsManager.factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -404,8 +404,7 @@ export class GanttRowsManager {
let tasks = [];
let visibleTasks = [];

for (let i = 0; i < this.rows.length; i++) {
let row = this.rows[i];
for (let row of this.rows) {
oldFilteredTasks = oldFilteredTasks.concat(row.filteredTasks);
row.updateVisibleTasks();
filteredTasks = filteredTasks.concat(row.filteredTasks);
Expand Down Expand Up @@ -435,9 +434,9 @@ export class GanttRowsManager {
from = from ? moment(from) : from;

let minRowFrom = from;
for (let i = 0; i < this.rows.length; i++) {
if (minRowFrom === undefined || minRowFrom > this.rows[i].from) {
minRowFrom = this.rows[i].from; // TODO: Corriger la type dans la version 1.x
for (let row of this.rows) {
if (minRowFrom === undefined || minRowFrom > row.from) {
minRowFrom = row.from;
}
}
if (minRowFrom && (!from || minRowFrom < from)) {
Expand All @@ -450,9 +449,9 @@ export class GanttRowsManager {
to = to ? moment(to) : to;

let maxRowTo = to;
for (let i = 0; i < this.rows.length; i++) {
if (maxRowTo === undefined || maxRowTo < this.rows[i].to) {
maxRowTo = this.rows[i].to;
for (let row of this.rows) {
if (maxRowTo === undefined || maxRowTo < row.to) {
maxRowTo = row.to;
}
}
let toDate = this.gantt.options.value('toDate');
Expand Down
1 change: 1 addition & 0 deletions src/core/logic/task/task.factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ export class GanttTask {
if (this.model.priority > 0) {
let priority = this.model.priority;
let children = this.$element.children();
// tslint:disable:prefer-for-of
for (let i = 0; i < children.length; i++) {
angular.element(children[i]).css('z-index', priority);
}
Expand Down
2 changes: 1 addition & 1 deletion src/core/logic/util/arrays.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export default class GanttArrays {
return array;
}

getRemovedIds<T>(newArray: T[], oldArray: T[], idProperty: string = 'id') {
getRemovedIds<T>(newArray: T[], oldArray: T[], idProperty = 'id') {
let i;
let l;
let removedIds = [];
Expand Down
7 changes: 3 additions & 4 deletions src/core/logic/util/hierarchy.factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,7 @@ export class GanttHierarchy {

if (row.model.children !== undefined) {
let children = row.model.children;
for (let j = 0; j < children.length; j++) {
let childRowNameOrId = children[j];
for (let childRowNameOrId of children) {
let childRow = this.nameToRow[childRowNameOrId];
if (childRow === undefined) {
childRow = this.idToRow[childRowNameOrId];
Expand Down Expand Up @@ -99,8 +98,8 @@ export class GanttHierarchy {
let children = this.children(row);
descendants.push.apply(descendants, children);
if (children !== undefined) {
for (let i = 0; i < children.length; i++) {
let childDescendants = this.descendants(children[i]);
for (let child of children) {
let childDescendants = this.descendants(child);
descendants.push.apply(descendants, childDescendants);
}
}
Expand Down
8 changes: 7 additions & 1 deletion src/core/ui/scroll/scrollable.directive.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
import moment from 'moment';
import {ITimeoutService} from 'angular';
import {GanttDebounce} from '../util/debounce.factory';
import {GanttDirectiveBuilder} from '../util/directiveBuilder.factory';

export default function (GanttDirectiveBuilder, $timeout, ganttDebounce) {
export default function (GanttDirectiveBuilder: {new(directiveName: string, templateUrl?: string, require?: string | string[], restrict?: string): GanttDirectiveBuilder},
$timeout: ITimeoutService,
ganttDebounce: GanttDebounce) {
'ngInject';

let builder = new GanttDirectiveBuilder('ganttScrollable');
builder.controller = function ($scope, $element) {
$scope.gantt.scroll.$element = $element;
Expand Down
11 changes: 9 additions & 2 deletions src/core/ui/util/debounce.factory.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
export default function ($timeout) {
import {ITimeoutService} from 'angular';

export interface GanttDebounce {
(fn: any, timeout?: number, invokeApply?: boolean): Function;
}

export default function ($timeout: ITimeoutService): GanttDebounce {
'ngInject';
function debounce(fn, timeout, invokeApply) {

function debounce(fn: any, timeout: number, invokeApply = false): Function {
let nthCall = 0;
return function () {
let self = this;
Expand Down
90 changes: 90 additions & 0 deletions src/core/ui/util/directiveBuilder.factory.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
import {IControllerService, ITemplateCacheService} from 'angular';

export class GanttDirectiveBuilder {
static $templateCache: ITemplateCacheService;

directiveName: string;
templateUrl: string;
require: string | string[];
restrict: string;

controller: IControllerService;
scope: boolean;
transclude: boolean;
replace: boolean;

constructor(directiveName: string, templateUrl?: string, require: string | string[] = '^gantt', restrict = 'E') {
this.directiveName = directiveName;
this.templateUrl = templateUrl === undefined ? 'template/' + directiveName + '.tmpl.html' : templateUrl;
this.require = require === undefined ? '^gantt' : require;
this.restrict = restrict === undefined ? 'E' : restrict;
this.scope = false;
this.transclude = true;
this.replace = true;
};

build() {
let directiveName = this.directiveName;
let templateUrl = this.templateUrl;
let controllerFunction = this.controller;

let directive = {
restrict: this.restrict,
require: this.require,
transclude: this.transclude,
replace: this.replace,
scope: this.scope,
templateUrl: function (tElement, tAttrs) {
if (tAttrs.templateUrl !== undefined) {
templateUrl = tAttrs.templateUrl;
}
if (tAttrs.template !== undefined) {
GanttDirectiveBuilder.$templateCache.put(templateUrl, tAttrs.template);
}
return templateUrl;
},
compile: function () {
return {
pre: function preLink(scope, iElement, iAttrs, controller) {
scope.gantt.api.directives.raise.preLink(directiveName, scope, iElement, iAttrs, controller);
},
post: function postLink(scope, iElement, iAttrs, controller) {
scope.gantt.api.directives.raise.postLink(directiveName, scope, iElement, iAttrs, controller);

}
};
},
controller: ['$scope', '$element', '$attrs', function ($scope, $element, $attrs) {
let controller = this;

if (controllerFunction !== undefined) {
controllerFunction($scope, $element, $attrs, controller);
}

$scope.gantt.api.directives.raise.controller(directiveName, $scope, $element, $attrs, controller);
$scope.$on('$destroy', function () {
$scope.gantt.api.directives.raise.destroy(directiveName, $scope, $element, $attrs, controller);
});

$scope.$applyAsync(function () {
$scope.gantt.api.directives.raise.new(directiveName, $scope, $element, $attrs, controller);
});
}]
};

if (!templateUrl) {
delete directive.templateUrl;
delete directive.replace;
delete directive.transclude;
}

return directive;
};
}

export default function ($templateCache: ITemplateCacheService) {
'ngInject';

GanttDirectiveBuilder.$templateCache = $templateCache;
return GanttDirectiveBuilder;
}
Loading

0 comments on commit f3cd7e7

Please sign in to comment.