import _ from 'lodash';
import { Observable, Subscriber } from 'rxjs';
-import { CdTableFetchDataContext } from '~/app/shared/models/cd-table-fetch-data-context';
-import { CdTableServerSideService } from '~/app/shared/services/cd-table-server-side.service';
import { RbdService } from '~/app/shared/api/rbd.service';
import { ListWithDetails } from '~/app/shared/classes/list-with-details.class';
import { TableStatusViewCache } from '~/app/shared/classes/table-status-view-cache';
import { ViewCacheStatus } from '~/app/shared/enum/view-cache-status.enum';
import { CdTableAction } from '~/app/shared/models/cd-table-action';
import { CdTableColumn } from '~/app/shared/models/cd-table-column';
+import { CdTableFetchDataContext } from '~/app/shared/models/cd-table-fetch-data-context';
import { CdTableSelection } from '~/app/shared/models/cd-table-selection';
import { FinishedTask } from '~/app/shared/models/finished-task';
import { ImageSpec } from '~/app/shared/models/image-spec';
import { DimlessBinaryPipe } from '~/app/shared/pipes/dimless-binary.pipe';
import { DimlessPipe } from '~/app/shared/pipes/dimless.pipe';
import { AuthStorageService } from '~/app/shared/services/auth-storage.service';
+import { CdTableServerSideService } from '~/app/shared/services/cd-table-server-side.service';
import { ModalService } from '~/app/shared/services/modal.service';
import { TaskListService } from '~/app/shared/services/task-list.service';
import { TaskWrapperService } from '~/app/shared/services/task-wrapper.service';
tableStatus = new TableStatusViewCache();
selection = new CdTableSelection();
icons = Icons;
- count: number = 0;
- private tableContext: CdTableFetchDataContext = null;
+ count = 0;
+ private tableContext: CdTableFetchDataContext = null;
modalRef: NgbModalRef;
public taskListService: TaskListService,
private urlBuilder: URLBuilderService,
public actionLabels: ActionLabelsI18n
- ) {
+ ) {
super();
this.permission = this.authStorageService.getPermissions().rbdImage;
const getImageUri = () =>
].includes(task.name);
};
- console.log(taskFilter);
- console.log(itemFilter);
- console.log(this.builders);
- // this.taskListService.init(
- // (context: CdTableFetchDataContext) => this.rbdService.list(context.toParams()),
- // (resp) => this.prepareResponse(resp),
- // (images) => (this.images = images),
- // () => this.onFetchError(),
- // taskFilter,
- // itemFilter,
- // this.builders
- // );
+ this.taskListService.init(
+ (context) => this.getRbdImages(context),
+ (resp) => this.prepareResponse(resp),
+ (images) => (this.images = images),
+ () => this.onFetchError(),
+ taskFilter,
+ itemFilter,
+ this.builders
+ );
}
onFetchError() {
this.tableStatus = new TableStatusViewCache(ViewCacheStatus.ValueException);
}
- getRbdImages(context: CdTableFetchDataContext = null){
- if(context !== null) {
- this.tableContext = context;
- }
- console.log(context);
- this.rbdService.list(this.tableContext.toParams()).
- subscribe((resp: any) => {
- console.log(resp);
- this.prepareResponse(resp);
- });
- }
- prepareResponse(resp: any[]): any[] {
- let images: any[] = [];
- const viewCacheStatusMap = {};
-
- console.log(resp);
- resp.forEach((pool) => {
- if (_.isUndefined(viewCacheStatusMap[pool.status])) {
- viewCacheStatusMap[pool.status] = [];
- }
- viewCacheStatusMap[pool.status].push(pool.pool_name);
- images = images.concat(pool.value);
- });
-
- let status: number;
- if (viewCacheStatusMap[ViewCacheStatus.ValueException]) {
- status = ViewCacheStatus.ValueException;
- } else if (viewCacheStatusMap[ViewCacheStatus.ValueStale]) {
- status = ViewCacheStatus.ValueStale;
- } else if (viewCacheStatusMap[ViewCacheStatus.ValueNone]) {
- status = ViewCacheStatus.ValueNone;
+ getRbdImages(context: CdTableFetchDataContext = null) {
+ if (context !== null) {
+ this.tableContext = context;
}
+ return this.rbdService.list(this.tableContext.toParams());
+ }
- if (status) {
- const statusFor =
- (viewCacheStatusMap[status].length > 1 ? 'pools ' : 'pool ') +
- viewCacheStatusMap[status].join();
+ prepareResponse(resp: any[]): any[] {
+ let images: any[] = [];
- this.tableStatus = new TableStatusViewCache(status, statusFor);
- } else {
- this.tableStatus = new TableStatusViewCache();
- }
+ resp.forEach((pool) => {
+ images = images.concat(pool.value);
+ });
images.forEach((image) => {
if (image.schedule_info !== undefined) {
}
});
- console.group('reponse');
- console.log(resp);
- console.log(resp[0].headers);
- this.count = CdTableServerSideService.getCount(resp[0]);
- console.log(this.count);
- this.images = images;
- console.groupEnd();
+ this.count = CdTableServerSideService.getCount(resp[0]);
+ this.images = images;
return images;
}
}
}
-
/*
for pool in pools
for namespace in namespaces
refs = get_image_refs
for ref in refs:
get_data(ref)
-
+
@ttl_cache(5)
def get_refs();
joint_refs = []
for ref in joint_refs[offset:offset+limit]:
get_data(ref)
-
-
-
*/
});
}
- get(imageSpec: ImageSpec) {
- return this.http.get(`api/block/image/${imageSpec.toStringEncoded()}`);
+ get(imageSpec: ImageSpec) {
+ return this.http.get(`api/block/image/${imageSpec.toStringEncoded()}`);
}
list(params: any) {
- return this.http.get<RbdPool[]>('api/block/image', {params: params, observe: 'response'}).pipe(
- map((response: any) => {
- console.log(response);
- return response['body'].map((pool: any) => {
- pool.value.map((image: any) => {
- if (!image.configuration) {
+ return this.http
+ .get<RbdPool[]>('api/block/image', { params: params, observe: 'response' })
+ .pipe(
+ map((response: any) => {
+ return response['body'].map((pool: any) => {
+ pool.value.map((image: any) => {
+ if (!image.configuration) {
+ return image;
+ }
+ image.configuration.map((option: any) =>
+ Object.assign(option, this.rbdConfigurationService.getOptionByName(option.name))
+ );
return image;
- }
- image.configuration.map((option: any) =>
- Object.assign(option, this.rbdConfigurationService.getOptionByName(option.name))
- );
- return image;
+ });
+ pool['headers'] = response.headers;
+ return pool;
});
- pool['headers'] = response.headers;
- return pool;
})
- }
- )
- );
+ );
}
copy(imageSpec: ImageSpec, rbd: any) {
-import { HttpParams } from "@angular/common/http";
-import { PageInfo } from "./cd-table-paging";
+import { HttpParams } from '@angular/common/http';
+
+import { PageInfo } from './cd-table-paging';
export class CdTableFetchDataContext {
errorConfig = {
* reset the data table to the correct state.
*/
error: Function;
- pageInfo: PageInfo = new PageInfo;
+ pageInfo: PageInfo = new PageInfo();
constructor(error: () => void) {
this.error = error;
}
- toParams(): HttpParams {
- if (this.pageInfo.limit === null) {
- this.pageInfo.limit = 0;
- }
- return new HttpParams({
- fromObject: {
- offset: String(this.pageInfo.offset * this.pageInfo.limit),
- limit: String(this.pageInfo.limit)
- }
- });
-
- }
+ toParams(): HttpParams {
+ if (this.pageInfo.limit === null) {
+ this.pageInfo.limit = 0;
+ }
+ return new HttpParams({
+ fromObject: {
+ offset: String(this.pageInfo.offset * this.pageInfo.limit),
+ limit: String(this.pageInfo.limit)
+ }
+ });
+ }
}
export class TaskListService implements OnDestroy {
summaryDataSubscription: Subscription;
- getUpdate: () => Observable<object>;
+ getUpdate: (context?: any) => Observable<object>;
preProcessing: (_: any) => any[];
setList: (_: any[]) => void;
onFetchError: (error: any) => void;
* @memberof TaskListService
*/
init(
- getUpdate: () => Observable<object>,
+ getUpdate: (context?: any) => Observable<object>,
preProcessing: (_: any) => any[],
setList: (_: any[]) => void,
onFetchError: (error: any) => void,
}, this.onFetchError);
}
- fetch() {
- this.getUpdate().subscribe((resp: any) => {
+ fetch(context: any = null) {
+ this.getUpdate(context).subscribe((resp: any) => {
this.updateData(resp, this.summary['executing_tasks'].filter(this.taskFilter));
}, this.onFetchError);
}