marioosh.net

mini blog / notes

Reactive Form: previous value

let form = this.fb.group({ ‘hotelLocation’:[null] });   form.get(’hotelLocation’).valueChanges.subscribe(v => {   // HERE !! let prevVal = this.form.value[’hotelLocation’]; });let form = this.fb.group({ ‘hotelLocation’:[null] }); form.get(‘hotelLocation’).valueChanges.subscribe(v => { // HERE !! let prevVal = this.form.value[‘hotelLocation’]; });

@DateTimeFormat usage example

@GetMapping("/find") public Page<ReportProjection> reports( @RequestParam(required = false, name = "status") ReportStatus status, @RequestParam(required = false, name = "search") String search, @DateTimeFormat(pattern="yyyy-MM-dd") @RequestParam(required = false, name = "from") Date from, @DateTimeFormat(pattern="yyyy-MM-dd") @RequestParam(required = false, name = "to") Date to, Pageable pageable) { return reportService.reports(status, search, from, to, pageable); }@GetMapping("/find") public Page<ReportProjection> reports( @RequestParam(required = false, name Read more about @DateTimeFormat usage example[…]

List to Map (streams)

@Getter @Setter class Directory { Long id; String name; }   List<Directory> l = repo.allDirectories();   Map<Long, String> m = l.stream() .collect(Collectors.toMap(d -> d.getId(), d -> d.getName()));@Getter @Setter class Directory { Long id; String name; } List<Directory> l = repo.allDirectories(); Map<Long, String> m = l.stream() .collect(Collectors.toMap(d -> d.getId(), d -> d.getName()));

@PreAuthorize and SpEL params

If @PreAuthorize is used on interface, parameter name (id) in SpEL must match parameter name in implementation (not required on interface – fileId). @Transactional public interface FileService {   @PreAuthorize("@securityService.canAccessFile(#id)") File getFile(Long fileId); }   /** * GOOD */ @Service public class FileServiceImpl implements FileService {   @Override public File getFile(Long id) { /* … Read more about @PreAuthorize and SpEL params[…]

Required @Input

selector: ‘app-test[id]‘ Component({ selector: ‘app-test[id]’ // id is required now }); export class TestComponent { @Input() id:number; }Component({ selector: ‘app-test[id]’ // id is required now }); export class TestComponent { @Input() id:number; }

rx.js – chain requests when need response from BOTH

On the end i need response from BOTH requests, but need chain them, because second request need something from first response. import { switchMap, map } from ‘rxjs/operators’;   this.restService.getFile(id) .pipe( switchMap((file:File) => this.restService.renderMd(file.markdown_id) .pipe(map((markdown:any) => { return { file:file, markdow: markdown }; })) ) ).subscribe((result:any) => { // I have results for two requests Read more about rx.js – chain requests when need response from BOTH[…]

@HostBinding example

import { Component, HostBinding, Input, OnInit } from ‘@angular/core’;   @Component({ selector: ‘app-host’, template: `<p>host works!</p>`, styles: [`:host(.someClass){ color: red; }`] }) export class HostComponent implements OnInit {   @Input(’idVal’) @HostBinding(’id’) id:string = ‘defaultId’; @Input() @HostBinding(’class.someClass’) withClass:boolean = true;   constructor() { }   ngOnInit(): void { }   }import { Component, HostBinding, Input, OnInit Read more about @HostBinding example[…]

updateValueAndValidity();

updateValueAndValidity() works for control, but NOT for children ! form:FormGroup; constructor(private fb:FormBuilder) { }   initForm() { this.form = this.fb.group({ ‘files’:[”, [this.fv.bind(this)]] }); }   /** * my validator */ fv(fc:AbstractControl) { console.log(’validate’, fc); // … }   /** * func that need to revalidate ‘files’ field */ someFunc() { // … this.form.updateValueAndValidity(); // NOT Read more about updateValueAndValidity();[…]

Change commit date

$ git rebase -i HEAD~3   In editor mark commit that need change as ‘edit’ (the second commit in example below)   pick 64b0966 commit message 1… edit 07f540b commit message 2… pick a2b69e4 commit message 3…   # Rebase 50d9975..a2b69e4 onto 50d9975 (3 command(s)) # # Commands: # p, pick = use commit # Read more about Change commit date[…]

Posted in git