code improvements

This commit is contained in:
VLE2FE
2020-09-03 15:51:53 +02:00
parent 1440e9a6fc
commit c38d0be457
73 changed files with 276 additions and 1686 deletions

View File

@ -1,4 +1,3 @@
<div class="header">
<rb-form-date-input name="dateInput" label="older than" [options]="{enableTime: true}"
[(ngModel)]="timestamp" (ngModelChange)="loadChangelog()">

View File

@ -1,51 +1,5 @@
// import { async, ComponentFixture, TestBed } from '@angular/core/testing';
//
// import { ChangelogComponent } from './changelog.component';
// import {ApiService} from '../services/api.service';
// import {ModalService, RbUiComponentsModule} from '@inst-iot/bosch-angular-ui-components';
// import {FormsModule} from '@angular/forms';
// import {ValidationService} from '../services/validation.service';
// import {DataService} from '../services/data.service';
// import {RbCustomInputsModule} from '../rb-custom-inputs/rb-custom-inputs.module';
//
// // TODO
//
// let apiServiceSpy: jasmine.SpyObj<ApiService>;
// let modalServiceSpy: jasmine.SpyObj<ModalService>;
//
// describe('ChangelogComponent', () => {
// let component: ChangelogComponent;
// let fixture: ComponentFixture<ChangelogComponent>;
//
// beforeEach(async(() => {
// const apiSpy = jasmine.createSpyObj('ApiService', ['get']);
// const modalSpy = jasmine.createSpyObj('ModalService', ['open']);
//
// TestBed.configureTestingModule({
// declarations: [ ChangelogComponent ],
// imports: [
// RbUiComponentsModule,
// RbCustomInputsModule
// ],
// providers: [
// {provide: ApiService, useValue: apiSpy},
// {provide: ModalService, useValue: modalSpy}
// ]
// })
// .compileComponents();
//
// apiServiceSpy = TestBed.inject(ApiService) as jasmine.SpyObj<ApiService>;
// modalServiceSpy = TestBed.inject(ModalService) as jasmine.SpyObj<ModalService>;
// }));
//
// beforeEach(() => {
// fixture = TestBed.createComponent(ChangelogComponent);
// component = fixture.componentInstance;
// component.ngOnInit();
// fixture.detectChanges();
// });
//
// it('should create', () => {
// expect(component).toBeTruthy();
// });
// });
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
describe('ChangelogComponent', () => {
});

View File

@ -10,10 +10,10 @@ import {ModalService} from '@inst-iot/bosch-angular-ui-components';
})
export class ChangelogComponent implements OnInit {
timestamp = new Date();
timestamp = new Date(); // time from date input
pageSize = 25;
changelog: ChangelogModel[] = [];
modalDetail = 0;
modalDetail = 0; // index of changelog element to show details of
constructor(
private api: ApiService,
@ -24,7 +24,7 @@ export class ChangelogComponent implements OnInit {
this.loadChangelog();
}
loadChangelog(page = 0) {
loadChangelog(page = 0) { // load changelog with page no relative to current page
this.api.get<ChangelogModel[]>(`/changelog/${
page > 0 ? this.changelog[0]._id : // use id if no new date was given
Math.floor(new Date(
@ -32,12 +32,13 @@ export class ChangelogComponent implements OnInit {
).getTime() / 1000).toString(16) + '0000000000000000' // id from time
}/${page}/${this.pageSize}`, data => {
this.changelog = data.map(e => new ChangelogModel().deserialize(e));
if (page) {
if (page) { // adjust date picker to new first element when user clicked on next page
this.timestamp = new Date(this.changelog[0].date);
}
});
}
// show details of a changelog element with reference to needed modal
showDetails(i: number, modal: TemplateRef<any>) {
this.modalDetail = i;
this.modal.open(modal).then(() => {});