add load from select save

This commit is contained in:
pakintada@gmail.com 2023-12-27 08:38:14 +07:00
parent f721517f25
commit 17030c72ce
10 changed files with 229 additions and 53 deletions

View file

@ -129,6 +129,10 @@ export class RecipeService {
return 'coffeethai02_580.json';
}
setCurrentFile(filename: string) {
localStorage.setItem('currentRecipeFile', filename);
}
getCurrentCountry(): string {
const currentRecipeCountry = localStorage.getItem('currentRecipeCountry');
if (currentRecipeCountry) {

View file

@ -122,40 +122,40 @@ export class RecipeDetailsComponent implements OnInit {
// get username
let username:string = ""
this._userService.currentUser.pipe(map((user) => {
if (user)
username = user.name;
let to_send = {
edit_by: username,
commit_msg: this.commit_msg,
productCode: this.productCode,
name: this.recipeDetailForm.getRawValue().name,
otherName: this.recipeDetailForm.getRawValue().otherName,
Description: this.recipeDetailForm.getRawValue().Description,
otherDescription: this.recipeDetailForm.getRawValue().otherDescription,
LastChange: this.recipeDetailForm.getRawValue().lastModified,
price: this.recipeDetailForm.getRawValue().price,
// isUse: this,
// isShow: null,
// disable: null,
recipes: [
...this.repl
],
username = this._userService.getCurrentUser()!.name;
let to_send = {
edit_by: username,
commit_msg: this.commit_msg,
productCode: this.productCode,
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,
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,
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,
// isUse: this,
// isShow: null,
// disable: null,
recipes: [
...(this.repl.length <= 0 ? [] : this.repl)
],
}
// TODO: update value in targeted recipe
console.log('to_send', to_send);
this._recipeService.editChanges(
this._recipeService.getCurrentCountry(),
this._recipeService.getCurrentFile(),
{
...to_send,
}
// TODO: update value in targeted recipe
this._recipeService.editChanges(
this._recipeService.getCurrentCountry(),
this._recipeService.getCurrentFile(),
{
...to_send,
}
);
console.log('Sending changes');
void this._router.navigate(['/'+this.department+'/recipes']);
}))
);
console.log('Sending changes');
void this._router.navigate(['/'+this.department+'/recipes']);
@ -194,11 +194,11 @@ export class RecipeDetailsComponent implements OnInit {
isValueChanged: boolean = false;
onRecipeDetailFormChange(recipeDetail: typeof this.recipeDetailForm.value) {
console.log('Recipe Detail Form Changed', recipeDetail);
// console.log('Recipe Detail Form Changed', recipeDetail);
}
onRecipeListFormChange(repl: unknown[]) {
console.log('Recipe List Form Changed', repl);
// console.log('Recipe List Form Changed', repl);
this.repl = repl as never[];
this.isValueChanged ||= repl != undefined;
}

View file

@ -72,8 +72,8 @@ export class RecipeListComponent implements OnInit {
});
this.recipeListForm.valueChanges.subscribe((value) => {
console.log(value.recipeListData);
console.log(this._recipeListOriginalArray);
// console.log(value.recipeListData);
// console.log(this._recipeListOriginalArray);
if (
!isEqual(
sortBy(value, 'materialID'),

View file

@ -150,7 +150,7 @@
<td>{{ file.Msg }}</td>
<td>{{ file.Editor }}</td>
<td>{{ file.Created_at }}</td>
<button class="btn bg-blue-400">Select</button>
<button class="btn bg-blue-400" (click)="loadSavedFile(file)">Select</button>
</tr>
</table>
</div>

View file

@ -154,8 +154,12 @@ export class RecipesComponent implements OnInit, OnDestroy {
next: (files:any) => {
console.log("Obtain saves: ", typeof files, files);
if(files != undefined && typeof files === 'object'){
// console.log("Obtain saves object: ", files.files[0], typeof files);
this.savedTmpfiles = files.files;
if(files.files != null){
console.log("Obtain saves object: ", files.files[0], typeof files);
this.savedTmpfiles = files.files;
} else {
this.showSaveNoti = false;
}
// let svf = (document.getElementById('select_savefile_modal') as HTMLInputElement)!.checked;
// console.log("isSavedModalOpened",svf)
}
@ -384,6 +388,44 @@ export class RecipesComponent implements OnInit, OnDestroy {
this.saveTab = true;
}
loadSavedFile(file_commit: any) {
this.showSaveNoti = false;
this.saveTab = false;
console.log('loadSavedFile', file_commit, this.department);
let country = this.department!;
switch(country){
case "tha":
country = "Thailand";
break;
case "aus":
country = "Australia";
break;
case "mys":
country = "Malaysia";
break;
case "alpha-3":
country = "alpha-3";
break;
}
console.log(file_commit.Change_file.split("/")[2]);
this._recipeService
.getRecipeOverview({
offset: this.offset,
take: this.take,
search: this.oldSearchStr,
filename: file_commit.Change_file.split("/")[2],
country: country,
materialIds: this.selectMaterialFilter || [],
}).subscribe(({ result, hasMore, totalCount }) => {
console.log('loadSavedFile', result);
this._recipeService.setCurrentFile(file_commit.Change_file.split("/")[2]);
});
}
ngOnDestroy(): void {
if (this.currentCountryFilterSubScription) {
this.currentCountryFilterSubScription.unsubscribe();