change dashboard -> recipe
This commit is contained in:
parent
e95078307b
commit
36be0426f6
9 changed files with 71 additions and 40 deletions
|
|
@ -1,6 +1,5 @@
|
||||||
import { NgModule, inject } from '@angular/core';
|
import { NgModule, inject } from '@angular/core';
|
||||||
import {
|
import {
|
||||||
ActivatedRoute,
|
|
||||||
ActivatedRouteSnapshot,
|
ActivatedRouteSnapshot,
|
||||||
CanActivateFn,
|
CanActivateFn,
|
||||||
Router,
|
Router,
|
||||||
|
|
@ -9,7 +8,7 @@ import {
|
||||||
Routes,
|
Routes,
|
||||||
} from '@angular/router';
|
} from '@angular/router';
|
||||||
import { UserService } from './core/services/user.service';
|
import { UserService } from './core/services/user.service';
|
||||||
import { lastValueFrom, map } from 'rxjs';
|
import { map } from 'rxjs';
|
||||||
|
|
||||||
const authGuard: CanActivateFn = (
|
const authGuard: CanActivateFn = (
|
||||||
route: ActivatedRouteSnapshot,
|
route: ActivatedRouteSnapshot,
|
||||||
|
|
@ -47,7 +46,7 @@ const loginGuard: CanActivateFn = (
|
||||||
// redirect to redirectUrl query param
|
// redirect to redirectUrl query param
|
||||||
console.log(route.queryParams['redirectUrl']);
|
console.log(route.queryParams['redirectUrl']);
|
||||||
return router.createUrlTree([
|
return router.createUrlTree([
|
||||||
router.parseUrl(route.queryParams['redirectUrl'] ?? '/dashboard'),
|
router.parseUrl(route.queryParams['redirectUrl'] ?? '/recipes'),
|
||||||
]);
|
]);
|
||||||
// return false;
|
// return false;
|
||||||
})
|
})
|
||||||
|
|
@ -76,12 +75,12 @@ const routes: Routes = [
|
||||||
{
|
{
|
||||||
path: '',
|
path: '',
|
||||||
pathMatch: 'full',
|
pathMatch: 'full',
|
||||||
redirectTo: 'dashboard',
|
redirectTo: 'recipes',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: 'dashboard',
|
path: 'recipes',
|
||||||
loadComponent: () =>
|
loadComponent: () =>
|
||||||
import('./features/dashboard/dashboard.component').then(
|
import('./features/recipes/recipes.component').then(
|
||||||
(m) => m.DashboardComponent
|
(m) => m.DashboardComponent
|
||||||
),
|
),
|
||||||
canActivate: [authGuard],
|
canActivate: [authGuard],
|
||||||
|
|
@ -90,7 +89,7 @@ const routes: Routes = [
|
||||||
path: 'recipe/:productCode',
|
path: 'recipe/:productCode',
|
||||||
loadComponent: () =>
|
loadComponent: () =>
|
||||||
import(
|
import(
|
||||||
'./features/dashboard/recipe-details/recipe-details.component'
|
'./features/recipes/recipe-details/recipe-details.component'
|
||||||
).then((m) => m.RecipeDetailsComponent),
|
).then((m) => m.RecipeDetailsComponent),
|
||||||
canActivate: [authGuard],
|
canActivate: [authGuard],
|
||||||
},
|
},
|
||||||
|
|
@ -103,7 +102,7 @@ const routes: Routes = [
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: '**',
|
path: '**',
|
||||||
redirectTo: 'dashboard',
|
redirectTo: 'recipes',
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -5,10 +5,16 @@ import { AppRoutingModule } from './app-routing.module';
|
||||||
import { HTTP_INTERCEPTORS, HttpClientModule } from '@angular/common/http';
|
import { HTTP_INTERCEPTORS, HttpClientModule } from '@angular/common/http';
|
||||||
import { AppComponent } from './app.component';
|
import { AppComponent } from './app.component';
|
||||||
import { ErrorInterceptor } from './core/interceptors/error.interceptor';
|
import { ErrorInterceptor } from './core/interceptors/error.interceptor';
|
||||||
|
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
|
||||||
|
|
||||||
@NgModule({
|
@NgModule({
|
||||||
declarations: [AppComponent],
|
declarations: [AppComponent],
|
||||||
imports: [BrowserModule, AppRoutingModule, HttpClientModule],
|
imports: [
|
||||||
|
BrowserModule,
|
||||||
|
AppRoutingModule,
|
||||||
|
HttpClientModule,
|
||||||
|
BrowserAnimationsModule,
|
||||||
|
],
|
||||||
providers: [
|
providers: [
|
||||||
{
|
{
|
||||||
provide: HTTP_INTERCEPTORS,
|
provide: HTTP_INTERCEPTORS,
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@
|
||||||
></path>
|
></path>
|
||||||
</svg>
|
</svg>
|
||||||
</button>
|
</button>
|
||||||
<a routerLink="/dashboard" class="flex ml-14 max-sm:hidden">
|
<a routerLink="/recipes" class="flex ml-14 max-sm:hidden">
|
||||||
<img
|
<img
|
||||||
src="assets/logo.svg"
|
src="assets/logo.svg"
|
||||||
class="h-10 md:h-20 px-4"
|
class="h-10 md:h-20 px-4"
|
||||||
|
|
@ -82,7 +82,7 @@
|
||||||
<ul class="py-1" role="none">
|
<ul class="py-1" role="none">
|
||||||
<li>
|
<li>
|
||||||
<a
|
<a
|
||||||
routerLink="/dashboard"
|
routerLink="/recipes"
|
||||||
class="block px-4 py-2 text-sm text-gray-700 hover:bg-gray-100"
|
class="block px-4 py-2 text-sm text-gray-700 hover:bg-gray-100"
|
||||||
role="menuitem"
|
role="menuitem"
|
||||||
>
|
>
|
||||||
|
|
@ -136,7 +136,7 @@
|
||||||
*ngIf="menu.icon_url"
|
*ngIf="menu.icon_url"
|
||||||
class="w-5 h-5 text-gray-500 transition duration-75 group-hover:text-gray-900"
|
class="w-5 h-5 text-gray-500 transition duration-75 group-hover:text-gray-900"
|
||||||
src="{{ menu.icon_url }}"
|
src="{{ menu.icon_url }}"
|
||||||
alt="dashboard icon"
|
alt="recipes icon"
|
||||||
/>
|
/>
|
||||||
<span class="ml-3 capitalize font-kanit">{{ menu.name }}</span>
|
<span class="ml-3 capitalize font-kanit">{{ menu.name }}</span>
|
||||||
</a>
|
</a>
|
||||||
|
|
|
||||||
|
|
@ -21,9 +21,9 @@ interface MenuItem {
|
||||||
export class LayoutComponent implements OnInit, OnDestroy {
|
export class LayoutComponent implements OnInit, OnDestroy {
|
||||||
menuItems: MenuItem[] = [
|
menuItems: MenuItem[] = [
|
||||||
{
|
{
|
||||||
name: 'Dashboard',
|
name: 'Recipe',
|
||||||
icon_url: 'assets/icons/dashboard.svg',
|
icon_url: 'assets/icons/recipes.svg',
|
||||||
link: '/dashboard',
|
link: '/recipes',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'Log',
|
name: 'Log',
|
||||||
|
|
|
||||||
|
|
@ -3,13 +3,17 @@
|
||||||
<div
|
<div
|
||||||
class="block col-span-1 p-6 bg-white border border-gray-200 rounded-lg shadow"
|
class="block col-span-1 p-6 bg-white border border-gray-200 rounded-lg shadow"
|
||||||
>
|
>
|
||||||
<h5 class="mb-2 text-2xl font-bold text-gray-900">
|
<div *ngIf="isLoaded; else indicator" [@inOutAnimation]>
|
||||||
กาแฟดำ(อเมริกาโน) | 12-03-0003
|
<h5 class="mb-2 text-xl font-bold text-gray-900">
|
||||||
|
{{ originalRecipeDetail?.name }} |
|
||||||
|
{{ originalRecipeDetail?.productCode }}
|
||||||
</h5>
|
</h5>
|
||||||
<div class="flex items-center mb-2">
|
<div class="flex items-center mb-2">
|
||||||
<div class="flex items-center mr-4">
|
<div class="flex items-center mr-4">
|
||||||
<p class="text-sm text-gray-500">สูตร</p>
|
<p class="text-sm text-gray-500">สูตร</p>
|
||||||
<p class="ml-2 text-sm text-gray-900">กาแฟดำ(อเมริกาโน)</p>
|
<p class="ml-2 text-sm text-gray-900">
|
||||||
|
{{ originalRecipeDetail?.name }}
|
||||||
|
</p>
|
||||||
</div>
|
</div>
|
||||||
<div class="flex items-center">
|
<div class="flex items-center">
|
||||||
<p class="text-sm text-gray-500">ประเภท</p>
|
<p class="text-sm text-gray-500">ประเภท</p>
|
||||||
|
|
@ -23,12 +27,19 @@
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<ng-template #indicator>
|
||||||
|
<div class="flex w-full h-full justify-center items-center">
|
||||||
|
<span class="loading loading-spinner w-20"></span>
|
||||||
|
</div>
|
||||||
|
</ng-template>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div
|
<div
|
||||||
class="block col-span-2 p-6 bg-white border border-gray-200 rounded-lg shadow"
|
class="block col-span-2 p-6 bg-white border border-gray-200 rounded-lg shadow min-h-[300px]"
|
||||||
>
|
>
|
||||||
<div
|
<div
|
||||||
*ngIf="isLoaded; else indicator"
|
*ngIf="isLoaded; else indicator"
|
||||||
|
[@inOutAnimation]
|
||||||
class="grid grid-cols-2 gap-4 w-full"
|
class="grid grid-cols-2 gap-4 w-full"
|
||||||
>
|
>
|
||||||
<div class="flex items-center">
|
<div class="flex items-center">
|
||||||
|
|
@ -318,6 +329,7 @@
|
||||||
<button
|
<button
|
||||||
(click)="onPressConfirmSave()"
|
(click)="onPressConfirmSave()"
|
||||||
class="btn btn-success w-36 text-white"
|
class="btn btn-success w-36 text-white"
|
||||||
|
[disabled]="!isValueChanged"
|
||||||
>
|
>
|
||||||
Save
|
Save
|
||||||
</button>
|
</button>
|
||||||
|
|
@ -6,6 +6,8 @@ import { isEqual } from 'lodash';
|
||||||
import { delay } from 'rxjs';
|
import { delay } from 'rxjs';
|
||||||
import { RecipeService } from 'src/app/core/services/recipe.service';
|
import { RecipeService } from 'src/app/core/services/recipe.service';
|
||||||
import { ConfirmModal } from 'src/app/shared/modal/confirm/confirm-modal.component';
|
import { ConfirmModal } from 'src/app/shared/modal/confirm/confirm-modal.component';
|
||||||
|
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
|
||||||
|
import { animate, style, transition, trigger } from '@angular/animations';
|
||||||
|
|
||||||
interface RecipeDetail {
|
interface RecipeDetail {
|
||||||
productCode: string;
|
productCode: string;
|
||||||
|
|
@ -33,6 +35,14 @@ interface RecipeMetaData {
|
||||||
templateUrl: './recipe-details.component.html',
|
templateUrl: './recipe-details.component.html',
|
||||||
standalone: true,
|
standalone: true,
|
||||||
imports: [NgIf, RouterLink, ReactiveFormsModule, ConfirmModal],
|
imports: [NgIf, RouterLink, ReactiveFormsModule, ConfirmModal],
|
||||||
|
animations: [
|
||||||
|
trigger('inOutAnimation', [
|
||||||
|
transition(':enter', [
|
||||||
|
style({ opacity: 0 }),
|
||||||
|
animate('1s ease-out', style({ opacity: 1 })),
|
||||||
|
]),
|
||||||
|
]),
|
||||||
|
],
|
||||||
})
|
})
|
||||||
export class RecipeDetailsComponent implements OnInit {
|
export class RecipeDetailsComponent implements OnInit {
|
||||||
title: string = 'Recipe Detail';
|
title: string = 'Recipe Detail';
|
||||||
|
|
@ -100,7 +110,7 @@ export class RecipeDetailsComponent implements OnInit {
|
||||||
message: 'Do you want to save changes?',
|
message: 'Do you want to save changes?',
|
||||||
confirmCallBack: () => {
|
confirmCallBack: () => {
|
||||||
console.log('confirm save');
|
console.log('confirm save');
|
||||||
this._router.navigate(['..']);
|
this._router.navigate(['/recipes']);
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -109,23 +119,27 @@ export class RecipeDetailsComponent implements OnInit {
|
||||||
message: 'Do you want to close without saving?',
|
message: 'Do you want to close without saving?',
|
||||||
confirmCallBack: () => {
|
confirmCallBack: () => {
|
||||||
console.log('confirm close');
|
console.log('confirm close');
|
||||||
this._router.navigate(['..']);
|
this._router.navigate(['/recipes']);
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
onPressConfirmSave() {
|
onPressConfirmSave() {
|
||||||
if (!isEqual(this.recipeDetail.value, this.originalRecipeDetail)) {
|
if (this.isValueChanged) {
|
||||||
this.showConfirmSaveModal.emit(true);
|
this.showConfirmSaveModal.emit(true);
|
||||||
} else {
|
} else {
|
||||||
this._router.navigate(['..']);
|
this._router.navigate(['/recipes']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
onPressConfirmClose() {
|
onPressConfirmClose() {
|
||||||
if (!isEqual(this.recipeDetail.value, this.originalRecipeDetail)) {
|
if (this.isValueChanged) {
|
||||||
this.showConfirmCloseModal.emit(true);
|
this.showConfirmCloseModal.emit(true);
|
||||||
} else {
|
} else {
|
||||||
this._router.navigate(['..']);
|
this._router.navigate(['/recipes']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get isValueChanged() {
|
||||||
|
return !isEqual(this.recipeDetail.value, this.originalRecipeDetail);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -11,10 +11,10 @@ import * as lodash from 'lodash';
|
||||||
import { ActivatedRoute, Router, RouterLink } from '@angular/router';
|
import { ActivatedRoute, Router, RouterLink } from '@angular/router';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-dashboard',
|
selector: 'app-recipes',
|
||||||
standalone: true,
|
standalone: true,
|
||||||
imports: [RouterLink, NgIf, NgFor, DatePipe, RecipeModalComponent],
|
imports: [RouterLink, NgIf, NgFor, DatePipe, RecipeModalComponent],
|
||||||
templateUrl: './dashboard.component.html',
|
templateUrl: './recipes.component.html',
|
||||||
})
|
})
|
||||||
export class DashboardComponent implements OnInit {
|
export class DashboardComponent implements OnInit {
|
||||||
recipes: Recipe | null = null;
|
recipes: Recipe | null = null;
|
||||||
|
Before Width: | Height: | Size: 340 B After Width: | Height: | Size: 340 B |
Loading…
Add table
Add a link
Reference in a new issue