-
-
Notifications
You must be signed in to change notification settings - Fork 931
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(admin-ui): Enable removal of Product from Channel
Relates to #12
- Loading branch information
1 parent
b295e52
commit 27eea68
Showing
10 changed files
with
156 additions
and
18 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 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 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 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 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
41 changes: 41 additions & 0 deletions
41
packages/admin-ui/src/app/shared/directives/if-default-channel-active.directive.ts
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,41 @@ | ||
import { ChangeDetectorRef, Directive, Input, TemplateRef, ViewContainerRef } from '@angular/core'; | ||
import { tap } from 'rxjs/operators'; | ||
import { DEFAULT_CHANNEL_CODE } from 'shared/shared-constants'; | ||
|
||
import { UserStatus } from '../../common/generated-types'; | ||
import { DataService } from '../../data/providers/data.service'; | ||
|
||
import { IfDirectiveBase } from './if-directive-base'; | ||
|
||
@Directive({ | ||
selector: '[vdrIfDefaultChannelActive]', | ||
}) | ||
export class IfDefaultChannelActiveDirective extends IfDirectiveBase<[]> { | ||
constructor( | ||
_viewContainer: ViewContainerRef, | ||
templateRef: TemplateRef<any>, | ||
private dataService: DataService, | ||
private changeDetectorRef: ChangeDetectorRef, | ||
) { | ||
super(_viewContainer, templateRef, () => { | ||
return this.dataService.client | ||
.userStatus() | ||
.mapStream(({ userStatus }) => this.defaultChannelIsActive(userStatus)) | ||
.pipe(tap(() => this.changeDetectorRef.markForCheck())); | ||
}); | ||
} | ||
|
||
/** | ||
* A template to show if the current user does not have the speicified permission. | ||
*/ | ||
@Input() | ||
set vdrIfMultichannelElse(templateRef: TemplateRef<any> | null) { | ||
this.setElseTemplate(templateRef); | ||
} | ||
|
||
private defaultChannelIsActive(userStatus: UserStatus): boolean { | ||
const defaultChannel = userStatus.channels.find(c => c.code === DEFAULT_CHANNEL_CODE); | ||
|
||
return !!(defaultChannel && userStatus.activeChannelId === defaultChannel.id); | ||
} | ||
} |
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 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 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 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