Skip to content

bug fix #229

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Jan 9, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
bug fix
  • Loading branch information
jiangliwu committed Jan 8, 2019
commit 3e300b6cde8627601b91049e7b5d84c853b0828e
2 changes: 1 addition & 1 deletion src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ export class AppComponent implements OnInit {
if (newValue.onSuccess) {
newValue.onSuccess(newValue);
}
this.util.showMessage('new value added successfully');
this.util.showMessage(newValue.edit ? 'The value is updated successfully' : 'New value added successfully');
}, e => {
console.error(e.error.message);
this.util.showMessage('new value add failed, ' + this.util.getErrorMessage(e));
Expand Down
57 changes: 52 additions & 5 deletions src/app/components/add-value-dialog/add-value-dialog.component.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import {Component, Inject, OnInit} from '@angular/core';
import {MAT_DIALOG_DATA, MatDialogRef, MatSnackBar} from '@angular/material';
import {MAT_DIALOG_DATA, MatDialog, MatDialogRef, MatSnackBar} from '@angular/material';
import {UtilService} from '../../services/util.service';
import _ from 'lodash';
import {ConfirmDialogComponent} from '../confirm-dialog/confirm-dialog.component';
import {RedisService} from '../../services/redis.service';


/**
Expand Down Expand Up @@ -37,7 +39,9 @@ export class AddValueDialogComponent implements OnInit {
public dialogRef: MatDialogRef<AddValueDialogComponent>,
@Inject(MAT_DIALOG_DATA) public data: ValueMode,
private snackBar: MatSnackBar,
private util: UtilService
private util: UtilService,
private redisService: RedisService,
private dialogService: MatDialog
) {
}

Expand Down Expand Up @@ -127,8 +131,10 @@ export class AddValueDialogComponent implements OnInit {
return this.showError('duplicate keys found');
}
for (let i = 0; i < values.length; i++) {
this.data.rawLine.push('HMSET');
this.data.rawLine.push(this.data.key);
if (i === 0) {
this.data.rawLine.push('HMSET');
this.data.rawLine.push(this.data.key);
}
values[i].value = getValue(values[i].value);
values[i].key = getValue(values[i].key);
if (!values[i].key) {
Expand All @@ -144,7 +150,48 @@ export class AddValueDialogComponent implements OnInit {
break;
}
}
this.dialogRef.close(this.data);
this.checkIsExist(this.data, () => {
this.dialogRef.close(this.data);
});
}

/**
* remove exist key
* @param ret the ret include id and key
* @param cb the callback
*/
removeExistKey(ret, cb) {
this.redisService.call(ret.id, [['DEL', ret.key]]).subscribe(() => {
cb();
}, err => {
this.util.showMessage('del key failed, ' + this.util.getErrorMessage(err));
});
}

/**
* check is exist
* @param ret the ret include id and key/values
* @param cb the callback
*/
checkIsExist(ret, cb) {
this.redisService.call(ret.id, [['EXISTS', ret.key]]).subscribe((r) => {
if (r && r.length > 0 && r[0] > 0) { // exist
this.dialogService.open(ConfirmDialogComponent, {
width: '360px', data: {
title: `Key "${ret.key}" Exists`,
message: `Are you sure you want to to replace original value ?`
}
}).afterClosed().subscribe(cr => {
if (cr) {
this.removeExistKey(ret, cb);
}
});
} else {
cb();
}
}, () => {
this.util.showMessage('check key is exist failed');
});
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
</div>

<div class="line buttons">
<button mat-button (click)="onAddItem(getItemArray())" [disabled]="isEditMode">
<button mat-button (click)="onAddItem(getItemArray())" *ngIf="!isEditMode">
<i class="material-icons">add</i>Add New Value
</button>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,9 @@ export class AddValueFormComponent implements OnInit {
onValueChange() {
this.onValueUpdate.emit({
orderedValues: this.orderedValues,
hashMapValues: _.map(this.hashMapValues, (o) => { return _.omit(o, 'isNew'); }),
hashMapValues: _.map(this.hashMapValues, (o) => {
return _.omit(o, 'isNew');
}),
values: this.values
});
}
Expand Down
7 changes: 5 additions & 2 deletions src/app/components/data-viewer/data-viewer.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,8 +237,10 @@ export class DataViewerComponent implements OnInit, OnChanges {

/**
* on add new record
* @param values the record base values
* @param edit is edit mode
*/
onAddNewRecords(values) {
onAddNewRecords(values, edit = false) {
const viewMode = new ValueMode();
viewMode.type = TYPE_MAP[this.pageData.item.type];
viewMode.hideType = true;
Expand Down Expand Up @@ -274,6 +276,7 @@ export class DataViewerComponent implements OnInit, OnChanges {
this.fetchData();
}
};
ret.edit = edit;
this.onNewValue.emit(ret);
}
});
Expand Down Expand Up @@ -354,7 +357,7 @@ export class DataViewerComponent implements OnInit, OnChanges {
* @param elements the element arr
*/
onEditMapElements(elements) {
this.onAddNewRecords({hashMapValues: JSON.parse(JSON.stringify(elements))});
this.onAddNewRecords({hashMapValues: JSON.parse(JSON.stringify(elements))}, true);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import {UtilService} from '../../services/util.service';
import {RedisService} from '../../services/redis.service';
import { saveAs } from 'file-saver';
import _ from 'lodash';
import {Store} from '@ngrx/store';
import {REQ_FETCH_TREE} from '../../ngrx/actions/redis-actions';

@Component({
selector: 'app-import-data-dialog',
Expand All @@ -23,6 +25,7 @@ export class ImportDataDialogComponent implements OnInit {
@Inject(MAT_DIALOG_DATA) public data,
private dialogRef: MatDialogRef<ImportDataDialogComponent>,
private redisService: RedisService,
private _store: Store<any>,
public util: UtilService) {
}

Expand Down Expand Up @@ -120,6 +123,7 @@ export class ImportDataDialogComponent implements OnInit {
this.util.showMessage(`${numberOfSucceed} of row import successful, ${totalRow
- numberOfSucceed} of row import failed.`);
this.dialogRef.close();
this._store.dispatch({type: REQ_FETCH_TREE, payload: {id: this.instanceId}});
}, err => {
this.util.showMessage('Import data failed, ' + this.util.getErrorMessage(err));
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@ export class InstanceRootPanelComponent implements OnInit {
pageSize: 20,
};

constructor(public dialogService: MatDialog, private _store: Store<any>,
private util: UtilService,
private redisService: RedisService) {
constructor(public dialogService: MatDialog, private _store: Store<any>) {
this.cli$ = this._store.select('cli');
}

Expand Down Expand Up @@ -72,27 +70,6 @@ export class InstanceRootPanelComponent implements OnInit {
});
}

checkIsExist(ret) {
this.redisService.call(this.pageData.id, [['EXISTS', ret.key]]).subscribe((r) => {
if (r && r.length > 0 && r[0] > 0) { // exist
this.dialogService.open(ConfirmDialogComponent, {
width: '360px', data: {
title: `Key "${ret.key}" Exists`,
message: `Are you sure you want to to replace original value ?`
}
}).afterClosed().subscribe(cr => {
if (cr) {
this.onNewValue.emit(ret);
}
});
} else {
this.onNewValue.emit(ret);
}
}, () => {
this.util.showMessage('network error');
});
}

/**
* on add new record event, show a dialog
*/
Expand All @@ -107,7 +84,7 @@ export class InstanceRootPanelComponent implements OnInit {
if (ret) {
ret.from = 'root';
ret.item = {};
this.checkIsExist(ret);
this.onNewValue.emit(ret);
}
});
}
Expand Down