various code quality fixes (#5792)

* various code quality fixes

* reduce duplicated code

* add safety check
This commit is contained in:
Denys Vuika
2020-06-18 17:57:46 +01:00
committed by GitHub
parent dc2060fe49
commit e9350bd297
54 changed files with 96 additions and 154 deletions

View File

@@ -31,11 +31,7 @@ export class ButtonsMenuComponent implements AfterContentInit {
isMenuEmpty: boolean;
ngAfterContentInit() {
if (this.buttons.length > 0) {
this.isMenuEmpty = false;
} else {
this.isMenuEmpty = true;
}
this.isMenuEmpty = this.buttons.length <= 0;
}
isMobile(): boolean {

View File

@@ -175,14 +175,14 @@ export class CommentsComponent implements OnChanges {
}
isATask(): boolean {
return this.taskId ? true : false;
return !!this.taskId;
}
isANode(): boolean {
return this.nodeId ? true : false;
return !!this.nodeId;
}
private sanitize(input: string) {
private sanitize(input: string): string {
return input.replace(/<[^>]+>/g, '')
.replace(/^\s+|\s+$|\s+(?=\s)/g, '')
.replace(/\r?\n/g, '<br/>');

View File

@@ -285,7 +285,7 @@ export class DataTableComponent implements AfterContentInit, OnChanges, DoCheck,
}
isPropertyChanged(property: SimpleChange): boolean {
return property && property.currentValue ? true : false;
return !!(property && property.currentValue);
}
convertToRowsData(rows: any []): ObjectDataRow[] {
@@ -375,7 +375,7 @@ export class DataTableComponent implements AfterContentInit, OnChanges, DoCheck,
this.rowMenuCache = {};
}
isTableEmpty() {
isTableEmpty(): boolean {
return this.data === undefined || this.data === null;
}

View File

@@ -44,7 +44,7 @@ export class EditJsonDialogComponent implements OnInit {
ngOnInit() {
if (this.settings) {
this.editable = this.settings.editable ? true : false;
this.editable = this.settings.editable;
this.value = this.settings.value || '';
this.title = this.settings.title || 'JSON';
}

View File

@@ -98,7 +98,7 @@ export abstract class FormBaseComponent {
}
hasForm(): boolean {
return this.form ? true : false;
return !!this.form;
}
isTitleEnabled(): boolean {

View File

@@ -53,19 +53,19 @@
}
hasPreviewStatus(): boolean {
return this.previewStatus === 'supported' ? true : false;
return this.previewStatus === 'supported';
}
isTypeImage(): boolean {
return this.simpleType === 'image' ? true : false;
return this.simpleType === 'image';
}
isTypePdf(): boolean {
return this.simpleType === 'pdf' ? true : false;
return this.simpleType === 'pdf';
}
isTypeDoc(): boolean {
return this.simpleType === 'word' || this.simpleType === 'content' ? true : false;
return this.simpleType === 'word' || this.simpleType === 'content';
}
isThumbnailReady(): boolean {

View File

@@ -27,8 +27,8 @@ export class ErrorMessageModel {
this.attributes = new Map();
}
isActive() {
return this.message ? true : false;
isActive(): boolean {
return !!this.message;
}
getAttributesAsJsonObj() {

View File

@@ -80,7 +80,7 @@ export class RequiredFieldValidator implements FormFieldValidator {
}
if (field.type === FormFieldTypes.BOOLEAN) {
return field.value ? true : false;
return !!field.value;
}
if (field.value === null || field.value === undefined || field.value === '') {

View File

@@ -221,7 +221,7 @@ export class FormFieldModel extends FormWidgetModel {
}
private isTypeaheadFieldType(type: string): boolean {
return type === 'typeahead' ? true : false;
return type === 'typeahead';
}
private getFieldNameWithLabel(name: string): string {
@@ -419,11 +419,7 @@ export class FormFieldModel extends FormWidgetModel {
* @param type
*/
isInvalidFieldType(type: string) {
if (type === 'container') {
return true;
} else {
return false;
}
return type === 'container';
}
getOptionName(): string {

View File

@@ -154,7 +154,7 @@ export class FormModel {
}
}
this.isValid = errorsField.length > 0 ? false : true;
this.isValid = errorsField.length <= 0;
if (this.formService) {
validateFormEvent.isValid = this.isValid;

View File

@@ -110,7 +110,7 @@ export class DropdownWidgetComponent extends WidgetComponent implements OnInit {
}
isReadOnlyType(): boolean {
return this.field.type === 'readonly' ? true : false;
return this.field.type === 'readonly';
}
}

View File

@@ -180,7 +180,7 @@ export class DynamicTableModel extends FormWidgetModel {
}
if (column.type === 'Boolean') {
return rowValue ? true : false;
return !!rowValue;
}
if (column.type === 'Date') {

View File

@@ -59,8 +59,8 @@ export class WidgetComponent implements AfterViewInit {
constructor(public formService?: FormService) {
}
hasField() {
return this.field ? true : false;
hasField(): boolean {
return !!this.field;
}
// Note for developers:
@@ -73,7 +73,7 @@ export class WidgetComponent implements AfterViewInit {
}
isValid(): boolean {
return this.field.validationSummary ? true : false;
return !!this.field.validationSummary;
}
hasValue(): boolean {

View File

@@ -74,7 +74,6 @@ describe('HeaderLayoutComponent', () => {
const logo = fixture.nativeElement.querySelector('.adf-app-logo');
const src = logo.getAttribute('src');
expect(logo === null).toBeFalsy();
expect(src).toEqual('logo.png');
});

View File

@@ -71,8 +71,8 @@ export class LicenseModel {
this.remainingDays = obj.remainingDays || null;
this.holder = obj.holder || null;
this.mode = obj.mode || null;
this.isClusterEnabled = obj.isClusterEnabled ? true : false;
this.isCryptodocEnabled = obj.isCryptodocEnabled ? true : false;
this.isClusterEnabled = !!obj.isClusterEnabled;
this.isCryptodocEnabled = !!obj.isCryptodocEnabled;
}
}
}
@@ -85,10 +85,10 @@ export class VersionStatusModel {
constructor(obj?: any) {
if (obj) {
this.isReadOnly = obj.isReadOnly ? true : false;
this.isAuditEnabled = obj.isAuditEnabled ? true : false;
this.isQuickShareEnabled = obj.isQuickShareEnabled ? true : false;
this.isThumbnailGenerationEnabled = obj.isThumbnailGenerationEnabled ? true : false;
this.isReadOnly = !!obj.isReadOnly;
this.isAuditEnabled = !!obj.isAuditEnabled;
this.isQuickShareEnabled = !!obj.isQuickShareEnabled;
this.isThumbnailGenerationEnabled = !!obj.isThumbnailGenerationEnabled;
}
}
}

View File

@@ -28,7 +28,7 @@ export class FileSizePipe implements PipeTransform {
}
transform(bytes: number, decimals: number = 2): string {
if (bytes == null || bytes === undefined) {
if (bytes == null) {
return '';
}

View File

@@ -25,7 +25,7 @@ export class FileTypePipe implements PipeTransform {
transform(value: string) {
if ( value == null || value === undefined ) {
if ( value == null ) {
return '';
} else {
const fileInfo = value.substring(value.lastIndexOf('/') + 1).replace(/\.[a-z]+/, '');

View File

@@ -157,7 +157,7 @@ export class AuthenticationService {
* @returns True if set, false otherwise
*/
isRememberMeSet(): boolean {
return (this.cookie.getItem(REMEMBER_ME_COOKIE_KEY) === null) ? false : true;
return (this.cookie.getItem(REMEMBER_ME_COOKIE_KEY) !== null);
}
/**

View File

@@ -287,10 +287,7 @@ export class IdentityGroupService {
checkGroupHasClientApp(groupId: string, clientId: string): Observable<boolean> {
return this.getClientRoles(groupId, clientId).pipe(
map((response: any[]) => {
if (response && response.length > 0) {
return true;
}
return false;
return response && response.length > 0;
}),
catchError((error) => this.handleError(error))
);

View File

@@ -201,10 +201,7 @@ export class IdentityUserService {
checkUserHasClientApp(userId: string, clientId: string): Observable<boolean> {
return this.getClientRoles(userId, clientId).pipe(
map((clientRoles: any[]) => {
if (clientRoles.length > 0) {
return true;
}
return false;
return clientRoles.length > 0;
})
);
}

View File

@@ -82,7 +82,7 @@ export class UploadService {
* @returns True if a file is uploading, false otherwise
*/
isUploading(): boolean {
return this.activeTask ? true : false;
return !!this.activeTask;
}
/**