Add merge ops (not yet import py api)
This commit is contained in:
parent
a6a7397dce
commit
850c483d5b
13 changed files with 220 additions and 1676 deletions
|
|
@ -12,6 +12,7 @@ import { HeaderComponent } from './core/layout/header.component';
|
||||||
import { HttpClientModule } from '@angular/common/http';
|
import { HttpClientModule } from '@angular/common/http';
|
||||||
import { AppComponent } from './app.component';
|
import { AppComponent } from './app.component';
|
||||||
import { ChangelogComponent } from './features/changelog/changelog.component';
|
import { ChangelogComponent } from './features/changelog/changelog.component';
|
||||||
|
import { ReactiveFormsModule } from '@angular/forms';
|
||||||
|
|
||||||
@NgModule({
|
@NgModule({
|
||||||
declarations: [AppComponent],
|
declarations: [AppComponent],
|
||||||
|
|
|
||||||
File diff suppressed because it is too large
Load diff
|
|
@ -1,11 +1,16 @@
|
||||||
import { Component } from '@angular/core';
|
import { Component } from '@angular/core';
|
||||||
|
import { MergeComponent } from '../merge/merge.component';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-changelog',
|
selector: 'app-changelog',
|
||||||
standalone: true,
|
standalone: true,
|
||||||
templateUrl: './changelog.component.html',
|
templateUrl: './changelog.component.html',
|
||||||
styleUrls: ['./changelog.component.css']
|
styleUrls: ['./changelog.component.css'],
|
||||||
|
imports: [MergeComponent]
|
||||||
})
|
})
|
||||||
export class ChangelogComponent {
|
export class ChangelogComponent {
|
||||||
|
fetchLog(){
|
||||||
|
// TODO: Fetch changelog.html
|
||||||
|
fetch("/changelog")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
16
client/src/app/features/merge/merge-service.service.spec.ts
Normal file
16
client/src/app/features/merge/merge-service.service.spec.ts
Normal file
|
|
@ -0,0 +1,16 @@
|
||||||
|
import { TestBed } from '@angular/core/testing';
|
||||||
|
|
||||||
|
import { MergeServiceService } from './merge-service.service';
|
||||||
|
|
||||||
|
describe('MergeServiceService', () => {
|
||||||
|
let service: MergeServiceService;
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
TestBed.configureTestingModule({});
|
||||||
|
service = TestBed.inject(MergeServiceService);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should be created', () => {
|
||||||
|
expect(service).toBeTruthy();
|
||||||
|
});
|
||||||
|
});
|
||||||
12
client/src/app/features/merge/merge-service.service.ts
Normal file
12
client/src/app/features/merge/merge-service.service.ts
Normal file
|
|
@ -0,0 +1,12 @@
|
||||||
|
import { Injectable } from '@angular/core';
|
||||||
|
|
||||||
|
@Injectable({
|
||||||
|
providedIn: 'root'
|
||||||
|
})
|
||||||
|
export class MergeServiceService {
|
||||||
|
|
||||||
|
master_version: number = 0;
|
||||||
|
dev_version: number = 0;
|
||||||
|
|
||||||
|
constructor() { }
|
||||||
|
}
|
||||||
0
client/src/app/features/merge/merge.component.css
Normal file
0
client/src/app/features/merge/merge.component.css
Normal file
43
client/src/app/features/merge/merge.component.html
Normal file
43
client/src/app/features/merge/merge.component.html
Normal file
|
|
@ -0,0 +1,43 @@
|
||||||
|
|
||||||
|
<div class="flex-3 bg-stone-400 h-screen justify-centers items-center">
|
||||||
|
|
||||||
|
<h3 class="text-2xl text-center py-4 font-semibold">Merge 2 json</h3>
|
||||||
|
|
||||||
|
<div class="bg-stone-600 p-1 m-2 rounded-md">
|
||||||
|
<div class="bg-stone-500 m-2 rounded-md">
|
||||||
|
<p class="px-1 py-5 font-semibold">
|
||||||
|
❓ What does this function do?
|
||||||
|
</p>
|
||||||
|
<div class="bg-stone-300 rounded">
|
||||||
|
<p class="px-2 ">
|
||||||
|
Apply changes from the `dev` version
|
||||||
|
<br>into the `master` version
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="bg-stone-200 p-1 m-2 rounded-md">
|
||||||
|
<p class="px-2 py-4 text-md text-center font-bold">
|
||||||
|
❗Beware❗
|
||||||
|
<br>`master` = base version
|
||||||
|
<br>`dev` = your version
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<form class="space-y-6 p-3 bg-stone-500 rounded" [formGroup]="mergeForm" (ngSubmit)="fetchMerge()">
|
||||||
|
<div class="flex">
|
||||||
|
<label class="flex-1 text-red-700 font-bold bg-yellow-100 rounded text-center" for="master_version">Master</label>
|
||||||
|
<input class="flex-1 mx-1 bg-slate-300 hover:bg-blue-400 text-center border border-collapse rounded-md" id="master_version" formControlName="master_version" type="text">
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="flex">
|
||||||
|
<label class="flex-1 bg-yellow-100 font-bold rounded text-center" for="dev_version">Dev</label>
|
||||||
|
<input class="flex-1 mx-1 bg-slate-300 hover:bg-blue-400 text-center border border-collapse rounded-md" id="dev_version" formControlName="dev_version" type="text">
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<button class="button font-semibold bg-red-300 p-4 border border-collapse rounded-md" type="submit">Begin Merge</button>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
21
client/src/app/features/merge/merge.component.spec.ts
Normal file
21
client/src/app/features/merge/merge.component.spec.ts
Normal file
|
|
@ -0,0 +1,21 @@
|
||||||
|
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||||
|
|
||||||
|
import { MergeComponent } from './merge.component';
|
||||||
|
|
||||||
|
describe('MergeComponent', () => {
|
||||||
|
let component: MergeComponent;
|
||||||
|
let fixture: ComponentFixture<MergeComponent>;
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
TestBed.configureTestingModule({
|
||||||
|
imports: [MergeComponent]
|
||||||
|
});
|
||||||
|
fixture = TestBed.createComponent(MergeComponent);
|
||||||
|
component = fixture.componentInstance;
|
||||||
|
fixture.detectChanges();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should create', () => {
|
||||||
|
expect(component).toBeTruthy();
|
||||||
|
});
|
||||||
|
});
|
||||||
49
client/src/app/features/merge/merge.component.ts
Normal file
49
client/src/app/features/merge/merge.component.ts
Normal file
|
|
@ -0,0 +1,49 @@
|
||||||
|
import { Component } from '@angular/core';
|
||||||
|
import { CommonModule } from '@angular/common';
|
||||||
|
|
||||||
|
import { FormBuilder, ReactiveFormsModule } from '@angular/forms';
|
||||||
|
import { MergeServiceService } from './merge-service.service';
|
||||||
|
|
||||||
|
@Component({
|
||||||
|
selector: 'app-merge',
|
||||||
|
standalone: true,
|
||||||
|
imports: [CommonModule, ReactiveFormsModule],
|
||||||
|
templateUrl: './merge.component.html',
|
||||||
|
styleUrls: ['./merge.component.css']
|
||||||
|
})
|
||||||
|
export class MergeComponent {
|
||||||
|
|
||||||
|
exceptionValues = [0, null, undefined]
|
||||||
|
|
||||||
|
mergeForm = this.formBuilder.group({
|
||||||
|
master_version: 0,
|
||||||
|
dev_version: 0
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
constructor(
|
||||||
|
private targets: MergeServiceService,
|
||||||
|
private formBuilder: FormBuilder,
|
||||||
|
){}
|
||||||
|
|
||||||
|
private isException(value: any){
|
||||||
|
return this.exceptionValues.includes(value)
|
||||||
|
}
|
||||||
|
|
||||||
|
fetchMerge(){
|
||||||
|
if(this.isException(this.mergeForm.value.master_version) || this.isException(this.mergeForm.value.dev_version)){
|
||||||
|
return
|
||||||
|
}
|
||||||
|
this.targets.master_version = this.mergeForm.value.master_version!;
|
||||||
|
this.targets.dev_version = this.mergeForm.value.dev_version!;
|
||||||
|
|
||||||
|
// TODO: Fetch merge. Modify this to websocket
|
||||||
|
return fetch("http://localhost:3000/merge", {
|
||||||
|
method: "POST",
|
||||||
|
body: JSON.stringify({
|
||||||
|
master: this.targets.master_version,
|
||||||
|
dev: this.targets.dev_version
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
10
server/git_pull_recipe.sh
Normal file
10
server/git_pull_recipe.sh
Normal file
|
|
@ -0,0 +1,10 @@
|
||||||
|
# modify this
|
||||||
|
# .sh for linux
|
||||||
|
# .bat for windows
|
||||||
|
|
||||||
|
# pull only 1 file
|
||||||
|
|
||||||
|
git clone --depth 1 --no-checkout --filter=blob:none ssh://ikong@192.168.10.159/1TBHDD/ikong/repo/cofffeemachineConfig
|
||||||
|
cd cofffeemachineConfig
|
||||||
|
git checkout master -- coffeethai02_577.json
|
||||||
|
cd ..
|
||||||
|
|
@ -3,3 +3,5 @@ module recipe-manager
|
||||||
go 1.21.1
|
go 1.21.1
|
||||||
|
|
||||||
require github.com/go-chi/chi/v5 v5.0.10
|
require github.com/go-chi/chi/v5 v5.0.10
|
||||||
|
|
||||||
|
require github.com/go-chi/cors v1.2.1 // indirect
|
||||||
|
|
|
||||||
|
|
@ -1,2 +1,4 @@
|
||||||
github.com/go-chi/chi/v5 v5.0.10 h1:rLz5avzKpjqxrYwXNfmjkrYYXOyLJd37pz53UFHC6vk=
|
github.com/go-chi/chi/v5 v5.0.10 h1:rLz5avzKpjqxrYwXNfmjkrYYXOyLJd37pz53UFHC6vk=
|
||||||
github.com/go-chi/chi/v5 v5.0.10/go.mod h1:DslCQbL2OYiznFReuXYUmQ2hGd1aDpCnlMNITLSKoi8=
|
github.com/go-chi/chi/v5 v5.0.10/go.mod h1:DslCQbL2OYiznFReuXYUmQ2hGd1aDpCnlMNITLSKoi8=
|
||||||
|
github.com/go-chi/cors v1.2.1 h1:xEC8UT3Rlp2QuWNEr4Fs/c2EAGVKBwy/1vHx3bppil4=
|
||||||
|
github.com/go-chi/cors v1.2.1/go.mod h1:sSbTewc+6wYHBBCW7ytsFSn836hqM7JxpglAy2Vzc58=
|
||||||
|
|
|
||||||
|
|
@ -6,10 +6,13 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"os"
|
||||||
|
"os/exec"
|
||||||
"recipe-manager/data"
|
"recipe-manager/data"
|
||||||
"recipe-manager/routers"
|
"recipe-manager/routers"
|
||||||
|
|
||||||
"github.com/go-chi/chi/v5"
|
"github.com/go-chi/chi/v5"
|
||||||
|
"github.com/go-chi/cors"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Server struct {
|
type Server struct {
|
||||||
|
|
@ -33,7 +36,52 @@ func (s *Server) Run() error {
|
||||||
|
|
||||||
func createHandler() http.Handler {
|
func createHandler() http.Handler {
|
||||||
r := chi.NewRouter()
|
r := chi.NewRouter()
|
||||||
|
r.Use(cors.Handler(cors.Options{
|
||||||
|
AllowedOrigins: []string{"https://*", "http://*"},
|
||||||
|
AllowCredentials: true,
|
||||||
|
ExposedHeaders: []string{"Content-Type"},
|
||||||
|
AllowedMethods: []string{"GET", "POST", "PUT", "DELETE"},
|
||||||
|
}))
|
||||||
|
r.Post("/merge", func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
var targetMap map[string]interface{}
|
||||||
|
err := json.NewDecoder(r.Body).Decode(&targetMap)
|
||||||
|
if err != nil {
|
||||||
|
w.WriteHeader(http.StatusBadRequest)
|
||||||
|
log.Fatalln("Merge request failed: ", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
log.Println(targetMap)
|
||||||
|
master_version := targetMap["master"].(string)
|
||||||
|
dev_version := targetMap["dev"].(string)
|
||||||
|
|
||||||
|
// find target file in the cofffeemachineConfig
|
||||||
|
if _, err := os.Stat("coffeemachineConfig/coffeethai02_" + master_version + ".json"); err != nil {
|
||||||
|
w.WriteHeader(http.StatusBadRequest)
|
||||||
|
log.Fatalln("Merge request failed. Master file not found: ", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if _, err := os.Stat("coffeemachineConfig/coffeethai02_" + dev_version + ".json"); err != nil {
|
||||||
|
w.WriteHeader(http.StatusBadRequest)
|
||||||
|
log.Fatalln("Merge request failed. Dev file not found: ", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
repo_path := "coffeemachineConfig/coffeethai02_"
|
||||||
|
master_path := repo_path + master_version + ".json"
|
||||||
|
dev_path := repo_path + dev_version + ".json"
|
||||||
|
|
||||||
|
// output path
|
||||||
|
output_path := ""
|
||||||
|
|
||||||
|
// changelog path
|
||||||
|
changelog_path := ""
|
||||||
|
|
||||||
|
// TODO: Call merge api if found
|
||||||
|
err = exec.Command("python", "merge", master_path, dev_path, output_path, changelog_path).Run()
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalln("Merge request failed. Python merge failed: ", err)
|
||||||
|
}
|
||||||
|
})
|
||||||
rr := routers.NewRecipeRouter(data.NewData())
|
rr := routers.NewRecipeRouter(data.NewData())
|
||||||
rr.Route(r)
|
rr.Route(r)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue