Skip to content

Commit

Permalink
Merge pull request #241 from mshima/adjusts
Browse files Browse the repository at this point in the history
reimplement angular-audit and adjust javers
  • Loading branch information
mshima authored Apr 10, 2024
2 parents 65e34f2 + e66165b commit c7acc95
Show file tree
Hide file tree
Showing 12 changed files with 255 additions and 259 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,30 @@ application {
devDatabaseType h2Disk
enableHibernateCache false
enableTranslation false
jwtSecretKey "ZjY4MTM4YjI5YzMwZjhjYjI2OTNkNTRjMWQ5Y2Q0Y2YwOWNmZTE2NzRmYzU3NTMwM2NjOTE3MTllOTM3MWRkMzcyYTljMjVmNmQ0Y2MxOTUzODc0MDhhMTlkMDIxMzI2YzQzZDM2ZDE3MmQ3NjVkODk3OTVmYzljYTQyZDNmMTQ="
testFrameworks [cypress]
}

entities Blog, Post, Tag
}

@EnableAudit
@ChangelogDate(20240000000000)
entity Blog {
name String required minlength(3)
handle String required minlength(2)
}

@EnableAudit
@ChangelogDate(20240000000100)
entity Post {
title String required
content TextBlob required
date Instant required
}

@EnableAudit
@ChangelogDate(20240000000300)
entity Tag {
name String required minlength(2)
}
Expand Down
2 changes: 1 addition & 1 deletion generators/angular-audit/generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export default class extends BaseApplicationGenerator {
source.addItemToAdminMenu?.({
icon: 'list-alt',
route: 'admin/entity-audit',
translationKey: 'entityAudit',
translationKey: 'global.menu.admin.entityAudit',
name: 'Entity Audit',
});
},
Expand Down
2 changes: 1 addition & 1 deletion generators/angular-audit/resources/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"dependencies": {
"ngx-diff": "6.0.1"
"ngx-diff": "8.0.4"
}
}
Original file line number Diff line number Diff line change
@@ -1,44 +1,27 @@
<div class="modal-header">
<h4 class="modal-title" <%= jhiPrefix %>Translate="entityAudit.detail.title">
Audit Details
</h4>
<button
<%_ if (enableTranslation) { _%>
attr.aria-label="{{ 'entityAudit.detail.close' | translate }}"
<%_ } else { _%>
aria-label="Close"
<%_ } _%>
data-dismiss="modal" class="close" type="button"
(click)="activeModal.dismiss('closed')">
<span aria-hidden="true">&times;</span>
</button>
<h4 class="modal-title">__jhiTranslateTag__('entityAudit.detail.title')</h4>

<span class="btn btn-close" data-dismiss="modal" aria-hidden="true" (click)="activeModal.dismiss('closed')"></span>
</div>
<div class="modal-body pad">
<div>
<strong<% if (enableTranslation) { %>
<%= jhiPrefix %>Translate="entityAudit.detail.action"
[translateValues]="{ action: action }"<% } %>>
{{action}} action was performed on below data
</strong>
<br><br>
<strong>__jhiTranslateTag__('entityAudit.detail.action', { "action": "action" })</strong>
<br /><br />

<del class="diff diff-key" <%= jhiPrefix %>Translate="entityAudit.detail.old">
Old/Removed value
</del>
&nbsp;
<ins class="diff diff-key" <%= jhiPrefix %>Translate="entityAudit.detail.new">
New/Added value
</ins>
<del class="ngx-diff-light-theme">__jhiTranslateTag__('entityAudit.detail.old')</del>
&nbsp;
<ins class="ngx-diff-light-theme">__jhiTranslateTag__('entityAudit.detail.new')</ins>
</div>
<br>
<br />

<label <%= jhiPrefix %>Translate="entityAudit.detail.changedFields">Changed Fields</label>
<inline-diff *ngIf="left && right" class="code" [oldText]="left" [newText]="right" />
<label>__jhiTranslateTag__('entityAudit.detail.changedFields')</label>
<ngx-unified-diff *ngIf="left && right" class="ngx-diff-light-theme" [before]="left" [after]="right" />
</div>
<div class="modal-footer">
<button
data-dismiss="modal" class="btn btn-secondary float-left"
type="button" (click)="activeModal.dismiss('closed')">
Done
</button>
data-dismiss="modal"
class="btn btn-secondary float-left"
type="button"
(click)="activeModal.dismiss('closed')"
>__jhiTranslateTag__('entityAudit.detail.close')</button>
</div>
Original file line number Diff line number Diff line change
@@ -1,66 +1,52 @@
import { Component } from '@angular/core';
import { HttpResponse } from '@angular/common/http';
import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';
import { InlineDiffComponent } from 'ngx-diff';
import { UnifiedDiffComponent } from 'ngx-diff';

import SharedModule from 'app/shared/shared.module';
import { EntityAuditService } from './entity-audit.service';
import { EntityAuditEvent } from './entity-audit-event.model';

@Component({
standalone: true,
selector: '<%= jhiPrefixDashed %>-entity-audit-modal',
templateUrl: './entity-audit-modal.component.html',
imports: [SharedModule, InlineDiffComponent],
styles: [`
/* NOTE: for now the ::ng-deep shadow-piercing descendant combinator is
* required because Angular defaults to emulated view encapsulation and
* preprocesses all component styles to approximate shadow scoping
* rules. This means these styles wouldn't apply to the HTML generated
* by ng-diff-match-patch.
*
* This shouldn't be required when browsers support native
* encapsulation, at which point ::ng-deep will also be deprecated/removed
* see https://angular.io/guide/component-styles
*/

:host ::ng-deep ins {
color: black;
background: #bbffbb;
}

:host ::ng-deep del {
color: black;
background: #ffbbbb;
}

.code {
background: #dcdada;
padding: 10px;
}
`]
standalone: true,
selector: '<%= jhiPrefixDashed %>-entity-audit-modal',
templateUrl: './entity-audit-modal.component.html',
imports: [SharedModule, UnifiedDiffComponent],
styles: [
`
@import 'ngx-diff/styles/default-theme';

ins {
color: black;
background-color: var(--ngx-diff-inserted-background-color);
}

del {
color: black;
background-color: var(--ngx-diff-deleted-background-color);
}
`,
],
})
export default class EntityAuditModalComponent {
action?: string;
left?: string;
right?: string;

constructor(
private service: EntityAuditService,
public activeModal: NgbActiveModal
) {}

openChange(audit: EntityAuditEvent): void {
this.service.getPrevVersion(
audit.entityType, audit.entityId, audit.commitVersion!
).subscribe((res: HttpResponse<EntityAuditEvent>) => {
const data: EntityAuditEvent = res.body!;
const previousVersion = JSON.stringify(JSON.parse(data.entityValue ?? '{}'), null, 2);
const currentVersion = JSON.stringify(audit.entityValue, null, 2);

this.action = audit.action;
this.left = previousVersion;
this.right = currentVersion;
});
}
action?: string;
left?: string;
right?: string;

constructor(
private service: EntityAuditService,
public activeModal: NgbActiveModal,
) {}

openChange(audit: EntityAuditEvent): void {
this.service.getPrevVersion(audit.entityType, audit.entityId, audit.commitVersion!).subscribe((res: HttpResponse<EntityAuditEvent>) => {
const data: EntityAuditEvent = res.body!;
const previousVersion = JSON.stringify(JSON.parse(data.entityValue ?? '{}'), null, 2);
const currentVersion = JSON.stringify(audit.entityValue, null, 2);

this.action = audit.action;
this.left = previousVersion;
this.right = currentVersion;
});
}
}
Loading

0 comments on commit c7acc95

Please sign in to comment.