-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c584686
commit 60287d4
Showing
3 changed files
with
50 additions
and
4 deletions.
There are no files selected for viewing
This file contains 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
This file was deleted.
Oops, something went wrong.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/** | ||
* Created by Mohammad.hajiaghazadeh on 8/13/2018 | ||
*/ | ||
import {Injectable} from "@angular/core"; | ||
import {ActivatedRouteSnapshot, Resolve} from "@angular/router"; | ||
import {Observable} from "rxjs/Rx"; | ||
import {HttpClient} from "@angular/common/http"; | ||
|
||
@Injectable() | ||
export class FormLoaderService implements Resolve<Observable<any>> { | ||
private JSON_DIR = '/assets/forms/'; | ||
|
||
constructor(private httpClient: HttpClient) { | ||
|
||
} | ||
|
||
/** | ||
* load form from forms directory | ||
* @param form | ||
* @returns {Observable<Object>} | ||
*/ | ||
load(form) { | ||
return this.httpClient.get(`${this.JSON_DIR}${form.path}.form.schema.json`); | ||
} | ||
|
||
/** | ||
* load forms based on form config | ||
* @param route | ||
* @returns {any} | ||
*/ | ||
loadForms(route): any { | ||
return Object.keys(route.data.forms).forEach((formKey) => { | ||
route.data.forms[formKey].schema = this.load(route.data.forms[formKey]); | ||
// .subscribe(res => { | ||
// }); | ||
}); | ||
} | ||
|
||
/** | ||
* resolve forms | ||
* @param {ActivatedRouteSnapshot} route | ||
* @returns {any} | ||
*/ | ||
resolve(route: ActivatedRouteSnapshot) { | ||
return this.loadForms(route); | ||
} | ||
} |