Skip to content

Commit

Permalink
Add Admin module
Browse files Browse the repository at this point in the history
  • Loading branch information
Popovkov57 committed Sep 29, 2022
1 parent 66e14fd commit 418e624
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/app/admin/admin.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<div class="bg-info p-2 text-white">
<h3>Placeholder for Admin Features</h3>
</div>
7 changes: 7 additions & 0 deletions src/app/admin/admin.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { Component } from "@angular/core";

@Component({
templateUrl: "admin.component.html"
})

export class AdminComponent {}
18 changes: 18 additions & 0 deletions src/app/admin/admin.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { NgModule } from "@angular/core";
import { CommonModule } from "@angular/common";
import { FormsModule } from "@angular/forms";
import { RouterModule } from "@angular/router";
import { AuthComponent } from "./auth.component";
import { AdminComponent } from "./admin.component";

let routing = RouterModule.forChild([
{ path: "auth", component: AuthComponent },
{ path: "main", component: AdminComponent },
{ path: "**", redirectTo: "auth" },
])

@NgModule({
imports: [CommonModule, FormsModule, routing],
declarations: [AuthComponent, AdminComponent]
})
export class AdminModule{}
22 changes: 22 additions & 0 deletions src/app/admin/auth.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<div class="bg-info p-2 text-center">
<h3>SportsStore Admin</h3>
</div>
<div class="bg-danger mt-2 p-2 text-center text-white" *ngIf="errorMessage != null">
{{ errorMessage }}
</div>
<div class="p-2">
<form novalidate #form="ngForm" (ngSubmit)="authenticate(form)">
<div class="form-group">
<label>Name</label>
<input class="form-control" name="username" [(ngModel)]="username" required />
</div>
<div class="form-group">
<label>Password</label>
<input class="form-control" type="password" name="password" [(ngModel)]="password" required />
</div>
<div class="text-center">
<button class="btn btn-secondary m-1" routerLink="/">Go back></button>
<button class="btn btn-primary m-1" type="submit">Log in</button>
</div>
</form>
</div>
25 changes: 25 additions & 0 deletions src/app/admin/auth.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { Component } from "@angular/core";
import { NgForm } from "@angular/forms";
import { Router } from "@angular/router";

@Component({
templateUrl: "auth.component.html"
})

export class AuthComponent {

public username: string;
public password: string;
public errorMessage: string;

constructor(private router: Router){}

authenticate(form: NgForm) {
if (form.valid) {
//perform authentication
this.router.navigateByUrl("/admin/main");
} else {
this.errorMessage = "Form data invalid";
}
}
}
6 changes: 6 additions & 0 deletions src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { StoreFirstGuard } from './storeFirst.guard';
imports: [BrowserModule, StoreModule,
RouterModule.forRoot([
{

path: "store", component: StoreComponent,
canActivate: [StoreFirstGuard]
},
Expand All @@ -23,6 +24,11 @@ import { StoreFirstGuard } from './storeFirst.guard';
path: "checkout", component: CheckoutComponent,
canActivate: [StoreFirstGuard]
},
{
path: "admin",
loadChildren: () => import('./admin/admin.module').then(m => m.AdminModule),
canActivate: [StoreFirstGuard]
},
{ path: "**", redirectTo: "/store" }
])],
providers: [StoreFirstGuard],
Expand Down
3 changes: 3 additions & 0 deletions src/app/store/store.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
<button *ngFor="let category of categories" [class.active]="category == selectedCategory" class="btn btn-outline-primary btn-block" (click)="changeCategory(category)">
{{category}}
</button>
<button class="btn btn-block btn-danger m-t-3" routerLink="/admin">
Admin
</button>
</div>
</div>
<div class="col-9 p-2">
Expand Down

0 comments on commit 418e624

Please sign in to comment.