refactored collapsing widget, fixed refreshing a collapsed widget (#1107)

This commit is contained in:
Anthony Dresser
2018-04-11 14:39:23 -07:00
committed by GitHub
parent 087a6a0810
commit ed10f984b6
2 changed files with 14 additions and 12 deletions

View File

@@ -210,7 +210,6 @@ export class CollapseWidgetAction extends Action {
private _uri: string,
private _widgetUuid: string,
private collpasedState: boolean,
private collapsedStateChangedEvent: Event<boolean>,
@IAngularEventingService private _angularEventService: IAngularEventingService
) {
super(
@@ -218,7 +217,6 @@ export class CollapseWidgetAction extends Action {
collpasedState ? CollapseWidgetAction.EXPAND_LABEL : CollapseWidgetAction.COLLPASE_LABEL,
collpasedState ? CollapseWidgetAction.EXPAND_ICON : CollapseWidgetAction.COLLAPSE_ICON
);
this.collapsedStateChangedEvent(collapsed => this._updateState(collapsed));
}
run(): TPromise<boolean> {
@@ -232,8 +230,15 @@ export class CollapseWidgetAction extends Action {
}
private _updateState(collapsed: boolean): void {
if (collapsed === this.collpasedState) {
return;
}
this.collpasedState = collapsed;
this._setClass(this.collpasedState ? CollapseWidgetAction.EXPAND_ICON : CollapseWidgetAction.COLLAPSE_ICON);
this._setLabel(this.collpasedState ? CollapseWidgetAction.EXPAND_LABEL : CollapseWidgetAction.COLLPASE_LABEL);
}
public set state(collapsed: boolean) {
this._updateState(collapsed);
}
}

View File

@@ -53,6 +53,7 @@ export class DashboardWidgetWrapper extends AngularDisposable implements OnInit
@Input() private _config: WidgetConfig;
@Input() private collapsable = false;
private _collapseAction: CollapseWidgetAction;
private _collapsed = false;
public get collapsed(): boolean {
@@ -64,17 +65,13 @@ export class DashboardWidgetWrapper extends AngularDisposable implements OnInit
return;
}
this._collapsed = val;
if (this.collapsedStateChangedEmitter) {
this.collapsedStateChangedEmitter.fire(this._collapsed);
}
this._collapseAction.state = val;
this._changeref.detectChanges();
if (!val) {
this.loadWidget();
}
}
private collapsedStateChangedEmitter: Emitter<boolean>;
@memoize
public get guid(): string {
return generateUuid();
@@ -114,8 +111,8 @@ export class DashboardWidgetWrapper extends AngularDisposable implements OnInit
this._actionbar = new ActionBar(this._actionbarRef.nativeElement);
if (this._actions) {
if (this.collapsable) {
this.collapsedStateChangedEmitter = new Emitter<boolean>();
this._actionbar.push(this._bootstrap.instantiationService.createInstance(CollapseWidgetAction, this._bootstrap.getUnderlyingUri(), this.guid, this.collapsed, this.collapsedStateChangedEmitter.event), { icon: true, label: false });
this._collapseAction = this._bootstrap.instantiationService.createInstance(CollapseWidgetAction, this._bootstrap.getUnderlyingUri(), this.guid, this.collapsed);
this._actionbar.push(this._collapseAction, { icon: true, label: false });
}
this._actionbar.push(this._bootstrap.instantiationService.createInstance(ToggleMoreWidgetAction, this._actions, this._component.actionsContext), { icon: true, label: false });
}
@@ -123,13 +120,13 @@ export class DashboardWidgetWrapper extends AngularDisposable implements OnInit
}
public refresh(): void {
if (this._component && this._component.refresh) {
if (!this.collapsed && this._component && this._component.refresh) {
this._component.refresh();
}
}
public layout(): void {
if (this._component && this._component.layout) {
if (!this.collapsed && this._component && this._component.layout) {
this._component.layout();
}
}
@@ -170,7 +167,7 @@ export class DashboardWidgetWrapper extends AngularDisposable implements OnInit
this._component = componentRef.instance;
let actions = componentRef.instance.actions;
if (componentRef.instance.refresh) {
actions.push(new RefreshWidgetAction(componentRef.instance.refresh, componentRef.instance));
actions.push(new RefreshWidgetAction(this.refresh, this));
}
if (actions !== undefined && actions.length > 0) {
this._actions = actions;