Adjustements everywhere
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { Component, Input, OnInit } from '@angular/core';
|
||||
import { Component, Input, OnInit, Output, EventEmitter } from '@angular/core';
|
||||
import { FormGroup } from '@angular/forms';
|
||||
import { FormlyFieldConfig } from '@ngx-formly/core'
|
||||
import { ActivatedRoute, Router } from '@angular/router';
|
||||
@@ -19,6 +19,12 @@ export interface Model {
|
||||
export class CardComponent implements OnInit {
|
||||
@Input() resource: string | undefined;
|
||||
@Input() resource_id: string | null = null;
|
||||
@Input() is_modal: Boolean = false;
|
||||
|
||||
@Output() resourceCreated: EventEmitter<string> = new EventEmitter();
|
||||
@Output() resourceDeleted: EventEmitter<string> = new EventEmitter();
|
||||
|
||||
|
||||
form = new FormGroup({});
|
||||
model = {};
|
||||
fields: FormlyFieldConfig[] = [];
|
||||
@@ -60,7 +66,11 @@ export class CardComponent implements OnInit {
|
||||
if (this.isCreateForm()) {
|
||||
this.crudService.create(this.resource!, model).subscribe((response: any) => {
|
||||
this._loading$.next(false);
|
||||
this.router.navigate([`../${response.id}`], {relativeTo: this.route});
|
||||
if (! this.is_modal) {
|
||||
this.router.navigate([`../${response.id}`], {relativeTo: this.route});
|
||||
} else {
|
||||
this.resourceCreated.emit(response.id)
|
||||
}
|
||||
});
|
||||
} else {
|
||||
this.crudService.update(this.resource!, model).subscribe((model: any) => {
|
||||
@@ -74,7 +84,11 @@ export class CardComponent implements OnInit {
|
||||
this._loading$.next(true);
|
||||
this.crudService.delete(this.resource!, this.model).subscribe((model: any) => {
|
||||
this._loading$.next(false);
|
||||
this.router.navigate(['../'], {relativeTo: this.route});
|
||||
if (! this.is_modal) {
|
||||
this.router.navigate(['../'], {relativeTo: this.route});
|
||||
} else {
|
||||
this.resourceDeleted.emit("")
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user