mirror of
				https://github.com/paperless-ngx/paperless-ngx.git
				synced 2025-10-30 03:56:23 -05:00 
			
		
		
		
	fixed date editing, fixes #10
This commit is contained in:
		| @@ -38,6 +38,7 @@ import { SelectComponent } from './components/common/input/select/select.compone | ||||
| import { CheckComponent } from './components/common/input/check/check.component'; | ||||
| import { SaveViewConfigDialogComponent } from './components/document-list/save-view-config-dialog/save-view-config-dialog.component'; | ||||
| import { InfiniteScrollModule } from 'ngx-infinite-scroll'; | ||||
| import { DateTimeComponent } from './components/common/input/date-time/date-time.component'; | ||||
|  | ||||
| @NgModule({ | ||||
|   declarations: [ | ||||
| @@ -69,7 +70,8 @@ import { InfiniteScrollModule } from 'ngx-infinite-scroll'; | ||||
|     TextComponent, | ||||
|     SelectComponent, | ||||
|     CheckComponent, | ||||
|     SaveViewConfigDialogComponent | ||||
|     SaveViewConfigDialogComponent, | ||||
|     DateTimeComponent | ||||
|   ], | ||||
|   imports: [ | ||||
|     BrowserModule, | ||||
|   | ||||
| @@ -0,0 +1,14 @@ | ||||
| <div class="form-row"> | ||||
|   <div class="form-group col"> | ||||
|       <label for="created_date">{{titleDate}}</label> | ||||
|       <input type="date" class="form-control" id="created_date" [(ngModel)]="dateValue" (change)="dateOrTimeChanged()"> | ||||
|   </div> | ||||
|   <div class="form-group col"> | ||||
|       <label for="created_time">{{titleTime}}</label> | ||||
|       <input type="time" class="form-control" id="created_time" [(ngModel)]="timeValue" (change)="dateOrTimeChanged()"> | ||||
|   </div> | ||||
|  | ||||
| </div> | ||||
|  | ||||
|  | ||||
| <!-- <small *ngIf="hint" class="form-text text-muted">{{hint}}</small> --> | ||||
| @@ -0,0 +1,25 @@ | ||||
| import { ComponentFixture, TestBed } from '@angular/core/testing'; | ||||
|  | ||||
| import { DateTimeComponent } from './date-time.component'; | ||||
|  | ||||
| describe('DateTimeComponent', () => { | ||||
|   let component: DateTimeComponent; | ||||
|   let fixture: ComponentFixture<DateTimeComponent>; | ||||
|  | ||||
|   beforeEach(async () => { | ||||
|     await TestBed.configureTestingModule({ | ||||
|       declarations: [ DateTimeComponent ] | ||||
|     }) | ||||
|     .compileComponents(); | ||||
|   }); | ||||
|  | ||||
|   beforeEach(() => { | ||||
|     fixture = TestBed.createComponent(DateTimeComponent); | ||||
|     component = fixture.componentInstance; | ||||
|     fixture.detectChanges(); | ||||
|   }); | ||||
|  | ||||
|   it('should create', () => { | ||||
|     expect(component).toBeTruthy(); | ||||
|   }); | ||||
| }); | ||||
| @@ -0,0 +1,62 @@ | ||||
| import { formatDate } from '@angular/common'; | ||||
| import { Component, forwardRef, Input, OnInit } from '@angular/core'; | ||||
| import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms'; | ||||
| import { AbstractInputComponent } from '../abstract-input'; | ||||
|  | ||||
| @Component({ | ||||
|   providers: [{ | ||||
|     provide: NG_VALUE_ACCESSOR, | ||||
|     useExisting: forwardRef(() => DateTimeComponent), | ||||
|     multi: true | ||||
|   }], | ||||
|   selector: 'app-input-date-time', | ||||
|   templateUrl: './date-time.component.html', | ||||
|   styleUrls: ['./date-time.component.css'] | ||||
| }) | ||||
| export class DateTimeComponent implements OnInit,ControlValueAccessor  { | ||||
|  | ||||
|   constructor() { | ||||
|   } | ||||
|  | ||||
|   onChange = (newValue: any) => {}; | ||||
|    | ||||
|   onTouched = () => {}; | ||||
|  | ||||
|   writeValue(newValue: any): void { | ||||
|     this.dateValue = formatDate(newValue, 'yyyy-MM-dd', "en-US") | ||||
|     this.timeValue = formatDate(newValue, 'HH:mm:ss', 'en-US') | ||||
|   } | ||||
|   registerOnChange(fn: any): void { | ||||
|     this.onChange = fn; | ||||
|   } | ||||
|   registerOnTouched(fn: any): void { | ||||
|     this.onTouched = fn; | ||||
|   } | ||||
|   setDisabledState?(isDisabled: boolean): void { | ||||
|     this.disabled = isDisabled; | ||||
|   } | ||||
|  | ||||
|   @Input() | ||||
|   titleDate: string = "Date" | ||||
|  | ||||
|   @Input() | ||||
|   titleTime: string = "Time" | ||||
|  | ||||
|   @Input() | ||||
|   disabled: boolean = false | ||||
|  | ||||
|   @Input() | ||||
|   hint: string | ||||
|  | ||||
|   timeValue | ||||
|  | ||||
|   dateValue | ||||
|  | ||||
|   ngOnInit(): void { | ||||
|   } | ||||
|  | ||||
|   dateOrTimeChanged() { | ||||
|     this.onChange(formatDate(this.dateValue + "T" + this.timeValue,"yyyy-MM-ddTHH:mm:ssZZZZZ", "en-us", "UTC")) | ||||
|   } | ||||
|  | ||||
| } | ||||
| @@ -32,16 +32,7 @@ | ||||
|                     formControlName='archive_serial_number'> | ||||
|             </div> | ||||
|              | ||||
|             <div class="form-row"> | ||||
|                 <div class="form-group col"> | ||||
|                     <label for="created_date">Date created</label> | ||||
|                     <input type="date" class="form-control" id="created_date" formControlName='created_date'> | ||||
|                 </div> | ||||
|                 <div class="form-group col"> | ||||
|                     <label for="created_time">Time created</label> | ||||
|                     <input type="time" class="form-control" id="created_time" formControlName='created_time'> | ||||
|                 </div> | ||||
|             </div> | ||||
|             <app-input-date-time title="Date created" titleTime="Time created" formControlName="created"></app-input-date-time> | ||||
|              | ||||
|             <div class="form-group"> | ||||
|                 <label for="content">Content</label> | ||||
|   | ||||
| @@ -38,8 +38,7 @@ export class DocumentDetailComponent implements OnInit { | ||||
|   documentForm: FormGroup = new FormGroup({ | ||||
|     title: new FormControl(''), | ||||
|     content: new FormControl(''), | ||||
|     created_date: new FormControl(), | ||||
|     created_time: new FormControl(), | ||||
|     created: new FormControl(), | ||||
|     correspondent_id: new FormControl(), | ||||
|     document_type_id: new FormControl(), | ||||
|     archive_serial_number: new FormControl(), | ||||
| @@ -59,6 +58,10 @@ export class DocumentDetailComponent implements OnInit { | ||||
|     private documentListViewService: DocumentListViewService) { } | ||||
|  | ||||
|   ngOnInit(): void { | ||||
|     this.documentForm.valueChanges.subscribe(wow => { | ||||
|       Object.assign(this.document, this.documentForm.value) | ||||
|     }) | ||||
|  | ||||
|     this.correspondentService.list(1,100000).subscribe(result => this.correspondents = result.results) | ||||
|     this.documentTypeService.list(1,100000).subscribe(result => this.documentTypes = result.results) | ||||
|     this.tagService.list(1,100000).subscribe(result => this.tags = result.results) | ||||
| @@ -67,16 +70,22 @@ export class DocumentDetailComponent implements OnInit { | ||||
|       this.documentId = +paramMap.get('id') | ||||
|       this.previewUrl = this.documentsService.getPreviewUrl(this.documentId) | ||||
|       this.downloadUrl = this.documentsService.getDownloadUrl(this.documentId) | ||||
|       if (this.openDocumentService.getOpenDocument(this.documentId)) { | ||||
|         this.updateComponent(this.openDocumentService.getOpenDocument(this.documentId)) | ||||
|       } else { | ||||
|         this.documentsService.get(this.documentId).subscribe(doc => { | ||||
|           this.openDocumentService.openDocument(doc) | ||||
|           this.updateComponent(doc) | ||||
|         }, error => {this.router.navigate(['404'])}) | ||||
|       } | ||||
|     }) | ||||
|  | ||||
|   } | ||||
|  | ||||
|   updateComponent(doc: PaperlessDocument) { | ||||
|     this.document = doc | ||||
|     this.title = doc.title | ||||
|     this.documentForm.patchValue(doc) | ||||
|         this.documentForm.get('created_date').patchValue(this.datePipe.transform(doc.created, 'yyyy-MM-dd')) | ||||
|         this.documentForm.get('created_time').patchValue(this.datePipe.transform(doc.created, 'HH:mm:ss')) | ||||
|       }, error => {this.router.navigate(['404'])}) | ||||
|     }) | ||||
|  | ||||
|   } | ||||
|  | ||||
|   createTag() { | ||||
| @@ -133,29 +142,15 @@ export class DocumentDetailComponent implements OnInit { | ||||
|     } | ||||
|   } | ||||
|  | ||||
|   getDateCreated() { | ||||
|     let newDate = this.documentForm.value.created_date | ||||
|     let newTime = this.documentForm.value.created_time | ||||
|     return formatDate(newDate + "T" + newTime,"yyyy-MM-ddTHH:mm:ssZZZZZ", "en-us", "UTC") | ||||
|      | ||||
|   } | ||||
|  | ||||
|   save() {     | ||||
|     let newDocument = Object.assign(Object.assign({}, this.document), this.documentForm.value) | ||||
|  | ||||
|     newDocument.created = this.getDateCreated() | ||||
|      | ||||
|     this.documentsService.update(newDocument).subscribe(result => { | ||||
|     this.documentsService.update(this.document).subscribe(result => { | ||||
|       this.close() | ||||
|     }) | ||||
|   } | ||||
|  | ||||
|   saveEditNext() { | ||||
|     let newDocument = Object.assign(Object.assign({}, this.document), this.documentForm.value) | ||||
|  | ||||
|     newDocument.created = this.getDateCreated() | ||||
|  | ||||
|     this.documentsService.update(newDocument).subscribe(result => { | ||||
|     this.documentsService.update(this.document).subscribe(result => { | ||||
|       this.documentListViewService.getNext(this.document.id).subscribe(nextDocId => { | ||||
|         if (nextDocId) { | ||||
|           this.openDocumentService.closeDocument(this.document) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Jonas Winkler
					Jonas Winkler