fixed some bug change get by id to get by product code
This commit is contained in:
parent
7450796a6b
commit
d5cfdf496f
5 changed files with 30 additions and 29 deletions
|
|
@ -14,8 +14,8 @@ import { environment } from 'src/environments/environment';
|
||||||
|
|
||||||
@Injectable({ providedIn: 'root' })
|
@Injectable({ providedIn: 'root' })
|
||||||
export class UserService {
|
export class UserService {
|
||||||
private currnetUserSubject = new BehaviorSubject<User | null>(null);
|
private currentUserSubject = new BehaviorSubject<User | null>(null);
|
||||||
public currentUser = this.currnetUserSubject
|
public currentUser = this.currentUserSubject
|
||||||
.asObservable()
|
.asObservable()
|
||||||
.pipe(distinctUntilChanged());
|
.pipe(distinctUntilChanged());
|
||||||
|
|
||||||
|
|
@ -54,10 +54,10 @@ export class UserService {
|
||||||
}
|
}
|
||||||
|
|
||||||
setAuth(user: User): void {
|
setAuth(user: User): void {
|
||||||
void this.currnetUserSubject.next(user);
|
void this.currentUserSubject.next(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
purgeAuth(): void {
|
purgeAuth(): void {
|
||||||
void this.currnetUserSubject.next(null);
|
void this.currentUserSubject.next(null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -142,7 +142,7 @@
|
||||||
{{ recipe.LastChange | date : "dd-MMM-yyyy hh:mm:ss" }}
|
{{ recipe.LastChange | date : "dd-MMM-yyyy hh:mm:ss" }}
|
||||||
</td>
|
</td>
|
||||||
<td class="px-4 py-4 flex">
|
<td class="px-4 py-4 flex">
|
||||||
<recipe-modal id="{{ recipe.id }}"></recipe-modal>
|
<recipe-modal productCode="{{ recipe.productCode }}"></recipe-modal>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
|
|
|
||||||
|
|
@ -101,8 +101,8 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="modal-action">
|
<div class="modal-action">
|
||||||
<a class="btn px-10" (click)="onConfirmSave()">Save</a>
|
<a class="btn px-10" (click)="onPressConfirmSave()">Save</a>
|
||||||
<a class="btn" (click)="onConfirmClose()">Close</a>
|
<a class="btn" (click)="onPressConfirmClose()">Close</a>
|
||||||
</div>
|
</div>
|
||||||
<confirm-modal
|
<confirm-modal
|
||||||
[title]="confirmSave.title"
|
[title]="confirmSave.title"
|
||||||
|
|
|
||||||
|
|
@ -38,7 +38,7 @@ interface RecipeMetaData {
|
||||||
standalone: true,
|
standalone: true,
|
||||||
})
|
})
|
||||||
export class RecipeModalComponent {
|
export class RecipeModalComponent {
|
||||||
@Input({ required: true }) id!: string;
|
@Input({ required: true }) productCode!: string;
|
||||||
|
|
||||||
title: string = 'Recipe Detail';
|
title: string = 'Recipe Detail';
|
||||||
|
|
||||||
|
|
@ -73,23 +73,20 @@ export class RecipeModalComponent {
|
||||||
|
|
||||||
if (this.detailModal?.nativeElement.open) {
|
if (this.detailModal?.nativeElement.open) {
|
||||||
this.recipeService
|
this.recipeService
|
||||||
.getRecipesById(this.id)
|
.getRecipesById(this.productCode)
|
||||||
.subscribe(({ recipe, recipeMetaData }) => {
|
.subscribe(({ recipe, recipeMetaData }) => {
|
||||||
this.title = recipe.name + ' | ' + recipe.productCode;
|
this.title = recipe.name + ' | ' + recipe.productCode;
|
||||||
this.recipeDetail.patchValue(
|
this.recipeDetail.patchValue({
|
||||||
{
|
productCode: recipe.productCode,
|
||||||
productCode: recipe.productCode,
|
name: recipe.name,
|
||||||
name: recipe.name,
|
otherName: recipe.otherName,
|
||||||
otherName: recipe.otherName,
|
description: recipe.Description,
|
||||||
description: recipe.Description,
|
otherDescription: recipe.otherDescription,
|
||||||
otherDescription: recipe.otherDescription,
|
price: recipe.cashPrice,
|
||||||
price: recipe.cashPrice,
|
isUse: recipe.isUse,
|
||||||
isUse: recipe.isUse,
|
isShow: recipe.isShow,
|
||||||
isShow: recipe.isShow,
|
disable: recipe.disable,
|
||||||
disable: recipe.disable,
|
});
|
||||||
},
|
|
||||||
{ emitEvent: false }
|
|
||||||
);
|
|
||||||
this.originalRecipeDetail = {
|
this.originalRecipeDetail = {
|
||||||
productCode: recipe.productCode,
|
productCode: recipe.productCode,
|
||||||
name: recipe.name,
|
name: recipe.name,
|
||||||
|
|
@ -102,6 +99,7 @@ export class RecipeModalComponent {
|
||||||
disable: recipe.disable,
|
disable: recipe.disable,
|
||||||
};
|
};
|
||||||
this.recipeMetaData = recipeMetaData;
|
this.recipeMetaData = recipeMetaData;
|
||||||
|
console.log(this.recipeDetail.value);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -127,7 +125,7 @@ export class RecipeModalComponent {
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
onConfirmSave() {
|
onPressConfirmSave() {
|
||||||
if (!isEqual(this.recipeDetail.value, this.originalRecipeDetail)) {
|
if (!isEqual(this.recipeDetail.value, this.originalRecipeDetail)) {
|
||||||
this.showConfirmSaveModal.emit(true);
|
this.showConfirmSaveModal.emit(true);
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -135,7 +133,7 @@ export class RecipeModalComponent {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
onConfirmClose() {
|
onPressConfirmClose() {
|
||||||
if (!isEqual(this.recipeDetail.value, this.originalRecipeDetail)) {
|
if (!isEqual(this.recipeDetail.value, this.originalRecipeDetail)) {
|
||||||
this.showConfirmCloseModal.emit(true);
|
this.showConfirmCloseModal.emit(true);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -80,12 +80,12 @@ func (rr *RecipeRouter) Route(r chi.Router) {
|
||||||
recipe := rr.data.GetRecipe01()
|
recipe := rr.data.GetRecipe01()
|
||||||
recipeMetaData := rr.sheetService.GetSheet(r.Context(), "1rSUKcc5POR1KeZFGoeAZIoVoI7LPGztBhPw5Z_ConDE")
|
recipeMetaData := rr.sheetService.GetSheet(r.Context(), "1rSUKcc5POR1KeZFGoeAZIoVoI7LPGztBhPw5Z_ConDE")
|
||||||
|
|
||||||
recipeResult := models.Recipe01{}
|
var recipeResult *models.Recipe01
|
||||||
recipeMetaDataResult := map[string]string{}
|
recipeMetaDataResult := map[string]string{}
|
||||||
|
|
||||||
for _, v := range recipe {
|
for _, v := range recipe {
|
||||||
if v.ProductCode == productCode {
|
if v.ProductCode == productCode {
|
||||||
recipeResult = v
|
recipeResult = &v
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -104,12 +104,15 @@ func (rr *RecipeRouter) Route(r chi.Router) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if recipeResult == nil {
|
||||||
|
http.Error(w, "Not Found", http.StatusNotFound)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
json.NewEncoder(w).Encode(map[string]interface{}{
|
json.NewEncoder(w).Encode(map[string]interface{}{
|
||||||
"recipe": recipeResult,
|
"recipe": recipeResult,
|
||||||
"recipeMetaData": recipeMetaDataResult,
|
"recipeMetaData": recipeMetaDataResult,
|
||||||
})
|
})
|
||||||
|
|
||||||
http.Error(w, "Recipe not found", http.StatusNotFound)
|
|
||||||
})
|
})
|
||||||
|
|
||||||
r.Get("/{version}/json", func(w http.ResponseWriter, r *http.Request) {
|
r.Get("/{version}/json", func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue