update recipe now can select recipe file

This commit is contained in:
Kenta420 2023-10-03 15:06:50 +07:00
parent b25c836f0c
commit b5cb469a30
11 changed files with 209 additions and 236173 deletions

View file

@ -5,13 +5,37 @@
<table *ngIf="isLoaded" class="table">
<caption class="p-5 text-lg font-semibold text-left text-gray-900">
<div class="divide-y divide-solid divide-gray-400">
<div class="flex flex-row py-3">
<div class="flex flex-row py-3 justify-between">
<div class="flex flex-col">
<span
>Recipe Version {{ recipes?.MachineSetting?.configNumber }} |
{{"{{File name}}"}}</span
{{ fileName }}</span
>
</div>
<div class="flex flex-col ml-5">
<div class="dropdown dropdown-end">
<input
type="text"
tabindex="0"
placeholder="เลือก Recipe File"
class="input input-bordered input-sm w-full max-w-xs"
(input)="setRecipeVersion($event)"
(focus)="getRecipeVersions()"
/>
<div class="dropdown-content z-[1] max-h-[500px] overflow-y-auto">
<ul
tabindex="0"
class="menu p-2 shadow bg-base-100 rounded-box w-auto"
>
<li *ngFor="let recipeVersion of recipeVersions">
<a (click)="loadRecipe(recipeVersion)">{{
recipeVersion
}}</a>
</li>
</ul>
</div>
</div>
</div>
<div class="flex flex-col ml-auto">
<span class=""
>Last Updated:

View file

@ -6,6 +6,8 @@ import { Recipe, Recipe01 } from 'src/app/core/models/recipe.model';
import { RecipeService } from 'src/app/core/services/recipe.service';
import { environment } from 'src/environments/environment';
import { RecipeModalComponent } from 'src/app/shared/modal/recipe-modal.component';
import { BehaviorSubject } from 'rxjs';
import * as lodash from 'lodash';
@Component({
selector: 'app-dashboard',
@ -17,6 +19,8 @@ export class DashboardComponent implements OnInit {
userInfo: User | null = null;
recipes: Recipe | null = null;
recipes01: Recipe01[] | null = null;
recipeVersions: string[] = [];
fileName: string = '';
tableHeads: string[] = [
'Product Code',
@ -27,6 +31,11 @@ export class DashboardComponent implements OnInit {
];
private offset = 0;
private take = 10;
private recipeVersionData: string[] = [];
private currentRecipeVersion: string = 'coffeethai02_580.json';
recipeVersion: BehaviorSubject<string> = new BehaviorSubject<string>('');
recipeVersion$ = this.recipeVersion.asObservable();
isLoaded: boolean = false;
isLoadMore: boolean = false;
@ -52,8 +61,9 @@ export class DashboardComponent implements OnInit {
offset: this.offset,
take: this.take,
search: this.oldSearchStr,
version: this.currentRecipeVersion,
})
.subscribe(({ recipes, hasMore }) => {
.subscribe(({ recipes, hasMore, fileName }) => {
const { Recipe01, ...recipesWithoutRecipe01 } = recipes;
if (this.recipes01 && this.isHasMore) {
this.recipes01 = [...this.recipes01, ...Recipe01];
@ -64,6 +74,7 @@ export class DashboardComponent implements OnInit {
...recipesWithoutRecipe01,
Recipe01: [],
};
this.fileName = fileName;
this.offset += 10;
this.isLoadMore = false;
this.isHasMore = hasMore;
@ -89,8 +100,9 @@ export class DashboardComponent implements OnInit {
offset: this.offset,
take: this.take,
search: this.oldSearchStr,
version: this.currentRecipeVersion,
})
.subscribe(({ recipes, hasMore }) => {
.subscribe(({ recipes, hasMore, fileName }) => {
const { Recipe01, ...recipesWithoutRecipe01 } = recipes;
if (this.recipes01 && this.isHasMore) {
this.recipes01 = [...this.recipes01, ...Recipe01];
@ -101,10 +113,18 @@ export class DashboardComponent implements OnInit {
...recipesWithoutRecipe01,
Recipe01: [],
};
this.fileName = fileName;
this.offset += 10;
this.isLoaded = true;
this.isHasMore = hasMore;
});
this.recipeVersion$.subscribe((version) => {
if (version)
this.recipeVersions = lodash.filter(this.recipeVersionData, (v) =>
v.includes(version)
);
});
}
setSearch(event: Event) {
@ -119,8 +139,9 @@ export class DashboardComponent implements OnInit {
offset: this.offset,
take: this.take,
search: this.searchStr,
version: this.currentRecipeVersion,
})
.subscribe(({ recipes, hasMore }) => {
.subscribe(({ recipes, hasMore, fileName }) => {
const { Recipe01, ...recipesWithoutRecipe01 } = recipes;
this.recipes01 = Recipe01;
@ -128,13 +149,65 @@ export class DashboardComponent implements OnInit {
...recipesWithoutRecipe01,
Recipe01: [],
};
this.fileName = fileName;
this.offset += 10;
this.isLoaded = true;
this.isHasMore = hasMore;
});
}
loadRecipe(recipeVersion: string) {
// clear all recipes
this.recipes = null;
this.recipes01 = null;
this.offset = 0;
this.isLoaded = false;
this.isHasMore = true;
this.isLoadMore = false;
this.oldSearchStr = '';
this.currentRecipeVersion = recipeVersion;
this._recipeService
.getRecipes({
offset: this.offset,
take: this.take,
search: this.oldSearchStr,
version: recipeVersion,
})
.subscribe(({ recipes, hasMore, fileName }) => {
const { Recipe01, ...recipesWithoutRecipe01 } = recipes;
if (this.recipes01 && this.isHasMore) {
this.recipes01 = [...this.recipes01, ...Recipe01];
} else {
this.recipes01 = Recipe01;
}
this.recipes = {
...recipesWithoutRecipe01,
Recipe01: [],
};
this.fileName = fileName;
this.offset += 10;
this.isLoaded = true;
this.isHasMore = hasMore;
});
}
setRecipeVersion(event: Event) {
this.recipeVersion.next((event.target as HTMLInputElement).value);
}
getRecipeVersions() {
if (this.recipeVersionData.length > 0) return;
this._recipeService.getRecipeVersions().subscribe((versions) => {
this.recipeVersionData = versions;
this.recipeVersions = versions;
});
}
openJsonTab() {
window.open(environment.api + '/recipes/json', '_blank');
window.open(
environment.api + `/recipes/${this.currentRecipeVersion}/json`,
'_blank'
);
}
}