Skip to content

Commit

Permalink
feat: hide activity part if no activities are registered
Browse files Browse the repository at this point in the history
closes #107
  • Loading branch information
danielwiehl committed Mar 13, 2019
1 parent 2360f4b commit fb43cf6
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
*/

import { Injectable } from '@angular/core';
import { ApplicationManifest, HOST_APPLICATION_SYMBOLIC_NAME, ApplicationConfig } from './metadata';
import { ApplicationConfig, ApplicationManifest, HOST_APPLICATION_SYMBOLIC_NAME } from './metadata';
import { Defined } from './defined.util';
import { ManifestRegistry } from './manifest-registry.service';
import { Application } from '@scion/workbench-application-platform.api';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@ import { ActivatedRouteSnapshot, Router } from '@angular/router';
import { ACTIVITY_DATA_KEY, ACTIVITY_OUTLET_NAME } from '../workbench.constants';
import { InternalWorkbenchRouter } from '../routing/workbench-router.service';
import { Activity, InternalActivity } from './activity';
import { BehaviorSubject, Observable } from 'rxjs';

@Injectable()
export class WorkbenchActivityPartService {

private _activities: Activity[] = [];
private _activities$ = new BehaviorSubject<Activity[]>([]);

constructor(private _router: Router,
private _wbRouter: InternalWorkbenchRouter,
Expand All @@ -28,7 +29,14 @@ export class WorkbenchActivityPartService {
* Returns the list of activities.
*/
public get activities(): Activity[] {
return this._activities;
return this._activities$.value;
}

/**
* Returns the list of activities as {Observable}, which emits when activities are added or removed.
*/
public get activities$(): Observable<Activity[]> {
return this._activities$;
}

/**
Expand All @@ -42,7 +50,7 @@ export class WorkbenchActivityPartService {
* Returns the activity which is currently active, or `null` otherwise.
*/
public get activeActivity(): Activity | null {
return this._activities.find(it => it.active) || null;
return this.activities.find(it => it.active) || null;
}

/**
Expand All @@ -55,8 +63,9 @@ export class WorkbenchActivityPartService {
return this._router.navigate([{outlets: {[ACTIVITY_OUTLET_NAME]: activity.active ? null : activity.commands}}], {
queryParamsHandling: 'preserve'
});
} else if (activity.target === 'view') {
return this._wbRouter.navigate(activity.commands);
}
else if (activity.target === 'view') {
return this._wbRouter.navigate(activity.commands, {activateIfPresent: false});
}
throw Error('[IllegalActivityTargetError] Target must be \'activity-panel\' or \'view\'');
}
Expand All @@ -65,19 +74,16 @@ export class WorkbenchActivityPartService {
* Adds an activity to the activity bar.
*/
public addActivity(activity: Activity): void {
this._activities.push(activity);
this._activities.sort((a1, a2) => (a1.position || 0) - (a2.position || 0));
const activities = [...this.activities, activity].sort((a1, a2) => (a1.position || 0) - (a2.position || 0));
this._activities$.next(activities);
}

/**
* Removes an activity from the activity bar.
*/
public removeActivity(activity: Activity): void {
const index = this._activities.findIndex(it => it === activity);
if (index === -1) {
throw Error('[IllegalStateError] Activity not registered');
}
this._activities.splice(index, 1);
const activities = this.activities.filter(it => it !== activity);
this._activities$.next(activities);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export class ActivityResolver implements Resolve<Activity>, OnDestroy {
.pipe(
filter(event => event instanceof NavigationEnd),
filter(() => !this._router.routerState.snapshot.root.children.some(it => it.outlet === ACTIVITY_OUTLET_NAME)),
takeUntil(this._destroy$)
takeUntil(this._destroy$),
)
.subscribe(() => {
this.deactivateActivity();
Expand Down
2 changes: 1 addition & 1 deletion projects/scion/workbench/src/lib/workbench.component.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<ng-container #content_host></ng-container> <!-- placed upfront to not cover other elements, e.g. sashes or popus -->
<wb-activity-part></wb-activity-part>
<wb-activity-part *ngIf="activitiesVisible$ | async"></wb-activity-part>
<wb-view-part-grid></wb-view-part-grid>
<ng-container #overlay_host></ng-container>
<wb-message-box-stack></wb-message-box-stack>
Expand Down
7 changes: 5 additions & 2 deletions projects/scion/workbench/src/lib/workbench.component.scss
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,14 @@
flex: none;
}

> wb-activity-part + wb-view-part-grid {
position: relative; // forms a stacking context to show 'box-shadow'
box-shadow: -1px 0 2px 0 rgba(0, 0, 0, .4);
}

> wb-view-part-grid {
@include preventPointerEvents;
flex: auto;
position: relative; // forms a stacking context to show 'box-shadow'
box-shadow: -1px 0 2px 0 rgba(0, 0, 0, .4);
}

> wb-message-box-stack {
Expand Down
11 changes: 11 additions & 0 deletions projects/scion/workbench/src/lib/workbench.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ import { Component, HostBinding, ViewChild, ViewContainerRef } from '@angular/co
import { WorkbenchLayoutService } from './workbench-layout.service';
import { OverlayHostRef } from './overlay-host-ref.service';
import { ContentHostRef } from './content-projection/content-host-ref.service';
import { filter, map } from 'rxjs/operators';
import { Observable } from 'rxjs';
import { WorkbenchActivityPartService } from './activity-part/workbench-activity-part.service';

@Component({
selector: 'wb-workbench',
Expand All @@ -20,6 +23,8 @@ import { ContentHostRef } from './content-projection/content-host-ref.service';
})
export class WorkbenchComponent {

public activitiesVisible$: Observable<boolean>;

@ViewChild('overlay_host', {read: ViewContainerRef})
public set overlayHost(overlayHost: ViewContainerRef) {
this._overlayHostRef.set(overlayHost);
Expand All @@ -36,7 +41,13 @@ export class WorkbenchComponent {
}

constructor(private _workbenchLayout: WorkbenchLayoutService,
private _activityPartService: WorkbenchActivityPartService,
private _overlayHostRef: OverlayHostRef,
private _contentHostRef: ContentHostRef) {
this.activitiesVisible$ = this._activityPartService.activities$
.pipe(
map(activities => activities.filter(activity => activity.visible)),
map(activities => activities.length > 0),
);
}
}

0 comments on commit fb43cf6

Please sign in to comment.