Browse Source

UI: Code cleanup

feature/widget-bundles
Igor Kulikov 3 years ago
parent
commit
453f9cdbee
  1. 58
      ui-ngx/src/app/core/http/widget.service.ts
  2. 16
      ui-ngx/src/app/modules/home/pages/widget/widget-library-routing.module.ts
  3. 1
      ui-ngx/src/app/modules/home/pages/widget/widget-types-table-config.resolver.ts

58
ui-ngx/src/app/core/http/widget.service.ts

@ -24,7 +24,6 @@ import { WidgetsBundle } from '@shared/models/widgets-bundle.model';
import {
BaseWidgetType,
fullWidgetTypeFqn,
Widget,
WidgetType,
widgetType,
WidgetTypeDetails,
@ -168,63 +167,6 @@ export class WidgetService {
}
}
public loadBundleLibraryWidgets(widgetsBundleId: string,
config?: RequestConfig): Observable<Array<Widget>> {
return this.getBundleWidgetTypes(widgetsBundleId, config).pipe(
map((types) => {
types = types.sort((a, b) => {
let result = (a.deprecated ? 1 : 0) - (b.deprecated ? 1 : 0);
if (result === 0) {
result = widgetType[b.descriptor.type].localeCompare(widgetType[a.descriptor.type]);
if (result === 0) {
result = b.createdTime - a.createdTime;
}
}
return result;
});
const widgetTypes = new Array<Widget>();
let top = 0;
const lastTop = [0, 0, 0];
let col = 0;
let column = 0;
types.forEach((type) => {
const widgetTypeInfo = toWidgetInfo(type);
const sizeX = 8;
const sizeY = Math.floor(widgetTypeInfo.sizeY);
const widget: Widget = {
typeId: type.id,
typeFullFqn: widgetTypeInfo.fullFqn,
type: widgetTypeInfo.type,
title: widgetTypeInfo.widgetName,
sizeX,
sizeY,
row: top,
col,
config: JSON.parse(widgetTypeInfo.defaultConfig)
};
widget.config.title = widgetTypeInfo.widgetName;
if (type.deprecated) {
widget.config.title += ` (${this.translate.instant('widget.deprecated')})`;
}
widgetTypes.push(widget);
top += sizeY;
if (top > lastTop[column] + 10) {
lastTop[column] = top;
column++;
if (column > 2) {
column = 0;
}
top = lastTop[column];
col = column * 8;
}
});
return widgetTypes;
})
);
}
public getWidgetType(fullFqn: string, config?: RequestConfig): Observable<WidgetType> {
return this.http.get<WidgetType>(`/api/widgetType?fqn=${fullFqn}`,
defaultHttpOptionsFromConfig(config));

16
ui-ngx/src/app/modules/home/pages/widget/widget-library-routing.module.ts

@ -62,21 +62,6 @@ export class WidgetsBundleWidgetsResolver implements Resolve<Array<WidgetTypeInf
}
}
/*
@Injectable()
export class WidgetsTypesDataResolver implements Resolve<WidgetsData> {
constructor(private widgetsService: WidgetService) {
}
resolve(route: ActivatedRouteSnapshot): Observable<WidgetsData> {
const widgetsBundleId = route.params.widgetsBundleId;
return this.widgetsService.loadBundleLibraryWidgets(widgetsBundleId).pipe(
map((widgets) => ({ widgets })
));
}
}*/
@Injectable()
export class WidgetEditorDataResolver implements Resolve<WidgetEditorData> {
@ -279,7 +264,6 @@ const routes: Routes = [
WidgetsBundlesTableConfigResolver,
WidgetsBundleResolver,
WidgetsBundleWidgetsResolver,
// WidgetsTypesDataResolver,
WidgetEditorDataResolver
]
})

1
ui-ngx/src/app/modules/home/pages/widget/widget-types-table-config.resolver.ts

@ -152,7 +152,6 @@ export class WidgetTypesTableConfigResolver implements Resolve<EntityTableConfig
this.config.deleteEnabled = (widgetType) => this.isWidgetTypeEditable(widgetType, authUser.authority);
this.config.entitySelectionEnabled = (widgetType) => this.isWidgetTypeEditable(widgetType, authUser.authority);
this.config.detailsReadonly = (widgetType) => !this.isWidgetTypeEditable(widgetType, authUser.authority);
const authState = getCurrentAuthState(this.store);
this.config.entitiesFetchFunction = pageLink => this.widgetsService.getWidgetTypes(pageLink);
return this.config;
}

Loading…
Cancel
Save