Skip to content

Commit

Permalink
Merge pull request #84 from szymonpoltorak/DEV-168-GoToProjectsButton
Browse files Browse the repository at this point in the history
Dev 168 go to projects button
  • Loading branch information
Higunio320 authored Mar 27, 2024
2 parents f3c7340 + eb3f6a3 commit d01f08a
Show file tree
Hide file tree
Showing 8 changed files with 146 additions and 54 deletions.
36 changes: 7 additions & 29 deletions corn-frontend/src/app/pages/boards/boards.component.html
Original file line number Diff line number Diff line change
@@ -1,30 +1,7 @@
<mat-toolbar color="primary">
<div class="flex space-x-4 items-center">
<button mat-icon-button (click)="toggleSidebar()">
<mat-icon>{{sidebarShown ? 'menu_open' : 'menu'}}</mat-icon>
</button>

<button mat-button [matMenuTriggerFor]="menu" #t="matMenuTrigger">
Your Projects
<mat-icon iconPositionEnd>{{t.menuOpen ? 'expand_less' : 'expand_more'}}</mat-icon>
</button>

<mat-menu #menu="matMenu">
<button mat-menu-item>Some Project</button>
<button mat-menu-item>Another Project</button>
</mat-menu>
</div>

<span class="flex-auto"></span>

@if (isLoggedIn && userProfile) {
<userinfo [username]="userProfile!.username || ''" [fullName]="userProfile!.firstName + ' ' + userProfile!.lastName"
(logout)="logout()">
</userinfo>
}
</mat-toolbar>

<mat-drawer-container style="min-height: calc(100vh - 64px);">
<app-toolbar (sidebarEvent)="sidebarShown = $event">
</app-toolbar>

<mat-drawer-container>
<mat-drawer [opened]="sidebarShown" mode="side">
<div class="p-[6px] w-[224px] flex flex-col gap-[4px]">

Expand All @@ -39,7 +16,7 @@
[label]="'Backlog'" [selected]="selected == 'backlog'"></sidebar-button>

<sidebar-button (click)="navigateToBoard()" [selected]="selected == 'board'"
[iconName]="'akarClipboard'" [label]="'Board'"></sidebar-button>
[iconName]="'akarClipboard'" [label]="'Board'"></sidebar-button>

<sidebar-button (click)="{}" [iconName]="'octGraph'" [label]="'Reports'"
[selected]="selected == 'reports'"></sidebar-button>
Expand All @@ -52,8 +29,9 @@

</div>
</mat-drawer>

<mat-drawer-content>
<div class="pl-[24px] pt-[24px]">
<div class="overflow-hidden min-h-screen">
<router-outlet></router-outlet>
</div>
</mat-drawer-content>
Expand Down
28 changes: 5 additions & 23 deletions corn-frontend/src/app/pages/boards/boards.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { KeycloakProfile } from 'keycloak-js';
import { MatMenuModule, MatMenuTrigger } from '@angular/material/menu';
import { RouterPaths } from '@core/enum/RouterPaths';
import { BoardsPaths } from '@core/enum/BoardsPaths';
import { ToolbarComponent } from "@shared/toolbar/toolbar.component";

