Skip to content

Commit

Permalink
Realizacao do merge da branch correções-cobertura-sonarcloud
Browse files Browse the repository at this point in the history
Aumento da cobertura de testes e resolução de issues do SonarCloud.
  • Loading branch information
GabrielRoger07 authored Sep 6, 2024
2 parents 62dd341 + e5e1af8 commit d0193b2
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 37 deletions.
26 changes: 13 additions & 13 deletions src/app/app-routing.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import { ResetPasswordComponent } from './pages/reset-password/reset-password.co
import { AuthGuard } from './guard/auth.guard';
import { EditUserComponent } from './pages/edit-user/edit-user.component';
import { UpdateRoleComponent } from './pages/update-role/update-role.component';
import { AdminGuard } from './services/admin.guard';
import { SuggestAgendaComponent } from './pages/suggest-agenda/suggest-agenda.component';
import { ParticipateComponent } from './pages/participate/participate.component';
import { GridDaysComponent } from './pages/grid-days/grid-days.component';
Expand Down Expand Up @@ -101,25 +100,26 @@ const routes: Routes = [
},
{ path: 'privacy', component: PrivacyPolicyComponent },

{ path: 'homeAdmin',
{
path: 'homeAdmin',
component: HomeAdminComponent,
canActivate: [TokenAdminGuard],
},
{
path: 'adminActivate',
component: AdminActivateComponent
component: AdminActivateComponent,
},
{
path: 'superAdminActivate',
component: SuperAdminActivateComponent,
},
{
{
path: 'category-views',
component: CategoryTableComponent,
canActivate: [TokenAdminGuard],
},
{
path: 'video-views',
{
path: 'video-views',
component: VideoViewsComponent,
canActivate: [TokenAdminGuard],
},
Expand All @@ -129,14 +129,14 @@ const routes: Routes = [
canActivate: [TokenAdminGuard],
},
{
path: 'record',
component: RecordComponent,
canActivate: [AuthGuard]
path: 'record',
component: RecordComponent,
canActivate: [AuthGuard],
},
{
path: 'notifications',
component: NotificationsComponent,
canActivate: [AuthGuard]
path: 'notifications',
component: NotificationsComponent,
canActivate: [AuthGuard],
},
{
path: 'recommendation',
Expand Down Expand Up @@ -169,4 +169,4 @@ const routes: Routes = [
imports: [RouterModule.forRoot(routes)],
exports: [RouterModule],
})
export class AppRoutingModule { }
export class AppRoutingModule {}
37 changes: 22 additions & 15 deletions src/app/components/background/background.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { Subscription, interval } from 'rxjs';
export class BackgroundComponent implements OnInit, OnDestroy {
items: MenuItem[] = [];
mobileDevide: boolean = true;
hasNotifications: boolean = false; // Indica se há notificações
hasNotifications: boolean = false; // Indica se há notificações
private intervalSubscription: Subscription | null = null;

constructor(
Expand All @@ -22,7 +22,7 @@ export class BackgroundComponent implements OnInit, OnDestroy {

ngOnInit(): void {
console.log('BackgroundComponent initialized');

this.items = [
{
label: 'Perfil',
Expand All @@ -32,12 +32,12 @@ export class BackgroundComponent implements OnInit, OnDestroy {
label: `Notificações`,
routerLink: '/notifications',
escape: false,
}
},
];

// Atualiza as notificações imediatamente com base no serviço
this.notificationService.recommendedVideosCount$.subscribe(count => {
this.hasNotifications = count > 0; // Verifica se há notificações
this.notificationService.recommendedVideosCount$.subscribe((count) => {
this.hasNotifications = count > 0; // Verifica se há notificações
this.updateNotificationLabel();
});

Expand All @@ -46,8 +46,9 @@ export class BackgroundComponent implements OnInit, OnDestroy {
const token = localStorage.getItem('token') as string;
this.notificationService.setUserIdFromToken(token);
const userId = this.notificationService.userId;
this.notificationService.fetchRecommendedVideosCount(userId)
.subscribe(response => {
this.notificationService
.fetchRecommendedVideosCount(userId)
.subscribe((response) => {
console.log('Response from fetchRecommendedVideosCount:', response);
this.updateNotificationCount(response);
});
Expand All @@ -60,16 +61,17 @@ export class BackgroundComponent implements OnInit, OnDestroy {
const token = localStorage.getItem('token') as string;
this.notificationService.setUserIdFromToken(token);
const userId = this.notificationService.userId;
this.notificationService.fetchRecommendedVideosCount(userId)
.subscribe(response => {
this.notificationService
.fetchRecommendedVideosCount(userId)
.subscribe((response) => {
console.log('Response from interval fetch:', response);
this.updateNotificationCount(response);
});
}

this.notificationService.recommendedVideosCount$.subscribe(count => {
this.notificationService.recommendedVideosCount$.subscribe((count) => {
console.log('New notifications count (from BehaviorSubject):', count);
this.hasNotifications = count > 0; // Verifica se há notificações
this.hasNotifications = count > 0; // Verifica se há notificações
this.updateNotificationLabel();
});
});
Expand All @@ -84,7 +86,7 @@ export class BackgroundComponent implements OnInit, OnDestroy {
}

updateNotificationCount(response: any): void {
if (response && response.recommend_videos) {
if (response?.recommend_videos) {
const count = response.recommend_videos.length;
console.log('Updating notification count with:', count);
this.hasNotifications = count > 0;
Expand All @@ -99,7 +101,8 @@ export class BackgroundComponent implements OnInit, OnDestroy {

identifiesUserDevice(): void {
const userAgent = navigator.userAgent;
this.mobileDevide = /Android|iPhone|iPad|iPod|BlackBerry|Windows Phone/i.test(userAgent);
this.mobileDevide =
/Android|iPhone|iPad|iPod|BlackBerry|Windows Phone/i.test(userAgent);
}

getActualRoute(): string {
Expand All @@ -108,9 +111,13 @@ export class BackgroundComponent implements OnInit, OnDestroy {

updateNotificationLabel(): void {
console.log('Updating notification label');
this.items = this.items.map(item => {
this.items = this.items.map((item) => {
if (item.routerLink === '/notifications') {
item.label = `Notificações ${this.hasNotifications ? '<span class="notification-badge"></span>' : ''}`;
item.label = `Notificações ${
this.hasNotifications
? '<span class="notification-badge"></span>'
: ''
}`;
}
return item;
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ button:hover {
background-color: #979ea0;
}

.btn_and_select_container{
.btn_and_select_container {
display: flex;
}

Expand Down Expand Up @@ -157,7 +157,6 @@ select {
align-items: center; /* Centraliza o texto verticalmente */
justify-content: center; /* Centraliza o texto horizontalmente */
width: auto; /* Define o tamanho automático para alinhar com o conteúdo */
min-width: 10rem; /* Define uma largura mínima para o texto readonly */
text-align: center; /* Centraliza o texto dentro do elemento */
cursor: not-allowed; /* Cursor de proibição padrão */
transition: background-color 0.3s ease, box-shadow 0.3s ease; /* Transição suave para hover */
Expand Down Expand Up @@ -194,4 +193,4 @@ select:focus {

select option {
color: #000; /* Cor do texto das opções */
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ <h1>Lista de usuários cadastrados:</h1>
<td>{{ user.name }}</td>
<td>{{ user.connection }}</td>
<td>{{ user.email }}</td>
<th>{{ user.role }}</th>
<td>{{ user.role }}</td>
<td class="btn_and_select_container">
<button
*ngIf="user.id !== userId; else readOnly_exlcuir"
Expand Down
6 changes: 3 additions & 3 deletions src/app/pages/edit-user/edit-user.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export class EditUserComponent implements OnInit {
private userService: UserService,
private route: ActivatedRoute,
private alertService: AlertService
) { }
) {}

ngOnInit(): void {
const userId = this.route.snapshot.params['id'];
Expand Down Expand Up @@ -64,7 +64,7 @@ export class EditUserComponent implements OnInit {
],
});

if (this.userData && this.userData.connection) {
if (this.userData?.connection) {
this.userForm.get('connection')?.setValue(this.userData.connection);
}
}
Expand All @@ -85,7 +85,7 @@ export class EditUserComponent implements OnInit {
}

updateUser() {
if (this.userForm && this.userForm.valid) {
if (this.userForm?.valid) {
const data = {
...this.userForm.value,
connection: this.userForm.value.connection.name,
Expand Down
6 changes: 4 additions & 2 deletions src/app/pages/update-role/update-role.component.html
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
<div class="mx-5">
<div class="filter-container">
<div>
<label>Nome ou Email:</label>
<label for="filterInput">Nome ou Email:</label>
<input
id="filterInput"
[(ngModel)]="filterInputValue"
(change)="filterUser()"
placeholder="Filtrar pelo nome do usuário"
class="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-100 p-2.5 outline-none"
/>
</div>
<div>
<label>Vínculo:</label>
<label for="filterConnection">Vínculo:</label>
<select
id="filterConnection"
(change)="filterUser()"
[(ngModel)]="filterConnectionValue"
class="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-100 p-2.5 outline-none"
Expand Down

0 comments on commit d0193b2

Please sign in to comment.