-
Notifications
You must be signed in to change notification settings - Fork 12k
feat(@schematics/angular): Added multiselect guard implements option #13109
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,24 @@ | ||
import { Injectable } from '@angular/core'; | ||
import { CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot, UrlTree } from '@angular/router'; | ||
import { <%= implementationImports %>ActivatedRouteSnapshot, RouterStateSnapshot, UrlTree } from '@angular/router'; | ||
import { Observable } from 'rxjs'; | ||
|
||
@Injectable({ | ||
providedIn: 'root' | ||
}) | ||
export class <%= classify(name) %>Guard implements CanActivate { | ||
canActivate( | ||
export class <%= classify(name) %>Guard implements <%= implementations %> { | ||
<% if (implements.includes('CanActivate')) { %>canActivate( | ||
next: ActivatedRouteSnapshot, | ||
state: RouterStateSnapshot): Observable<boolean | UrlTree> | Promise<boolean | UrlTree> | boolean | UrlTree { | ||
return true; | ||
} | ||
<% } %><% if (implements.includes('CanActivateChild')) { %>canActivateChild( | ||
next: ActivatedRouteSnapshot, | ||
state: RouterStateSnapshot): Observable<boolean | UrlTree> | Promise<boolean | UrlTree> | boolean | UrlTree { | ||
return true; | ||
} | ||
<% } %><% if (implements.includes('CanLoad')) { %>canLoad( | ||
route: Route, | ||
segments: UrlSegment[]): Observable<boolean> | Promise<boolean> | boolean { | ||
return true; | ||
}<% } %> | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,6 +47,24 @@ | |
"type": "boolean", | ||
"default": false, | ||
"description": "When true, applies lint fixes after generating the guard." | ||
}, | ||
"implements": { | ||
"type": "array", | ||
clydin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"description": "Specifies which interfaces to implement.", | ||
"uniqueItems": true, | ||
"items": { | ||
"type": "string" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This looks like an There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @hansl If I change this to
I realized that the way this is being used the items could be updated to just a list of strings, thank you for pointing that out. Let me know what you think! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should be something like; "implements": {
"type": "array",
"description": "Specifies which interfaces to implement.",
"default": "CanActivate",
"enum": [
"CanActivate",
"CanActivateChild",
"CanLoad"
]
....
},
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @alan-agius4 I'm sorry I could be totally missing something (my first time working with json schema 😬), but the x prompt logic requires this array to be named as Are you saying in addition to the x-prompt defintion, also include the Thanks for your help btw! Just trying to learn and make sure I understand. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not really, I think it should be something like;
The There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note: updated the above is I spotted a mistake There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note also that I have a followup planned to add auto-configuration of multi-select based on the schema. It will eliminate the need to manually specify most of the prompt options and is the reason I originally suggested just using a string constraint for now (this schema would be adjusted in the process either way). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. in that case, it LGTM There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @clydin would I be able to help out with the implementation of the multi select auto configuration?? I’d love to keep learning and contributing and this could transition well from the work I’ve done so far. Let me know what you think and thanks everyone for the help so far! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @clydin @okeefem2 @alan-agius4 For info, the decision made here causes issues like this one: cyrilletuzi/vscode-angular-schematics#32. The x-prompts is a specific use of the schema, the classic schema properties should be respected for other tools to work (ie. possible values must be in |
||
}, | ||
"x-prompt": { | ||
"message": "Which interfaces would you like to implement?", | ||
"type": "list", | ||
"multiselect": true, | ||
"items": [ | ||
"CanActivate", | ||
"CanActivateChild", | ||
"CanLoad" | ||
] | ||
} | ||
} | ||
}, | ||
"required": [ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can eventually use the enum type here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@alan-agius4 Are you saying to create an enum for the values instead of comparing hard coded strings? If yes would this live in the index.ts file or should it have it’s own file?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi, the enum is created from the json schema, you don't need to redefine it.
You can run
yarn build
it will generate an new schema with the enum you created in the json schema.So you can import it like such
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh very cool. I will make these changes later today when I get home. Thanks!