[frontend] Add dashboard routing and bare component logic
This commit is contained in:
parent
165263e559
commit
3e7bb6878f
|
@ -3,15 +3,17 @@ import { Routes, RouterModule } from '@angular/router';
|
||||||
import { DashboardComponent } from './dashboard.component';
|
import { DashboardComponent } from './dashboard.component';
|
||||||
import { HoodsComponent } from './hoods/hoods.component';
|
import { HoodsComponent } from './hoods/hoods.component';
|
||||||
import { SettingspageComponent } from './settingspage/settingspage.component';
|
import { SettingspageComponent } from './settingspage/settingspage.component';
|
||||||
|
import { AuthGuard } from '../core/auth/auth.guard';
|
||||||
|
|
||||||
const routes: Routes = [
|
const routes: Routes = [
|
||||||
{
|
{
|
||||||
path: '',
|
path: '',
|
||||||
component: DashboardComponent,
|
component: DashboardComponent,
|
||||||
children: [
|
children: [
|
||||||
{ path: 'list', component: HoodsComponent },
|
{ path: '', component: HoodsComponent },
|
||||||
{ path: 'settings', component: SettingspageComponent },
|
{ path: 'settings', component: SettingspageComponent },
|
||||||
],
|
],
|
||||||
|
canActivate: [AuthGuard],
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
<p>dashboard works!</p>
|
<router-outlet></router-outlet>
|
||||||
|
|
|
@ -3,9 +3,10 @@ import { CommonModule } from '@angular/common';
|
||||||
import { HoodsComponent } from './hoods/hoods.component';
|
import { HoodsComponent } from './hoods/hoods.component';
|
||||||
import { SettingspageComponent } from './settingspage/settingspage.component';
|
import { SettingspageComponent } from './settingspage/settingspage.component';
|
||||||
import { DashboardComponent } from './dashboard.component';
|
import { DashboardComponent } from './dashboard.component';
|
||||||
|
import { DashboardRoutingModule } from './dashboard-routing.module';
|
||||||
|
|
||||||
@NgModule({
|
@NgModule({
|
||||||
declarations: [HoodsComponent, SettingspageComponent, DashboardComponent],
|
declarations: [HoodsComponent, SettingspageComponent, DashboardComponent],
|
||||||
imports: [CommonModule],
|
imports: [CommonModule, DashboardRoutingModule],
|
||||||
})
|
})
|
||||||
export class DashboardModule {}
|
export class DashboardModule {}
|
||||||
|
|
|
@ -1 +1,2 @@
|
||||||
<p>hoods works!</p>
|
<p>hoods works!</p>
|
||||||
|
<div *ngFor="let item of hoods$ | async">{{ item.name }}</div>
|
||||||
|
|
|
@ -1,15 +1,23 @@
|
||||||
import { Component, OnInit } from '@angular/core';
|
import { Component, OnInit } from '@angular/core';
|
||||||
|
import { AdminService } from 'src/app/core/api';
|
||||||
|
import { map } from 'rxjs/operators';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-hoods',
|
selector: 'app-hoods',
|
||||||
templateUrl: './hoods.component.html',
|
templateUrl: './hoods.component.html',
|
||||||
styleUrls: ['./hoods.component.scss']
|
styleUrls: ['./hoods.component.scss'],
|
||||||
})
|
})
|
||||||
export class HoodsComponent implements OnInit {
|
export class HoodsComponent implements OnInit {
|
||||||
|
hoods$ = this.adminService.getHoodsAdmin().pipe(
|
||||||
|
map((hoods) => {
|
||||||
|
const result = hoods.map((hood) => {
|
||||||
|
return hood.hood;
|
||||||
|
});
|
||||||
|
return result;
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
constructor() { }
|
constructor(private readonly adminService: AdminService) {}
|
||||||
|
|
||||||
ngOnInit(): void {
|
|
||||||
}
|
|
||||||
|
|
||||||
|
ngOnInit(): void {}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1 +1,3 @@
|
||||||
<p>hoodpage works!</p>
|
<p>hoodpage works!</p>
|
||||||
|
|
||||||
|
{{ hood.landingpage }}
|
||||||
|
|
|
@ -1,15 +1,36 @@
|
||||||
import { Component, OnInit } from '@angular/core';
|
import { Component, OnInit } from '@angular/core';
|
||||||
|
import { ActivatedRoute, Router } from '@angular/router';
|
||||||
|
import { HoodsService, BodyHood } from '../core/api';
|
||||||
|
import { first } from 'rxjs/operators';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-hoodpage',
|
selector: 'app-hoodpage',
|
||||||
templateUrl: './hoodpage.component.html',
|
templateUrl: './hoodpage.component.html',
|
||||||
styleUrls: ['./hoodpage.component.scss']
|
styleUrls: ['./hoodpage.component.scss'],
|
||||||
})
|
})
|
||||||
export class HoodpageComponent implements OnInit {
|
export class HoodpageComponent implements OnInit {
|
||||||
|
hood: BodyHood;
|
||||||
|
|
||||||
constructor() { }
|
constructor(
|
||||||
|
private route: ActivatedRoute,
|
||||||
|
private router: Router,
|
||||||
|
private readonly hoodService: HoodsService
|
||||||
|
) {}
|
||||||
|
|
||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
|
const hoodId = this.route.snapshot.params['id'];
|
||||||
|
if (hoodId) {
|
||||||
|
this.hoodService
|
||||||
|
.getHood(hoodId)
|
||||||
|
.pipe(first())
|
||||||
|
.subscribe(
|
||||||
|
(data) => {
|
||||||
|
this.hood = data;
|
||||||
|
},
|
||||||
|
(error) => {
|
||||||
|
this.router.navigate(['/404']);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue