Skip to content

Commit

Permalink
update : web ui
Browse files Browse the repository at this point in the history
  • Loading branch information
heedaeshin committed Sep 13, 2024
1 parent 465dc04 commit 0113193
Show file tree
Hide file tree
Showing 40 changed files with 689 additions and 203 deletions.
2 changes: 1 addition & 1 deletion models/basicTask.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ type Schedule struct {
}

type GenarateTask struct {
Task
Task `json:"inline"`
TargetPoint GenTaskTarget `json:"targetPoint"`
}

Expand Down
2 changes: 1 addition & 1 deletion models/genDataParams.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ type GenDataParams struct {

type GenFileParams struct {
Directory string `json:"Directory,omitempty" swaggerignore:"true"`
DummyPath string `json:"dummyPath,omitempty" swaggerignore:"true"`
DummyPath string `json:"path,omitempty" swaggerignore:"true"`
FileFormatParams
FileSizeParams
}
Expand Down
14 changes: 12 additions & 2 deletions pkg/rdbms/mysql/mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func (d *MysqlDBMS) Exec(query string) error {
if err != nil {
log.Error().Err(err).Str("query", query).Msg("Failed to execute SQL query")
}
log.Info().Str("query", query).Msg("SQL query executed successfully")
log.Debug().Str("query", query).Msg("SQL query executed successfully")
return err
}

Expand Down Expand Up @@ -106,13 +106,16 @@ func (d *MysqlDBMS) DeleteDB(dbName string) error {
func (d *MysqlDBMS) ListDB(dst *[]string) error {
rows, err := d.db.Query("SHOW DATABASES")
if err != nil {
log.Error().Err(err).Msgf("SQL query executed failed %v", rows)
return err
}

defer rows.Close()

for rows.Next() {
var dbName string
if err := rows.Scan(&dbName); err != nil {
log.Error().Err(err).Msgf("SQL query executed failed %v", rows)
return err
}

Expand All @@ -127,6 +130,7 @@ func (d *MysqlDBMS) ListDB(dst *[]string) error {
func (d *MysqlDBMS) ListTable(dbName string, dst *[]string) error {
_, err := d.db.Exec(fmt.Sprintf("USE %s;", dbName))
if err != nil {
log.Error().Err(err).Msgf("SQL query executed failed")
return err
}

Expand All @@ -150,6 +154,7 @@ func (d *MysqlDBMS) ListTable(dbName string, dst *[]string) error {
func (d *MysqlDBMS) ShowCreateDBSql(dbName string, dbCreateSql *string) error {
err := d.db.QueryRow(fmt.Sprintf("SHOW CREATE DATABASE %s;", dbName)).Scan(&dbName, dbCreateSql)
if err != nil {
log.Error().Err(err).Msgf("SQL query executed failed")
return err
}

Expand All @@ -173,9 +178,11 @@ func (d *MysqlDBMS) ShowCreateDBSql(dbName string, dbCreateSql *string) error {
// Get table create sql
func (d *MysqlDBMS) ShowCreateTableSql(dbName, tableName string, tableCreateSql *string) error {
if err := d.Exec(fmt.Sprintf("USE %s;", dbName)); err != nil {
log.Error().Err(err).Msgf("SQL query executed failed")
return err
}
if err := d.db.QueryRow(fmt.Sprintf("SHOW CREATE TABLE %s;", tableName)).Scan(&tableName, tableCreateSql); err != nil {
log.Error().Err(err).Msgf("SQL query executed failed")
return err
}
*tableCreateSql = removeSequenceOption(*tableCreateSql)
Expand All @@ -188,6 +195,7 @@ func (d *MysqlDBMS) ShowCreateTableSql(dbName, tableName string, tableCreateSql
func (d *MysqlDBMS) GetInsert(dbName, tableName string, insertSql *[]string) error {
colRows, err := d.db.Query("SELECT COLUMN_NAME FROM information_schema.COLUMNS WHERE TABLE_SCHEMA = ? AND TABLE_NAME = ?", dbName, tableName)
if err != nil {
log.Error().Err(err).Msgf("SQL query executed failed")
return err
}
defer colRows.Close()
Expand All @@ -196,6 +204,7 @@ func (d *MysqlDBMS) GetInsert(dbName, tableName string, insertSql *[]string) err
for colRows.Next() {
var columnName string
if err := colRows.Scan(&columnName); err != nil {
log.Error().Err(err).Msgf("SQL query executed failed")
return err
}
columns = append(columns, columnName)
Expand All @@ -210,6 +219,7 @@ func (d *MysqlDBMS) GetInsert(dbName, tableName string, insertSql *[]string) err
selectQuery := "SELECT " + strings.Join(escapedColumns, ", ") + " FROM " + tableName
selRows, err := d.db.Query(selectQuery)
if err != nil {
log.Error().Err(err).Msgf("SQL query executed failed")
return err
}
defer selRows.Close()
Expand All @@ -225,7 +235,7 @@ func (d *MysqlDBMS) GetInsert(dbName, tableName string, insertSql *[]string) err

err := selRows.Scan(valuePtrs...)
if err != nil {

log.Error().Err(err).Msgf("SQL query executed failed")
return err
}

Expand Down
2 changes: 1 addition & 1 deletion service/rdbc/rdbc.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func New(rdb RDBMS, opts ...Option) (*RDBController, error) {
func (rdb *RDBController) ListDB(dst *[]string) error {
err := rdb.client.ListDB(dst)
if err != nil {
log.Info().Msgf("RDB", *dst)
log.Error().Err(err).Msgf("RDB %v", *dst)
return err
}
return nil
Expand Down
111 changes: 93 additions & 18 deletions web/js/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,50 @@ window.addEventListener('DOMContentLoaded', event => {

});

function convertCheckboxParams(obj) {
for (const key in obj) {
if (obj.hasOwnProperty(key)) {
if (obj[key] === "on") {
obj[key] = true;
} else if (obj[key] === "off") {
obj[key] = false;
} else if (typeof obj[key] === "object" && !Array.isArray(obj[key])) {
convertCheckboxParams(obj[key]);
}
}
}
return obj;
}

function formDataToObject(formData) {
const data = {};
formData.forEach((value, key) => {
const match = key.match(/(\w+)\[(\w+)\]/);
if (match) {
const objName = match[1];
const paramName = match[2];
if (!data[objName]) {
data[objName] = {};
}
data[objName][paramName] = value;
} else {
data[key] = value;
}
});
return data;
}

function getInputValue(id) {
const element = document.getElementById(id);
if (!element) {
// console.warn(`Element with id '${id}' not found.`);
return null;
}

const value = element.value.trim();
return value !== "" ? value : null;
}


function generateFormSubmit() {
const form = document.getElementById('genForm');
Expand All @@ -45,41 +89,52 @@ function generateFormSubmit() {
resultCollpase();

const payload = new FormData(form);
let jsonData = JSON.stringify(Object.fromEntries(payload));
console.log(jsonData);
let jsonData = Object.fromEntries(payload);
jsonData=convertCheckboxParams(jsonData)
jsonData.targetPoint = {
...jsonData
};
console.log(jsonData)
jsonData.targetPoint.provider = document.getElementById('provider').value;
const target = document.getElementById('genTarget').value;

const target= document.getElementById('genTarget').value;
if ( (jsonData.targetPoint.provider =="ncp") && (jsonData.targetPoint.endpoint =="") ) {
jsonData.targetPoint.endpoint ="https://kr.object.ncloudstorage.com"
}
const url = "/generate/" + target;

console.log(url);

let req;
if (target == "gcp" || target == "firestore") {
req = { method: 'POST', body: payload };
} else {
req = { method: 'POST', body: jsonData };
}

req = {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(jsonData)
};

fetch(url, req)
.then(response => {
if (!response.ok) {
throw new Error('Network response was not ok');
}
return response.json();
})
.then(json => {
const resultText = document.getElementById('resultText');
resultText.value = json.Result;
console.log(json);
console.log("generate done.");
console.log("Generate done.");
})
.catch(reason => {
console.log(reason);
alert(reason);
console.error("Error during generate:", reason);
alert(reason.message || reason);
})
.finally(() => {
loadingButtonOff();
});

console.log("generate progressing...");

console.log("Generate progressing...");
});
}

Expand All @@ -92,19 +147,39 @@ function migrationFormSubmit() {
resultCollpase();

const payload = new FormData(form);
let jsonData= formDataToObject(payload)
console.log(jsonData)
const dest = document.getElementById('migDest').value;
const source = document.getElementById('migSource').value;
jsonData.targetPoint.provider = getInputValue('targetPoint[provider]');
jsonData.sourcePoint.provider = getInputValue('sourcePoint[provider]');


let url = "/migration/" + source;
if (source != dest) {
url = url + "/" + dest;
}

if ( (jsonData.targetPoint.provider =="ncp") && (jsonData.targetPoint.endpoint =="") ) {
jsonData.targetPoint.endpoint ="https://kr.object.ncloudstorage.com"
}
if ( (jsonData.sourcePoint.provider =="ncp") && (jsonData.sourcePoint.endpoint =="") ) {
jsonData.sourcePoint.endpoint ="https://kr.object.ncloudstorage.com"
}

console.log(url);

fetch(url, {
let req;

req = {
method: 'POST',
body: payload
})
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(jsonData)
};

fetch(url, req)
.then(response => {
return response.json();
})
Expand Down
11 changes: 9 additions & 2 deletions web/templates/gen-dynamodb.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,14 @@ <h1 class="mt-4">데이터 생성 DynamoDB</h1>
<label for="gen-dynamodb-region">리전 선택</label>
</div>
</div>

<div class="input-group mb-3">
<span class="input-group-text"><i class="fa-solid fa-user-secret"></i></span>
<div class="form-floating">
<input type="text" class="form-control" id="gen-s3-profile" name="profileName" placeholder="profile name" required>
<label for="gen-s3-profile">Profile</label>
</div>
</div>
<!-- <div class="input-group mb-3">
<span class="input-group-text"><i class="fa-solid fa-key"></i></span>
<div class="form-floating">
<input type="text" class="form-control" id="gen-dynamodb-accessKey" name="accessKey" placeholder="Access Key" required>
Expand All @@ -44,10 +50,11 @@ <h1 class="mt-4">데이터 생성 DynamoDB</h1>
<input type="password" class="form-control" id="gen-dynamodb-secretKey" name="secretKey" placeholder="Secret Key" required>
<label for="gen-dynamodb-secretKey">Secret Key</label>
</div>
</div>
</div> -->

<button type="submit" class="btn btn-primary" id="submitBtn">생성</button>
<input type="hidden" id="genTarget" value="dynamodb" />
<input type="hidden" id="provider" value="aws">
</form>
</div>
</div>
Expand Down
20 changes: 17 additions & 3 deletions web/templates/gen-firestore.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,21 @@ <h1 class="mt-4">데이터 생성 Firestore</h1>
<label for="gen-firestore-region">리전 선택</label>
</div>
</div>

<div class="mb-3">
<div class="input-group mb-3">
<span class="input-group-text"><i class="fa-solid fa-user-secret"></i></span>
<div class="form-floating">
<input type="text" class="form-control" id="gen-s3-profile" name="profileName" placeholder="profile name" required>
<label for="gen-s3-profile">Profile</label>
</div>
</div>
<div class="input-group mb-3">
<span class="input-group-text"><i class="fa-solid fa-folder"></i></span>
<div class="form-floating">
<input type="text" class="form-control" id="gen-s3-profile" name="databaseId" placeholder="database id">
<label for="gen-s3-databaseId">DatabaseId</label>
</div>
</div>
<!-- <div class="mb-3">
<label for="gen-firestore-credential" class="form-label">Credentials 파일</label>
<input class="form-control" type="file" id="mig-gcp-credential" name="gcpCredential" required>
</div>
Expand All @@ -38,10 +51,11 @@ <h1 class="mt-4">데이터 생성 Firestore</h1>
<input type="text" class="form-control" id="gen-firestore-projectid" name="projectid" placeholder="Project ID" required>
<label for="gen-firestore-projectid">Project ID</label>
</div>
</div>
</div> -->

<button type="submit" class="btn btn-primary" id="submitBtn">Submit</button>
<input type="hidden" id="genTarget" value="firestore">
<input type="hidden" id="provider" value="gcp">
</form>
</div>
</div>
Expand Down
12 changes: 10 additions & 2 deletions web/templates/gen-gcp.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,14 @@ <h1 class="mt-4">데이터 생성 GCP</h1>
</div>
</div>

<div class="mb-3">
<div class="input-group mb-3">
<span class="input-group-text"><i class="fa-solid fa-user-secret"></i></span>
<div class="form-floating">
<input type="text" class="form-control" id="gen-s3-profile" name="profileName" placeholder="profile name" required>
<label for="gen-s3-profile">Profile</label>
</div>
</div>
<!-- <div class="mb-3">
<label for="gen-gcp-credential" class="form-label">Credentials 파일</label>
<input class="form-control" type="file" id="mig-gcp-credential" name="gcpCredential" required>
</div>
Expand All @@ -37,7 +44,7 @@ <h1 class="mt-4">데이터 생성 GCP</h1>
<input type="text" class="form-control" id="gen-s3-projectid" name="projectid" placeholder="ProjectID" required>
<label for="gen-s3-bucket">ProjectID</label>
</div>
</div>
</div> -->

<div class="input-group mb-3">
<span class="input-group-text"><i class="fa-solid fa-bucket"></i></span>
Expand All @@ -51,6 +58,7 @@ <h1 class="mt-4">데이터 생성 GCP</h1>

<button type="submit" class="btn btn-primary" id="submitBtn">Submit</button>
<input type="hidden" id="genTarget" value="gcp">
<input type="hidden" id="provider" value="gcp">
</form>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion web/templates/gen-linux.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ <h1 class="mt-4">데이터 생성 Linux</h1>
<div class="input-group">
<span class="input-group-text"><i class="fas fa-folder"></i></span>
<div class="form-floating">
<input type="text" class="form-control" id="gen-linux-path" name="path" value="/tmp/dummy" placeholder="디렉토리 경로">
<input type="text" class="form-control" id="gen-linux-path" name="dummyPath" value="/tmp/dummy" placeholder="디렉토리 경로">
<label for="gen-linux-path">디렉토리 경로</label>
</div>
</div>
Expand Down
1 change: 1 addition & 0 deletions web/templates/gen-mongodb.html
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ <h1 class="mt-4">데이터 생성 MongoDB</h1>

<button type="submit" class="btn btn-primary" id="submitBtn">생성</button>
<input type="hidden" id="genTarget" value="mongodb">
<input type="hidden" id="provider" value="ncp">
</form>
</div>
</div>
Expand Down
Loading

0 comments on commit 0113193

Please sign in to comment.