]> git.apps.os.sepia.ceph.com Git - ceph.git/blob
4545f2ba8a8a8a8c25ea377770749c8dfdd34b6b
[ceph.git] /
1 import { Component, OnInit } from '@angular/core';
2 import { ActivatedRoute } from '@angular/router';
3 import { DataGatewayService } from '~/app/shared/services/data-gateway.service';
4 import { BackButtonComponent } from '~/app/shared/components/back-button/back-button.component';
5 import { TaskWrapperService } from '~/app/shared/services/task-wrapper.service';
6 import { FinishedTask } from '~/app/shared/models/finished-task';
7 import { Location } from '@angular/common';
8
9 @Component({
10   selector: 'cd-crud-form',
11   templateUrl: './crud-form.component.html',
12   styleUrls: ['./crud-form.component.scss']
13 })
14 export class CrudFormComponent implements OnInit {
15   uiSchema: any;
16   controlSchema: any;
17   data: any;
18   widgets: any = {
19     cancel: BackButtonComponent
20   };
21   resource: string;
22   title: string;
23
24   formOptions = {
25     defautWidgetOptions: {
26       validationMessages: {
27         required: 'This field is required'
28       }
29     }
30   };
31   constructor(
32     private dataGatewayService: DataGatewayService,
33     private activatedRoute: ActivatedRoute,
34     private taskWrapper: TaskWrapperService,
35     private location: Location
36   ) {}
37
38   ngOnInit(): void {
39     this.activatedRoute.data.subscribe((data: any) => {
40       this.resource = data.resource;
41       this.dataGatewayService.list(`ui-${this.resource}`).subscribe((response: any) => {
42         this.title = response.forms[0].control_schema.title;
43         this.uiSchema = response.forms[0].ui_schema;
44         this.controlSchema = response.forms[0].control_schema;
45       });
46     });
47   }
48
49   submit(data: any) {
50     if (data) {
51       this.taskWrapper
52         .wrapTaskAroundCall({
53           task: new FinishedTask('ceph-user/create', {
54             user_entity: data.user_entity
55           }),
56           call: this.dataGatewayService.create(this.resource, data)
57         })
58         .subscribe({
59           complete: () => {
60             this.location.back();
61           }
62         });
63     }
64   }
65 }