Part 3: Components

Overview

In this section, we'll explore the essential components of our application.

Completed code: live examplearrow-up-right / download examplearrow-up-right

Step 1: The Router

Before adding our components, we must configure the router and verify user authentication using our Guard.

Here is the updated code for the router.

circle-info

The oauth/callback path is crucial for the OAuth 2.0 Authorization Flow.

Typescript

chevron-rightapp-routing.module.tshashtag
import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';
import { LoginComponent } from '../components/login/login.component';

const routes: Routes = [
	{
		path: 'login',
		component: LoginComponent,
		runGuardsAndResolvers: 'always',
		title: 'Login',
	},
	{
		path: 'oauth/callback',
		component: LoginComponent,
		runGuardsAndResolvers: 'always',
	},
	{
		path: '',
		redirectTo: 'tasks',
		pathMatch: 'full',
		runGuardsAndResolvers: 'always',
	},
	{
		path: '**',
		redirectTo: 'tasks',
		runGuardsAndResolvers: 'always',
	},
];

@NgModule({
	imports: [RouterModule.forRoot(routes, { useHash: true })],
	exports: [RouterModule],
})
export class AppRoutingModule {}

The application will crash at this point, but that's ok! This is expected. We will fix it in a moment.

Step 2: RootComponent

Until now, we've used the default hello world template at src/app/components/app.component.ts. We'll remove this file, replacing it with the root component.

circle-info

If you check the index.html file, you will see that there is an element app-root which is where the application will be embedded within.

Note how we have three new components in the root component.

  • app-navigation is where the top nav bar will be inserted.

  • app-breadcrumbs will show where you are in the application, right below the nav bar but above the main content section.

  • router-outlet is where the Angular router will inject the rest of the components dynamically, based on the logic we implement.

Template

chevron-rightapp-root.component.htmlhashtag

Typescript

chevron-rightapp-root.component.tshashtag

Step 2: LoginComponent

Let's craft our inaugural component: the login page. The flow will use Authorization Code grant_type. This will redirect the user to the ProcessMaker installation you created the client application in, where they login and are then redirected back to the application with the authorization code.

circle-info

The components we will be creating will consist of two files: the template file and the typescript file.

Template

chevron-rightlogin.component.htmlhashtag

Typescript

chevron-rightlogin.component.tshashtag

Step 3: NavigationComponent

The navigation component houses the header logo and a logout button.

The ngIf="authService.authenticated" ensures the navbar displays only when the user is authenticated using our auth service.

Template

Typescript

Step 4: AppBreadCrumbsComponent

Template

chevron-rightapp-breadcrumbs.component.htmlhashtag

Typescript

chevron-rightapp-breadcrumbs.component.tshashtag

Step 5: AppModule

The updated app.module.ts contains the dependencies:

  • Router

  • RootComponent

  • LoginComponent

  • NavigationComponent

  • AppBreadCrumbsComponent

chevron-rightapp.module.tshashtag

Review

By following the steps, navigating to http://localhost:4200/#/login should display the login page.

Login

With the correct OAuth credentials and Client Application setup, logging into ProcessMaker should redirect you back to the login page, now displaying the navbar and breadcrumbs, indicating a successful login.

navbar authenticated

Next Steps

Part 4: The Inboxchevron-right

Last updated