@Component({
selector: 'app-boards',
Expand All @@ -37,6 +38,7 @@ import { BoardsPaths } from '@core/enum/BoardsPaths';
MatMenuTrigger,
MatMenuModule,
CommonModule,
ToolbarComponent,
],
templateUrl: './boards.component.html',
})
Expand All @@ -47,30 +49,20 @@ export class BoardsComponent implements OnInit {

selected: string = '';

isLoggedIn: boolean = false;
userProfile?: KeycloakProfile;

constructor(
protected readonly router: Router,
protected readonly location: Location,
protected readonly keycloak: KeycloakService,
protected readonly location: Location
) {
}

async ngOnInit() {
async ngOnInit(): Promise<void> {
this.selected = this.location.path().split('/').pop() || '';

this.router.events.subscribe((val) => {
if (val instanceof NavigationEnd) {
this.selected = val.url.split('/').pop() || '';
}
});
this.isLoggedIn = this.keycloak.isLoggedIn();

if (this.isLoggedIn) {
this.userProfile = await this.keycloak.loadUserProfile();
} else {
this.router.navigate([RouterPaths.HOME_DIRECT_PATH]);
}
}

navigateToBacklog(): void {
Expand All @@ -84,14 +76,4 @@ export class BoardsComponent implements OnInit {
navigateToBoard(): void {
this.router.navigate([`/${RouterPaths.BOARDS_PATH}/${BoardsPaths.BOARD}`]);
}

toggleSidebar(): void {
this.sidebarShown = !this.sidebarShown;
}

logout(): void {
this.keycloak
.logout();
}

}
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
<app-toolbar [isOnProjectRoute]="true"></app-toolbar>

<div class="project-list">
<mat-grid-list [cols]="cols">
<mat-grid-tile><app-project [title]="'DevCooperation'"
Expand All @@ -15,4 +17,4 @@
<mat-grid-tile><app-project></app-project></mat-grid-tile>
<mat-grid-tile><app-project></app-project></mat-grid-tile>
</mat-grid-list>
</div>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@ import { Component, HostListener } from '@angular/core';
import { ProjectComponent } from "@pages/project-list/project/project.component";
import { MatGridList, MatGridTile } from "@angular/material/grid-list";
import { User } from "@core/interfaces/boards/user";
import { ToolbarComponent } from "@shared/toolbar/toolbar.component";

@Component({
selector: 'app-project-list',
standalone: true,
imports: [
ProjectComponent,
MatGridList,
MatGridTile
MatGridTile,
ToolbarComponent
],
templateUrl: './project-list.component.html',
styleUrl: './project-list.component.scss'
Expand Down
38 changes: 38 additions & 0 deletions corn-frontend/src/app/shared/toolbar/toolbar.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<mat-toolbar color="primary">
@if (!isOnProjectRoute) {
<div class="flex space-x-4 items-center">
<button mat-icon-button (click)="toggleSidebar()">
<mat-icon>{{ sidebarShown ? 'menu_open' : 'menu' }}</mat-icon>
</button>

<button mat-button [matMenuTriggerFor]="menu" #t="matMenuTrigger">
Your Projects
<mat-icon iconPositionEnd>{{ t.menuOpen ? 'expand_less' : 'expand_more' }}</mat-icon>
</button>

<mat-menu #menu="matMenu">
<button mat-menu-item>Some Project</button>
<button mat-menu-item>Another Project</button>
</mat-menu>
</div>
}

<span class="flex-auto"></span>

@if (!isOnProjectRoute) {
<button mat-icon-button
[routerLink]="RouterPaths.PROJECT_LIST_DIRECT_PATH"
class="center"
matTooltip="Go to projects"
aria-label="Go to projects">
<mat-icon>apps</mat-icon>
</button>
}

@if (isLoggedIn && userProfile) {
<userinfo [username]="userProfile!.username || ''"
[fullName]="userProfile!.firstName + ' ' + userProfile!.lastName"
(logout)="logout()">
</userinfo>
}
</mat-toolbar>
3 changes: 3 additions & 0 deletions corn-frontend/src/app/shared/toolbar/toolbar.component.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.center {
@apply flex items-center justify-center;
}
23 changes: 23 additions & 0 deletions corn-frontend/src/app/shared/toolbar/toolbar.component.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';

import { ToolbarComponent } from './toolbar.component';

describe('ToolbarComponent', () => {
let component: ToolbarComponent;
let fixture: ComponentFixture<ToolbarComponent>;

beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [ToolbarComponent]
})
.compileComponents();

fixture = TestBed.createComponent(ToolbarComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it('should create', () => {
expect(component).toBeTruthy();
});
});
64 changes: 64 additions & 0 deletions corn-frontend/src/app/shared/toolbar/toolbar.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core';
import { MatButton, MatIconButton } from "@angular/material/button";
import { MatIcon } from "@angular/material/icon";
import { MatMenu, MatMenuItem, MatMenuTrigger } from "@angular/material/menu";
import { MatToolbar } from "@angular/material/toolbar";
import { KeycloakProfile } from "keycloak-js";
import { UserinfoComponent } from "@pages/boards/userinfo/userinfo.component";
import { KeycloakService } from "keycloak-angular";
import { Router, RouterLink } from "@angular/router";
import { RouterPaths } from "@core/enum/RouterPaths";
import { MatTooltip } from "@angular/material/tooltip";

@Component({
selector: 'app-toolbar',
standalone: true,
imports: [
MatButton,
MatIcon,
MatIconButton,
MatMenu,
MatMenuItem,
MatToolbar,
UserinfoComponent,
MatMenuTrigger,
MatTooltip,
RouterLink
],
templateUrl: './toolbar.component.html',
styleUrl: './toolbar.component.scss'
})
export class ToolbarComponent implements OnInit {
@Input() isOnProjectRoute: boolean = false;
userProfile ?: KeycloakProfile;
isLoggedIn: boolean = false;
@Output() sidebarEvent: EventEmitter<boolean> = new EventEmitter<boolean>();
sidebarShown: boolean = true;

constructor(private keycloak: KeycloakService,
private router: Router) {
}

async ngOnInit(): Promise<void> {
this.isLoggedIn = this.keycloak.isLoggedIn();

if (this.isLoggedIn) {
this.userProfile = await this.keycloak.loadUserProfile();
console.log(this.userProfile);
} else {
this.router.navigate([RouterPaths.HOME_DIRECT_PATH]);
}
}

toggleSidebar(): void {
this.sidebarShown = !this.sidebarShown;

this.sidebarEvent.emit(this.sidebarShown);
}

logout(): void {
this.keycloak.logout();
}

protected readonly RouterPaths = RouterPaths;
}

0 comments on commit d01f08a

Please sign in to comment.