Skip to content

Commit

Permalink
feat(filters): change all private keyword to protected for extensabil…
Browse files Browse the repository at this point in the history
…ity (#679)

- also changed all services to readonly
  • Loading branch information
ghiscoding authored Jan 21, 2021
1 parent 7b95401 commit e5b5e8d
Show file tree
Hide file tree
Showing 26 changed files with 183 additions and 180 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -236,23 +236,23 @@ export class AngularSlickgridComponent implements AfterViewInit, OnDestroy, OnIn
}

constructor(
private cd: ChangeDetectorRef,
private elm: ElementRef,
private excelExportService: ExcelExportService,
private exportService: ExportService,
private extensionService: ExtensionService,
private extensionUtility: ExtensionUtility,
private filterService: FilterService,
private gridEventService: GridEventService,
private gridService: GridService,
private gridStateService: GridStateService,
private groupingAndColspanService: GroupingAndColspanService,
private paginationService: PaginationService,
private resizer: ResizerService,
private sharedService: SharedService,
private sortService: SortService,
private treeDataService: TreeDataService,
@Optional() private translate: TranslateService,
private readonly cd: ChangeDetectorRef,
private readonly elm: ElementRef,
private readonly excelExportService: ExcelExportService,
private readonly exportService: ExportService,
private readonly extensionService: ExtensionService,
private readonly extensionUtility: ExtensionUtility,
private readonly filterService: FilterService,
private readonly gridEventService: GridEventService,
private readonly gridService: GridService,
private readonly gridStateService: GridStateService,
private readonly groupingAndColspanService: GroupingAndColspanService,
private readonly paginationService: PaginationService,
private readonly resizer: ResizerService,
private readonly sharedService: SharedService,
private readonly sortService: SortService,
private readonly treeDataService: TreeDataService,
@Optional() private readonly translate: TranslateService,
@Inject('config') private forRootConfig: GridOption
) {
this.slickEmptyWarning = new SlickEmptyWarningComponent(this.translate);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export class SlickPaginationComponent implements OnDestroy, OnInit {
textPage = 'Page';

/** Constructor */
constructor(private paginationService: PaginationService, @Optional() private translate: TranslateService) { }
constructor(private readonly paginationService: PaginationService, @Optional() private readonly translate: TranslateService) { }

get availablePageSizes(): number[] {
return this.paginationService.availablePageSizes;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ export class CellMenuExtension implements Extension {
private _locales: Locale;

constructor(
private extensionUtility: ExtensionUtility,
private sharedService: SharedService,
@Optional() private translate: TranslateService,
private readonly extensionUtility: ExtensionUtility,
private readonly sharedService: SharedService,
@Optional() private readonly translate: TranslateService,
) {
this._eventHandler = new Slick.EventHandler();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ export class ContextMenuExtension implements Extension {
private _userOriginalContextMenu: ContextMenu | undefined;

constructor(
private excelExportService: ExcelExportService,
private exportService: ExportService,
private extensionUtility: ExtensionUtility,
private sharedService: SharedService,
private treeDataService: TreeDataService,
@Optional() private translate: TranslateService,
private readonly excelExportService: ExcelExportService,
private readonly exportService: ExportService,
private readonly extensionUtility: ExtensionUtility,
private readonly sharedService: SharedService,
private readonly treeDataService: TreeDataService,
@Optional() private readonly translate: TranslateService,
) {
this._eventHandler = new Slick.EventHandler();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { getTranslationPrefix } from '../services/utilities';

@Injectable()
export class ExtensionUtility {
constructor(private sharedService: SharedService, @Optional() private translate: TranslateService) { }
constructor(private sharedService: SharedService, @Optional() private readonly translate: TranslateService) { }

/**
* From a Grid Menu object property name, we will return the correct title output string following this order
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ export class GridMenuExtension implements Extension {
private _userOriginalGridMenu: GridMenu;

constructor(
private excelExportService: ExcelExportService,
private exportService: ExportService,
private extensionUtility: ExtensionUtility,
private filterService: FilterService,
private sharedService: SharedService,
private sortService: SortService,
@Optional() private translate: TranslateService,
private readonly excelExportService: ExcelExportService,
private readonly exportService: ExportService,
private readonly extensionUtility: ExtensionUtility,
private readonly filterService: FilterService,
private readonly sharedService: SharedService,
private readonly sortService: SortService,
@Optional() private readonly translate: TranslateService,
) {
this._eventHandler = new Slick.EventHandler();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ export class HeaderMenuExtension implements Extension {
private _locales: Locale;

constructor(
private extensionUtility: ExtensionUtility,
private filterService: FilterService,
private sharedService: SharedService,
private sortService: SortService,
@Optional() private translate: TranslateService,
private readonly extensionUtility: ExtensionUtility,
private readonly filterService: FilterService,
private readonly sharedService: SharedService,
private readonly sortService: SortService,
@Optional() private readonly translate: TranslateService,
) {
this._eventHandler = new Slick.EventHandler();
}
Expand Down
18 changes: 9 additions & 9 deletions src/app/modules/angular-slickgrid/filters/autoCompleteFilter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ declare const $: any;

@Injectable()
export class AutoCompleteFilter implements Filter {
private _autoCompleteOptions: AutocompleteOption;
private _clearFilterTriggered = false;
private _collection: any[] | null;
private _shouldTriggerQuery = true;
protected _autoCompleteOptions: AutocompleteOption;
protected _clearFilterTriggered = false;
protected _collection: any[] | null;
protected _shouldTriggerQuery = true;

/** DOM Element Name, useful for auto-detecting positioning (dropup / dropdown) */
elementName: string;
Expand Down Expand Up @@ -65,7 +65,7 @@ export class AutoCompleteFilter implements Filter {
/**
* Initialize the Filter
*/
constructor(protected translate: TranslateService, protected collectionService: CollectionService) { }
constructor(protected readonly translate: TranslateService, protected readonly collectionService: CollectionService) { }

/** Getter for the Autocomplete Option */
get autoCompleteOptions(): Partial<AutocompleteOption> {
Expand Down Expand Up @@ -346,7 +346,7 @@ export class AutoCompleteFilter implements Filter {
/**
* Create the HTML template as a string
*/
private buildTemplateHtmlString() {
protected buildTemplateHtmlString() {
const columnId = this.columnDef && this.columnDef.id;
let placeholder = (this.gridOptions) ? (this.gridOptions.defaultFilterPlaceholder || '') : '';
if (this.columnFilter && this.columnFilter.placeholder) {
Expand All @@ -359,7 +359,7 @@ export class AutoCompleteFilter implements Filter {
* From the html template string, create a DOM element
* @param filterTemplate
*/
private createDomElement(filterTemplate: string, collection: any[], searchTerm?: SearchTerm) {
protected createDomElement(filterTemplate: string, collection: any[], searchTerm?: SearchTerm) {
const columnId = this.columnDef && this.columnDef.id;
const $headerElm = this.grid.getHeaderRowColumn(columnId);
$($headerElm).empty();
Expand Down Expand Up @@ -447,10 +447,10 @@ export class AutoCompleteFilter implements Filter {
}

//
// private functions
// protected functions
// ------------------

// this function should be PRIVATE but for unit tests purposes we'll make it public until a better solution is found
// this function should be protected but for unit tests purposes we'll make it public until a better solution is found
// a better solution would be to get the autocomplete DOM element to work with selection but I couldn't find how to do that in Jest
onSelect(event: Event, ui: { item: any; }) {
if (ui && ui.item) {
Expand Down
34 changes: 17 additions & 17 deletions src/app/modules/angular-slickgrid/filters/compoundDateFilter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,25 +31,25 @@ require('flatpickr');
declare const $: any;

export class CompoundDateFilter implements Filter {
private _clearFilterTriggered = false;
private _currentDate: Date;
private _flatpickrOptions: FlatpickrOption;
private _shouldTriggerQuery = true;
private $filterElm: any;
private $filterInputElm: any;
private $selectOperatorElm: any;
private _currentValue: string;
private _operator: OperatorType | OperatorString;
protected _clearFilterTriggered = false;
protected _currentDate: Date;
protected _flatpickrOptions: FlatpickrOption;
protected _shouldTriggerQuery = true;
protected $filterElm: any;
protected $filterInputElm: any;
protected $selectOperatorElm: any;
protected _currentValue: string;
protected _operator: OperatorType | OperatorString;
flatInstance: any;
grid: any;
searchTerms: SearchTerm[];
columnDef: Column;
callback: FilterCallback;

constructor(@Optional() private translate: TranslateService) { }
constructor(@Optional() protected readonly translate: TranslateService) { }

/** Getter for the Grid Options pulled through the Grid Object */
private get gridOptions(): GridOption {
protected get gridOptions(): GridOption {
return (this.grid && this.grid.getOptions) ? this.grid.getOptions() : {};
}

Expand Down Expand Up @@ -182,9 +182,9 @@ export class CompoundDateFilter implements Filter {
}

//
// private functions
// protected functions
// ------------------
private buildDatePickerInput(searchTerm?: SearchTerm) {
protected buildDatePickerInput(searchTerm?: SearchTerm) {
const inputFormat = mapFlatpickrDateFormatWithFieldType(this.columnFilter.type || this.columnDef.type || FieldType.dateIso);
const outputFormat = mapFlatpickrDateFormatWithFieldType(this.columnDef.outputType || this.columnFilter.type || this.columnDef.type || FieldType.dateUtc);
const userFilterOptions = (this.columnFilter && this.columnFilter.filterOptions || {}) as FlatpickrOption;
Expand Down Expand Up @@ -245,7 +245,7 @@ export class CompoundDateFilter implements Filter {
return $filterInputElm;
}

private getOptionValues(): { operator: OperatorString, description: string }[] {
protected getOptionValues(): { operator: OperatorString, description: string }[] {
return [
{ operator: '', description: '' },
{ operator: '=', description: this.getOutputText('EQUAL_TO', 'TEXT_EQUAL_TO', 'Equal to') },
Expand All @@ -258,7 +258,7 @@ export class CompoundDateFilter implements Filter {
}

/** Get Locale, Translated or a Default Text if first two aren't detected */
private getOutputText(translationKey: string, localeText: string, defaultText: string): string {
protected getOutputText(translationKey: string, localeText: string, defaultText: string): string {
if (this.gridOptions && this.gridOptions.enableTranslate && this.translate && this.translate.instant) {
const translationPrefix = getTranslationPrefix(this.gridOptions);
return this.translate.instant(`${translationPrefix}${translationKey}`);
Expand All @@ -269,7 +269,7 @@ export class CompoundDateFilter implements Filter {
/**
* Create the DOM element
*/
private createDomElement(searchTerm?: SearchTerm) {
protected createDomElement(searchTerm?: SearchTerm) {
const fieldId = this.columnDef && this.columnDef.id;
const $headerElm = this.grid.getHeaderRowColumn(fieldId);
$($headerElm).empty();
Expand Down Expand Up @@ -320,7 +320,7 @@ export class CompoundDateFilter implements Filter {
return $filterContainerElm;
}

private onTriggerEvent(e: Event | undefined) {
protected onTriggerEvent(e: Event | undefined) {
if (this._clearFilterTriggered) {
this.callback(e, { columnDef: this.columnDef, clearFilterTriggered: this._clearFilterTriggered, shouldTriggerQuery: this._shouldTriggerQuery });
this.$filterElm.removeClass('filled');
Expand Down
31 changes: 15 additions & 16 deletions src/app/modules/angular-slickgrid/filters/compoundInputFilter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,19 @@ import { getTranslationPrefix, mapOperatorToShorthandDesignation } from '../serv
declare const $: any;

export class CompoundInputFilter implements Filter {
private _clearFilterTriggered = false;
private _locales: Locale;
private _shouldTriggerQuery = true;
private _inputType = 'text';
private $filterElm: any;
private $filterInputElm: any;
private $selectOperatorElm: any;
private _operator: OperatorType | OperatorString;
protected _clearFilterTriggered = false;
protected _shouldTriggerQuery = true;
protected _inputType = 'text';
protected $filterElm: any;
protected $filterInputElm: any;
protected $selectOperatorElm: any;
protected _operator: OperatorType | OperatorString;
grid: any;
searchTerms: SearchTerm[];
columnDef: Column;
callback: FilterCallback;

constructor(protected translate: TranslateService) { }
constructor(protected readonly translate: TranslateService) { }

/** Getter for the Column Filter */
get columnFilter(): ColumnFilter {
Expand All @@ -47,7 +46,7 @@ export class CompoundInputFilter implements Filter {
}

/** Getter for the Grid Options pulled through the Grid Object */
private get gridOptions(): GridOption {
protected get gridOptions(): GridOption {
return (this.grid && this.grid.getOptions) ? this.grid.getOptions() : {};
}

Expand Down Expand Up @@ -147,18 +146,18 @@ export class CompoundInputFilter implements Filter {
}

//
// private functions
// protected functions
// ------------------

private buildInputHtmlString() {
protected buildInputHtmlString() {
let placeholder = (this.gridOptions) ? (this.gridOptions.defaultFilterPlaceholder || '') : '';
if (this.columnFilter && this.columnFilter.placeholder) {
placeholder = this.columnFilter.placeholder;
}
return `<input type="${this._inputType || 'text'}" role="presentation" autocomplete="off" class="form-control compound-input" placeholder="${placeholder}" /><span></span>`;
}

private getOptionValues(): { operator: OperatorString, description: string }[] {
protected getOptionValues(): { operator: OperatorString, description: string }[] {
const type = (this.columnDef.type && this.columnDef.type) ? this.columnDef.type : FieldType.string;
let optionValues = [];

Expand Down Expand Up @@ -191,7 +190,7 @@ export class CompoundInputFilter implements Filter {
}

/** Get Locale, Translated or a Default Text if first two aren't detected */
private getOutputText(translationKey: string, localeText: string, defaultText: string): string {
protected getOutputText(translationKey: string, localeText: string, defaultText: string): string {
if (this.gridOptions && this.gridOptions.enableTranslate && this.translate && this.translate.instant) {
const translationPrefix = getTranslationPrefix(this.gridOptions);
return this.translate.instant(`${translationPrefix}${translationKey}`);
Expand All @@ -202,7 +201,7 @@ export class CompoundInputFilter implements Filter {
/**
* Create the DOM element
*/
private createDomElement(searchTerm?: SearchTerm) {
protected createDomElement(searchTerm?: SearchTerm) {
const fieldId = this.columnDef && this.columnDef.id;
const $headerElm = this.grid.getHeaderRowColumn(fieldId);
$($headerElm).empty();
Expand Down Expand Up @@ -251,7 +250,7 @@ export class CompoundInputFilter implements Filter {
return $filterContainerElm;
}

private onTriggerEvent(e: KeyboardEvent | undefined) {
protected onTriggerEvent(e: KeyboardEvent | undefined) {
// we'll use the "input" event for everything (keyup, change, mousewheel & spinner)
// with 1 small exception, we need to use the keyup event to handle ENTER key, everything will be processed by the "input" event
if (e && e.type === 'keyup' && e.key !== 'Enter') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { CompoundInputFilter } from './compoundInputFilter';

export class CompoundInputNumberFilter extends CompoundInputFilter {
/** Initialize the Filter */
constructor(protected translate: TranslateService) {
constructor(protected readonly translate: TranslateService) {
super(translate);
this.inputType = 'number';
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { CompoundInputFilter } from './compoundInputFilter';

export class CompoundInputPasswordFilter extends CompoundInputFilter {
/** Initialize the Filter */
constructor(protected translate: TranslateService) {
constructor(protected readonly translate: TranslateService) {
super(translate);
this.inputType = 'password';
}
Expand Down
Loading

0 comments on commit e5b5e8d

Please sign in to comment.