display commit at recipe
This commit is contained in:
parent
820557a268
commit
f2ec0ed5fa
6 changed files with 640 additions and 555 deletions
|
|
@ -1,194 +1,224 @@
|
|||
import { HttpClient } from '@angular/common/http';
|
||||
import { Injectable } from '@angular/core';
|
||||
import { Observable, tap } from 'rxjs';
|
||||
import {
|
||||
Recipe,
|
||||
Recipe01,
|
||||
RecipeDetail,
|
||||
RecipeDetailMat,
|
||||
RecipeOverview,
|
||||
RecipeOverviewList,
|
||||
RecipesDashboard,
|
||||
} from '../models/recipe.model';
|
||||
import { environment } from 'src/environments/environment';
|
||||
import { RecipeMetaData } from 'src/app/shared/types/recipe';
|
||||
|
||||
type RecipeOverviewParams = {
|
||||
filename: string;
|
||||
country: string;
|
||||
materialIds: number[];
|
||||
offset: number;
|
||||
take: number;
|
||||
search: string;
|
||||
};
|
||||
|
||||
type RecipeDashboardParams = {
|
||||
filename: string;
|
||||
country: string;
|
||||
};
|
||||
|
||||
interface RecipeFiles {
|
||||
[key: string]: string[];
|
||||
}
|
||||
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class RecipeService {
|
||||
private countries: string[] = [];
|
||||
private recipeFiles: RecipeFiles = {};
|
||||
|
||||
constructor(private _httpClient: HttpClient) {}
|
||||
|
||||
getRecipesDashboard(
|
||||
params: RecipeDashboardParams = {
|
||||
country: this.getCurrentCountry(),
|
||||
filename: this.getCurrentFile(),
|
||||
}
|
||||
): Observable<RecipesDashboard> {
|
||||
return this._httpClient.get<RecipesDashboard>(
|
||||
environment.api + '/recipes/dashboard',
|
||||
{
|
||||
params: {
|
||||
country: params.country,
|
||||
filename: params.filename,
|
||||
},
|
||||
withCredentials: true,
|
||||
responseType: 'json',
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
getRecipeOverview(
|
||||
params: RecipeOverviewParams = {
|
||||
country: this.getCurrentCountry(),
|
||||
filename: this.getCurrentFile(),
|
||||
materialIds: [],
|
||||
offset: 0,
|
||||
take: 20,
|
||||
search: '',
|
||||
}
|
||||
): Observable<RecipeOverviewList> {
|
||||
return this._httpClient.get<RecipeOverviewList>(
|
||||
environment.api + '/recipes/overview',
|
||||
{
|
||||
params: {
|
||||
country: params.country,
|
||||
filename: params.filename,
|
||||
materialIds: params.materialIds.join(','),
|
||||
offset: params.offset.toString(),
|
||||
take: params.take.toString(),
|
||||
search: params.search,
|
||||
},
|
||||
withCredentials: true,
|
||||
responseType: 'json',
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
getRecipeDetail(productCode: string): Observable<RecipeDetail> {
|
||||
return this._httpClient.get<RecipeDetail>(
|
||||
environment.api + '/recipes/' + productCode,
|
||||
{
|
||||
params: {
|
||||
filename: this.getCurrentFile(),
|
||||
country: this.getCurrentCountry(),
|
||||
},
|
||||
withCredentials: true,
|
||||
responseType: 'json',
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
getRecipeDetailMat(
|
||||
productCode: string
|
||||
): Observable<{ result: RecipeDetailMat[] }> {
|
||||
return this._httpClient.get<{ result: RecipeDetailMat[] }>(
|
||||
environment.api + '/recipes/' + productCode + '/mat',
|
||||
{
|
||||
params: {
|
||||
filename: this.getCurrentFile(),
|
||||
country: this.getCurrentCountry(),
|
||||
},
|
||||
withCredentials: true,
|
||||
responseType: 'json',
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
getCurrentFile(): string {
|
||||
const currentRecipeFile = localStorage.getItem('currentRecipeFile');
|
||||
if (currentRecipeFile) {
|
||||
return currentRecipeFile;
|
||||
}
|
||||
|
||||
return 'coffeethai02_580.json';
|
||||
}
|
||||
|
||||
getCurrentCountry(): string {
|
||||
const currentRecipeCountry = localStorage.getItem('currentRecipeCountry');
|
||||
if (currentRecipeCountry) {
|
||||
return currentRecipeCountry;
|
||||
}
|
||||
|
||||
return 'Thailand';
|
||||
}
|
||||
|
||||
getRecipesById(id: string): Observable<{
|
||||
recipe: Recipe01;
|
||||
recipeMetaData: RecipeMetaData;
|
||||
}> {
|
||||
return this._httpClient.get<{
|
||||
recipe: Recipe01;
|
||||
recipeMetaData: RecipeMetaData;
|
||||
}>(environment.api + '/recipes/' + id, {
|
||||
withCredentials: true,
|
||||
responseType: 'json',
|
||||
});
|
||||
}
|
||||
|
||||
getRecipeCountries(): Observable<string[]> {
|
||||
return this._httpClient
|
||||
.get<string[]>(environment.api + '/recipes/versions', {
|
||||
withCredentials: true,
|
||||
responseType: 'json',
|
||||
})
|
||||
.pipe(tap((countries) => (this.countries = countries)));
|
||||
}
|
||||
|
||||
getRecipeFiles(country: string): Observable<string[]> {
|
||||
return this._httpClient
|
||||
.get<string[]>(environment.api + '/recipes/versions/' + country, {
|
||||
withCredentials: true,
|
||||
responseType: 'json',
|
||||
})
|
||||
.pipe(tap((files) => (this.recipeFiles[country] = files)));
|
||||
}
|
||||
|
||||
getRecipeFileCountries(): string[] {
|
||||
return this.countries;
|
||||
}
|
||||
|
||||
getRecipeFileNames(country: string): string[] | null {
|
||||
return this.recipeFiles[country] ?? null;
|
||||
}
|
||||
|
||||
editChanges(country: string, filename: string, change: any) {
|
||||
console.log('target version = ', filename);
|
||||
console.log('change in edit: ', change.value);
|
||||
return this._httpClient
|
||||
.post<{
|
||||
status: string;
|
||||
}>(
|
||||
environment.api + ('/recipes/edit/' + country + '/' + filename),
|
||||
change.value,
|
||||
{
|
||||
withCredentials: true,
|
||||
responseType: 'json',
|
||||
}
|
||||
)
|
||||
.subscribe({
|
||||
next(value) {
|
||||
console.log(value, change.value);
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import { Injectable } from '@angular/core';
|
||||
import { Observable, tap } from 'rxjs';
|
||||
import {
|
||||
Recipe,
|
||||
Recipe01,
|
||||
RecipeDetail,
|
||||
RecipeDetailMat,
|
||||
RecipeOverview,
|
||||
RecipeOverviewList,
|
||||
RecipesDashboard,
|
||||
} from '../models/recipe.model';
|
||||
import { environment } from 'src/environments/environment';
|
||||
import { RecipeMetaData } from 'src/app/shared/types/recipe';
|
||||
|
||||
type RecipeOverviewParams = {
|
||||
filename: string;
|
||||
country: string;
|
||||
materialIds: number[];
|
||||
offset: number;
|
||||
take: number;
|
||||
search: string;
|
||||
};
|
||||
|
||||
type RecipeDashboardParams = {
|
||||
filename: string;
|
||||
country: string;
|
||||
};
|
||||
|
||||
interface RecipeFiles {
|
||||
[key: string]: string[];
|
||||
}
|
||||
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class RecipeService {
|
||||
private countries: string[] = [];
|
||||
private recipeFiles: RecipeFiles = {};
|
||||
|
||||
private tmp_files: string[] = [];
|
||||
|
||||
private get tmpfiles(): string[] {
|
||||
return this.tmp_files;
|
||||
}
|
||||
|
||||
constructor(private _httpClient: HttpClient) {}
|
||||
|
||||
getRecipesDashboard(
|
||||
params: RecipeDashboardParams = {
|
||||
country: this.getCurrentCountry(),
|
||||
filename: this.getCurrentFile(),
|
||||
}
|
||||
): Observable<RecipesDashboard> {
|
||||
return this._httpClient.get<RecipesDashboard>(
|
||||
environment.api + '/recipes/dashboard',
|
||||
{
|
||||
params: {
|
||||
country: params.country,
|
||||
filename: params.filename,
|
||||
},
|
||||
withCredentials: true,
|
||||
responseType: 'json',
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
getRecipeOverview(
|
||||
params: RecipeOverviewParams = {
|
||||
country: this.getCurrentCountry(),
|
||||
filename: this.getCurrentFile(),
|
||||
materialIds: [],
|
||||
offset: 0,
|
||||
take: 20,
|
||||
search: '',
|
||||
}
|
||||
): Observable<RecipeOverviewList> {
|
||||
return this._httpClient.get<RecipeOverviewList>(
|
||||
environment.api + '/recipes/overview',
|
||||
{
|
||||
params: {
|
||||
country: params.country,
|
||||
filename: params.filename,
|
||||
materialIds: params.materialIds.join(','),
|
||||
offset: params.offset.toString(),
|
||||
take: params.take.toString(),
|
||||
search: params.search,
|
||||
},
|
||||
withCredentials: true,
|
||||
responseType: 'json',
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
getRecipeDetail(productCode: string): Observable<RecipeDetail> {
|
||||
return this._httpClient.get<RecipeDetail>(
|
||||
environment.api + '/recipes/' + productCode,
|
||||
{
|
||||
params: {
|
||||
filename: this.getCurrentFile(),
|
||||
country: this.getCurrentCountry(),
|
||||
},
|
||||
withCredentials: true,
|
||||
responseType: 'json',
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
getRecipeDetailMat(
|
||||
productCode: string
|
||||
): Observable<{ result: RecipeDetailMat[] }> {
|
||||
return this._httpClient.get<{ result: RecipeDetailMat[] }>(
|
||||
environment.api + '/recipes/' + productCode + '/mat',
|
||||
{
|
||||
params: {
|
||||
filename: this.getCurrentFile(),
|
||||
country: this.getCurrentCountry(),
|
||||
},
|
||||
withCredentials: true,
|
||||
responseType: 'json',
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
getCurrentFile(): string {
|
||||
const currentRecipeFile = localStorage.getItem('currentRecipeFile');
|
||||
if (currentRecipeFile) {
|
||||
return currentRecipeFile;
|
||||
}
|
||||
|
||||
return 'coffeethai02_580.json';
|
||||
}
|
||||
|
||||
getCurrentCountry(): string {
|
||||
const currentRecipeCountry = localStorage.getItem('currentRecipeCountry');
|
||||
if (currentRecipeCountry) {
|
||||
return currentRecipeCountry;
|
||||
}
|
||||
|
||||
return 'Thailand';
|
||||
}
|
||||
|
||||
getRecipesById(id: string): Observable<{
|
||||
recipe: Recipe01;
|
||||
recipeMetaData: RecipeMetaData;
|
||||
}> {
|
||||
return this._httpClient.get<{
|
||||
recipe: Recipe01;
|
||||
recipeMetaData: RecipeMetaData;
|
||||
}>(environment.api + '/recipes/' + id, {
|
||||
withCredentials: true,
|
||||
responseType: 'json',
|
||||
});
|
||||
}
|
||||
|
||||
getRecipeCountries(): Observable<string[]> {
|
||||
return this._httpClient
|
||||
.get<string[]>(environment.api + '/recipes/versions', {
|
||||
withCredentials: true,
|
||||
responseType: 'json',
|
||||
})
|
||||
.pipe(tap((countries) => (this.countries = countries)));
|
||||
}
|
||||
|
||||
getRecipeFiles(country: string): Observable<string[]> {
|
||||
return this._httpClient
|
||||
.get<string[]>(environment.api + '/recipes/versions/' + country, {
|
||||
withCredentials: true,
|
||||
responseType: 'json',
|
||||
})
|
||||
.pipe(tap((files) => (this.recipeFiles[country] = files)));
|
||||
}
|
||||
|
||||
getRecipeFileCountries(): string[] {
|
||||
return this.countries;
|
||||
}
|
||||
|
||||
getRecipeFileNames(country: string): string[] | null {
|
||||
return this.recipeFiles[country] ?? null;
|
||||
}
|
||||
|
||||
editChanges(country: string, filename: string, change: any) {
|
||||
console.log('target version = ', filename);
|
||||
console.log('change in edit: ', change);
|
||||
return this._httpClient
|
||||
.post<{
|
||||
status: string;
|
||||
}>(
|
||||
environment.api + ('/recipes/edit/' + country + '/' + filename),
|
||||
JSON.stringify(change),
|
||||
{
|
||||
withCredentials: true,
|
||||
responseType: 'json',
|
||||
}
|
||||
)
|
||||
.subscribe({
|
||||
next(value) {
|
||||
console.log( value);
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
getSavedTmp(country: string, filename:string) {
|
||||
console.log("loading saved .tmp* file", country, filename)
|
||||
|
||||
// do split filename
|
||||
filename = filename.split('_')[1];
|
||||
|
||||
|
||||
// this._user.getCurrentUser().subscribe((user) => {
|
||||
// this.user = user.user;
|
||||
// })
|
||||
return this._httpClient
|
||||
.get<string[]>(
|
||||
environment.api + ("/recipes/saved/"+ country + "/" + filename),
|
||||
{
|
||||
withCredentials: true,
|
||||
}
|
||||
);
|
||||
// .subscribe({
|
||||
// next(value) {
|
||||
// console.log( value);
|
||||
// },
|
||||
// });
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -112,17 +112,20 @@
|
|||
</button>
|
||||
<!-- todo: add modal -->
|
||||
<dialog id="select_savefile_modal" class="modal">
|
||||
<div class="modal-box max-w-[600px] overflow-visible">
|
||||
<div class="modal-box max-w-[1000px] overflow-visible">
|
||||
<p class="font-bold text-lg m-2">Saved Files</p>
|
||||
<table class="table">
|
||||
<tr class="bg-primary ">
|
||||
<th>Name</th>
|
||||
<th>Commit ID</th>
|
||||
<th>Comment</th>
|
||||
<!-- <th></th> -->
|
||||
<th>Editor</th>
|
||||
<th>Date</th>
|
||||
</tr>
|
||||
<tr class="row hover:bg-secondary" *ngFor="let file of savedTmpfiles">
|
||||
<td>{{ file }}</td>
|
||||
<td>"-"</td>
|
||||
<td>{{ file.Id }}</td>
|
||||
<td>{{ file.Msg }}</td>
|
||||
<td>{{ file.Editor }}</td>
|
||||
<td>{{ file.Created_at }}</td>
|
||||
<button class="btn bg-blue-400">Select</button>
|
||||
</tr>
|
||||
</table>
|
||||
|
|
|
|||
|
|
@ -65,7 +65,7 @@ export class RecipesComponent implements OnInit, OnDestroy {
|
|||
private searchStr = '';
|
||||
private oldSearchStr = '';
|
||||
|
||||
savedTmpfiles: string[] = [];
|
||||
savedTmpfiles: any[] = [];
|
||||
|
||||
tableCtx?: ElementRef;
|
||||
|
||||
|
|
@ -146,7 +146,7 @@ export class RecipesComponent implements OnInit, OnDestroy {
|
|||
this._recipeService.getCurrentFile()
|
||||
).subscribe({
|
||||
next: (files:any) => {
|
||||
console.log("Obtain saves: ", typeof files);
|
||||
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;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue