-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: allow adding actions to the viewpart action bar
Viewpart actions are added to the viewpart action bar located to the right of the view tabs. If added in the context of a view, the action is local to the containing viewpart and only shown if the view is active. If not in the context of a viewpart, the action is added to every viewpart instead. closes #104
- Loading branch information
1 parent
fdc9218
commit 0b31ca3
Showing
32 changed files
with
505 additions
and
20 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
5 changes: 5 additions & 0 deletions
5
projects/app/workbench/workbench-app/src/app/view-4a3a8932/view-4a3a8932.component.html
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,5 @@ | ||
<ng-template wbViewPartAction align="end"> | ||
<button class="material-icons e2e-button-4a3a8932"> | ||
send | ||
</button> | ||
</ng-template> |
14 changes: 14 additions & 0 deletions
14
projects/app/workbench/workbench-app/src/app/view-4a3a8932/view-4a3a8932.component.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,14 @@ | ||
import { Component } from '@angular/core'; | ||
import { WorkbenchView } from '@scion/workbench'; | ||
|
||
@Component({ | ||
selector: 'app-view-4a3a8932', | ||
templateUrl: './view-4a3a8932.component.html', | ||
}) | ||
export class View4a3a8932Component { | ||
|
||
constructor(view: WorkbenchView) { | ||
view.title = 'Testcase 4a3a8932'; | ||
view.cssClass = 'e2e-view-4a3a8932'; | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/* | ||
* Copyright (c) 2018 Swiss Federal Railways | ||
* | ||
* This program and the accompanying materials are made | ||
* available under the terms of the Eclipse Public License 2.0 | ||
* which is available at https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
*/ | ||
|
||
import { AppPO } from './page-object/app.po'; | ||
import { browser } from 'protractor'; | ||
import { WelcomePagePO } from './page-object/welcome-page.po'; | ||
|
||
describe('ViewPartAction', () => { | ||
|
||
const appPO = new AppPO(); | ||
|
||
beforeEach(async () => { | ||
await browser.get('/'); | ||
}); | ||
|
||
it('should be added to all viewparts', async () => { | ||
const openNewTabActionButtonPO = appPO.findViewPartAction('e2e-open-new-tab'); | ||
|
||
await expect(appPO.isViewTabBarShowing()).toBeTruthy(); | ||
await expect(openNewTabActionButtonPO.isPresent()).toBeTruthy(); | ||
|
||
await browser.get('/#/?show-open-new-view-tab-action=false'); | ||
await expect(appPO.isViewTabBarShowing()).toBeFalsy(); | ||
await expect(openNewTabActionButtonPO.isPresent()).toBeFalsy(); | ||
|
||
await browser.get('/#/?show-open-new-view-tab-action=true'); | ||
await expect(appPO.isViewTabBarShowing()).toBeTruthy(); | ||
await expect(openNewTabActionButtonPO.isPresent()).toBeTruthy(); | ||
}); | ||
|
||
it('should stick to a view if registered in the context of a view [testcase: 4a3a8932]', async () => { | ||
const welcomePagePO = new WelcomePagePO(); | ||
const viewTabPO = appPO.findViewTab('e2e-view-4a3a8932'); | ||
const viewLocalActionButtonPO = appPO.findViewPartAction('e2e-button-4a3a8932'); | ||
|
||
await welcomePagePO.clickTile('e2e-tile-4a3a8932'); | ||
|
||
// Open a view which contributes a view-local action | ||
await expect(viewTabPO.isActive()).toBeTruthy(); | ||
await expect(viewLocalActionButtonPO.isPresent()).toBeTruthy(); | ||
|
||
// Open a new view tab | ||
await appPO.openNewViewTab(); | ||
await expect(viewLocalActionButtonPO.isPresent()).toBeFalsy(); | ||
|
||
// Activate previous view | ||
await viewTabPO.click(); | ||
await expect(viewLocalActionButtonPO.isPresent()).toBeTruthy(); | ||
|
||
// Close the view | ||
await viewTabPO.close(); | ||
await expect(viewTabPO.isPresent()).toBeFalsy(); | ||
await expect(viewLocalActionButtonPO.isPresent()).toBeFalsy(); | ||
}); | ||
}); |
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,51 @@ | ||
/* | ||
* Copyright (c) 2018 Swiss Federal Railways | ||
* | ||
* This program and the accompanying materials are made | ||
* available under the terms of the Eclipse Public License 2.0 | ||
* which is available at https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
*/ | ||
|
||
import { AppPO } from './page-object/app.po'; | ||
import { browser } from 'protractor'; | ||
import { WelcomePagePO } from './page-object/welcome-page.po'; | ||
|
||
describe('ViewTabBar', () => { | ||
|
||
const appPO = new AppPO(); | ||
const welcomePagePO = new WelcomePagePO(); | ||
|
||
beforeEach(async () => { | ||
await browser.get('/'); | ||
}); | ||
|
||
it('should not show if no views are open and no viewpart actions present', async () => { | ||
await browser.get('/#/?show-open-new-view-tab-action=false'); | ||
|
||
await expect(appPO.getViewTabCount()).toEqual(0); | ||
await expect(appPO.isViewTabBarShowing()).toBeFalsy(); | ||
|
||
await welcomePagePO.clickTile('e2e-tile-view-1'); | ||
await expect(appPO.getViewTabCount()).toEqual(1); | ||
await expect(appPO.isViewTabBarShowing()).toBeTruthy(); | ||
|
||
await appPO.findViewTab('e2e-tile-view-1').close(); | ||
await expect(appPO.getViewTabCount()).toEqual(0); | ||
await expect(appPO.isViewTabBarShowing()).toBeFalsy(); | ||
|
||
await browser.get('/#/?show-open-new-view-tab-action=true'); | ||
|
||
await expect(appPO.getViewTabCount()).toEqual(0); | ||
await expect(appPO.isViewTabBarShowing()).toBeTruthy(); | ||
|
||
await welcomePagePO.clickTile('e2e-tile-view-1'); | ||
await expect(appPO.getViewTabCount()).toEqual(1); | ||
await expect(appPO.isViewTabBarShowing()).toBeTruthy(); | ||
|
||
await appPO.findViewTab('e2e-tile-view-1').close(); | ||
await expect(appPO.getViewTabCount()).toEqual(0); | ||
await expect(appPO.isViewTabBarShowing()).toBeTruthy(); | ||
}); | ||
}); |
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,36 @@ | ||
/* | ||
* Copyright (c) 2018 Swiss Federal Railways | ||
* | ||
* This program and the accompanying materials are made | ||
* available under the terms of the Eclipse Public License 2.0 | ||
* which is available at https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
*/ | ||
|
||
import { AppPO } from './page-object/app.po'; | ||
import { browser } from 'protractor'; | ||
import { expectViewToShow } from './util/testing.util'; | ||
|
||
describe('Workbench', () => { | ||
|
||
const appPO = new AppPO(); | ||
|
||
beforeEach(async () => { | ||
await browser.get('/'); | ||
}); | ||
|
||
it('should allow to always have an entry view open', async () => { | ||
await browser.get('/#/?ensure-welcome-view=true'); | ||
|
||
await expect(appPO.getViewTabCount()).toEqual(1); | ||
await expect(appPO.isViewTabBarShowing()).toBeTruthy(); | ||
await expectViewToShow({viewCssClass: 'e2e-welcome-page', componentSelector: 'app-welcome-page'}); | ||
|
||
// close the view | ||
await appPO.findViewTab('e2e-welcome-page').close(); | ||
await expect(appPO.getViewTabCount()).toEqual(1); | ||
await expect(appPO.isViewTabBarShowing()).toBeTruthy(); | ||
await expectViewToShow({viewCssClass: 'e2e-welcome-page', componentSelector: 'app-welcome-page'}); | ||
}); | ||
}); |
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 |
---|---|---|
|
@@ -59,5 +59,5 @@ $size: 14px; | |
} | ||
|
||
:host-context:not(.visible) { | ||
visibility: hidden; | ||
display: none; | ||
} |
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
19 changes: 19 additions & 0 deletions
19
...cion/workbench/src/lib/view-part/view-part-action-bar/view-part-action-bar.component.html
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,19 @@ | ||
<ul class="e2e-view-actions start"> | ||
<li *ngFor="let action of startActions$ | async"> | ||
<ng-container *ngTemplateOutlet="action_template; context: {$implicit: action}"></ng-container> | ||
</li> | ||
</ul> | ||
<ul class="e2e-view-actions end"> | ||
<li *ngFor="let action of endActions$ | async"> | ||
<ng-container *ngTemplateOutlet="action_template; context: {$implicit: action}"></ng-container> | ||
</li> | ||
</ul> | ||
|
||
<ng-template #action_template let-action> | ||
<ng-container *ngIf="isTemplate(action)"> | ||
<ng-container *ngTemplateOutlet="action.templateOrComponent"></ng-container> | ||
</ng-container> | ||
<ng-container *ngIf="!isTemplate(action)"> | ||
<ng-container *ngComponentOutlet="action.templateOrComponent.component; injector: addViewPartToInjector(action.templateOrComponent.injector)"></ng-container> | ||
</ng-container> | ||
</ng-template> |
19 changes: 19 additions & 0 deletions
19
...cion/workbench/src/lib/view-part/view-part-action-bar/view-part-action-bar.component.scss
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,19 @@ | ||
:host { | ||
display: flex; | ||
align-items: center; | ||
justify-content: space-between; | ||
margin: 0 1em 0 1em; | ||
|
||
> ul { | ||
display: flex; | ||
flex-direction: row; | ||
align-items: center; | ||
list-style: none; | ||
margin: 0; | ||
padding: 0; | ||
|
||
> li { | ||
flex: none; | ||
} | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
.../scion/workbench/src/lib/view-part/view-part-action-bar/view-part-action-bar.component.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,53 @@ | ||
/* | ||
* Copyright (c) 2018 Swiss Federal Railways | ||
* | ||
* This program and the accompanying materials are made | ||
* available under the terms of the Eclipse Public License 2.0 | ||
* which is available at https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
*/ | ||
|
||
import { ChangeDetectionStrategy, Component, Injector, TemplateRef } from '@angular/core'; | ||
import { WorkbenchViewPartService } from '../workbench-view-part.service'; | ||
import { combineLatest, Observable, OperatorFunction } from 'rxjs'; | ||
import { map } from 'rxjs/operators'; | ||
import { WorkbenchViewPart, WorkbenchViewPartAction } from '../../workbench.model'; | ||
import { InternalWorkbenchService } from '../../workbench.service'; | ||
import { PortalInjector } from '@angular/cdk/portal'; | ||
|
||
@Component({ | ||
selector: 'wb-view-part-action-bar', | ||
templateUrl: './view-part-action-bar.component.html', | ||
styleUrls: ['./view-part-action-bar.component.scss'], | ||
changeDetection: ChangeDetectionStrategy.OnPush, | ||
}) | ||
export class ViewPartActionBarComponent { | ||
|
||
public startActions$: Observable<WorkbenchViewPartAction[]>; | ||
public endActions$: Observable<WorkbenchViewPartAction[]>; | ||
|
||
constructor(private _viewPart: WorkbenchViewPart, workbenchService: InternalWorkbenchService, viewPartService: WorkbenchViewPartService) { | ||
this.startActions$ = combineLatest(this._viewPart.actions$, workbenchService.viewPartActions$, viewPartService.activeViewRef$).pipe(combineAndFilterViewPartActions('start')); | ||
this.endActions$ = combineLatest(this._viewPart.actions$, workbenchService.viewPartActions$, viewPartService.activeViewRef$).pipe(combineAndFilterViewPartActions('end')); | ||
} | ||
|
||
public isTemplate(action: WorkbenchViewPartAction): boolean { | ||
return action.templateOrComponent instanceof TemplateRef; | ||
} | ||
|
||
public addViewPartToInjector(injector: Injector): Injector { | ||
const injectionTokens = new WeakMap(); | ||
injectionTokens.set(WorkbenchViewPart, this._viewPart); | ||
return new PortalInjector(injector, injectionTokens); | ||
} | ||
} | ||
|
||
function combineAndFilterViewPartActions(align: 'start' | 'end'): OperatorFunction<[WorkbenchViewPartAction[], WorkbenchViewPartAction[], string], WorkbenchViewPartAction[]> { | ||
return map(([localActions, globalActions, activeViewRef]: [WorkbenchViewPartAction[], WorkbenchViewPartAction[], string]): WorkbenchViewPartAction[] => { | ||
return [...localActions, ...globalActions] | ||
.filter(action => (action.align || 'start') === align) | ||
.filter(action => !action.viewRef || action.viewRef === activeViewRef); | ||
} | ||
); | ||
} |
Oops, something went wrong.