- ng g component form/create
- Add the following code
Created
October 14, 2019 19:36
-
-
Save travist/f35298a8a807750df7d88eeea2fe5998 to your computer and use it in GitHub Desktop.
Add Submission Access to Form Manager
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Component, OnInit, ChangeDetectorRef } from '@angular/core'; | |
import { FormioAlerts } from 'angular-formio'; | |
import { FormioAuthService } from 'angular-formio/auth'; | |
import { FormManagerService, FormManagerEditComponent, FormManagerConfig } from 'angular-formio/manager'; | |
import { Router, ActivatedRoute } from '@angular/router'; | |
@Component({ | |
selector: 'app-create', | |
templateUrl: './create.component.html', | |
styleUrls: ['./create.component.scss'] | |
}) | |
export class CreateComponent extends FormManagerEditComponent implements OnInit { | |
constructor( | |
public service: FormManagerService, | |
public router: Router, | |
public route: ActivatedRoute, | |
public config: FormManagerConfig, | |
public ref: ChangeDetectorRef, | |
public alerts: FormioAlerts, | |
public auth: FormioAuthService | |
) { | |
super(service, router, route, config, ref, alerts); | |
auth.accessReady.then((access) => { | |
let authRole = null; | |
for (const name in access.roles) { | |
if (name === 'authenticated') { | |
authRole = access.roles[name]; | |
break; | |
} | |
} | |
this.form.submissionAccess = [ | |
{ | |
type: 'create_all', | |
roles: [authRole._id] | |
}, | |
{ | |
type: 'read_all', | |
roles: [authRole._id] | |
} | |
]; | |
}); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { NgModule } from '@angular/core'; | |
import { CommonModule } from '@angular/common'; | |
import { RouterModule } from '@angular/router'; | |
import { FormioGrid } from 'angular-formio/grid'; | |
import { FormioModule } from 'angular-formio'; | |
import { FormManagerModule, FormManagerRoutes, FormManagerService, FormManagerConfig } from 'angular-formio/manager'; | |
import { CreateComponent } from './create/create.component'; | |
@NgModule({ | |
imports: [ | |
CommonModule, | |
FormioGrid, | |
FormioModule, | |
FormManagerModule, | |
RouterModule.forChild(FormManagerRoutes({ | |
formCreate: CreateComponent | |
})) | |
], | |
declarations: [ | |
CreateComponent | |
], | |
providers: [ | |
FormManagerService, | |
{provide: FormManagerConfig, useValue: { | |
tag: 'common' | |
}} | |
] | |
}) | |
export class FormModule { } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment