Skip to content

Commit

Permalink
Makes it possible to save user data only with changes
Browse files Browse the repository at this point in the history
Change-Id: I2bde131eb83b9f73d68b9375b28ed0054320665c
  • Loading branch information
frague committed May 2, 2017
1 parent 2d0dcf2 commit c3d6f32
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
11 changes: 5 additions & 6 deletions ui/app/admin/user_diff.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,22 +41,21 @@ export class UserDiff {
};

ngOnInit() {
let versionsCount = this.versions.length - 1;

this.currentVersion = this.versions[this.index];

if (!this.index) return;
if (this.index === versionsCount) return;

let currentData = this.currentVersion.data;
let previousData = this.versions[this.index - 1].data;
let previousData = this.versions[this.index + 1].data;

_.forEach(this.fields, (name, field) => {
let [oldValue, newValue] = [currentData[field], previousData[field]];
let [newValue, oldValue] = [currentData[field], previousData[field]];

console.log(field, oldValue, newValue);
if (!_.isEqual(oldValue, newValue)) {
this.diff.push({name, oldValue, newValue});
}
});

console.log(this.diff);
}
}
7 changes: 7 additions & 0 deletions ui/app/admin/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export class UsersComponent {
shownUserId: string = null;
pagedData: pagedResult = {} as pagedResult;
canSeeRoles: boolean = false;
fields = ['login', 'full_name', 'email', 'role_id'];

constructor(
private auth: AuthService,
Expand Down Expand Up @@ -91,6 +92,12 @@ export class UsersComponent {
return role ? role.data.name : '-';
}

hasChanges(user: User) {
return _.some(this.fields, field => {
return _.get(this.newUser.data, field) !== _.get(user.data, field);
});
}

editUser(user: User = null) {
this.newUser = _.isNull(user) ? new User({}) : user.clone();
this.shownUserId = null;
Expand Down
2 changes: 1 addition & 1 deletion ui/app/templates/users.html
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@
type="button"
class="btn btn-primary pull-right"
(click)="saveUser()"
[disabled]="!editUserForm.form.valid"
[disabled]="!editUserForm.form.valid || !hasChanges(user)"
[shownFor]="'edit_user'"
>
Save
Expand Down

0 comments on commit c3d6f32

Please sign in to comment.