Skip to content

Commit

Permalink
fix indents and json parse
Browse files Browse the repository at this point in the history
  • Loading branch information
lyubov-voloshko committed Sep 13, 2023
1 parent ebcf51b commit bd85f65
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
</div>
<form #editRowForm="ngForm" class="form"
(ngSubmit)="handleRowSubmitting()">
{{tableRowValues | json}}
<div *ngFor="let value of fieldsOrdered; let index = index">
<!-- <mat-form-field class="example-form-field" appearance="outline">
<mat-label>test label</mat-label>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ import { DbActionLinkDialogComponent } from '../dashboard/db-action-link-dialog/
import { Location } from '@angular/common';
import { MatDialog } from '@angular/material/dialog';
import { NotificationsService } from 'src/app/services/notifications.service';
import { ServerError } from 'src/app/models/alert';
import { TableRowService } from 'src/app/services/table-row.service';
import { TablesService } from 'src/app/services/tables.service';
import { Title } from '@angular/platform-browser';
import { getTableTypes } from 'src/app/lib/setup-table-row-structure';
import { normalizeTableName } from '../../lib/normalize';
import { ServerError } from 'src/app/models/alert';

@Component({
selector: 'app-db-table-row-edit',
Expand Down Expand Up @@ -248,46 +248,51 @@ export class DbTableRowEditComponent implements OnInit {
};
}

handleRowSubmitting() {
if (this.hasKeyAttributesFromURL) {
this.updateRow();
} else {
this.addRow();
}
}

addRow(continueEditing?: boolean) {
this.submitting = true;
getFormattedUpdatedRow = () => {
let updatedRow = {...this.tableRowValues};

//crutch
//crutch, format datetime fields
if (this._connections.currentConnection.type === DBtype.MySQL) {
const datetimeFields = Object.entries(this.tableTypes).filter(([key, value]) => value === 'datetime');
const datetimeFields = Object.entries(this.tableTypes)
.filter(([key, value]) => value === 'datetime');
if (datetimeFields.length) {
for (const datetimeField of datetimeFields) {
if (this.tableRowValues[datetimeField[0]]) this.tableRowValues[datetimeField[0]] = this.tableRowValues[datetimeField[0]].split('.')[0];
if (updatedRow[datetimeField[0]]) updatedRow[datetimeField[0]] = updatedRow[datetimeField[0]].split('.')[0];
}
}
}
//end crutch

//parse json fields
const jsonFields = Object.entries(this.tableTypes)
.filter(([key, value]) => value === 'json' || value === 'jsonb')
.map(jsonField => jsonField[0]);
if (jsonFields.length) {
for (const jsonField of jsonFields) {
if (this.tableRowValues[jsonField] !== null) {
console.log('this.tableRowValues', jsonField);
console.log(this.tableRowValues[jsonField]);
const clearString = this.tableRowValues[jsonField].split('\n').join('').split('\t').join('');
console.log({clearString});
const updatedFiled = JSON.parse(clearString);
console.log({updatedFiled});
this.tableRowValues[jsonField] = updatedFiled;
if (updatedRow[jsonField] !== null) {
const updatedFiled = JSON.parse(updatedRow[jsonField].toString());
updatedRow[jsonField] = updatedFiled;
}
}
}

this._tableRow.addTableRow(this.connectionID, this.tableName, this.tableRowValues)
return updatedRow;
}

handleRowSubmitting() {
if (this.hasKeyAttributesFromURL) {
this.updateRow();
} else {
this.addRow();
}
}

addRow(continueEditing?: boolean) {
this.submitting = true;

const formattedUpdatedRow = this.getFormattedUpdatedRow();

this._tableRow.addTableRow(this.connectionID, this.tableName, formattedUpdatedRow)
.subscribe((res) => {

this.keyAttributesFromURL = {};
Expand All @@ -312,19 +317,9 @@ export class DbTableRowEditComponent implements OnInit {
updateRow(continueEditing?: boolean) {
this.submitting = true;

//crutch
if (this._connections.currentConnection.type === DBtype.MySQL) {
const datetimeFields = Object.entries(this.tableTypes)
.filter(([key, value]) => value === 'datetime');
if (datetimeFields.length) {
for (const datetimeField of datetimeFields) {
if (this.tableRowValues[datetimeField[0]]) this.tableRowValues[datetimeField[0]] = this.tableRowValues[datetimeField[0]].split('.')[0];
}
}
}
//end crutch
const formattedUpdatedRow = this.getFormattedUpdatedRow();

this._tableRow.updateTableRow(this.connectionID, this.tableName, this.keyAttributesFromURL, this.tableRowValues)
this._tableRow.updateTableRow(this.connectionID, this.tableName, this.keyAttributesFromURL, formattedUpdatedRow)
.subscribe((res) => {
this.ngZone.run(() => {
if (continueEditing) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Input, Output, OnInit, EventEmitter, Component, ViewChild } from '@angular/core';
import { Component, EventEmitter, Input, OnInit, Output, ViewChild } from '@angular/core';

// import { JsonEditorComponent as JsonEditor, JsonEditorOptions } from 'ang-jsoneditor';
import { normalizeFieldName } from '../../../../lib/normalize';

Expand Down Expand Up @@ -28,7 +29,7 @@ export class JsonEditorComponent implements OnInit {

ngOnInit(): void {
this.normalizedLabel = normalizeFieldName(this.label);
this.value = JSON.stringify(this.value) || '';
this.value = JSON.stringify(this.value, undefined, 4) || '';
}

// onJSONchange(event) {
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/config.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"#important to keep it /api for prod": true,
"baseURL": "https://app.rocketadmin.com/api"
"baseURL": "/api"
}

0 comments on commit bd85f65

Please sign in to comment.