display commit at recipe
This commit is contained in:
parent
820557a268
commit
f2ec0ed5fa
6 changed files with 640 additions and 555 deletions
|
|
@ -36,6 +36,12 @@ export class RecipeService {
|
||||||
private countries: string[] = [];
|
private countries: string[] = [];
|
||||||
private recipeFiles: RecipeFiles = {};
|
private recipeFiles: RecipeFiles = {};
|
||||||
|
|
||||||
|
private tmp_files: string[] = [];
|
||||||
|
|
||||||
|
private get tmpfiles(): string[] {
|
||||||
|
return this.tmp_files;
|
||||||
|
}
|
||||||
|
|
||||||
constructor(private _httpClient: HttpClient) {}
|
constructor(private _httpClient: HttpClient) {}
|
||||||
|
|
||||||
getRecipesDashboard(
|
getRecipesDashboard(
|
||||||
|
|
@ -173,13 +179,13 @@ export class RecipeService {
|
||||||
|
|
||||||
editChanges(country: string, filename: string, change: any) {
|
editChanges(country: string, filename: string, change: any) {
|
||||||
console.log('target version = ', filename);
|
console.log('target version = ', filename);
|
||||||
console.log('change in edit: ', change.value);
|
console.log('change in edit: ', change);
|
||||||
return this._httpClient
|
return this._httpClient
|
||||||
.post<{
|
.post<{
|
||||||
status: string;
|
status: string;
|
||||||
}>(
|
}>(
|
||||||
environment.api + ('/recipes/edit/' + country + '/' + filename),
|
environment.api + ('/recipes/edit/' + country + '/' + filename),
|
||||||
change.value,
|
JSON.stringify(change),
|
||||||
{
|
{
|
||||||
withCredentials: true,
|
withCredentials: true,
|
||||||
responseType: 'json',
|
responseType: 'json',
|
||||||
|
|
@ -187,8 +193,32 @@ export class RecipeService {
|
||||||
)
|
)
|
||||||
.subscribe({
|
.subscribe({
|
||||||
next(value) {
|
next(value) {
|
||||||
console.log(value, change.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>
|
</button>
|
||||||
<!-- todo: add modal -->
|
<!-- todo: add modal -->
|
||||||
<dialog id="select_savefile_modal" class="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>
|
<p class="font-bold text-lg m-2">Saved Files</p>
|
||||||
<table class="table">
|
<table class="table">
|
||||||
<tr class="bg-primary ">
|
<tr class="bg-primary ">
|
||||||
<th>Name</th>
|
<th>Commit ID</th>
|
||||||
<th>Comment</th>
|
<th>Comment</th>
|
||||||
<!-- <th></th> -->
|
<th>Editor</th>
|
||||||
|
<th>Date</th>
|
||||||
</tr>
|
</tr>
|
||||||
<tr class="row hover:bg-secondary" *ngFor="let file of savedTmpfiles">
|
<tr class="row hover:bg-secondary" *ngFor="let file of savedTmpfiles">
|
||||||
<td>{{ file }}</td>
|
<td>{{ file.Id }}</td>
|
||||||
<td>"-"</td>
|
<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">Select</button>
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
|
|
|
||||||
|
|
@ -65,7 +65,7 @@ export class RecipesComponent implements OnInit, OnDestroy {
|
||||||
private searchStr = '';
|
private searchStr = '';
|
||||||
private oldSearchStr = '';
|
private oldSearchStr = '';
|
||||||
|
|
||||||
savedTmpfiles: string[] = [];
|
savedTmpfiles: any[] = [];
|
||||||
|
|
||||||
tableCtx?: ElementRef;
|
tableCtx?: ElementRef;
|
||||||
|
|
||||||
|
|
@ -146,7 +146,7 @@ export class RecipesComponent implements OnInit, OnDestroy {
|
||||||
this._recipeService.getCurrentFile()
|
this._recipeService.getCurrentFile()
|
||||||
).subscribe({
|
).subscribe({
|
||||||
next: (files:any) => {
|
next: (files:any) => {
|
||||||
console.log("Obtain saves: ", typeof files);
|
console.log("Obtain saves: ", typeof files, files);
|
||||||
if(files != undefined && typeof files === 'object'){
|
if(files != undefined && typeof files === 'object'){
|
||||||
// console.log("Obtain saves object: ", files.files[0], typeof files);
|
// console.log("Obtain saves object: ", files.files[0], typeof files);
|
||||||
this.savedTmpfiles = files.files;
|
this.savedTmpfiles = files.files;
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,8 @@
|
||||||
package data
|
package data
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/jmoiron/sqlx"
|
"github.com/jmoiron/sqlx"
|
||||||
_ "github.com/mattn/go-sqlite3"
|
_ "github.com/mattn/go-sqlite3"
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
|
|
@ -60,9 +62,46 @@ func Insert(c *CommitLog) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// func GetCommitLogOfFilename(filename string) ([]CommitLog, error) {
|
func GetCommitLogOfFilename(countryId string, filename string) ([]CommitLog, error) {
|
||||||
//}
|
|
||||||
// cut .json, split then get pos 2, check `change_file` startwith "filename" then return all quries
|
filename = strings.TrimSuffix(filename, ".json")
|
||||||
|
|
||||||
|
// try split and get pos 1 and 2
|
||||||
|
filenameParts := strings.Split(filename, "_")
|
||||||
|
if len(filenameParts) == 2 {
|
||||||
|
filename = filenameParts[1]
|
||||||
|
} else if len(filenameParts) > 2 {
|
||||||
|
filename = filenameParts[1] + "_" + filenameParts[2]
|
||||||
|
}
|
||||||
|
|
||||||
|
Log.Debug("CommitDB", zap.Any("lookup", filename))
|
||||||
|
|
||||||
|
commitDB, err := sqlx.Connect("sqlite3", "./data/database.db")
|
||||||
|
if err != nil {
|
||||||
|
Log.Fatal("Error when connecting to database", zap.Error(err))
|
||||||
|
}
|
||||||
|
|
||||||
|
var commits []CommitLog
|
||||||
|
// get contains
|
||||||
|
// err = commitDB.Get(&commits, "SELECT * FROM commit_log WHERE change_file LIKE ?", "%"+filename+"%")
|
||||||
|
|
||||||
|
err = commitDB.Select(&commits, "SELECT * FROM commit_log WHERE change_file LIKE ?", "%"+filename+"%")
|
||||||
|
|
||||||
|
var commitsByCountryID []CommitLog
|
||||||
|
|
||||||
|
for _, v := range commits {
|
||||||
|
if strings.Contains(v.Change_file, countryId) {
|
||||||
|
commitsByCountryID = append(commitsByCountryID, v)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
Log.Error("Error when get commit log", zap.Error(err))
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return commitsByCountryID, nil
|
||||||
|
}
|
||||||
|
|
||||||
func GetCommitLogs() ([]CommitLog, error) {
|
func GetCommitLogs() ([]CommitLog, error) {
|
||||||
commit_db, err := sqlx.Connect("sqlite3", "./data/database.db")
|
commit_db, err := sqlx.Connect("sqlite3", "./data/database.db")
|
||||||
|
|
|
||||||
|
|
@ -91,7 +91,7 @@ func (d *Data) GetRecipe(countryID, filename string) *models.Recipe {
|
||||||
recipe, err := helpers.ReadRecipeFile(countryID, filename)
|
recipe, err := helpers.ReadRecipeFile(countryID, filename)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.GetInstance().Error("Error when read recipe file", zap.Error(err))
|
logger.GetInstance().Error("Error when read recipe file [GetRecipe]", zap.Error(err))
|
||||||
return d.currentRecipe
|
return d.currentRecipe
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -123,6 +123,10 @@ func (d *Data) GetRecipe01() []models.Recipe01 {
|
||||||
return d.currentRecipe.Recipe01
|
return d.currentRecipe.Recipe01
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (d *Data) GetCurrentRecipe() *models.Recipe {
|
||||||
|
return d.currentRecipe
|
||||||
|
}
|
||||||
|
|
||||||
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 filename == "" || filename == d.CurrentFile {
|
||||||
|
|
@ -144,7 +148,7 @@ func (d *Data) GetRecipe01ByProductCode(filename, countryID, productCode string)
|
||||||
recipe, err := helpers.ReadRecipeFile(countryID, filename)
|
recipe, err := helpers.ReadRecipeFile(countryID, filename)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.GetInstance().Error("Error when read recipe file", zap.Error(err))
|
logger.GetInstance().Error("Error when read recipe file [GetRecipe01ByProductCode]", zap.Error(err))
|
||||||
for _, v := range d.currentRecipe.Recipe01 {
|
for _, v := range d.currentRecipe.Recipe01 {
|
||||||
if v.ProductCode == productCode {
|
if v.ProductCode == productCode {
|
||||||
return v, nil
|
return v, nil
|
||||||
|
|
@ -183,9 +187,11 @@ func (d *Data) GetRecipe01ByProductCode(filename, countryID, productCode string)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *Data) SetValuesToRecipe(recipe models.Recipe01) {
|
func (d *Data) SetValuesToRecipe(recipe models.Recipe01) {
|
||||||
for _, v := range d.currentRecipe.Recipe01 {
|
for index, v := range d.currentRecipe.Recipe01 {
|
||||||
if v.ProductCode == recipe.ProductCode {
|
if v.ProductCode == recipe.ProductCode {
|
||||||
v = recipe
|
// Log.Debug("SetValuesToRecipe", zap.Any("old", v), zap.Any("new", recipe))
|
||||||
|
// v = recipe
|
||||||
|
d.currentRecipe.Recipe01[index] = recipe
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -216,7 +222,7 @@ func (d *Data) GetMaterialSetting(countryID, filename string) []models.MaterialS
|
||||||
recipe, err := helpers.ReadRecipeFile(countryID, filename)
|
recipe, err := helpers.ReadRecipeFile(countryID, filename)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.GetInstance().Error("Error when read recipe file", zap.Error(err))
|
logger.GetInstance().Error("Error when read recipe file [GetMaterialSetting]", zap.Error(err))
|
||||||
copy(result, d.currentRecipe.MaterialSetting)
|
copy(result, d.currentRecipe.MaterialSetting)
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
@ -260,7 +266,7 @@ func (d *Data) GetMaterialCode(ids []uint64, countryID, filename string) []model
|
||||||
recipe, err := helpers.ReadRecipeFile(countryID, filename)
|
recipe, err := helpers.ReadRecipeFile(countryID, filename)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.GetInstance().Error("Error when read recipe file", zap.Error(err))
|
logger.GetInstance().Error("Error when read recipe file [GetMaterialCode]", zap.Error(err))
|
||||||
return d.currentRecipe.MaterialCode
|
return d.currentRecipe.MaterialCode
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -370,31 +370,38 @@ func (rr *RecipeRouter) Route(r chi.Router) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
recipe_root_path := "./cofffeemachineConfig/"
|
// recipe_root_path := "./cofffeemachineConfig/"
|
||||||
|
|
||||||
// structure
|
// structure
|
||||||
full_file_name_targets := []string{}
|
// full_file_name_targets := []string{}
|
||||||
|
|
||||||
files, err := os.ReadDir(recipe_root_path + countryID)
|
// files, err := os.ReadDir(recipe_root_path + countryID)
|
||||||
|
|
||||||
|
// if err != nil {
|
||||||
|
// Log.Error("Error when read directory", zap.Error(err))
|
||||||
|
// return
|
||||||
|
// }
|
||||||
|
|
||||||
|
// for _, file := range files {
|
||||||
|
// Log.Debug("File: ", zap.Any("file", file.Name()))
|
||||||
|
// if strings.Contains(file.Name(), file_version) && strings.Contains(file.Name(), ".tmp") {
|
||||||
|
// full_file_name_targets = append(full_file_name_targets, file.Name())
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
commits, err := data.GetCommitLogOfFilename(countryID, file_version)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
Log.Error("Error when read directory", zap.Error(err))
|
Log.Error("Error when get commit log", zap.Error(err))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, file := range files {
|
|
||||||
Log.Debug("File: ", zap.Any("file", file.Name()))
|
|
||||||
if strings.Contains(file.Name(), file_version) && strings.Contains(file.Name(), ".tmp") {
|
|
||||||
full_file_name_targets = append(full_file_name_targets, file.Name())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
w.Header().Set("Content-Type", "application/json")
|
w.Header().Set("Content-Type", "application/json")
|
||||||
|
|
||||||
w.WriteHeader(http.StatusOK)
|
w.WriteHeader(http.StatusOK)
|
||||||
json.NewEncoder(w).Encode(map[string]interface{}{"files": full_file_name_targets})
|
json.NewEncoder(w).Encode(map[string]interface{}{"files": commits})
|
||||||
|
|
||||||
Log.Debug("Saved Files: ", zap.Any("files", full_file_name_targets))
|
Log.Debug("Saved Files: ", zap.Any("files", commits))
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue