Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MOSIP-32289 resolved sonar code smells #185

Merged
merged 2 commits into from
Apr 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions pre-registration-ui/src/app/app.component.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { Component, OnInit, OnDestroy } from '@angular/core';
import { HostListener } from '@angular/core';
import { Event as NavigationEvent, Router } from '@angular/router';
import { Component, OnInit, OnDestroy, HostListener } from '@angular/core';
import { Event as NavigationEvent, Router, NavigationStart } from '@angular/router';
import { filter } from 'rxjs/operators';
import { NavigationStart } from '@angular/router';

import { AutoLogoutService } from 'src/app/core/services/auto-logout.service';
import { ConfigService } from './core/services/config.service';
Expand All @@ -21,7 +19,9 @@ export class AppComponent implements OnInit, OnDestroy {
constructor(private autoLogout: AutoLogoutService, private router: Router, private configService: ConfigService) {}

ngOnInit() {
this.subscriptions.push(this.autoLogout.currentMessageAutoLogout.subscribe(() => {}));
this.subscriptions.push(this.autoLogout.currentMessageAutoLogout.subscribe(() => {
// This is intentional
}));
this.autoLogout.changeMessage({ timerFired: false });
this.routerType();
}
Expand All @@ -32,8 +32,7 @@ export class AppComponent implements OnInit, OnDestroy {
.pipe(filter((event: NavigationEvent) => event instanceof NavigationStart))
.subscribe((event: NavigationStart) => {
if (event.restoredState) {
// this.configService.navigationType = 'popstate';
//this.preventBack();
// This is intentional
}
})
);
Expand Down
10 changes: 2 additions & 8 deletions pre-registration-ui/src/app/app.util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ export default class Utils {
urlSegments.pop();
}
urlSegments.push(nextRoute);
const url = urlSegments.join("/");
return url;
return urlSegments.join("/");
}
}

Expand All @@ -40,7 +39,6 @@ export default class Utils {
language: string,
ltrLangs: string[]
) {
//console.log(`language: ${language}`);
let localeId = language.substring(0, 2);
JSON.parse(localStorage.getItem(appConstants.LANGUAGE_CODE_VALUES)).forEach((element) => {
if (language === element.code && element.locale) {
Expand All @@ -50,12 +48,10 @@ export default class Utils {
}
}
});
//console.log(`getBookingDateTime: ${localeId}`);
const localeData = localStorage.getItem(localeId);
let proceed = false;
if (localeData !== null) {
registerLocaleData(JSON.parse(localeData));
//console.log(`registered localeId: ${localeId}`);
proceed = true;
} else {
registerLocaleData(localeEn, "en");
Expand All @@ -73,7 +69,6 @@ export default class Utils {
} else {
appointmentDateTime = date.join(" ");
}
//console.log(appointmentDateTime);
return appointmentDateTime;
} else {
return appointment_date;
Expand Down Expand Up @@ -173,7 +168,7 @@ export default class Utils {
return dataCaptureLanguagesLabels;
};

static getLangSelectionPopupAttributes(textDir: string,dataCaptureLabels: any, mandatoryLanguages: string[], minLanguage: Number, maxLanguage: Number, userPrefLanguage : string) {
static getLangSelectionPopupAttributes(textDir: string,dataCaptureLabels: any, mandatoryLanguages: string[], minLanguage: number, maxLanguage: number, userPrefLanguage : string) {
//create string with mandatory Lang Names
let mandatoryLang = "";
mandatoryLanguages.forEach((lang) => {
Expand Down Expand Up @@ -242,7 +237,6 @@ export default class Utils {
} else if (userRequest.langCode) {
applicationLanguages = [userRequest.langCode];
}
//console.log(`applicationLanguages: ${applicationLanguages}`);
return applicationLanguages;
}

Expand Down
4 changes: 1 addition & 3 deletions pre-registration-ui/src/app/auth/auth-guard.service.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { TestBed } from '@angular/core/testing';
import { ActivatedRouteSnapshot } from '@angular/router';
import { RouterStateSnapshot } from '@angular/router';
import { Router } from '@angular/router';
import { ActivatedRouteSnapshot, RouterStateSnapshot, Router } from '@angular/router';
import { AuthService } from './auth.service';
import { AuthGuardService } from './auth-guard.service';
describe('AuthGuardService', () => {
Expand Down
3 changes: 1 addition & 2 deletions pre-registration-ui/src/app/auth/auth-guard.service.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot } from '@angular/router';
import { CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot, Router } from '@angular/router';
import { Injectable } from '@angular/core';
import { Router } from '@angular/router';
import { AuthService } from './auth.service';

@Injectable({
Expand Down
3 changes: 1 addition & 2 deletions pre-registration-ui/src/app/auth/auth.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ import { AppRoutingModule } from "../app-routing.module";
import { SharedModule } from "../shared/shared.module";
import { CoreModule } from "../core/core.module";
import {
RecaptchaModule,
RECAPTCHA_LANGUAGE,
RecaptchaModule
} from "ng-recaptcha";
import { CaptchaComponent } from './captcha/captcha.component';
@NgModule({
Expand Down
5 changes: 1 addition & 4 deletions pre-registration-ui/src/app/auth/login/login.component.css
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ button {
visibility: hidden;
}
::ng-deep .mat-form-field-appearance-outline .mat-form-field-outline {
color: lightgrey;
color: white !important;
}

::ng-deep .mat-form-field-appearance-outline.mat-focused .mat-form-field-outline-thick {
Expand All @@ -93,9 +93,6 @@ button {
/* ::ng-deep.mat-form-field-wrapper {
padding-bottom: 0.5em !important;
} */
::ng-deep .mat-form-field-appearance-outline .mat-form-field-outline {
color: white !important;
}

@media (max-width: 500px) {
.form_fields_padding {
Expand Down
12 changes: 0 additions & 12 deletions pre-registration-ui/src/app/auth/login/login.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@
</mat-form-field>
</div>

<!-- class="pinkBg whiteText boldText" -->
<div *ngIf="showSendOTP">
<button
mat-raised-button
Expand All @@ -104,17 +103,6 @@
</button>
</div>

<!-- <div *ngIf="showResend">
<button
mat-raised-button
class="btn_axn-pri"
disabled="{{ disableBtn }}"
(click)="submit()"
>
{{ "login.action_resend" | translate }}
</button>
</div> -->

<div class="pinkText boldText" id="timer">
<span>{{ "login.otp_valid_label" | translate }}&nbsp;</span
><span id="minutesSpan">{{ minutes }}</span
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { async, ComponentFixture, TestBed, inject } from '@angular/core/testing';
import { async, ComponentFixture, TestBed } from '@angular/core/testing';

import { LoginComponent } from './login.component';
import { TranslateModule, TranslateLoader } from '@ngx-translate/core';
Expand Down
34 changes: 6 additions & 28 deletions pre-registration-ui/src/app/auth/login/login.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import { ConfigService } from "src/app/core/services/config.service";
import * as appConstants from "../../app.constants";
import Utils from "src/app/app.util";
import moment from "moment";
import stubConfig from "../../../assets/stub-config.json";

@Component({
selector: "app-login",
Expand Down Expand Up @@ -47,8 +46,8 @@ export class LoginComponent implements OnInit {
captchaError: boolean;
mandatoryLanguages: string[];
optionalLanguages: string[];
minLanguage: Number;
maxLanguage: Number;
minLanguage: number;
maxLanguage: number;
languageSelectionArray = [];
userPreferredLanguage: string;
langCode: string;
Expand All @@ -74,11 +73,8 @@ export class LoginComponent implements OnInit {
}

async ngOnInit() {
//console.log(`forceLogout: ${localStorage.getItem(appConstants.FORCE_LOGOUT)}`);
//console.log("isAuthenticated: " + this.authService.isAuthenticated());
if (localStorage.getItem(appConstants.FORCE_LOGOUT) != appConstants.FORCE_LOGOUT_YES
&& this.authService.isAuthenticated()) {
//console.log("valid session redirecting to dashboard");
this.router.navigate([localStorage.getItem("langCode"), "dashboard"]);
} else {
if (localStorage.getItem(appConstants.FORCE_LOGOUT) == appConstants.FORCE_LOGOUT_YES) {
Expand All @@ -104,7 +100,6 @@ export class LoginComponent implements OnInit {

async loadConfigs() {
this.dataService.getConfig().subscribe((response) => {
//response = stubConfig;
this.configService.setConfig(response);
this.appVersion = this.configService.getConfigByKey(
"preregistration.ui.version"
Expand Down Expand Up @@ -144,9 +139,7 @@ export class LoginComponent implements OnInit {
console.log(`otp_sent_time: ${otp_sent_time}`);
if (otp_sent_time && user_email_or_phone) {
let otpSentTime = moment(otp_sent_time).toISOString();
//console.log(`otpSentTime: ${otpSentTime}`);
let currentTime = moment().toISOString();
//console.log(`currentTime: ${currentTime}`);
let otpExpiryIntervalInSeconds = Number(
this.configService.getConfigByKey(
appConstants.CONFIG_KEYS.mosip_kernel_otp_expiry_time
Expand All @@ -155,15 +148,12 @@ export class LoginComponent implements OnInit {
if (isNaN(otpExpiryIntervalInSeconds)) {
otpExpiryIntervalInSeconds = 120; //2 mins by default
}
//console.log(`otpExpiryIntervalInSeconds: ${otpExpiryIntervalInSeconds}`);
var timeLapsedInSeconds = moment(currentTime).diff(
moment(otpSentTime),
"seconds"
);
//console.log(`timeLapsedInSeconds: ${timeLapsedInSeconds}`);
if (timeLapsedInSeconds <= otpExpiryIntervalInSeconds) {
console.log("otp interval not yet expired");
//console.log(this.timer);
let newOtpIntervalInSeconds =
otpExpiryIntervalInSeconds - timeLapsedInSeconds;
console.log(`newOtpIntervalInSeconds: ${newOtpIntervalInSeconds}`);
Expand All @@ -174,7 +164,6 @@ export class LoginComponent implements OnInit {
}
this.errorMessage = "";
this.inputOTP = "";
//this.showResend = false;
this.showOTP = true;
this.showSendOTP = false;
this.showContactDetails = false;
Expand Down Expand Up @@ -215,9 +204,7 @@ export class LoginComponent implements OnInit {
...this.mandatoryLanguages,
...this.optionalLanguages,
];
this.maxLanguage == 1
? (this.showLanguageDropDown = false)
: (this.showLanguageDropDown = true);
this.showLanguageDropDown = this.maxLanguage == 1 ? false : true;
localStorage.setItem(
"availableLanguages",
JSON.stringify(this.languageSelectionArray)
Expand Down Expand Up @@ -354,15 +341,12 @@ export class LoginComponent implements OnInit {
) {
this.errorMessage = "";
this.showVerify = true;
//this.showResend = false;
} else {
//this.showResend = false;
this.showVerify = false;
}
}

verifyInput() {
//this.loginIdValidator();
this.errorMessage ="";
}

Expand Down Expand Up @@ -393,7 +377,6 @@ export class LoginComponent implements OnInit {
// redirecting to initial phase on completion of timer
this.showContactDetails = true;
this.showSendOTP = true;
//this.showResend = true;
this.showOTP = false;
this.showVerify = false;
this.enableSendOtp = true;
Expand All @@ -417,10 +400,11 @@ export class LoginComponent implements OnInit {
}
if (document.getElementById("secondsSpan") &&
document.getElementById("secondsSpan").innerText) {
let newSecVal = --secValue;
if (secValue === 10 || secValue < 10) {
document.getElementById("secondsSpan").innerText = "0" + --secValue;
document.getElementById("secondsSpan").innerText = "0" + newSecVal;
} else {
document.getElementById("secondsSpan").innerText = --secValue + "";
document.getElementById("secondsSpan").innerText = newSecVal + "";
}
}
};
Expand Down Expand Up @@ -452,7 +436,6 @@ export class LoginComponent implements OnInit {
);
this.errorMessage = undefined;
this.inputOTP = "";
//this.showResend = false;
this.showOTP = true;
this.showSendOTP = false;
this.showContactDetails = false;
Expand All @@ -475,9 +458,7 @@ export class LoginComponent implements OnInit {
},
(error) => {
clearInterval(this.timer);
//console.log(error);
if (this.enableCaptcha){
//this.inputContactDetails = "";
this.resetCaptcha = true;
this.captchaToken = null;
this.enableSendOtp = false;
Expand Down Expand Up @@ -506,7 +487,6 @@ export class LoginComponent implements OnInit {
}
},
(error) => {
//console.log(error);
this.inputOTP = "";
this.disableVerify = false;
this.showVerify = false;
Expand Down Expand Up @@ -534,7 +514,6 @@ export class LoginComponent implements OnInit {
localStorage.removeItem("otp_sent_time");
localStorage.removeItem("user_email_or_phone");
localStorage.removeItem("show_captcha");
return;
}
}
);
Expand Down Expand Up @@ -591,7 +570,6 @@ export class LoginComponent implements OnInit {
showOtpMessage() {
this.inputOTP = "";
let response = this.Languagelabels;
//console.log(response);
let otpmessage = response["message"]["login"]["msg3"];
const message = {
case: "MESSAGE",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ export class AboutUsComponent implements OnInit {
langCode = '';
panelOpenState = -1;

constructor() { }

ngOnInit() {
this.langCode = localStorage.getItem('langCode');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@ import { Component, OnInit } from '@angular/core';
})
export class ContactComponent implements OnInit {

constructor() { }

ngOnInit() {
//Empty function
}

}
4 changes: 2 additions & 2 deletions pre-registration-ui/src/app/core/footer/footer.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import { Component, Input, OnInit } from "@angular/core";
})
export class FooterComponent implements OnInit {
@Input() appVersion: string;
constructor() {}

ngOnInit() {
}
//Empty function
}
}
2 changes: 0 additions & 2 deletions pre-registration-ui/src/app/core/header/header.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
<a *ngIf="authService.isAuthenticated()" (click)="onLogoClick()" mat-list-item>
<img src="assets\logo-final.png" alt="MOSIP logo" class="header--logo" style="max-height: 40px"/>
</a>
<!-- <div style="margin-left:5px;"><a routerLink="/" class="logo">logo</a></div> -->
<mat-nav-list class="list-item">
<a mat-list-item routerLink="/about-us">{{ 'header.link_about' | translate }}</a>
<a mat-list-item routerLink="/faq">{{ 'header.link_faq' | translate }}</a>
Expand All @@ -45,7 +44,6 @@
</mat-toolbar>
<main class="main">
<router-outlet></router-outlet>
<!-- <app-footer></app-footer> -->
</main>
</mat-sidenav-content>
</mat-sidenav-container>
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,4 @@ describe('HeaderComponent', () => {
expect(routerStub.navigate).toHaveBeenCalled();
});
});
// describe('doLogout', () => {
// it('makes expected calls', () => {
// const authServiceStub: AuthService = fixture.debugElement.injector.get(AuthService);
// spyOn(authServiceStub, 'onLogout');
// component.doLogout();
// expect(authServiceStub.onLogout).toHaveBeenCalled();
// });
// });
});
Loading
Loading