adjust mat selection
This commit is contained in:
parent
17030c72ce
commit
bf693aab2a
15 changed files with 548 additions and 186 deletions
|
|
@ -26,6 +26,25 @@ export class MaterialService {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getFullMaterialDetail(
|
||||||
|
country?: string,
|
||||||
|
filename?: string
|
||||||
|
): Observable<{
|
||||||
|
"materialId": number,
|
||||||
|
"name": string,
|
||||||
|
"type": string
|
||||||
|
}[] | null>{
|
||||||
|
console.log("getFullMaterialDetail", country, filename);
|
||||||
|
|
||||||
|
return this._httpClient.get<{
|
||||||
|
"materialId": number,
|
||||||
|
"name": string,
|
||||||
|
"type": string
|
||||||
|
}[]>(`${environment.api}/materials/full/${country}/${filename}`, {
|
||||||
|
withCredentials: true,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
getMaterialSettingById(
|
getMaterialSettingById(
|
||||||
id: number,
|
id: number,
|
||||||
country?: string,
|
country?: string,
|
||||||
|
|
|
||||||
25
client/src/app/core/services/topping.service.ts
Normal file
25
client/src/app/core/services/topping.service.ts
Normal file
|
|
@ -0,0 +1,25 @@
|
||||||
|
import { HttpClient } from '@angular/common/http';
|
||||||
|
import { Injectable } from '@angular/core';
|
||||||
|
import { Observable } from 'rxjs';
|
||||||
|
import { environment } from 'src/environments/environment';
|
||||||
|
import { Topping } from '../models/recipe.model';
|
||||||
|
|
||||||
|
@Injectable({
|
||||||
|
providedIn: 'root',
|
||||||
|
})
|
||||||
|
export class ToppingService {
|
||||||
|
constructor(private _httpClient: HttpClient) {}
|
||||||
|
|
||||||
|
getToppings(country: string, filename: string): Observable<Topping> {
|
||||||
|
return this._httpClient.get<Topping>(
|
||||||
|
`${environment.api}/recipes/${country}/${filename}/toppings`,
|
||||||
|
{
|
||||||
|
params: {
|
||||||
|
country: country,
|
||||||
|
filename: filename,
|
||||||
|
},
|
||||||
|
withCredentials: true
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -72,7 +72,7 @@
|
||||||
<input
|
<input
|
||||||
type="text"
|
type="text"
|
||||||
class="input input-sm input-bordered input-ghost w-full"
|
class="input input-sm input-bordered input-ghost w-full"
|
||||||
formControlName="Description"
|
formControlName="description"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div class="flex items-center">
|
<div class="flex items-center">
|
||||||
|
|
@ -96,6 +96,7 @@
|
||||||
[productCode]="productCode"
|
[productCode]="productCode"
|
||||||
(recipeListFormChange)="onRecipeListFormChange($event)"
|
(recipeListFormChange)="onRecipeListFormChange($event)"
|
||||||
></app-recipe-list>
|
></app-recipe-list>
|
||||||
|
<div *ngFor=""></div>
|
||||||
</div>
|
</div>
|
||||||
<div class="grid grid-cols-2 gap-4 mb-4">
|
<div class="grid grid-cols-2 gap-4 mb-4">
|
||||||
<div
|
<div
|
||||||
|
|
|
||||||
|
|
@ -10,10 +10,12 @@ import { RecipeListComponent } from './recipe-list/recipe-list.component';
|
||||||
import {
|
import {
|
||||||
RecipeDetail,
|
RecipeDetail,
|
||||||
RecipeDetailMat,
|
RecipeDetailMat,
|
||||||
|
Topping,
|
||||||
} from 'src/app/core/models/recipe.model';
|
} from 'src/app/core/models/recipe.model';
|
||||||
import { ActionRecord } from 'src/app/shared/actionRecord/actionRecord';
|
import { ActionRecord } from 'src/app/shared/actionRecord/actionRecord';
|
||||||
import { UserService } from 'src/app/core/services/user.service';
|
import { UserService } from 'src/app/core/services/user.service';
|
||||||
import { UserPermissions } from 'src/app/core/auth/userPermissions';
|
import { UserPermissions } from 'src/app/core/auth/userPermissions';
|
||||||
|
import { ToppingService } from 'src/app/core/services/topping.service';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-recipe-details',
|
selector: 'app-recipe-details',
|
||||||
|
|
@ -59,6 +61,7 @@ export class RecipeDetailsComponent implements OnInit {
|
||||||
private _route: ActivatedRoute,
|
private _route: ActivatedRoute,
|
||||||
private _router: Router,
|
private _router: Router,
|
||||||
private _recipeService: RecipeService,
|
private _recipeService: RecipeService,
|
||||||
|
private _toppingService: ToppingService,
|
||||||
private _userService: UserService
|
private _userService: UserService
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
|
|
@ -68,7 +71,7 @@ export class RecipeDetailsComponent implements OnInit {
|
||||||
productCode: '',
|
productCode: '',
|
||||||
name: '',
|
name: '',
|
||||||
otherName: '',
|
otherName: '',
|
||||||
Description: '',
|
description: '',
|
||||||
otherDescription: '',
|
otherDescription: '',
|
||||||
lastModified: new Date(),
|
lastModified: new Date(),
|
||||||
price: 0,
|
price: 0,
|
||||||
|
|
@ -79,6 +82,8 @@ export class RecipeDetailsComponent implements OnInit {
|
||||||
|
|
||||||
repl = []
|
repl = []
|
||||||
|
|
||||||
|
topping: Topping | null = null;
|
||||||
|
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
this.productCode = this._route.snapshot.params['productCode'];
|
this.productCode = this._route.snapshot.params['productCode'];
|
||||||
|
|
||||||
|
|
@ -96,6 +101,11 @@ export class RecipeDetailsComponent implements OnInit {
|
||||||
|
|
||||||
this.recipeDetailForm.valueChanges.subscribe(this.onRecipeDetailFormChange);
|
this.recipeDetailForm.valueChanges.subscribe(this.onRecipeDetailFormChange);
|
||||||
|
|
||||||
|
|
||||||
|
this._toppingService.getToppings(this.department, this._recipeService.getCurrentFile()).subscribe((data) => {
|
||||||
|
this.topping = data;
|
||||||
|
})
|
||||||
|
|
||||||
// snap recipe detail form value
|
// snap recipe detail form value
|
||||||
|
|
||||||
this.actionRecord.registerOnAddAction((currAction, allAction) => {
|
this.actionRecord.registerOnAddAction((currAction, allAction) => {
|
||||||
|
|
@ -132,7 +142,7 @@ export class RecipeDetailsComponent implements OnInit {
|
||||||
productCode: this.productCode,
|
productCode: this.productCode,
|
||||||
name: this.recipeDetailForm.getRawValue().name != this.recipeOriginalDetail.name ? this.recipeDetailForm.getRawValue().name : this.recipeOriginalDetail.name,
|
name: this.recipeDetailForm.getRawValue().name != this.recipeOriginalDetail.name ? this.recipeDetailForm.getRawValue().name : this.recipeOriginalDetail.name,
|
||||||
otherName: this.recipeDetailForm.getRawValue().otherName != this.recipeOriginalDetail.otherName ? this.recipeDetailForm.getRawValue().otherName : this.recipeOriginalDetail.otherName,
|
otherName: this.recipeDetailForm.getRawValue().otherName != this.recipeOriginalDetail.otherName ? this.recipeDetailForm.getRawValue().otherName : this.recipeOriginalDetail.otherName,
|
||||||
Description: this.recipeDetailForm.getRawValue().Description != this.recipeOriginalDetail.Description ? this.recipeDetailForm.getRawValue().Description : this.recipeOriginalDetail.Description,
|
description: this.recipeDetailForm.getRawValue().description != this.recipeOriginalDetail.description ? this.recipeDetailForm.getRawValue().description : this.recipeOriginalDetail.description,
|
||||||
otherDescription: this.recipeDetailForm.getRawValue().otherDescription != this.recipeOriginalDetail.otherDescription ? this.recipeDetailForm.getRawValue().otherDescription : this.recipeOriginalDetail.otherDescription,
|
otherDescription: this.recipeDetailForm.getRawValue().otherDescription != this.recipeOriginalDetail.otherDescription ? this.recipeDetailForm.getRawValue().otherDescription : this.recipeOriginalDetail.otherDescription,
|
||||||
LastChange: this.recipeDetailForm.getRawValue().lastModified != this.recipeOriginalDetail.lastModified ? this.recipeDetailForm.getRawValue().lastModified : this.recipeOriginalDetail.lastModified,
|
LastChange: this.recipeDetailForm.getRawValue().lastModified != this.recipeOriginalDetail.lastModified ? this.recipeDetailForm.getRawValue().lastModified : this.recipeOriginalDetail.lastModified,
|
||||||
price: this.recipeDetailForm.getRawValue().price != this.recipeOriginalDetail.price ? this.recipeDetailForm.getRawValue().price : this.recipeOriginalDetail.price,
|
price: this.recipeDetailForm.getRawValue().price != this.recipeOriginalDetail.price ? this.recipeDetailForm.getRawValue().price : this.recipeOriginalDetail.price,
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,12 @@
|
||||||
<input type="checkbox" class="toggle" formControlName="isUse" />
|
<input type="checkbox" class="toggle" formControlName="isUse" />
|
||||||
</td>
|
</td>
|
||||||
<td class="px-6 py-4 font-medium text-gray-900 whitespace-nowrap">
|
<td class="px-6 py-4 font-medium text-gray-900 whitespace-nowrap">
|
||||||
<input type="text" class="input" formControlName="materialPathId" />
|
<input
|
||||||
|
type="text"
|
||||||
|
class="input"
|
||||||
|
formControlName="materialPathId"
|
||||||
|
(click)="openMaterialList(i)"
|
||||||
|
/>
|
||||||
</td>
|
</td>
|
||||||
<td class="px-6 py-4 font-medium text-gray-900 whitespace-nowrap">
|
<td class="px-6 py-4 font-medium text-gray-900 whitespace-nowrap">
|
||||||
<input type="text" class="input" formControlName="name" />
|
<input type="text" class="input" formControlName="name" />
|
||||||
|
|
@ -55,3 +60,32 @@
|
||||||
</tr>
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
|
<!-- show material selector modal -->
|
||||||
|
|
||||||
|
<input
|
||||||
|
type="checkbox"
|
||||||
|
id="material_selector"
|
||||||
|
class="modal-toggle"
|
||||||
|
#checkBox="ngModel"
|
||||||
|
[(ngModel)]="showMaterialSelector"
|
||||||
|
/>
|
||||||
|
<label for="material_selector" class="modal">
|
||||||
|
<div class="modal-box max-h-[400px] overflow-scroll">
|
||||||
|
<div class="flex flex-row m-2 modal">
|
||||||
|
<p class="font-bold text-lg m-2">Materials</p>
|
||||||
|
</div>
|
||||||
|
<div
|
||||||
|
*ngFor="let material of materialList"
|
||||||
|
class="flex flex-row m-2 overflow-y-scroll"
|
||||||
|
>
|
||||||
|
<button
|
||||||
|
class="btn bg-primary btn-md border-2 text-base text-gray-700"
|
||||||
|
(click)="selectMaterial(currentSelectRecipeList!, material)"
|
||||||
|
>
|
||||||
|
{{ material.materialID }}
|
||||||
|
</button>
|
||||||
|
<h3 class="m-3">{{ material.PackageDescription }}</h3>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</label>
|
||||||
|
|
|
||||||
|
|
@ -5,33 +5,44 @@ import {
|
||||||
FormBuilder,
|
FormBuilder,
|
||||||
FormControl,
|
FormControl,
|
||||||
FormGroup,
|
FormGroup,
|
||||||
|
NgModel,
|
||||||
ReactiveFormsModule,
|
ReactiveFormsModule,
|
||||||
} from '@angular/forms';
|
} from '@angular/forms';
|
||||||
import { forEach, isEqual, sortBy } from 'lodash';
|
import { forEach, isEqual, sortBy } from 'lodash';
|
||||||
import { first } from 'rxjs';
|
import { first } from 'rxjs';
|
||||||
import { UserPermissions } from 'src/app/core/auth/userPermissions';
|
import { UserPermissions } from 'src/app/core/auth/userPermissions';
|
||||||
import {
|
import {
|
||||||
|
MaterialCode,
|
||||||
RecipeDetail,
|
RecipeDetail,
|
||||||
RecipeDetailMat,
|
RecipeDetailMat,
|
||||||
} from 'src/app/core/models/recipe.model';
|
} from 'src/app/core/models/recipe.model';
|
||||||
|
import { MaterialService } from 'src/app/core/services/material.service';
|
||||||
import { RecipeService } from 'src/app/core/services/recipe.service';
|
import { RecipeService } from 'src/app/core/services/recipe.service';
|
||||||
import { UserService } from 'src/app/core/services/user.service';
|
import { UserService } from 'src/app/core/services/user.service';
|
||||||
import { Action, ActionRecord } from 'src/app/shared/actionRecord/actionRecord';
|
import { Action, ActionRecord } from 'src/app/shared/actionRecord/actionRecord';
|
||||||
|
import { FormsModule } from '@angular/forms';
|
||||||
|
import { NgSelectModule } from '@ng-select/ng-select';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-recipe-list',
|
selector: 'app-recipe-list',
|
||||||
templateUrl: './recipe-list.component.html',
|
templateUrl: './recipe-list.component.html',
|
||||||
standalone: true,
|
standalone: true,
|
||||||
imports: [NgIf, NgFor, ReactiveFormsModule],
|
imports: [NgIf, NgFor, ReactiveFormsModule, FormsModule],
|
||||||
})
|
})
|
||||||
export class RecipeListComponent implements OnInit {
|
export class RecipeListComponent implements OnInit {
|
||||||
@Input({ required: true }) productCode!: string;
|
@Input({ required: true }) productCode!: string;
|
||||||
@Output() recipeListFormChange = new EventEmitter<unknown[]>();
|
@Output() recipeListFormChange = new EventEmitter<unknown[]>();
|
||||||
|
|
||||||
|
materialList: MaterialCode[] = [];
|
||||||
|
showMaterialSelector: boolean = false;
|
||||||
|
|
||||||
|
currentSelectRecipeList: number | null = null;
|
||||||
|
|
||||||
isMatLoaded: boolean = false;
|
isMatLoaded: boolean = false;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private _recipeService: RecipeService,
|
private _recipeService: RecipeService,
|
||||||
|
private _materialService: MaterialService,
|
||||||
private _formBuilder: FormBuilder,
|
private _formBuilder: FormBuilder,
|
||||||
private _userService: UserService
|
private _userService: UserService
|
||||||
) {}
|
) {}
|
||||||
|
|
@ -97,6 +108,10 @@ export class RecipeListComponent implements OnInit {
|
||||||
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
this._materialService.getMaterialCodes().subscribe((materials) => {
|
||||||
|
this.materialList = materials;
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
get recipeListData(): FormArray {
|
get recipeListData(): FormArray {
|
||||||
|
|
@ -106,4 +121,18 @@ export class RecipeListComponent implements OnInit {
|
||||||
isEditable(){
|
isEditable(){
|
||||||
return this._userService.getCurrentUser()!.permissions.includes(UserPermissions.EDITOR);
|
return this._userService.getCurrentUser()!.permissions.includes(UserPermissions.EDITOR);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
openMaterialList(i: any){
|
||||||
|
console.log("open material list for ", i);
|
||||||
|
this.showMaterialSelector = true;
|
||||||
|
this.currentSelectRecipeList = i;
|
||||||
|
}
|
||||||
|
|
||||||
|
selectMaterial(i: number, material: MaterialCode){
|
||||||
|
|
||||||
|
this.showMaterialSelector = false;
|
||||||
|
|
||||||
|
this.recipeListData.at(i).get('materialPathId')?.setValue(material.materialID);
|
||||||
|
console.log("set mat ", material.materialID, "to slot", i);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -141,6 +141,7 @@
|
||||||
<th>Comment</th>
|
<th>Comment</th>
|
||||||
<th>Editor</th>
|
<th>Editor</th>
|
||||||
<th>Date</th>
|
<th>Date</th>
|
||||||
|
<th>Based on</th>
|
||||||
</tr>
|
</tr>
|
||||||
<tr
|
<tr
|
||||||
class="row hover:bg-secondary"
|
class="row hover:bg-secondary"
|
||||||
|
|
@ -150,6 +151,7 @@
|
||||||
<td>{{ file.Msg }}</td>
|
<td>{{ file.Msg }}</td>
|
||||||
<td>{{ file.Editor }}</td>
|
<td>{{ file.Editor }}</td>
|
||||||
<td>{{ file.Created_at }}</td>
|
<td>{{ file.Created_at }}</td>
|
||||||
|
<td>{{ file.Relation }}</td>
|
||||||
<button class="btn bg-blue-400" (click)="loadSavedFile(file)">Select</button>
|
<button class="btn bg-blue-400" (click)="loadSavedFile(file)">Select</button>
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
|
|
@ -223,7 +225,7 @@
|
||||||
(input)="setSearch($event)"
|
(input)="setSearch($event)"
|
||||||
(keydown.enter)="search($event)"
|
(keydown.enter)="search($event)"
|
||||||
/>
|
/>
|
||||||
<ng-select
|
<!-- <ng-select
|
||||||
[items]="materialList"
|
[items]="materialList"
|
||||||
class="join-item text-base"
|
class="join-item text-base"
|
||||||
bindLabel="name"
|
bindLabel="name"
|
||||||
|
|
@ -236,6 +238,24 @@
|
||||||
<p class="text-xs">{{ item.name }}</p>
|
<p class="text-xs">{{ item.name }}</p>
|
||||||
<small class="text-xs text-gray-500">{{ item.id }}</small>
|
<small class="text-xs text-gray-500">{{ item.id }}</small>
|
||||||
</ng-template>
|
</ng-template>
|
||||||
|
</ng-select> -->
|
||||||
|
|
||||||
|
<!-- test material setting -->
|
||||||
|
<ng-select
|
||||||
|
[items]="materialDetail"
|
||||||
|
class="join-item text-base"
|
||||||
|
bindLabel="name"
|
||||||
|
bindValue="materialId"
|
||||||
|
[searchable]="true"
|
||||||
|
[multiple]="true"
|
||||||
|
[searchFn]="filterMaterial"
|
||||||
|
[closeOnSelect]="false"
|
||||||
|
[(ngModel)]="selectMaterialFilter"
|
||||||
|
>
|
||||||
|
<ng-template ng-option-tmp let-item="item">
|
||||||
|
<p class="text-xs">{{ item.name }} ({{ item.materialId }})</p>
|
||||||
|
<small class="text-xs text-gray-500">{{ item.materialId }}</small>
|
||||||
|
</ng-template>
|
||||||
</ng-select>
|
</ng-select>
|
||||||
<button class="btn join-item" (click)="search($event)">
|
<button class="btn join-item" (click)="search($event)">
|
||||||
Search
|
Search
|
||||||
|
|
|
||||||
|
|
@ -30,6 +30,7 @@ import { FormsModule } from '@angular/forms';
|
||||||
import { MaterialService } from 'src/app/core/services/material.service';
|
import { MaterialService } from 'src/app/core/services/material.service';
|
||||||
import { UserService } from 'src/app/core/services/user.service';
|
import { UserService } from 'src/app/core/services/user.service';
|
||||||
import { UserPermissions } from 'src/app/core/auth/userPermissions';
|
import { UserPermissions } from 'src/app/core/auth/userPermissions';
|
||||||
|
import { ToppingService } from 'src/app/core/services/topping.service';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-recipes',
|
selector: 'app-recipes',
|
||||||
|
|
@ -50,6 +51,19 @@ export class RecipesComponent implements OnInit, OnDestroy {
|
||||||
selectMaterialFilter: number[] | null = null;
|
selectMaterialFilter: number[] | null = null;
|
||||||
materialList: { id: number; name: string | number }[] | null = null;
|
materialList: { id: number; name: string | number }[] | null = null;
|
||||||
|
|
||||||
|
materialDetail:
|
||||||
|
| {
|
||||||
|
materialId: number;
|
||||||
|
name: string;
|
||||||
|
type: string;
|
||||||
|
}[]
|
||||||
|
| null = null;
|
||||||
|
|
||||||
|
toppings: {
|
||||||
|
toppingGroup: {} | null;
|
||||||
|
toppingList: {} | null;
|
||||||
|
} | null = null;
|
||||||
|
|
||||||
tableHeads: string[] = [
|
tableHeads: string[] = [
|
||||||
'Product Code',
|
'Product Code',
|
||||||
'Name',
|
'Name',
|
||||||
|
|
@ -73,7 +87,6 @@ export class RecipesComponent implements OnInit, OnDestroy {
|
||||||
|
|
||||||
department: string = this.route.parent!.snapshot.params['department'];
|
department: string = this.route.parent!.snapshot.params['department'];
|
||||||
|
|
||||||
|
|
||||||
@ViewChild('table', { static: false }) set content(table: ElementRef) {
|
@ViewChild('table', { static: false }) set content(table: ElementRef) {
|
||||||
// expose element ref for other fn
|
// expose element ref for other fn
|
||||||
|
|
||||||
|
|
@ -117,6 +130,7 @@ export class RecipesComponent implements OnInit, OnDestroy {
|
||||||
constructor(
|
constructor(
|
||||||
private _recipeService: RecipeService,
|
private _recipeService: RecipeService,
|
||||||
private _materialService: MaterialService,
|
private _materialService: MaterialService,
|
||||||
|
private _toppingService: ToppingService,
|
||||||
private route: ActivatedRoute,
|
private route: ActivatedRoute,
|
||||||
private _userService: UserService
|
private _userService: UserService
|
||||||
) {}
|
) {}
|
||||||
|
|
@ -147,26 +161,38 @@ export class RecipesComponent implements OnInit, OnDestroy {
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
this._recipeService.getSavedTmp(
|
this._recipeService
|
||||||
this._recipeService.getCurrentCountry(),
|
.getSavedTmp(
|
||||||
this._recipeService.getCurrentFile()
|
this._recipeService.getCurrentCountry(),
|
||||||
).subscribe({
|
this._recipeService.getCurrentFile()
|
||||||
next: (files:any) => {
|
)
|
||||||
console.log("Obtain saves: ", typeof files, files);
|
.subscribe({
|
||||||
if(files != undefined && typeof files === 'object'){
|
next: (files: any) => {
|
||||||
if(files.files != null){
|
console.log('Obtain saves: ', typeof files, files);
|
||||||
console.log("Obtain saves object: ", files.files[0], typeof files);
|
if (files != undefined && typeof files === 'object') {
|
||||||
|
if (files.files != null) {
|
||||||
|
console.log(
|
||||||
|
'Obtain saves object: ',
|
||||||
|
files.files[0],
|
||||||
|
typeof files
|
||||||
|
);
|
||||||
this.savedTmpfiles = files.files;
|
this.savedTmpfiles = files.files;
|
||||||
} else {
|
} else {
|
||||||
this.showSaveNoti = false;
|
this.showSaveNoti = false;
|
||||||
|
this.savedTmpfiles = [];
|
||||||
|
console.log(this.showSaveNoti, this.savedTmpfiles);
|
||||||
}
|
}
|
||||||
// let svf = (document.getElementById('select_savefile_modal') as HTMLInputElement)!.checked;
|
// let svf = (document.getElementById('select_savefile_modal') as HTMLInputElement)!.checked;
|
||||||
// console.log("isSavedModalOpened",svf)
|
// console.log("isSavedModalOpened",svf)
|
||||||
|
} else {
|
||||||
|
this.showSaveNoti = false;
|
||||||
|
this.savedTmpfiles = [];
|
||||||
|
console.log(this.showSaveNoti, this.savedTmpfiles);
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
},
|
// TODO: get all materials; MaterialSetting + MaterialCode
|
||||||
})
|
|
||||||
|
|
||||||
this._materialService
|
this._materialService
|
||||||
.getMaterialCodes()
|
.getMaterialCodes()
|
||||||
.pipe(
|
.pipe(
|
||||||
|
|
@ -181,10 +207,31 @@ export class RecipesComponent implements OnInit, OnDestroy {
|
||||||
this.materialList = materials;
|
this.materialList = materials;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
this._materialService
|
||||||
|
.getFullMaterialDetail(
|
||||||
|
this.department,
|
||||||
|
this._recipeService.getCurrentFile()
|
||||||
|
)
|
||||||
|
.subscribe((mat) => {
|
||||||
|
this.materialDetail = mat;
|
||||||
|
console.log(this.materialDetail?.length);
|
||||||
|
});
|
||||||
|
|
||||||
|
this._toppingService
|
||||||
|
.getToppings(this.department, this._recipeService.getCurrentFile())
|
||||||
|
.subscribe((tp) => {
|
||||||
|
this.toppings = {
|
||||||
|
toppingGroup: tp.ToppingGroup,
|
||||||
|
toppingList: tp.ToppingList,
|
||||||
|
};
|
||||||
|
// console.log(this.toppings);
|
||||||
|
});
|
||||||
|
|
||||||
this.initRecipeSelection();
|
this.initRecipeSelection();
|
||||||
}
|
}
|
||||||
|
|
||||||
setSearch(event: Event) {
|
setSearch(event: Event) {
|
||||||
|
console.log((event.target as HTMLInputElement).value);
|
||||||
this.searchStr = (event.target as HTMLInputElement).value;
|
this.searchStr = (event.target as HTMLInputElement).value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -268,18 +315,18 @@ export class RecipesComponent implements OnInit, OnDestroy {
|
||||||
// do perms
|
// do perms
|
||||||
let accessibleCountries = [];
|
let accessibleCountries = [];
|
||||||
|
|
||||||
for(let country of countries){
|
for (let country of countries) {
|
||||||
if(this.grantAccessCountry(country)){
|
if (this.grantAccessCountry(country)) {
|
||||||
accessibleCountries.push(country);
|
accessibleCountries.push(country);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log('granted accessible countries', accessibleCountries);
|
console.log('granted accessible countries', accessibleCountries);
|
||||||
|
|
||||||
if (accessibleCountries.length > 0) {
|
if (accessibleCountries.length > 0) {
|
||||||
this.recipeCountryFiltered = lodash.filter(accessibleCountries, (country) =>
|
this.recipeCountryFiltered = lodash.filter(
|
||||||
country.toLowerCase().includes(c.toLowerCase())
|
accessibleCountries,
|
||||||
|
(country) => country.toLowerCase().includes(c.toLowerCase())
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -287,19 +334,35 @@ export class RecipesComponent implements OnInit, OnDestroy {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Grant access to view a country recipe
|
// Grant access to view a country recipe
|
||||||
grantAccessCountry(countryName: string):boolean{
|
grantAccessCountry(countryName: string): boolean {
|
||||||
if(countryName.toLowerCase().startsWith("tha")
|
if (
|
||||||
&& this._userService.getCurrentUser()!.permissions.includes(UserPermissions.THAI_PERMISSION)){
|
countryName.toLowerCase().startsWith('tha') &&
|
||||||
|
this._userService
|
||||||
|
.getCurrentUser()!
|
||||||
|
.permissions.includes(UserPermissions.THAI_PERMISSION)
|
||||||
|
) {
|
||||||
|
return true;
|
||||||
|
} else if (
|
||||||
|
countryName.toLowerCase().startsWith('aus') &&
|
||||||
|
this._userService
|
||||||
|
.getCurrentUser()!
|
||||||
|
.permissions.includes(UserPermissions.AUS_PERMISSION)
|
||||||
|
) {
|
||||||
|
return true;
|
||||||
|
} else if (
|
||||||
|
countryName.toLowerCase().startsWith('malay') &&
|
||||||
|
this._userService
|
||||||
|
.getCurrentUser()!
|
||||||
|
.permissions.includes(UserPermissions.MALAY_PERMISSION)
|
||||||
|
) {
|
||||||
|
return true;
|
||||||
|
} else if (
|
||||||
|
countryName.toLowerCase().startsWith('alpha-3') &&
|
||||||
|
this._userService
|
||||||
|
.getCurrentUser()!
|
||||||
|
.permissions.includes(UserPermissions.ALPHA3_PERMISSION)
|
||||||
|
) {
|
||||||
return true;
|
return true;
|
||||||
} else if (countryName.toLowerCase().startsWith("aus")
|
|
||||||
&& this._userService.getCurrentUser()!.permissions.includes(UserPermissions.AUS_PERMISSION)){
|
|
||||||
return true;
|
|
||||||
} else if (countryName.toLowerCase().startsWith("malay")
|
|
||||||
&& this._userService.getCurrentUser()!.permissions.includes(UserPermissions.MALAY_PERMISSION)){
|
|
||||||
return true;
|
|
||||||
} else if (countryName.toLowerCase().startsWith("alpha-3")
|
|
||||||
&& this._userService.getCurrentUser()!.permissions.includes(UserPermissions.ALPHA3_PERMISSION)){
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
@ -379,11 +442,11 @@ export class RecipesComponent implements OnInit, OnDestroy {
|
||||||
}
|
}
|
||||||
|
|
||||||
// get tmp files
|
// get tmp files
|
||||||
openTmpFilesList(){
|
openTmpFilesList() {
|
||||||
// TODO: get tmp files to display or
|
// TODO: get tmp files to display or
|
||||||
}
|
}
|
||||||
|
|
||||||
openLoadSaves(){
|
openLoadSaves() {
|
||||||
this.showSaveNoti = false;
|
this.showSaveNoti = false;
|
||||||
this.saveTab = true;
|
this.saveTab = true;
|
||||||
}
|
}
|
||||||
|
|
@ -395,34 +458,38 @@ export class RecipesComponent implements OnInit, OnDestroy {
|
||||||
|
|
||||||
let country = this.department!;
|
let country = this.department!;
|
||||||
|
|
||||||
switch(country){
|
switch (country) {
|
||||||
case "tha":
|
case 'tha':
|
||||||
country = "Thailand";
|
country = 'Thailand';
|
||||||
break;
|
break;
|
||||||
case "aus":
|
case 'aus':
|
||||||
country = "Australia";
|
country = 'Australia';
|
||||||
break;
|
break;
|
||||||
case "mys":
|
case 'mys':
|
||||||
country = "Malaysia";
|
country = 'Malaysia';
|
||||||
break;
|
break;
|
||||||
case "alpha-3":
|
case 'alpha-3':
|
||||||
country = "alpha-3";
|
country = 'alpha-3';
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(file_commit.Change_file.split("/")[2]);
|
console.log(file_commit.Change_file.split('/')[2]);
|
||||||
|
|
||||||
this._recipeService
|
this._recipeService
|
||||||
.getRecipeOverview({
|
.getRecipeOverview({
|
||||||
offset: this.offset,
|
offset: this.offset,
|
||||||
take: this.take,
|
take: this.take,
|
||||||
search: this.oldSearchStr,
|
search: this.oldSearchStr,
|
||||||
filename: file_commit.Change_file.split("/")[2],
|
filename: file_commit.Change_file.split('/')[2],
|
||||||
country: country,
|
country: country,
|
||||||
materialIds: this.selectMaterialFilter || [],
|
materialIds: this.selectMaterialFilter || [],
|
||||||
}).subscribe(({ result, hasMore, totalCount }) => {
|
})
|
||||||
|
.subscribe(({ result, hasMore, totalCount }) => {
|
||||||
console.log('loadSavedFile', result);
|
console.log('loadSavedFile', result);
|
||||||
this._recipeService.setCurrentFile(file_commit.Change_file.split("/")[2]);
|
this._recipeService.setCurrentFile(
|
||||||
|
file_commit.Change_file.split('/')[2]
|
||||||
|
);
|
||||||
|
window.location.reload();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -434,4 +501,8 @@ export class RecipesComponent implements OnInit, OnDestroy {
|
||||||
this.currentFileFilterSubScription.unsubscribe();
|
this.currentFileFilterSubScription.unsubscribe();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
filterMaterial = (term: string, item: any) =>
|
||||||
|
item.name.toLowerCase().includes(term.toLowerCase()) ||
|
||||||
|
item.materialId.toString().includes(term);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
package data
|
package data
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/jmoiron/sqlx"
|
"github.com/jmoiron/sqlx"
|
||||||
|
|
@ -16,7 +17,8 @@ CREATE TABLE IF NOT EXISTS commit_log (
|
||||||
msg VARCHAR(255),
|
msg VARCHAR(255),
|
||||||
created_at DATETIME,
|
created_at DATETIME,
|
||||||
editor VARCHAR(255),
|
editor VARCHAR(255),
|
||||||
change_file VARCHAR(255)
|
change_file VARCHAR(255),
|
||||||
|
relation VARCHAR(255)
|
||||||
);
|
);
|
||||||
`
|
`
|
||||||
|
|
||||||
|
|
@ -26,6 +28,7 @@ type CommitLog struct {
|
||||||
Created_at string `db:"created_at"`
|
Created_at string `db:"created_at"`
|
||||||
Editor string `db:"editor"`
|
Editor string `db:"editor"`
|
||||||
Change_file string `db:"change_file"`
|
Change_file string `db:"change_file"`
|
||||||
|
Relation string `db:"relation"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func HashCommit(n int) (string, error) {
|
func HashCommit(n int) (string, error) {
|
||||||
|
|
@ -52,7 +55,7 @@ func Insert(c *CommitLog) error {
|
||||||
// init table in db
|
// init table in db
|
||||||
commit_db.MustExec(schema)
|
commit_db.MustExec(schema)
|
||||||
|
|
||||||
_, err = commit_db.NamedExec("INSERT INTO commit_log (id, msg, created_at, editor, change_file) VALUES (:id, :msg, :created_at, :editor, :change_file)", c)
|
_, err = commit_db.NamedExec("INSERT INTO commit_log (id, msg, created_at, editor, change_file, relation) VALUES (:id, :msg, :created_at, :editor, :change_file, :relation)", c)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
||||||
return err
|
return err
|
||||||
|
|
@ -74,8 +77,10 @@ func GetCommitLogOfFilename(countryId string, filename string) ([]CommitLog, err
|
||||||
}
|
}
|
||||||
|
|
||||||
commitDB, err := sqlx.Connect("sqlite3", "./data/database.db")
|
commitDB, err := sqlx.Connect("sqlite3", "./data/database.db")
|
||||||
|
// fmt.Println("GetCommitLogOfFilename", err)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
||||||
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
var commits []CommitLog
|
var commits []CommitLog
|
||||||
|
|
@ -84,6 +89,12 @@ func GetCommitLogOfFilename(countryId string, filename string) ([]CommitLog, err
|
||||||
|
|
||||||
err = commitDB.Select(&commits, "SELECT * FROM commit_log WHERE change_file LIKE ?", "%"+filename+"%")
|
err = commitDB.Select(&commits, "SELECT * FROM commit_log WHERE change_file LIKE ?", "%"+filename+"%")
|
||||||
|
|
||||||
|
// fmt.Println("commits", err)
|
||||||
|
if err != nil {
|
||||||
|
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
var commitsByCountryID []CommitLog
|
var commitsByCountryID []CommitLog
|
||||||
|
|
||||||
for _, v := range commits {
|
for _, v := range commits {
|
||||||
|
|
@ -101,6 +112,12 @@ func GetCommitLogOfFilename(countryId string, filename string) ([]CommitLog, err
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// fmt.Println("commitsByCountryID", len(commitsByCountryID) == 0)
|
||||||
|
if len(commitsByCountryID) == 0 {
|
||||||
|
|
||||||
|
return nil, fmt.Errorf("no commit found for %s", filename)
|
||||||
|
}
|
||||||
|
|
||||||
return commitsByCountryID, nil
|
return commitsByCountryID, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ import (
|
||||||
"recipe-manager/helpers"
|
"recipe-manager/helpers"
|
||||||
"recipe-manager/models"
|
"recipe-manager/models"
|
||||||
"recipe-manager/services/logger"
|
"recipe-manager/services/logger"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"reflect"
|
"reflect"
|
||||||
|
|
@ -28,9 +29,8 @@ type Data struct {
|
||||||
taoLogger *logger.TaoLogger
|
taoLogger *logger.TaoLogger
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewData(taoLogger *logger.TaoLogger) *Data {
|
var (
|
||||||
|
countries = []helpers.CountryName{{
|
||||||
countries := []helpers.CountryName{{
|
|
||||||
CountryID: "tha",
|
CountryID: "tha",
|
||||||
CountryName: "Thailand",
|
CountryName: "Thailand",
|
||||||
}, {
|
}, {
|
||||||
|
|
@ -41,6 +41,9 @@ func NewData(taoLogger *logger.TaoLogger) *Data {
|
||||||
CountryName: "Australia",
|
CountryName: "Australia",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
func NewData(taoLogger *logger.TaoLogger) *Data {
|
||||||
|
|
||||||
allRecipeFiles := helpers.ScanRecipeFiles(countries)
|
allRecipeFiles := helpers.ScanRecipeFiles(countries)
|
||||||
|
|
||||||
|
|
@ -129,22 +132,35 @@ func (d *Data) GetCurrentRecipe() *models.Recipe {
|
||||||
|
|
||||||
func (d *Data) GetRecipe01ByProductCode(filename, countryID, productCode string) (models.Recipe01, error) {
|
func (d *Data) GetRecipe01ByProductCode(filename, countryID, productCode string) (models.Recipe01, error) {
|
||||||
|
|
||||||
if filename == "" || filename == d.CurrentFile {
|
if !strings.Contains(filename, "tmp") {
|
||||||
for _, v := range d.currentRecipe.Recipe01 {
|
if filename == "" || filename == d.CurrentFile {
|
||||||
if v.ProductCode == productCode {
|
fmt.Println("GetRecipe01ByProductCode.ReadCurrent", filename, d.CurrentFile)
|
||||||
return v, nil
|
for _, v := range d.currentRecipe.Recipe01 {
|
||||||
|
if v.ProductCode == productCode {
|
||||||
|
return v, nil
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
} else if recipe, ok := d.recipeMap[filename]; ok {
|
||||||
} else if recipe, ok := d.recipeMap[filename]; ok {
|
fmt.Println("GetRecipe01ByProductCode.ReadMap", filename, d.CurrentFile)
|
||||||
for _, v := range recipe.Recipe.Recipe01 {
|
for _, v := range recipe.Recipe.Recipe01 {
|
||||||
if v.ProductCode == productCode {
|
if v.ProductCode == productCode {
|
||||||
return v, nil
|
return v, nil
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
d.CurrentFile = filename
|
d.CurrentFile = filename
|
||||||
d.CurrentCountryID = countryID
|
d.CurrentCountryID = countryID
|
||||||
|
|
||||||
|
for _, v := range countries {
|
||||||
|
if v.CountryName == countryID {
|
||||||
|
d.CurrentCountryID = v.CountryID
|
||||||
|
countryID = v.CountryID
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
recipe, err := helpers.ReadRecipeFile(countryID, filename)
|
recipe, err := helpers.ReadRecipeFile(countryID, filename)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -179,6 +195,7 @@ func (d *Data) GetRecipe01ByProductCode(filename, countryID, productCode string)
|
||||||
|
|
||||||
for _, v := range d.currentRecipe.Recipe01 {
|
for _, v := range d.currentRecipe.Recipe01 {
|
||||||
if v.ProductCode == productCode {
|
if v.ProductCode == productCode {
|
||||||
|
// d.taoLogger.Log.Debug("GetRecipe01ByProductCode", zap.Any("productCode", productCode), zap.Any("result", v))
|
||||||
return v, nil
|
return v, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -186,7 +203,6 @@ func (d *Data) GetRecipe01ByProductCode(filename, countryID, productCode string)
|
||||||
return models.Recipe01{}, fmt.Errorf("product code: %s not found", productCode)
|
return models.Recipe01{}, fmt.Errorf("product code: %s not found", productCode)
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME: saved in log but not actual file
|
|
||||||
func (d *Data) SetValuesToRecipe(base_recipe []models.Recipe01, recipe models.Recipe01) {
|
func (d *Data) SetValuesToRecipe(base_recipe []models.Recipe01, recipe models.Recipe01) {
|
||||||
not_found := false
|
not_found := false
|
||||||
global_idx := 0
|
global_idx := 0
|
||||||
|
|
@ -203,7 +219,7 @@ func (d *Data) SetValuesToRecipe(base_recipe []models.Recipe01, recipe models.Re
|
||||||
|
|
||||||
for k, v := range recipe01_Map {
|
for k, v := range recipe01_Map {
|
||||||
if !reflect.DeepEqual(base_recipe01_Map[k], v) {
|
if !reflect.DeepEqual(base_recipe01_Map[k], v) {
|
||||||
d.taoLogger.Log.Debug("SetValuesToRecipe", zap.Any("key", k), zap.Any("value", v), zap.Any("old", base_recipe01_Map[k]), zap.Any("new", recipe01_Map[k]))
|
d.taoLogger.Log.Debug("SetValuesToRecipe", zap.Any("key", k))
|
||||||
base_recipe01_Map[k] = v
|
base_recipe01_Map[k] = v
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -231,16 +247,19 @@ func (d *Data) GetMaterialSetting(countryID, filename string) []models.MaterialS
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
if filename == "" || filename == d.CurrentFile {
|
if !strings.Contains(filename, "tmp") {
|
||||||
copy(result, d.currentRecipe.MaterialSetting)
|
if filename == "" || filename == d.CurrentFile {
|
||||||
return result
|
copy(result, d.currentRecipe.MaterialSetting)
|
||||||
}
|
d.taoLogger.Log.Debug("GetMaterialSetting", zap.Any("result", result))
|
||||||
|
return d.currentRecipe.MaterialSetting
|
||||||
|
}
|
||||||
|
|
||||||
if recipe, ok := d.recipeMap[filename]; ok {
|
if recipe, ok := d.recipeMap[filename]; ok {
|
||||||
copy(result, recipe.Recipe.MaterialSetting)
|
copy(result, recipe.Recipe.MaterialSetting)
|
||||||
d.CurrentFile = filename
|
d.CurrentFile = filename
|
||||||
d.CurrentCountryID = countryID
|
d.CurrentCountryID = countryID
|
||||||
return result
|
return d.currentRecipe.MaterialSetting
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
d.CurrentFile = filename
|
d.CurrentFile = filename
|
||||||
|
|
@ -250,9 +269,11 @@ func (d *Data) GetMaterialSetting(countryID, filename string) []models.MaterialS
|
||||||
if err != nil {
|
if err != nil {
|
||||||
d.taoLogger.Log.Error("Error when read recipe file, Return default recipe", zap.Error(err))
|
d.taoLogger.Log.Error("Error when read recipe file, Return default recipe", zap.Error(err))
|
||||||
copy(result, d.currentRecipe.MaterialSetting)
|
copy(result, d.currentRecipe.MaterialSetting)
|
||||||
return result
|
return d.currentRecipe.MaterialSetting
|
||||||
}
|
}
|
||||||
|
|
||||||
|
d.taoLogger.Log.Debug("GetMaterialSetting", zap.Any("recipe", recipe.MaterialSetting))
|
||||||
|
|
||||||
d.currentRecipe = recipe
|
d.currentRecipe = recipe
|
||||||
|
|
||||||
// save to map
|
// save to map
|
||||||
|
|
@ -274,8 +295,8 @@ func (d *Data) GetMaterialSetting(countryID, filename string) []models.MaterialS
|
||||||
TimeStamps: time.Now().Unix(),
|
TimeStamps: time.Now().Unix(),
|
||||||
}
|
}
|
||||||
|
|
||||||
copy(result, d.currentRecipe.MaterialSetting)
|
// copy(result, recipe.MaterialSetting)
|
||||||
return result
|
return recipe.MaterialSetting
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *Data) GetMaterialCode(ids []uint64, countryID, filename string) []models.MaterialCode {
|
func (d *Data) GetMaterialCode(ids []uint64, countryID, filename string) []models.MaterialCode {
|
||||||
|
|
@ -341,6 +362,39 @@ func (d *Data) GetMaterialCode(ids []uint64, countryID, filename string) []model
|
||||||
return resultFilter
|
return resultFilter
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (d *Data) GetToppings(countryID, filename string) models.Topping {
|
||||||
|
|
||||||
|
if filename == "" || filename == d.CurrentFile {
|
||||||
|
return d.currentRecipe.Topping
|
||||||
|
} else if recipe, ok := d.recipeMap[filename]; ok {
|
||||||
|
d.CurrentFile = filename
|
||||||
|
return recipe.Recipe.Topping
|
||||||
|
}
|
||||||
|
d.CurrentFile = filename
|
||||||
|
d.CurrentCountryID = countryID
|
||||||
|
recipe, err := helpers.ReadRecipeFile(countryID, filename)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
d.taoLogger.Log.Error("Error when read recipe file, Return default recipe", zap.Error(err))
|
||||||
|
return d.currentRecipe.Topping
|
||||||
|
}
|
||||||
|
|
||||||
|
d.currentRecipe = recipe
|
||||||
|
|
||||||
|
return recipe.Topping
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *Data) GetToppingsOfRecipe(countryID, filename string, productCode string) ([]models.ToppingSet, error) {
|
||||||
|
recipe, err := d.GetRecipe01ByProductCode(filename, countryID, productCode)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
d.taoLogger.Log.Error("Error when read recipe file, Return default recipe", zap.Error(err))
|
||||||
|
return []models.ToppingSet{}, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return recipe.ToppingSet, nil
|
||||||
|
}
|
||||||
|
|
||||||
func (d *Data) GetCountryNameByID(countryID string) (string, error) {
|
func (d *Data) GetCountryNameByID(countryID string) (string, error) {
|
||||||
for _, country := range d.Countries {
|
for _, country := range d.Countries {
|
||||||
if country.CountryID == countryID {
|
if country.CountryID == countryID {
|
||||||
|
|
|
||||||
Binary file not shown.
|
|
@ -50,6 +50,9 @@ type MaterialSetting struct {
|
||||||
PayRettryMaxCount int `json:"pay_rettry_max_count"`
|
PayRettryMaxCount int `json:"pay_rettry_max_count"`
|
||||||
FeedMode string `json:"feed_mode"`
|
FeedMode string `json:"feed_mode"`
|
||||||
MaterialParameter string `json:"MaterialParameter"`
|
MaterialParameter string `json:"MaterialParameter"`
|
||||||
|
MaterialName string `json:"materialName"`
|
||||||
|
MaterialOtherName string `json:"materialOtherName"`
|
||||||
|
RawMaterialUnit string `json:"RawMaterialUnit"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Recipe01 struct {
|
type Recipe01 struct {
|
||||||
|
|
|
||||||
|
|
@ -2,14 +2,15 @@ package routers
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"github.com/go-chi/chi/v5"
|
|
||||||
"go.uber.org/zap"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"recipe-manager/data"
|
"recipe-manager/data"
|
||||||
"recipe-manager/models"
|
"recipe-manager/models"
|
||||||
"recipe-manager/services/logger"
|
"recipe-manager/services/logger"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/go-chi/chi/v5"
|
||||||
|
"go.uber.org/zap"
|
||||||
)
|
)
|
||||||
|
|
||||||
type MaterialRouter struct {
|
type MaterialRouter struct {
|
||||||
|
|
@ -29,9 +30,72 @@ func (mr *MaterialRouter) Route(r chi.Router) {
|
||||||
r.Get("/code", mr.getMaterialCode)
|
r.Get("/code", mr.getMaterialCode)
|
||||||
|
|
||||||
r.Get("/setting/{mat_id}", mr.getMaterialSettingByMatID)
|
r.Get("/setting/{mat_id}", mr.getMaterialSettingByMatID)
|
||||||
|
|
||||||
|
r.Get("/full/{country}/{filename}", mr.GetFullMaterialDetail)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (mr *MaterialRouter) GetFullMaterialDetail(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
|
w.Header().Add("Content-Type", "application/json")
|
||||||
|
|
||||||
|
country := chi.URLParam(r, "country")
|
||||||
|
filename := chi.URLParam(r, "filename")
|
||||||
|
|
||||||
|
mr.taoLogger.Log.Debug("GetFullMaterialDetail", zap.Any("country", country), zap.Any("filename", filename))
|
||||||
|
|
||||||
|
// get material setting and code
|
||||||
|
matSettings := mr.data.GetMaterialSetting(country, filename)
|
||||||
|
matCodes := mr.data.GetRecipe(country, filename).MaterialCode
|
||||||
|
|
||||||
|
// combine
|
||||||
|
materialDetails := []map[string]interface{}{}
|
||||||
|
|
||||||
|
for _, matSetting := range matSettings {
|
||||||
|
|
||||||
|
// if material name exist
|
||||||
|
mat_name := ""
|
||||||
|
if matSetting.MaterialName != "" {
|
||||||
|
mat_name = matSetting.MaterialName
|
||||||
|
// mr.taoLogger.Log.Debug("GetFullMaterialDetail", zap.Any("mat_name", mat_name))
|
||||||
|
} else {
|
||||||
|
|
||||||
|
for _, matCode := range matCodes {
|
||||||
|
if matCode.MaterialID == matSetting.ID {
|
||||||
|
mat_name = matCode.PackageDescription
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
materialDetails = append(materialDetails, map[string]interface{}{
|
||||||
|
"materialId": matSetting.ID,
|
||||||
|
"name": mat_name,
|
||||||
|
"type": "powder:" + strconv.FormatBool(matSetting.PowderChannel) + ",syrup:" + strconv.FormatBool(matSetting.SyrupChannel) + ",bean:" + strconv.FormatBool(matSetting.BeanChannel) + ",equipment:" + strconv.FormatBool(matSetting.IsEquipment),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// for _, matCode := range matCodes {
|
||||||
|
// for index, matDetail := range materialDetails {
|
||||||
|
// if matCode.MaterialID == matDetail["materialId"] {
|
||||||
|
// materialDetails[index]["name"] = matCode.PackageDescription
|
||||||
|
// } else if matDetail["materialId"].(uint64) > 8110 && matDetail["materialId"].(uint64) <= 8130 {
|
||||||
|
// slotNum := matDetail["materialId"].(uint64) - 8110
|
||||||
|
// // mr.taoLogger.Log.Debug("GetFullMaterialDetail", zap.Any("slotNum", matDetail["materialId"]), zap.Any("slotNum", slotNum))
|
||||||
|
// materialDetails[index]["name"] = "Topping" + strconv.Itoa(int(slotNum))
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
// send result
|
||||||
|
if err := json.NewEncoder(w).Encode(materialDetails); err != nil {
|
||||||
|
mr.taoLogger.Log.Error("MaterialRouter.GetFullMaterialDetail", zap.Error(err))
|
||||||
|
http.Error(w, "Internal Error", http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
func (mr *MaterialRouter) getMaterialCode(w http.ResponseWriter, r *http.Request) {
|
func (mr *MaterialRouter) getMaterialCode(w http.ResponseWriter, r *http.Request) {
|
||||||
w.Header().Add("Content-Type", "application/json")
|
w.Header().Add("Content-Type", "application/json")
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -53,12 +53,12 @@ func (rr *RecipeRouter) Route(r chi.Router) {
|
||||||
|
|
||||||
r.Get("/{product_code}/mat", rr.getRecipeMatByProductCode)
|
r.Get("/{product_code}/mat", rr.getRecipeMatByProductCode)
|
||||||
|
|
||||||
|
r.Get("/{country}/{filename}/toppings", rr.getToppings)
|
||||||
|
|
||||||
r.Get("/{country}/{filename}/json", rr.getRecipeJson)
|
r.Get("/{country}/{filename}/json", rr.getRecipeJson)
|
||||||
|
|
||||||
r.Post("/edit/{country}/{filename}", rr.updateRecipe)
|
r.Post("/edit/{country}/{filename}", rr.updateRecipe)
|
||||||
|
|
||||||
r.Post("/upgrade/{country}/{filename}", rr.ApplyTmpChanges)
|
|
||||||
|
|
||||||
r.Get("/saved/{country}/{filename_version_only}", rr.getSavedRecipes)
|
r.Get("/saved/{country}/{filename_version_only}", rr.getSavedRecipes)
|
||||||
|
|
||||||
r.Get("/countries", func(w http.ResponseWriter, r *http.Request) {
|
r.Get("/countries", func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
@ -336,7 +336,7 @@ func (rr *RecipeRouter) updateRecipe(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
rr.taoLogger.Log.Debug("Changes: ", zap.Any("changes", changes))
|
rr.taoLogger.Log.Debug("Changes: ", zap.Any("changes", changes))
|
||||||
// TODO: find the matched pd
|
// TODO: find the matched pd
|
||||||
targetMenu, err := rr.data.GetRecipe01ByProductCode(filename, countryID, changes.ProductCode)
|
_, err = rr.data.GetRecipe01ByProductCode(filename, countryID, changes.ProductCode)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
rr.taoLogger.Log.Error("RecipeRouter.UpdateRecipe", zap.Error(errors.WithMessage(err, "Error when get recipe by product code")))
|
rr.taoLogger.Log.Error("RecipeRouter.UpdateRecipe", zap.Error(errors.WithMessage(err, "Error when get recipe by product code")))
|
||||||
|
|
@ -344,28 +344,28 @@ func (rr *RecipeRouter) updateRecipe(w http.ResponseWriter, r *http.Request) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
menuMap := targetMenu.ToMap()
|
// menuMap := targetMenu.ToMap()
|
||||||
changeMap := changes.ToMap()
|
changeMap := changes.ToMap()
|
||||||
|
|
||||||
// Find changes
|
// Find changes
|
||||||
for key, val := range menuMap {
|
// for key, val := range menuMap {
|
||||||
// rr.taoLogger.Log.Debug("..DynamicCompare.key", zap.Any("key", key))
|
// // rr.taoLogger.Log.Debug("..DynamicCompare.key", zap.Any("key", key))
|
||||||
testBool, err := helpers.DynamicCompare(val, changeMap[key])
|
// testBool, err := helpers.DynamicCompare(val, changeMap[key])
|
||||||
|
|
||||||
// if err != nil {
|
// // if err != nil {
|
||||||
// rr.taoLogger.Log.Error("RecipeRouter.UpdateRecipe", zap.Error(errors.WithMessage(err, "DynamicCompare in request failed")))
|
// // rr.taoLogger.Log.Error("RecipeRouter.UpdateRecipe", zap.Error(errors.WithMessage(err, "DynamicCompare in request failed")))
|
||||||
// http.Error(w, "Internal Error", http.StatusInternalServerError)
|
// // http.Error(w, "Internal Error", http.StatusInternalServerError)
|
||||||
// return
|
// // return
|
||||||
// }
|
// // }
|
||||||
|
|
||||||
if !testBool && err == nil {
|
// if !testBool && err == nil {
|
||||||
menuMap[key] = changeMap[key]
|
// menuMap[key] = changeMap[key]
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
// Apply changes
|
// Apply changes
|
||||||
tempRecipe := models.Recipe01{}
|
tempRecipe := models.Recipe01{}
|
||||||
tempRecipe = tempRecipe.FromMap(menuMap)
|
tempRecipe = tempRecipe.FromMap(changeMap)
|
||||||
rr.data.SetValuesToRecipe(targetRecipe.Recipe01, tempRecipe)
|
rr.data.SetValuesToRecipe(targetRecipe.Recipe01, tempRecipe)
|
||||||
rr.taoLogger.Log.Debug("ApplyChange", zap.Any("status", "passed"))
|
rr.taoLogger.Log.Debug("ApplyChange", zap.Any("status", "passed"))
|
||||||
|
|
||||||
|
|
@ -390,6 +390,7 @@ func (rr *RecipeRouter) updateRecipe(w http.ResponseWriter, r *http.Request) {
|
||||||
Created_at: time.Now().Local().Format("2006-01-02 15:04:05"),
|
Created_at: time.Now().Local().Format("2006-01-02 15:04:05"),
|
||||||
Editor: editor,
|
Editor: editor,
|
||||||
Change_file: temp_file_name,
|
Change_file: temp_file_name,
|
||||||
|
Relation: filename,
|
||||||
}
|
}
|
||||||
|
|
||||||
err = data.Insert(&commit)
|
err = data.Insert(&commit)
|
||||||
|
|
@ -434,10 +435,10 @@ func (rr *RecipeRouter) getSavedRecipes(w http.ResponseWriter, r *http.Request)
|
||||||
}
|
}
|
||||||
|
|
||||||
commits, err := data.GetCommitLogOfFilename(countryID, file_version)
|
commits, err := data.GetCommitLogOfFilename(countryID, file_version)
|
||||||
|
// fmt.Println("commits", commits)
|
||||||
rr.taoLogger.Log.Debug("RecipeRouter.getSavedRecipes", zap.Any("commits", commits))
|
rr.taoLogger.Log.Debug("RecipeRouter.getSavedRecipes", zap.Any("commits", commits))
|
||||||
|
|
||||||
if err != nil {
|
if err != nil || len(commits) == 0 {
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
@ -448,92 +449,46 @@ func (rr *RecipeRouter) getSavedRecipes(w http.ResponseWriter, r *http.Request)
|
||||||
json.NewEncoder(w).Encode(map[string]interface{}{"files": commits})
|
json.NewEncoder(w).Encode(map[string]interface{}{"files": commits})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (rr *RecipeRouter) ApplyTmpChanges(w http.ResponseWriter, r *http.Request) {
|
func (rr *RecipeRouter) getToppings(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
|
countryID := chi.URLParam(r, "country")
|
||||||
filename := chi.URLParam(r, "filename")
|
filename := chi.URLParam(r, "filename")
|
||||||
country := chi.URLParam(r, "country")
|
|
||||||
|
|
||||||
countryID, err := rr.data.GetCountryIDByName(country)
|
|
||||||
if err != nil {
|
|
||||||
rr.taoLogger.Log.Error("RecipeRouter.UpdateRecipe", zap.Error(err))
|
|
||||||
http.Error(w, fmt.Sprintf("Country Name: %s not found!!!", country), http.StatusNotFound)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
var legit_changes map[string]interface{}
|
|
||||||
|
|
||||||
target_recipe := rr.data.GetRecipe(countryID, filename)
|
|
||||||
new_file_version := target_recipe.MachineSetting.ConfigNumber + 1
|
|
||||||
|
|
||||||
show_to_current := legit_changes["no_upgrade"].(bool)
|
|
||||||
if show_to_current {
|
|
||||||
new_file_version = target_recipe.MachineSetting.ConfigNumber
|
|
||||||
}
|
|
||||||
|
|
||||||
err = json.NewDecoder(r.Body).Decode(&legit_changes)
|
|
||||||
if err != nil {
|
|
||||||
rr.taoLogger.Log.Error("ApplyErr", zap.Any("err", err))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
user_selected_tmp := legit_changes["selected_files"].([]string)
|
|
||||||
|
|
||||||
for select_tmp := range user_selected_tmp {
|
|
||||||
// open selected
|
|
||||||
current_temp_file, err := os.ReadFile(user_selected_tmp[select_tmp])
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
rr.taoLogger.Log.Error("TmpFile", zap.Any("Open", "tried to open but failed => "+user_selected_tmp[select_tmp]))
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
// load to model
|
|
||||||
|
|
||||||
temp_recipe := models.Recipe01{}
|
|
||||||
json.Unmarshal(current_temp_file, &temp_recipe)
|
|
||||||
|
|
||||||
// apply set value
|
|
||||||
rr.data.SetValuesToRecipe(target_recipe.Recipe01, temp_recipe)
|
|
||||||
rr.taoLogger.Log.Debug("ApplyTmpChanges", zap.Any("Update|Push", string(rune(temp_recipe.ID))+":"+temp_recipe.ProductCode))
|
|
||||||
}
|
|
||||||
|
|
||||||
// export
|
|
||||||
exported_filename := "coffeethai02_" + string(rune(new_file_version))
|
|
||||||
|
|
||||||
if countryID != "tha" {
|
|
||||||
exported_filename += "_" + countryID
|
|
||||||
}
|
|
||||||
|
|
||||||
exported_filename += ".json"
|
|
||||||
|
|
||||||
full_exported_path := "cofffeemachineConfig/" + countryID + "/" + exported_filename
|
|
||||||
|
|
||||||
outfile, _ := os.Create(full_exported_path)
|
|
||||||
|
|
||||||
target_recipe.MachineSetting.ConfigNumber = new_file_version
|
|
||||||
encoder := json.NewEncoder(outfile)
|
|
||||||
encoder.SetIndent("", " ")
|
|
||||||
|
|
||||||
err = encoder.Encode(target_recipe)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
rr.taoLogger.Log.Error("UpgradeToFullRecipeFailed", zap.Any("File", err))
|
|
||||||
http.Error(w, "Internal Error", http.StatusInternalServerError)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
w.Header().Add("Content-Type", "application/json")
|
w.Header().Add("Content-Type", "application/json")
|
||||||
json.NewEncoder(w).Encode(map[string]interface{}{
|
json.NewEncoder(w).Encode(rr.data.GetToppings(countryID, filename))
|
||||||
"status": "OK",
|
|
||||||
"version": new_file_version,
|
|
||||||
"path": full_exported_path,
|
|
||||||
})
|
|
||||||
|
|
||||||
delete_files := legit_changes["del_after_upgrade"].(bool)
|
}
|
||||||
|
|
||||||
if delete_files && !show_to_current {
|
func (rr *RecipeRouter) getToppingsOfRecipe(w http.ResponseWriter, r *http.Request) {
|
||||||
for seleted_file := range user_selected_tmp {
|
|
||||||
os.Remove(user_selected_tmp[seleted_file])
|
// countryID := chi.URLParam(r, "country")
|
||||||
}
|
// filename := chi.URLParam(r, "filename")
|
||||||
}
|
// productCode := chi.URLParam(r, "product_code")
|
||||||
|
|
||||||
|
w.Header().Add("Content-Type", "application/json")
|
||||||
|
|
||||||
|
// all toppings
|
||||||
|
// allToppings := rr.data.GetToppings(countryID, filename)
|
||||||
|
|
||||||
|
// topps, err := rr.data.GetToppingsOfRecipe(countryID, filename, productCode)
|
||||||
|
|
||||||
|
// expandedToppings := map[string]interface{}{}
|
||||||
|
|
||||||
|
// for _, v := range allToppings.ToppingGroup {
|
||||||
|
// for _, t := range topps {
|
||||||
|
// if v.GroupID == t.ListGroupID[0] {
|
||||||
|
// expandedToppings[v.GroupID] = v
|
||||||
|
// break
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
// if err != nil {
|
||||||
|
// http.Error(w, err.Error(), http.StatusNotFound)
|
||||||
|
// return
|
||||||
|
// }
|
||||||
|
|
||||||
|
// json.NewEncoder(w).Encode()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (rr *RecipeRouter) doMergeJson(w http.ResponseWriter, r *http.Request) {
|
func (rr *RecipeRouter) doMergeJson(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
|
||||||
|
|
@ -40,13 +40,20 @@ func (rs *recipeService) GetRecipeDetail(request *contracts.RecipeDetailRequest)
|
||||||
// DEBUG: picture
|
// DEBUG: picture
|
||||||
rs.taoLogger.Log.Debug("GetRecipeDetail", zap.String("picture", recipe.UriData))
|
rs.taoLogger.Log.Debug("GetRecipeDetail", zap.String("picture", recipe.UriData))
|
||||||
|
|
||||||
|
uri_img := recipe.UriData
|
||||||
|
uri_img = strings.TrimPrefix(uri_img, "img=")
|
||||||
|
// if strings.HasPrefix(uri_img, "img=") {
|
||||||
|
|
||||||
|
// uri_img = uri_img[len("img="):]
|
||||||
|
// }
|
||||||
|
|
||||||
result := contracts.RecipeDetailResponse{
|
result := contracts.RecipeDetailResponse{
|
||||||
Name: recipe.Name,
|
Name: recipe.Name,
|
||||||
OtherName: recipe.OtherName,
|
OtherName: recipe.OtherName,
|
||||||
Description: recipe.Description,
|
Description: recipe.Description,
|
||||||
OtherDescription: recipe.OtherDescription,
|
OtherDescription: recipe.OtherDescription,
|
||||||
LastUpdated: recipe.LastChange,
|
LastUpdated: recipe.LastChange,
|
||||||
Picture: recipe.UriData[len("img="):], // remove "img=" prefix
|
Picture: uri_img, // remove "img=" prefix
|
||||||
}
|
}
|
||||||
|
|
||||||
return result, nil
|
return result, nil
|
||||||
|
|
@ -60,6 +67,8 @@ func (rs *recipeService) GetRecipeDetailMat(request *contracts.RecipeDetailReque
|
||||||
return contracts.RecipeDetailMatListResponse{}, fmt.Errorf("country name: %s not found", request.Country)
|
return contracts.RecipeDetailMatListResponse{}, fmt.Errorf("country name: %s not found", request.Country)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// rs.taoLogger.Log.Debug("GetRecipeDetailMat", zap.Any("request", request))
|
||||||
|
|
||||||
recipe, err := rs.db.GetRecipe01ByProductCode(request.Filename, request.Country, request.ProductCode)
|
recipe, err := rs.db.GetRecipe01ByProductCode(request.Filename, request.Country, request.ProductCode)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -73,19 +82,46 @@ func (rs *recipeService) GetRecipeDetailMat(request *contracts.RecipeDetailReque
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// rs.taoLogger.Log.Debug("GetRecipeDetailMat", zap.Any("matIds", matIds))
|
||||||
|
|
||||||
matsCode := rs.db.GetMaterialCode(matIds, countryID, request.Filename)
|
matsCode := rs.db.GetMaterialCode(matIds, countryID, request.Filename)
|
||||||
|
|
||||||
|
materials := []models.MaterialSetting{}
|
||||||
|
matsSetting := rs.db.GetMaterialSetting(countryID, request.Filename)
|
||||||
|
|
||||||
|
// rs.taoLogger.Log.Debug("GetRecipeDetailMat", zap.Any("matsSetting", matsSetting))
|
||||||
|
|
||||||
|
for _, v := range matsSetting {
|
||||||
|
// rs.taoLogger.Log.Debug("GetRecipeDetailMat,Iterate", zap.Any("mats", v.ID))
|
||||||
|
for _, mat := range matIds {
|
||||||
|
if v.ID == mat {
|
||||||
|
materials = append(materials, v)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// rs.taoLogger.Log.Debug("GetRecipeDetailMat", zap.Any("matsCode", materials))
|
||||||
|
|
||||||
result := contracts.RecipeDetailMatListResponse{
|
result := contracts.RecipeDetailMatListResponse{
|
||||||
Result: []contracts.RecipeDetailMat{},
|
Result: []contracts.RecipeDetailMat{},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, v := range recipe.Recipes {
|
for _, v := range recipe.Recipes {
|
||||||
for _, mat := range matsCode {
|
for _, mat := range materials {
|
||||||
if v.MaterialPathId == int(mat.MaterialID) {
|
if v.MaterialPathId == int(mat.ID) {
|
||||||
|
mat_name := ""
|
||||||
|
for _, m := range matsCode {
|
||||||
|
if m.MaterialID == mat.ID {
|
||||||
|
mat_name = m.PackageDescription
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
result.Result = append(result.Result, contracts.RecipeDetailMat{
|
result.Result = append(result.Result, contracts.RecipeDetailMat{
|
||||||
IsUse: v.IsUse,
|
IsUse: v.IsUse,
|
||||||
MaterialID: mat.MaterialID,
|
MaterialID: mat.ID,
|
||||||
Name: mat.PackageDescription,
|
Name: mat_name,
|
||||||
MixOrder: v.MixOrder,
|
MixOrder: v.MixOrder,
|
||||||
FeedParameter: v.FeedParameter,
|
FeedParameter: v.FeedParameter,
|
||||||
FeedPattern: v.FeedPattern,
|
FeedPattern: v.FeedPattern,
|
||||||
|
|
@ -103,6 +139,30 @@ func (rs *recipeService) GetRecipeDetailMat(request *contracts.RecipeDetailReque
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// add padding until full 30
|
||||||
|
if len(result.Result) < 30 {
|
||||||
|
for i := len(result.Result); i < 30; i++ {
|
||||||
|
result.Result = append(result.Result, contracts.RecipeDetailMat{
|
||||||
|
IsUse: false,
|
||||||
|
MaterialID: 0,
|
||||||
|
Name: "",
|
||||||
|
MixOrder: 0,
|
||||||
|
FeedParameter: 0,
|
||||||
|
FeedPattern: 0,
|
||||||
|
MaterialPathId: 0,
|
||||||
|
PowderGram: 0,
|
||||||
|
PowderTime: 0,
|
||||||
|
StirTime: 0,
|
||||||
|
SyrupGram: 0,
|
||||||
|
SyrupTime: 0,
|
||||||
|
WaterCold: 0,
|
||||||
|
WaterYield: 0,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// rs.taoLogger.Log.Debug("GetRecipeDetailMat", zap.Any("result", result))
|
||||||
|
|
||||||
// sort by id
|
// sort by id
|
||||||
// sort.Slice(result.Result, func(i, j int) bool {
|
// sort.Slice(result.Result, func(i, j int) bool {
|
||||||
// return result.Result[i].MaterialID < result.Result[j].MaterialID
|
// return result.Result[i].MaterialID < result.Result[j].MaterialID
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue