mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
various code quality fixes (#5792)
* various code quality fixes * reduce duplicated code * add safety check
This commit is contained in:
@@ -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 {
|
||||
|
@@ -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/>');
|
||||
|
@@ -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;
|
||||
}
|
||||
|
||||
|
@@ -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';
|
||||
}
|
||||
|
@@ -98,7 +98,7 @@ export abstract class FormBaseComponent {
|
||||
}
|
||||
|
||||
hasForm(): boolean {
|
||||
return this.form ? true : false;
|
||||
return !!this.form;
|
||||
}
|
||||
|
||||
isTitleEnabled(): boolean {
|
||||
|
@@ -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 {
|
||||
|
@@ -27,8 +27,8 @@ export class ErrorMessageModel {
|
||||
this.attributes = new Map();
|
||||
}
|
||||
|
||||
isActive() {
|
||||
return this.message ? true : false;
|
||||
isActive(): boolean {
|
||||
return !!this.message;
|
||||
}
|
||||
|
||||
getAttributesAsJsonObj() {
|
||||
|
@@ -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 === '') {
|
||||
|
@@ -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 {
|
||||
|
@@ -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;
|
||||
|
@@ -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';
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -180,7 +180,7 @@ export class DynamicTableModel extends FormWidgetModel {
|
||||
}
|
||||
|
||||
if (column.type === 'Boolean') {
|
||||
return rowValue ? true : false;
|
||||
return !!rowValue;
|
||||
}
|
||||
|
||||
if (column.type === 'Date') {
|
||||
|
@@ -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 {
|
||||
|
@@ -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');
|
||||
});
|
||||
|
||||
|
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -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 '';
|
||||
}
|
||||
|
||||
|
@@ -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]+/, '');
|
||||
|
@@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -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))
|
||||
);
|
||||
|
@@ -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;
|
||||
})
|
||||
);
|
||||
}
|
||||
|
@@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user