Browse Source

Hide edge widget if edgesSupportEnabled()

pull/3811/head
deaflynx 6 years ago
parent
commit
206c570abb
  1. 16
      ui-ngx/src/app/modules/home/pages/widget/widgets-bundles-table-config.resolver.ts
  2. 10
      ui-ngx/src/app/shared/components/widgets-bundle-select.component.ts

16
ui-ngx/src/app/modules/home/pages/widget/widgets-bundles-table-config.resolver.ts

@ -33,11 +33,12 @@ import { WidgetsBundleComponent } from '@modules/home/pages/widget/widgets-bundl
import { NULL_UUID } from '@shared/models/id/has-uuid';
import { Store } from '@ngrx/store';
import { AppState } from '@core/core.state';
import { getCurrentAuthUser } from '@app/core/auth/auth.selectors';
import { getCurrentAuthState, getCurrentAuthUser } from '@app/core/auth/auth.selectors';
import { Authority } from '@shared/models/authority.enum';
import { DialogService } from '@core/services/dialog.service';
import { ImportExportService } from '@home/components/import-export/import-export.service';
import { Direction } from "@shared/models/page/sort-order";
import { map } from "rxjs/operators";
@Injectable()
export class WidgetsBundlesTableConfigResolver implements Resolve<EntityTableConfig<WidgetsBundle>> {
@ -106,7 +107,7 @@ export class WidgetsBundlesTableConfigResolver implements Resolve<EntityTableCon
this.config.deleteEntitiesTitle = count => this.translate.instant('widgets-bundle.delete-widgets-bundles-title', {count});
this.config.deleteEntitiesContent = () => this.translate.instant('widgets-bundle.delete-widgets-bundles-text');
this.config.entitiesFetchFunction = pageLink => this.widgetsService.getWidgetBundles(pageLink);
this.config.loadEntity = id => this.widgetsService.getWidgetsBundle(id.id);
this.config.saveEntity = widgetsBundle => this.widgetsService.saveWidgetsBundle(widgetsBundle);
this.config.deleteEntity = id => this.widgetsService.deleteWidgetsBundle(id.id);
@ -119,6 +120,17 @@ export class WidgetsBundlesTableConfigResolver implements Resolve<EntityTableCon
this.config.deleteEnabled = (widgetsBundle) => this.isWidgetsBundleEditable(widgetsBundle, authUser.authority);
this.config.entitySelectionEnabled = (widgetsBundle) => this.isWidgetsBundleEditable(widgetsBundle, authUser.authority);
this.config.detailsReadonly = (widgetsBundle) => !this.isWidgetsBundleEditable(widgetsBundle, authUser.authority);
const authState = getCurrentAuthState(this.store);
if (!authState.edgesSupportEnabled) {
this.config.entitiesFetchFunction = pageLink => this.widgetsService.getWidgetBundles(pageLink).pipe(
map((widgetBundles) => {
widgetBundles.data = widgetBundles.data.filter(widgetBundle => widgetBundle.alias !== 'edge_widgets');
return widgetBundles;
})
);
} else {
this.config.entitiesFetchFunction = pageLink => this.widgetsService.getWidgetBundles(pageLink);
}
return this.config;
}

10
ui-ngx/src/app/shared/components/widgets-bundle-select.component.ts

@ -17,7 +17,7 @@
import { Component, forwardRef, Input, OnChanges, OnInit, SimpleChanges, ViewEncapsulation } from '@angular/core';
import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms';
import { Observable } from 'rxjs';
import { share, tap } from 'rxjs/operators';
import { map, share, tap } from 'rxjs/operators';
import { Store } from '@ngrx/store';
import { AppState } from '@app/core/core.state';
import { coerceBooleanProperty } from '@angular/cdk/coercion';
@ -25,6 +25,7 @@ import { WidgetsBundle } from '@shared/models/widgets-bundle.model';
import { WidgetService } from '@core/http/widget.service';
import { isDefined } from '@core/utils';
import { NULL_UUID } from '@shared/models/id/has-uuid';
import { getCurrentAuthState } from "@core/auth/auth.selectors";
@Component({
selector: 'tb-widgets-bundle-select',
@ -94,6 +95,13 @@ export class WidgetsBundleSelectComponent implements ControlValueAccessor, OnIni
}
}
}),
map((widgetsBundles) => {
const authState = getCurrentAuthState(this.store);
if (!authState.edgesSupportEnabled) {
widgetsBundles = widgetsBundles.filter(widgetsBundle => widgetsBundle.alias !== 'edge_widgets');
}
return widgetsBundles;
}),
share()
);
}

Loading…
Cancel
Save